//Constructor public Pipeline(Component startComp, Component endComp, Point startCompLoc, Point endCompLoc, IList<Point> inbetweenPts) { this.InBetweenPoints = inbetweenPts; this.StartComponent = startComp; this.EndComponent = endComp; this.StartPoint = startCompLoc; this.EndPoint = endCompLoc; }
private void panel1_MouseDoubleClick(object sender, MouseEventArgs e) { selectedComponent = myNetwork.GetComponent(e.Location); Pump p = selectedComponent as Pump; if (p != null) { this.tbCurrentFlow.Text = p.Flow.ToString(); this.tbCapacity.Text = p.Capacity.ToString(); } Components.Splitter splitterComp = selectedComponent as Components.Splitter; if (splitterComp != null && splitterComp.IsAdjustable) { splitterTrackBar.Visible = true; AdjSplitLb.Visible = true; AdjSplitLb1.Visible = true; } else { splitterTrackBar.Visible = false; AdjSplitLb.Visible = false; AdjSplitLb1.Visible = false; } if (selectedComponent != null) { selectedPipeline = null; selectedPipelineLoc = new Point(0, 0); } else { selectedPipelineLoc = e.Location; } panel1.Invalidate(); }
private void panel1_MouseClick(object sender, MouseEventArgs e) { if (type != ComponentType.NONE && type != ComponentType.PIPELINE) { Component c = myNetwork.CreateComponent(type, e.X, e.Y); if (panel1.DisplayRectangle.Contains(c.ComponentBox)) { myNetwork.AddComponent(c); } } if (type == ComponentType.PIPELINE) { if (startComp == null) { startComp = myNetwork.GetComponent(e.Location); startCompLoc = e.Location; return; } endComp = myNetwork.GetComponent(e.Location); if (endComp == null) { inbetweenPts.Add(e.Location); return; } endCompLoc = e.Location; myNetwork.RegisterPipeline(startComp, endComp, startCompLoc, endCompLoc, inbetweenPts); ClearVariables(); type = ComponentType.NONE; } panel1.Invalidate(); }
private void ClearVariables() { this.startComp = null; this.endComp = null; this.inbetweenPts = new List<Point>(); }
private void btnUpdateFlow_Click(object sender, EventArgs e) { if (selectedComponent != null) { if (selectedComponent is Pump) { Pump p = (Pump)selectedComponent; double capacity; double flow; if (double.TryParse(tbCapacity.Text, out capacity) && double.TryParse(tbCurrentFlow.Text, out flow)) { p.SetFlow(capacity, flow); } else { MessageBox.Show("Invalid values!"); } } selectedComponent = null; this.tbCurrentFlow.Text = ""; this.tbCapacity.Text = ""; panel1.Invalidate(); } else if (selectedPipeline != null) { double maxFlow; if (double.TryParse(tbCapacity.Text, out maxFlow)) { selectedPipeline.ChangeMaxFlow(maxFlow); } else { MessageBox.Show("Invalid max value!"); } selectedPipeline = null; this.tbCurrentFlow.Text = ""; this.tbCapacity.Text = ""; panel1.Invalidate(); } }
private void btnRemove_Click(object sender, EventArgs e) { if (selectedComponent != null) { myNetwork.RemoveComponent(selectedComponent); myNetwork.RemovePipeline(selectedComponent); selectedComponent = null; type = ComponentType.NONE; if (splitterTrackBar.Visible) { splitterTrackBar.Visible = false; AdjSplitLb1.Visible = false; AdjSplitLb.Visible = false; } } if (selectedPipeline != null) { myNetwork.RemovePipeline(selectedPipeline); selectedPipeline = null; selectedPipelineLoc = new Point(0, 0); type = ComponentType.NONE; } this.tbCapacity.Text = ""; this.tbCurrentFlow.Text = ""; panel1.Invalidate(); }
/// <summary> /// Adds a component to the list after checking if the component overlaps with any of the other components. /// </summary> /// <param name="comp">The component that must be added.</param> /// <returns>True if the component has been added,otherwise-false.</returns> public bool AddComponent(Component comp) { foreach (Component c in MyComponents) { if (c.CheckOverlapComponent(comp)) { return false; } } MyComponents.Add(comp); return true; }
/// <summary> /// Validates whether the pipeline is eligible and should be created. /// </summary> /// <param name="startComp">The starting comp of the pipeline.</param> /// <param name="endComp">The ending comp of the pipeline.</param> /// <param name="startCompLoc">The location of the starting comp.</param> /// <param name="endCompLoc">The location of the ending comp.</param> /// <remarks>The following criterias must be met /// 1. The location for both starting and ending point must be empty/ /// 2. The starting comp can't be Sink.The ending comp can't be Pump. /// 3. The starting and ending comp must be different.</remarks> /// <returns>A boolean indicating whether the pipeline is eligible.</returns> private bool ValidatePipeline(Component startComp, Component endComp, Point startCompLoc, Point endCompLoc) { if (!(startComp.IsLocationEmpty(startCompLoc) && endComp.IsLocationEmpty(endCompLoc))) { return false; } if (startComp == endComp) { return false; } if (startComp is Sink || endComp is Pump) { return false; } return true; }
/// <summary> /// Creates a pipeline between the starting and ending component based on their location. /// </summary> /// <param name="startComp">The starting component of the pipeline.</param> /// <param name="endComp">The ending component of the pipeline.</param> /// <param name="startCompLoc">The location of the starting component.</param> /// <param name="endCompLoc">The location of the ending component.</param> /// <param name="inbetweenPts">The list of points that the pipeline consists of.</param> /// <returns>A newly created pipeline.</returns> private Pipeline CreatePipeline(Component startComp, Component endComp, Point startCompLoc, Point endCompLoc, IList<Point> inbetweenPts) { Point startPoint = (Point)startComp.GetPipelineLocation(startCompLoc); Point endPoint = (Point)endComp.GetPipelineLocation(endCompLoc); return new Pipeline(startComp, endComp, startPoint, endPoint, inbetweenPts); }
/// <summary> /// Removes a pipeline from the pipeline list and sets its starting and ending component to null. /// </summary> /// <param name="c">The component for which all the pipelines will removed.</param> public void RemovePipeline(Component c) { foreach (var pipe in c.GetPipelines()) { pipe.ClearComponents(); this.Pipelines.Remove(pipe); } }
/// <summary> /// Removes a component from the list. /// </summary> /// <param name="c">The component that has to be removed.</param> public void RemoveComponent(Component c) { MyComponents.Remove(c); }
/// <summary> /// Creates a pipeline using the private <see cref="CreatePipeline(Component, Component, Point, Point, List{Point})"/> method. /// Then the pipeline is added to the list. /// </summary> /// <param name="startComp">The starting component of the pipeline.</param> /// <param name="endComp">The ending component of the pipeline.</param> /// <param name="startCompLoc">The location of the starting component.</param> /// <param name="endCompLoc">The location of the ending component.</param> /// <param name="inBetweenPts">The list of points that the pipeline consists of.</param> public void RegisterPipeline(Component startComp, Component endComp, Point startCompLoc, Point endCompLoc, List<Point> inBetweenPts) { if (ValidatePipeline(startComp, endComp, startCompLoc, endCompLoc)) { Pipeline p = CreatePipeline(startComp, endComp, startCompLoc, endCompLoc, inBetweenPts); startComp.SetPipeline(startCompLoc, p); endComp.SetPipeline(endCompLoc, p); AddPipeline(p); } }
/// <summary> /// Checks if the other component overlaps with this one. /// </summary> /// <param name="otherComponent">The component that is checked.</param> /// <returns>True if the two components overlap.Otherwise false.</returns> public bool CheckOverlapComponent(Component otherComponent) { return this.ComponentBox.IntersectsWith(otherComponent.ComponentBox); }