public void DrawSection(GeneralComponent component, int StartingX, int StartingY) { if (component.GetType() == 'b') { PictureBoxWithReference PictureBoxImage = ModifyPicture(Resources.Resistor, StartingX, StartingY, PrefixDouble(component.GetResistance(), 'Ω')); // This is the bit that draws the resistors based on positions worked out by the parrallel and series bits PictureBoxImage.AssosiatedComponent = component; } else if (component.GetType() == 'p') { List <GeneralComponent> ListForDrawing = component.GetCopyOfSubList();// Gets a copy of the current circuit from the PhysicsEngine Module // Starts From Current position and starts to draw a parrallel component // Draws the bottom line first as if it dosn't, It ovverides TOPRIGHTLEFT DrawBottomLine(StartingX + 1, StartingY, StartingX + component.xsize - 1);// If this wasn't there there would be gaps ModifyPicture(Resources.TopRightLeft, StartingX, StartingY).AssosiatedComponent = component; ModifyPicture(Resources.TopRightLeft, StartingX + component.xsize - 1, StartingY).AssosiatedComponent = component; DrawSection(ListForDrawing[0], StartingX + 1, StartingY); //Starts going through the vertical list of components to be drawn in parrallel for (int i = 1; i < ListForDrawing.Count; i++) { //If the y Size of The Component that Has to be drawn previously is larger than 1, extra extentions are drawn for (int x = 1; x < ListForDrawing[i - 1].ysize; x++) { StartingY--; //Moves the Y value up ModifyPicture(Resources.Down, StartingX, StartingY).AssosiatedComponent = component; //Draws a vertical Straight Line ModifyPicture(Resources.Down, StartingX + (component.xsize - 1), StartingY).AssosiatedComponent = component; //Draws the corresponding line on the other side } StartingY--; //Itterates the Y one more if (i == ListForDrawing.Count - 1) // If this is the last component in the List, Draw a different joining wire { ModifyPicture(Resources.RightBottom, StartingX, StartingY).AssosiatedComponent = component; ModifyPicture(Resources.LeftBottom, StartingX + (component.xsize - 1), StartingY).AssosiatedComponent = component; } else { ModifyPicture(Resources.TopRightBottom, StartingX, StartingY).AssosiatedComponent = component;//If not then Just branch for the next component ModifyPicture(Resources.TopLeftBottom, StartingX + (component.xsize - 1), StartingY).AssosiatedComponent = component; } DrawBottomLine(StartingX + 1, StartingY, StartingX + component.xsize - 1); DrawSection(ListForDrawing[i], StartingX + 1, StartingY);// Goes up the parrallel component and draws the next section } } else if (component.GetType() == 's') { List <GeneralComponent> ListForDrawing = component.GetCopyOfSubList(); // Gets a copy of the current circuit from the PhysicsEngine Module foreach (GeneralComponent subComponent in ListForDrawing) // Goes through each series component { if (subComponent.GetName() != "IntRes") { DrawSection(subComponent, StartingX, StartingY); //Draws each one StartingX += subComponent.xsize; // Increments The starting X so it is in the correct position for next component. } } } }
private void RemoveC_Click(object sender, EventArgs e) { GeneralComponent ParraComponentList = MainCircuit.Main.GetCopyOfSubList()[0]; if (ParraComponentList.GetType() != 'b') { ParraComponentList.RemoveComponent(ParraComponentList.GetCopyOfSubList()[0]); RefreshDiagram(); } UpdatePointers(); }
private void AddC_Click(object sender, EventArgs e) { GeneralComponent ComponentToBeInsertedAt = MainCircuit.Main.GetCopyOfSubList()[0]; if (ComponentToBeInsertedAt.GetType() != 'b') { ComponentToBeInsertedAt = ComponentToBeInsertedAt.GetCopyOfSubList()[0]; } MainCircuit.Main.ComponentSearch(ComponentToBeInsertedAt.GetName(), "Insert", new string[] { CurrentResistance.ToString(), "p" }); MainCircuit.Main.CalculateResistance(); RefreshDiagram(); UpdatePointers(); }
public void UpdatePointers() { GeneralComponent ParraComponentList = MainCircuit.Main.GetCopyOfSubList()[0]; if (ParraComponentList.GetType() != 'b') { SumResistance = ParraComponentList.GetResistance(); CurrentPerBranch = ParraComponentList.GetCopyOfSubList()[0].GetCurrent(); SumCurrent = ParraComponentList.GetCurrent(); UpdateLabels(); } else { SingleResistorLabelValues(); } }