public override void MouseMove(MouseButtons button, PointF location, Keys controlKeys) { if (m_Editor == null) { return; } GraphicBaseElement element = m_Editor.GetElementAt(location); if (element != m_SelectedElement && element is GraphicInputOutputElement) { m_SelectedElement = element; } if (m_HighLightElement != null && !m_HighLightElement.Equals(element) && m_HighLightElement.Highlighted) { //Un-Hover the element m_HighLightElement.Highlighted = false; m_HighLightElement = null; m_Editor.UpdateBackground(); m_Editor.Invalidate(); } if (element != null && !element.Highlighted && element is GraphicInputOutputElement) { //Hover an element m_HighLightElement = element; m_HighLightElement.Highlighted = true; m_Editor.UpdateBackground(); m_Editor.Invalidate(); } }
private void menuItem_OpenMacro_Click(object sender, EventArgs e) { if (macroForm == null) { macroForm = new MacroForm(); } if (macroForm.ShowDialog() == DialogResult.OK) { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(Macro), MacroCache.Instance.GetMacro(macroForm.SelectedMacro)); SetGateTool(element); int count = 0; foreach (ToolStripItem tsitem in btn_Macro.DropDownItems) { if (tsitem.Tag != null && tsitem.Tag is int && (int)tsitem.Tag == -10) { tsitem.Text = macroForm.LastSelectedMacros[count]; count++; } } while (count < macroForm.LastSelectedMacros.Count) { ToolStripMenuItem menuItem = new ToolStripMenuItem(macroForm.LastSelectedMacros[count]); menuItem.Click += new EventHandler(SelectRecentMacro); menuItem.Tag = -10; btn_Macro.DropDownItems.Add(menuItem); count++; } } }
/// <summary> /// Event handler when changes in elements occur /// </summary> /// <param name="sender"></param> /// <param name="completeDrawing">update complete drawing</param> private void element_OnUpdateDrawing(object sender, bool completeDrawing) { if (InvokeRequired) { //handle thread safety UpdateDrawingEvent d = new UpdateDrawingEvent(element_OnUpdateDrawing); Invoke(d, new object[] { sender, completeDrawing }); return; } if (completeDrawing) { UpdateDrawing(); Invalidate(); } else { // only update particular object GraphicBaseElement element = sender as GraphicBaseElement; if (element != null) { Graphics g = Graphics.FromImage(m_Drawing); element.Paint(g); Graphics control = this.CreateGraphics(); control.DrawImage(m_Drawing, 0, 0); } } }
private void combo_SymbolName_SelectedIndexChanged(object sender, EventArgs e) { if ((String)combo_SymbolName.SelectedItem == "AndGate") { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(AndGate), new AndGate(5)); element.Location = new PointF(8, 0); symbolView1.Element = element; } if ((String)combo_SymbolName.SelectedItem == "OrGate") { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(OrGate), new OrGate(5)); element.Location = new PointF(8, 0); symbolView1.Element = element; } if ((String)combo_SymbolName.SelectedItem == "NandGate") { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(NandGate), new NandGate(5)); element.Location = new PointF(8, 0); symbolView1.Element = element; } if ((String)combo_SymbolName.SelectedItem == "NorGate") { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(NorGate), new NorGate(5)); element.Location = new PointF(8, 0); symbolView1.Element = element; } if ((String)combo_SymbolName.SelectedItem == "NotGate") { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(NotGate), new NotGate()); element.Location = new PointF(8, 0); symbolView1.Element = element; } }
private void SetGateTool(GraphicBaseElement element) { m_CircuitTool = new GateTool(element); if (ActiveMdiChild is CircuitEditorForm) { (ActiveMdiChild as CircuitEditorForm).CircuitEditor.CurrentTool = m_CircuitTool; } }
public override void MouseClick(PointF location, Keys controlKeys) { GraphicBaseElement element = m_Editor.GetElementAt(location); if (element == null) { if (m_FromElement != null) { //floating connection - create a new connection line FloatingConnection(location); m_LastMouseLocation = location; } return; } if (element is GraphicInputOutputElement == false && element is GraphicConnection == false) { return; } //user clicked a terminal of an element GraphicInputOutputElement ioelem = element as GraphicInputOutputElement; GraphicTerminal graphicTerminal = null; if (ioelem != null) { graphicTerminal = ioelem.GetTerminalAt(location); if (graphicTerminal == null || graphicTerminal.Equals(m_FromElement)) { return; } if (m_FromElement == null) { m_FromElement = graphicTerminal; m_LastMouseLocation = location; return; } TryConnectToTerminal(graphicTerminal, location); m_LastMouseLocation = location; } //user clicked a connection GraphicConnection connection = element as GraphicConnection; if (connection != null) { if (connection.Equals(m_FromElement)) { return; } if (m_FromElement == null) { m_FromElement = connection; m_LastMouseLocation = location; return; } TryConnectToConnection(connection, location); m_LastMouseLocation = location; } }
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> /// Removes the highlight from an element /// </summary> /// <param name="element">element that has a highlight</param> private void UnHighlightElement(GraphicBaseElement element) { if (element != null && element.Highlighted) { m_ParentElement = null; m_HighLightElement = null; element.Highlighted = false; m_Editor.UpdateBackground(); m_Editor.Invalidate(); } }
public override void MouseUp(PointF location, Keys controlKeys) { if (m_Editor == null) { return; } if (m_SelectedElement != null) { DeleteElement(m_SelectedElement); } m_SelectedElement = null; }
public override void MouseClick(PointF location, Keys controlKeys) { if (m_Editor == null) { return; } GraphicBaseElement element = m_Editor.GetElementAt(location); if (element != null) { DeleteElement(element); } }
public override void MouseDown(PointF location, Keys controlKeys) { if (m_Editor == null) { return; } GraphicBaseElement element = m_Editor.GetElementAt(location); if (element != null) { //Select the element m_SelectedElement = element; } }
/// <summary> /// Removes an element from the circuit /// </summary> /// <param name="element">the element to remove</param> public void RemoveElement(GraphicBaseElement element) { if (element != null && m_Circuit.ContainsElement(element.LinkedObject as BaseElement)) { m_Circuit.RemoveElement(element.LinkedObject as BaseElement); element.OnUpdateDrawing -= element_OnUpdateDrawing; if (element is GraphicInput && element.LinkedObject is SignalInput) { m_SignalList.Remove((element.LinkedObject as SignalInput).Signal); } RaiseChangedEvent(); UpdateDrawing(); Invalidate(); } }
/// <summary> /// Adds a new element to the circuit /// </summary> /// <param name="element">the element to add</param> public void AddElement(GraphicBaseElement element) { if (element != null) { m_Circuit.AddElement(element.LinkedObject as BaseElement); element.OnUpdateDrawing += new UpdateDrawingEvent(element_OnUpdateDrawing); if (element is GraphicInput && element.LinkedObject is SignalInput) { m_SignalList.Add((element.LinkedObject as SignalInput).Signal); } RaiseChangedEvent(); UpdateDrawing(); Invalidate(); } }
/// <summary> /// Updates the circuit drawing /// </summary> public virtual void UpdateDrawing() { if (Width == 0 || Height == 0) { return; } m_Drawing = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(m_Drawing); g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, Width, Height); foreach (BaseElement logic in m_Circuit) { GraphicBaseElement element = logic.LinkedObject as GraphicBaseElement; element.Paint(g); } }
public override void MouseMove(MouseButtons button, PointF location, Keys controlKeys) { if (m_Editor == null) { return; } GraphicBaseElement element = m_Editor.GetElementAt(location); if (m_HighLightElement != null) { if (element == null || (element.Equals(m_ParentElement) == false && m_HighLightElement is GraphicTerminal) || (element.Equals(m_HighLightElement) == false && m_HighLightElement is GraphicConnection)) { //Un-Hover the element UnHighlightElement(m_HighLightElement); return; } } if (element is GraphicInputOutputElement) { GraphicInputOutputElement ioelem = element as GraphicInputOutputElement; GraphicTerminal graphicTerminal = ioelem.GetTerminalAt(location); if (graphicTerminal != null) { if ((graphicTerminal.LinkedObject as Terminal).IsConnected == false) { //Hover an element m_ParentElement = element; HighlightElement(graphicTerminal); } } else if (m_HighLightElement != null) { //Un-Hover the element UnHighlightElement(m_HighLightElement); } } if (element is GraphicConnection) { if (m_HighLightElement == null) { //Hover an element HighlightElement(element); } } }
private void SelectElementAt(PointF location) { if (m_Editor != null) { GraphicBaseElement element = m_Editor.GetElementAt(location); if (element != null) { //Select the element m_SelectedElement = element; m_SelectionOffset = new PointF(location.X - m_SelectedElement.Location.X, location.Y - m_SelectedElement.Location.Y); if (OnElementSelected != null) { OnElementSelected(this, new ElementSelectedEventArgs(element)); } } } }
/// <summary> /// Highlights an element /// </summary> /// <param name="element">element to highlight</param> private void HighlightElement(GraphicBaseElement element) { if (element != null) { if (!element.Highlighted) { m_HighLightElement = element; m_HighLightElement.Highlighted = true; m_Editor.UpdateBackground(); m_Editor.Invalidate(); } else { m_HighLightElement = element; } } }
void SelectRecentMacro(object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; if (menuItem == null) { return; } Macro macro = MacroCache.Instance.GetMacro(menuItem.Text); if (macro == null) { return; } GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(Macro), macro); SetGateTool(element); }
/// <summary> /// Connect to a Connection /// </summary> /// <param name="connection"></param> private void TryConnectToConnection(GraphicConnection connection, PointF location) { if (m_FromElement is GraphicTerminal) { Terminal fromTerminal = m_FromElement.LinkedObject as Terminal; if (fromTerminal.Connection != null) { MergeConnections(fromTerminal.Connection.LinkedObject as GraphicConnection, m_LastMouseLocation, connection, location); } else { IConnectionItem connectionItem = connection.GetItemAt(location); if (connectionItem is ConnectionNode) { //user clicked near a node - connect to this ConnectionLine line = new ConnectionLine((m_FromElement as GraphicTerminal).ConnectionNode, connectionItem as ConnectionNode); connection.AddChild(line); } else if (connectionItem is ConnectionLine) { //user clicked near a line ConnectionLine prevLine = connectionItem as ConnectionLine; //place a connection node at location - split connection line ConnectionNode node = SplitConnectionLine(prevLine, location); ConnectionLine line = new ConnectionLine(node, (m_FromElement as GraphicTerminal).ConnectionNode); connection.AddChild(line); } connection.ConnectTerminal(m_FromElement as GraphicTerminal); m_Editor.UpdateDrawing(); m_Editor.RaiseChangedEvent(); } } else if (m_FromElement is GraphicConnection) { MergeConnections(m_FromElement as GraphicConnection, m_LastMouseLocation, connection, location); } else if (m_FromElement is ConnectionNode) { MergeConnections(m_FromElement.Parent as GraphicConnection, m_LastMouseLocation, connection, location); //GraphicConnection fromConnection = m_FromElement.Parent as GraphicConnection; } m_FromElement = null; m_Editor.Invalidate(); }
private void DeleteElement(GraphicBaseElement element) { if (m_Editor == null) { return; } if (element is GraphicInputOutputElement) { //disconnect the element from all all connections InputOutputElement logicIO = (element.LinkedObject as InputOutputElement); foreach (Terminal terminal in logicIO.Inputs) { if (terminal.IsConnected == false) { continue; } Connection connection = terminal.Connection; //terminal.Disconnect(); connection.DisconnectTerminal(terminal); if (connection.Terminals.Count == 0) { m_Editor.RemoveElement(connection.LinkedObject as GraphicConnection); } } foreach (Terminal terminal in logicIO.Outputs) { if (terminal.IsConnected == false) { continue; } Connection connection = terminal.Connection; terminal.Disconnect(); if (connection.Terminals.Count == 0) { m_Editor.RemoveElement(connection.LinkedObject as GraphicConnection); } } //delete the element m_Editor.RemoveElement(element); } }
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); } } }
/// <summary> /// Updates the background drawing /// </summary> public virtual void UpdateBackground() { if (Width == 0 || Height == 0) { return; } m_Background = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(m_Background); g.FillRectangle(new SolidBrush(BackColor), 0, 0, Width, Height); Pen pen = new Pen(m_GridColor); if (GridSize.X > 0 && GridSize.Y > 0) { for (int i = m_GridSize.X; i < Width; i += m_GridSize.X) { for (int j = m_GridSize.X; j < Height; j += m_GridSize.Y) { if (m_GridMode.Equals(GridModes.Dots)) { (m_Background as Bitmap).SetPixel(i, j, m_GridColor); } if (m_GridMode.Equals(GridModes.Lines)) { g.DrawLine(pen, 0, j, Width, j); } } if (m_GridMode.Equals(GridModes.Lines)) { g.DrawLine(pen, i, 0, i, Height); } } } foreach (BaseElement logic in m_Circuit) { GraphicBaseElement element = logic.LinkedObject as GraphicBaseElement; //if (element.Highlighted) element.PaintBackground(g); } }
private void GenerateItems() { MacroCache macroCache = MacroCache.Instance; List <string> macroNames = macroCache.GetMacroNames(); macroNames.Sort(String.Compare); foreach (string name in macroNames) { //Symbol symbol = macroCache.GetSymbol(name); GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(Macro), MacroCache.Instance.GetMacro(name)); element.Location = new PointF(element.Bounds.X * -1, element.Bounds.Y * -1); int width = (int)element.Bounds.Width + 1; int height = (int)element.Bounds.Height + 1; if (width < 48) { width = 48; } if (height < 48) { height = 48; } if (width > 48 && height <= 48) { element.Location = new PointF(element.Location.X, element.Location.Y + (width - height)); height = width; } if (height > 48 && width <= 48) { element.Location = new PointF(element.Location.X + (height - width), element.Location.Y); width = height; } Image img = new Bitmap(width, height); element.Paint(Graphics.FromImage(img)); imageList_Symbols.Images.Add(name, img); ListViewItem item = listView_Macros.Items.Add(name, imageList_Symbols.Images.IndexOfKey(name)); } }
/// <summary> /// Returns the element at a given location /// </summary> /// <param name="location">Location of interest</param> /// <returns>Element at the given location or null respectively</returns> public GraphicBaseElement GetElementAt(PointF location) { //foreach (GraphicBaseElement element in m_Elements) foreach (BaseElement logic in m_Circuit) { GraphicBaseElement element = logic.LinkedObject as GraphicBaseElement; RectangleF bounds = element.Bounds; if (element is GraphicConnection) { GraphicConnection connection = element as GraphicConnection; if (connection.BelongsTo(location)) { return(element); } } if (bounds.Contains(location)) { return(element); } } return(null); }
public override void MouseMove(MouseButtons button, PointF location, Keys controlKeys) { if (m_Editor == null) { return; } if (button == MouseButtons.Left && m_SelectedElement != null && m_SelectedElement is GraphicConnection == false) { PointF newloc = m_Editor.AlignToGrid(new PointF(location.X - m_SelectionOffset.X, location.Y - m_SelectionOffset.Y)); if (newloc.Equals(m_SelectedElement.Location) == false) { //m_HighLightElement.Highlighted = false; m_SelectedElement.Location = newloc; m_Editor.RaiseChangedEvent(); m_Editor.UpdateBackground(); m_Editor.UpdateDrawing(); m_Editor.Invalidate(); } return; } GraphicBaseElement element = m_Editor.GetElementAt(location); if (m_HighLightElement != null && !m_HighLightElement.Equals(element) && m_HighLightElement.Highlighted) { //Un-Hover the element m_HighLightElement.Highlighted = false; m_HighLightElement = null; m_Editor.UpdateBackground(); m_Editor.Invalidate(); } if (element != null && !element.Highlighted) { //Hover an element m_HighLightElement = element; m_HighLightElement.Highlighted = true; m_Editor.UpdateBackground(); m_Editor.Invalidate(); } }
/// <summary> /// Constructor /// </summary> /// <param name="element">The selected element</param> public ElementSelectedEventArgs(GraphicBaseElement element) { m_Element = element; }
//private Connection ConvertConnectionData(ConnectionData connectionData) //directly done in CreateElements() //{ // Connection connection = new Connection(); // connection.Name = connectionData.Name; // return connection; //} private InputOutputElement ConvertElementData(BaseElementData elemData, bool createGraphics, Dictionary <BaseElement, BaseElementData> elemDict, SignalList signals) { InputOutputElement io = null; //determine type string desiredType = String.Empty; if (elemData is ClockData) { desiredType = typeof(Clock).Name; } if (elemData is ConstantInputData) { desiredType = typeof(ConstantInput).Name; } if (elemData is InputElementData) { desiredType = typeof(SignalInput).Name; } if (elemData is OutputElementData) { desiredType = typeof(SignalOutput).Name; } if (elemData is IOElementData) { desiredType = (elemData as IOElementData).Type; } if (elemData is MacroElementData) { desiredType = typeof(Macro).Name; MacroCache cache = MacroCache.Instance; MacroElementData macroElementData = elemData as MacroElementData; io = cache.GetMacro(macroElementData.Type); if (io == null) { string loaded = cache.LoadMacro(macroElementData.Reference); if (String.IsNullOrEmpty(loaded)) { throw new MacroReferenceNotFoundException(String.Format("Macro not found: \"{0}\".", macroElementData.Type)); } else if (loaded.CompareTo(macroElementData.Type) != 0) { throw new MacroReferenceTypeMismatchException(String.Format("Desired macro type \"{0}\" mismatches type \"{1}\" contained in file \"{2}\".", macroElementData.Type, loaded, macroElementData.Reference)); } io = cache.GetMacro(macroElementData.Type); } if (createGraphics) { GraphicBaseElement graphic = GraphicObjectFactory.CreateInstance(typeof(Macro), io); graphic.Location = new PointF(elemData.X, elemData.Y); } } if (String.IsNullOrEmpty(desiredType)) { throw new NotImplementedException(String.Format("Restoring of Type {0} not implemented", elemData.GetType().Name)); //return null; } //create instance of io element type type (not macros) foreach (Type type in m_ElementTypes) { if (type.Name.Equals(desiredType)) { io = (InputOutputElement)Activator.CreateInstance(type); if (elemData is InputElementData) { InputElementData inelemData = elemData as InputElementData; if (signals != null) { foreach (Signal signal in signals) { if (signal.Name.Equals(inelemData.SignalName)) { (io as SignalInput).Signal = signal; } } } } if (createGraphics) { GraphicBaseElement graphic = GraphicObjectFactory.CreateInstance(type, io); graphic.Location = new PointF(elemData.X, elemData.Y); } break; } } if (io == null) { return(null); } //restore terminals if (elemData is ClockData) { ClockData clockData = elemData as ClockData; io.OutputCount = clockData.Outputs.Length; RestoreTerminals(clockData.Outputs, io.Outputs); Clock clock = io as Clock; clock.HighDuration = clockData.HighDuration; clock.LowDuration = clockData.LowDuration; } if (elemData is ConstantInputData) { ConstantInputData inelemData = elemData as ConstantInputData; StateTypeConverter stateconv = new StateTypeConverter(); (io as ConstantInput).State = (State)stateconv.ConvertFromString(inelemData.State.Trim()); io.OutputCount = inelemData.Outputs.Length; RestoreTerminals(inelemData.Outputs, io.Outputs); } if (elemData is InputElementData) { InputElementData inelemData = elemData as InputElementData; io.OutputCount = inelemData.Outputs.Length; RestoreTerminals(inelemData.Outputs, io.Outputs); if (signals != null) { foreach (Signal signal in signals) { if (signal.Name.Equals(inelemData.SignalName)) { (io as SignalInput).Signal = signal; } } } } if (elemData is OutputElementData) { OutputElementData outelemData = elemData as OutputElementData; (io as SignalOutput).SignalName = outelemData.SignalName; io.InputCount = outelemData.Inputs.Length; RestoreTerminals(outelemData.Inputs, io.Inputs); } if (elemData is IOElementData || elemData is MacroElementData) { IOElementData ioelemData = elemData as IOElementData; io.InputCount = ioelemData.Inputs.Length; io.OutputCount = ioelemData.Outputs.Length; RestoreTerminals(ioelemData.Inputs, io.Inputs); RestoreTerminals(ioelemData.Outputs, io.Outputs); io.UpdateIndex = ioelemData.Index; io.UnitDelay = ioelemData.UnitDelay; io.NegEdgeDelay = ioelemData.NegativeEdgeDelay; io.PosEdgeDelay = ioelemData.PositiveEdgeDelay; } io.Name = elemData.Name; elemDict.Add(io, elemData); return(io); }
private void menuItem_Output_Click(object sender, EventArgs e) { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(SignalOutput), new SignalOutput()); circuitEditor.CurrentTool = new GateTool(element); }
private void menuItem_NOT_Click(object sender, EventArgs e) { GraphicBaseElement element = GraphicObjectFactory.CreateInstance(typeof(NotGate), new NotGate()); circuitEditor.CurrentTool = new GateTool(element); }
/// <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(); }