public void MouseUp(MouseEventArgs e)
        {
            if (IsActive)
            {
                DeactivateTool();

                //whatever comes hereafter, a compund command is the most economic approach
                CompoundCommand package = new CompoundCommand(this.Controller);

                //let's see if the connection endpoints hit other connectors
                //note that the following can be done because the actual connection has not been created yet
                //otherwise the search would find the endpoints of the newly created connection, which
                //would create a loop and a stack overflow!
                IConnector startConnector = Selection.FindConnectorAt(initialPoint);
                IConnector endConnector = Selection.FindConnectorAt(e.Location);

                #region Create the new connection
                DDTConnection cn = new DDTConnection(this.initialPoint, e.Location, this.Controller.Model, connectionType);

                AddConnectionCommand newcon = new AddConnectionCommand(this.Controller, cn);
                package.Commands.Add(newcon);
                #endregion

                #region assign id

                if(startConnector != null)
                {
                    BindConnectorsCommand bindStart = new BindConnectorsCommand(this.Controller, startConnector, cn.From);
                    package.Commands.Add(bindStart);
                    cn.fromConnectorIndex = getConnectorIndex(startConnector);
                    cn.fromId = ((IDDTObject)startConnector.Parent).ID;
                }
                #endregion

                #region
                if(endConnector != null)
                {
                    BindConnectorsCommand bindEnd = new BindConnectorsCommand(this.Controller, endConnector, cn.To);
                    package.Commands.Add(bindEnd);
                    cn.toConnectorIndex = getConnectorIndex(endConnector);
                    cn.toId = ((IDDTObject)endConnector.Parent).ID;
                }
                #endregion
                 package.Text = "New connection";
                this.Controller.UndoManager.AddUndoCommand(package);

                //do it all
                package.Redo();

                //drop the painted ghost
                Controller.View.ResetGhost();
                //release other tools
                this.UnsuspendTools();
            }
        }
 //using!!!
 public ConnectionText(DDTConnection conn, TextPosition pos)
     : base("ConnectionText", false)
 {
     this.conn = conn;
     this.pos = pos;
 }
        public static Netron.NetronLight.DDTConnection DDTRelationToCanvas(DDTRelation rel, Netron.NetronLight.Win.DiagramControl diagramControl)
        {
            Netron.NetronLight.DDTConnection connection;
            Netron.NetronLight.ConnectionType type;
            int fromId = rel.from.objectId;
            int toId = rel.to.objectId;
            int fromIndex;
            int toIndex;
            Netron.NetronLight.IDDTObject fromObj=null;
            Netron.NetronLight.IDDTObject toObj = null;
            IConnector fromConnector = null;
            IConnector toConnector = null;

            //get from and to objects
            foreach (Netron.NetronLight.IDDTDiagramEntity temp in diagramControl.controller.Model.Paintables)
            {

                if (temp.GetType().IsSubclassOf(typeof(Netron.NetronLight.IDDTObject)))
                {
                    if (((Netron.NetronLight.IDDTObject)temp).ID == fromId && fromObj == null)
                    {
                        fromObj = ((Netron.NetronLight.IDDTObject)temp);
                    }
                    if (((Netron.NetronLight.IDDTObject)temp).ID == toId && toObj == null)
                    {
                        toObj = ((Netron.NetronLight.IDDTObject)temp);
                    }
                    if (fromObj != null && toObj != null) { break; }
                }

            }

            fromConnector = getConnector(rel, ConnectorOrientation.FROM, fromObj);
            toConnector = getConnector(rel, ConnectorOrientation.TO, toObj);

             switch (rel.from.pos)
            {
                case Conn_Position.LEFT:
                    fromIndex = 1;
                    break;
                case Conn_Position.TOP:
                    fromIndex = 2;
                    break;
                case Conn_Position.RIGHT:
                    fromIndex = 3;
                    break;
                case Conn_Position.BOTTOM:
                    fromIndex = 4;
                    break;
                default:
                    fromIndex = 1;
                    break;
            }

             switch (rel.to.pos)
             {
                 case Conn_Position.LEFT:
                     toIndex = 1;
                     break;
                 case Conn_Position.TOP:
                     toIndex = 2;
                     break;
                 case Conn_Position.RIGHT:
                     toIndex = 3;
                     break;
                 case Conn_Position.BOTTOM:
                     toIndex = 4;
                     break;
                 default:
                     toIndex = 1;
                     break;
             }

            if (fromConnector == null || toConnector == null)
            {
                MessageBox.Show("DDTRelationToCanvas: the connection connects to a null DDTObject");
                return null;
            }

            type = getType(rel);

            connection = new Netron.NetronLight.DDTConnection(fromConnector, toConnector, diagramControl.controller.Model, type);

            connection.fromId = fromId;
            connection.toId = toId;
            connection.ID = rel.ID;
            connection.fromConnectorIndex = fromIndex;
            connection.toConnectorIndex = toIndex;

            /////////////////////////
            return connection;
        }