Ejemplo n.º 1
0
        public Pipeline(Component InPut, Component OutPut)
        {
            this.InPut = InPut;
            this.OutPut = OutPut;
            SafetyLimit = 5;

        }
Ejemplo n.º 2
0
        }/*
        //constructors
        /// <summary>
        /// this is used for moving a component
        /// </summary>
        /// <param name="p">the position of the component</param>
        /// <param name="action">type "Move" here without quotations</param>
        /// <param name="comp">reference to the component</param>
        public Action(Point p, ActionType Move, Component comp)
        {
            this.Position = p;
            this.ActionType = Move;
            this.Component = comp;
        }
        */
        /// <summary>
        /// this is used when you create, delete or Move a component
        /// </summary>
        /// <param name="Act">type "ActionType." followed "Create", "Delete" or "Move" here without quotations</param>
        /// <param name="comp">reference to the component </param>
        public Action(ActionType Act, Component comp )
        {
            this.ActionType = Act;
            if ( Act == ActionType.Move)
            {
                Position = new Point(comp.Position.X, comp.Position.Y);
            }
            if (Act == ActionType.Delete)
            {
                this.Component = (Component) comp.Clone();
            }
            else
            {
                this.Component = comp;
            }

        }
Ejemplo n.º 3
0
 /// <summary>
 /// To add a new component to the canvas
 /// </summary>
 /// <param name="mousePoint"></param>
 /// <param name="selectedCompIndex"></param>
 public void CreateComponent(Component c)
 {
     Components.Add(c);
 }
Ejemplo n.º 4
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;
                
            }
        }
Ejemplo n.º 5
0
    /// <summary>
    /// To re-add a deleted component
    /// </summary>
    /// <param name="comp"></param>
        public void ReAddComponent(Component comp)
        {
            Components.Add(comp);
            switch (comp.GetType())
            {
                case ComponentType.Pipeline:
                    if (comp.InPut != null)
                    {
                        ((Part)(comp).InPut).Connect((Pipeline)comp);
                    }

                    if (comp.OutPut != null)
                    {
                        ((Part)(comp).OutPut).Connect((Pipeline)comp);
                    }
                    break;
                case ComponentType.Pump:
                    if (comp.OutPut != null)
                    { ((Part)(comp).OutPut.OutPut).Connect((Pipeline)comp.OutPut);
                        Components.Add(comp.OutPut);
                    }

                    break;
                case ComponentType.Splitter:
                    if (comp.InPut != null)
                    { ((Part)(comp).InPut.OutPut).Connect((Pipeline)comp.InPut);
                        Components.Add(comp.InPut);
                    }
                    if (comp.OutPutUp != null)
                    { ((Part)(comp).OutPutUp.OutPut).Connect((Pipeline)comp.OutPutUp);
                        Components.Add(comp.OutPutUp);
                    }
                    if (comp.OutPutDown != null)
                    { ((Part)(comp).OutPutDown.OutPut).Connect((Pipeline)comp.OutPutDown);
                        Components.Add(comp.OutPutDown);
                    }
                    break;
                case ComponentType.Merger:
                    if (comp.OutPut != null)
                    { ((Part)(comp).OutPut.OutPut).Connect((Pipeline)comp.OutPut);
                        Components.Add(comp.OutPut);
                    }
                    if (comp.InPutUp != null)
                    { ((Part)(comp).InPutUp.OutPut).Connect((Pipeline)comp.InPutUp);
                        Components.Add(comp.InPutUp);
                    }
                    if (comp.InPutDown != null)
                    { ((Part)(comp).InPutDown.OutPut).Connect((Pipeline)comp.InPutDown);
                        Components.Add(comp.InPutDown);
                    }
                    break;
                case ComponentType.Sink:
                    if (comp.InPut != null)
                    {
                        ((Part)(comp).InPut.OutPut).Connect((Pipeline)comp.InPut);
                        Components.Add(comp.InPut);
                    }
                    break;
                
            }
           
        }
Ejemplo n.º 6
0
        /// <summary>
        /// this is used for creating an undo. NOTE: use this method before you give the component it's new position or before you delete the component!
        /// </summary> 
        /// <param name="ActType">type "Create", "Delete" or "Move" here without quotations</param>
        /// <param name="comp">reference to the component</param>
        public void CreateUndo(ActionType ActType, Component comp)
        {
             
            if (( UndoRedoIndex + 2 <= UndoRedoList.Count))
            {
                if (UndoRedoIndex <0)
                UndoRedoList.RemoveRange(UndoRedoIndex + 1, UndoRedoList.Count);
                else
                UndoRedoList.RemoveRange((UndoRedoIndex  + 1 ), (UndoRedoList.Count - (UndoRedoIndex + 1)));
            }
            
            UndoRedoList.Add(new Action(ActType, comp));
            UndoRedoIndex++;
           

        }
Ejemplo n.º 7
0
        /// <summary>
        /// To delete a single component
        /// </summary>
        /// <param name="wantedcomp"></param>
        public void DeleteComponent(Component wantedcomp)
        {
            //Rectangle tempMousePoint = new Rectangle(mouseClicked, new Size(1, 1));

           
            // removes all Components connected
            switch (wantedcomp.GetType())
            {
                
                case ComponentType.Pump:
                    if (wantedcomp.OutPut!=null)
                    {
                        DeAttachPipeLine((Pipeline)wantedcomp.OutPut);
                    }
                    
                    break;
                case ComponentType.Splitter:
                    if (wantedcomp.InPut != null)
                    {
                        DeAttachPipeLine((Pipeline)wantedcomp.InPut);
                    }
                    if (wantedcomp.OutPutUp != null)
                    {
                        DeAttachPipeLine((Pipeline)wantedcomp.OutPutUp);
                    }
                    if (wantedcomp.OutPutDown != null)
                    {
                        DeAttachPipeLine((Pipeline)wantedcomp.OutPutDown);
                    }
                    break;
                case ComponentType.Merger:
                    if (wantedcomp.InPutUp != null)
                    {
                        DeAttachPipeLine((Pipeline)wantedcomp.InPutUp);
                    }
                    if (wantedcomp.InPutDown != null)
                    {
                        DeAttachPipeLine((Pipeline)wantedcomp.InPutUp);
                    }
                    if (wantedcomp.OutPut != null)
                    {
                        DeAttachPipeLine((Pipeline)wantedcomp.OutPut);
                    }
                    break;
                case ComponentType.Sink:
                    if (wantedcomp.InPut != null)
                    {
                        DeAttachPipeLine((Pipeline)wantedcomp.InPut);
                    }
                    break;
                
            }
            Components.Remove(wantedcomp);
        }