|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using SpiceSharp.Components; |
| 4 | +using SpiceSharp.Components.Mosfets; |
| 5 | +using SpiceSharp.Entities; |
4 | 6 | using SpiceSharpParser.Common.Validation; |
5 | 7 | using SpiceSharpParser.ModelReaders.Netlist.Spice.Context; |
6 | 8 | using SpiceSharpParser.Models.Netlist.Spice.Objects; |
@@ -56,9 +58,20 @@ public MosfetModelGenerator() |
56 | 58 | /// </summary> |
57 | 59 | protected static Dictionary<int, Func<string, string, string, Context.Models.Model>> Levels { get; } = new Dictionary<int, Func<string, string, string, Context.Models.Model>>(); |
58 | 60 |
|
59 | | - public static void AddLevel(int level, Func<string, string, string, Context.Models.Model> generator) |
| 61 | + public static void AddLevel<TModel>(int level) |
| 62 | + where TModel : Entity<Parameters> |
60 | 63 | { |
61 | | - Levels[level] = generator; |
| 64 | + Levels[level] = (name, type, _) => |
| 65 | + { |
| 66 | + var mosfet = (TModel)Activator.CreateInstance(typeof(TModel), name); |
| 67 | + switch (type.ToLower()) |
| 68 | + { |
| 69 | + case "nmos": mosfet.SetParameter("nmos", true); break; |
| 70 | + case "pmos": mosfet.SetParameter("pmos", true); break; |
| 71 | + } |
| 72 | + |
| 73 | + return new Context.Models.Model(name, mosfet, mosfet.Parameters); |
| 74 | + }; |
62 | 75 | } |
63 | 76 |
|
64 | 77 | public override Context.Models.Model Generate(string id, string type, ParameterCollection parameters, IReadingContext context) |
|
0 commit comments