Skip to content

Commit b1839a8

Browse files
Expose Levels and Mosfets
1 parent 73117ba commit b1839a8

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/EntityGenerators/Components/Semiconductors/MosfetGenerator.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,18 @@ public MosfetGenerator()
3535
});
3636
}
3737

38-
protected Dictionary<Type, Func<string, MosfetDetails>> Mosfets { get; } = new ();
38+
protected static Dictionary<Type, Func<string, MosfetDetails>> Mosfets { get; } = new ();
39+
40+
public static void AddMosfet<TModel, TMosfet>()
41+
where TMosfet : SpiceSharp.Components.Component
42+
where TModel : Context.Models.Model
43+
{
44+
Mosfets.Add(typeof(TModel), (name) =>
45+
{
46+
var mosfet = (TMosfet)Activator.CreateInstance(typeof(TMosfet), name);
47+
return new MosfetDetails { Mosfet = mosfet, SetModelAction = (model) => mosfet.Model = model.Name };
48+
});
49+
}
3950

4051
public override IEntity Generate(string componentIdentifier, string originalName, string type, ParameterCollection parameters, IReadingContext context)
4152
{

src/SpiceSharpParser/ModelReaders/Netlist/Spice/Readers/EntityGenerators/Models/MosfetModelGenerator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public MosfetModelGenerator()
5454
/// Gets available model generators indexed by their LEVEL.
5555
/// The parameters passed are name, type (nmos or pmos) and the version.
5656
/// </summary>
57-
protected Dictionary<int, Func<string, string, string, Context.Models.Model>> Levels { get; } = new Dictionary<int, Func<string, string, string, Context.Models.Model>>();
57+
protected static Dictionary<int, Func<string, string, string, Context.Models.Model>> Levels { get; } = new Dictionary<int, Func<string, string, string, Context.Models.Model>>();
58+
59+
public static void AddLevel(int level, Func<string, string, string, Context.Models.Model> generator)
60+
{
61+
Levels[level] = generator;
62+
}
5863

5964
public override Context.Models.Model Generate(string id, string type, ParameterCollection parameters, IReadingContext context)
6065
{

0 commit comments

Comments
 (0)