Example #1
0
        public void createPipe(ComponentTable ct, String[] tokens,StreamReader sr)
        {
            
            idPipe = Convert.ToInt32(tokens[0]);
            int startComponentID = Convert.ToInt32(tokens[1]);
            int endComponentID = Convert.ToInt32(tokens[2]);
            int startType = Convert.ToInt32(tokens[3]);
            int endType = Convert.ToInt32(tokens[4]);
            int maxFlow = Convert.ToInt32(tokens[5]);
            int currentFlow = Convert.ToInt32(tokens[6]);

            Pipe pipe = new Pipe(startComponentID,endComponentID,startType, endType, id, maxFlow);
            pipe.CurrentFlow = currentFlow;

            //Let´s check if there are intermediate points in the pipe
            String[] PipesToken;
            s = sr.ReadLine();
            
            if (s == "startpoints")
            {
                s = sr.ReadLine();
                List<Point> pipesCoordAux = new List<Point>();

                while (s != "endpoints")
                {
                    PipesToken = s.Split();
                    int x = Convert.ToInt32(PipesToken[0]);
                    int y = Convert.ToInt32(PipesToken[1]);
                    Point point = new Point(x, y);
                    pipesCoordAux.Add(point);
                    s = sr.ReadLine();

                }
                pipe.PointOfPipe = pipesCoordAux;
                s = sr.ReadLine();
            }
            
            ct.PipeList.Add(pipe);
            
        }
