Exemplo n.º 1
0
 private void NewPartElementHandler(object sender, NewSymbolPartEventArgs e)
 {
     if (e.SymbolPart != null)
     {
         if (e.SymbolPart is PortPart)
         {
             (e.SymbolPart as PortPart).Name = UniqueName.GetUniquePortName(m_Symbol);
         }
         e.SymbolPart.OnUpdateDrawing += new UpdateDrawingEvent(SymbolPart_OnUpdateDrawing);
         m_Symbol.AddPart(e.SymbolPart);
         RaiseChangedEvent();
         UpdateDrawing();
         Invalidate();
     }
 }
Exemplo n.º 2
0
 public override void MouseClick(PointF location, Keys controlKeys)
 {
     if (m_Editor != null)
     {
         if (m_Editor.GetElementAt(location) == null)
         {
             GraphicBaseElement element = GraphicObjectFactory.CreateClone(m_GraphicElement);
             element.Name = UniqueName.GetUniqueName(m_Editor.Circuit, m_GraphicElement.LinkedObject.GetType());
             if (element is GraphicInput)
             {
                 (element as GraphicInput).SignalName = UniqueName.GetUniqueSignalName(m_Editor.Circuit);
             }
             if (element is GraphicOutput)
             {
                 (element.LinkedObject as SignalOutput).SignalName = UniqueName.GetUniqueSignalName(m_Editor.Circuit);
             }
             element.Location = m_Editor.AlignToGrid(location);
             m_Editor.AddElement(element);
         }
     }
 }
Exemplo n.º 3
0
        /// <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();
        }
Exemplo n.º 4
0
        /// <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();
        }