Пример #1
0
        protected List <Export> GenerateExports(ParameterCollection parameterCollection, Simulation simulation, ICircuitContext context)
        {
            if (parameterCollection.Count == 0)
            {
                return(CreateExportsForAllVoltageAndCurrents(simulation, context));
            }

            List <Export> result = new List <Export>();

            foreach (Parameter parameter in parameterCollection)
            {
                if (parameter is BracketParameter || parameter is ReferenceParameter)
                {
                    result.Add(GenerateExport(parameter, context, simulation));
                }
                else
                {
                    string expressionName  = parameter.Image;
                    var    expressionNames = context.Evaluator.GetExpressionNames();

                    if (expressionNames.Contains(expressionName))
                    {
                        var export = new ExpressionExport(
                            simulation.Name,
                            expressionName,
                            context.Evaluator.GetEvaluationContext(simulation));

                        result.Add(export);
                    }
                }
            }

            return(result);
        }
        private void AddLetExport(ICircuitContext context, Type simulationType, SingleParameter parameter)
        {
            string expressionName  = parameter.Image;
            var    expressionNames = context.Evaluator.GetExpressionNames();

            if (expressionNames.Contains(expressionName))
            {
                var simulations = Filter(context.Result.Simulations, simulationType);
                foreach (var simulation in simulations)
                {
                    var export = new ExpressionExport(simulation.Name, expressionName, context.Evaluator.GetEvaluationContext(simulation));
                    context.Result.AddExport(export);
                }
            }
            else
            {
                context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader,
                                                                  ValidationEntryLevel.Warning,
                                                                  $"There is no {expressionName} expression",
                                                                  parameter.LineInfo));
            }
        }
Пример #3
0
        public Export Create(
            Parameter exportParameter,
            ICircuitContext context,
            Simulation simulation,
            IMapper <Exporter> mapper)
        {
            if (exportParameter is BracketParameter bp)
            {
                string type = bp.Name;

                if (mapper.TryGetValue(type, context.CaseSensitivity.IsFunctionNameCaseSensitive, out var exporter))
                {
                    return(exporter.CreateExport(
                               exportParameter.Image,
                               type,
                               bp.Parameters,
                               context.Evaluator.GetEvaluationContext(simulation),
                               context.CaseSensitivity));
                }
            }

            if (exportParameter is ReferenceParameter rp)
            {
                string type       = "@";
                var    parameters = new ParameterCollection(
                    new List <Parameter>()
                {
                    new VectorParameter(
                        new List <SingleParameter>()
                    {
                        new WordParameter(rp.Name, rp.LineInfo),
                        new WordParameter(rp.Argument, rp.LineInfo),
                    }),
                });

                if (mapper.TryGetValue(type, true, out var exporter))
                {
                    return(exporter.CreateExport(
                               exportParameter.Image,
                               type,
                               parameters,
                               context.Evaluator.GetEvaluationContext(simulation),
                               context.CaseSensitivity));
                }
            }

            if (exportParameter is SingleParameter s)
            {
                string expressionName  = s.Image;
                var    expressionNames = context.Evaluator.GetExpressionNames();

                if (expressionNames.Any(e => e == expressionName))
                {
                    var export = new ExpressionExport(
                        simulation.Name,
                        expressionName,
                        context.Evaluator.GetEvaluationContext(simulation));

                    return(export);
                }
                else
                {
                    context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"There is no {expressionName} expression", exportParameter.LineInfo));
                    return(null);
                }
            }

            context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"Unsupported export: {exportParameter.Image}", exportParameter.LineInfo));
            return(null);
        }