public Form1() { this.SetStyle( System.Windows.Forms.ControlStyles.UserPaint | System.Windows.Forms.ControlStyles.AllPaintingInWmPaint | System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer, true); InitializeComponent(); askMeSave = false; foreach (Control item in this.groupBox1.Controls) { if (item != toolPipe && item != toolEdit && item != toolRemove) if (item.Name.ToLower().StartsWith("tool")) { PictureBox pb = item as PictureBox; item.Click += (x, y) => ActivateCreating(pb); } } theGrid = new Grid(grid); flowly = new SystemFlowly(theGrid, this, this); currentSelectedComponent = null; SetTrackBarVisibility(false); }
public ConnectionPoint(Rectangle theRectangle, ComponentDrawn theComponentDrawnBelong, bool theIsOutput, Point pipeConnectionPoint) { this.PipeStartPoint = pipeConnectionPoint; rectangle = theRectangle; SetCurrentFlow(0); isOutput = theIsOutput; componentDrawnBelong = theComponentDrawnBelong; //SetAvailable(true); }
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); } }
private void HighlightPointsOfComponent(ComponentDrawn cd) { }
private bool CheckInteresectsWithComponentDrawn(Point start, Point end, Pipe currentPipe, ComponentDrawn d) { Rectangle dRect = d.RectangleBig; Point p = new Point(dRect.X, dRect.Y); Point p2 = new Point(dRect.X + dRect.Width, dRect.Y); if (CheckPipeIntersects(start, end, p, p2)) { return true; } p = new Point(dRect.X + dRect.Width, dRect.Y); p2 = new Point(dRect.X + dRect.Width, dRect.Y + dRect.Height); if (CheckPipeIntersects(start, end, p, p2)) { return true; } p = new Point(dRect.X, dRect.Y + dRect.Height); p2 = new Point(dRect.X + dRect.Width, dRect.Y + dRect.Height); if (CheckPipeIntersects(start, end, p, p2)) { return true; } p = new Point(dRect.X, dRect.Y); p2 = new Point(dRect.X, dRect.Y + dRect.Height); if (CheckPipeIntersects(start, end, p, p2)) { return true; } return false; }
internal void HighightAllAvailableInputs(ComponentDrawn currentComponent) { foreach (ComponentDrawn cd in ListOfComponents) { if (cd != null) { foreach (ConnectionPoint cp in cd.GiveMeYourConnectionPoints()) { if ((cp.Available && !cp.IsOutput) && currentComponent != cd) { DrawConnectionPointLimits(Brushes.Blue, cp); } else { DrawConnectionPointLimits(Brushes.Red, cp); } } } } }
/// <summary> /// Opposite of the other method. /// </summary> /// <param name="givenComponent"></param> /// <returns>True if successfull, false otherwise.</returns> public virtual bool RemoveComponentDrawnFromGridList(ComponentDrawn givenComponent) { //try // { foreach (ConnectionPoint cp in givenComponent.GiveMeYourConnectionPoints()) { if (cp.PipeConnection != null) { RemovePipe(cp.PipeConnection); } } this.ListOfComponents.Remove(givenComponent); PaintAllComponents(); return true; // } //catch (Exception e) //{ // MessageBox.Show("There are a problem removing the component to the grid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // return false; //} }
public void Paint(ComponentDrawn drawn) { if (drawn is Pipe) { Pipe d = drawn as Pipe; DrawPipelineAndUpdateFLow(d); return; } Rectangle r = drawn.RectangleBig; // graphic.DrawRectangle(Pens.Red, r); graphic.DrawImage(drawn.Image, r); graphic.DrawString("C: " + drawn.Capacity.ToString() + " / F: " + drawn.CurrentFlow.ToString(), SystemFonts.DefaultFont, Brushes.Black, r.X, r.Y - r.Width /4); }
/// <summary> /// Adds a component to the listOfComponents list. /// </summary> /// <param name="givenComponent"></param> /// <returns>True if successfull, false otherwise</returns> public virtual bool AddComponentDrawnToGridList(ComponentDrawn givenComponent) { try { this.ListOfComponents.Add(givenComponent); return true; } catch (Exception e) { MessageBox.Show("There are a problem adding the component to the grid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } }
/// <summary> /// The opposite action of method AddComponentDrawnToList. /// </summary> /// <param name="givenComponent"></param> /// <returns>True if successfull, false otherwise.</returns> public virtual bool RemoveComponentDrawnFromList(ComponentDrawn givenComponent) { try { listOfComponentDrawn.Remove(givenComponent); return true; } catch { return false; } }
/// <summary> /// Adds neighbour component to listOfComponentDrawn list. /// </summary> /// <param name="givenComponent"></param> /// <returns>True if successfull, false otherwise</returns> public virtual bool AddComponentDrawnToList(ComponentDrawn givenComponent) { try { listOfComponentDrawn.Add(givenComponent); return true; } catch { return false; } }