Beispiel #1
0
 public static void UpdateComponent(NumericUpDown numericUpDown1, double pumpFlow, double UpperPercent)
 {
     if (PipeLineSystem.UpdatePump != null && PipeLineSystem.Updated > 1)
     {
         numericUpDown1.Value = (decimal)PipeLineSystem.UpdatePump.GetCapacity();
         if (pumpFlow > PipeLineSystem.UpdatePump.GetCapacity())
         {
             MessageBox.Show("Current flow cannot exceed maximum flow.");
         }
         else
         {
             PipeLineSystem.UpdatePump.SetFlow(pumpFlow);
             PipeLineSystem.Network.UpdateComponent(PipeLineSystem.UpdatePump);
             PipeLineSystem.UpdatePump = null;
             PipeLineSystem.Updated    = 0;
             numericUpDown1.Enabled    = true;
         }
     }
     if (PipeLineSystem.UpdateSpliter != null && PipeLineSystem.Updated > 0)
     {
         PipeLineSystem.UpdateSpliter.SetUpperPercent(UpperPercent);
         PipeLineSystem.Network.UpdateComponent(PipeLineSystem.UpdateSpliter);
         PipeLineSystem.UpdateSpliter = null;
         PipeLineSystem.Updated       = 0;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Convert from string to component
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        private Component ConvertFromStringToComp(String s)
        {
            Component c = null;

            char[]   separators     = { '_' };
            string[] ComponentInfor = s.Split(separators);
            string   type           = ComponentInfor[0];

            if (type == "PU")
            {
                c = Pump.createPumpFromStringArray(ComponentInfor);
            }
            if (type == "SP")
            {
                c = Spliter.createSpliterFromStringArray(ComponentInfor);
            }
            if (type == "ASP")
            {
                c = AdjustableSpliter.createAdjustableSpliterFromStringArray(ComponentInfor);
            }
            if (type == "MG")
            {
                c = Merger.createMergerFromStringArray(ComponentInfor);
            }
            if (type == "SK")
            {
                c = Sink.createSinkFromStringArray(ComponentInfor);
            }
            return(c);
        }
Beispiel #3
0
        /// <summary>
        /// Convert a information of components into a string
        /// </summary>
        /// <param name="component"></param>
        /// <returns></returns>
        private String convertComponentToString(Component component)
        {
            string result = null;

            if (component is Pump)
            {
                Pump pu = (Pump)component;
                result = pu.ToString();
            }
            if (component is Sink)
            {
                Sink sk = (Sink)component;
                result = sk.ToString();
            }
            if (component is Merger)
            {
                Merger mg = (Merger)component;
                result = mg.ToString();
            }
            if (component is Spliter)
            {
                Spliter spt = (Spliter)component;
                result = spt.ToString();
            }
            if (component is AdjustableSpliter)
            {
                AdjustableSpliter aspt = (AdjustableSpliter)component;
                result = aspt.ToString();
            }
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Add temperory component
        /// </summary>
        /// <param name="eX"></param>
        /// <param name="eY"></param>
        /// <param name="currentFlow"></param>
        /// <param name="upperPct"></param>
        public static void AddTempComponent(int eX, int eY, double currentFlow, double upperPct, double pumpMaxFlow)
        {
            if (PipeLineSystem.TempComponent != null)
            {
                PipeLineSystem.TempComponent.SetLocation(eX, eY);
                if (PipeLineSystem.TempComponent is Pump)
                {
                    PipeLineSystem.TempComponent.SetFlow(currentFlow);
                    ((Pump)PipeLineSystem.TempComponent).SetMaxFlow(pumpMaxFlow);
                    PipeLineSystem.Network.Addcomponent(PipeLineSystem.TempComponent);
                    PipeLineSystem.TempComponent = null;
                }
                else if (PipeLineSystem.TempComponent is Merger)
                {
                    PipeLineSystem.Network.Addcomponent(PipeLineSystem.TempComponent);
                    PipeLineSystem.TempComponent = null;
                }
                else if (PipeLineSystem.TempComponent is Spliter)
                {
                    if (PipeLineSystem.TempComponent is AdjustableSpliter)
                    {
                        AdjustableSpliter tempSp = (AdjustableSpliter)PipeLineSystem.TempComponent;
                        tempSp.SetUpperPercent(upperPct);
                        PipeLineSystem.Network.Addcomponent(tempSp);
                        PipeLineSystem.TempComponent = null;
                    }
                    else
                    {
                        PipeLineSystem.Network.Addcomponent(PipeLineSystem.TempComponent);
                        PipeLineSystem.TempComponent = null;
                    }
                }

                else if (PipeLineSystem.TempComponent is Sink)
                {
                    PipeLineSystem.Network.Addcomponent(PipeLineSystem.TempComponent);
                    PipeLineSystem.TempComponent = null;
                }
            }
        }
Beispiel #5
0
 public static void UpdateComponentSelected(int eX, int eY, NumericUpDown numericUpDown1, NumericUpDown numericUpDown2)
 {
     if (PipeLineSystem.Updated == 0)
     {
         foreach (var c in PipeLineSystem.Network.GetListOfComponents())
         {
             if (c.ContainsPoint(eX, eY))
             {
                 if (c is Pump)
                 {
                     DialogResult dialogResult = MessageBox.Show("You want to change your current flow? Put the new input and double click on this pump again to update it ", "Update your pump's current flow?", MessageBoxButtons.YesNo);
                     if (dialogResult == DialogResult.Yes)
                     {
                         numericUpDown2.Enabled    = true;
                         numericUpDown1.Enabled    = false;
                         PipeLineSystem.UpdatePump = (Pump)c;
                         numericUpDown1.Value      = (decimal)PipeLineSystem.UpdatePump.GetCapacity();
                     }
                     else
                     {
                         PipeLineSystem.Updated = 0;
                     }
                 }
                 if (c is AdjustableSpliter)
                 {
                     DialogResult dialogResult = MessageBox.Show("You want to change your splitter setting? Put the new input and click on this spliter again to update it ", "Update your adjustable spliter?", MessageBoxButtons.YesNo);
                     if (dialogResult == DialogResult.Yes)
                     {
                         PipeLineSystem.UpdateSpliter = (AdjustableSpliter)c;
                     }
                     else
                     {
                         PipeLineSystem.Updated = 0;
                     }
                 }
             }
         }
     }
 }
Beispiel #6
0
        public static AdjustableSpliter createAdjustableSpliterFromStringArray(string[] ASpliterInfors)
        {
            AdjustableSpliter sp   = null;
            int      id            = Convert.ToInt16(ASpliterInfors[1]);
            int      x             = Convert.ToInt32(ASpliterInfors[2]);
            int      y             = Convert.ToInt32(ASpliterInfors[3]);
            Point    Location      = new Point(x, y);
            double   CurrentFlow   = Convert.ToDouble(ASpliterInfors[4]);
            double   upperFlow     = Convert.ToDouble(ASpliterInfors[5]);
            double   lowerFlow     = Convert.ToDouble(ASpliterInfors[6]);
            PipeLine inpipeline    = new PipeLine(Convert.ToInt32(ASpliterInfors[7]), 0);
            PipeLine outpipeline1  = new PipeLine(Convert.ToInt32(ASpliterInfors[8]), 0);
            PipeLine outpipeline2  = new PipeLine(Convert.ToInt32(ASpliterInfors[9]), 0);
            int      upperX        = Convert.ToInt32(ASpliterInfors[10]);
            int      upperY        = Convert.ToInt32(ASpliterInfors[11]);
            Point    UpperLocation = new Point(upperX, upperY);
            int      lowerX        = Convert.ToInt32(ASpliterInfors[12]);
            int      lowerY        = Convert.ToInt32(ASpliterInfors[13]);
            Point    LowerLocation = new Point(lowerX, lowerY);
            double   adjustPer     = Convert.ToDouble(ASpliterInfors[14]);

            sp = new AdjustableSpliter(id, Location, CurrentFlow, upperFlow, lowerFlow, inpipeline, outpipeline1, outpipeline2, UpperLocation, LowerLocation, adjustPer);
            return(sp);
        }
Beispiel #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.");
            }
        }