private bool PrepareConnection(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo, Action action) { // if we're not dealing with filter shapes... well, what the f**k?! get out of here! FilterSetupShapeBase shape = shapeAtCursorInfo.Shape as FilterSetupShapeBase; if (shape == null) throw new Exception("Can't connect a shape that isn't a FilterSetup shape!"); if (shape.OutputCount <= 0) return false; // get the starting control point for the line; ie. the first unused output for the shape, or the selected control point (if the mouse is over an output) ControlPointId connectionPoint = ControlPointId.None; if (shapeAtCursorInfo.IsCursorAtConnectionPoint && shape.GetTypeForControlPoint(shapeAtCursorInfo.ControlPointId) == FilterSetupShapeBase.FilterShapeControlPointType.Output) { connectionPoint = shapeAtCursorInfo.ControlPointId; } else { // try and find the first unconnected output if the mouse isn't over a specific control point for (int i = 0; i < shape.OutputCount; i++) { ControlPointId currentPoint = shape.GetControlPointIdForOutput(i); if (shape.GetConnectionInfos(currentPoint, null).Count() == 0) { connectionPoint = currentPoint; break; } } // if we couldn't find an unconnected point, just default to the first if (connectionPoint == ControlPointId.None) { connectionPoint = shape.GetControlPointIdForOutput(0); } } DataFlowConnectionLine line = (DataFlowConnectionLine) diagramPresenter.Project.ShapeTypes["DataFlowConnectionLine"].CreateInstance(); diagramPresenter.InsertShape(line); diagramPresenter.Diagram.Shapes.SetZOrder(line, 100); line.SecurityDomainName = ConfigFiltersAndPatching.SECURITY_DOMAIN_MOVABLE_SHAPE_WITH_CONNECTIONS; line.EndCapStyle = diagramPresenter.Project.Design.CapStyles.ClosedArrow; line.SourceDataFlowComponentReference = new DataFlowComponentReference(shape.DataFlowComponent, shape.GetOutputNumberForControlPoint( connectionPoint)); line.DestinationDataComponent = null; line.Connect(ControlPointId.FirstVertex, shape, connectionPoint); line.Disconnect(ControlPointId.LastVertex); line.MoveControlPointTo(ControlPointId.LastVertex, mouseState.X, mouseState.Y, ResizeModifiers.None); currentConnectionLine = line; StartToolAction(diagramPresenter, (int) action, ActionStartMouseState, true); return true; }