コード例 #1
0
        private void ApplySpiceProperty(EvaluationContext context, SpicePropertyFoundEventArgs <double> arg, bool applyVoltage)
        {
            var parameters = GetSpicePropertyParameters(context, arg);

            var propertyName = arg.Property.Identifier.ToLower();

            string key = $"{context.Name}_{propertyName}_{parameters}_{context.Simulation?.Name}";

            if (_exporterInstances.TryGetValue(key, out Export cachedExport))
            {
                ApplyExport(arg, cachedExport, applyVoltage);
            }
            else
            {
                var      voltageExportFactory = new VoltageExporter();
                var      currentExportFactory = new CurrentExporter();
                var      propertyExporter     = new PropertyExporter();
                Exporter factory = null;

                if (currentExportFactory.CreatedTypes.Contains(propertyName))
                {
                    factory = currentExportFactory;
                }

                if (voltageExportFactory.CreatedTypes.Contains(propertyName))
                {
                    factory = voltageExportFactory;
                }

                if (propertyName == "@")
                {
                    factory = propertyExporter;
                }

                if (factory == null)
                {
                    throw new SpiceSharpParserException($"Unknown spice property {propertyName}");
                }

                var export = factory.CreateExport(
                    $"{propertyName}_{parameters}",
                    propertyName,
                    parameters,
                    context,
                    _caseSettings);

                _exporterInstances[key] = export;

                ApplyExport(arg, export, applyVoltage);
            }
        }
コード例 #2
0
 private void ApplyExport(SpicePropertyFoundEventArgs <double> arg, Export export, bool applyVoltage)
 {
     if (export is VoltageExport)
     {
         if (applyVoltage)
         {
             arg.Apply(() => export.Extract(), 0, 0);
         }
     }
     else
     {
         arg.Apply(() => export.Extract(), 0, 0);
     }
 }
コード例 #3
0
        private ParameterCollection GetSpicePropertyParameters(EvaluationContext context, SpicePropertyFoundEventArgs <double> arg)
        {
            var vectorParameter = new VectorParameter(new List <SingleParameter>());

            for (var i = 0; i < arg.Property.ArgumentCount; i++)
            {
                var argumentName = arg.Property[i];
                if (context.Parameters.ContainsKey(argumentName))
                {
                    var val = context.Evaluate(argumentName);
                    vectorParameter.Elements.Add(new WordParameter(val.ToString(CultureInfo.InvariantCulture), null));
                }
                else
                {
                    vectorParameter.Elements.Add(new WordParameter(argumentName, null));
                }
            }

            var parameters = new ParameterCollection(new List <Parameter> {
                vectorParameter
            });

            return(parameters);
        }