Пример #1
0
        private void StartAddLink(ConnectorElement connStart, Point mousePoint)
        {
            if (Document.Action == DesignerAction.Connect)
            {
                _connStart = connStart;
                _connEnd   = new ConnectorElement(connStart.ParentElement)
                {
                    Location = connStart.Location
                };

                var controller = (IMoveController)((IControllable)_connEnd).GetController();
                controller.Start(mousePoint);

                _isAddLink = true;

                _linkLine = new StraightLinkElement(connStart, _connEnd)
                {
                    BorderWidth = 1
                };

                Invalidate(_linkLine, true);

                OnElementConnecting(new ElementConnectEventArgs(connStart.ParentElement, null, _linkLine));
            }
        }
Пример #2
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;
        }
Пример #3
0
 public void DeleteLink(BaseLinkElement lnk, bool callHandler = true)
 {
     if (lnk == null) return;
     lnk.Connector1.RemoveLink(lnk);
     lnk.Connector2.RemoveLink(lnk);
                     
     if (Elements.Contains(lnk))
         Elements.Remove(lnk);
     if (SelectedElements.Contains(lnk))
         SelectedElements.Remove(lnk);
     if (callHandler)
         OnLinkRemoved(new ElementEventArgs(lnk));
     OnAppearancePropertyChanged(new EventArgs());
 }
Пример #4
0
        private void DelteLink(BaseLinkElement baseLinkElement)
        {
            string toDelete = null;

            foreach (var v in linkedIOS)
            {
                if (v.Value == baseLinkElement.Tag as BaseElementLink)
                {
                    toDelete = v.Key;
                    break;
                }
            }

            if (toDelete != null)
            {
                linkedIOS.Remove(toDelete);
            }
        }
Пример #5
0
        public void DeleteLink(BaseLinkElement linkElement)
        {
            if (linkElement != null)
            {
                linkElement.Connector1.RemoveLink(linkElement);
                linkElement.Connector2.RemoveLink(linkElement);

                if (_elements.Contains(linkElement))
                {
                    _elements.Remove(linkElement);
                }
                if (SelectedElements.Contains(linkElement))
                {
                    SelectedElements.Remove(linkElement);
                }
                OnAppearancePropertyChanged(new EventArgs());
            }
        }
Пример #6
0
        private void CheckControlClick()
        {
            if ((ModifierKeys & Keys.Control) != Keys.Control ||
                SelectedElement == null || PreviousSelectedElement == null ||
                !(SelectedElement is NodeElement) || !(PreviousSelectedElement is NodeElement))
            {
                return;
            }
            var startConnector = ((NodeElement)PreviousSelectedElement).Connectors.OrderBy(c => c.Links.Count).FirstOrDefault(c => !c.IsStart);
            var endConnector   = ((NodeElement)SelectedElement).Connectors.FirstOrDefault(c => c.IsStart && c.Links.Count == 0);

            if (startConnector != null && endConnector != null)
            {
                _linkLine = Document.AddLink(startConnector, endConnector);
                OnElementConnected(new ElementConnectEventArgs(startConnector.ParentElement, endConnector.ParentElement,
                                                               _linkLine));
            }
        }
Пример #7
0
        private void UpdateLinkPosition(NodeElement node)
        {
            foreach (ConnectorElement conn in node.Connectors)
            {
                foreach (BaseElement el in conn.Links)
                {
                    BaseLinkElement lnk  = (BaseLinkElement)el;
                    IController     ctrl = ((IControllable)lnk).GetController();
                    if (ctrl is IMoveController)
                    {
                        IMoveController mctrl = (IMoveController)ctrl;
                        if (!mctrl.IsMoving)
                        {
                            lnk.NeedCalcLink = true;
                        }
                    }
                    else
                    {
                        lnk.NeedCalcLink = true;
                    }

                    if (lnk is ILabelElement)
                    {
                        LabelElement label = ((ILabelElement)lnk).Label;

                        ILabelController lblCtrl = ControllerHelper.GetLabelController(lnk);
                        if (lblCtrl != null)
                        {
                            lblCtrl.SetLabelPosition();
                        }
                        else
                        {
                            label.PositionBySite(lnk);
                        }
                        label.Invalidate();
                    }
                }
            }
        }
