Example #1
0
        private bool CheckIntersectAllOther(Point start, Point end, Pipe currentPipe)
        {
            if (CheckInteresectsWithSelf(start, end, currentPipe))
            {
                return false;
            }
            int listOfComponentsCount = listOfComponents.Count;
            for (int i = 0; i < listOfComponentsCount; i++)
            {
                ComponentDrawn d = listOfComponents[i];

                if (d is Pipe)
                {
                    if (CheckInteresectsWithPipe(start, end, currentPipe, d as Pipe))
                    {
                        return true;
                    }
                }
            }
            bool isColliding = false;
            for (int i = 0; i < listOfComponentsCount; i++)
            {
                ComponentDrawn d = listOfComponents[i];
                if (d != currentPipe.GiveMeYourConnectionPoints().Last().ComponentDrawnBelong)

                    if (CheckInteresectsWithComponentDrawn(start, end, currentPipe, d))
                    {
                        if (d.RectangleBig.Contains(start))
                        {
                            continue;
                        }
                        MessageBox.Show("Intersects component");
                        return true;

                    }
            }
            return false;
        }
Example #2
0
        private void grid_Click(object sender, EventArgs e)
        {
            if (currentPB != null)
            {
                //if(theImageLocationIsValid)
                int x = xPos;
                int y = yPos;
                if (currentWorkingMode != WorkingMode.pipe)
                {
                    if (pipe != null)
                    {
                        flowly.RemovePipe(pipe);
                        pipe = null;
                        lastPoint = new Point(-1, -1);
                    }
                }
                Point newPoint;
                switch (currentWorkingMode)
                {
                    case WorkingMode.pipe:
                        ResetProperties();
                        if (currentPB.Image.Equals(toolPipe.Image))
                        {
                            newPoint = new Point(x, y);
                            //  MessageBox.Show(newPoint.ToString() + "\nx:" + newPoint.X + " y:" + newPoint.Y);
                            //start drawing pipeline.
                            if (lastPoint.X == -1 || lastPoint.Y == -1)
                            {
                                ConnectionPoint cp = flowly.GetConnectionPointAt(newPoint);
                                if (cp != null)
                                {

                                    if (cp.IsOutput)
                                    {
                                        flowly.CreateChange("Pipeline");////////////////////////////////
                                        newPoint = cp.PipeStartPoint;
                                        // cp.SetAvailable(false);
                                        pipe = new Pipe();
                                        pipe.SetConnection(cp);
                                        cp.PipeConnection = pipe;
                                        lastPoint = newPoint;
                                        pipe.AddPointToList(lastPoint);
                                        flowly.HighlightAllAvailableInputs(pipe.GiveMeYourConnectionPoints().First().ComponentDrawnBelong);
                                    }
                                }
                                else
                                {

                                    return;
                                }
                            }
                            else
                            {

                                bool isAdded = flowly.DrawPipeToCursor(lastPoint, newPoint, ref pipe);
                                if (isAdded)
                                {
                                    //continues drawing line
                                    lastPoint = newPoint;

                                    //when connected to a component stops
                                    if (pipe.GiveMeYourConnectionPoints().Count == 2)
                                    {

                                        pipe.PipePoints.RemoveAt(pipe.PipePoints.Count - 1);
                                        pipe.PipePoints.Add(pipe.GiveMeYourConnectionPoints().Last().PipeStartPoint);
                                        flowly.DrawPipeline(pipe);
                                        flowly.AddComponentDrawn(pipe);

                                        flowly.UpdateGrid();
                                        flowly.HighlightAllAvailableOutputs();
                                        MessageBox.Show("Connected");
                                        pipe = null;
                                        lastPoint = new Point(-1, -1);

                                    }
                                }
                            }
                        }

                        break;
                    case WorkingMode.create:
                        //  ResetProperties();

                        x -= currentPB.Width / 2;
                        y -= currentPB.Height / 2;
                        if (flowly.Grid == null)
                        {
                            MessageBox.Show("No grid is open! Create a new grid or open an existing one!");

                        }
                        else
                        {
                            int width = currentPB.Width;
                            int height = currentPB.Height;
                            Rectangle r = new Rectangle(x, y, width, height);

                            if (flowly.CheckFreeSpot(r))
                            {
                                ComponentName currentComponentName;
                                ComponentDrawn createdComponent;
                                if (currentPB.Image.Equals(toolPump.Image))
                                {
                                    currentComponentName = ComponentName.Pump;
                                }
                                else if (currentPB.Image.Equals(toolPipe.Image))
                                {
                                    currentComponentName = ComponentName.Pipe;
                                }
                                else if (currentPB.Image.Equals(toolSplitter.Image))
                                {
                                    currentComponentName = ComponentName.Splitter;
                                }
                                else if (currentPB.Image.Equals(toolSplitterAdj.Image))
                                {
                                    currentComponentName = ComponentName.SplitterAdj;
                                }
                                else if (currentPB.Image.Equals(toolMerger.Image))
                                {
                                    currentComponentName = ComponentName.Merger;
                                }
                                else //then it's a sink
                                {
                                    currentComponentName = ComponentName.Sink;
                                }

                                if (flowly.CreateComponentDrawn(currentComponentName, r, nudFlow.Value, nudCapacity.Value, trackBarLeft.Value, trackBarRight.Value))
                                {

                                    if (currentComponentName == ComponentName.Pump)
                                    {

                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("The element is coliding with another element.");
                            }

                        }
                        // KeyValuePair<Rectangle, Image> item = new KeyValuePair<Rectangle, Image>(r, currentPB.Image);

                        // dictionary.Add(r, currentPB.Image);

                        // Paint(item);

                        //    ResetProperties();
                        break;
                    case WorkingMode.remove:
                        ResetProperties();

                        newPoint = new Point(x, y);
                        ComponentDrawn componentAtPoint = flowly.GetComponentPointAt(newPoint);
                        if (componentAtPoint == null)
                        {
                            if (flowly.Grid == null)
                            {
                                MessageBox.Show("No grid is open! Create a new grid or open an existing one!");
                            }
                            else
                            {
                                MessageBox.Show("No component selected");
                            }

                            return;
                        }
                        else
                        {

                            DialogResult dg = MessageBox.Show(String.Format("Do you wish to delete {0}?", componentAtPoint.GetType().Name), "Deleting component", MessageBoxButtons.YesNo);
                            if (dg == DialogResult.Yes)
                            {
                                flowly.DeleteComponent(componentAtPoint);

                            }

                        }

                        break;
                    case WorkingMode.edit:

                        ResetProperties();
                        newPoint = new Point(x, y);
                        currentSelectedComponent = flowly.GetComponentPointAt(newPoint);
                        if (currentSelectedComponent == null)
                        {
                            if (flowly.Grid == null)
                            {
                                MessageBox.Show("No grid is open! Create a new grid or open an existing one!");
                            }
                            else
                            {
                                MessageBox.Show("No component selected");
                            }

                            return;
                        }
                        //If component is adjustable splitter ->
                        if (currentSelectedComponent.DiffCurrFlowPossible == true)
                        {

                            SetTrackBarVisibility(true);
                            List<ConnectionPoint> currentOutputConnectionPoints = new List<ConnectionPoint>();
                            foreach (ConnectionPoint item in currentSelectedComponent.GiveMeYourConnectionPoints())
                            {
                                if (item.IsOutput)
                                {
                                    currentOutputConnectionPoints.Add(item);
                                }
                            }
                            //if (currentSelectedComponent.CurrentFlow == 0)
                            //{
                            //    trackBarLeft.Value = 50;
                            //    trackBarRight.Value = 50;
                            //}
                            //else
                            //{
                            //    int maxFlow = Convert.ToInt32(currentSelectedComponent.CurrentFlow);
                            //    trackBarLeft.Value = Convert.ToInt32((maxFlow - currentOutputConnectionPoints[1].CurrentFlow) * 100) / maxFlow;
                            //    trackBarRight.Value = Convert.ToInt32((maxFlow - currentOutputConnectionPoints[0].CurrentFlow) * 100) / maxFlow;
                            //}

                            Splitter testSplitter = (Splitter)currentSelectedComponent;
                            trackBarLeft.Value = testSplitter.TopOutputPercentage;
                            trackBarRight.Value = testSplitter.BottomOutputPercentage;

                            SetTrackBarVisibility(true);
                        }
                        else
                        {

                            SetTrackBarVisibility(false);

                            trackBarLeft.Enabled = false;
                            trackBarLeft.Value = 50;
                            trackBarRight.Enabled = false;
                            trackBarRight.Value = 50;

                        }
                        nudCapacity.Value = (decimal)currentSelectedComponent.Capacity;
                        nudFlow.Value = (decimal)currentSelectedComponent.CurrentFlow;

                        btnUpdate.Enabled = true;
                        if (currentSelectedComponent.EditableProperties.Contains(EditablePropertiesEnum.flow))
                        {
                            nudFlow.Enabled = true;
                        }
                        else
                        {
                            nudFlow.Enabled = false;
                        }
                        if (currentSelectedComponent.EditableProperties.Contains(EditablePropertiesEnum.capacity))
                        {
                            nudCapacity.Enabled = true;
                        }
                        else
                        {
                            nudCapacity.Enabled = false;
                        }

                        break;
                    default:
                        break;

                }
                // KeyValuePair<Rectangle, Image> item = new KeyValuePair<Rectangle, Image>(r, currentPB.Image);

                // dictionary.Add(r, currentPB.Image);

                // Paint(item);
            }
        }
Example #3
0
        internal void RemovePipe(Pipe pipe)
        {
            foreach (ConnectionPoint CP in pipe.GiveMeYourConnectionPoints())
            {
                foreach (ComponentDrawn cd in this.ListOfComponents)
                {
                    cd.FlowWasUpdated = false;
                }
                if (!CP.IsOutput)
                {
                    Queue<ComponentDrawn> elements = new Queue<ComponentDrawn>();

                    ComponentDrawn drawnComponent = CP.ComponentDrawnBelong;
                    CP.PipeConnection.GetEndConnectionPoint().SetCurrentFlow(0);
                    elements.Enqueue(drawnComponent);

                    while (elements.Count > 0)
                    {
                        drawnComponent = elements.Dequeue();

                        drawnComponent.UpdateComponentFlow();
                        drawnComponent.FlowWasUpdated = true;
                        List<ConnectionPoint> lcp = drawnComponent.GiveMeYourOutputConnectionPoints();

                        foreach (ConnectionPoint output in lcp)
                        {

                            if (output.PipeConnection != null)
                            {
                                if (!output.PipeConnection.GetEndConnectionPoint().ComponentDrawnBelong.FlowWasUpdated)
                                {
                                    output.PipeConnection.GetEndConnectionPoint().SetCurrentFlow(drawnComponent.CurrentFlow - CP.CurrentFlow);

                                    elements.Enqueue(output.PipeConnection.GetEndConnectionPoint().ComponentDrawnBelong);
                                }
                            }
                        }
                    }

                }
                CP.PipeConnection = null;
            }
            ListOfComponents.Remove(pipe);
        }