/// <summary> /// /// </summary> /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> 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(); //reset highlight of the found connector if (foundConnector != null) { foundConnector.Hovered = false; } //drop the painted ghost Controller.View.ResetGhost(); //release other tools this.UnsuspendTools(); } }
/// <summary> /// /// </summary> /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> public void MouseUp(MouseEventArgs e) { if (IsActive) { // First, make sure the initial point is far enough away from // the final point to make a connection. int maxX = Math.Abs(Math.Max(initialPoint.X, e.Location.X)); int maxY = Math.Abs(Math.Max(initialPoint.Y, e.Location.Y)); if (!(maxX > ConnectionBase.MinLength) || !(maxY > ConnectionBase.MinLength)) { return; } //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 = this.Controller.Model.Selection.FindConnectorAt(initialPoint); IConnector endConnector = this.Controller.Model.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); #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"; package.Commands.Add(newcon); this.Controller.UndoManager.AddUndoCommand(package); //do it all package.Redo(); //reset highlight of the found connector if (foundConnector != null) foundConnector.Hovered = false; //drop the painted ghost Controller.View.ResetGhost(); this.doDraw = false; } }
/// <summary> /// /// </summary> /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> public void MouseUp(MouseEventArgs e) { if (IsActive) { // First, make sure the initial point is far enough away from // the final point to make a connection. int maxX = Math.Abs(Math.Max(initialPoint.X, e.Location.X)); int maxY = Math.Abs(Math.Max(initialPoint.Y, e.Location.Y)); if (!(maxX > ConnectionBase.MinLength) || !(maxY > ConnectionBase.MinLength)) { return; } //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 = this.Controller.Model.Selection.FindConnectorAt(initialPoint); IConnector endConnector = this.Controller.Model.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); #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"; package.Commands.Add(newcon); this.Controller.UndoManager.AddUndoCommand(package); //do it all package.Redo(); //reset highlight of the found connector if (foundConnector != null) { foundConnector.Hovered = false; } //drop the painted ghost Controller.View.ResetGhost(); this.doDraw = false; } }