示例#1
0
        internal void CheckMerger(Point p, string name, Component e, Pipe plf)
        {
            foreach (Merger merg in Mergers)
            {
                if (merg.Position == e.Position)
                {
                    merger = merg;
                }
            }

            if ((tempPoint.X + 63 >= e.Position.X && (tempPoint.Y + 63 >= e.Position.Y) && ((tempPoint.X - 63 <= e.Position.X) && (tempPoint.Y - 63 <= e.Position.Y)) && (e is Merger)))
            {
                merger.listPipelineOutputMerger.Add(plf);
            }
            if ((p.X + 63 >= e.Position.X && (p.Y + 63 >= e.Position.Y) && ((p.X - 63 <= e.Position.X) && (p.Y - 63 <= e.Position.Y)) && (e is Merger)))
            {
                merger.listPipelineInputMerger.Add(plf);

                foreach (Pipe pl in Pipes)
                {
                    foreach (Pipe pl2 in merger.listPipelineInputMerger)
                    {
                        if (pl.SecondPoint == pl2.SecondPoint)
                        {
                            pl.Flow       = pl2.Flow;
                            pl.FirstPoint = pl2.FirstPoint;
                        }
                    }
                }
            }


            if (merger.listPipelineInputMerger.Count > 2)
            {
                MessageBox.Show("It is not possible to have more than 2 input pumps.");

                Pipe pl = CheckPipeline(p);

                Pipes.Remove(merger.listPipelineInputMerger[2]);
                merger.listPipelineInputMerger.Remove(merger.listPipelineInputMerger[2]);
            }



            if (merger.listPipelineInputMerger.Count == 1)
            {
                merger.listPipelineInputMerger[0].Flow = plf.Flow;

                foreach (Pipe pl in merger.listPipelineInputMerger)
                {
                    if ((pl.SecondPoint.X) + 63 >= e.Position.X && ((pl.SecondPoint.Y) + 63 >= e.Position.Y && (pl.SecondPoint.X) - 63 <= e.Position.X) && ((pl.SecondPoint.X) + 63 >= e.Position.X) && (e is Merger))
                    {
                        pl.SecondPoint = new Point(e.Position.X + 18, e.Position.Y + 18);
                    }
                }
                foreach (Pipe pl in Pipes)
                {
                    if ((pl.SecondPoint.X) + 63 >= e.Position.X && ((pl.SecondPoint.Y) + 63 >= e.Position.Y && (pl.SecondPoint.X) - 63 <= e.Position.X) && ((pl.SecondPoint.X) + 63 >= e.Position.X) && (e is Merger))
                    {
                        pl.SecondPoint = new Point(e.Position.X + 18, e.Position.Y + 18);
                    }
                }
            }
            else if (merger.listPipelineInputMerger.Count == 2 && merger.listPipelineOutputMerger.Count == 1)
            {
                double final = 0;
                foreach (Pipe pl in merger.listPipelineInputMerger)
                {
                    final += pl.Flow;
                }
                merger.listPipelineOutputMerger[0].Flow = final;
            }
        }
