private void SelectNotRequiredSubtrees() { PSMDiagram psmDiagram = ((PSMDiagram)Diagram); List <PSMClass> startClasses = SelectedItems.OfType <IModelElementRepresentant>().Select( r => ElementRepresentations.GetElementRepresentedBy(r)).OfType <PSMClass>().Where( r => psmDiagram.Roots.Contains(r)).ToList(); List <PSMClass> visitedClasses = new List <PSMClass>(startClasses); Queue <Element> queue = new Queue <Element>(startClasses); while (!queue.IsEmpty()) { Element element = queue.Dequeue(); PSMClass psmClass = element as PSMClass; if (psmClass != null) { visitedClasses.Add(psmClass); // new subtree added when structural representative found. if (psmClass.IsStructuralRepresentative && !psmClass.IsStructuralRepresentativeExternal) { queue.Enqueue(psmClass.RepresentedPSMClass); } } foreach (Element child in PSMTree.GetChildrenOfElement(element)) { queue.Enqueue(child); } } IEnumerable <IModelElementRepresentant> representants = psmDiagram.Roots.Where(r => !visitedClasses.Contains(r)).Select(element => ElementRepresentations[element]); SelectedItems.SetSelection(representants); }
internal override void CommandOperation() { IList <Element> _deleted; // try to order elements if (PSMTree.ReturnElementsInPSMOrder(DeletedElements, out _deleted, true)) { safeOrdering = true; _deletionOrder = _deleted.Reverse(); } else { // this will forbid undo safeOrdering = false; _deletionOrder = DeletedElements; } foreach (Element element in _deletionOrder) { if (DeletedElements.Contains(element)) { DeletedElementsViewHelpers[element] = Diagram.DiagramElements[element]; element.RemoveMeFromModel(); Diagram.RemoveModelElement(element); } //AssociatedElements.Add(element); } }
/// <summary> /// Executive function of a command /// </summary> /// <seealso cref="UndoOperation"/> internal override void CommandOperation() { DiagramClone = Diagram.Clone(); if (Diagram is PIMDiagram) { Dictionary <Element, ViewHelper> viewHelperCopies = new Dictionary <Element, ViewHelper>(); /* Elements in PIM diagram are loaded in the order of their LoadPriority in registration set */ foreach (Type ModelElementType in PIMElementsOrder) { foreach (KeyValuePair <Element, ViewHelper> pair in Diagram.DiagramElements) { Element element = pair.Key; ViewHelper viewHelper = pair.Value; if (!viewHelperCopies.ContainsKey(element) && ModelElementType.IsInstanceOfType(element)) { ViewHelper copiedViewHelper = viewHelper.CreateCopy(DiagramClone, null); viewHelperCopies.Add(element, copiedViewHelper); } } } Diagram.FillCopy(DiagramClone, Controller.Model, null, viewHelperCopies); } else { IList <Element> ordered; // order PSMTree.ReturnElementsInPSMOrder(((PSMDiagram)Diagram).Roots.Cast <Element>(), out ordered, true); // clone the selection ElementCopiesMap createdCopies = new ElementCopiesMap(); foreach (Element element in ordered) { Element copy = element.CreateCopy(Controller.Model, createdCopies); createdCopies[element] = copy; } // representants must be handled separately after all copies are created PSMTree.CopyRepresentantsRelations(createdCopies); // clone viewhelpers Dictionary <Element, ViewHelper> createdViewHelpers = new Dictionary <Element, ViewHelper>(); foreach (Element element in ordered) { ViewHelper viewHelper = Diagram.DiagramElements[element]; ViewHelper copiedViewHelper = viewHelper.CreateCopy(DiagramClone, createdCopies); createdViewHelpers.Add(element, copiedViewHelper); } Diagram.FillCopy(DiagramClone, Controller.Model, createdCopies, createdViewHelpers); } DiagramClone.Caption += " (copy)"; Controller.Project.AddDiagram(DiagramClone); }
public void BindToDiagram(Diagram diagram, ModelController modelController) { PropertyPath propertyPath = new PropertyPath("Caption"); Binding titleBinding = new Binding { Source = diagram, Path = propertyPath }; SetBinding(TitleProperty, titleBinding); // bound view to controller and controller to model DiagramController = new DiagramController(diagram, modelController); ModelController = modelController; xCaseDrawComponent.Canvas.Controller = DiagramController; try { Mouse.SetCursor(Cursors.Wait); #region load items on the diagram List <Element> alreadyProcessed = new List <Element>(); RegistrationSet registrationSet; if (diagram is PIMDiagram) { registrationSet = MainWindow.PIMRepresentantsSet; /* Elements in PIM diagram are loaded in the order of their LoadPriority in registration set */ foreach (RepresentantRegistration registration in registrationSet.OrderBy(reg => reg.LoadPriority)) { foreach (KeyValuePair <Element, ViewHelper> pair in diagram.DiagramElements) { if (!alreadyProcessed.Contains(pair.Key) && registration.ModelElementType.IsInstanceOfType(pair.Key)) { diagram.NotifyElementAdded(this, pair.Key, pair.Value); alreadyProcessed.Add(pair.Key); } } } } else { /* order of the elements in PSM diagram is more complex, an ordering function * is called to order the elements (basically BFS) */ TreeLayout.SwitchOff(); IList <Element> ordered; if (PSMTree.ReturnElementsInPSMOrder(((PSMDiagram)diagram).Roots, out ordered, true)) { foreach (Element element in ordered) { diagram.NotifyElementAdded(this, element, diagram.DiagramElements[element]); } foreach (Comment comment in diagram.DiagramElements.Keys.OfType <Comment>()) { diagram.NotifyElementAdded(this, comment, diagram.DiagramElements[comment]); } foreach (PSMDiagramReference psmDiagramReference in diagram.DiagramElements.Keys.OfType <PSMDiagramReference>()) { diagram.NotifyElementAdded(this, psmDiagramReference, diagram.DiagramElements[psmDiagramReference]); } } xCaseDrawComponent.Canvas.Loaded += Canvas_Loaded; } #endregion } finally { Mouse.SetCursor(Cursors.Arrow); } }
public bool SubtreeContains(object Object) { return(PSMTree.SubtreeContains(this, Object)); }
protected override Element GetRelatedElement(Element element) { return(PSMTree.GetFirstChildOfElement(element)); }
protected override Element GetRelatedElement(Element element) { return(PSMTree.GetRightSiblingOfElement(element)); }
protected override Element GetRelatedElement(Element element) { return(PSMTree.GetParentOfElement(element)); }
public void InitializeCommand(IEnumerable <PSMAssociation> associations, PSMClassUnion container) { if (associations.Count() == 0) { return; } if (container == null) { PSMSuperordinateComponent parentClass; if (!PSMTree.AreComponentsOfCommonParent(associations)) { return; } parentClass = associations.First().Parent; List <PSMClassUnion> candidates = new List <PSMClassUnion>(); FindCURecursive(parentClass, candidates); bool createNew = false; SelectItemsDialog d = new SelectItemsDialog(); d.Title = "Select class union"; d.ShortMessage = "Select class union"; d.LongMessage = String.Empty; d.UseRadioButtons = true; ArrayList _c = new ArrayList(candidates.ToList()); const string _newAC = "<< new class union >>"; _c.Add(_newAC); d.SetItems(_c); if (d.ShowDialog() == true) { if (d.selectedObjects.FirstOrDefault().Equals(_newAC)) { createNew = true; } else { ClassUnion = d.selectedObjects.FirstOrDefault() as PSMClassUnion; } } if (createNew) { JoinAssociationsToClassUnionMacroCommand createCUcommand = (JoinAssociationsToClassUnionMacroCommand) JoinAssociationsToClassUnionMacroCommandFactory.Factory().Create(Controller); createCUcommand.Set(parentClass, associations); Commands.Add(createCUcommand); return; } } else { ClassUnion = container; } if (ClassUnion != null) { MoveClassToExistingClassUnionMacroCommand moveCommand = (MoveClassToExistingClassUnionMacroCommand) MoveClassToExistingClassUnionMacroCommandFactory.Factory().Create(Controller); moveCommand.Set(ClassUnion, associations); Commands.Add(moveCommand); } }
public override bool CanExecute() { return(ClassUnion.ParentAssociation != null && AddedAssociations.Count > 0 && PSMTree.AreComponentsOfCommonParent(AddedAssociations)); }
public static void PasteContentToDiagram(XCaseCanvas targetDiagram, RegistrationSet registrationSet) { if (targetDiagram == null) { return; } if (State == EState.ContainsPIM) { List <Element> alreadyProcessed = new List <Element>(); Dictionary <Element, ViewHelper> createdCopies = new Dictionary <Element, ViewHelper>(); IncludeElementsCommand includeElementsCommand = (IncludeElementsCommand)IncludeElementsCommandFactory.Factory().Create(targetDiagram.Controller); /* Elements in PIM diagram are loaded in the order of their LoadPriority in registration set */ foreach (RepresentantRegistration registration in registrationSet.OrderBy(reg => reg.LoadPriority)) { foreach (KeyValuePair <Element, ViewHelper> pair in content) { Element element = pair.Key; ViewHelper viewHelper = pair.Value; if (!alreadyProcessed.Contains(element) && registration.ModelElementType.IsInstanceOfType(element)) { if (!targetDiagram.Diagram.IsElementPresent(element) && element.CanBePutToDiagram(targetDiagram.Diagram, includeElementsCommand.IncludedElements.Keys)) { ViewHelper copiedViewHelper = viewHelper.CreateCopy(targetDiagram.Diagram, null); createdCopies.Add(element, copiedViewHelper); includeElementsCommand.IncludedElements.Add(element, copiedViewHelper); } alreadyProcessed.Add(element); } } } includeElementsCommand.Execute(); } else if (State == EState.ContainsPSM) { IList <Element> ordered; PSMDiagram sourceDiagram = (PSMDiagram)content.First().Value.Diagram; if (!content.Keys.All(element => sourceDiagram.DiagramElements.Keys.Contains(element))) { throw new XCaseException("Cannot paste content. Source diagram was modified.") { ExceptionTitle = "Cannot paste content." }; } // identify tree roots IEnumerable <Element> roots = PSMTree.IdentifySubtreeRoots(content.Keys); List <AddPSMClassToRootsCommand> addToRootsCommands = new List <AddPSMClassToRootsCommand>(); // order PSMTree.ReturnElementsInPSMOrder(content.Keys.Union(roots), out ordered, false); IncludeElementsCommand includeElementsCommand = (IncludeElementsCommand)IncludeElementsCommandFactory.Factory().Create(targetDiagram.Controller); // clone the selection ElementCopiesMap createdCopies = new ElementCopiesMap(); foreach (Element element in ordered) { Element copy = element.CreateCopy(targetDiagram.Controller.ModelController.Model, createdCopies); createdCopies[element] = copy; } // representants must be handled separately after all copies are created PSMTree.CopyRepresentantsRelations(createdCopies); foreach (Element root in roots) { PSMClass _root = createdCopies[root] as PSMClass; if (_root != null) { AddPSMClassToRootsCommand command = (AddPSMClassToRootsCommand)AddPSMClassToRootsCommandFactory.Factory().Create(targetDiagram.Controller); command.Set(new ElementHolder <PSMClass>(_root)); addToRootsCommands.Add(command); } } // clone viewhelpers Dictionary <Element, ViewHelper> createdViewHelpers = new Dictionary <Element, ViewHelper>(); foreach (Element element in ordered) { ViewHelper viewHelper = sourceDiagram.DiagramElements[element]; ViewHelper copiedViewHelper = viewHelper.CreateCopy(targetDiagram.Diagram, createdCopies); createdViewHelpers.Add(element, copiedViewHelper); includeElementsCommand.IncludedElements.Add(createdCopies[element], copiedViewHelper); } IMacroCommand macro = targetDiagram.Controller.BeginMacro(); macro.CheckFirstOnlyInCanExecute = true; // put to diagram includeElementsCommand.Execute(); // new roots foreach (AddPSMClassToRootsCommand command in addToRootsCommands) { command.Execute(); } targetDiagram.Controller.CommitMacro(); #if DEBUG Tests.ModelIntegrity.ModelConsistency.CheckEverything(targetDiagram.Controller.ModelController.Project); #endif } }