public static bool CheckCommonParentClass(IEnumerable <PSMSubordinateComponent> components, out PSMClass parentClass) { parentClass = null; foreach (PSMSubordinateComponent component in components) { PSMSuperordinateComponent p = component.Parent; while (!(p is PSMClass) && (p is PSMSubordinateComponent) && ((PSMSubordinateComponent)p).Parent != null) { p = ((PSMSubordinateComponent)p).Parent; } if (p is PSMClass) { if (parentClass == null) { parentClass = (PSMClass)p; } else { if (parentClass != p) { parentClass = null; return(false); } } } } return(true); }
public override Element Clone(Model targetModel, ElementCopiesMap createdCopies) { PSMSuperordinateComponent copyParent = (PSMSuperordinateComponent)createdCopies[Parent]; PSMContentChoice clone = new _PSMContentChoice(copyParent, targetModel.Schema); return(clone); }
public static IList <EvolutionChange> Detect(Version v1, Version v2, PSMDiagram diagram) { List <EvolutionChange> result = new List <EvolutionChange>(); PSMDiagram diagramOldVersion = (PSMDiagram)diagram.GetInVersion(v1); foreach (PSMSuperordinateComponent root in diagram.Roots) { PSMSuperordinateComponent rootOldVersion = (PSMSuperordinateComponent)root.GetInVersion(v1); IList <PSMSuperordinateComponent> oldRoots = diagramOldVersion.Roots.ToList(); if (rootOldVersion != null && oldRoots.Contains(rootOldVersion) && oldRoots.IndexOf(rootOldVersion) != diagram.Roots.ToList().IndexOf(root) ) { result.Add(new DiagramRootIndexChange(root) { OldVersion = v1, NewVersion = v2 }); } } return(result); }
/// <summary> /// Creates a new attribute container. /// It is an UML Class with XSem.PSMAttributeContainer stereotype. /// </summary> /// <param name="_parent"> /// Reference to a component that is the parent of this container. /// </param> /// <param name="_schema"> /// Reference to the Schema instance that is the top /// of this model hierarchy. /// </param> public _PSMAttributeContainer(PSMSuperordinateComponent _parent, Schema _schema) : base(_schema, StereotypeTarget.Class) { parent = _parent; attributes = new ObservableCollection <PSMAttribute>(); attributes.CollectionChanged += OnAttributesChanged; adaptedElement = NUml.Uml2.Create.Class(); // Get the XSem.PSMAttributeContainer stereotype and apply it // The stereotype instance is then removed from the collection to hide it from the user. try { Stereotype xsem = Schema.Profiles.Get("XSem").Stereotypes.Get("PSMAttributeContainer"); xsemStereotype = xsem.ApplyTo(this); AppliedStereotypes.Remove(xsemStereotype); } catch (NullReferenceException) { throw new Exception("Fatal error! Cannot find the XSem profile or " + "the XSem.PSMAttributeContainer stereotype!"); } // Initialize the stereotype instance xsemStereotype.Attributes.Get("Parent").Value = new ValueSpecification(parent); }
internal override void CommandOperation() { PSMSuperordinateComponent p = AttributeContainerLeftOut.Parent; while (!(p is PSMClass) && p is PSMSubordinateComponent) { p = ((PSMSubordinateComponent)p).Parent; } parentClass = p as PSMClass; if (parentClass != null) { returnedAttributes = new List <PSMAttribute>(); foreach (PSMAttribute attribute in AttributeContainerLeftOut.PSMAttributes) { if (parentClass.PSMAttributes.Any(a => a.RepresentedAttribute == attribute.RepresentedAttribute)) { continue; } PSMAttribute createdAttribute = parentClass.AddAttribute(attribute.RepresentedAttribute); returnedAttributes.Add(createdAttribute); if (!String.IsNullOrEmpty(attribute.Alias)) { createdAttribute.Alias = attribute.Alias; } } AttributeContainerLeftOut.RemoveMeFromModel(); viewHelper = Diagram.DiagramElements[AttributeContainerLeftOut]; Diagram.RemoveModelElement(AttributeContainerLeftOut); } }
public static IList <EvolutionChange> Detect(Version v1, Version v2, PSMSuperordinateComponent superordinateComponent) { List <EvolutionChange> result = new List <EvolutionChange>(); PSMSuperordinateComponent superordinateComponentOldVersion = (PSMSuperordinateComponent)superordinateComponent.GetInVersion(v1); foreach (PSMSubordinateComponent subordinate in superordinateComponentOldVersion.Components) { /* must not exist in new version, testing whether it disappeard from components of the new * version is not enough. It could have been moved, but not deleted. */ if (subordinate.GetInVersion(v2) == null) { SuperordinateComponentRemovedChange change = new SuperordinateComponentRemovedChange(superordinateComponent) { RemovedComponent = subordinate, OldVersion = v1, NewVersion = v2 }; result.Add(change); } } return(result); }
private static int CompareByRootPositionsDesc(Element e1, Element e2) { PSMSuperordinateComponent c1 = e1 as PSMSuperordinateComponent; PSMSuperordinateComponent c2 = e2 as PSMSuperordinateComponent; if (c1 != null && c2 != null) { ObservableCollection <PSMSuperordinateComponent> roots = c1.Diagram.Roots; if (roots.Contains(c1) && roots.Contains(c2)) { return(roots.IndexOf(c1) > roots.IndexOf(c2) ? 0 : 1); } else if (roots.Contains(c1)) { return(1); } else if (roots.Contains(c2)) { return(0); } return((c1.GetHashCode() < c2.GetHashCode()) ? 0 : 1); } if (c1 != null) { return(1); } if (c2 != null) { return(0); } return((e1.GetHashCode() < e2.GetHashCode()) ? 0 : 1); }
public override Element Clone(Model targetModel, ElementCopiesMap createdCopies) { PSMSuperordinateComponent copyParent = (PSMSuperordinateComponent)createdCopies[Parent]; PSMAttributeContainer clone = (PSMAttributeContainer)PSMAttributeContainerFactory.Instance.Create(copyParent, targetModel.Schema); return(clone); }
public override void FillCopy(Element copyElement, Model targetModel, ElementCopiesMap createdCopies) { base.FillCopy(copyElement, targetModel, createdCopies); PSMAssociation copyPSMAssociation = (PSMAssociation)copyElement; copyPSMAssociation.Lower = Lower; copyPSMAssociation.Upper = Upper; //copyPSMAssociation.IsUnique = IsUnique; //copyPSMAssociation.IsOrdered = IsOrdered; copyPSMAssociation.Child = (PSMAssociationChild)createdCopies[Child]; foreach (NestingJoin nestingJoin in NestingJoins) { PIMClass coreClass; if (targetModel.Schema != this.Schema) { coreClass = (PIMClass)createdCopies[nestingJoin.CoreClass]; } else { coreClass = nestingJoin.CoreClass; } copyPSMAssociation.AddNestingJoin(coreClass); } if (Parent != null && createdCopies.ContainsKey(Parent)) { PSMSuperordinateComponent copyParent = (PSMSuperordinateComponent)createdCopies[Parent]; ((_ImplPSMSubordinateComponent)copyPSMAssociation).Parent = copyParent; copyParent.Components.Add(copyPSMAssociation); } }
public static void CheckPsmParentsAndRoots(PSMDiagram diagram) { foreach (Element element in diagram.DiagramElements.Keys) { PSMSubordinateComponent subordinateComponent = (element as PSMSubordinateComponent); if (subordinateComponent != null) { if (subordinateComponent.Parent == null && !diagram.Roots.Contains((PSMClass)subordinateComponent)) { throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent)); } if (subordinateComponent.Parent != null) { if (!subordinateComponent.Parent.Components.Contains(subordinateComponent)) { throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent)); } } } PSMSuperordinateComponent superordinateComponent = element as PSMSuperordinateComponent; if (superordinateComponent != null) { foreach (PSMSubordinateComponent component in superordinateComponent.Components) { if (component.Parent != superordinateComponent) { throw new ModelConsistencyException(string.Format("Bad superordinateComponent component {0}", superordinateComponent)); } } } } }
private void TranslateComponents(PSMSuperordinateComponent psmSuperordinateComponent, DataGeneratorContext context) { foreach (PSMSubordinateComponent component in psmSuperordinateComponent.Components) { TranslateSubordinateComponent(component, context); } }
private void TranslateComponents(PSMSuperordinateComponent psmSuperordinateComponent, ChangesDetectorContext context) { foreach (PSMSubordinateComponent psmSubordinateComponent in psmSuperordinateComponent.Components) { TranslateSubordinateComponent(psmSubordinateComponent, context); } }
static void GetDirectSubPSMClasses(List <PSMClass> OC, PSMSuperordinateComponent E) { foreach (PSMSubordinateComponent C in E.Components) { GetDirectSubPSMClasses(OC, C); } }
private void AddSuperordinateComponentDependencies(Element root, PSMSuperordinateComponent superordinateComponent) { foreach (PSMSubordinateComponent component in superordinateComponent.Components) { AddDependency(root, component); elementsToDo.Enqueue(new KeyValuePair <Element, Element>(root, component)); } }
static void GetSubElements(List <PSMElement> OC, PSMSuperordinateComponent E) { foreach (PSMSubordinateComponent C in E.Components) { GetSubElements(OC, C); } OC.Add(E); }
private static void FindACRecursive(PSMSuperordinateComponent superordinateComponent, List <PSMAttributeContainer> candidates) { candidates.AddRange(superordinateComponent.Components.OfType <PSMAttributeContainer>()); foreach (PSMSuperordinateComponent component in superordinateComponent.Components.OfType <PSMSuperordinateComponent>().Where(c => !(c is PSMClass))) { FindACRecursive(component, candidates); } }
private static void FindContainerRecursive(PSMSuperordinateComponent superordinateComponent, List <SUPERORDINATE_TYPE> candidates) { candidates.AddRange(superordinateComponent.Components.OfType <SUPERORDINATE_TYPE>()); foreach (PSMSuperordinateComponent component in superordinateComponent.Components.OfType <PSMSuperordinateComponent>().Where(c => !(c is PSMClass))) { FindContainerRecursive(component, candidates); } }
/// <summary> /// Checks if the given component is present in a tree with given root. /// The search starts in the given root and recursively continues to the /// subordinate components (associations, containers, choices, unions) and /// finally it descends through the specializations (inheritance) of the classes. /// </summary> /// <param name="root">Reference to the root of the searched subtree</param> /// <param name="item">Reference to the item being searched</param> /// <returns> /// True if the item is present in the subtree with the given root, false otherwise. /// </returns> public static bool SubtreeContains(PSMSuperordinateComponent root, object item) { if (root == item) { return(true); } foreach (PSMSubordinateComponent component in root.Components) { if (component == item) { return(true); } if (component is PSMSuperordinateComponent) { if (SubtreeContains(component as PSMSuperordinateComponent, item)) { return(true); } } else if (component is PSMAssociation) { PSMAssociation assoc = component as PSMAssociation; if (assoc.Child is PSMClass) { if (SubtreeContains(assoc.Child as PSMClass, item)) { return(true); } } if (assoc.Child is PSMClassUnion) { if (ClassUnionContains(assoc.Child as PSMClassUnion, item)) { return(true); } } } } if (root is PSMClass) { PSMClass rc = root as PSMClass; foreach (Generalization gen in rc.Specifications) { if (SubtreeContains(gen.Specific as PSMClass, item)) { return(true); } } } return(false); }
public static bool AreComponentsOfCommonParent <TYPE>(IEnumerable <TYPE> components) where TYPE : PSMSubordinateComponent { if (components.Count() == 0) { return(false); } PSMSuperordinateComponent parent = components.First().Parent; return(components.All(c => c.Parent == parent)); }
public override void FillCopy(Element copyElement, Model targetModel, ElementCopiesMap createdCopies) { base.FillCopy(copyElement, targetModel, createdCopies); PSMContentChoice copyPSMContentChoice = (PSMContentChoice)copyElement; if (Parent != null && createdCopies.ContainsKey(Parent)) { PSMSuperordinateComponent copyParent = (PSMSuperordinateComponent)createdCopies[Parent]; ((_ImplPSMSubordinateComponent)copyPSMContentChoice).Parent = (PSMSuperordinateComponent)createdCopies[Parent]; copyParent.Components.Add(copyPSMContentChoice); } }
private static void GetSpecificationsRecursive(PSMSuperordinateComponent root, ref List <PSMSuperordinateComponent> result) { result.Add(root); PSMClass psmClass = root as PSMClass; if (psmClass != null) { foreach (Generalization specification in psmClass.Specifications) { GetSpecificationsRecursive((PSMClass)specification.Specific, ref result); } } }
internal override void CommandOperation() { parent = ((PSMSubordinateComponent)Container).Parent; int index = ((PSMSubordinateComponent)Container).ComponentIndex() + 1; foreach (PSMSubordinateComponent component in movedComponents) { oldIndexes[component] = component.ComponentIndex(); Container.Components.Remove(component); parent.Components.Insert(index++, component); AssociatedElements.Add(component); } }
private static void FindCURecursive(PSMSuperordinateComponent superordinateComponent, List <PSMClassUnion> candidates) { //var a = from PSMSubordinateComponent c in superordinateComponent.Components // where c is PSMAssociation && ((PSMAssociation) c).Child is PSMClassUnion // select ((PSMAssociation) c).Child; candidates.AddRange( from PSMSubordinateComponent c in superordinateComponent.Components where c is PSMAssociation && ((PSMAssociation)c).Child is PSMClassUnion select(PSMClassUnion)((PSMAssociation)c).Child); //foreach (PSMSuperordinateComponent component in superordinateComponent.Components.OfType<PSMSuperordinateComponent>().Where(c => !(c is PSMClass))) //{ // FindCURecursive(component, candidates); //} }
public override bool CanExecute() { // Verify that the input is set bool canExecute = (Associations != null) && (Associations.Count >= 1) && GroupedClass != null; if (!canExecute) { ErrorDescription = CommandError.CMDERR_GROUP_BY_NOTSET; return(false); } // Verify that the grouped class is among the diagram roots canExecute &= GroupedClass.Diagram.Roots.Contains(GroupedClass); if (canExecute) { // Verify if all the input associations meet the requirements foreach (PSMAssociation assoc in Associations) { // Verify that the association represents only one nesting join without context // having the core class set to the association child, child path set to . and // parent path ending with the grouped class canExecute &= (assoc.NestingJoins.Count == 1) && (assoc.NestingJoins[0].Context.Count == 0) && (assoc.NestingJoins[0].CoreClass == ((PSMClass)assoc.Child).RepresentedClass) && (assoc.NestingJoins[0].Child.Steps.Count == 0) && (assoc.NestingJoins[0].Parent.Steps[assoc.NestingJoins[0].Parent.Steps.Count - 1].End == GroupedClass.RepresentedClass); if (!canExecute) { ErrorDescription = String.Format(CommandError.CMDERR_GROUP_BY_ALREADYGROUPED, assoc.Child.Name); break; } // Verify that the association goes directly or indirectly from the grouped class. PSMSuperordinateComponent parent = assoc.Parent; while (!(parent is PSMClass)) { parent = ((PSMSubordinateComponent)parent).Parent; } canExecute &= (parent == GroupedClass); } } else { ErrorDescription = CommandError.CMDERR_GROUP_BY_NOTROOT; } return(canExecute); }
/// <summary> /// Adds all the PSM attributes from the attribute containers subordinate /// to root to the attributes list. /// </summary> /// <param name="attributes">List that will receive the attributes</param> /// <param name="root">Reference to the root of the searched tree</param> protected void AddAllAttributes(List <PSMAttribute> attributes, PSMSuperordinateComponent root) { foreach (PSMSubordinateComponent component in root.Components) { if (component is PSMAttributeContainer) { attributes.AddRange((component as PSMAttributeContainer).PSMAttributes); } else if ((component is PSMContentContainer) || (component is PSMContentChoice)) { AddAllAttributes(attributes, component as PSMSuperordinateComponent); } } }
public static Element GetRightSiblingOfElement(Element element) { PSMSubordinateComponent subordinateComponent = element as PSMSubordinateComponent; if (subordinateComponent != null) { PSMSuperordinateComponent parent = subordinateComponent.Parent; if (parent != null) { ObservableCollection <PSMSubordinateComponent> components = parent.Components; if (components.IndexOf(subordinateComponent) < components.Count - 1) { return(components[components.IndexOf(subordinateComponent) + 1]); } else if (parent is PSMClass) { PSMClass parentClass = parent as PSMClass; if (parentClass.Specifications.Count > 0) { return(parentClass.Specifications.First()); } } } } Generalization generalization = element as Generalization; if (generalization != null) { IList <Generalization> specifications = generalization.General.Specifications; if (specifications.IndexOf(generalization) != specifications.Count - 1) { return(specifications[specifications.IndexOf(generalization) + 1]); } } PSMClass psmClass = element as PSMClass; if (psmClass != null && psmClass.ParentUnion != null) { ObservableCollection <PSMAssociationChild> components = psmClass.ParentUnion.Components; if (components.IndexOf(psmClass) < components.Count - 1) { return(components[components.IndexOf(psmClass) + 1]); } } return(null); }
/// <summary> /// Creates new instance of <see cref="PSM_ComponentsManager" />. /// </summary> /// <param name="xCaseCanvas">canvas of the PSM diagram</param> /// <param name="superordinateElement">element whose components are visualized by the created PSM_ComponentsManager</param> /// <param name="superordinateRepresentation">representation of <paramref name="superordinateElement"/> on <paramref name="xCaseCanvas"/></param> public PSM_ComponentsManager(XCaseCanvas xCaseCanvas, PSMSuperordinateComponent superordinateElement, XCaseViewBase superordinateRepresentation) { if (!(xCaseCanvas.Diagram is PSMDiagram)) { throw new ArgumentException("Component manager can be put only on canvas representing PSM diagram. ", "xCaseCanvas"); } XCaseCanavs = xCaseCanvas; SuperordinateElement = superordinateElement; SuperordinateRepresentation = superordinateRepresentation; ComponentsData = new Dictionary <PSMSubordinateComponent, ComponentData>(); SuperordinateElement.Components.CollectionChanged += Components_CollectionChanged; }
/// <summary> /// Checks whether <paramref name="items"/> are all children of a common parent, that is a <see cref="PSMSuperordinateComponent"/> and all /// items are <see cref="PSMSubordinateComponent"/>s. /// </summary> /// <param name="items">list of selectable items</param> /// <param name="parent">common parent for <paramref name="items"/> (if found)</param> /// <param name="components"><see cref="PSMSubordinateComponent"/>s that are represented by <paramref name="items"/></param> /// <returns>true if <paramref name="items"/> are all components of a common parent, false otherwise</returns> public static bool AreComponentsOfCommonParent(IEnumerable<IModelElementRepresentant> items, out PSMSuperordinateComponent parent, out IList<PSMSubordinateComponent> components) { parent = null; List<PSMSubordinateComponent> result = new List<PSMSubordinateComponent>(); components = null; foreach (IModelElementRepresentant item in items) { if (!(item is IPSMSubordinateComponentRepresentant) && !(item is Controls.PSM_Class)) { return false; } else { PSMSubordinateComponent component = null; if (item is Controls.PSM_Class) { PSMAssociationChild associationChild = (item as Controls.PSM_Class).ClassController.Class; if (associationChild != null && associationChild.ParentAssociation != null) component = associationChild.ParentAssociation; } else { component = ((IPSMSubordinateComponentRepresentant)item).ModelSubordinateComponent; } if (component == null) { return false; } PSMSuperordinateComponent itemParent = component.Parent; if (parent == null) parent = itemParent; else { if (parent != itemParent) { return false; } } if (!result.Contains(component)) result.Add(component); } } components = result; return true; }
/// <summary> /// Gets all PSMClass siblings of <paramref name="C"/> (skipping other components of the PSM Diagram) /// </summary> /// <param name="C">The PSMClass to get the siblings of</param> /// <returns>List of PSMClass siblings</returns> public static List <PSMClass> GetAllPSMClassSiblings(this PSMClass C) { if (C.ParentAssociation == null) { return(new List <PSMClass>()); } PSMSuperordinateComponent parent = C.ParentAssociation.Parent; while (!(parent is PSMClass)) { parent = (parent as PSMSubordinateComponent).Parent; } List <PSMClass> Siblings = parent.GetDirectPSMSubClasses(); Siblings.Remove(C); return(Siblings); }
/// <summary> /// Gets all following PSMClass siblings of <paramref name="C"/> (skipping other components of the PSM Diagram) /// </summary> /// <param name="C">The PSMClass to get the following siblings of</param> /// <returns>List of following PSMClass siblings</returns> public static List <PSMClass> GetAllPSMClassFollowingSiblings(this PSMClass C) { if (C.ParentAssociation == null) { return(new List <PSMClass>()); } PSMSuperordinateComponent parent = C.ParentAssociation.Parent; while (!(parent is PSMClass)) { parent = (parent as PSMSubordinateComponent).Parent; } List <PSMClass> Siblings = parent.GetDirectPSMSubClasses(); int idx = Siblings.IndexOf(C); List <PSMClass> FollowingSiblings = Siblings.Where <PSMClass>(S => Siblings.IndexOf(S) > idx).ToList <PSMClass>(); return(FollowingSiblings); }