コード例 #1
0
 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();
 }
コード例 #2
0
 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();
     }
 }
コード例 #3
0
        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);
        }
コード例 #4
0
 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();
 }
コード例 #5
0
 public void AddComponent(GeneralComponent Component)
 {
     ComponentList.Add(Component); //Adds to the current list
     CalculateResistance();        //Recalculates resistance
 }