public Circuit(char typeOfPsource, double valueofPsource, double IntRes, double ValOfFirstRes) { Main = new GeneralComponent("Main"); Main.AssignType('s'); if (IntRes != 0) { Main.AddComponent(PhysicsGlobals.CreateSimpleComponent(IntRes, "IntRes")); } Main.AddComponent(PhysicsGlobals.CreateSimpleComponent(ValOfFirstRes)); Type = typeOfPsource; emfValue = valueofPsource; RunVoltageCalcs(); }
public void InsertComponent(GeneralComponent component, double Resistance, char Mode) // Inserts new component { if ((Mode == 'p' && (Type == 'p')) || (Mode == 's' && (Type == 's'))) { ComponentList.Add(PhysicsGlobals.CreateSimpleComponent(Resistance)); //Adds to the current component list CalculateResistance(); //Re-calculates the resistance after new component has been added } else if (Mode == 's') { // Creates new Composite component string componentName = "RS" + PhysicsGlobals.SeriesNum.ToString(); GeneralComponent NewComponent = new GeneralComponent(componentName); PhysicsGlobals.SeriesNum++; NewComponent.AssignType('s'); // Adds both the old component and the new one to this composite one NewComponent.AddComponent(component); NewComponent.AddComponent(PhysicsGlobals.CreateSimpleComponent(Resistance)); // Removes the old and replaces with the new ComponentList[ComponentList.IndexOf(component)] = NewComponent; } else if (Mode == 'p') { // Same as above but with a parrallel component string componentName = "RP" + PhysicsGlobals.ParralellNum.ToString(); GeneralComponent NewComponent = new GeneralComponent(componentName); PhysicsGlobals.ParralellNum++; NewComponent.AssignType('p'); NewComponent.AddComponent(component); NewComponent.AddComponent(PhysicsGlobals.CreateSimpleComponent(Resistance)); ComponentList[ComponentList.IndexOf(component)] = NewComponent; } else { Console.WriteLine("p or s expected"); } CalculateResistance(); }