Exemple #1
0
        private void _pictureBox_MouseDown(Object sender, MouseEventArgs e)
        {
            Point contextPosition = new Point(e.Location.X - HorizontalScroll.Value, e.Location.Y - VerticalScroll.Value);

            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);
        }
Exemple #2
0
 public void AddNode(NodeBase nodeToAdd, Point position)
 {
     nodeToAdd.Update(position, CreateGraphics(), Font);
     _selectedProgram.AddNode(nodeToAdd);
     _pictureBox.Invalidate();
 }
Exemple #3
0
        /*
         * RemoveNode
         */

        public void RemoveNode(NodeBase nodeToRemove)
        {
            _selectedProgram.RemoveNode(nodeToRemove);
        }
Exemple #4
0
		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);
		}
Exemple #5
0
        /*
         * AddNode
         */

        public void AddNode(NodeBase nodeToAdd)
        {
            AddNode(nodeToAdd, new Point(0, 0));
        }
Exemple #6
0
		/*
		 * RemoveNode
		 */

		public void RemoveNode(NodeBase nodeToRemove)
		{
			_selectedProgram.RemoveNode(nodeToRemove);
		}
Exemple #7
0
		/*
		 * RemoveSelectedNode
		 */

		public void RemoveSelectedNode()
		{
			if (_selectedNode == null)
			{
				return;
			}

			RemoveNode(_selectedNode);
			_selectedNode = null;
		}
Exemple #8
0
		/*
		 * NewSchema
		 */

		public void NewSchema()
		{
			_program = new Program();
			_selectedProgram = _program;
			_selectedNode = null;
			_selectedPort = null;
		}
Exemple #9
0
		/*
		 * OpenSchema
		 */

		public void OpenSchema(String fileName)
		{
			_program = Program.Load(fileName);
			_selectedProgram = _program;
			_selectedNode = null;
			_selectedPort = null;
		}
Exemple #10
0
		public void AddNode(NodeBase nodeToAdd, Point position)
		{
			nodeToAdd.Update(position, CreateGraphics(), Font);
			_selectedProgram.AddNode(nodeToAdd);
			_pictureBox.Invalidate();
		}
Exemple #11
0
		/*
		 * InsertSchema
		 */

		public void InsertSchema(String fileName)
		{
			_selectedNode = null;
			ProgramNode programNode = Program.Insert(fileName);
			programNode.SubProgram.ParentProgram = _selectedProgram;
			Point location = new Point(SchemaRectangle.X + 10, SchemaRectangle.Y + 10);
			programNode.Update(location, CreateGraphics(), Font);
			_selectedProgram.AddNode(programNode);
		}
Exemple #12
0
		/*
		 * AddNode
		 */

		public void AddNode(NodeBase nodeToAdd)
		{
			AddNode(nodeToAdd, new Point(0, 0));
		}
Exemple #13
0
		/*
		 * RemoveNode
		 */

		public void RemoveNode(NodeBase nodeToRemove)
		{
			_selectedProgram.RemoveNode(nodeToRemove);
			SaveIsNeeded = true;
		}
Exemple #14
0
		/// <summary>
		/// Initializes a new instance of the <see cref="NodePort"/> class.
		/// </summary>
		/// <param name="node"></param>
		/// <param name="index"></param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="node"/> is <see langword="null"/>.</para>
		/// </exception>
		public NodePort(NodeBase node, Int32 index)
		{
			if (node == null)
			{
				throw new ArgumentNullException("node");
			}

			_node = node;
			_index = index;
		}
Exemple #15
0
        /*
         * RemoveNode
         */

        public void RemoveNode(NodeBase nodeToRemove)
        {
            _selectedProgram.RemoveNode(nodeToRemove);
            SaveIsNeeded = true;
        }
Exemple #16
0
        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) });
                        }
                }
            }
        }