コード例 #1
0
        //public void Recalculate(Component a)
        //{
        //    for(int i = 0; i < 3; i++)
        //    {
        //        a.PipesConnected[i].
        //    }
        //}
        //Drawing Components is done for now.
        public void DrawAllComponents(Graphics gr, ImageList il)
        {
            FontFamily fontFamily = new FontFamily("Arial");
            Font       font       = new Font(
                fontFamily,
                16,
                FontStyle.Bold,
                GraphicsUnit.Pixel);

            foreach (Component component in listOfComponents)
            {
                if (component is Sink)
                {
                    Sink temp = component as Sink;
                    gr.DrawImage(il.Images[0], component.X - il.ImageSize.Width / 2, component.Y - il.ImageSize.Height / 2);
                    gr.DrawString(temp.FlowOnInput.ToString(), font, Brushes.Red, temp.X + 15, temp.Y - 30);
                }
                else if (component is Pump)
                {
                    Pump temp = component as Pump;
                    gr.DrawImage(il.Images[1], temp.X - il.ImageSize.Width / 2, temp.Y - il.ImageSize.Height / 2);
                    gr.DrawString(temp.CurrentFlow.ToString(), font, Brushes.Red, temp.X + 15, temp.Y - 30);
                }
                else if (component is Splitter)
                {
                    if (component is AdjustableSplitter)
                    {
                        AdjustableSplitter temp = component as AdjustableSplitter;
                        gr.DrawImage(il.Images[3], component.X - il.ImageSize.Width / 2, component.Y - il.ImageSize.Height / 2);
                        gr.DrawString(temp.FlowOnOutputA.ToString(), font, Brushes.Red, temp.X + 15, temp.Y - 30);
                        gr.DrawString(temp.FlowOnOutputB.ToString(), font, Brushes.Red, temp.X + 15, temp.Y + 30);
                    }
                    else
                    {
                        Splitter temp = component as Splitter;
                        gr.DrawImage(il.Images[2], component.X - il.ImageSize.Width / 2, component.Y - il.ImageSize.Height / 2);
                        gr.DrawString((temp.InputLevel - temp.InputLevel / 2).ToString(), font, Brushes.Red, temp.X + 15, temp.Y - 30);
                        gr.DrawString((temp.InputLevel / 2).ToString(), font, Brushes.Red, temp.X + 15, temp.Y + 30);
                    }
                }
                else if (component is Merger)
                {
                    Merger temp = component as Merger;
                    gr.DrawImage(il.Images[4], component.X - il.ImageSize.Width / 2, component.Y - il.ImageSize.Height / 2);
                    gr.DrawString(temp.SumOfFlows.ToString(), font, Brushes.Red, temp.X + 15, temp.Y + 30);
                }

                if (component.Pressed == true)
                {
                    Brush brush = new SolidBrush(Color.FromArgb(120, 120, 5, 15));
                    gr.FillRectangle(brush, component.X - il.ImageSize.Width / 2, component.Y - il.ImageSize.Height / 2, il.ImageSize.Width, il.ImageSize.Height);
                }
            }
        }
