Exemplo n.º 1
0
 /// <summary>
 /// To establish a connection to a free input output in order of first input then output
 /// </summary>
 /// <returns></returns>
 public override void Connect(Pipeline pipeline)
 {
     if (ReferenceEquals(InPut, null))
     {
         InPut = pipeline;
     }
     else if (ReferenceEquals(OutPutUp, null))
     {
         OutPutUp = pipeline;
     }
     else if (ReferenceEquals(OutPutDown, null))
     {
         OutPutDown = pipeline;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Remove an existing connection
 /// </summary>
 /// <param name="p"></param>
 public override void Disconnect(Pipeline p)
 {
     if (InPutUp == p)
     {
         InPutUp = null;
     }
     if (InPutDown == p)
     {
         InPutDown = null;
     }
     if (OutPut == p)
     {
         OutPut = null;
     }
 }
Exemplo n.º 3
0
        private void FlowNetworkSimulator_MouseClick(object sender, MouseEventArgs e)
        {
            flowLabel.Visible = false;
            mousepoint = PointToClient(Cursor.Position);
            tooltip.RemoveAll();
            IWin32Window win = this;
            if (e.Button == MouseButtons.Left)
            {

                isSelected = false;

                if ((tempComponent = canvas.SelectComponent(mousepoint)) != null)
                {
                    isSelected = true;

                    trackBar1.Enabled = false;
                    textBox1.Enabled = false;
                    textBox2.Enabled = false;
                    switch (tempComponent.GetType())
                    {
                        case ComponentType.Pipeline:
                            textBox2.Enabled = true;
                            break;
                        case ComponentType.Pump:
                            textBox1.Enabled = true;
                            textBox2.Enabled = true;
                            break;
                        case ComponentType.Splitter:
                            trackBar1.Enabled = true;
                            break;


                    }
                    fh.saved = false;
                    this.Refresh();


                }
                if (selectedComponent != null && !canvas.IsOverlapping(selectedComponent.SelectionArea) && area.IntersectsWith(new Rectangle(mousepoint, new Size(40, 40))))
                {
                    selectedComponent.Position = new Point(mousepoint.X, mousepoint.Y);
                    selectedComponent.UpdateSelectionArea();
                    canvas.CreateComponent(selectedComponent);
                    if(!compIsMoving)
                    canvas.CreateUndo(ActionType.Create, selectedComponent);
                    UndoButton.Enabled = true;
                    selectedComponent = null;
                    compIsMoving = false;
                    fh.saved = false;
                    this.Refresh();
                    this.Cursor = Cursors.Arrow;
                }



                if (selectedComponent != null && canvas.IsOverlapping(selectedComponent.SelectionArea) || !area.IntersectsWith(new Rectangle(mousepoint, new Size(40, 40))))
                {
                    
                    UndoButton.Enabled = true;
                    if (compIsMoving)
                    {
                        canvas.UndoRedoList.RemoveAt(canvas.UndoRedoIndex);
                        canvas.UndoRedoIndex--;
                        selectedComponent.Position = oldCoordinates;
                        selectedComponent.UpdateSelectionArea();
                        // if(selectedComponent)
                        canvas.CreateComponent(selectedComponent);
                        compIsMoving = false;
                        fh.saved = false;
                        this.Refresh();
                    }

                    selectedComponent = null;
                    //this.Cursor = Cursors.Arrow;
                    tooltip.Show("You cannot place a component here", win, mousepoint);
                    this.Cursor = Cursors.Arrow;

                }
                if (addNewPipeline)
                {
                    if (!connectedComp1)
                    {
                        first = new Point(mousepoint.X, mousepoint.Y);
                        connectedComp1 = true;

                    }
                    else
                    {
                        second = new Point(mousepoint.X, mousepoint.Y);
                        if (canvas.DrawPipeline(canvas.SelectComponent(first), canvas.SelectComponent(second)))
                        {
                            connectedComp1 = false;
                            addNewPipeline = false;


                            fh.saved = false;
                            this.Refresh();
                            this.Cursor = Cursors.Arrow;
                        }
                        else
                        {
                            tooltip.Show("Unable to establish a connection", win, Cursor.Position);
                            connectedComp1 = false;
                            fh.saved = false;
                            this.Cursor = Cursors.Arrow;
                            this.Refresh();
                        }
                    }
                }


            }
            else if (e.Button == MouseButtons.Right)
            {
                //  mousepoint = this.formPointToClient(Cursor.Position);
                //this.Cursor = Cursors.Arrow;


                if ((tempComponent = canvas.SelectComponent(mousepoint)) != null)
                {
                    isSelected = true;
                    this.Refresh();
                    cmsEdit.Show(Cursor.Position);

                }
                else if ((selectedPipeline = canvas.SelectPipeline(mousepoint)) != null)
                {

                    cmsEditPipeline.Show(Cursor.Position);
                    wireIsSelected = true;
                }
                else
                {
                    isSelected = false;
                }
                fh.saved = false;
                this.Refresh();
            }

            if (isSelected)
            {
                Component temp = canvas.SelectComponent(mousepoint);
                UpdateFlowLabel(temp);
                fh.saved = false;


            }
            if ((selectedPipeline = canvas.SelectPipeline(mousepoint)) != null)
            {

                UpdateFlowLabel(selectedPipeline);
                fh.saved = false;
            }

        }
Exemplo n.º 4
0
 public override Port WhichPort(Pipeline p)
 {
     return Port.InPut;
 }
Exemplo n.º 5
0
 public override void Disconnect(Pipeline p)
 {
     InPut = null;
 }
Exemplo n.º 6
0
 /// <summary>
 /// To establish a connection to the input
 /// </summary>
 /// <param name="pipeline"></param>
 /// <returns></returns>
 public override void Connect(Pipeline pipeline)
 {
     InPut = pipeline;
 }
Exemplo n.º 7
0
 /// <summary>
 /// This is for disconnecting a pipe from the part
 /// </summary>
 /// <param name="p">the pipe that should be removed from the component</param>
 public abstract void Disconnect(Pipeline p);
Exemplo n.º 8
0
 /// <summary>
 /// To establish a connection between a Part and a pipeline
 /// </summary>
 /// <returns></returns>
 public abstract void Connect(Pipeline p);
Exemplo n.º 9
0
 /// <summary>
 /// it checks to know where the pipe is connected to the part
 /// </summary>
 /// <param name="p">the pipe in question</param>
 public abstract Port WhichPort(Pipeline p);
Exemplo n.º 10
0
 public override Port WhichPort(Pipeline p)
 {
     if (InPut == p)
     {
         return Port.InPut;
     }
     if (OutPutUp == p)
     {
         return Port.OutPutUp;
     }
     return Port.OutPutDown;
 }
Exemplo n.º 11
0
 /// <summary>
 /// establishes a connection(pipeline) between two parts(components)
 /// </summary>
 /// <param name="c1"></param>
 /// <param name="c2"></param>
 /// <returns></returns>
        public bool DrawPipeline(Component c1, Component c2)
        {

            try
            {

            
            if(c1 == c2)
            return false;
            switch (c1.GetType())
            {
                case ComponentType.Pump:
                    if (c1.OutPut != null )
                    {
                        return false;
                    }
                    break;

                case ComponentType.Splitter:
                    if ( ((Splitter)c1).CheckConnectedNodes()  == 3  )
                    {
                        return false;
                    }
                    break;
                case ComponentType.Merger:
                    if (((Merger)c1).CheckConnectedNodes() == 3)
                    { return false; }
                        break;
                case ComponentType.Sink:
                    if (c1.InPut != null)
                    {
                        return false;
                    }
                    break;
            }
            switch (c2.GetType())
            {
                case ComponentType.Pump:
                    if (c2.OutPut != null)
                    {return false;}
                    break;
                case ComponentType.Splitter:
                    if (((Splitter)c2).CheckConnectedNodes() == 3)
                    {return false; }
                    break;
                case ComponentType.Merger:
                    if (((Merger)c2).CheckConnectedNodes() == 3)
                    { return false; }
                    break;
                case ComponentType.Sink:
                    if (c2.InPut != null)
                    { return false;}
                    break;
            }
            Pipeline pipe = new Pipeline(c1, c2);
            Components.Add(pipe);
            ((Part)c1).Connect(pipe);
            ((Part)c2).Connect(pipe);
                CreateUndo(ActionType.Create, pipe);
            return true;
            }
            catch (Exception)
            {
                return false;
                
            }
        }
Exemplo n.º 12
0
  /// <summary>
  /// To delete a pipeline
  /// </summary>
  /// <param name="pipe"></param>
  public void DeletePipeline(Pipeline pipe)
  {
      
          // delete connections
         
             ((Part)pipe.InPut).Disconnect(pipe);
 
              ((Part)pipe.OutPut).Disconnect(pipe);
     
      Components.Remove(pipe);           //delete selected wire
  }
Exemplo n.º 13
0
 /// <summary>
 /// returns the midpoint of the pipeline
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public Point getMidPoint(Pipeline p)
 {
     return new Point((p.InPutPoint.X + p.OutPutPoint.X) / 2, (p.InPutPoint.Y + p.OutPutPoint.Y) / 2);
 }