Hello,
I have types that are groups which contain sub-groups, and those groups may also contain sub-groups and so forth. I have a palette item of this type and I am calling IPaletteClient.Convert to create a node, but I am unsure what the best way is to add child sub-groups. I have a certain set of rules for each group type:
TypeA should generate a child sub-group TypeB
TypeB should generate child sub-groups TypeC, TypeD, TypeE
TypeE should generate a child sub-group TypeF
If there is a palette item of TypeA, it should recursively generate all of its descendants. What is the best way to go about this? On a related note, I also want the ability to have right-click support which will add child nodes while selecting a group. For example, right-clicking on TypeE should have the ability to add nodes of TypeF.
Here is some pseudo-code (for my function AddChildren) I have been trying that seems to work in most cases:
List childDataList = new List();
if (parentType == TypeA)
childDataList add all children (but not grand-children)
foreach ( ChildData childData in childDataList )
{
var childNode = new DomNode(childData.ChildType);
if (childData.ChildType.IdAttribute != null)
childNode.SetAttribute(childData.ChildType.IdAttribute, childData.ChildId);
parentNode.GetChildList(childData.ChildInfo).Add(childNode);
AddChildren(childNode, childData.ChildType);
}
Currently, the only time there is an issue is when one of the sub-types has an input/output pin and only in very certain circumstances. For example, if TypeF has an output pin and the canvas (circuit) is empty, dragging and dropping a palette item with a grand-child (not child) of TypeF will not correctly propagate the output pin to all parent groups of TypeF. This leads to an assert in Debug builds on validation. If I drag the same base type again (grand-parent or higher of TypeF), the pins are correctly updated. The issue has something to do with the way the Dirty flag is updated; however, before I go into more detail, I want to know if my approach for adding descendants is correct or if you guys have a more elegant solution (which may then solve the pin issue).
Thanks