Inheritance: BaseElement
Ejemplo n.º 1
0
        private void StartAddLink(ConnectorElement connStart, Point mousePoint)
        {
            if (document.Action == DesignerAction.Connect)
            {
                this.connStart = connStart;
                this.connEnd   = new ConnectorElement(connStart.ParentElement);

                connEnd.Location = connStart.Location;
                IMoveController ctrl = (IMoveController)((IControllable)connEnd).GetController();
                ctrl.Start(mousePoint);

                isAddLink = true;

                switch (document.LinkType)
                {
                case (LinkType.Straight):
                    linkLine = new StraightLinkElement(connStart, connEnd);
                    break;

                case (LinkType.RightAngle):
                    linkLine = new RightAngleLinkElement(connStart, connEnd);
                    break;
                }
                linkLine.Visible     = true;
                linkLine.BorderColor = Color.FromArgb(150, Color.Black);
                linkLine.BorderWidth = 1;

                this.Invalidate(linkLine, true);

                OnElementConnecting(new ElementConnectEventArgs(connStart.ParentElement, null, linkLine));
            }
        }
Ejemplo n.º 2
0
        private void EndAddLink()
        {
            if (connEnd != linkLine.Connector2)
            {
                linkLine.Connector1.RemoveLink(linkLine);
                linkLine = document.AddLink(linkLine.Connector1, linkLine.Connector2);

                if (ElementsWillLink != null)
                {
                    var args = new ElementsLinkedArgs {
                        Connector1 = linkLine.Connector1, Connector2 = linkLine.Connector2, Element1 = linkLine.Connector1.ParentElement, Element2 = linkLine.Connector2.ParentElement, NewLink = linkLine
                    };

                    ElementsWillLink(this, args);

                    if (args.Cancel)
                    {
                        document.DeleteLink(linkLine);
                        connStart = null;
                        connEnd   = null;
                        linkLine  = null;
                        return;
                    }
                }

                OnElementConnected(new ElementConnectEventArgs(linkLine.Connector1.ParentElement, linkLine.Connector2.ParentElement, linkLine));
            }

            connStart = null;
            connEnd   = null;
            linkLine  = null;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public void SelectElements(Rectangle selectionRectangle)
        {
            selectedElements.EnabledCalc = false;
            selectedNodes.EnabledCalc    = false;

            // Add all "hitable" elements
            foreach (BaseElement element in elements)
            {
                if (element is IControllable)
                {
                    IController ctrl = ((IControllable)element).GetController();
                    if (ctrl.HitTest(selectionRectangle))
                    {
                        if (!(element is ConnectorElement))
                        {
                            selectedElements.Add(element);
                        }

                        if (element is NodeElement)
                        {
                            selectedNodes.Add(element);
                        }
                    }
                }
            }

            //if the seleciont isn't a expecific link, remove links
            // without 2 elements in selection
            if (selectedElements.Count > 1)
            {
                foreach (BaseElement el in elements)
                {
                    BaseLinkElement lnk = el as BaseLinkElement;
                    if (lnk == null)
                    {
                        continue;
                    }

                    if ((!selectedElements.Contains(lnk.Connector1.ParentElement)) ||
                        (!selectedElements.Contains(lnk.Connector2.ParentElement)))
                    {
                        selectedElements.Remove(lnk);
                    }
                }
            }

            selectedElements.EnabledCalc = true;
            selectedNodes.EnabledCalc    = true;

            OnElementSelection(this, new ElementSelectionEventArgs(selectedElements));
        }
Ejemplo n.º 5
0
        public void DeleteElement(BaseElement el)
        {
            if ((el != null) && !(el is ConnectorElement))
            {
                //Delete link
                if (el is BaseLinkElement)
                {
                    BaseLinkElement lnk = (BaseLinkElement)el;
                    DeleteLink(lnk);
                    return;
                }

                //Delete node
                if (el is NodeElement)
                {
                    NodeElement conn = ((NodeElement)el);
                    foreach (ConnectorElement elconn in conn.Connectors)
                    {
                        BaseLinkElement lnk;
                        for (int i = elconn.Links.Count - 1; i >= 0; i--)
                        {
                            lnk = (BaseLinkElement)elconn.Links[i];
                            DeleteLink(lnk);
                        }
                    }

                    if (selectedNodes.Contains(el))
                    {
                        selectedNodes.Remove(el);
                    }
                }

                if (SelectedElements.Contains(el))
                {
                    selectedElements.Remove(el);
                }

                elements.Remove(el);
                el.OnRemovedFromDocument(new DocumentEventArgs {
                    Document = this
                });
                OnAppearancePropertyChanged(new EventArgs());
            }
            el = null;
        }
Ejemplo n.º 6
0
        public void DeleteLink(BaseLinkElement lnk)
        {
            if (lnk != null)
            {
                lnk.Connector1.RemoveLink(lnk);
                lnk.Connector2.RemoveLink(lnk);

                if (elements.Contains(lnk))
                {
                    elements.Remove(lnk);
                }
                if (selectedElements.Contains(lnk))
                {
                    selectedElements.Remove(lnk);
                }
                OnAppearancePropertyChanged(new EventArgs());
            }
        }
Ejemplo n.º 7
0
        private void StartAddLink(ConnectorElement connStart, Point mousePoint)
        {
            if (document.Action == DesignerAction.Connect)
            {
                this.connStart = connStart;
                this.connEnd   = new ConnectorElement(connStart.ParentElement);

                connEnd.Location = connStart.Location;
                IMoveController ctrl = (IMoveController)((IControllable)connEnd).GetController();
                ctrl.Start(mousePoint);

                isAddLink = true;

                linkLine = CreateElementInstance(connStart, connEnd);

                this.Invalidate(linkLine, true);

                OnElementConnecting(new ElementConnectEventArgs(connStart.ParentElement, null, linkLine));
            }
        }
Ejemplo n.º 8
0
        internal void DrawSelections(Graphics g, Rectangle clippingRegion)
        {
            for (int i = selectedElements.Count - 1; i >= 0; i--)
            {
                if (selectedElements[i] is IControllable)
                {
                    IController ctrl = ((IControllable)selectedElements[i]).GetController();
                    ctrl.DrawSelection(g);

                    if (selectedElements[i] is BaseLinkElement)
                    {
                        BaseLinkElement link = (BaseLinkElement)selectedElements[i];
                        ctrl = ((IControllable)link.Connector1).GetController();
                        ctrl.DrawSelection(g);

                        ctrl = ((IControllable)link.Connector2).GetController();
                        ctrl.DrawSelection(g);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        protected virtual BaseLinkElement CreateElementInstance(ConnectorElement connStart, ConnectorElement connEnd)
        {
            BaseLinkElement linkLine;

            switch (document.LinkType)
            {
            default:
            case (LinkType.Straight):
                linkLine = new StraightLinkElement(connStart, connEnd);
                break;

            case (LinkType.RightAngle):
                linkLine = new RightAngleLinkElement(connStart, connEnd);
                break;
            }
            linkLine.Visible     = true;
            linkLine.BorderColor = Color.FromArgb(150, Color.Black);
            linkLine.BorderWidth = 1;

            return(linkLine);
        }
Ejemplo n.º 10
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();
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public ElementConnectEventArgs(NodeElement node1, NodeElement node2, BaseLinkElement link)
 {
     this.node1 = node1;
     this.node2 = node2;
     this.link  = link;
 }
Ejemplo n.º 12
0
		public ElementConnectEventArgs(NodeElement node1, NodeElement node2, BaseLinkElement link)
		{
			this.node1 = node1;
			this.node2 = node2;
			this.link = link;
		}
Ejemplo n.º 13
0
 internal void AddLink(BaseLinkElement lnk)
 {
     links.Add(lnk);
 }
Ejemplo n.º 14
0
 internal void RemoveLink(BaseLinkElement lnk)
 {
     links.Remove(lnk);
 }
Ejemplo n.º 15
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;
		}
Ejemplo n.º 16
0
		public void DeleteLink(BaseLinkElement lnk)
		{
			if (lnk != null)
			{
				lnk.Connector1.RemoveLink(lnk);
				lnk.Connector2.RemoveLink(lnk);
							
				if (elements.Contains(lnk))
					elements.Remove(lnk);
				if (selectedElements.Contains(lnk))
					selectedElements.Remove(lnk);
				OnAppearancePropertyChanged(new EventArgs());
			}
		}
Ejemplo n.º 17
0
		internal void RemoveLink(BaseLinkElement lnk)
		{
			links.Remove(lnk);
		}
Ejemplo n.º 18
0
		internal void AddLink(BaseLinkElement lnk)
		{
			links.Add(lnk);
		}
Ejemplo n.º 19
0
		private void StartAddLink(ConnectorElement connStart, Point mousePoint)
		{
			if (document.Action == DesignerAction.Connect)
			{
				this.connStart = connStart;
				this.connEnd = new ConnectorElement(connStart.ParentElement);

				connEnd.Location = connStart.Location;
				IMoveController ctrl = (IMoveController) ((IControllable) connEnd).GetController();
				ctrl.Start(mousePoint);

				isAddLink = true;
				
				switch(document.LinkType)
				{
					case (LinkType.Straight):
						linkLine = new StraightLinkElement(connStart, connEnd);
						break;
					case (LinkType.RightAngle):
						linkLine = new RightAngleLinkElement(connStart, connEnd);
						break;
				}
				linkLine.Visible = true;
				linkLine.BorderColor = Color.FromArgb(150, Color.Black);
				linkLine.BorderWidth = 1;
				
				this.Invalidate(linkLine, true);
				
				OnElementConnecting(new ElementConnectEventArgs(connStart.ParentElement, null, linkLine));
			}
		}
Ejemplo n.º 20
0
 public void AddLink(BaseLinkElement lnk)
 {
     elements.Add(lnk);
     lnk.AppearanceChanged += new EventHandler(element_AppearanceChanged);
     OnAppearancePropertyChanged(new EventArgs());
 }