private void CategorizeSubtree(PSMTreeIterator iterator) { if (iterator.CurrentNodeModelsElement() || IsContentGroupNode(iterator.CurrentNode)) { significantNodes.Add(iterator.CurrentNode); bool isRed = false; if ((changesByTargetSignificantNode.ContainsKey(iterator.CurrentNode) && !changesByTargetSignificantNode[iterator.CurrentNode].All(c => c.Element == iterator.CurrentNode && c is ICanBeIgnoredOnTarget)) || GetState(iterator.CurrentNode) == EContentPlacementState.Added) { redNodes.Add(iterator.CurrentNode); isRed = true; } PSMElement cn = iterator.CurrentNode; foreach (PSMElement child in iterator.GetChildNodes()) { iterator.CurrentNode = child; CategorizeSubtree(iterator); } iterator.CurrentNode = cn; PSMElement firstFoundRedChild = iterator.GetChildNodes().FirstOrDefault(child => (child is PSMAssociation) && redNodes.Contains(((PSMAssociation)child).Child) && IsContentGroupNode(((PSMAssociation)child).Child)); if (!isRed && firstFoundRedChild != null) { isRed = true; int index = redNodes.IndexOf(((PSMAssociation)firstFoundRedChild).Child); redNodes.Insert(index, iterator.CurrentNode); } if (!isRed) { if (iterator.GetChildNodes().Any(child => redNodes.Contains(child) || blueNodes.Contains(child) || insignificantBlueNodes.Contains(child))) { blueNodes.Add(iterator.CurrentNode); } else { greenNodes.Add(iterator.CurrentNode); } } } else { PSMElement cn = iterator.CurrentNode; foreach (PSMElement child in iterator.GetChildNodes()) { iterator.CurrentNode = child; CategorizeSubtree(iterator); } iterator.CurrentNode = cn; if (iterator.GetChildNodes().Any(child => redNodes.Contains(child) || blueNodes.Contains(child) || insignificantBlueNodes.Contains(child))) { insignificantBlueNodes.Add(iterator.CurrentNode); } } }
public static List <NodeElementWrapper> GetSubtreeElements(this PSMElement node) { PSMTreeIterator it = new PSMTreeIterator(node); List <NodeElementWrapper> contentList = new List <NodeElementWrapper>(); //if (((PSMClass)node).IsStructuralRepresentative && node.ModelsElement()) //{ // PSMClass representedClass = ((PSMClass)node).RepresentedPSMClass; // contentList.Add(new StructuralRepresentativeElements((PSMClass)node, representedClass)); //} foreach (PSMElement childNode in it.GetChildNodes()) { GetSubtreeContentComponentsInclRoot(childNode, ref contentList); } return(contentList); }
/// <summary> /// Adds attributes under a node into <param name="attributeList"/> (when called for a superordinate component, attributes /// from all subordinate PSM classes without element labels are included in the result too) /// </summary> /// <param name="node">node where to search for attributes</param> /// <param name="firstCall">false value indicates recursive call</param> /// <param name="attributeList">list in which attributes are added</param> private static void GetAttributesUnderNode(PSMElement node, bool firstCall, ref List <NodeAttributeWrapper> attributeList) { if (!firstCall && node is PSMClass && !((PSMClass)node).HasElementLabel && ((PSMClass)node).IsStructuralRepresentative) { PSMClass representedClass = ((PSMClass)node).RepresentedPSMClass; attributeList.Add(new StructuralRepresentativeAttributes((PSMClass)node, representedClass)); } { PSMClass psmClass = node as PSMClass; if (psmClass != null) { if (firstCall || (!psmClass.HasElementLabel)) { foreach (PSMAttribute psmAttribute in psmClass.PSMAttributes) { attributeList.Add(new SimpleNodeAttribute(psmAttribute)); } } else { return; } } } if (node is PSMClass || (node is PSMContentContainer && firstCall)) { foreach (PSMSubordinateComponent component in ((PSMSuperordinateComponent)node).Components) { GetAttributesUnderNode(component, false, ref attributeList); } } if (node is PSMClassUnion) { //throw new NotImplementedException("Can't handle unions yet"); } if (node is PSMContentChoice) { PSMContentChoice contentChoice = (PSMContentChoice)node; PSMTreeIterator it = new PSMTreeIterator(contentChoice); List <ChoiceAttributeOption> options = new List <ChoiceAttributeOption>(); foreach (PSMElement childNode in it.GetChildNodes()) { List <NodeAttributeWrapper> choices = new List <NodeAttributeWrapper>(); GetAttributesUnderNode(childNode, false, ref choices); if (choices.Count > 0) { ChoiceAttributeOption option = new ChoiceAttributeOption(); option.Items = choices; options.Add(option); } } if (options.Count > 0) { ChoiceAttributes choiceAttributes = new ChoiceAttributes(contentChoice, options); attributeList.Add(choiceAttributes); } } else if (node is PSMClassUnion) { PSMClassUnion classUnion = (PSMClassUnion)node; PSMTreeIterator it = new PSMTreeIterator(classUnion); List <ChoiceAttributeOption> options = new List <ChoiceAttributeOption>(); foreach (PSMElement childNode in it.GetChildNodes()) { List <NodeAttributeWrapper> choices = new List <NodeAttributeWrapper>(); GetAttributesUnderNode(childNode, false, ref choices); if (choices.Count > 0) { ChoiceAttributeOption option = new ChoiceAttributeOption(); option.Items = choices; options.Add(option); } } if (options.Count > 0) { UnionAttributes choiceAttributes = new UnionAttributes(classUnion, options); attributeList.Add(choiceAttributes); } } if (node is PSMAssociation) { GetAttributesUnderNode(((PSMAssociation)node).Child, false, ref attributeList); } return; }
private static void GetSubtreeContentComponentsInclRoot(PSMElement node, ref List <NodeElementWrapper> e) { List <NodeElementWrapper> contentList = e; bool?group = null; if ((node is PSMClass) || (node is PSMContentContainer)) { if (node.ModelsElement()) { group = false; } else { group = true; } } if (group != null) // i.e. (node is PSMClass) || (node is PSMContentContainer) { if (group == false) // not in group { contentList.Add(new SimpleNodeElement(node)); } else // in group { if (EncompassesContentForParentSignificantNode(node)) { ContentGroup cg = new ContentGroup(); cg.ContainingClass = (PSMClass)node; if (((PSMClass)node).IsStructuralRepresentative && !node.ModelsElement()) { PSMClass representedClass = ((PSMClass)node).RepresentedPSMClass; cg.ContentComponents.Add(new StructuralRepresentativeElements((PSMClass)node, representedClass)); } PSMTreeIterator it = new PSMTreeIterator(node); foreach (PSMElement component in it.GetChildNodes()) { List <NodeElementWrapper> tmp = new List <NodeElementWrapper>(); GetSubtreeContentComponentsInclRoot(component, ref tmp); cg.ContentComponents.AddRange(tmp); } contentList.Add(cg); } } } #region choice and union else if (node is PSMAttributeContainer) { foreach (PSMAttribute psmAttribute in ((PSMAttributeContainer)node).PSMAttributes) { contentList.Add(new SimpleNodeElement(psmAttribute)); } } else if ((node is PSMContentChoice) || (node is PSMClassUnion)) { PSMTreeIterator it = new PSMTreeIterator(node); List <ChoiceElementOption> options = new List <ChoiceElementOption>(); foreach (PSMElement childNode in it.GetChildNodes()) { List <NodeElementWrapper> items = new List <NodeElementWrapper>(); GetSubtreeContentComponentsInclRoot(childNode, ref items); if (items.Count > 0) { ChoiceElementOption option = new ChoiceElementOption(); option.Items = items; options.Add(option); } } if (options.Count > 0) { if (node is PSMContentChoice) { ChoiceElements choiceElements = new ChoiceElements((PSMContentChoice)node, options); contentList.Add(choiceElements); } else { UnionElements unionElements = new UnionElements((PSMClassUnion)node, options); contentList.Add(unionElements); } } } #endregion else if (node is PSMAssociation) { GetSubtreeContentComponentsInclRoot(((PSMAssociation)node).Child, ref contentList); } return; }