コード例 #1
0
ファイル: Merger.cs プロジェクト: bilal614/OOD
        /// <summary>
        /// Create an object of type Merger from string infors
        /// </summary>
        /// <param name="MergerInfors"></param>
        /// <returns></returns>
        public static Merger createMergerFromStringArray(string[] MergerInfors)
        {
            Merger   mg            = null;
            int      id            = Convert.ToInt16(MergerInfors[1]);
            int      x             = Convert.ToInt32(MergerInfors[2]);
            int      y             = Convert.ToInt32(MergerInfors[3]);
            Point    Location      = new Point(x, y);
            double   CurrentFlow   = Convert.ToDouble(MergerInfors[4]);
            PipeLine inpipeline1   = new PipeLine(Convert.ToInt32(MergerInfors[5]), 0);
            PipeLine inpipeline2   = new PipeLine(Convert.ToInt32(MergerInfors[6]), 0);
            PipeLine outpipeline   = new PipeLine(Convert.ToInt32(MergerInfors[7]), 0);
            int      upperX        = Convert.ToInt32(MergerInfors[8]);
            int      upperY        = Convert.ToInt32(MergerInfors[9]);
            Point    UpperLocation = new Point(upperX, upperY);
            int      lowerX        = Convert.ToInt32(MergerInfors[10]);
            int      lowerY        = Convert.ToInt32(MergerInfors[11]);
            Point    LowerLocation = new Point(lowerX, lowerY);

            mg = new Merger(id, Location, CurrentFlow, inpipeline1, inpipeline2, outpipeline, UpperLocation, LowerLocation);
            return(mg);
        }
コード例 #2
0
 public bool DrawAllPipeLines(Graphics gr)
 {
     try
     {
         foreach (PipeLine p in pipelines)
         {
             if (p.CurrentFlow > p.SafeLimit)
             {
                 PipeLine.DrawPipeline(gr, p, Pens.Red);
             }
             else
             {
                 PipeLine.DrawPipeline(gr, p, Pens.Black);
             }
         }
     }
     catch
     {
         MessageBox.Show("Some of the pipelines are not connected to a component.");
     }
     return(true);
 }
コード例 #3
0
ファイル: Spliter.cs プロジェクト: bilal614/OOD
        /// <summary>
        ///  Create an object of type Spliter from string infors
        /// </summary>
        /// <param name="SpliterInfors"></param>
        /// <returns></returns>
        public static Spliter createSpliterFromStringArray(string[] SpliterInfors)
        {
            Spliter  sp            = null;
            int      id            = Convert.ToInt16(SpliterInfors[1]);
            int      x             = Convert.ToInt32(SpliterInfors[2]);
            int      y             = Convert.ToInt32(SpliterInfors[3]);
            Point    Location      = new Point(x, y);
            double   CurrentFlow   = Convert.ToDouble(SpliterInfors[4]);
            double   upperFlow     = Convert.ToDouble(SpliterInfors[5]);
            double   lowerFlow     = Convert.ToDouble(SpliterInfors[6]);
            PipeLine inpipeline    = new PipeLine(Convert.ToInt32(SpliterInfors[7]), 0);
            PipeLine outpipeline1  = new PipeLine(Convert.ToInt32(SpliterInfors[8]), 0);
            PipeLine outpipeline2  = new PipeLine(Convert.ToInt32(SpliterInfors[9]), 0);
            int      upperX        = Convert.ToInt32(SpliterInfors[10]);
            int      upperY        = Convert.ToInt32(SpliterInfors[11]);
            Point    UpperLocation = new Point(upperX, upperY);
            int      lowerX        = Convert.ToInt32(SpliterInfors[12]);
            int      lowerY        = Convert.ToInt32(SpliterInfors[13]);
            Point    LowerLocation = new Point(lowerX, lowerY);

            sp = new Spliter(id, Location, CurrentFlow, upperFlow, lowerFlow, inpipeline, outpipeline1, outpipeline2, UpperLocation, LowerLocation);
            return(sp);
        }
