Exemple #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var graphics = e.Graphics;

            graphics.PageUnit = GraphicsUnit.Pixel;

            var scrollPoint = AutoScrollPosition;

            graphics.TranslateTransform(scrollPoint.X, scrollPoint.Y);

            //Zoom
            using (var matrix = graphics.Transform)
            {
                var graphicsContainer = graphics.BeginContainer();

                graphics.SmoothingMode      = Document.SmoothingMode;
                graphics.PixelOffsetMode    = Document.PixelOffsetMode;
                graphics.CompositingQuality = Document.CompositionQuality;

                graphics.ScaleTransform(Document.Zoom, Document.Zoom);

                var clipRectangle = Gsc2Goc(e.ClipRectangle);

                Document.DrawElements(graphics, clipRectangle);

                if (!((_resizeAction != null) && _resizeAction.IsResizing))
                {
                    Document.DrawSelections(graphics, e.ClipRectangle);
                }

                if (_isMultiSelection || _isAddSelection)
                {
                    DrawSelectionRectangle(graphics);
                }

                if (_isAddLink)
                {
                    _linkLine.CalcLink();
                    _linkLine.Draw(graphics);
                }
                if ((_resizeAction != null) && !((_moveAction != null) && _moveAction.IsMoving))
                {
                    _resizeAction.DrawResizeCorner(graphics);
                }

                if (_mousePointerElement != null)
                {
                    if (_mousePointerElement is IControllable)
                    {
                        var ctrl = ((IControllable)_mousePointerElement).GetController();
                        ctrl.DrawSelection(graphics);
                    }
                }

                graphics.EndContainer(graphicsContainer);
                graphics.Transform = matrix;
            }

            base.OnPaint(e);
        }
Exemple #2
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();
        }
Exemple #3
0
        private void GetConnectors(Link link, out ConnectorElement startConnectorElement, out ConnectorElement endConnectorElement)
        {
            startConnectorElement = (ConnectorElement)Document.FindElement(new Point(link.StartPointX, link.StartPointY));
            endConnectorElement   = (ConnectorElement)Document.FindElement(new Point(link.EndPointX, link.EndPointY));

            if (startConnectorElement == null || endConnectorElement == null)
            {
                var startNode = Document.Elements.GetArray().FirstOrDefault(n => n.Id == link.StartNodeId);
                var endNode   = Document.Elements.GetArray().FirstOrDefault(n => n.Id == link.EndNodeId);

                if (startNode != null && endNode != null)
                {
                    var listTuples = new List <LineVariantTuple>();
                    foreach (var connector1 in ((NodeElement)startNode).Connectors)
                    {
                        foreach (var connector2 in ((NodeElement)endNode).Connectors)
                        {
                            listTuples.Add(new LineVariantTuple
                            {
                                StartPoint = connector1.Location,
                                EndPoint   = connector2.Location
                            });
                        }
                    }

                    var minLengthLine = listTuples.OrderBy(l => l.Length).FirstOrDefault();
                    if (minLengthLine != null)
                    {
                        startConnectorElement = (ConnectorElement)Document.FindElement(minLengthLine.StartPoint);
                        endConnectorElement   = (ConnectorElement)Document.FindElement(minLengthLine.EndPoint);
                    }
                }
            }
        }
Exemple #4
0
        private void EndAddElement(Rectangle selectionRectangle)
        {
            BaseElement el;

            switch (Document.ElementType)
            {
            case ElementType.Rectangle:
                el = new RectangleElement(selectionRectangle);
                break;

            case ElementType.RectangleNode:
                el = new RectangleNode(selectionRectangle);
                break;

            case ElementType.Ellipse:
                el = new EllipseElement(selectionRectangle);
                break;

            case ElementType.EllipseNode:
                el = new EllipseNode(selectionRectangle);
                break;

            case ElementType.CommentBox:
                el = new CommentBoxElement(selectionRectangle);
                break;

            default:
                el = new RectangleNode(selectionRectangle);
                break;
            }

            Document.AddElement(el);

            Document.Action = DesignerAction.Select;
        }
Exemple #5
0
        public void OpenFile(string fileName, FileExtensionType type)
        {
            var document = FileManager.Open(fileName, type);

            CreateDocument(document);
            RestartInitValues();
            Document.SetCurrentId();
            RecreateEventsHandlers();
            Invalidate();
        }
Exemple #6
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);
        }
Exemple #7
0
        private void EndAddLink()
        {
            if (_connEnd != _linkLine.Connector2)
            {
                _linkLine.Connector1.RemoveLink(_linkLine);
                _linkLine = Document.AddLink(_linkLine.Connector1, _linkLine.Connector2);
                OnElementConnected(new ElementConnectEventArgs(_linkLine.Connector1.ParentElement, _linkLine.Connector2.ParentElement, _linkLine));
            }

            _connStart = null;
            _connEnd   = null;
            _linkLine  = null;
        }
Exemple #8
0
        public void RestartInitValues()
        {
            // Reinitialize status
            _moveAction = null;

            _isMultiSelection = false;
            _isAddSelection   = false;
            _isAddLink        = false;

            _changed = false;

            _connStart = null;

            _selectionArea.FillColor = SystemColors.Control;

            Document.CalcWindow(true);
        }
