public void removePipes(Component c, Graphics graphic) { { if ((((Pipe)c).InputA != null) && (((Pipe)c).InputA is Pipe)) { removePipes(((Pipe)c).InputA, graphic); } if ((((Pipe)c).OutputA != null) && (((Pipe)c).OutputA is Pipe)) { removePipes(((Pipe)c).OutputA, graphic); } Components.Remove(c); grid.unDrawComponent(c, graphic); } Components.Remove(c); //componentToRemove just an example //<<<<<<< HEAD PointP p = new PointP(1, 1); Component splitter = new Splitter(p); grid.unDrawComponent(splitter, graphic); grid.unDrawComponent(c, graphic); //======= grid.unDrawComponent(c, graphic); //>>>>>>> origin/master //then delete the component //return true; }
PointP p; // for testing right click public PipeSystem() { Components = new List<Component>(); p = new PointP(); // populating the list for testing purposes }
public PointP returnMousePosition(Point mousePosition) { PointP gridSpace = new PointP(); gridSpace.X = Convert.ToSingle(mousePosition.X / xSpace); gridSpace.Y = Convert.ToSingle(mousePosition.Y / ySpace); gridSpace.X = (float)Math.Floor(gridSpace.X); gridSpace.Y = (float)Math.Floor(gridSpace.Y); return(gridSpace); }
public bool CheckCordinates(PointP tocheck) { if (tocheck.X == X && tocheck.Y == Y) { return(true); } return(false); }
PointP returnMousePosition(Point mousePosition) { PointP gridSpace = null; gridSpace.X = Convert.ToSingle(mousePosition.X / xSpace); gridSpace.Y = Convert.ToSingle(mousePosition.Y / ySpace); Math.Floor(gridSpace.X); Math.Floor(gridSpace.Y); return(gridSpace); }
//Component selectedComponent = null; public Form1() { InitializeComponent(); system.showsave += allowSave; system.saveload = new SaveLoad(); system.grid = new Grid(GridPanel, system.CurrentXsize); system.drawTheComponent += drawComponent; p = new PointP(); //When the SaveSinceLast is at anypoint turned to false, //an event will rise not allowing the Save Button to be clicked }
private void button2_Click(object sender, EventArgs e) { PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel position = system.grid.returnMousePosition(point); foreach (Component c in system.Components) { // checks if a component with the current location exists if (c.location.X == p.X && c.location.Y == p.Y) { label2.Text = c.Flow.ToString(); } } }
private void RightClickInputB_Click(object sender, EventArgs e) { PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel position = system.grid.returnMousePosition(point); foreach (Component c in system.Components) { // checks if a component with the current location exists if (c.location.X == p.X && c.location.Y == p.Y) { // parameter neeed to be assignet selector = Selection.InputB; } } }
private void button1_Click(object sender, EventArgs e) { try { int flow = Convert.ToInt32(textBox1.Text); PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel position = system.grid.returnMousePosition(point); foreach (Component c in system.Components) { // checks if a component with the current location exists if (c.location.X == p.X && c.location.Y == p.Y) { c.SetFlow(flow); } } } catch (Exception ex) { MessageBox.Show("error: " + ex.Message); } }
public Pump(PointP loc) : base(loc) { }
public Splitter(PointP loc) : base(loc) { Ratio = 50; }
public Component(PointP loc) { location = loc; }
public Sink(PointP loc) : base(loc) { }
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) { PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel position = system.grid.returnMousePosition(point); //RightClickInputA.Visible = false; //RightClickInputB.Visible = false; //RightClickOutputA.Visible = false; //RightClickOutputB.Visible = false; //RightClickChange.Visible = false; //RightClickDelete.Visible = false; RightClickInputA.Enabled = false; RightClickInputB.Enabled = false; RightClickOutputA.Enabled = false; RightClickOutputB.Enabled = false; RightClickDelete.Enabled = false; RightClickChange.Enabled = false; int x = -1; foreach (Component c in system.Components) { x++; // checks if a component with the current location exists if (c.location.X == p.X && c.location.Y == p.Y) { system.index = x; //system.selectedComponent = c; // toolStripMenuItem1.HideDropDown(); if (c is Pipe) { // when you right click only Pipe properties are shown //RightClickInputA.Visible = true; //RightClickOutputA.Visible = true; //RightClickChange.Visible = true; //RightClickDelete.Visible = true; RightClickInputA.Enabled = true; RightClickInputB.Enabled = false; RightClickOutputA.Enabled = true; RightClickOutputB.Enabled = false; RightClickChange.Enabled = true; RightClickDelete.Enabled = true; } else if (c is Pump) { //RightClickOutputA.Visible = true; //RightClickChange.Visible = true; //RightClickDelete.Visible = true; RightClickInputA.Enabled = false; RightClickInputB.Enabled = false; RightClickOutputA.Enabled = true; RightClickOutputB.Enabled = false; RightClickChange.Enabled = true; RightClickDelete.Enabled = true; } else if (c is Merger) { //RightClickInputA.Visible = true; //RightClickOutputA.Visible = true; //RightClickOutputB.Visible = true; //RightClickChange.Visible = true; //RightClickDelete.Visible = true; RightClickInputA.Enabled = true; RightClickInputB.Enabled = true; RightClickOutputA.Enabled = true; RightClickOutputB.Enabled = false; RightClickChange.Enabled = true; RightClickDelete.Enabled = true; } else if (c is Splitter) { //RightClickInputA.Visible = true; //RightClickInputB.Visible = true; //RightClickOutputA.Visible = true; //RightClickChange.Visible = true; //RightClickDelete.Visible = true; RightClickInputA.Enabled = true; RightClickInputB.Enabled = false; RightClickOutputA.Enabled = true; RightClickOutputB.Enabled = true; RightClickChange.Enabled = true; RightClickDelete.Enabled = true; } else if (c is Sink) { //RightClickInputA.Visible = true; //RightClickChange.Visible = true; //RightClickDelete.Visible = true; RightClickInputA.Enabled = true; RightClickInputB.Enabled = false; RightClickOutputA.Enabled = false; RightClickOutputB.Enabled = false; RightClickChange.Enabled = true; RightClickDelete.Enabled = true; } } } }
private void GridPanel_Click(object sender, EventArgs e) /* * This changes how the click even works according to the context menu selection. It looks correct, * but for some reason takes in the wrong coordinates, and I can't figure out why. */ { switch (selector) { case Selection.Add: { //When Clicked in the Panel selectedComponent will be selected based on grid space PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel p = system.grid.returnMousePosition(point); return; } case Selection.InputA: { PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel p = system.grid.returnMousePosition(point); foreach (Component c in system.Components) { // checks if a component with the current location exists if (c.location.X == p.X && c.location.Y == p.Y) { // parameter neeed to be assignet system.Components[system.index].attachInputA(c); } } selector = Selection.Add; return; } case Selection.InputB: { //When Clicked in the Panel selectedComponent will be selected based on grid space PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel p = system.grid.returnMousePosition(point); foreach (Component c in system.Components) { // checks if a component with the current location exists if (c.location.X == p.X && c.location.Y == p.Y) { // parameter neeed to be assignet system.Components[system.index].attachInputB(c); } } selector = Selection.Add; return; } case Selection.OutputA: { //When Clicked in the Panel selectedComponent will be selected based on grid space PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel p = system.grid.returnMousePosition(point); foreach (Component c in system.Components) { // checks if a component with the current location exists if (c.location.X == p.X && c.location.Y == p.Y) { // parameter neeed to be assignet system.Components[system.index].attachOutputA(c); } } selector = Selection.Add; return; } case Selection.OutputB: { //When Clicked in the Panel selectedComponent will be selected based on grid space PointP position = new PointP(); Point point = GridPanel.PointToClient(Cursor.Position); //mouse position is relative to panel p = system.grid.returnMousePosition(point); foreach (Component c in system.Components) { // checks if a component with the current location exists if (c.location.X == p.X && c.location.Y == p.Y) { // parameter neeed to be assignet system.Components[system.index].attachOutputB(c); } } selector = Selection.Add; return; } default: return; } }
// constructor public Pipe(PointP loc) : base(loc) { }
private bool getImage(Component component, out Image img) { if (component != null) { if (component is Pipe) { PointP next = new PointP(); PointP previous = new PointP(); if (((Pipe)component).InputA == null) { img = Pipes.Properties.Resources.RedHorizontalPipe; return(true); } previous = ((Pipe)component).InputA.location; PointP test = new PointP(); PointP test2 = new PointP(); //gets cooridnates of the input and outputs if (((Pipe)component).OutputA != null) { next = ((Pipe)component).OutputA.location; //pipe has an output test = component.location; test2 = component.location; test.X = component.location.X - 1; test2.X = component.location.X + 1; if (((previous.CheckCordinates(test)) && (next.CheckCordinates(test2))) || ((previous.CheckCordinates(test2)) && (next.CheckCordinates(test)))) { //Is horizontal Pipe switch (((Pipe)component).checkSystemFlow()) { case 0: img = Pipes.Properties.Resources.RedHorizontalPipe; break; case 1: img = Pipes.Properties.Resources.GreenHorizontalPipe; break; default: img = Pipes.Properties.Resources.HorizontalPipe; break; } return(true); } test = component.location; test2 = component.location; test.Y = component.location.Y - 1; test2.Y = component.location.Y + 1; if (((previous.CheckCordinates(test)) && (next.CheckCordinates(test2))) || ((previous.CheckCordinates(test2)) && (next.CheckCordinates(test)))) { switch (((Pipe)component).checkSystemFlow()) { case 0: img = Pipes.Properties.Resources.verticalRedPipe; break; case 1: img = Pipes.Properties.Resources.GreenVerticalPipe; break; default: img = Pipes.Properties.Resources.VerticalPipe; break; } return(true); } test = component.location; test2 = component.location; test.X = component.location.X - 1; test2.Y = component.location.Y + 1; if (((previous.CheckCordinates(test)) && (next.CheckCordinates(test2))) || ((previous.CheckCordinates(test2)) && (next.CheckCordinates(test)))) { switch (((Pipe)component).checkSystemFlow()) { case 0: img = Pipes.Properties.Resources.RedWestSouthPipe; break; case 1: img = Pipes.Properties.Resources.GreenWestSouthPipe; break; default: img = Pipes.Properties.Resources.WestSouthPipe; break; } return(true); } test = component.location; test2 = component.location; test.X = component.location.X - 1; test2.Y = component.location.Y - 1; if (((previous.CheckCordinates(test)) && (next.CheckCordinates(test2))) || ((previous.CheckCordinates(test2)) && (next.CheckCordinates(test)))) { switch (((Pipe)component).checkSystemFlow()) { case 0: img = Pipes.Properties.Resources.RedWestNorthPipe; break; case 1: img = Pipes.Properties.Resources.GreenWestNorthPipe; break; default: img = Pipes.Properties.Resources.NorthWestPipe; break; } return(true); } test = component.location; test2 = component.location; test.X = component.location.X + 1; test2.Y = component.location.Y - 1; if (((previous.CheckCordinates(test)) && (next.CheckCordinates(test2))) || ((previous.CheckCordinates(test2)) && (next.CheckCordinates(test)))) { switch (((Pipe)component).checkSystemFlow()) { case 0: img = Pipes.Properties.Resources.RedNorthEastPipe; break; case 1: img = Pipes.Properties.Resources.GreenEastNorthPipe; break; default: img = Pipes.Properties.Resources.NorthEastPipe; break; } return(true); } test = component.location; test2 = component.location; test.X = component.location.X + 1; test2.Y = component.location.Y + 1; if (((previous.CheckCordinates(test)) && (next.CheckCordinates(test2))) || ((previous.CheckCordinates(test2)) && (next.CheckCordinates(test)))) { switch (((Pipe)component).checkSystemFlow()) { case 0: img = Pipes.Properties.Resources.RedEastSouthPipe; break; case 1: img = Pipes.Properties.Resources.GreenEastSouthPipe; break; default: img = Pipes.Properties.Resources.SouthEastPipe; break; } return(true); } img = null; return(false); } else { //Pipe does not yet have an output //Therefore can only a horizontal or vertical test = component.location; test2 = component.location; test.Y = component.location.Y - 1; test2.Y = component.location.Y + 1; if ((previous.CheckCordinates(test)) || (previous.CheckCordinates(test2))) { //test vertical img = Pipes.Properties.Resources.VerticalPipe; return(true); } test = component.location; test2 = component.location; test.X = component.location.X - 1; test2.X = component.location.X + 1; if ((previous.CheckCordinates(test)) || (previous.CheckCordinates(test2))) { //test horizontal img = Pipes.Properties.Resources.HorizontalPipe; return(true); } img = null; return(false); } } else if (component is Sink) { img = Pipes.Properties.Resources.sink; return(true); } else if (component is Splitter) { PointP previous = new PointP(); // previous = ((Splitter)component).InputA.location; PointP test = new PointP(); test = component.location; test.X = component.location.X + 1; if (test.CheckCordinates(previous)) { img = Pipes.Properties.Resources.EastSpiltter; return(true); } test = component.location; test.Y = component.location.Y - 1; if (test.CheckCordinates(previous)) { img = Pipes.Properties.Resources.NorthSpiltter; return(true); } test = component.location; test.Y = component.location.Y + 1; if (test.CheckCordinates(previous)) { img = Pipes.Properties.Resources.SouthSpiltter; return(true); } //Must be SpiltterWest Image img = Pipes.Properties.Resources.SouthSpiltter; return(true); } else if (component is Merger) { PointP next = new PointP(); if (((Merger)component).location != null) { // next = ((Merger)component).OutputA.location; PointP test = new PointP(component.location); test.X = component.location.X + 1; if (test.CheckCordinates(next)) { img = Pipes.Properties.Resources.MergerEast; return(true); } test.Y = component.location.Y - 1; if (test.CheckCordinates(next)) { img = Pipes.Properties.Resources.MergerNorthpng; return(true); } test.X = component.location.X + 1; if (test.CheckCordinates(next)) { img = Pipes.Properties.Resources.MergerSouth; return(true); } //Defeault image img = Pipes.Properties.Resources.MergerWest; return(true); } else { //Output not yet determined default image img = Pipes.Properties.Resources.MergerEast; return(true); } } else if (component is Pump) { img = Pipes.Properties.Resources.pump; return(true); } else { img = null; return(false); } } else { img = null; return(false); } }
public PointP(PointP point) { this.X = point.X; this.Y = point.Y; }
// connstructor public Merger(PointP loc) : base(loc) { }