private void AddConnectionInfo(IConnectionInfo connectionInfo) { this.RegisterConnectionInfoEvents(connectionInfo); IShape shapeFrom = this.shapeInfoShapeMapping.GetByFirst(connectionInfo.From); IShape shapeTo = this.shapeInfoShapeMapping.GetByFirst(connectionInfo.To); IConnector connectorFrom = shapeFrom.Connectors.Where(c => c.Name == connectionInfo.ConnectorFrom).FirstOrDefault(); IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == connectionInfo.ConnectorTo).FirstOrDefault(); if (connectorFrom != null && connectorTo != null) { Connection connection = new Connection(connectorFrom.Point, connectorTo.Point); connection.From.AllowMove = false; connection.To.AllowMove = false; connectorFrom.AttachConnector(connection.From); connectorTo.AttachConnector(connection.To); connection.PenStyle = this.connectionPenStyle; this.connectionInfoConnectionMapping.Add(connectionInfo, connection); this.graphVisualization.Controller.Model.AddConnection(connection); this.graphVisualization.Invalidate(); } }
/// <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> /// Adds a connection between two shape connectors. /// </summary> /// <param name="from">From connector.</param> /// <param name="to">To connector.</param> // ------------------------------------------------------------------ public IConnection AddConnection(IConnector from, IConnector to) { Connection con = new Connection(from.Point, to.Point); this.AddConnection(con); return con; }
public override void OnPortDrivesSignal(Signal signal, Port port, int outputIndex) { SignalShape ss = _bridge.Signals[signal.InstanceId]; PortShape ps = _bridge.Ports[port.InstanceId]; IConnector sc = ss.InputConnector; IConnector pc = ps.OutputConnectors[outputIndex]; Connection cn = new Connection(Point.Empty, Point.Empty); pc.AttachConnector(cn.From); sc.AttachConnector(cn.To); _bridge.Model.AddConnection(cn); ss.Location = new Point(pc.Point.X - 16, pc.Point.Y - 10); _bridge.Model.SendToFront(ss); }
public override void OnSignalDrivesPort(Signal signal, Port port, int inputIndex) { SignalShape ss = _bridge.Signals[signal.InstanceId]; PortShape ps = _bridge.Ports[port.InstanceId]; IConnector sc = ss.OutputConnector; IConnector pc = ps.InputConnectors[inputIndex]; Connection cn = new Connection(Point.Empty, Point.Empty); sc.AttachConnector(cn.From); pc.AttachConnector(cn.To); _bridge.Model.AddConnection(cn); }
public override void OnSignalDrivesPort(Signal signal, Port port, int inputIndex) { if(maskMDrives) return; bool wasMasked = maskNDrives; try { maskNDrives = true; SignalShape ss = _bridge.Signals[signal.InstanceId]; PortShape ps = _bridge.Ports[port.InstanceId]; IConnector sc = ss.OutputConnector; IConnector pc = ps.InputConnectors[inputIndex]; Connection cn = new Connection(Point.Empty, Point.Empty); _bridge.Model.AddConnection(cn); sc.AttachConnector(cn.From); pc.AttachConnector(cn.To); } finally { maskNDrives = wasMasked; } }
/// <summary> /// Adds a connection to the diagram. /// </summary> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns></returns> public IConnection AddConnection(IConnector from, IConnector to) { Connection cn = new Connection(Point.Empty, Point.Empty); this.AddConnection(cn); from.AttachConnector(cn.From); to.AttachConnector(cn.To); return cn; }