public override void MouseClick(PointF location, Keys controlKeys) { GraphicBaseElement element = m_Editor.GetElementAt(location); if (element == null) { return; } if (element is GraphicInputOutputElement == false && element is GraphicConnection == false) { return; } GraphicConnection graphicConnection = null; //user clicked a terminal of an element GraphicInputOutputElement ioelem = element as GraphicInputOutputElement; if (ioelem != null) { GraphicTerminal graphicTerminal = ioelem.GetTerminalAt(location); if (graphicTerminal != null) { Terminal terminal = (graphicTerminal.LinkedObject as Terminal); if (terminal.IsConnected) { Connection connection = terminal.Connection; graphicConnection = terminal.Connection.LinkedObject as GraphicConnection; graphicConnection.RemoveChild(graphicTerminal.ConnectionNode.Lines[0]); //terminal.Disconnect(); connection.DisconnectTerminal(terminal); if (connection.Terminals.Count == 0) { m_Editor.RemoveElement(connection.LinkedObject as GraphicConnection); } m_Editor.UpdateDrawing(); m_Editor.RaiseChangedEvent(); m_Editor.Invalidate(); } } } //user clicked a connection graphicConnection = element as GraphicConnection; if (graphicConnection != null) { foreach (GraphicBaseElement child in graphicConnection.Children) { graphicConnection.RemoveChild(child); } Connection connection = graphicConnection.LinkedObject as Connection; foreach (Terminal terminal in connection.Terminals) { //terminal.Disconnect(); connection.DisconnectTerminal(terminal); } m_Editor.RemoveElement(graphicConnection); } }
/// <summary> /// Splits the connection line at the given point and places a node there /// </summary> /// <param name="line">the line to split</param> /// <param name="atPoint">the point to place a node</param> /// <returns>the placed node</returns> private ConnectionNode SplitConnectionLine(ConnectionLine line, PointF atPoint) { GraphicConnection connection = line.Parent as GraphicConnection; ConnectionNode node = new ConnectionNode(line.NearestPointOnLine(m_Editor.AlignToGrid(atPoint))); ConnectionLine line1 = new ConnectionLine(line.Nodes[0], node); ConnectionLine line2 = new ConnectionLine(line.Nodes[1], node); connection.RemoveChild(line); connection.AddChild(node); connection.AddChild(line1); connection.AddChild(line2); return(node); }
/// <summary> /// Connect to a Terminal (resp. its connection) /// </summary> /// <param name="graphicTerminal"></param> private void TryConnectToTerminal(GraphicTerminal graphicTerminal, PointF location) { Terminal toTerminal = graphicTerminal.LinkedObject as Terminal; if (toTerminal.Connection != null) { //merging connections not supported by clicking terminals return; } if (m_FromElement is GraphicTerminal) { Terminal fromTerminal = m_FromElement.LinkedObject as Terminal; //if (fromTerminal.Connection != null && toTerminal.Connection != null) //{ // MergeConnections(fromTerminal.Connection.LinkedObject as GraphicConnection, m_LastMouseLocation, // toTerminal.Connection.LinkedObject as GraphicConnection, location); //} //else if (fromTerminal.Connection != null) //{ // //IDEE: suche über allen linien die kürzeste entfernung vom ziel zur verbindung // GraphicConnection graphicConnection = fromTerminal.Connection.LinkedObject as GraphicConnection; // ConnectionLine line = new ConnectionLine((m_FromElement as GraphicTerminal).ConnectionNode, graphicTerminal.ConnectionNode); // graphicConnection.AddChild(line); // graphicConnection.ConnectTerminal(graphicTerminal); // m_Editor.UpdateDrawing(); // m_Editor.RaiseChangedEvent(); //} //else if (toTerminal.Connection != null) //{ // GraphicConnection graphicConnection = toTerminal.Connection.LinkedObject as GraphicConnection; // graphicConnection.ConnectTerminal(m_FromElement as GraphicTerminal); // m_Editor.UpdateDrawing(); // m_Editor.RaiseChangedEvent(); //} //else if (fromTerminal.Connection == null && toTerminal.Connection == null) { GraphicTerminal fromGraphicTerminal = m_FromElement as GraphicTerminal; if (IsOrthogonal(fromGraphicTerminal.ConnectionNode.Location, graphicTerminal.ConnectionNode.Location) == false) { return; } GraphicConnection graphicConnection = GraphicObjectFactory.CreateInstance(typeof(Connection), new Connection()) as GraphicConnection; graphicConnection.Name = UniqueName.GetUniqueName(m_Editor.Circuit, typeof(Connection)); graphicConnection.ConnectTerminal(fromGraphicTerminal); graphicConnection.ConnectTerminal(graphicTerminal); ConnectionLine line = new ConnectionLine(fromGraphicTerminal.ConnectionNode, graphicTerminal.ConnectionNode); graphicConnection.AddChild(line); m_Editor.AddElement(graphicConnection); m_Editor.UpdateDrawing(); m_Editor.RaiseChangedEvent(); } } if (m_FromElement is GraphicConnection) { GraphicConnection fromConnection = m_FromElement as GraphicConnection; IConnectionItem connectionItem = fromConnection.GetItemAt(m_LastMouseLocation); if (connectionItem is ConnectionNode) { ConnectionLine line = new ConnectionLine(connectionItem as ConnectionNode, graphicTerminal.ConnectionNode); fromConnection.AddChild(line); } else if (connectionItem is ConnectionLine) { ConnectionLine prevLine = connectionItem as ConnectionLine; ConnectionNode node = new ConnectionNode(prevLine.NearestPointOnLine(m_LastMouseLocation)); ConnectionLine line1 = new ConnectionLine(prevLine.Nodes[0], node); ConnectionLine line2 = new ConnectionLine(prevLine.Nodes[1], node); fromConnection.RemoveChild(prevLine); fromConnection.AddChild(node); fromConnection.AddChild(line1); fromConnection.AddChild(line2); ConnectionLine line = new ConnectionLine(node, graphicTerminal.ConnectionNode); fromConnection.AddChild(line); } fromConnection.ConnectTerminal(graphicTerminal); m_Editor.UpdateDrawing(); m_Editor.RaiseChangedEvent(); } if (m_FromElement is ConnectionNode) { m_FromElement.Location = ForceOrthogonality(graphicTerminal.ConnectionNode.Location, m_FromElement.Location); ConnectionLine line = new ConnectionLine(m_FromElement as ConnectionNode, graphicTerminal.ConnectionNode); m_FromElement.Parent.AddChild(line); (m_FromElement.Parent as GraphicConnection).ConnectTerminal(graphicTerminal); m_Editor.UpdateDrawing(); m_Editor.RaiseChangedEvent(); } m_FromElement = null; m_Editor.Invalidate(); }