Example #2
0
        private void leftClickBehaviour(object sender, MouseEventArgs e)
        {
            //You cannot click outside of the mapbox
            if (((e.X + menuImages.Images[0].Width < mapBox.Width) && (e.Y + menuImages.Images[0].Height < mapBox.Height)) || typeC == (int)EnumTypes.Pipe)
            {
                if (ct.OverlappingComp(e.Location, menuImages) != -1 && typeC <= (int)EnumTypes.Merger)
                {
                    MessageBox.Show("There cannot be an overlapping of components!");
                }
                else
                {
                    Component c1 = null; // Creating a Component object in order to use the heritage (subcomponents)
                    
                    switch (typeC) // Switching between type of Component in order to place the different images depending on the clicked button
                    {
                        case (int)EnumTypes.Sink:
                            // Creating the new object (Sick in this case) - The (int)EnumTypes.Sink uses the enum created so you don't need to remember which number is it each type.
                            c1 = new Sink(id, e.Location, 20, (int)EnumTypes.Sink);
                            break;

                        case (int)EnumTypes.Pump:
                            c1 = new Pump(id, e.Location, (int)EnumTypes.Pump);
                            break;

                        case (int)EnumTypes.Merger:
                            c1 = new Merger(id, e.Location, (int)EnumTypes.Merger);
                            break;

                        case (int)EnumTypes.Regulable:
                            c1 = new Regulable(id, e.Location, 1, 50, (int)EnumTypes.Regulable);
                            break;

                        case (int)EnumTypes.Normal:
                            c1 = new Normal(id, e.Location, 0, (int)EnumTypes.Normal);
                            break;

                        case (int)EnumTypes.Pipe:
                            if (idStart == -1)
                            {
                                int resulStart = ct.pointOverlappingComp(e.Location, menuImages);
                                if (resulStart != -1)
                                {
                                    if (ct.isComponentConnectionAvailable(resulStart, e.Location, menuImages) == -1)
                                    {
                                        idStart = resulStart;
                                        typeOfConnectionStart = ct.whatKindOfCoennectionIs(idStart, e.Location, menuImages);
                                    }
                                    else
                                    {
                                        MessageBox.Show(ct.isComponentConnectionAvailable(resulStart, e.Location, menuImages).ToString());
                                        cleanValues();
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("You should click ontop of a component");
                                    cleanValues();
                                }
                            }
                            else
                            {
                                int resulEnd = ct.pointOverlappingComp(e.Location, menuImages);
                                if (resulEnd != -1 && (idStart != resulEnd))
                                {
                                    if (ct.isComponentConnectionAvailable(resulEnd, e.Location, menuImages) == -1)
                                    {
                                        idEnd = resulEnd;
                                        typeOfConnectionEnd = ct.whatKindOfCoennectionIs(idEnd, e.Location, menuImages);

                                        pipeFlowForm = new AskFlow((int)EnumTypes.Pipe);

                                        if (pipeFlowForm.ShowDialog(this) == DialogResult.OK)
                                        {
                                            pipeFlow = (int)pipeFlowForm.GetFlow.Value;

                                            if (pipesCoordAux == null)
                                            {
                                                p = new Pipe(idStart, idEnd, typeOfConnectionStart, typeOfConnectionEnd, pipeId, pipeFlow);
                                            }
                                            else
                                            {
                                                p = new Pipe(idStart, idEnd, typeOfConnectionStart, typeOfConnectionEnd, pipesCoordAux, pipeId, pipeFlow);
                                            }

                                            if (!ct.pipeOverlappingComponent(p, menuImages))
                                            {
                                                //makeConnectionInaccessible
                                                ct.invalidateConnection(idStart, typeOfConnectionStart, pipeId);
                                                ct.invalidateConnection(idEnd, typeOfConnectionEnd, pipeId);
                                                ct.PipeList.Add(p);
                                                pipeId++;

                                                // Inserting the flow into the different components
                                                currentFlow = ct.FlowOut(idStart, typeOfConnectionStart, pipeId);
                                                //MessageBox.Show(currentFlow.ToString());
                                                if (currentFlow >= p.MaxFlow)
                                                {
                                                    p.CurrentFlow = p.MaxFlow;
                                                }
                                                else
                                                {
                                                    p.CurrentFlow = currentFlow;
                                                }
                                                
                                                ct.FlowIn(idEnd, typeOfConnectionEnd, pipeId, p.CurrentFlow);
                                                // End

                                                cleanValues();
                                            }
                                            else
                                            {
                                                MessageBox.Show("This pipe is overlapping a component");
                                                cleanValues();
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Cancelled!");
                                        }

                                        pipeFlowForm.Dispose();
                                    }
                                    else
                                    {
                                        MessageBox.Show(ct.isComponentConnectionAvailable(resulEnd, e.Location, menuImages).ToString());
                                        cleanValues();
                                    }
                                }
                                else
                                {
                                    if (pipesCoordAux == null)
                                    {
                                        pipesCoordAux = new List<Point>();
                                        pipesCoordAux.Add(e.Location);
                                    }
                                    else
                                    {
                                        pipesCoordAux.Add(e.Location);
                                    }
                                }
                            }
                            break;

                        case (int)EnumTypes.Remove:
                            ct.RemoveComp(e.Location, menuImages);
                            break;

                        default:
                            break;
                    }

                    if (c1 != null)
                    {
                        id++; // Increments the id of component
                        ct.CompList.Add(c1); // Adding component to the List in the ComponentTable.
                    }
                    else if (c1 == null && typeC > (int)EnumTypes.Pipe)
                    { // If theres no component created and the typeC is out from the component range
                        if(typeC != (int)EnumTypes.Remove)
                            MessageBox.Show("Error selecting object.");
                    }
                }
                Refresh();
            }
        }
Example #3
0
        public bool pipeOverlappingComponent(Pipe p, ImageList iL)
        {
            Point p1 = new Point(compList.Find(x => x.Id == p.StartComponentID).Coord.X, compList.Find(x => x.Id == p.StartComponentID).Coord.Y);
            Point p2 = new Point(compList.Find(x => x.Id == p.EndComponentID).Coord.X, compList.Find(x => x.Id == p.EndComponentID).Coord.Y);

            foreach (Component c in CompList)
            {
                if (c.Id != p.StartComponentID && c.Id != p.EndComponentID)
                {
                    Rectangle r = new Rectangle(c.Coord.X, c.Coord.Y, iL.Images[0].Width, iL.Images[0].Height);

                    if (LineIntersectsLine(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)) ||
                  LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)) ||
                  LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)) ||
                  LineIntersectsLine(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)) ||
                  (r.Contains(p1) && r.Contains(p2)))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
Example #4
0
 private void cleanValues()
 {
     idStart = -1;
     idEnd = -1;
     typeOfConnectionStart = -1;
     typeOfConnectionEnd = -1;
     pipesCoordAux = null;
     p = null;
 }