I asked https://stackoverflow.com/questions/35579843/get-only-ring-nodes-from-a-diagram on stack overflow but there was no help at all. So I hope I get help from someone on here :)
I have a diagram that basically forms into a ring, each node is connected to another node. some nodes are part of the ring some are not. As the picture below shows, there is a ring of nodes (0,1,2,7,8,9). I want to get those nodes from the diagram and store them into a list.
Each node object contains details on the nodes it is connected to, so node 0, contains a list of connected nodes which basically has 1, and 9 in it.
I am trying to get the nodes within the ring, but the method I wrote does not work for all ring diagrams. Here is what I wrote that works on some diagrams
private bool SetMainRingList(StructureFeature strct, StructureFeature root, List<StructureFeature> mainRing) {
if ((strct.Equals(root) && mainRing.Contains(strct))) {
return false;
}
var children = strct.GetConnectedStructures();
if ((children.Contains(root) && mainRing.Contains(strct))) {
return false;
}
mainRing.Add(strct);
foreach (var structureFeature in children) {
if (mainRing.Contains(structureFeature)) {
var strcture = mainRing.Find(x => x.Oid == structureFeature.Oid);
if (strcture.ParentFeature == null)
continue;
if (strcture.ParentFeature.Equals(root)) {
bool skip = false;
var crntChildren = strcture.GetConnectedStructures();
foreach (var childContainerse in crntChildren) {
if (!mainRing.Contains(childContainerse)) {
skip = true;
break;
}
}
if (!skip)
return false;
}
continue;
}
structureFeature.ParentFeature = strct;
var leaf = SetMainRingList(structureFeature, root, mainRing);
var exchangeSite = structureFeature as ExchangeStructure;
if (leaf && ReferenceEquals(exchangeSite, null)) {
mainRing.Remove(structureFeature);
} else {
return false;
}
}
return true;
}