예제 #1
0
 public void RemoveConnector(ActionConnector r)
 {
     if (connectors.Contains(r))
     {
         connectors.Remove(r);
     }
 }
예제 #2
0
        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            //местим, когато не чертаем Flow и ActionConnector
            if (!btnFlow.Checked && !btnActionConnector.Checked && (e.Button == MouseButtons.Left && selectedIndex > -1 && items[selectedIndex] is BuildingBlock))
            {
                Point newPosition = new Point();
                newPosition.X = ((BuildingBlock)items[selectedIndex]).GetBounds().X + e.X - x;
                newPosition.Y = ((BuildingBlock)items[selectedIndex]).GetBounds().Y + e.Y - y;
                x             = e.X;
                y             = e.Y;

                ((BuildingBlock)items[selectedIndex]).Move(newPosition);

                this.panel1.Refresh();
            }
            //
            else if (btnActionConnector.Checked)
            {
                if (this.startItem != null && startItem is BuildingBlock)
                {
                    this.Refresh();
                    Graphics g = this.panel1.CreateGraphics();
                    ActionConnector.Draw(startItem, new Point(e.X, e.Y), g);
                    g.Dispose();
                }
            }
            else if (btnFlow.Checked)
            {
                if (startItem != null)
                {
                    this.panel1.Refresh();
                    Graphics g = this.panel1.CreateGraphics();

                    //средната точка на правоъгълника на startItem
                    Point startP = new Point(startItem.GetBounds().X + startItem.GetBounds().Width / 2,
                                             startItem.GetBounds().Y + startItem.GetBounds().Height / 2);

                    Flow.Draw(startP, new Point(e.X, e.Y), g);

                    g.Dispose();
                }

                else if (startPoint.X > -1 && startPoint.Y > -1)
                {
                    this.panel1.Refresh();
                    Graphics g = this.panel1.CreateGraphics();

                    Flow.Draw(startPoint, new Point(e.X, e.Y), g);

                    g.Dispose();
                }
            }
        }
예제 #3
0
 public void Connect(ActionConnector r)
 {
     this.connectors.Add(r);
 }
예제 #4
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            Point mouseCoord = new Point(e.X, e.Y);

            //селектираме, ако мишката е върху съществуващ итем
            SelectClickedOnItem(mouseCoord);

            if (e.Button == MouseButtons.Left)
            {
                //добавяме конектор
                if (btnActionConnector.Checked)
                {
                    //начален итем
                    if (this.selectedIndex > -1 && this.startItem == null && items[selectedIndex] is BuildingBlock)
                    {
                        this.startItem = (BuildingBlock)items[selectedIndex];
                        return; // излизаме преди да се деселектира бутона Action Connector
                    }
                    //краен итем и създаване и добавяне в списъка
                    else if (this.selectedIndex > -1 && items[selectedIndex] is BuildingBlock)
                    {
                        if (startItem != (BuildingBlock)items[selectedIndex])
                        {
                            ActionConnector connector = new ActionConnector(startItem, (BuildingBlock)items[selectedIndex]);
                            this.connectors.Add(connector);
                            this.startItem = null;
                        }
                        //DeselectAndRefresh();
                    }
                    DeselectAndRefresh();
                }


                //добавяме flow
                else if (btnFlow.Checked)
                {
                    //начална точка
                    if (startItem == null && (startPoint.X < 0 || startPoint.Y < 0))
                    {
                        if (selectedIndex > -1 && items[selectedIndex] is Stock)
                        {
                            if (((Stock)items[selectedIndex]).getOutFlow() == null)
                            {
                                startItem = (Stock)items[selectedIndex];
                            }
                        }
                        else
                        {
                            startPoint = mouseCoord;
                        }
                        // излизаме преди да се деселектира бутона Flow
                        return;
                    }
                    //крайна точка
                    else
                    {
                        Flow flow = null;

                        //създава Flow и го добавя към Stock
                        if (selectedIndex > -1 && items[selectedIndex] is Stock && ((Stock)items[selectedIndex]).getInFlow() == null)
                        {
                            if (startItem != null)
                            {
                                flow = new Flow((Stock)startItem, (Stock)items[selectedIndex]);
                                ((Stock)startItem).AddOutFlow(flow);
                                ((Stock)items[selectedIndex]).AddInFlow(flow);
                            }
                            else
                            {
                                flow = new Flow(startPoint, (Stock)items[selectedIndex]);
                                ((Stock)items[selectedIndex]).AddInFlow(flow);
                            }
                        }
                        else if (startItem != null)
                        {
                            flow = new Flow((Stock)startItem, mouseCoord);
                            ((Stock)startItem).AddOutFlow(flow);
                        }

                        //добавя Flow към items
                        if (flow != null)
                        {
                            items.Add(flow);
                        }

                        startItem  = null;
                        startPoint = new Point(-1, -1);

                        DeselectAndRefresh();
                    }
                }



                //добавяме stock
                else if (btnStock.Checked)
                {
                    Stock stock = new Stock(mouseCoord);
                    items.Add(stock);
                    DeselectAndRefresh();
                }
                //добавяме constant
                else if (btnConstant.Checked)
                {
                    Constant c = new Constant(mouseCoord);
                    items.Add(c);
                    DeselectAndRefresh();
                }
                //Редактираме при двойно кликване
                else if (e.Clicks > 1 && this.selectedIndex > -1)
                {
                    EditSelectedItem();
                }
            }
            ReleaseButtons();
        }