/// <summary> /// Create a floating connnection, i.e. not completely connected everywhere /// </summary> /// <param name="location"></param> private void FloatingConnection(PointF location) { if (m_FromElement is GraphicConnection) { GraphicConnection graphicConnection = m_FromElement as GraphicConnection; IConnectionItem connectionItem = graphicConnection.GetItemAt(m_LastMouseLocation); if (connectionItem is ConnectionNode) { //user clicked near a node at fist, connect to this ConnectionNode prevNode = connectionItem as ConnectionNode; location = ForceOrthogonality(prevNode.Location, m_Editor.AlignToGrid(location)); bool skip = false; //check whether the new line would just lenghten the previous line if (prevNode.Lines.Length == 1) { ConnectionLine prevLine = prevNode.Lines[0]; if (prevLine.LineStyle == ConnectionLine.DetermineLineStyle(prevNode.Location, location)) { //place the node at the new location in this case prevNode.Location = location; skip = true; } } if (skip == false) { //place a new line ConnectionNode node = new ConnectionNode(location); ConnectionLine line = new ConnectionLine(prevNode, node); m_FromElement.AddChild(node); m_FromElement.AddChild(line); m_FromElement = node; } } else if (connectionItem is ConnectionLine) { //user clicked near a line at first ConnectionLine prevLine = connectionItem as ConnectionLine; //place a connection node at location - split connection line ConnectionNode node = SplitConnectionLine(prevLine, m_LastMouseLocation); //the new node/line location = ForceOrthogonality(node.Location, m_Editor.AlignToGrid(location)); ConnectionNode fnode = new ConnectionNode(location); ConnectionLine line = new ConnectionLine(node, fnode); m_FromElement.AddChild(fnode); m_FromElement.AddChild(line); m_FromElement = fnode; } } else if (m_FromElement is GraphicTerminal) { //floating connection from a terminal GraphicTerminal graphicTerminal = m_FromElement as GraphicTerminal; location = ForceOrthogonality(graphicTerminal.ConnectionNode.Location, m_Editor.AlignToGrid(location)); ConnectionNode node = new ConnectionNode(location); ConnectionLine line = new ConnectionLine(node, graphicTerminal.ConnectionNode); GraphicConnection graphicConnection = GraphicObjectFactory.CreateInstance(typeof(Connection), new Connection()) as GraphicConnection; graphicConnection.Name = UniqueName.GetUniqueName(m_Editor.Circuit, typeof(Connection)); graphicConnection.AddChild(node); graphicConnection.AddChild(line); graphicConnection.ConnectTerminal(graphicTerminal); m_Editor.AddElement(graphicConnection); //proceed connecting with this node m_FromElement = node; } else if (m_FromElement is ConnectionNode) { //special case -> could be covered by "is GraphicConnection" //sequential floating lines ConnectionNode prevNode = m_FromElement as ConnectionNode; location = ForceOrthogonality(prevNode.Location, m_Editor.AlignToGrid(location)); bool skip = false; //check whether the new line would just lenghten the previous line if (prevNode.Lines.Length == 1) { ConnectionLine prevLine = prevNode.Lines[0]; if (prevLine.LineStyle == ConnectionLine.DetermineLineStyle(prevNode.Location, location)) { //place the node at the new location in this case prevNode.Location = location; skip = true; } } if (skip == false) { //place a new line ConnectionNode node = new ConnectionNode(location); ConnectionLine line = new ConnectionLine(prevNode, node); GraphicConnection graphicConnection = prevNode.Parent as GraphicConnection; graphicConnection.AddChild(node); graphicConnection.AddChild(line); m_FromElement = node; } } m_Editor.UpdateDrawing(); m_Editor.RaiseChangedEvent(); m_Editor.Invalidate(); }