示例#1
0
        private void createRegulable(ComponentTable ct, String[] tokens)
        {
            id = Convert.ToInt32(tokens[1]);
            x  = Convert.ToInt32(tokens[2]);
            y  = Convert.ToInt32(tokens[3]);
            int       splitterType = Convert.ToInt32(tokens[4]);
            int       isInAvail    = Convert.ToInt32(tokens[5]);
            int       isOut1Avail  = Convert.ToInt32(tokens[6]);
            int       isOut2Avail  = Convert.ToInt32(tokens[7]);
            int       inFlow       = Convert.ToInt32(tokens[8]);
            int       out1Flow     = Convert.ToInt32(tokens[9]);
            int       out2Flow     = Convert.ToInt32(tokens[10]);
            int       percentage   = Convert.ToInt32(tokens[11]);
            Point     p            = new Point(x, y);
            Regulable regulable    = new Regulable(id, p, splitterType, percentage, type);

            ct.CompList.Add(regulable);
            regulable.IsInAvailable   = isInAvail;
            regulable.IsOut1Available = isOut1Avail;
            regulable.IsOut2Available = isOut2Avail;
            regulable.GetFlowIn       = inFlow;
            regulable.GetFlowOut1     = out1Flow;
            regulable.GetFlowOut2     = out2Flow;
            regulable.GetFlowOut2     = out2Flow;
        }
示例#2
0
 private void createRegulable(ComponentTable ct, String[] tokens)
 {
     id = Convert.ToInt32(tokens[1]);
     x = Convert.ToInt32(tokens[2]);
     y = Convert.ToInt32(tokens[3]);
     int splitterType = Convert.ToInt32(tokens[4]);
     int isInAvail = Convert.ToInt32(tokens[5]);
     int isOut1Avail = Convert.ToInt32(tokens[6]);
     int isOut2Avail = Convert.ToInt32(tokens[7]);
     int inFlow = Convert.ToInt32(tokens[8]);
     int out1Flow = Convert.ToInt32(tokens[9]);
     int out2Flow = Convert.ToInt32(tokens[10]);
     int percentage = Convert.ToInt32(tokens[11]);
     Point p = new Point(x, y);
     Regulable regulable = new Regulable(id, p, splitterType,percentage, type);
     ct.CompList.Add(regulable);
     regulable.IsInAvailable = isInAvail;
     regulable.IsOut1Available = isOut1Avail;
     regulable.IsOut2Available = isOut2Avail;
     regulable.GetFlowIn = inFlow;
     regulable.GetFlowOut1 = out1Flow;
     regulable.GetFlowOut2 = out2Flow;
     regulable.GetFlowOut2 = out2Flow;
     
 }
示例#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();
            }
        }
示例#4
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();
            }
        }