Exemple #9
0
        public void SaveDb()
        {
            if (string.IsNullOrEmpty(Document.Name))
            {
                var form = new InputForm();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    Document.Name = form.DocumentName;
                }
            }

            if (!string.IsNullOrEmpty(Document.Name))
            {
                if (!DataBaseManager.IsDocumentExists(Document.Name) ||
                    MessageBox.Show(Strings.ReplaceInDbText, Strings.ReplaceInDbTitle,
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var document = Document.GetDocument();
                    DataBaseManager.SaveDocument(document);
                    MessageBox.Show(Strings.SuccessSaveToDbText, Strings.ApplicationTitle, MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
        }
Exemple #10
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);
        }
Exemple #11
0
        public void CreateDocument(DomainDocument domainDocument)
        {
            Document = new Document
            {
                Id         = domainDocument.Id,
                Name       = domainDocument.Name,
                WindowSize = Size
            };

            foreach (var node in domainDocument.Nodes)
            {
                var rectangle = new Rectangle(node.X, node.Y, node.Width, node.Height);

                switch (node.Type)
                {
                case NodeType.Concept:
                    var rectangleNode = new RectangleNode(rectangle)
                    {
                        Id = node.Id, Label = new LabelElement {
                            Text = node.Label
                        }
                    };
                    rectangleNode.Label.PositionBySite(rectangleNode);
                    Document.AddElement(rectangleNode);
                    break;

                case NodeType.Relation:
                    var ellipseNode = new EllipseNode(rectangle)
                    {
                        Id = node.Id, Label = new LabelElement {
                            Text = node.Label
                        }
                    };
                    ellipseNode.Label.PositionBySite(ellipseNode);
                    Document.AddElement(ellipseNode);
                    break;

                case NodeType.Comment:
                    var commentBoxElement = new CommentBoxElement(rectangle)
                    {
                        Id = node.Id, Label = new LabelElement {
                            Text = node.Label
                        }
                    };
                    commentBoxElement.Label.PositionBySite(commentBoxElement);
                    Document.AddElement(commentBoxElement);
                    break;
                }
            }

            foreach (var link in domainDocument.Links)
            {
                ConnectorElement startConnectorElement, endConnectorElement;
                GetConnectors(link, out startConnectorElement, out endConnectorElement);

                if (startConnectorElement != null && endConnectorElement != null)
                {
                    var linkElement = new StraightLinkElement(startConnectorElement, endConnectorElement)
                    {
                        Id    = link.Id,
                        Label = new LabelElement
                        {
                            Text = link.Label
                        }
                    };
                    linkElement.Label.Size = EditLabelAction.GetTextSize(linkElement);
                    linkElement.Label.PositionBySite(linkElement);
                    Document.Elements.Add(linkElement);
                }
            }

            Document.SetCurrentId();
            RecreateEventsHandlers();
        }
Exemple #12
0
 public void SaveFile(string fileName, FileExtensionType type)
 {
     FileManager.Save(fileName, Document.GetDocument(), type);
 }
Exemple #13
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.None)
            {
                Cursor = Cursors.Arrow;
                var mousePoint = Gsc2Goc(new Point(e.X, e.Y));

                if ((_resizeAction != null) &&
                    ((Document.Action == DesignerAction.Select) ||
                     ((Document.Action == DesignerAction.Connect) &&
                      _resizeAction.IsResizingLink)))
                {
                    Cursor = _resizeAction.UpdateResizeCornerCursor(mousePoint);
                }

                if (Document.Action == DesignerAction.Connect)
                {
                    var mousePointerElementTMP = Document.FindElement(mousePoint);
                    if (_mousePointerElement != mousePointerElementTMP)
                    {
                        if (mousePointerElementTMP is ConnectorElement)
                        {
                            _mousePointerElement = mousePointerElementTMP;
                            _mousePointerElement.Invalidate();
                            Invalidate(_mousePointerElement, true);
                        }
                        else if (_mousePointerElement != null)
                        {
                            _mousePointerElement.Invalidate();
                            Invalidate(_mousePointerElement, true);
                            _mousePointerElement = null;
                        }
                    }
                }
                else
                {
                    Invalidate(_mousePointerElement, true);
                    _mousePointerElement = null;
                }
            }

            if (e.Button == MouseButtons.Left)
            {
                var dragPoint = Gsc2Goc(new Point(e.X, e.Y));

                if ((_resizeAction != null) && _resizeAction.IsResizing)
                {
                    _resizeAction.Resize(dragPoint);
                    Invalidate();
                }

                if ((_moveAction != null) && _moveAction.IsMoving)
                {
                    _moveAction.Move(dragPoint);
                    Invalidate();
                }

                if (_isMultiSelection || _isAddSelection)
                {
                    var p = Gsc2Goc(new Point(e.X, e.Y));
                    _selectionArea.Size = new Size(p.X - _selectionArea.Location.X, p.Y - _selectionArea.Location.Y);
                    _selectionArea.Invalidate();
                    Invalidate(_selectionArea, true);
                }

                if (_isAddLink)
                {
                    _selectedElement = Document.FindElement(dragPoint);
                    if (_selectedElement is ConnectorElement &&
                        Document.CanAddLink(_connStart, (ConnectorElement)_selectedElement))
                    {
                        _linkLine.Connector2 = (ConnectorElement)_selectedElement;
                    }
                    else
                    {
                        _linkLine.Connector2 = _connEnd;
                    }

                    var moveController = (IMoveController)((IControllable)_connEnd).GetController();
                    moveController.Move(dragPoint);

                    base.Invalidate();
                }
            }

            base.OnMouseMove(e);
        }
Exemple #14
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);
        }
Exemple #15
0
 private void DeleteSelectedElements()
 {
     Document.DeleteSelectedElements();
 }
Exemple #16
0
 private void DeleteElement(Point mousePoint)
 {
     Document.DeleteElement(mousePoint);
     _selectedElement = null;
     Document.Action  = DesignerAction.Select;
 }
Exemple #17
0
 private void EndSelectElements(Rectangle selectionRectangle)
 {
     Document.SelectElements(selectionRectangle);
 }