예제 #1
0
        private void PerformDuplicateShape(object obj)
        {
            if (SelectedElements.Count == 0)
            {
                return;
            }

            var duplicates = new List <ShapeViewModel>();

            foreach (var shape in SelectedElements)
            {
                var duplicateModel = new UMLShape(shape.Shape.X, shape.Shape.Y, shape.Shape.Height, shape.Shape.Width,
                                                  shape.Shape.Type);
                var duplicate = new ShapeViewModel(duplicateModel);
                if (duplicate.Type == EShape.Initial)
                {
                    return;
                }
                duplicates.Add(duplicate);
            }
            foreach (var shape in duplicates)
            {
                Shapes.Add(shape);
            }

            IUndoRedoCommand cmd = new DuplicateCommand(duplicates, this);

            _undoRedo.InsertInUndoRedo(cmd);
        }
예제 #2
0
        private void PerformPaste(object obj)
        {
            var temps = new List <ShapeViewModel>();
            var doesShapesContainIntialNode = DoesShapesContainInitialNode();

            if (_storedElements.Count == 0)
            {
                return;
            }
            foreach (var shape in StoredElements)
            {
                if ((shape.Type == EShape.Initial) && doesShapesContainIntialNode)
                {
                    return;
                }

                var temp =
                    new ShapeViewModel(new UMLShape(shape.X, shape.Y, shape.Height, shape.Width, shape.Shape.Type));
                Shapes.Add(temp);
                temps.Add(temp);
            }
            IUndoRedoCommand cmd = new PasteCommand(this, temps);

            _undoRedo.InsertInUndoRedo(cmd);
        }
예제 #3
0
        /// <summary>
        /// PerformCanvasMouseDown - Called when the canvas is clicked, will NOT be called when clicking a shape.
        /// </summary>
        /// <param name="e"></param>
        private void PerformCanvasMouseDown(MouseButtonEventArgs e)
        {
            try
            {
                // TODO: The behavior is kinda fishy..
                if (_shapeMode)
                {
                    var source = e.Source as UIElement;
                    var point  = source is Canvas?e.GetPosition(source) : RelativeMousePosition(e);

                    var model = new UMLShape(point.X, point.Y, GetDefaultHeight(_toolboxShapeValue),
                                             GetDefaultWidth(_toolboxShapeValue), _toolboxShapeValue);
                    var shapeToAdd = new ShapeViewModel(model);

                    // If we already have a initial node on canvas, don't allow another one.
                    if ((shapeToAdd.Type == EShape.Initial) && DoesShapesContainInitialNode())
                    {
                        System.Windows.MessageBox.Show("Canvas can only contain one initial node.");
                    }
                    else
                    {
                        Shapes.Add(shapeToAdd);
                        IUndoRedoCommand cmd = new AddShapeCommand(shapeToAdd, this);
                        _undoRedo.InsertInUndoRedo(cmd);
                    }
                }
                else if (SelectedElements != null)
                {
                    ClearSelection();
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(Constants.Messages.GenericError);
                Console.WriteLine(ex.Message);
            }
        }