Beispiel #1
0
        public void Paste()
        {
            const int pasteStep = 20;

            _undo.Enabled = false;
            var iData  = Clipboard.GetDataObject();
            var format = DataFormats.GetFormat("Diagram.NET Element Collection");

            if (iData.GetDataPresent(format.Name))
            {
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = (MemoryStream)iData.GetData(format.Name);
                var        elCol     = (BaseElement[])formatter.Deserialize(stream);
                stream.Close();

                foreach (var el in elCol)
                {
                    el.Location = new Point(el.Location.X + pasteStep, el.Location.Y + pasteStep);
                }

                Document.AddElements(elCol);
                Document.ClearSelection();
                Document.SelectElements(elCol);
            }
            _undo.Enabled = true;

            AddUndo();
            EndGeneralAction();
        }
Beispiel #2
0
        private void StartAddElement(Point mousePoint)
        {
            Document.ClearSelection();

            //Change Selection Area Color
            _selectionArea.FillColor = Color.LightSteelBlue;

            _isAddSelection         = true;
            _selectionArea.Location = mousePoint;
            _selectionArea.Size     = new Size(0, 0);
        }
Beispiel #3
0
        private void StartSelectElements(BaseElement selectedElement, Point mousePoint)
        {
            // Vefiry if element is in selection
            if (!Document.SelectedElements.Contains(selectedElement))
            {
                //Clear selection and add new element to selection
                Document.ClearSelection();
                Document.SelectElement(selectedElement);
            }

            _changed = false;


            _moveAction = new MoveAction();
            MoveAction.OnElementMovingDelegate onElementMovingDelegate = OnElementMoving;
            _moveAction.Start(mousePoint, Document, onElementMovingDelegate);


            // Get Controllers
            _controllers = new IController[Document.SelectedElements.Count];
            for (var i = Document.SelectedElements.Count - 1; i >= 0; i--)
            {
                if (Document.SelectedElements[i] is IControllable)
                {
                    // Get General Controller
                    _controllers[i] = ((IControllable)Document.SelectedElements[i]).GetController();
                }
                else
                {
                    _controllers[i] = null;
                }
            }

            _resizeAction = new ResizeAction();
            _resizeAction.Select(Document);
        }
Beispiel #4
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            Point mousePoint;

            //ShowSelectionCorner((document.Action==DesignerAction.Select));

            switch (Document.Action)
            {
            // SELECT
            case DesignerAction.Connect:
            case DesignerAction.Select:
                if (e.Button == MouseButtons.Left)
                {
                    mousePoint = Gsc2Goc(new Point(e.X, e.Y));

                    //Verify resize action
                    StartResizeElement(mousePoint);
                    if ((_resizeAction != null) && _resizeAction.IsResizing)
                    {
                        break;
                    }

                    //Verify LabelElement editing
                    if (_isEditLabel)
                    {
                        EndEditLabel();
                    }

                    // Search element by click
                    _selectedElement = Document.FindElement(mousePoint);

                    if (_selectedElement != null)
                    {
                        //Events
                        var eventMouseDownArg = new ElementMouseEventArgs(_selectedElement, e.X, e.Y);
                        OnElementMouseDown(eventMouseDownArg);

                        // Double-click to edit Label
                        if ((e.Clicks == 2) && _selectedElement is ILabelElement)
                        {
                            StartEditLabel();
                            break;
                        }

                        // Element selected
                        if (_selectedElement is ConnectorElement)
                        {
                            StartAddLink((ConnectorElement)_selectedElement, mousePoint);
                            _selectedElement = null;
                        }
                        else
                        {
                            StartSelectElements(_selectedElement, mousePoint);
                        }
                    }
                    else
                    {
                        // If click is on neutral area, clear selection
                        Document.ClearSelection();
                        var p = Gsc2Goc(new Point(e.X, e.Y));
                        ;
                        _isMultiSelection       = true;
                        _selectionArea.Location = p;
                        _selectionArea.Size     = new Size(0, 0);
                    }
                    base.Invalidate();
                }
                break;

            // ADD
            case DesignerAction.Add:

                if (e.Button == MouseButtons.Left)
                {
                    mousePoint = Gsc2Goc(new Point(e.X, e.Y));
                    StartAddElement(mousePoint);
                }
                break;

            // DELETE
            case DesignerAction.Delete:
                if (e.Button == MouseButtons.Left)
                {
                    mousePoint = Gsc2Goc(new Point(e.X, e.Y));
                    DeleteElement(mousePoint);
                }
                break;
            }

            base.OnMouseDown(e);
        }