/// <summary> /// Draws given root element and all its children and counts width of its subtree. /// </summary> /// <param name="diagram">Diagram to be layouted</param> /// <param name="root">Root element of layouted subtree</param> /// <param name="top">Location of the upper border of the root</param> /// <param name="left">Location of the left border of the entire subtree</param> /// <returns>Width of the subtree (root included)</returns> private static double DrawTree(XCaseCanvas diagram, NamedElement root, double top, double left) { if (!diagram.ElementRepresentations.IsElementPresent(root)) { return(-horizontalSpace); } XCaseViewBase element = (diagram.ElementRepresentations[root] as XCaseViewBase); double height = element.ActualHeight; double width = element.ActualWidth; double right = left + TreeLayout.DrawSubtree(diagram, root, top + height + verticalSpace, left); if (right == left) { right = left + width; } else { if (right < left + width) { double subtreeWidth = right - left; TreeLayout.DrawSubtree(diagram, root, top + height + verticalSpace, left + (width - subtreeWidth) / 2); right = left + width; } } element.X = Math.Round((right + left) / 2 - width / 2); element.ViewHelper.X = element.X; element.Y = Math.Round(top); element.ViewHelper.Y = element.Y; return(right - left); }
static void dragData_DragCompleted(object sender, MouseButtonEventArgs e) { DragButtonData dragData = (DragButtonData)sender; PIM_Class draggedClass = ((PIM_Class)dragData.DraggedObject); XCaseCanvas ActiveDiagramView = draggedClass.XCaseCanvas; dragData.DraggedObject.Visibility = Visibility.Hidden; ActiveDiagramView.Children.Remove(dragData.DraggedObject); ActiveDiagramView.State = ECanvasState.Normal; if (draggedClass.Left > 0 && draggedClass.Top > 0) { if (ActiveDiagramView.Diagram is PIMDiagram) { ElementToDiagramCommand <Class, ClassViewHelper> command = (ElementToDiagramCommand <Class, ClassViewHelper>)dragData.CommandFactory.Create(ActiveDiagramView.Controller); command.ViewHelper.X = draggedClass.Left; command.ViewHelper.Y = draggedClass.Top; command.IncludedElement = new ElementHolder <Class> { Element = (Class)draggedClass.ModelElement }; command.Execute(); } else if (ActiveDiagramView.Diagram is PSMDiagram) { DerivePSMClassToDiagramCommand c = (DerivePSMClassToDiagramCommand)DerivePSMClassToDiagramCommandFactory.Factory().Create(ActiveDiagramView.Controller.ModelController); c.Set(draggedClass.ClassController.Class, (PSMDiagram)ActiveDiagramView.Diagram); if (c.CanExecute()) { c.Execute(); } } } }
private void OnActiveDiagramChanged(PanelWindow panelWindow) { if (panelWindow != null) { Project diagramProject = panelWindow.xCaseDrawComponent.Canvas.Diagram.Project; if (diagramProject != CurrentProject) { CurrentProject = diagramProject; } } if (panelWindow != null && panelWindow.xCaseDrawComponent.Canvas.Diagram != null) { //if (panelWindow.xCaseDrawComponent.Canvas.Diagram is PSMDiagram) // View.TreeLayout.SwitchOff(); ActiveDiagram = panelWindow.xCaseDrawComponent.Canvas; Debug.WriteLine("ActiveDiagramChanged (" + ActiveDiagram.Diagram.Caption + ")"); } else { ActiveDiagram = null; Debug.WriteLine("ActiveDiagramChanged (null)"); } navigatorWindow.ActiveDiagram = ActiveDiagram; propertiesWindow.ActiveDiagram = ActiveDiagram; InvokeDiagramSelectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); UIElement[] pimMenus = new UIElement[] { PIMmenu, AlignmentMenu, PIMDeleteMenu, DeriveMenu }; UIElement[] psmMenus = new UIElement[] { PSMmenuClass, PSMmenuElements, OrderingMenu, PSMDeleteMenu, bXMLSchema, bSampleDocument, ReverseMenu }; bool showPIMMenus = ActiveDiagram != null && ActiveDiagram.Diagram != null && ActiveDiagram.Diagram is PIMDiagram; bool showPSMMenus = ActiveDiagram != null && ActiveDiagram.Diagram != null && ActiveDiagram.Diagram is PSMDiagram; foreach (UIElement menu in pimMenus) { menu.Visibility = showPIMMenus ? Visibility.Visible : Visibility.Collapsed; } foreach (UIElement menu in psmMenus) { menu.Visibility = showPSMMenus ? Visibility.Visible : Visibility.Collapsed; } if (ActiveDiagram != null) { ActiveDiagram.SelectedItems.CollectionChanged += navigatorWindow.SelectedItems_CollectionChanged; } // I am hiding the reverse menu in release versions for now #if DEBUG #else ReverseMenu.Visibility = Visibility.Collapsed; #endif }
/// <summary> /// /// </summary> /// <param name="xCaseCanvas"></param> /// <param name="element"></param> /// <param name="controller"></param> /// <returns></returns> public IModelElementRepresentant CreateRepresentant(XCaseCanvas xCaseCanvas, Element element, out ElementController controller) { RepresentantRegistration?registration = TrySearchRepresentantType(element); if (registration == null) { throw new InvalidOperationException(string.Format("Cannot represent elements of type {0}", element)); } controller = (ElementController)Activator.CreateInstance(registration.Value.ControllerType, element, xCaseCanvas.Controller); return((IModelElementRepresentant)Activator.CreateInstance(registration.Value.RepresentantType, xCaseCanvas)); }
public static void PutToClipboard(XCaseCanvas diagram) { if (diagram == null) { return; } Clear(); if (diagram.SelectedRepresentants.Count() > 0) { State = diagram.Diagram is PSMDiagram ? EState.ContainsPSM : EState.ContainsPIM; foreach (IModelElementRepresentant elementRepresentant in diagram.SelectedRepresentants) { Element element = diagram.ElementRepresentations.GetElementRepresentedBy(elementRepresentant); content.Add(element, diagram.Diagram.DiagramElements[element]); } } }
/// <summary> /// Completely performs layouting of a PSM diagram. /// </summary> /// <param name="canvas">The diagram (resp. canvas) to be layouted.</param> public static void LayoutDiagram(XCaseCanvas canvas) { if (active) { PSMDiagram diagram = canvas.Diagram as PSMDiagram; if (diagram != null) { Debug.WriteLine("Layouting..."); double left = TreeLayout.horizontalSpace; foreach (PSMSuperordinateComponent aClass in diagram.Roots) { left += TreeLayout.DrawTree(canvas, aClass, TreeLayout.verticalSpace / 2, left) + TreeLayout.horizontalSpace; } foreach (PSMDiagramReference reference in diagram.DiagramReferences) { left += TreeLayout.DrawTree(canvas, reference, TreeLayout.verticalSpace / 2, left) + TreeLayout.horizontalSpace; } } } }
public override bool CanExecute(object parameter) { if (MainWindow.ActiveDiagram != null && MainWindow.ActiveDiagram.SelectedItems.Count == 1 && MainWindow.CurrentProject.VersionManager != null) { ISelectable i = MainWindow.ActiveDiagram.SelectedItems[0]; if (i is IModelElementRepresentant) { Element e = MainWindow.ActiveDiagram.ElementRepresentations.GetElementRepresentedBy( (IModelElementRepresentant)i); Version v; Version newerVersion = MainWindow.ActiveDiagram.Diagram.Project.VersionManager.Versions[1]; Version olderVersion = MainWindow.ActiveDiagram.Diagram.Project.VersionManager.Versions[0]; if (e.Version == newerVersion) { v = olderVersion; } else { v = newerVersion; } XCaseCanvas xCaseCanvas = MainWindow.DiagramTabManager.GetDiagramView( (Diagram)MainWindow.ActiveDiagram.Diagram.GetInVersion(v)); if (xCaseCanvas.SelectedItems.Count == 1) { ISelectable i2 = xCaseCanvas.SelectedItems[0]; if (i2 is IModelElementRepresentant) { return(true); } } } } return(false); }
public override void Execute(object parameter) { if (CanExecute(parameter)) { ISelectable i = MainWindow.ActiveDiagram.SelectedItems[0]; if (i is IModelElementRepresentant) { Element e = MainWindow.ActiveDiagram.ElementRepresentations.GetElementRepresentedBy((IModelElementRepresentant)i); Version v; Version newerVersion = MainWindow.ActiveDiagram.Diagram.Project.VersionManager.Versions[1]; Version olderVersion = MainWindow.ActiveDiagram.Diagram.Project.VersionManager.Versions[0]; if (e.Version == newerVersion) { v = olderVersion; } else { v = newerVersion; } XCaseCanvas xCaseCanvas = MainWindow.DiagramTabManager.GetDiagramView((Diagram)MainWindow.ActiveDiagram.Diagram.GetInVersion(v)); if (xCaseCanvas.SelectedItems.Count == 1) { ISelectable i2 = xCaseCanvas.SelectedItems[0]; if (i2 is IModelElementRepresentant) { Element e2 = xCaseCanvas.ElementRepresentations.GetElementRepresentedBy((IModelElementRepresentant)i2); Element source = e.Version == olderVersion ? e : e2; Element branch = e.Version == newerVersion ? e : e2; MainWindow.CurrentProject.VersionManager.RegisterBranch(source, branch, newerVersion, true, olderVersion); } } } } }
public static void Executed(object sender, ExecutedRoutedEventArgs e) { PIMClass modelClass = (PIMClass)(((StackPanel)((Button)e.OriginalSource).Parent).DataContext); XCaseCanvas ActiveDiagramView = ((MainWindow)sender).ActiveDiagram; if (ActiveDiagramView != null && !ActiveDiagramView.ElementRepresentations.IsElementPresent(modelClass) && !(modelClass is AssociationClass)) { ActiveDiagramView.State = ECanvasState.DraggingElement; PIM_Class draggedObject = new PIM_Class(ActiveDiagramView); draggedObject.InitializeRepresentant(modelClass, new ClassViewHelper(ActiveDiagramView.Diagram), new ClassController(modelClass, ActiveDiagramView.Controller)); DragButtonData dragData = new DragButtonData(ElementToDiagramCommandFactory <Class, ClassViewHelper> .Factory(), draggedObject); dragData.DragCompleted += dragData_DragCompleted; DragButtonData classButtonData = dragData; classButtonData.AssociateWithControl((Button)e.OriginalSource); ActiveDiagramView.draggingElementState.DragData = classButtonData; classButtonData.DraggedObject.Visibility = Visibility.Hidden; classButtonData.Sender = (Button)e.OriginalSource; ActiveDiagramView.CaptureMouse(); } }
//public void DrawPSMExample(int x, int y) //{ // PIM_Class clPurchase, clCustomer1, clCustomer2, clShop, // clDealer, clItem, clAddress, clProduct, clRegion; // XCaseAttributeContainer acCustomer1, acCustomer2, // acAddress, acRegion, acProduct, acItem; // XCaseAssociationChoice asc1, asc2; // XCaseAssociationContainer ascoItems; // List<string> prPurchase = new List<string>() { "date" }, // prShop = new List<string>() { "shop-number" }, // prDealer = new List<string>() { "dealer-number" }, // prProduct = new List<string>() { "product-number" }, // atCustomer1 = new List<string>() { "customer-number" }, // atCustomer2 = new List<string>() { "name", "email" }, // atAddress = new List<string>() { "street", "postcode", "city" }, // atRegion = new List<string>() { "name AS region" }, // atProduct = new List<string>() { "unit-price", "title" }, // atItem = new List<string>() { "amount" }; // clPurchase = AddClass("Purchase", null, "purchase", prPurchase, null, 364 + x, 65 + y); // clCustomer1 = AddClass("Customer", null, null, null, null, 51 + x, 256 + y); // clCustomer2 = AddClass("Customer", null, "new-customer", null, null, 172 + x, 239 + y); // clShop = AddClass("Shop", null, "from-shop", prShop, null, 309 + x, 254 + y); // clDealer = AddClass("Dealer", null, "from-dealer", prDealer, null, 430 + x, 229 + y); // clItem = AddClass("Item", null, "item", null, null, 561 + x, 273 + y); // clAddress = AddClass("Address", null, "delivery-address", null, null, 262 + x, 352 + y); // clProduct = AddClass("Product", null, null, prProduct, null, 443 + x, 379 + y); // clRegion = AddClass("Region", null, null, null, null, 344 + x, 460 + y); // acCustomer1 = AddAttributeContainer(atCustomer1, 36 + x, 320 + y); // acCustomer2 = AddAttributeContainer(atCustomer2, 153 + x, 332 + y); // acAddress = AddAttributeContainer(atAddress, 193 + x, 434 + y); // acRegion = AddAttributeContainer(atRegion, 353 + x, 515 + y); // acProduct = AddAttributeContainer(atProduct, 468 + x, 455 + y); // acItem = AddAttributeContainer(atItem, 586 + x, 364 + y); // ascoItems = AddAssociationContainer("items", 532 + x, 147 + y); // asc1 = AddAssociationChoice(150 + x, 150 + y); // asc2 = AddAssociationChoice(395 + x, 150 + y); // AddAssociation(clPurchase, asc1); // AddAssociation(asc1, clCustomer1, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "buyer", "0..*", "1"); // AddAssociation(asc1, clCustomer2, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "buyer", "0..*", "1"); // AddAssociation(clCustomer1, acCustomer1); // AddAssociation(clCustomer2, acCustomer2); // AddAssociation(clCustomer2, clAddress, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "deliver to", "0..1", "0..1"); // AddAssociation(clAddress, acAddress); // AddAssociation(clAddress, clRegion, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "in", "0..*", "1"); // AddAssociation(clRegion, acRegion); // AddAssociation(clPurchase, asc2); // AddAssociation(asc2, clShop, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "from shop", "0..*", "1"); // AddAssociation(asc2, clDealer, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "from dealer", "0..*", "1"); // AddAssociation(clPurchase, ascoItems); // AddAssociation(ascoItems, clItem, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "<<ordered>>\ncontained in", "1", "1..*"); // AddAssociation(clItem, clProduct, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "purchases", "0..*", "1"); // AddAssociation(clProduct, acProduct); // AddAssociation(clItem, acItem); //} #endregion public void DrawPIMPSMExample() { // prepare simple PIM diagram to start with RepresentationCollection ModelViewMap = xCaseDrawComponent.Canvas.ElementRepresentations; CreationResult <Class, ClassViewHelper> classCreationResult = DiagramController.NewClass("Region", 100, 10); Class clRegion = classCreationResult.ModelElement; PIM_Class clRegionView = (PIM_Class)ModelViewMap[clRegion]; classCreationResult = DiagramController.NewClass("Address", 35, 189); Class clAddress = classCreationResult.ModelElement; PIM_Class clAddressView = (PIM_Class)ModelViewMap[classCreationResult.ModelElement]; Dictionary <PIM_Class, List <string> > properties = new Dictionary <PIM_Class, List <string> >(); properties[clRegionView] = new List <string> { "name", "code" }; properties[clAddressView] = new List <string> { "street", "postcode", "city" }; foreach (KeyValuePair <PIM_Class, List <string> > keyValuePair in properties) { foreach (string attribute in keyValuePair.Value) { keyValuePair.Key.ClassController.AddNewAttribute(attribute); } } CreationResult <Association, AssociationViewHelper> associationCreationResult = DiagramController.NewAssociation("in", (Class)clRegionView.ModelElement, (Class)clAddressView.ModelElement); PIM_Association aRegionAdress = (PIM_Association)ModelViewMap[associationCreationResult.ModelElement]; aRegionAdress.Controller.ChangeMultiplicity(aRegionAdress.Ends[0], "1"); aRegionAdress.Controller.ChangeMultiplicity(aRegionAdress.Ends[1], "0..*"); // derive PSM diagram PSMClass psmRegion = clRegionView.ClassController.DerivePSMClassToNewDiagram(); PanelWindow p = (PanelWindow)Manager.Documents.Last(); XCaseCanvas psmDiagramView = p.xCaseDrawComponent.Canvas; //ManageAttributesMacroCommand c = (ManageAttributesMacroCommand)ManageAttributesMacroCommandFactory.Factory().Create(psmDiagramView.Controller); PSM_Class psmRegionView = (PSM_Class)psmDiagramView.ElementRepresentations[psmRegion]; //((PSM_ClassController)psmRegionView.Controller).IncludeAttributes(new Dictionary<Property, string> { {clRegion.Attributes[0], "RegionName"}, {clRegion.Attributes[1], "RegionCode"} }); ViewController.MoveElement(200, 20, psmRegionView.ViewHelper, DiagramController); // add an attribute container NewPSMAttributeContainerCommand attrib = (NewPSMAttributeContainerCommand)NewPSMAttributeContainerCommandFactory.Factory().Create(psmDiagramView.Controller); attrib.PSMAttributes.Add(psmRegion.PSMAttributes[0]); attrib.PSMClass = psmRegion; attrib.ViewHelper = new PSMElementViewHelper(Diagram) { X = 100, Y = 100 }; attrib.Execute(); NewPSMAttributeContainerCommand attrib2 = (NewPSMAttributeContainerCommand)NewPSMAttributeContainerCommandFactory.Factory().Create(psmDiagramView.Controller); attrib2.PSMAttributes.Add(psmRegion.PSMAttributes[0]); attrib2.PSMClass = psmRegion; attrib2.ViewHelper = new PSMElementViewHelper(Diagram) { X = 280, Y = 100 }; attrib2.Execute(); AddPSMChildrenMacroCommand command = (AddPSMChildrenMacroCommand)AddPSMChildrenMacroCommandFactory.Factory().Create(psmDiagramView.Controller); command.Set(psmRegion); command.Execute(); }
/// <summary> /// Creates new instance of <see cref="PSMAttributesContainer" />. /// </summary> /// <param name="container">Panel used to display the items</param> /// <param name="xCaseCanvas">canvas owning the control</param> public PSMAttributesContainer(Panel container, XCaseCanvas xCaseCanvas) : base(container, xCaseCanvas) { }
public static CommandBase CreateMoveCommand(IEnumerable <IAlignable> affectedObjects, EAlignment alignment, XCaseCanvas diagramView) { MacroCommand <DiagramController> moveMacroCommand = MacroCommandFactory <DiagramController> .Factory().Create(diagramView.Controller); List <Point> aidsPointsForDiagram = VisualAidsAdorner.GetVisualAidsPointsForDiagram(diagramView, ignoredTypes); double minTop, nextTop; double maxBottom, nextBottom; double minLeft, nextLeft; double maxRight, nextRight; double delta; switch (alignment) { case EAlignment.Top: minTop = affectedObjects.Min(item => item.Top); if (minTop > 0) { nextTop = aidsPointsForDiagram.Where(point => point.Y < minTop).Max(point => point.Y); delta = nextTop - minTop; foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(null, element.Top + delta, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } } break; case EAlignment.Bottom: maxBottom = affectedObjects.Max(item => item.Bottom); IEnumerable <Point> candidatesBottom = aidsPointsForDiagram.Where(point => point.Y > maxBottom); if (candidatesBottom.Count() > 0) { nextBottom = candidatesBottom.Min(point => point.Y); delta = nextBottom - maxBottom; foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(null, element.Top + delta, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } } break; case EAlignment.Left: minLeft = affectedObjects.Min(item => item.Left); if (minLeft > 0) { nextLeft = aidsPointsForDiagram.Where(point => point.X < minLeft).Max(point => point.X); delta = nextLeft - minLeft; foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(element.Left + delta, null, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } } break; case EAlignment.Right: maxRight = affectedObjects.Max(item => item.Right); IEnumerable <Point> candidatesRight = aidsPointsForDiagram.Where(point => point.X > maxRight); if (candidatesRight.Count() > 0) { nextRight = candidatesRight.Min(point => point.X); delta = nextRight - maxRight; foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(element.Left + delta, null, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } } break; case EAlignment.CenterV: case EAlignment.CenterH: case EAlignment.DistributeV: case EAlignment.DistributeH: throw new ArgumentException("Not valid for this command: " + alignment); } return(moveMacroCommand); }
public static CommandBase CreateMoveCommand(IEnumerable <IAlignable> affectedObjects, EAlignment alignment, XCaseCanvas diagramView) { MacroCommand <DiagramController> moveMacroCommand = MacroCommandFactory <DiagramController> .Factory().Create(diagramView.Controller); double minTop; double maxBottom; double distance; double offset; switch (alignment) { case EAlignment.Top: minTop = affectedObjects.Min(item => item.Top); foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(null, minTop, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } break; case EAlignment.Bottom: maxBottom = affectedObjects.Max(item => item.Bottom); foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(null, maxBottom - (element.Bottom - element.Top), element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } break; case EAlignment.Left: double minLeft = affectedObjects.Min(item => item.Left); foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(minLeft, null, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } break; case EAlignment.Right: double maxRight = affectedObjects.Max(item => item.Right); foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(maxRight - (element.Right - element.Left), null, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } break; case EAlignment.CenterV: double centerH = Math.Round(affectedObjects.Average(item => item.Top + (item.Bottom - item.Top) / 2)); foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(null, (centerH - (element.Bottom - element.Top) / 2), element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } break; case EAlignment.CenterH: double centerV = Math.Round(affectedObjects.Average(item => item.Left + (item.Right - item.Left) / 2)); foreach (IAlignable element in affectedObjects) { var cmd = ViewController.CreateMoveCommand(centerV - (element.Right - element.Left) / 2, null, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); } break; case EAlignment.DistributeV: minTop = affectedObjects.Min(item => item.Top); maxBottom = affectedObjects.Max(item => item.Bottom); double sumHeight = affectedObjects.Sum(item => item.Bottom - item.Top); distance = Math.Max(0, (maxBottom - minTop - sumHeight) / (affectedObjects.Count() - 1)); offset = minTop; foreach (IAlignable element in affectedObjects.OrderBy(item => item.Top)) { double delta = offset - element.Top; var cmd = ViewController.CreateMoveCommand(null, element.Top + delta, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); offset = offset + element.Bottom - element.Top + distance; } break; case EAlignment.DistributeH: minLeft = affectedObjects.Min(item => item.Left); maxRight = affectedObjects.Max(item => item.Right); double sumWidth = affectedObjects.Sum(item => item.Right - item.Left); distance = Math.Max(0, (maxRight - minLeft - sumWidth) / (affectedObjects.Count() - 1)); offset = minLeft; foreach (IAlignable element in affectedObjects.OrderBy(item => item.Left)) { double delta = offset - element.Left; var cmd = ViewController.CreateMoveCommand(element.Left + delta, null, element.ViewHelper, diagramView.Controller); moveMacroCommand.Commands.Add(cmd); offset = offset + element.Right - element.Left + distance; } break; } return(moveMacroCommand); }
/// <summary> /// Initializes a new instance of the <see cref="OperationsContainer"/> class. /// </summary> /// <param name="container">Panel used to display the items</param> /// <param name="xCaseCanvas">canvas owning the control</param> public OperationsContainer(Panel container, XCaseCanvas xCaseCanvas) : base(container, xCaseCanvas) { }
/// <summary> /// Draws all children of given root element and counts width of its subtree. /// </summary> /// <param name="diagram">Diagram to be layouted</param> /// <param name="root">Root element of layouted subtree</param> /// <param name="top">Location of the upper border of the root's children</param> /// <param name="left">Location of the left border of the entire subtree</param> /// <returns>Width of the subtree (root not included)</returns> private static double DrawSubtree(XCaseCanvas diagram, NamedElement root, double top, double left) { double right = left; if (root is PSMSuperordinateComponent) { PSMSuperordinateComponent aClass = root as PSMSuperordinateComponent; NamedElement child = null; if (aClass.Components.Count > 0) { foreach (PSMSubordinateComponent component in aClass.Components) { if (component is PSMAssociation) { child = (component as PSMAssociation).Child; } else { if (component is PSMAttributeContainer) { child = component as PSMAttributeContainer; } else { if (component is PSMContentChoice || component is PSMContentContainer) { child = component as PSMSuperordinateComponent; } } } if (child != null) { right += DrawTree(diagram, child, top, right) + horizontalSpace; } child = null; } } if (aClass is PSMClass && (aClass as PSMClass).Specifications.Count > 0) { foreach (Generalization specification in (aClass as PSMClass).Specifications) { right += DrawTree(diagram, specification.Specific, top, right) + horizontalSpace; } } if (right != left) { right -= horizontalSpace; } } else { if (root is PSMClassUnion) { PSMClassUnion classUnion = root as PSMClassUnion; if (classUnion.Components.Count > 0) { foreach (PSMAssociationChild component in classUnion.Components) { right += DrawTree(diagram, component, top, right) + horizontalSpace; } right = right - horizontalSpace; } } } return(right - left); }
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 } }