public static PSMElement GetSignificantAncestorOrSelf(PSMElement element, NodeMarker additionalSignificantNodeMarker) { PSMTreeIterator helper = new PSMTreeIterator(element); while (!((helper.CurrentNode is PSMClass && ((PSMClass)helper.CurrentNode).HasElementLabel) || helper.CurrentNode is PSMContentContainer || (additionalSignificantNodeMarker != null && additionalSignificantNodeMarker(helper.CurrentNode))) && helper.CanGoToParent()) { helper.GoToParent(); } if ((helper.CurrentNode is PSMClass && ((PSMClass)helper.CurrentNode).HasElementLabel) || helper.CurrentNode is PSMContentContainer || (additionalSignificantNodeMarker != null && additionalSignificantNodeMarker(helper.CurrentNode))) { return(helper.CurrentNode); } //else if (!helper.CanGoToParent()) // return helper.CurrentNode; else { return(null); } }
public object Clone() { PSMTreeIterator psmTreeIterator = new PSMTreeIterator(Diagram) { CurrentNode = this.CurrentNode }; return(psmTreeIterator); }
public static IEnumerable <PSMElement> SignificantAncestors(PSMElement element, NodeMarker nodeMarker) { List <PSMElement> result = new List <PSMElement>(); PSMTreeIterator it = new PSMTreeIterator(element); while (it.CanGoToParent()) { it.GoToParent(); PSMElement significantAncestorOrSelf = it.GetSignificantAncestorOrSelf(nodeMarker); result.AddIfNotContained(significantAncestorOrSelf); } return(result); }
public static bool NodeIsUnderRepresentedClass(PSMElement redNode) { PSMTreeIterator it = new PSMTreeIterator(redNode); while (it.CanGoToParent()) { it.GoToParent(); PSMClass psmClass = it.CurrentNode as PSMClass; if (psmClass != null && psmClass.IsReferencedFromStructuralRepresentative()) { return(true); } } return(false); }
public static bool IsInSignificantSubtree(PSMElement node) { PSMTreeIterator it = new PSMTreeIterator(node); PSMElement rootCandidate = null; if (CanBeDocumentRoot(node)) { rootCandidate = node; } while (it.CanGoToParent()) { it.GoToParent(); if (CanBeDocumentRoot(it.CurrentNode)) { rootCandidate = it.CurrentNode; } else if (!(node is PSMClassUnion)) { rootCandidate = null; } } return(rootCandidate != null); }
/// <summary> /// Returns PSM associations between an two nodes (they must be part of a path in the PSM tree). /// (assocations are returned in root to leafes order. /// </summary> /// <param name="ancestor">ancestor node</param> /// <param name="descendant">descendant node</param> public static IEnumerable <PSMAssociation> GetAssociationsBetweenNodes(PSMElement ancestor, PSMElement descendant) { List <PSMAssociation> associations = new List <PSMAssociation>(); PSMTreeIterator it = new PSMTreeIterator(descendant); while (it.CurrentNode != ancestor) { { PSMAssociationChild associationChild = it.CurrentNode as PSMAssociationChild; if (associationChild != null && associationChild.ParentAssociation != null) { associations.Insert(0, associationChild.ParentAssociation); } } if (!it.CanGoToParent()) { throw new ArgumentException("Nodes are not valid ancestor-descendant pair"); } it.GoToParent(); } return(associations); }
public PSMElement GetParent() { PSMElement parent = null; { PSMClass cl = CurrentNode as PSMClass; if (cl != null) { if (cl.ParentAssociation != null) { parent = cl.ParentAssociation.Parent; return(parent); } if (cl.ParentUnion != null) { parent = cl.ParentUnion; return(parent); } if (Diagram.Roots.Contains(cl)) { return(null); } if (cl.Generalizations.Count > 0) { PSMTreeIterator tmp = new PSMTreeIterator((PSMClass)cl.Generalizations[0].General); return(tmp.GetParent()); } } } { PSMSubordinateComponent cs = CurrentNode as PSMSubordinateComponent; if (cs != null) { parent = cs.Parent; return(parent); } } { PSMClassUnion cu = CurrentNode as PSMClassUnion; if (cu != null) { parent = cu.ParentAssociation.Parent; return(parent); } } { PSMAttribute ca = CurrentNode as PSMAttribute; if (ca != null) { if (ca.AttributeContainer != null) { return(ca.AttributeContainer); } else { return(ca.Class); } } } return(parent); }