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();
            }
        }
Exemplo n.º 2
0
        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
                Connection           cn     = new Connection(this.initialPoint, e.Location, this.Controller.Model);
                AddConnectionCommand newcon = new AddConnectionCommand(this.Controller, cn);
                package.Commands.Add(newcon);
                #endregion

                #region Initial attachment?
                if (startConnector != null)
                {
                    BindConnectorsCommand bindStart = new BindConnectorsCommand(this.Controller, startConnector, cn.From);
                    package.Commands.Add(bindStart);
                }
                #endregion

                #region Final attachment?
                if (endConnector != null)
                {
                    BindConnectorsCommand bindEnd = new BindConnectorsCommand(this.Controller, endConnector, cn.To);
                    package.Commands.Add(bindEnd);
                }
                #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();
            }
        }
Exemplo n.º 3
0
        public void MouseUp(MouseEventArgs e)
        {
            if (IsActive)
            {
                DeactivateTool();
                //creation of the total undoredo package
                CompoundCommand package = new CompoundCommand(this.Controller);
                string          message = string.Empty;
                //notice that the connector can only be a connection connector because of the MouseDown check above
                if (connectorMove)
                {
                    #region We are moving a connection-connector

                    #region Is the connector attached?
                    //detach only if there is a parent different than a connection; the join of a chained connection is allowed to move
                    if (Selection.Connector.AttachedTo != null && !typeof(IConnection).IsInstanceOfType(Selection.Connector.AttachedTo))
                    {
                        DetachConnectorCommand detach = new DetachConnectorCommand(this.Controller, Selection.Connector.AttachedTo, Selection.Connector);
                        detach.Redo();
                        package.Commands.Add(detach);
                    }
                    #endregion

                    #region The moving part
                    //a bundle might look like overkill here but it makes the coding model uniform
                    Bundle bundle = new Bundle(Controller.Model);
                    bundle.Entities.Add(Selection.Connector);
                    MoveCommand move = new MoveCommand(this.Controller, bundle, new Point(lastPoint.X - initialPoint.X, lastPoint.Y - initialPoint.Y));
                    //no Redo() necessary here!
                    package.Commands.Add(move);
                    #endregion

                    #region The re-attachment near another connector
                    //let's see if the connection endpoints hit other connectors (different than the selected one!)
                    //define a predicate delegate to filter things out otherwise the hit will return the moved connector which would results
                    //in a stack overflow later on
                    Predicate <IConnector> predicate =
                        delegate(IConnector conn)
                    {
                        //whatever, except itself and any children of the moved connector
                        //since this would entail a child becoming a parent!
                        if (conn.Hit(e.Location) && conn != Selection.Connector && !Selection.Connector.AttachedConnectors.Contains(conn))
                        {
                            return(true);
                        }
                        return(false);
                    };
                    //find it!
                    IConnector parentConnector = Selection.FindConnector(predicate);

                    if (parentConnector != null) //aha, there's an attachment
                    {
                        BindConnectorsCommand binder = new BindConnectorsCommand(this.Controller, parentConnector, Selection.Connector);
                        package.Commands.Add(binder);
                        binder.Redo(); //this one is necessary since the redo cannot be performed on the whole compound command
                    }
                    #endregion

                    message = "Connector move";
                    #endregion
                }
                else
                {
                    #region We are moving entities other than a connector
                    Bundle bundle = new Bundle(Controller.Model);
                    bundle.Entities.AddRange(Selection.SelectedItems);
                    MoveCommand cmd = new MoveCommand(this.Controller, bundle, new Point(lastPoint.X - initialPoint.X, lastPoint.Y - initialPoint.Y));
                    package.Commands.Add(cmd);
                    //not necessary to perform the Redo action of the command since the mouse-move already moved the bundle!
                    #endregion

                    message = "Entities move";
                }
                package.Text = message;
                //whatever the content of the package we add it to the undo history
                this.Controller.UndoManager.AddUndoCommand(package);

                //show the tracker again
                this.Controller.View.ShowTracker();
            }
        }
