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 VariableResistance_ValueChanged(object sender, EventArgs e) { GeneralComponent Load = MainCircuit.Main.GetCopyOfSubList()[0]; Resistance = (sender as TrackBar).Value; Load.AssignResistance(Resistance); CalculatePower(); RefreshDiagram(); }
public void UpdatePointers() { GeneralComponent ParraComponentList = MainCircuit.Main; SumResistance = ParraComponentList.GetResistance(); VoltagePerComponent = ParraComponentList.GetCopyOfSubList()[0].GetVoltage(); SumCurrent = ParraComponentList.GetCurrent(); UpdateLabels(); }
private void AddC_Click(object sender, EventArgs e) { GeneralComponent ComponentToBeInsertedAt = MainCircuit.Main.GetCopyOfSubList()[0]; MainCircuit.Main.ComponentSearch(ComponentToBeInsertedAt.GetName(), "Insert", new string[] { CurrentResistance.ToString(), "s" }); MainCircuit.Main.CalculateResistance(); RefreshDiagram(); UpdatePointers(); }
private void ResistanceSlider_ValueChanged(object sender, EventArgs e) { GeneralComponent Load = MainCircuit.Main.GetCopyOfSubList()[0]; Resistance = (sender as TrackBar).Value; ResistanceLabel.Text = PrefixDouble(Resistance, 'Ω'); Load.AssignResistance(Resistance); UpdateCurrent(); RefreshDiagram(); }
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 RemoveC_Click(object sender, EventArgs e) { GeneralComponent ParraComponentList = MainCircuit.Main; if (ParraComponentList.GetCopyOfSubList().Count != 1) { ParraComponentList.RemoveComponent(ParraComponentList.GetCopyOfSubList()[0]); } 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(); } }
public void DrawCircuit() { double EMFValue = MainCircuit.GetEmfValue(); MainCircuit.Main.CalculateResistance(); // Recalcuates so all drawn values are correct UpdateDimensions(); //Resizes the table based on the current size of the circuit ResetPanel(); DrawSection(MainCircuit.Main, 1, numRows - 1); //Draws the circuit recursively if (MainCircuit.Main.FindComponentFromName("IntRes") == null) { DrawEMFSource(EMFValue); } else { DrawEMFSource(EMFValue); GeneralComponent InternalResistance = MainCircuit.Main.FindComponentFromName("IntRes"); //Finds the internal resistance from the circuit ModifyPicture(Resources.ResistorIntRes, MiddleCollumn + 1, 0, PrefixDouble(InternalResistance.GetResistance(), 'Ω')).AssosiatedComponent = InternalResistance; //Updates the diagram to include internal resistance } }
public void ComponentClick(object sender, EventArgs e)// Forwards on the correct action when user clicks a component { PictureBoxWithReference SenderPicture; // This first bit just gets the correct PictureBoxWithReference as the user can click on the label covering the picture or the picture itself if (sender.GetType() == new Label().GetType()) { SenderPicture = (PictureBoxWithReference)(((Label)sender).Parent); } else { SenderPicture = (PictureBoxWithReference)sender; } if (SenderPicture.AssosiatedComponent != null && ClickActions.SelectedItem != null) // Checks the image has a resistor attached { switch (ClickActions.SelectedItem.ToString()) //Switches on the ClickActions Drop Down menu { case ("Edit Values"): double value = GetUserInputAsDouble($"What would you like to change the value of {SenderPicture.AssosiatedComponent.GetName()} to ?", 'Ω'); if (value == 0) { break; } SenderPicture.AssosiatedComponent.AssignResistance(value); Label InternalLabel = ((Label)SenderPicture.Controls[0]); // Now Updates the Label to reflect the new value InternalLabel.Text = PrefixDouble(value, 'Ω'); RefreshDiagram(); break; case "Add Resistor In Parrallel": if (MainCircuit.Main.ysize >= 12 || MainCircuit.Main.xsize >= 12) { MessageBox.Show("The Circuit has hit maximum size"); break; } double NewResistanceValue = GetUserInputAsDouble("What is the resistance of the new resistor", 'Ω'); if (NewResistanceValue == 0) { break; } MainCircuit.Main.ComponentSearch(SenderPicture.AssosiatedComponent.GetName(), "Insert", new string[] { NewResistanceValue.ToString(), "p" }); RefreshDiagram(); break; case "Add Resistor In Series": if (MainCircuit.Main.ysize >= 12 || MainCircuit.Main.xsize >= 12) { MessageBox.Show("The Circuit has hit maximum size"); break; } double NewResistanceValue2 = GetUserInputAsDouble("What is the resistance of the new resistor", 'Ω'); if (NewResistanceValue2 == 0) { break; } MainCircuit.Main.ComponentSearch(SenderPicture.AssosiatedComponent.GetName(), "Insert", new string[] { NewResistanceValue2.ToString(), "s" }); RefreshDiagram(); break; case "Remove Resistor": if (!(MainCircuit.Main.GetCopyOfSubList().Count == 1 || (MainCircuit.Main.GetCopyOfSubList().Count == 2 && MainCircuit.Main.FindComponentFromName("IntRes") != null && SenderPicture.AssosiatedComponent.GetName() != "IntRes")))// This long if statement checks if the component to be removed is the last in the circuit, if it is, it isn't removed { MainCircuit.Main.ComponentSearch(SenderPicture.AssosiatedComponent.GetName(), "Remove"); RefreshDiagram(); } break; case "Current Probe": CurrentProbeTarget = SenderPicture.AssosiatedComponent; // Changes the targeted component for Probing UpdateCurrentProbeText(); break; case "Voltage Probe": VoltageTarget = SenderPicture.AssosiatedComponent; UpdateVoltageTargetText(); break; default: throw new NotImplementedException(); } } }
public void OnCourseDeselected() { GeneralComponent.OnDeselectCourseOperation(); PracticalComponent.OnDeselectCourseOperation(); TutorialComponent.OnDeselectCourseOperation(); }
/// <summary> /// 刷新单个视窗 /// </summary> /// <param name="view">视窗</param> protected virtual void refreshView(GeneralComponent view) { view.requestRefresh(true); }