Пример #8
0
        private void EndAddLink()
        {
            if (_connEnd != _linkLine.Connector2)
            {
                _linkLine.Connector1.RemoveLink(_linkLine);
                _linkLine = _document.AddLink(_linkLine.Connector1, _linkLine.Connector2);
                var eventArgs = new ElementConnectEventArgs(_linkLine.Connector1.ParentElement, _linkLine.Connector2.ParentElement, _linkLine);
                var accepted  = true;
                if (_linkLine.Connector1.ParentElement is DiagramBlock)
                {
                    accepted = (_linkLine.Connector1.ParentElement as DiagramBlock).OnElementConnected(this, eventArgs);
                }
                if (accepted)
                {
                    OnElementConnected(eventArgs);
                }
            }

            _connStart = null;
            _connEnd   = null;
            _linkLine  = null;
        }
Пример #9
0
        private void StartAddLink(ConnectorElement connectorStart, Point mousePoint)
        {
            if (_document.Action != DesignerAction.Connect)
            {
                return;
            }
            _connStart = connectorStart;
            _connEnd   = new ConnectorElement(connectorStart.ParentElement)
            {
                Location = connectorStart.Location
            };

            var ctrl = (IMoveController)((IControllable)_connEnd).GetController();

            ctrl.Start(mousePoint);

            _isAddLink = true;

            switch (_document.LinkType)
            {
            case (LinkType.Straight):
                _linkLine = new StraightLinkElement(connectorStart, _connEnd);
                break;

            case (LinkType.RightAngle):
                _linkLine = new RightAngleLinkElement(connectorStart, _connEnd);
                break;
            }
            _linkLine.Visible     = true;
            _linkLine.BorderColor = Color.FromArgb(150, Color.Black);
            _linkLine.BorderWidth = 1;

            Invalidate(_linkLine, true);

            OnElementConnecting(new ElementConnectEventArgs(connectorStart.ParentElement, null, _linkLine));
        }
Пример #10
0
 public ElementConnectEventArgs(NodeElement node1, NodeElement node2, BaseLinkElement link)
 {
     Node1 = node1;
     Node2 = node2;
     Link  = link;
 }
Пример #11
0
        void designer1_ElementsWillConnect(object sender, Designer.ElementsLinkedArgs e)
        {
            NodeElement node1 = e.Element1 as NodeElement;
            NodeElement node2 = e.Element2 as NodeElement;

            ConnectorElement connector1 = e.Connector1;
            ConnectorElement connector2 = e.Connector2;


            ElementInputType  input  = null;
            ElementOutputType output = null;

            bool inputOnRight  = false;
            bool outputOnRight = false;

            BaseLinkElement outputLink = null;

            if (e.Element1.Tag is ElementInputType)
            {
                inputOnRight = node1.Connectors[1] == connector1;
                input        = (ElementInputType)e.Element1.Tag;
            }

            if (e.Element2.Tag is ElementInputType)
            {
                inputOnRight = node2.Connectors[1] == connector2;
                input        = (ElementInputType)e.Element2.Tag;
            }

            if (e.Element1.Tag is ElementOutputType)
            {
                outputOnRight = node1.Connectors[1] == connector1;
                output        = (ElementOutputType)e.Element1.Tag;
            }

            if (e.Element2.Tag is ElementOutputType)
            {
                outputOnRight = node2.Connectors[1] == connector2;
                output        = (ElementOutputType)e.Element2.Tag;
            }

            if (input == null)
            {
                e.Cancel = true;
                MessageBox.Show("Cannot connect two outputs");
                return;
            }

            if (output == null)
            {
                e.Cancel = true;
                MessageBox.Show("Cannot connect two inputs");
                return;
            }

            if (input.InputType != output.OutputType)
            {
                e.Cancel = true;
                MessageBox.Show("Cannot connect an input of type " + input.InputType + " to an output of type " + output.OutputType);
                return;
            }

            Guid g = Guid.NewGuid();

            var lnk = new BaseElementLink {
                Input = input, InputOnLeft = !inputOnRight, Output = output, OutputOnLeft = !outputOnRight
            };

            linkedIOS.Add(g.ToString(), lnk);

            e.NewLink.Tag = lnk;
        }
Пример #12
0
 internal void RemoveLink(BaseLinkElement baseLinkElement)
 {
     Links.Remove(baseLinkElement);
 }
Пример #13
0
 internal void AddLink(BaseLinkElement baseLinkElement)
 {
     Links.Add(baseLinkElement);
 }