Exemplo n.º 4
0
        public void MouseUp(MouseEventArgs e)
        {
            if(IsActive)
            {
                DeactivateTool();
                //creation of the total undoredo package
                CompoundCommand package = new CompoundCommand(this.Controller);
                string message = string.Empty;
                //notice that the connector can only be a connection connector because of the MouseDown check above
                if(connectorMove)
                {
                    #region We are moving a connection-connector

                    #region Is the connector attached?
                    //detach only if there is a parent different than a connection; the join of a chained connection is allowed to move
                    if( Selection.Connector.AttachedTo != null && !typeof(IConnection).IsInstanceOfType(Selection.Connector.AttachedTo))
                    {
                        DetachConnectorCommand detach = new DetachConnectorCommand(this.Controller, Selection.Connector.AttachedTo, Selection.Connector);
                        detach.Redo();
                        package.Commands.Add(detach);

                    }
                    #endregion

                    #region The moving part
                    //a bundle might look like overkill here but it makes the coding model uniform
                    Bundle bundle = new Bundle(Controller.Model);
                    bundle.Entities.Add(Selection.Connector);
                    MoveCommand move = new MoveCommand(this.Controller, bundle, new Point(lastPoint.X - initialPoint.X, lastPoint.Y - initialPoint.Y));
                    //no Redo() necessary here!
                    package.Commands.Add(move);
                    #endregion

                    #region The re-attachment near another connector
                    //let's see if the connection endpoints hit other connectors (different than the selected one!)
                    //define a predicate delegate to filter things out otherwise the hit will return the moved connector which would results
                    //in a stack overflow later on
                    Predicate<IConnector> predicate =
                        delegate(IConnector conn)
                        {
                            //whatever, except itself and any children of the moved connector
                            //since this would entail a child becoming a parent!
                            if(conn.Hit(e.Location) && conn != Selection.Connector && !Selection.Connector.AttachedConnectors.Contains(conn))
                                return true;
                            return false;
                        };
                    //find it!
                    IConnector parentConnector = Selection.FindConnector(predicate);

                    if(parentConnector != null) //aha, there's an attachment
                    {
                        BindConnectorsCommand binder = new BindConnectorsCommand(this.Controller, parentConnector, Selection.Connector);
                        package.Commands.Add(binder);
                        binder.Redo(); //this one is necessary since the redo cannot be performed on the whole compound command

                        // change the DDTConnection properties
                        if (Selection.Connector.Equals(((DDTConnection)Selection.Connector.Parent).From))
                        {
                            ((DDTConnection)Selection.Connector.Parent).fromId = ((IDDTObject)parentConnector.Parent).ID;
                            ((DDTConnection)Selection.Connector.Parent).fromConnectorIndex = DDTConnectionTool.getConnectorIndex(parentConnector);

                           // MessageBox.Show(((DDTConnection)Selection.Connector.Parent).fromId.ToString()); //connection
                           // MessageBox.Show(((DDTConnection)Selection.Connector.Parent).fromConnectorIndex.ToString());  //object
                        }
                        else //equals To
                        {
                            ((DDTConnection)Selection.Connector.Parent).toId = ((IDDTObject)parentConnector.Parent).ID;
                            ((DDTConnection)Selection.Connector.Parent).toConnectorIndex = DDTConnectionTool.getConnectorIndex(parentConnector);

                            //MessageBox.Show(((DDTConnection)Selection.Connector.Parent).toId.ToString()); //connection
                           // MessageBox.Show(((DDTConnection)Selection.Connector.Parent).toConnectorIndex.ToString());  //object
                        }

                    }
                    #endregion

                    message = "Connector move";
                    #endregion
                }
                else
                {
                    #region We are moving entities other than a connector
                    Bundle bundle = new Bundle(Controller.Model);
                    bundle.Entities.AddRange(Selection.SelectedItems);
                    MoveCommand cmd = new MoveCommand(this.Controller, bundle, new Point(lastPoint.X - initialPoint.X, lastPoint.Y - initialPoint.Y));
                    package.Commands.Add(cmd);
                    //not necessary to perform the Redo action of the command since the mouse-move already moved the bundle!
                    #endregion

                    message = "Entities move";
                }
                package.Text = message;
                //whatever the content of the package we add it to the undo history
                this.Controller.UndoManager.AddUndoCommand(package);

                //show the tracker again
                this.Controller.View.ShowTracker();

            }
        }