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 RemoveComponent(GeneralComponent component)//Removes Component and then checks if it needs to collapse that component into a basic component
 {
     ComponentList.Remove(component);
     if (ComponentList.Count == 1 && name != "Main")
     {
         GeneralComponent CarryComponent = ComponentList[0];
         Type                   = 'b';
         resistance             = CarryComponent.GetResistance();
         ysize                  = 1;
         xsize                  = 1;
         name                   = CarryComponent.GetName();
         IsTargetedCurrentProbe = CarryComponent.IsTargetedCurrentProbe;
         ComponentList.Clear();
     }
 }
        public static GeneralComponent CreateSimpleComponent(double resistance, string name = "")
        {
            string componentName;

            if (name == "")
            {
                componentName = "R" + PhysicsGlobals.ResistorNum.ToString(); // Creates the Name of the component, with globals to ensure it will be unique
                PhysicsGlobals.ResistorNum++;                                // Increments Global variable
            }
            else
            {
                componentName = name;
            }
            GeneralComponent NewBasicComponent = new GeneralComponent(componentName); // Creates new instance of the most basic component

            NewBasicComponent.AssignResistance(resistance);                           // Assigns the resistance the user has given
            return(NewBasicComponent);
        }
 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();
 }
 public void AddComponent(GeneralComponent Component)
 {
     ComponentList.Add(Component); //Adds to the current list
     CalculateResistance();        //Recalculates resistance
 }