private void createMerger(ComponentTable ct, String[] tokens)
        {
            id = Convert.ToInt32(tokens[1]);
            x  = Convert.ToInt32(tokens[2]);
            y  = Convert.ToInt32(tokens[3]);
            int    isIn1Avail = Convert.ToInt32(tokens[4]);
            int    isIn2Avail = Convert.ToInt32(tokens[5]);
            int    isOutAvail = Convert.ToInt32(tokens[6]);
            int    in1Flow    = Convert.ToInt32(tokens[7]);
            int    in2Flow    = Convert.ToInt32(tokens[8]);
            int    outFlow    = Convert.ToInt32(tokens[9]);
            Point  p          = new Point(x, y);
            Merger merger     = new Merger(id, p, type);

            ct.CompList.Add(merger);
            merger.IsIn1Available = isIn1Avail;
            merger.IsIn2Available = isIn2Avail;
            merger.IsOutAvailable = isOutAvail;
            merger.FlowIn1        = in1Flow;
            merger.FlowIn2        = in2Flow;
            merger.GetFlowOut     = outFlow;
        }
Exemple #2
0
 private void createMerger(ComponentTable ct, String[] tokens)
 {
     id = Convert.ToInt32(tokens[1]);
     x = Convert.ToInt32(tokens[2]);
     y = Convert.ToInt32(tokens[3]);
     int isIn1Avail = Convert.ToInt32(tokens[4]);
     int isIn2Avail = Convert.ToInt32(tokens[5]);
     int isOutAvail = Convert.ToInt32(tokens[6]);
     int in1Flow = Convert.ToInt32(tokens[7]);
     int in2Flow = Convert.ToInt32(tokens[8]);
     int outFlow = Convert.ToInt32(tokens[9]);
     Point p = new Point(x, y);
     Merger merger = new Merger(id, p, type);
     ct.CompList.Add(merger);
     merger.IsIn1Available = isIn1Avail;
     merger.IsIn2Available = isIn2Avail;
     merger.IsOutAvailable = isOutAvail;
     merger.FlowIn1 = in1Flow;
     merger.FlowIn2 = in2Flow;
     merger.GetFlowOut = outFlow;
 }
Exemple #3
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, 0, (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);

                                    if (ct.isTheConecctionPossible(typeOfConnectionStart, typeOfConnectionEnd))
                                    {
                                        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;
                                                 * }*/

                                                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("This kind of connection isn´t possible");
                                        cleanValues();
                                    }
                                }
                                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();
            }
        }