public virtual void DrawConnections(Graphics g, Color outlineColor, NodePort selectedPort) { if (g == null) { throw new ArgumentNullException("g"); } for (Int32 i = 0; i < InputsLength; i++) { if (GetInput(i).Connection != null) { Color color = Color.Black; if (Object.ReferenceEquals(GetInput(i), selectedPort)) { color = outlineColor; } NodeBase currentNode = GetInput(i).Connection.Node; Int32 connectionIndex = 0; for (Int32 j = 0; j < currentNode.OutputsLength; j++) { if (Object.ReferenceEquals(currentNode.GetOutput(j), GetInput(i).Connection)) { connectionIndex = j; break; } } /* Calculate extreme points. */ Point output = new Point( currentNode.BodyRectangle.X + currentNode.BodyRectangle.Width , currentNode.BodyRectangle.Y + connectionIndex * currentNode.HeaderRectangle.Height + currentNode.HeaderRectangle.Height / 2 + 1 ); Point input = new Point( BodyRectangle.X , BodyRectangle.Y + i * HeaderRectangle.Height + HeaderRectangle.Height / 2 + 1 ); /* Draw connection shadow and the connection itself. */ g.DrawBezier( _connectionPen , input , new Point(input.X - 26, input.Y + 4) , new Point(output.X + 34, output.Y + 4) , output ); using (SolidBrush sb = new SolidBrush(color)) using (Pen pen = new Pen(sb, 2f)) { g.DrawBezier(pen, input, new Point(input.X - 30, input.Y), new Point(output.X + 30, output.Y), output); g.FillPolygon(sb, new Point[] { new Point(input.X - 5, input.Y - 5), input, new Point(input.X - 5, input.Y + 5) }); } } } }
private void SetInput(Int32 index, String name, Object data, NodePort connection) { _inputs[index] = new NodePort(this, index); _inputs[index].Name = name; _inputs[index].Data = data; _inputs[index].Connection = connection; }
public void SetOutput(Int32 index, String name, Object data) { _outputs[index] = new NodePort(this, index); _outputs[index].Name = name; _outputs[index].Data = data; }
public void SetInput(Int32 index, String name, NodePort connection) { SetInput(index, name, null, connection); }
private void _pictureBox_MouseDown(Object sender, MouseEventArgs e) { Point contextPosition = new Point(e.X, e.Y); if (_selectedProgram != null) { Boolean go = true; _selectedNode = null; if (_selectedProgram.Nodes.Count > 0) { Int32 mx = Convert.ToInt32(e.X / _scale); Int32 my = Convert.ToInt32(e.Y / _scale); _px = mx; _px = my; if (e.Button == MouseButtons.Left && _selectOperations) { // Select node. // Loop backwards to select the one on top. for (Int32 i = _selectedProgram.Nodes.Count - 1; i >= 0; i--) { NodeBase node = _selectedProgram.Nodes[i]; if (node.HeaderRectangle.IntersectsWith(new Rectangle(mx, my, 1, 1))) { _selectedNode = node; _px = mx - node.ClientRectangle.X; _py = my - node.ClientRectangle.Y; _selectedProgram.Nodes.Insert(_selectedProgram.Nodes.Count, _selectedNode); _selectedProgram.Nodes.RemoveAt(i); i = -1; } } // Connect port. if (_selectedPort != null) { for (Int32 i = 0; i < _selectedProgram.Nodes.Count; i++) { NodeBase node = _selectedProgram.Nodes[i]; if (node.BodyRectangle.IntersectsWith(new Rectangle(mx, my, 1, 1))) { for (Int32 j = 0; j < node.OutputsLength; j++) { if (node.OutputRectCollection[j].IntersectsWith(new Rectangle(mx, my, 1, 1))) { if (_testConnections) { if (_selectedPort.IsCompatibleConnection(node.GetOutput(j))) { _selectedPort.Connection = node.GetOutput(j); } } else { _selectedPort.Connection = node.GetOutput(j); } } } } } } // Select port. _selectedPort = null; for (Int32 i = 0; i < _selectedProgram.Nodes.Count; i++) { NodeBase node = _selectedProgram.Nodes[i]; if (node.BodyRectangle.IntersectsWith(new Rectangle(mx, my, 1, 1))) { for (Int32 j = 0; j < node.InputsLength; j++) { if (node.InputRectCollection[j].IntersectsWith(new Rectangle(mx, my, 1, 1))) { _selectedPort = node.GetInput(j); } } } } } if (e.Button == MouseButtons.Right && _removeOperations) { // Remove node for (Int32 i = 0; i < _selectedProgram.Nodes.Count; i++) { NodeBase node = _selectedProgram.Nodes[i]; if (node.HeaderRectangle.IntersectsWith(new Rectangle(mx, my, 1, 1))) { _selectedNode = node; } } if (_selectedNode != null) { ContextMenu conextMenu = new ContextMenu(); MenuItem deleteNodeMenuItem = new MenuItem(Resources.Text_DeleteNode); deleteNodeMenuItem.Click += delegate { RemoveNode(_selectedNode); }; go = false; conextMenu.MenuItems.Add(deleteNodeMenuItem); conextMenu.Show(this, contextPosition); } // Remove connection _selectedPort = null; for (Int32 i = 0; i < _selectedProgram.Nodes.Count; i++) { NodeBase node = _selectedProgram.Nodes[i]; if (node.BodyRectangle.IntersectsWith(new Rectangle(mx, my, 1, 1))) { for (Int32 j = 0; j < node.InputsLength; j++) { if (node.InputRectCollection[j].IntersectsWith(new Rectangle(mx, my, 1, 1))) { _selectedPort = node.GetInput(j); } } } } if (_selectedPort != null) { go = false; ContextMenu contextMenu = new ContextMenu(); MenuItem removeConnectionMenuItem = new MenuItem(Resources.Text_RemoveConnection); removeConnectionMenuItem.Click += delegate { _selectedPort.Connection = null; }; contextMenu.MenuItems.Add(removeConnectionMenuItem); contextMenu.Show(this, contextPosition); } } } if (e.Button == MouseButtons.Right && _upOperations) { // Go to parent program. if (go) { if (_selectedNode == null) { if (_selectedProgram.ParentProgram != null) { foreach (NodeBase node in _selectedProgram.ParentProgram.Nodes) { node.Update(new Point(node.HeaderRectangle.X, node.HeaderRectangle.Y), CreateGraphics(), Font); } _selectedProgram = _selectedProgram.ParentProgram; } } } } } _pictureBox.Invalidate(); OnMouseDown(e); }
/* * OpenSchema */ public void OpenSchema(String fileName) { _program = Program.Load(fileName); _selectedProgram = _program; _selectedNode = null; _selectedPort = null; }
/* * NewSchema */ public void NewSchema() { _program = new Program(); _selectedProgram = _program; _selectedNode = null; _selectedPort = null; }
/* * IsCompatibleConnection */ /// <summary> /// </summary> /// <param name="nodePortToCheck"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// <para><paramref name="nodePortToCheck"/> is <see langword="null"/>.</para> /// </exception> public Boolean IsCompatibleConnection(NodePort nodePortToCheck) { if (nodePortToCheck == null) { throw new ArgumentNullException("nodePortToCheck"); } try { if (_data != null && nodePortToCheck._data != null) { Type dataType = _data.GetType(); Type anotherDataType = nodePortToCheck._data.GetType(); return dataType == anotherDataType; } } catch { return true; } return false; }