示例#2
0
        public void AddPipe(Point p, string name)
        {
            int       xx   = 0;
            Component comp = CheckComponent(p);

            componentlist.Add(comp);
            if (comp != null)          //If comp is not null means user clicked on a component in the form else it returns null
            {
                if (position == false) //if click first time (first point of pipeline)
                {
                    position  = true;
                    tempPoint = p;

                    if (comp is Pump)
                    {
                        checkPump++;
                    }

                    else if (comp is Sink)
                    {
                        int x = CheckPipelineForSink(p, comp).Count();

                        if (x > 1)
                        {
                            MessageBox.Show("The sink can not have more then 2 input ");
                            position = false;
                        }
                    }
                }
                else //if click second time (second point of pipeline)
                {
                    if (comp is Pump && checkPump == 1)
                    {
                        MessageBox.Show("Pump can not be your next component");
                        checkPump--;
                        position = false;
                    }
                    else
                    {
                        if (!(comp is Pump))
                        {
                            checkPump = 0;
                        }
                        if (comp is Sink)
                        {
                            int x = CheckPipelineForSink(p, comp).Count();

                            if (x > 1)
                            {
                                MessageBox.Show("The sink can not have more then 2 input ");
                                x        = 0;
                                xx       = 1;
                                position = false;
                            }
                        }

                        if (xx == 0)
                        {
                            Pipe plf = new Pipe(tempPoint, p, name);
                            foreach (Component c in Components)
                            {
                                if (c == componentlist[0] && c is Pump || c == componentlist[1] && c is Pump)
                                {
                                    plf.Flow = c.Flow;
                                    c.AddPipe(plf);
                                }
                                if (c == componentlist[0] && c is Sink || c == componentlist[1] && c is Sink)
                                {
                                    c.AddPipe(plf);
                                }
                                if (c == componentlist[0] && c is Splitter || c == componentlist[1] && c is Splitter)
                                {
                                    if (((Splitter)c).listPipeInputSplitter.Count == 0)
                                    {
                                        c.AddPipe(plf);
                                    }
                                }
                            }
                            Pipes.Add(plf);

                            foreach (Component e in Components.ToList())
                            {
                                if ((tempPoint.X + 63 >= e.Position.X && (tempPoint.Y + 63 >= e.Position.Y) && (tempPoint.X - 63 <= e.Position.X) && (tempPoint.Y - 63 <= e.Position.Y) && (e is Splitter) && !(e is AdjSplitter)))
                                {
                                    CheckSplitter(p, name, e, plf);
                                }
                                else if (tempPoint.X + 63 >= e.Position.X && (tempPoint.Y + 63 >= e.Position.Y) && (tempPoint.X - 63 <= e.Position.X) && (tempPoint.Y - 63 <= e.Position.Y) && (e is AdjSplitter))
                                {
                                    CheckAdjustableSplitter(p, name, e, plf);
                                }
                                else if ((p.X + 63 >= e.Position.X && (p.Y + 63 >= e.Position.Y) && (p.X - 63 <= e.Position.X) && (p.Y - 63 <= e.Position.Y) && (e is Splitter) && !(e is AdjSplitter)))
                                {
                                    splitter = new Splitter(e.Position, e.Name);
                                    splitter.listPipeInputSplitter.Add(plf);
                                    CheckSplitter1(p, name, e, plf);
                                }
                                else if (p.X + 63 >= e.Position.X && (p.Y + 63 >= e.Position.Y) && (p.X - 63 <= e.Position.X) && (p.Y - 63 <= e.Position.Y) && (e is AdjSplitter))
                                {
                                    adjsplit = new AdjSplitter(e.Position, e.Name, 100);
                                    adjsplit.listPipeInputSplitter.Add(plf);
                                    CheckAdjustableSplitter1(p, name, e, plf);
                                }
                                if (((p.X + 63 >= e.Position.X && (p.Y + 63 >= e.Position.Y) && (p.Y - 63 <= e.Position.Y) && (e is Merger))))
                                {
                                    CheckMerger(p, name, e, plf);
                                }
                                else if (((tempPoint.X + 63 >= e.Position.X && (tempPoint.Y + 63 >= e.Position.Y) && (tempPoint.Y - 63 <= e.Position.Y) && (e is Merger))))
                                {
                                    try
                                    {
                                        merger.listPipelineOutputMerger.Add(plf);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                    CheckMerger1(p, name, e, plf);
                                }
                                position = false;
                            }

                            if (componentlist.Count == 2)
                            {
                                componentlist = new List <Component>();
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        internal void CheckAdjustableSplitter1(Point p, string name, Component e, Pipe plf)
        {
            foreach (AdjSplitter spl in AdjSplitters)
            {
                if (spl.Position == e.Position)
                {
                    adjsplit = spl;
                }
            }

            foreach (Pipe pl in Pipes)
            {
                foreach (Pipe pl2 in adjsplit.listPipeOutputSplitter)
                {
                    if (pl.SecondPoint == pl2.SecondPoint)
                    {
                        pl.Flow       = pl2.Flow;
                        pl.FirstPoint = pl2.FirstPoint;
                    }
                }
            }

            if (adjsplit.listPipeInputSplitter.Count > 1)
            {
                MessageBox.Show("It is not possible for pump to have more than 1 input.");
                Pipe pl = CheckPipeline(p);

                foreach (Pipe plg in adjsplit.listPipeInputSplitter.ToList())
                {
                    if (adjsplit.listPipeInputSplitter.Count > 1)
                    {
                        if (adjsplit.listPipeInputSplitter.Count > 2)
                        {
                            Pipes.Remove(adjsplit.listPipeInputSplitter[i]);
                            adjsplit.listPipeInputSplitter.Remove(adjsplit.listPipeInputSplitter[i]);
                        }
                        else if (adjsplit.listPipeInputSplitter.Count == 2)
                        {
                            Pipes.Remove(adjsplit.listPipeInputSplitter[1]);
                            adjsplit.listPipeInputSplitter.Remove(adjsplit.listPipeInputSplitter[1]);
                        }

                        i++;
                    }
                }
            }

            if (adjsplit.listPipeOutputSplitter.Count == 1)
            {
                adjsplit.listPipeOutputSplitter[0].Flow = adjsplit.listPipeInputSplitter[0].Flow;
                foreach (Pipe pl in adjsplit.listPipeOutputSplitter)
                {
                    if ((pl.FirstPoint.X) + 63 >= e.Position.X && ((pl.FirstPoint.Y) + 63 >= e.Position.Y && (pl.FirstPoint.X) - 63 <= e.Position.X) && ((pl.FirstPoint.X) + 63 >= e.Position.X) && (e is Splitter))
                    {
                        pl.FirstPoint = e.Position;
                    }
                }

                foreach (Pipe pl in Pipes)
                {
                    if ((pl.FirstPoint.X) + 63 >= e.Position.X && ((pl.FirstPoint.Y) + 63 >= e.Position.Y && (pl.FirstPoint.X) - 63 <= e.Position.X) && ((pl.FirstPoint.X) + 63 >= e.Position.X) && (e is Splitter))
                    {
                        pl.FirstPoint = e.Position;
                    }
                }
            }
            else if (adjsplit.listPipeOutputSplitter.Count == 2)
            {
                adjsplit.listPipeOutputSplitter[0].Flow = Convert.ToInt32(adjsplit.listPipeInputSplitter[0].Flow * adjsplit.upValue / 100);
                adjsplit.listPipeOutputSplitter[1].Flow = Convert.ToInt32(adjsplit.listPipeInputSplitter[0].Flow - (adjsplit.listPipeInputSplitter[0].Flow * adjsplit.upValue / 100));
            }
        }
示例#4
0
        internal void CheckSplitter1(Point p, string name, Component e, Pipe plf)
        {
            foreach (Splitter spl in Splitters)
            {
                if (spl.Position == e.Position)
                {
                    splitter = spl;
                }
            }


            foreach (Pipe pl in Pipes)
            {
                foreach (Pipe pl2 in splitter.listPipeOutputSplitter)
                {
                    if (pl.SecondPoint == pl2.SecondPoint)
                    {
                        pl.Flow       = pl2.Flow;
                        pl.FirstPoint = pl2.FirstPoint;
                    }
                }
            }

            if (splitter.listPipeInputSplitter.Count > 1)
            {
                MessageBox.Show("It is not possible for pump to have more than 1 input.");
                Pipe pl = CheckPipeline(p);

                foreach (Pipe plg in splitter.listPipeInputSplitter.ToList())
                {
                    if (splitter.listPipeInputSplitter.Count > 1)
                    {
                        if (splitter.listPipeInputSplitter.Count > 2)
                        {
                            Pipes.Remove(splitter.listPipeInputSplitter[i]);
                            splitter.listPipeInputSplitter.Remove(splitter.listPipeInputSplitter[i]);
                        }
                        else if (splitter.listPipeInputSplitter.Count == 2)
                        {
                            Pipes.Remove(splitter.listPipeInputSplitter[1]);
                            splitter.listPipeInputSplitter.Remove(splitter.listPipeInputSplitter[1]);
                        }

                        i++;
                    }
                }
            }

            if (splitter.listPipeOutputSplitter.Count == 1)
            {
                splitter.listPipeOutputSplitter[0].Flow = splitter.listPipeInputSplitter[0].Flow;
                foreach (Pipe pl in splitter.listPipeOutputSplitter)
                {
                    if ((pl.FirstPoint.X) + 63 >= e.Position.X && ((pl.FirstPoint.Y) + 63 >= e.Position.Y && (pl.FirstPoint.X) - 63 <= e.Position.X) && ((pl.FirstPoint.X) + 63 >= e.Position.X) && (e is Splitter))
                    {
                        pl.FirstPoint = e.Position;
                    }
                }

                foreach (Pipe pl in Pipes)
                {
                    if ((pl.FirstPoint.X) + 63 >= e.Position.X && ((pl.FirstPoint.Y) + 63 >= e.Position.Y && (pl.FirstPoint.X) - 63 <= e.Position.X) && ((pl.FirstPoint.X) + 63 >= e.Position.X) && (e is Splitter))
                    {
                        pl.FirstPoint = e.Position;
                    }
                }
            }
            else if (splitter.listPipeOutputSplitter.Count == 2)
            {
                splitter.listPipeOutputSplitter[0].Flow = splitter.listPipeInputSplitter[0].Flow / 2;
                splitter.listPipeOutputSplitter[1].Flow = splitter.listPipeInputSplitter[0].Flow / 2;
            }
        }
示例#5
0
        internal void CheckSplitter(Point p, string name, Component e, Pipe plf)
        {
            foreach (Splitter spl in Splitters)
            {
                if (spl.Position == e.Position)
                {
                    splitter = spl;
                }
            }

            splitter.listPipeOutputSplitter.Add(plf);

            foreach (Pipe pl in Pipes)
            {
                foreach (Pipe pl2 in splitter.listPipeOutputSplitter)
                {
                    if (pl.SecondPoint == pl2.SecondPoint)
                    {
                        pl.Flow       = pl2.Flow;
                        pl.FirstPoint = pl2.FirstPoint;
                    }
                }
            }

            if (splitter.listPipeOutputSplitter.Count == 1)
            {
                try
                {
                    splitter.listPipeOutputSplitter[0].Flow = splitter.listPipeInputSplitter[0].Flow;
                }
                catch (Exception)
                {
                }
                foreach (Pipe pl in splitter.listPipeOutputSplitter)
                {
                    if ((pl.FirstPoint.X) + 63 >= e.Position.X && ((pl.FirstPoint.Y) + 63 >= e.Position.Y && (pl.FirstPoint.X) - 63 <= e.Position.X) && ((pl.FirstPoint.X) + 63 >= e.Position.X) && (e is Splitter))
                    {
                        pl.FirstPoint = e.Position;
                    }
                }

                foreach (Pipe pl in Pipes)
                {
                    if ((pl.FirstPoint.X) + 63 >= e.Position.X && ((pl.FirstPoint.Y) + 63 >= e.Position.Y && (pl.FirstPoint.X) - 63 <= e.Position.X) && ((pl.FirstPoint.X) + 63 >= e.Position.X) && (e is Splitter))
                    {
                        pl.FirstPoint = e.Position;
                    }
                }
            }
            else if (splitter.listPipeOutputSplitter.Count == 2)
            {
                splitter.listPipeOutputSplitter[0].Flow = splitter.listPipeInputSplitter[0].Flow / 2;
                splitter.listPipeOutputSplitter[1].Flow = splitter.listPipeInputSplitter[0].Flow / 2;
            }
            else if (splitter.listPipeOutputSplitter.Count > 2)
            {
                MessageBox.Show("You cant have more than 2 output pumps.");
                splitter.listPipeOutputSplitter.Remove(splitter.listPipeOutputSplitter[2]);

                Component el = CheckComponent(p);
                Pipe      pl = CheckPipeline(p);

                if (el != null)
                {
                    foreach (Pipe pl12 in Pipes.ToList())
                    {
                        if (pl12.SecondPoint == pl.SecondPoint)
                        {
                            Pipes.Remove(pl12);
                        }
                    }
                }
                if (pl != null)
                {
                    Pipes.Remove(pl);
                }
            }
        }
示例#6
0
 public override void AddPipe(Pipe pipe)
 {
     listPipeInputSplitter.Add(pipe);
 }
示例#7
0
 public override void AddPipe(Pipe pipe)
 {
     InPipe = pipe;
 }