public void AddNewAttribute(string attributeName, string newSimpleDataType, uint?lower, UnlimitedNatural?upper, string @default) { MacroCommand <ModelController> command = MacroCommandFactory <ModelController> .Factory().Create(DiagramController.ModelController); AddSimpleTypeCommand simpleTypeCommand = (AddSimpleTypeCommand)AddSimpleTypeCommandFactory.Factory().Create(DiagramController.ModelController); ElementHolder <DataType> type = new ElementHolder <DataType>(); simpleTypeCommand.CreatedSimpleType = type; command.Commands.Add(simpleTypeCommand); NewAttributeCommand attributeCommand = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController); if (!String.IsNullOrEmpty(attributeName)) { attributeCommand.Name = attributeName; } else { attributeCommand.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name); } attributeCommand.Type = type; attributeCommand.Lower = lower; attributeCommand.Upper = upper; attributeCommand.Default = @default; attributeCommand.Owner = Class; command.Commands.Add(attributeCommand); command.Execute(); }
private void bOk_Click(object sender, RoutedEventArgs e) { MacroCommand <ModelController> command = MacroCommandFactory <ModelController> .Factory().Create(controller); command.Description = CommandDescription.UPDATE_PACKAGE_MACRO; if (tbName.Text != oldName) { RenameElementCommand <Package> renameElementCommand = (RenameElementCommand <Package>) RenameElementCommandFactory <Package> .Factory().Create(controller); renameElementCommand.NewName = tbName.Text; renameElementCommand.RenamedElement = package; renameElementCommand.ContainingCollection = package.NestingPackage.NestedPackages; command.Commands.Add(renameElementCommand); } if (cbPackages.SelectedItem != package.NestingPackage) { MovePackageCommand movePackageCommand = (MovePackageCommand)MovePackageCommandFactory.Factory().Create(controller); movePackageCommand.OldPackage = package.NestingPackage; movePackageCommand.NewPackage = (Package)cbPackages.SelectedItem; movePackageCommand.MovedPackage = package; command.Commands.Add(movePackageCommand); } if (command.Commands.Count > 0) { command.Execute(); } DialogResult = true; Close(); }
private void bOk_Click(object sender, RoutedEventArgs e) { MacroCommand <ModelController> command = MacroCommandFactory <ModelController> .Factory().Create(controller); command.Description = CommandDescription.UPDATE_OPERATION_MACRO; if (tbName.Text != oldName) { RenameElementCommand <Operation> renameElementCommand = (RenameElementCommand <Operation>) RenameElementCommandFactory <Operation> .Factory().Create(controller); renameElementCommand.NewName = tbName.Text; renameElementCommand.RenamedElement = operation; renameElementCommand.ContainingCollection = operation.Class.Operations; command.Commands.Add(renameElementCommand); } if (command.Commands.Count > 0) { command.Execute(); } DialogResult = true; Close(); }
public override void Execute(object parameter) { Element element; MacroCommand <DiagramController> command = MacroCommandFactory <DiagramController> .Factory().Create(ActiveDiagramView.Controller); command.Description = CommandDescription.ADD_OPERATION; foreach (ISelectable item in ActiveDiagramView.SelectedItems) { if (item is XCaseViewBase && (element = (item as XCaseViewBase).Controller.Element) is IHasOperations) { NewOperationCommand c = NewOperationCommandFactory.Factory().Create(ActiveDiagramView.Controller.ModelController) as NewOperationCommand; c.Owner = element as IHasOperations; c.Name = NameSuggestor <Operation> .SuggestUniqueName((element as IHasOperations).Operations, "Operation", property => property.Name); command.Commands.Add(c); } } if (command.Commands.Count > 0) { command.Execute(); } }
public override void Execute(object parameter) { Element element; MacroCommand <DiagramController> command = MacroCommandFactory <DiagramController> .Factory().Create(ActiveDiagramView.Controller); command.Description = CommandDescription.ADD_PSM_ATTRIBUTE; foreach (ISelectable item in ActiveDiagramView.SelectedItems) { if (item is PSM_Class && (element = (item as PSM_Class).Controller.Element) is PSMClass) { AddPSMClassAttributeCommand c = AddPSMClassAttributeCommandFactory.Factory().Create(ActiveDiagramView.Controller) as AddPSMClassAttributeCommand; c.PSMClass = (PSMClass)element; c.Name = NameSuggestor <PSMAttribute> .SuggestUniqueName(((PSMClass)element).PSMAttributes, "FreeAttribute", property => property.AliasOrName); command.Commands.Add(c); } } if (command.Commands.Count > 0) { command.Execute(); } }
/// <summary> /// Finalizes the resizing process, issues the resize command (see <see cref="ResizeElementCommand"/>). /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Controls.Primitives.DragCompletedEventArgs"/> instance containing the event data.</param> void ResizeThumb_DragCompleted(object sender, DragCompletedEventArgs e) { Control designerItem = this.belongsTo; XCaseCanvas designer = VisualTreeHelper.GetParent(designerItem) as XCaseCanvas; if (designer != null) { MacroCommand <DiagramController> macroResize = MacroCommandFactory <DiagramController> .Factory().Create(designer.Controller); macroResize.Description = CommandDescription.RESIZE_MACRO; // generate move Commands for all resized elements and execute them as macro foreach (Control item in designer.SelectedItems.OfType <IResizable>()) { item.Width = startSizes[item].Width; item.Height = startSizes[item].Height; CommandBase command = ViewController.CreateResizeCommand(item.ActualWidth, item.ActualHeight, ((IResizable)item).ViewHelper, designer.Controller); macroResize.Commands.Add(command); } macroResize.Execute(); } }
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); }
/// <summary> /// All commands executed after this call will be stored in a queue and executed when CommitMacro is called /// </summary> /// <returns>The MacroCommand created</returns> public override IMacroCommand BeginMacro() { CreatedMacro = MacroCommandFactory <ModelController> .Factory().Create(this); return(CreatedMacro); }
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> /// Drags the completed. /// </summary> /// <param name="finalPoint">The final point.</param> /// <param name="totalShift">The total shift.</param> protected virtual void DragCompleted(Point finalPoint, Vector totalShift) { if (visualAidsAdorner != null) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(XCaseCanvas); adornerLayer.Remove(visualAidsAdorner); visualAidsAdorner = null; } if (DragStartPoint != finalPoint) { DiagramController controller = XCaseCanvas.Controller; MacroCommand <DiagramController> moveMacroCommand = MacroCommandFactory <DiagramController> .Factory().Create(controller); moveMacroCommand.Description = CommandDescription.MOVE_MACRO; JunctionPointCommand.PointMoveDataDictionary pointMoveDataCollection = null; foreach (KeyValuePair <DragThumb, rPoint> pair in startPositions) { if (pair.Key is IAlignable) { IAlignable element = (IAlignable)pair.Key; DragThumb dragThumb = element as DragThumb; double _x; double _y; if (dragThumb != null && dragThumb.Placement == EPlacementKind.RelativeCanvas) { _x = dragThumb.Left - dragThumb.ReferentialElement.CanvasPosition.X; _y = dragThumb.Top - dragThumb.ReferentialElement.CanvasPosition.Y; } else { _x = element.Left; _y = element.Top; } CommandBase command = ViewController.CreateMoveCommand( _x, _y, element.ViewHelper, controller); moveMacroCommand.Commands.Add(command); } else if (pair.Key is JunctionPoint) { JunctionPoint junctionPoint = (JunctionPoint)pair.Key; JunctionPointCommand.PointMoveData data = new JunctionPointCommand.PointMoveData { Index = junctionPoint.OrderInJunction, OldPosition = pair.Value, NewPosition = new rPoint(junctionPoint.Position) { tag = junctionPoint.Placement }, }; if (pointMoveDataCollection == null) { pointMoveDataCollection = new JunctionPointCommand.PointMoveDataDictionary(); } if (!pointMoveDataCollection.ContainsKey(junctionPoint.Junction.viewHelperPointsCollection)) { pointMoveDataCollection[junctionPoint.Junction.viewHelperPointsCollection] = new List <JunctionPointCommand.PointMoveData>(); } pointMoveDataCollection[junctionPoint.Junction.viewHelperPointsCollection].Add(data); } } // add one command for each affected junction if (pointMoveDataCollection != null) { JunctionPointCommand junctionPointCommand = (JunctionPointCommand)JunctionPointCommandFactory.Factory().Create(controller); junctionPointCommand.Action = JunctionPointCommand.EJunctionPointAction.MovePoints; junctionPointCommand.PointMoveDataCollection = pointMoveDataCollection; junctionPointCommand.Description = CommandDescription.MOVE_JUNCTION_POINTS; moveMacroCommand.Commands.Add(junctionPointCommand); } moveMacroCommand.Execute(); if (Dropped != null) { Dropped(); } } }