Ejemplo n.º 1
0
        public void AddComponent(Component component, int percentage, Point position, string type, double currentFlow, double maxFlow)
        {
            if (type == "Pump")
            {
                component = new Pump(position, type, currentFlow);
            }
            else if (type == "Sink")
            {
                component = new Sink(position, type, maxFlow);
            }
            else if (type == "Merger")
            {
                component = new Merger(position, type);
                Mergers.Add(((Merger)component));
            }
            else if (type == "Splitter")
            {
                component = new Splitter(position, type);
                Splitters.Add(((Splitter)component));
            }
            else if (type == "AdjSplitter")
            {
                component = new AdjSplitter(position, type, percentage);
                AdjSplitters.Add(((AdjSplitter)component));
            }


            if (CheckAddingComponents(component))
            {
                Components.Add(component);
                // component.Draw(component.Position, form);
            }
        }
Ejemplo n.º 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>();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Save()
        {
            FileStream   fs = null;
            StreamWriter sw = null;

            try
            {
                SaveFileDialog info = new SaveFileDialog();
                info.Title  = "Saving Pipeline Network";
                info.Filter = "Text Document |*.txt";
                info.ShowDialog();

                fs = new FileStream(info.FileName, FileMode.OpenOrCreate, FileAccess.Write);
                sw = new StreamWriter(fs);

                foreach (Component x in Components)
                {
                    if (x.Name == "Pump")
                    {
                        sw.WriteLine(x.Name);
                        sw.WriteLine(((Component)x).Position.X);
                        sw.WriteLine(((Component)x).Position.Y);

                        Pump temp = (Pump)x;
                        sw.WriteLine(temp.Flow);
                    }
                    if (x.Name == "Sink")
                    {
                        sw.WriteLine(x.Name);
                        sw.WriteLine(((Component)x).Position.X);
                        sw.WriteLine(((Component)x).Position.Y);

                        Sink temp = (Sink)x;
                        sw.WriteLine(temp.Flow);
                    }
                    if (x.Name == "Merger")
                    {
                        sw.WriteLine(x.Name);
                        sw.WriteLine(((Component)x).Position.X);
                        sw.WriteLine(((Component)x).Position.Y);
                    }
                    if (x.Name == "Splitter")
                    {
                        sw.WriteLine(x.Name);
                        sw.WriteLine(((Component)x).Position.X);
                        sw.WriteLine(((Component)x).Position.Y);
                    }
                    if (x.Name == "Adjustable Splitter")
                    {
                        sw.WriteLine(x.Name);
                        sw.WriteLine(((Component)x).Position.X);
                        sw.WriteLine(((Component)x).Position.Y);

                        AdjSplitter temp = (AdjSplitter)x;
                        sw.WriteLine(temp.upValue);
                    }
                }
                foreach (Pipe p in Pipes)
                {
                    sw.WriteLine(p.Name);
                    sw.WriteLine(p.FirstPoint.X); //Write coordinates of first point
                    sw.WriteLine(p.FirstPoint.Y);

                    sw.WriteLine(p.SecondPoint.X); //Write coordinates of second point
                    sw.WriteLine(p.SecondPoint.Y);
                    sw.WriteLine(p.Flow);
                }
                sw.WriteLine("*"); //* - means end
                MessageBox.Show("Saving is done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Ejemplo n.º 4
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));
            }
        }