Beispiel #1
0
        /// <summary>
        /// Get the expression encapsulated in the UnitParameter for a parameter that gets its value from outside its model.
        /// </summary>
        /// <param name="parentID">ID of parent of the model that contains the parameter.</param>
        /// <param name="parameter">CyPhyParameter to which the returned UnitParameter will be correspond to.</param>
        /// <param name="vf">Incoming value-flow to parameter.</param>
        /// <returns>Value-expression in UnitParameter.</returns>
        private UnitParameter GetArgumentParameter(string parentID, CyPhy.Parameter parameter, CyPhy.ValueFlow vf)
        {
            ModelicaValue modelicaValue = null;
            if (vf.SrcEnds.Parameter != null)
            {
                var srcParameter = vf.SrcEnds.Parameter;
                if (this.ParentContainerIsDynamic(srcParameter))
                {
                    var parameterName = this.ParentIsComponent(srcParameter) ? ParameterPrefix + srcParameter.Name : srcParameter.Name;

                    // The Parameter is in a subModel (prepend instance name of the subModel).
                    if (srcParameter.ParentContainer.ID != parentID)
                    {
                        parameterName = string.Format("{0}.{1}", srcParameter.ParentContainer.Name, parameterName);
                    }

                    modelicaValue = new ModelicaValue(parameterName);
                }
                else
                {
                    modelicaValue = new ModelicaValue(srcParameter.Attributes.Value);
                }
            }
            else if (vf.SrcEnds.SimpleFormula != null)
            {
                modelicaValue = new ModelicaValue(this.GetFormulaExpression(vf.SrcEnds.SimpleFormula));
            }
            else if (vf.SrcEnds.Property != null)
            {
                modelicaValue = new ModelicaValue(vf.SrcEnds.Property.Attributes.Value);
            }
            else if (vf.SrcEnds.CustomFormula != null)
            {
                modelicaValue = new ModelicaValue(parameter.Attributes.Value);
            }

            var parameter_mo = new UnitParameter()
            {
                Name = this.ParentIsComponent(parameter) ? ParameterPrefix + parameter.Name : parameter.Name,
                Value = modelicaValue
            };

            return parameter_mo;
        }
Beispiel #2
0
        /// <summary>
        /// Get the ModelicaValue for a Property. Not the ClassName will always be Real (not used for Properties in any case).
        /// If elaborateType is set to true, the type will be looked for in property.Attributes.DataType. If it is set to string
        /// and can be parsed as a boolean it is set to Boolean, else to Real.
        /// </summary>
        /// <param name="property">The Property to get the value for.</param>
        /// <param name="elaborateType">Indicates if the ClassName is of importance.</param>
        /// <returns>The ModelicaValue from the property.</returns>
        private ModelicaValue GetPropertyModelicaValue(CyPhy.Property property, bool elaborateType = false)
        {
            var modelicaValue = new ModelicaValue(property.Attributes.Value);
            if (elaborateType)
            {
                switch (property.Attributes.DataType)
                {
                    case CyPhyClasses.Property.AttributesClass.DataType_enum.Boolean:
                        modelicaValue.ClassName = "Boolean";
                        break;
                    case CyPhyClasses.Property.AttributesClass.DataType_enum.Float:
                        modelicaValue.ClassName = "Real";
                        break;
                    case CyPhyClasses.Property.AttributesClass.DataType_enum.Integer:
                        modelicaValue.ClassName = "Integer";
                        break;
                    case CyPhyClasses.Property.AttributesClass.DataType_enum.String:
                        if (modelicaValue.Value == "false" || modelicaValue.Value == "true")
                        {
                            modelicaValue.ClassName = "Boolean";
                        }
                        else if (modelicaValue.Value.StartsWith("\"") && modelicaValue.Value.EndsWith("\""))
                        {
                            modelicaValue.ClassName = "String";
                        }
                        else
                        {
                            modelicaValue.ClassName = "Real";
                        }

                        break;
                }
            }
            else
            {
                modelicaValue.ClassName = "Real";
            }

            return modelicaValue;
        }
Beispiel #3
0
        /// <summary>
        /// Get the value-expression for parameter encapsulated in the ModelicaValue.
        /// </summary>
        /// <param name="parameter">CyPhyParameter to which the ModelicaValue belongs.</param>
        /// <returns>Value-expression as part of the ModelicaValue.</returns>
        private ModelicaValue GetParameterModelicaValue(CyPhy.Parameter parameter)
        {
            var modelicaValue = new ModelicaValue(parameter.Attributes.Value);

            var vf = parameter.SrcConnections.ValueFlowCollection.FirstOrDefault();
            if (vf != null)
            {
                if (vf.ParentContainer.ID == parameter.ParentContainer.ID)
                {
                    // Value flow takes place on same level as receiving parameter.
                    if (vf.SrcEnds.Parameter != null)
                    {
                        var srcParameter = vf.SrcEnds.Parameter;
                        if (this.ParentContainerIsDynamic(srcParameter))
                        {
                            var parameterName = this.ParentIsComponent(srcParameter) ? ParameterPrefix + srcParameter.Name : srcParameter.Name;

                            if (srcParameter.ParentContainer.ID != parameter.ParentContainer.ID)
                            {
                                // The Parameter is in a subModel (prepend instance name of the subModel).
                                parameterName = string.Format("{0}.{1}", srcParameter.ParentContainer.Name, parameterName);
                            }

                            modelicaValue = new ModelicaValue(parameterName);
                        }
                    }
                    else if (vf.SrcEnds.SimpleFormula != null)
                    {
                        modelicaValue = new ModelicaValue(this.GetFormulaExpression(vf.SrcEnds.SimpleFormula));
                    }
                    else
                    {
                        // If Property or CustomFormula or any other kind.-> Use the value passed from FormulaEvaluator,
                        // i.e. as given in the instantiation of modelicaValue in beginning of this method.
                    }
                }
            }

            switch (parameter.Attributes.DataType)
            {
                case CyPhyClasses.Parameter.AttributesClass.DataType_enum.Boolean:
                    modelicaValue.ClassName = "Boolean";
                    break;
                case CyPhyClasses.Parameter.AttributesClass.DataType_enum.Float:
                    modelicaValue.ClassName = "Real";
                    break;
                case CyPhyClasses.Parameter.AttributesClass.DataType_enum.Integer:
                    modelicaValue.ClassName = "Integer";
                    break;
                case CyPhyClasses.Parameter.AttributesClass.DataType_enum.String:
                    if (modelicaValue.Value == "false" || modelicaValue.Value == "true")
                    {
                        modelicaValue.ClassName = "Boolean";
                    }
                    else if (modelicaValue.Value.StartsWith("\"") && modelicaValue.Value.EndsWith("\""))
                    {
                        modelicaValue.ClassName = "String";
                    }
                    else
                    {
                        modelicaValue.ClassName = "Real";
                    }

                    break;
            }

            return modelicaValue;
        }