コード例 #2
0
        public void Recalc(Component c)
        {
            if (c is Sink)
            {
                Sink sinkComponent = (Sink)c;
                if (sinkComponent.PipesConnected[0] != null)
                {
                    if (sinkComponent.PipesConnected[0] is Splitter)
                    {
                        if (sinkComponent.PipesConnected[0] is AdjustableSplitter)
                        {
                            if (sinkComponent.PipesConnected[0].PipesConnected[1] == sinkComponent)
                            {
                                sinkComponent.FlowOnInput = ((AdjustableSplitter)sinkComponent.PipesConnected[0]).FlowOnOutputA;
                                sinkComponent.compFlow    = sinkComponent.FlowOnInput;
                            }
                            else if (sinkComponent.PipesConnected[0].PipesConnected[2] == sinkComponent)
                            {
                                sinkComponent.FlowOnInput += ((AdjustableSplitter)sinkComponent.PipesConnected[0]).FlowOnOutputB;
                                sinkComponent.compFlow     = sinkComponent.FlowOnInput;
                            }
                        }
                        else if (sinkComponent.PipesConnected[0] is Splitter)
                        {
                            if (sinkComponent.PipesConnected[0].PipesConnected[1] == sinkComponent)
                            {
                                sinkComponent.FlowOnInput = sinkComponent.PipesConnected[0].compFlow - sinkComponent.PipesConnected[1].compFlow / 2;
                                sinkComponent.compFlow    = sinkComponent.FlowOnInput;
                            }
                            else if (sinkComponent.PipesConnected[0].PipesConnected[2] == sinkComponent)
                            {
                                sinkComponent.FlowOnInput = sinkComponent.PipesConnected[1].compFlow / 2;
                                sinkComponent.compFlow    = sinkComponent.FlowOnInput;
                            }
                        }
                    }
                    else
                    {
                        sinkComponent.FlowOnInput = sinkComponent.PipesConnected[0].compFlow;
                        sinkComponent.compFlow    = sinkComponent.FlowOnInput;
                        return;
                    }
                }
            }

            else if (c is Merger)
            {
                int    tempOldFlowA    = 0;
                int    tempOldFlowB    = 0;
                Merger mergerComponent = (Merger)c;
                if (mergerComponent.PipesConnected[1] != null && mergerComponent.PipesConnected[2] != null)
                {
                    if (mergerComponent.PipesConnected[1] is AdjustableSplitter)
                    {
                        if (mergerComponent.PipesConnected[1].PipesConnected[1] == mergerComponent)
                        {
                            tempOldFlowA = ((AdjustableSplitter)mergerComponent.PipesConnected[1]).FlowOnOutputA;
                        }
                        else if (mergerComponent.PipesConnected[1].PipesConnected[2] == mergerComponent)
                        {
                            tempOldFlowA = ((AdjustableSplitter)mergerComponent.PipesConnected[1]).FlowOnOutputB;
                        }
                    }
                    else if (mergerComponent.PipesConnected[1] is Splitter)
                    {
                        if (mergerComponent.PipesConnected[1].PipesConnected[1] == mergerComponent)
                        {
                            tempOldFlowA = mergerComponent.PipesConnected[1].compFlow - mergerComponent.PipesConnected[1].compFlow / 2;
                        }
                        else if (mergerComponent.PipesConnected[1].PipesConnected[2] == mergerComponent)
                        {
                            tempOldFlowA = mergerComponent.PipesConnected[1].compFlow / 2;
                        }
                    }


                    //////////////////////////

                    if (mergerComponent.PipesConnected[2] is AdjustableSplitter)
                    {
                        if (mergerComponent.PipesConnected[2].PipesConnected[1] == mergerComponent)
                        {
                            tempOldFlowB = ((AdjustableSplitter)mergerComponent.PipesConnected[2]).FlowOnOutputA;
                        }
                        else if (mergerComponent.PipesConnected[2].PipesConnected[2] == mergerComponent)
                        {
                            tempOldFlowB = ((AdjustableSplitter)mergerComponent.PipesConnected[2]).FlowOnOutputB;
                        }
                    }
                    else if (mergerComponent.PipesConnected[2] is Splitter)
                    {
                        if (mergerComponent.PipesConnected[2].PipesConnected[1] == mergerComponent)
                        {
                            tempOldFlowB = mergerComponent.PipesConnected[2].compFlow - mergerComponent.PipesConnected[2].compFlow / 2;
                        }
                        else if (mergerComponent.PipesConnected[2].PipesConnected[2] == mergerComponent)
                        {
                            tempOldFlowB = mergerComponent.PipesConnected[2].compFlow / 2;
                        }
                    }

                    if (tempOldFlowA != 0 && tempOldFlowB != 0)
                    {
                        mergerComponent.SumOfFlows = tempOldFlowA + tempOldFlowB;
                        mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                    }
                    else if (tempOldFlowA != 0)
                    {
                        mergerComponent.SumOfFlows = tempOldFlowA + mergerComponent.PipesConnected[2].compFlow;
                        mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                    }
                    else if (tempOldFlowB != 0)
                    {
                        mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow + tempOldFlowB;
                        mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                    }
                    else
                    {
                        mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow + mergerComponent.PipesConnected[2].compFlow;
                        mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                    }
                }
                else if (mergerComponent.PipesConnected[1] != null)
                {
                    if (mergerComponent.PipesConnected[1] is Splitter)
                    {
                        if (mergerComponent.PipesConnected[1] is AdjustableSplitter)
                        {
                            if (mergerComponent.PipesConnected[1].PipesConnected[1] == mergerComponent)
                            {
                                mergerComponent.SumOfFlows = ((AdjustableSplitter)mergerComponent.PipesConnected[1]).FlowOnOutputA;
                                mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                            }
                            else if (mergerComponent.PipesConnected[1].PipesConnected[2] == mergerComponent)
                            {
                                mergerComponent.SumOfFlows = ((AdjustableSplitter)mergerComponent.PipesConnected[1]).FlowOnOutputB;
                                mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                            }
                        }
                        else if (mergerComponent.PipesConnected[1] is Splitter)
                        {
                            if (mergerComponent.PipesConnected[1].PipesConnected[1] == mergerComponent)
                            {
                                mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow - mergerComponent.PipesConnected[1].compFlow / 2;
                                mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                            }
                            else if (mergerComponent.PipesConnected[1].PipesConnected[2] == mergerComponent)
                            {
                                mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow / 2;
                                mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                            }
                        }
                    }
                    else
                    {
                        mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow;
                        mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                    }
                }
                else if (mergerComponent.PipesConnected[2] != null)
                {
                    if (mergerComponent.PipesConnected[2] is Splitter)
                    {
                        if (mergerComponent.PipesConnected[2] is AdjustableSplitter)
                        {
                            if (mergerComponent.PipesConnected[2].PipesConnected[1] == mergerComponent)
                            {
                                mergerComponent.SumOfFlows = ((AdjustableSplitter)mergerComponent.PipesConnected[2]).FlowOnOutputA;
                                mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                            }
                            else if (mergerComponent.PipesConnected[2].PipesConnected[2] == mergerComponent)
                            {
                                mergerComponent.SumOfFlows = ((AdjustableSplitter)mergerComponent.PipesConnected[2]).FlowOnOutputB;
                                mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                            }
                        }
                        else if (mergerComponent.PipesConnected[2] is Splitter)
                        {
                            if (mergerComponent.PipesConnected[2].PipesConnected[1] == mergerComponent)
                            {
                                mergerComponent.SumOfFlows = mergerComponent.PipesConnected[2].compFlow - mergerComponent.PipesConnected[2].compFlow / 2;
                                mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                            }
                            else if (mergerComponent.PipesConnected[2].PipesConnected[2] == mergerComponent)
                            {
                                mergerComponent.SumOfFlows = mergerComponent.PipesConnected[2].compFlow / 2;
                                mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                            }
                        }
                    }
                    else
                    {
                        mergerComponent.SumOfFlows = mergerComponent.PipesConnected[2].compFlow;
                        mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                    }
                }
                else
                {
                    mergerComponent.SumOfFlows = 0;
                    mergerComponent.compFlow   = mergerComponent.SumOfFlows;
                }


                if (mergerComponent.PipesConnected[0] != null)
                {
                    mergerComponent.PipesConnected[0].compFlow = mergerComponent.SumOfFlows;
                    Recalc(mergerComponent.PipesConnected[0]);
                }
                return;
            }
            else if (c is AdjustableSplitter)
            {
                AdjustableSplitter adjustableSplitterComponent = (AdjustableSplitter)c;
                if (adjustableSplitterComponent.PipesConnected[0] != null)
                {
                    if (adjustableSplitterComponent.PipesConnected[0] is AdjustableSplitter)
                    {
                        if (adjustableSplitterComponent.PipesConnected[0].PipesConnected[1] == adjustableSplitterComponent)
                        {
                            adjustableSplitterComponent.InputLevel = ((AdjustableSplitter)adjustableSplitterComponent.PipesConnected[0]).FlowOnOutputA;
                            adjustableSplitterComponent.compFlow   = adjustableSplitterComponent.InputLevel;
                        }
                        else if (adjustableSplitterComponent.PipesConnected[0].PipesConnected[2] == adjustableSplitterComponent)
                        {
                            adjustableSplitterComponent.InputLevel = ((AdjustableSplitter)adjustableSplitterComponent.PipesConnected[0]).FlowOnOutputB;
                            adjustableSplitterComponent.compFlow   = adjustableSplitterComponent.InputLevel;
                        }
                    }
                    else if (adjustableSplitterComponent.PipesConnected[0] is Splitter)
                    {
                        adjustableSplitterComponent.InputLevel = adjustableSplitterComponent.PipesConnected[0].compFlow / 2;
                        adjustableSplitterComponent.compFlow   = adjustableSplitterComponent.InputLevel;
                    }
                    else
                    {
                        adjustableSplitterComponent.InputLevel = adjustableSplitterComponent.PipesConnected[0].compFlow;
                        adjustableSplitterComponent.compFlow   = adjustableSplitterComponent.InputLevel;
                    }
                    adjustableSplitterComponent.FlowOnOutputA = adjustableSplitterComponent.compFlow * adjustableSplitterComponent.Proportion / 100;
                    adjustableSplitterComponent.FlowOnOutputB = adjustableSplitterComponent.compFlow - adjustableSplitterComponent.FlowOnOutputA;
                }
                else if (adjustableSplitterComponent.PipesConnected[0] == null)
                {
                    adjustableSplitterComponent.InputLevel = 0;
                    adjustableSplitterComponent.compFlow   = adjustableSplitterComponent.InputLevel;
                }

                if (adjustableSplitterComponent.PipesConnected[1] != null && adjustableSplitterComponent.PipesConnected[2] != null)
                {
                    if (adjustableSplitterComponent.InputLevel != 0)
                    {
                        adjustableSplitterComponent.PipesConnected[1].compFlow = adjustableSplitterComponent.InputLevel * adjustableSplitterComponent.Proportion / 100;
                        adjustableSplitterComponent.FlowOnOutputA = adjustableSplitterComponent.PipesConnected[1].compFlow;
                        adjustableSplitterComponent.PipesConnected[2].compFlow = adjustableSplitterComponent.InputLevel - adjustableSplitterComponent.PipesConnected[1].compFlow;
                        adjustableSplitterComponent.FlowOnOutputB = adjustableSplitterComponent.PipesConnected[2].compFlow;
                        Recalc(adjustableSplitterComponent.PipesConnected[1]);
                        Recalc(adjustableSplitterComponent.PipesConnected[2]);
                    }
                    else if (adjustableSplitterComponent.InputLevel == 0)
                    {
                        adjustableSplitterComponent.PipesConnected[1].compFlow = adjustableSplitterComponent.InputLevel;
                        adjustableSplitterComponent.FlowOnOutputA = adjustableSplitterComponent.PipesConnected[1].compFlow;
                        adjustableSplitterComponent.PipesConnected[2].compFlow = adjustableSplitterComponent.InputLevel;
                        adjustableSplitterComponent.FlowOnOutputB = adjustableSplitterComponent.PipesConnected[2].compFlow;
                        Recalc(adjustableSplitterComponent.PipesConnected[1]);
                        Recalc(adjustableSplitterComponent.PipesConnected[2]);
                    }
                }
                else if (adjustableSplitterComponent.PipesConnected[1] != null)
                {
                    adjustableSplitterComponent.PipesConnected[1].compFlow = adjustableSplitterComponent.InputLevel * adjustableSplitterComponent.Proportion / 100;
                    adjustableSplitterComponent.FlowOnOutputA = adjustableSplitterComponent.PipesConnected[1].compFlow;
                    Recalc(adjustableSplitterComponent.PipesConnected[1]);
                }
                else if (adjustableSplitterComponent.PipesConnected[2] != null)
                {
                    adjustableSplitterComponent.PipesConnected[2].compFlow = adjustableSplitterComponent.InputLevel - (adjustableSplitterComponent.InputLevel * adjustableSplitterComponent.Proportion / 100);
                    adjustableSplitterComponent.FlowOnOutputB = adjustableSplitterComponent.PipesConnected[2].compFlow;
                    Recalc(adjustableSplitterComponent.PipesConnected[2]);
                }
                return;
            }
            else if (c is Splitter)
            {
                Splitter splitterComponent = (Splitter)c;
                if (splitterComponent.PipesConnected[0] != null)
                {
                    if (splitterComponent.PipesConnected[0] is AdjustableSplitter)
                    {
                        if (splitterComponent.PipesConnected[0].PipesConnected[1] == splitterComponent)
                        {
                            splitterComponent.InputLevel = ((AdjustableSplitter)splitterComponent.PipesConnected[0]).FlowOnOutputA;
                            splitterComponent.compFlow   = splitterComponent.InputLevel;
                        }
                        else if (splitterComponent.PipesConnected[0].PipesConnected[2] == splitterComponent)
                        {
                            splitterComponent.InputLevel = ((AdjustableSplitter)splitterComponent.PipesConnected[0]).FlowOnOutputB;
                            splitterComponent.compFlow   = splitterComponent.InputLevel;
                        }
                    }
                    else if (splitterComponent.PipesConnected[0] is Splitter)
                    {
                        splitterComponent.InputLevel = splitterComponent.PipesConnected[0].compFlow / 2;
                        splitterComponent.compFlow   = splitterComponent.InputLevel;
                    }
                    else
                    {
                        splitterComponent.InputLevel = splitterComponent.PipesConnected[0].compFlow;
                        splitterComponent.compFlow   = splitterComponent.InputLevel;
                    }
                }
                else if (splitterComponent.PipesConnected[0] == null)
                {
                    splitterComponent.InputLevel = 0;
                    splitterComponent.compFlow   = splitterComponent.InputLevel;
                }

                if (splitterComponent.PipesConnected[1] != null && splitterComponent.PipesConnected[2] != null)
                {
                    if (splitterComponent.InputLevel != 0)
                    {
                        splitterComponent.PipesConnected[1].compFlow = splitterComponent.InputLevel / 2;
                        splitterComponent.PipesConnected[2].compFlow = splitterComponent.InputLevel - splitterComponent.PipesConnected[1].compFlow;
                        Recalc(splitterComponent.PipesConnected[1]);
                        Recalc(splitterComponent.PipesConnected[2]);
                    }
                    else if (splitterComponent.InputLevel == 0)
                    {
                        splitterComponent.PipesConnected[1].compFlow = splitterComponent.InputLevel;
                        splitterComponent.PipesConnected[2].compFlow = splitterComponent.InputLevel;
                        Recalc(splitterComponent.PipesConnected[1]);
                        Recalc(splitterComponent.PipesConnected[2]);
                    }
                }
                else if (splitterComponent.PipesConnected[1] != null)
                {
                    splitterComponent.PipesConnected[1].compFlow = splitterComponent.InputLevel / 2;
                    Recalc(splitterComponent.PipesConnected[1]);
                }
                else if (splitterComponent.PipesConnected[2] != null)
                {
                    splitterComponent.PipesConnected[2].compFlow = splitterComponent.InputLevel / 2;
                    Recalc(splitterComponent.PipesConnected[2]);
                }
                return;
            }
            if (c is Pump)
            {
                Pump pumpComponent = (Pump)c;
                if (pumpComponent.PipesConnected[0] != null)
                {
                    pumpComponent.PipesConnected[0].compFlow = pumpComponent.CurrentFlow;
                    Recalc(pumpComponent.PipesConnected[0]);
                }
            }
        }
コード例 #3
0
 //Here is the same! We need after changing adjustment to recalculate flows!
 public void AdjustSplitter(AdjustableSplitter adjSplitter)
 {
 }