コード例 #4
0
ファイル: Network.cs プロジェクト: bilal614/OOD
        public bool RemovePipeline(PipeLine P)
        {
            foreach (PipeLine pipe in pipelines)
            {
                if (pipe == P)
                {
                    pipe.CurrentFlow = 0;
                    if (pipe.CompEnd != null)
                    {
                        pipe.CompEnd.SetFlow(0);
                    }
                    pipelines.Remove(pipe);
                    // below will inform component that its pipeline has gone now.
                    foreach (var c in components)
                    {
                        UpdatePipelinesOfComps(c);
                    }

                    //UpdateCurrentFlowOfNetwork(); //don't need this the network is updated when the form refreshes
                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
 /// <summary>
 /// Constructors
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="componentLocation"></param>
 /// <param name="CurrentFlow"></param>
 /// <param name="outPipeLine"></param>
 public Sink(int ID, Point componentLocation, double CurrentFlow, PipeLine inPipeLine) :
     base(ID, componentLocation, CurrentFlow)
 {
     this.inPipeLine = inPipeLine;
 }
コード例 #6
0
ファイル: AdjustableSpliter.cs プロジェクト: bilal614/OOD
 /// <summary>
 /// Alternavite contructors
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="componentLocation"></param>
 /// <param name="CurrentFlow"></param>
 /// <param name="upperFlow"></param>
 /// <param name="lowerFlow"></param>
 /// <param name="inPipeLine"></param>
 /// <param name="outPipeline1"></param>
 /// <param name="outPipeline2"></param>
 /// <param name="upperLocation"></param>
 /// <param name="lowerLocation"></param>
 /// <param name="upperPercent"></param>
 public AdjustableSpliter(int ID, Point componentLocation, double CurrentFlow, double upperFlow, double lowerFlow, PipeLine inPipeLine,
                          PipeLine outPipeline1, PipeLine outPipeline2, Point upperLocation, Point lowerLocation, double upperPercent) :
     base(ID, componentLocation, CurrentFlow, upperFlow, lowerFlow, inPipeLine, outPipeline1, outPipeline2, upperLocation, lowerLocation)
 {
     this.upperPercent = upperPercent;
 }
コード例 #7
0
        /// <summary>
        /// Update the currentflow of all neighbors when pipeline is added
        /// </summary>
        public void UpdateCurrentFlowOfNetwork()
        {
            try
            {
                double mergerFlow = 0;
                foreach (PipeLine p in GetListOfPipeline())
                {
                    if (p.CompStart is Pump)
                    {
                        if (p.CompEnd is Merger)
                        {
                            mergerFlow += p.CompStart.GetFlow();
                            p.CompEnd.SetFlow(mergerFlow);
                            p.CurrentFlow = p.CompStart.GetFlow();
                        }
                        else
                        {
                            p.CompEnd.SetFlow(p.CompStart.GetFlow());
                            p.CurrentFlow = p.CompStart.GetFlow();
                        }
                    }
                }

                int countSplitters = 0;
                foreach (PipeLine p in GetListOfPipeline())
                {
                    if (p.CompStart is Spliter)
                    {
                        if (p.CompStart is AdjustableSpliter)
                        {
                            double            upperFlow = 0, lowerFlow = 0;
                            PipeLine          p1 = null, p2 = null;
                            AdjustableSpliter temp = (AdjustableSpliter)p.CompStart;
                            if (p.CompStart == temp && countSplitters == 0)
                            {
                                upperFlow      = temp.GetOutUpperFlow();
                                p1             = p;
                                p1.CurrentFlow = upperFlow;
                                countSplitters++;
                            }

                            if (p1 != p && p.CompStart == temp && countSplitters == 1)
                            {
                                lowerFlow      = temp.GetOutLowerFlow();
                                p2             = p;
                                p2.CurrentFlow = lowerFlow;
                            }
                            if (p1 != null)
                            {
                                p1.CompEnd.SetFlow(upperFlow);
                            }
                            if (p2 != null)
                            {
                                p2.CompEnd.SetFlow(lowerFlow);
                            }
                        }
                        else
                        {
                            p.CompEnd.SetFlow(p.CompStart.GetFlow() / 2);
                            p.CurrentFlow = p.CompStart.GetFlow() / 2;
                        }
                    }
                }

                foreach (PipeLine p in GetListOfPipeline())
                {
                    if (p.CompStart is Merger)
                    {
                        //double mergerCurrentFlow = 0;
                        Merger temp = (Merger)p.CompStart;

                        /*foreach (PipeLine pi in GetListOfPipeline())
                         * {
                         *  if (pi.CompEnd == temp)
                         *  {
                         *      mergerCurrentFlow = pi.CompEnd.GetFlow();
                         *  }
                         * }*/
                        p.CompEnd.SetFlow(p.CompStart.GetFlow());
                        p.CurrentFlow = p.CompStart.GetFlow();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Current flow update error.");
            }
        }
コード例 #8
0
 /// <summary>
 /// Update Pipelines of Comps depending type of com
 /// </summary>
 /// <param name="c"></param>
 private void UpdatePipelinesOfComps(Component c)
 {
     if (c is Pump)
     {
         Pump p = (Pump)c;
         if (p.getOutPipeLine() != null)
         {
             PipeLine outPipeLine = GetPipeline(p.getOutPipeLine().getId());
             p.addOutPipeLine(outPipeLine);
         }
         else
         {
             p.addOutPipeLine(null);
         }
     }
     if (c is Spliter || c is AdjustableSpliter)
     {
         Spliter sp = null;
         sp = (Spliter)c;
         if (c is AdjustableSpliter)
         {
             sp = (AdjustableSpliter)c;
         }
         if (sp.getInPipeLine() != null)
         {
             PipeLine inPipeLine = GetPipeline(sp.getInPipeLine().getId());
             sp.addInPipeLine(inPipeLine);
         }
         else
         {
             sp.addInPipeLine(null);
         }
         if (sp.getOutPipeLine1() != null)
         {
             PipeLine outPipeLine1 = GetPipeline(sp.getOutPipeLine1().getId());
             sp.addOutPipeLine1(outPipeLine1);
         }
         else
         {
             sp.addOutPipeLine1(null);
         }
         if (sp.getOutPipeLine2() != null)
         {
             PipeLine outPipeLine2 = GetPipeline(sp.getOutPipeLine2().getId());
             sp.addOutPipeLine2(outPipeLine2);
         }
         else
         {
             sp.addOutPipeLine2(null);
         }
     }
     if (c is Merger)
     {
         Merger mg = (Merger)c;
         if (mg.getOutPipeLine() != null)
         {
             PipeLine outPipeline = GetPipeline(mg.getOutPipeLine().getId());
             mg.addOutPipeLine(outPipeline);
         }
         else
         {
             mg.addOutPipeLine(null);
         }
         if (mg.getInPipeLine1() != null)
         {
             PipeLine inPipeline1 = GetPipeline(mg.getInPipeLine1().getId());
             mg.addInPipeLine1(inPipeline1);
         }
         else
         {
             mg.addInPipeLine1(null);
         }
         if (mg.getInPipeLine2() != null)
         {
             PipeLine intPipeline2 = GetPipeline(mg.getInPipeLine2().getId());
             mg.addInPipeLine2(intPipeline2);
         }
         else
         {
             mg.addInPipeLine2(null);
         }
     }
     if (c is Sink)
     {
         Sink sk = (Sink)c;
         if (sk.getInPipeLine() != null)
         {
             PipeLine inPipeline = GetPipeline(sk.getInPipeLine().getId());
             sk.addInPipeLine(inPipeline);
         }
         else
         {
             sk.addInPipeLine(null);
         }
     }
 }
コード例 #9
0
        public bool AddPipeLine(PipeLine p)
        {
            bool toAddOrNot = true;
            int  count1 = 0, count2 = 0;

            foreach (PipeLine pl in this.GetListOfPipeline())
            {
                if (pl.CompStart is Pump)//to avoid multiple connections from pump
                {
                    if (p.CompStart == pl.CompStart)
                    {
                        toAddOrNot = false;
                        break;
                    }
                }

                if (pl.CompEnd is Sink)
                {
                    if (p.CompEnd == pl.CompEnd)
                    {
                        toAddOrNot = false;
                        break;
                    }
                }

                if (pl.CompStart is Merger)
                {
                    if (p.CompStart == pl.CompStart)
                    {
                        toAddOrNot = false;
                        break;
                    }
                }
                if (pl.CompEnd is Merger)
                {
                    if (p.CompEnd == pl.CompEnd)
                    {
                        count1++;
                    }
                }

                if (pl.CompStart is Spliter)
                {
                    if (p.CompStart == pl.CompStart)
                    {
                        count2++;
                    }
                }
                if (pl.CompEnd is Spliter)
                {
                    if (p.CompEnd == pl.CompEnd)
                    {
                        toAddOrNot = false;
                        break;
                    }
                }
            }

            if (count1 >= 2 || count2 >= 2)
            {
                toAddOrNot = false;
            }
            if (p.CompStart is Sink)
            {
                toAddOrNot = false;
            }
            if (p.CompEnd is Pump)
            {
                toAddOrNot = false;
            }
            if (toAddOrNot)
            {
                pipelines.Add(p);
                PipeLineSystem.Saved = false;
                PipeLineSystem.Added = true;
            }
            return(toAddOrNot);
            //}
            //return false;
        }
コード例 #10
0
ファイル: Pump.cs プロジェクト: bilal614/OOD
 /// <summary>
 /// Constructor with all infors for loading from file
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="componentLoctaion"></param>
 /// <param name="CurrentFlow"></param>
 /// <param name="outPipeline"></param>
 public Pump(int ID, Point componentLoctaion, double CurrentFlow, PipeLine outPipeline)
     : base(ID, componentLoctaion, CurrentFlow)
 {
     this.outPipeLine = outPipeline;
 }
コード例 #11
0
ファイル: Spliter.cs プロジェクト: bilal614/OOD
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="componentLocation"></param>
 /// <param name="CurrentFlow"></param>
 /// <param name="upperFlow"></param>
 /// <param name="lowerFlow"></param>
 /// <param name="inPipeLine"></param>
 /// <param name="outPipeline1"></param>
 /// <param name="outPipeline2"></param>
 /// <param name="upperLocation"></param>
 /// <param name="lowerLocation"></param>
 public Spliter(int ID, Point componentLocation, double CurrentFlow, double upperFlow, double lowerFlow, PipeLine inPipeLine,
                PipeLine outPipeline1, PipeLine outPipeline2, Point upperLocation, Point lowerLocation) :
     base(ID, componentLocation, CurrentFlow)
 {
     this.upperOut      = upperFlow;
     this.lowerOut      = lowerFlow;
     this.inPipeline    = inPipeLine;
     this.outPipeLine1  = outPipeline1;
     this.outPipeLine2  = outPipeline2;
     this.upperLocation = upperLocation;
     this.lowerLocation = lowerLocation;
 }
コード例 #12
0
ファイル: Merger.cs プロジェクト: bilal614/OOD
 /// <summary>
 /// Alternative contructor
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="componentLocation"></param>
 /// <param name="CurrentFlow"></param>
 /// <param name="inPipeline1"></param>
 /// <param name="inPipeLine2"></param>
 /// <param name="outPipeLine"></param>
 /// <param name="upperLoc"></param>
 /// <param name="lowerLow"></param>
 public Merger(int ID, Point componentLocation, double CurrentFlow, PipeLine inPipeline1, PipeLine inPipeLine2, PipeLine outPipeLine,
               Point upperLoc, Point lowerLow)
     : base(ID, componentLocation, CurrentFlow)
 {
     this.inPipeline1   = inPipeline1;
     this.outPipeline   = outPipeLine;
     this.inPipeline2   = inPipeLine2;
     this.upperLocation = upperLoc;
     this.lowerLocation = lowerLow;
 }