示例#1
0
        /// <summary>
        /// Adds TestComponent and instance to test-bench. Populates all mapping related to the TestComponent.
        /// </summary>
        /// <param name="testComponent">CyPhy TestComponent.</param>
        /// <param name="modelicaModel">CyPhy ModelicaModel of the testComponent.</param>
        private void AddTestComponent(CyPhy.TestComponent testComponent, CyPhy.ModelicaModel modelicaModel)
        {
            Modelica.Component testComponent_mo = null;

            // META-1624 : TestComponents in the test-bench are all seen as self-contained models 
            //             and will be generated as they appear there inside the Modelica package-tree.
            testComponent_mo = new Component(testComponent)
            {
                FullName = MainPackage + ".TestComponents." + testComponent.Name,
                Extends = modelicaModel.Attributes.Class,
            };

            // Add all defined Parameters at the component-level
            foreach (var cyPhyParameter in testComponent.Children.ParameterCollection)
            {
                var parameter_mo = new UnitParameter()
                {
                    Name = CodeGenerator.ParameterPrefix + cyPhyParameter.Name,
                    Value = this.GetParameterModelicaValue(cyPhyParameter),
                    Modifier = this.GetParameterModifier(cyPhyParameter)
                };

                testComponent_mo.CyPhyParameters.Add(parameter_mo);
            }

            // Add all modelicaParameters from the ModelicaModel.
            foreach (var parameter in modelicaModel.Children.ModelicaParameterCollection)
            {
                var value = this.GetModelicaParameterValue(parameter);
                if (string.IsNullOrWhiteSpace(value) == false)
                {
                    testComponent_mo.Parameters.Add(
                        new UnitParameter()
                        {
                            Name = parameter.Name,
                            Value = new ModelicaValue(value)
                        });
                }
            }

            // Add all modelicaRedeclares from the ModelicaModel.
            foreach (var redeclareParameter in modelicaModel.Children.ModelicaRedeclareCollection)
            {
                var value = redeclareParameter.Attributes.Value;

                if (string.IsNullOrWhiteSpace(value) == false)
                {
                    testComponent_mo.Parameters.Add(
                        new UnitRedeclareParameter(redeclareParameter)
                        {
                            Value = new ModelicaValue(value)
                        });
                }
            }

            this.testBench_mo.TestComponents.Add(testComponent_mo);

            // Make sure there are margins to the upper- and left-border
            int canvasX = testComponent.GenericAspect.X > ScaleFactor * ComponentIconSize ? 
                testComponent.GenericAspect.X : ScaleFactor * ComponentIconSize;
            int canvasY = testComponent.GenericAspect.Y > ScaleFactor * ComponentIconSize ? 
                testComponent.GenericAspect.Y : ScaleFactor * ComponentIconSize;

            // Make sure there are margins to the bottom- and right-border
            this.testBench_mo.CanvasXMax = canvasX + (ScaleFactor * ComponentIconSize) > this.testBench_mo.CanvasXMax ? 
                canvasX + (ScaleFactor * ComponentIconSize) : this.testBench_mo.CanvasXMax;
            this.testBench_mo.CanvasYMax = canvasY + (ScaleFactor * ComponentIconSize) > this.testBench_mo.CanvasYMax ? 
                canvasY + (ScaleFactor * ComponentIconSize) : this.testBench_mo.CanvasYMax;

            var testComponentInstance_mo = new ComponentInstance(testComponent)
            {
                InstanceOf = testComponent_mo,
                CanvasX = canvasX,
                CanvasY = canvasY
            };

            var testComponentInfo = new ComponentInfo(testComponent.Impl as GME.MGA.IMgaFCO, "ContextModel", this.traceability);
            this.instanceURIMap.Add(string.Format("{0}.TestBenches.{1}.{2}", MainPackage, this.testBench_mo.Name, testComponent.Name), testComponentInfo);
            var uri = MainPackage + ".TestComponents." + testComponent.Name;
            if (this.modelURIMap.ContainsKey(uri) == false)
            {
                this.modelURIMap.Add(uri, testComponentInfo);
            }

            if (this.extendsURIMap.ContainsKey(testComponent_mo.Extends) == false)
            {
                var testComponentExtendInfo = new ComponentInfo(modelicaModel.Impl as GME.MGA.IMgaFCO, "ContextModel", this.traceability);
                this.extendsURIMap.Add(testComponent_mo.Extends, testComponentExtendInfo);
            }

            // Parameters of instance
            foreach (var parameter in testComponent.Children.ParameterCollection)
            {
                var vf = parameter.SrcConnections.ValueFlowCollection.FirstOrDefault();
                if (vf != null && vf.ParentContainer.ID == this.testBench_mo.Impl.ID)
                {
                    var parameter_mo = this.GetArgumentParameter(this.testBench_mo.Impl.ID, parameter, vf);
                    testComponentInstance_mo.Parameters.Add(parameter_mo);
                }
            }

            this.testBench_mo.TestComponentInstances.Add(testComponentInstance_mo);

            // ModelicaConnectors
            foreach (var port in testComponent.Children.ModelicaConnectorCollection)
            {
                foreach (var dstPort in port.DstConnections.PortCompositionCollection
                    .Select(c => c.DstEnds.ModelicaConnector)
                    .Where(p => p.ParentContainer is CyPhy.ModelicaModel == false))
                {
                    CyPhy.ModelicaConnector srcConnector = this.GetModelicaModelConnectorFromComponentPort(port);
                    if (srcConnector == null)
                    {
                        continue;
                    }

                    CyPhy.ModelicaConnector dstConnector = null;

                    if (dstPort.ParentContainer is CyPhy.TestComponent)
                    {
                        dstConnector = this.GetModelicaModelConnectorFromComponentPort(dstPort);
                    }
                    else if (dstPort.ParentContainer is CyPhy.ComponentAssembly)
                    {
                        dstConnector = dstPort;
                    }
                    else if (dstPort.ParentContainer is CyPhy.Environment)
                    {
                        dstConnector = dstPort;
                    }

                    // The Fidelty Selected might not have this Connection - don't make it.
                    // Or it might be a floating connector with no purpose.
                    if (dstConnector == null)
                    {
                        continue;
                    }

                    var connection_mo = new Connection(srcConnector.Name, dstConnector.Name)
                    {
                        SrcInstanceName = testComponent.Name,
                        DstInstanceName = dstPort.ParentContainer.Name,
                        Type = srcConnector.Attributes.Class
                    };

                    this.testBench_mo.Connections.Add(connection_mo);
                }
            }

            // Connectors - aka portContainers
            foreach (var portContainer in testComponent.Children.ConnectorCollection)
            {
                if (portContainer.Children.ModelicaConnectorCollection.Count() != 1)
                {
                    continue;
                }

                foreach (var dstPortContainer in portContainer.DstConnections.ConnectorCompositionCollection.Select(c => c.DstEnds.Connector))
                {
                    if (dstPortContainer.Children.ModelicaConnectorCollection.Count() != 1)
                    {
                        continue;
                    }

                    CyPhy.ModelicaConnector srcConnector = this.GetModelicaModelConnectorFromComponentPortContainer(portContainer);
                    if (srcConnector == null)
                    {
                        continue;
                    }

                    CyPhy.ModelicaConnector dstConnector = null;

                    string dstConnectorName = "ERROR No Name Assigned";

                    if (dstPortContainer.ParentContainer is CyPhy.TestComponent)
                    {
                        dstConnector = this.GetModelicaModelConnectorFromComponentPortContainer(dstPortContainer);
                        dstConnectorName = dstConnector.Name;
                    }
                    else if (dstPortContainer.ParentContainer is CyPhy.ComponentAssembly)
                    {
                        dstConnector = dstPortContainer.Children.ModelicaConnectorCollection.FirstOrDefault();
                        dstConnectorName = dstPortContainer.Name.Replace(' ', '_');
                    }
                    else if (dstPortContainer.ParentContainer is CyPhy.Environment)
                    {
                        this.Logger.WriteDebug("Environment connected in Connector-chains not supported!");
                        continue;
                    }

                    // The Fidelty Selected might not have this Connection - don't make it.
                    // Or it might be a floating connector with no purpose.
                    if (dstConnector == null)
                    {
                        continue;
                    }

                    var connection_mo = new Connection(srcConnector.Name, dstConnectorName)
                    {
                        SrcInstanceName = testComponent.Name,
                        DstInstanceName = dstPortContainer.ParentContainer.Name,
                        Type = srcConnector.Attributes.Class
                    };

                    this.testBench_mo.Connections.Add(connection_mo);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Adds the component to componentAssembly_mo as an instance.
        /// </summary>
        /// <param name="componentAssembly_mo">ComponentAssembly that contains the component.</param>
        /// <param name="parentComponentAssembly_mo">ComponentAssembly that contains componentAssembly_mo.</param>
        /// <param name="component">CyPhy Component to add.</param>
        private void AddComponent(ComponentAssembly componentAssembly_mo, ComponentAssembly parentComponentAssembly_mo, CyPhy.Component component)
        {
            var ca = componentAssembly_mo.Impl;
            var modelicaModel = this.GetModelicaModelFromComponent(component);

            // Make sure there are margins to the top- and left-border
            int canvasX = component.GenericAspect.X > ScaleFactor * ComponentIconSize ? 
                component.GenericAspect.X : ScaleFactor * ComponentIconSize;
            int canvasY = component.GenericAspect.Y > ScaleFactor * ComponentIconSize ? 
                component.GenericAspect.Y : ScaleFactor * ComponentIconSize;

            // Make sure there are margins to the bottom- and right-border
            componentAssembly_mo.CanvasXMax = canvasX + (ScaleFactor * ComponentIconSize) > componentAssembly_mo.CanvasXMax ? 
                canvasX + (ScaleFactor * ComponentIconSize) : componentAssembly_mo.CanvasXMax;
            componentAssembly_mo.CanvasYMax = canvasY + (ScaleFactor * ComponentIconSize) > componentAssembly_mo.CanvasYMax ? 
                canvasY + (ScaleFactor * ComponentIconSize) : componentAssembly_mo.CanvasYMax;

            var componentInstance_mo = new ComponentInstance(component)
            {
                InstanceOf = this.treeComponents[component.DerivedFrom().ID],
                CanvasX = canvasX,
                CanvasY = canvasY
            };

            foreach (var parameter in component.Children.ParameterCollection)
            {
                // META-3622
                if (String.IsNullOrWhiteSpace(parameter.Attributes.Dimension) || parameter.Attributes.Dimension.Trim() == "1")
                {
                    var vf = parameter.SrcConnections.ValueFlowCollection.FirstOrDefault();
                    if (vf != null && vf.ParentContainer.ID == ca.ID)
                    {
                        var parameter_mo = this.GetArgumentParameter(ca.ID, parameter, vf);
                        componentInstance_mo.Parameters.Add(parameter_mo);
                    }
                }
            }

            // META-2189 Overwrite ModelicaParameters connected to properties with formulated values in the design.
            foreach (var modelicaParameter in modelicaModel.Children.ModelicaParameterCollection)
            {
                var connection = modelicaParameter.SrcConnections.ModelicaParameterPortMapCollection.FirstOrDefault();
                if (connection != null && connection.SrcEnds.Property != null)
                {
                    double temp;
                    var value = modelicaParameter.Attributes.Value.Trim();
                    if (double.TryParse(modelicaParameter.Attributes.Value, out temp) || value == "true" || value == "false" || 
                        (value.StartsWith("\"") && value.EndsWith("\"")))
                    {
                        var parameter_mo = new UnitParameter();
                        parameter_mo.Name = modelicaParameter.Name;
                        parameter_mo.Value = new ModelicaValue(modelicaParameter.Attributes.Value.Trim());
                        componentInstance_mo.Parameters.Add(parameter_mo);
                    }
                }
            }

            componentAssembly_mo.ComponentInstances.Add(componentInstance_mo);

            string componentModelicaURI = componentAssembly_mo.Name + "." + componentInstance_mo.Name;
            var parentCA = parentComponentAssembly_mo;
            while (parentCA != null)
            {
                componentModelicaURI = parentCA.Name + "." + componentModelicaURI;
                parentCA = parentCA.ParentComponentAssembly;
            }

            this.ExtractPCCInputs(component, componentModelicaURI);


            string modelType;
            if (modelicaModel is CyPhy.CyberModel)
            {
                modelType = "ControllerModel";
            }
            else
            {
                modelType = "PlantModel";
            }

            var componentInfo = new ComponentInfo(component.Impl as GME.MGA.IMgaFCO, modelType, this.traceability);
            this.instanceURIMap.Add(string.Format("{0}.TestBenches.{1}.{2}", MainPackage, this.testBench_mo.Name, componentModelicaURI), componentInfo);
            if (this.modelURIMap.ContainsKey(componentInstance_mo.InstanceOf.FullName) == false)
            {
                this.modelURIMap.Add(componentInstance_mo.InstanceOf.FullName, componentInfo);
            }

            if (this.extendsURIMap.ContainsKey(componentInstance_mo.InstanceOf.Extends) == false)
            {
                var componentExtendInfo = new ComponentInfo(modelicaModel.Impl as GME.MGA.IMgaFCO, modelType, this.traceability);
                this.extendsURIMap.Add(componentInstance_mo.InstanceOf.Extends, componentExtendInfo);
            }

            // Iterate over all ports and look for connections FROM the port. These connections will generate equations in the 
            // component assembly if the connections is not entering a ModelicaModel.

            // Connections from ModelicaConnectors (Components)
            foreach (var port in component.Children.ModelicaConnectorCollection)
            {
                foreach (var dstPort in port.DstConnections.PortCompositionCollection
                    .Select(c => c.DstEnds.ModelicaConnector)
                    .Where(p => p.ParentContainer is CyPhy.ModelicaModel == false))
                {
                    CyPhy.ModelicaConnector srcConnector = this.GetModelicaModelConnectorFromComponentPort(port);
                    if (srcConnector == null)
                    {
                        continue;
                    }

                    CyPhy.ModelicaConnector dstConnector = null;

                    if (dstPort.ParentContainer is CyPhy.Component)
                    {
                        dstConnector = this.GetModelicaModelConnectorFromComponentPort(dstPort);
                    }
                    else if (dstPort.ParentContainer is CyPhy.ComponentAssembly)
                    {
                        dstConnector = dstPort;
                    }

                    // The Fidelty Selected might not have this Connection - don't make it.
                    // Or it might be a floating connector with no purpose.
                    if (dstConnector == null)
                    {
                        continue;
                    }

                    var connection_mo = new Connection(srcConnector.Name, dstConnector.Name)
                    {
                        SrcInstanceName = component.Name,
                        Type = srcConnector.Attributes.Class
                    };

                    if (dstPort.ParentContainer.ID != ca.ID)
                    {
                        connection_mo.DstInstanceName = dstPort.ParentContainer.Name;
                    }

                    componentAssembly_mo.Connections.Add(connection_mo);
                }
            }

            // Connections from Connectors (Components)
            foreach (var portContainer in component.Children.ConnectorCollection)
            {
                if (portContainer.Children.ModelicaConnectorCollection.Count() != 1)
                {
                    continue;
                }

                foreach (var dstPortContainer in portContainer.DstConnections.ConnectorCompositionCollection.Select(c => c.DstEnds.Connector))
                {
                    if (dstPortContainer.Children.ModelicaConnectorCollection.Count() != 1)
                    {
                        continue;
                    }

                    CyPhy.ModelicaConnector srcConnector = this.GetModelicaModelConnectorFromComponentPortContainer(portContainer);
                    if (srcConnector == null)
                    {
                        continue;
                    }

                    CyPhy.ModelicaConnector dstConnector = null;

                    string dstConnectorName = "ERROR No Name Assigned";
                    if (dstPortContainer.ParentContainer is CyPhy.Component)
                    {
                        var portComponent = CyPhyClasses.Component.Cast(dstPortContainer.ParentContainer.Impl);
                        if (this.ComponentIsDynamic(portComponent) == false)
                        {
                            this.Logger.WriteWarning("'{0}' does not contain any dynamic-components, connections to it skipped.", portComponent.Name);
                            continue;
                        }

                        dstConnector = this.GetModelicaModelConnectorFromComponentPortContainer(dstPortContainer);
                        if (dstConnector != null)
                        {
                            dstConnectorName = dstConnector.Name;
                        }
                    }
                    else if (dstPortContainer.ParentContainer is CyPhy.ComponentAssembly)
                    {
                        var portCA = dstPortContainer.ParentContainer.Impl;
                        if (this.ContainsDynamicComponents(CyPhyClasses.ComponentAssembly.Cast(portCA)) == false)
                        {
                            this.Logger.WriteWarning("'{0}' does not contain any dynamic-components, connections to it skipped.", portCA.Name);
                            continue;
                        }

                        dstConnector = dstPortContainer.Children.ModelicaConnectorCollection.FirstOrDefault();
                        dstConnectorName = dstPortContainer.Name.Replace(' ', '_');
                    }

                    // The Fidelty Selected might not have this Connection - don't make it.
                    // Or it might be a floating connector with no purpose.
                    if (dstConnector == null)
                    {
                        continue;
                    }

                    var connection_mo = new Connection(srcConnector.Name, dstConnectorName)
                    {
                        SrcInstanceName = component.Name,
                        Type = srcConnector.Attributes.Class
                    };

                    if (dstPortContainer.ParentContainer.ID != ca.ID)
                    {
                        connection_mo.DstInstanceName = dstPortContainer.ParentContainer.Name;
                    }

                    componentAssembly_mo.Connections.Add(connection_mo);
                }
            }

            // Add limit-checks for the component to the test-bench
            foreach (var modelicaModelLimit in modelicaModel.Children.LimitCheckCollection)
            {
                // TODO: When META-1124 and META-1129 both are merged, merge Limit and LimitCheck class.
                var limit = new Limit(modelicaModelLimit)
                {
                    ComponentModelicaUri = componentModelicaURI
                };
                this.testBench_mo.Limits.Add(limit);
                var limitCheck = new LimitCheck()
                {
                    ParentKind = modelicaModelLimit.ParentContainer.Kind,
                    LimitFullPath = modelicaModelLimit.Path,
                    LimitName = modelicaModelLimit.Name,
                    VariableName = modelicaModelLimit.Attributes.VariableName,
                    Type = modelicaModelLimit.Attributes.LimitType.ToString(),
                    Value = modelicaModelLimit.Attributes.Value,
                    VariableFullPath = string.Format("{0}.{1}", componentModelicaURI, modelicaModelLimit.Attributes.VariableName),
                    ModelicaRecordName = string.Format("Limit{0}", this.testBench_mo.Limits.Count)
                };

                this.LimitDefintion.LimitChecks.Add(limitCheck);

            }
        }
示例#3
0
        /// <summary>
        /// Does most of the work for GenerateModelicaCode()
        /// </summary>
        private void BuildUpTestBench()
        {
            var testBench = this.testBench_mo.Impl;
            this.instanceURIMap.Add(
                string.Format("{0}.TestBenches.{1}", MainPackage, testBench.Name),
                new ComponentInfo(testBench.Impl as GME.MGA.IMgaFCO, "ContextAssembly", this.traceability));

            // ------- Parameters/Properties & Metrics ---------
            foreach (var defParameter in testBench.Children.ParameterCollection)
            {
                var parameter_mo = new UnitParameter()
                {
                    Name = defParameter.Name,
                    Value = this.GetParameterModelicaValue(defParameter),
                    Modifier = this.GetParameterModifier(defParameter)
                };

                this.testBench_mo.Parameters.Add(parameter_mo);
            }

            foreach (var defProperty in testBench.Children.PropertyCollection)
            {
                var parameter_mo = new UnitParameter()
                {
                    Name = defProperty.Name,
                    Value = this.GetPropertyModelicaValue(defProperty, true)
                };

                this.testBench_mo.Parameters.Add(parameter_mo);
            }

            foreach (var metric in testBench.Children.MetricCollection)
            {
                var metric_mo = new Metric()
                {
                    Name = metric.Name,
                    Description = metric.Attributes.Description,
                };

                if (metric.SrcConnections.PPOutput2MetricCollection.Count() == 1)
                {
                    metric_mo.PostProcessing = true;
                }

                this.testBench_mo.Metrics.Add(metric_mo);
            }

            var ca = testBench.Children.ComponentAssemblyCollection.FirstOrDefault();
            var componentAssemblyFullName = string.Format("{0}.ComponentAssemblies.{1}", MainPackage, ca.Name);
            var hasInnerCAs = ca.Children.ComponentAssemblyCollection.Count() > 0;
            if (hasInnerCAs)
            {
                componentAssemblyFullName += "." + ca.Name;
            }

            var componentAssembly_mo = new ComponentAssembly(ca)
            {
                FullName = componentAssemblyFullName,
                HasInnerCAs = hasInnerCAs,
                ConstrainedBys = this.modelicaSettings.GenerateConstrainedBys
            };

            this.testBench_mo.ComponentAssemblies.Add(componentAssembly_mo);

            // Make sure there are margins to the upper- and left-border
            int canvasX = ca.GenericAspect.X > ScaleFactor * 3 * ComponentIconSize ? ca.GenericAspect.X : ScaleFactor * 3 * ComponentIconSize;
            int canvasY = ca.GenericAspect.Y > ScaleFactor * 2 * ComponentIconSize ? ca.GenericAspect.Y : ScaleFactor * 2 * ComponentIconSize;

            // Make sure there are margins to the bottom- and right-border
            this.testBench_mo.CanvasXMax = canvasX + (ScaleFactor * 3 * ComponentIconSize);
            this.testBench_mo.CanvasYMax = canvasY + (ScaleFactor * 2 * ComponentIconSize);

            var componentAssemblyInstance_mo = new ComponentAssemblyInstance(ca)
            {
                InstanceOf = componentAssembly_mo,
                CanvasX = canvasX,
                CanvasY = canvasY
            };

            foreach (var parameter in ca.Children.ParameterCollection)
            {
                var vf = parameter.SrcConnections.ValueFlowCollection.FirstOrDefault();

                // The Value flow is in the TestBench (if in the CA it's dealt with of the definition of the Parameter)
                if (vf != null && vf.ParentContainer.ID == testBench.ID)
                {
                    var parameter_mo = this.GetArgumentParameter(testBench.ID, parameter, vf);

                    componentAssemblyInstance_mo.Parameters.Add(parameter_mo);
                }
            }

            var componentAssemblyInfo = new ComponentInfo(ca.Impl as GME.MGA.IMgaFCO, "PlantAssembly", this.traceability);
            this.instanceURIMap.Add(string.Format("{0}.TestBenches.{1}.{2}", MainPackage, this.testBench_mo.Name, ca.Name), componentAssemblyInfo);
            this.modelURIMap.Add(string.Format("{0}.ComponentAssemblies.{1}.{1}", MainPackage, ca.Name), componentAssemblyInfo);

            this.testBench_mo.ComponentAssemblyInstances.Add(componentAssemblyInstance_mo);

            // ---------- SystemUnderTest (ComponentAssembly)-------
            this.BuildUpComponentAssembly(componentAssembly_mo, null);

            // ----------- TestComponents ----------
            foreach (var testComponent in testBench.Children.TestComponentCollection)
            {
                var modelicaModel = testComponent.Children.ModelicaModelCollection.FirstOrDefault();
                if (modelicaModel == null)
                {
                    continue;
                }

                this.AddTestComponent(testComponent, modelicaModel);
            }

            // -------- Environments ------
            foreach (var environment in testBench.Children.EnvironmentCollection)
            {
                this.AddEnvironment(environment);
                this.instanceURIMap.Add(
                string.Format("{0}.TestBenches.{1}.{2}", MainPackage, testBench.Name, environment.Name),
                    new ComponentInfo(environment.Impl as GME.MGA.IMgaFCO, "Environment", this.traceability));
            }
        }
示例#4
0
        /// <summary>
        /// Builds up all components (through AddComponent), connectors (through AddConnector/AddModelicaConnector)
        /// and inner component assemblies (and calls this function recursively on such), for componentAssembly_mo.
        /// </summary>
        /// <param name="componentAssembly_mo">ComponentAssembly to start from.</param>
        /// <param name="parentComponentAssembly_mo">If the callee was a component assembly -> the callee.</param>
        private void BuildUpComponentAssembly(ComponentAssembly componentAssembly_mo, ComponentAssembly parentComponentAssembly_mo)
        {
            var ca = componentAssembly_mo.Impl;

            // ------- Parameters/Properties & Metrics ---------
            foreach (var defParameter in ca.Children.ParameterCollection)
            {
                // META-3622
                if (String.IsNullOrWhiteSpace(defParameter.Attributes.Dimension) || defParameter.Attributes.Dimension.Trim() == "1")
                {
                    var parameter_mo = new UnitParameter()
                    {
                        Name = defParameter.Name,
                        Value = this.GetParameterModelicaValue(defParameter),
                        Modifier = this.GetParameterModifier(defParameter)
                    };

                    componentAssembly_mo.Parameters.Add(parameter_mo);
                }
            }

            foreach (var defProperty in ca.Children.PropertyCollection)
            {
                // META-3622
                if (String.IsNullOrWhiteSpace(defProperty.Attributes.Dimension) || defProperty.Attributes.Dimension.Trim() == "1")
                {
                    var parameter_mo = new UnitParameter()
                    {
                        Name = defProperty.Name,
                        Value = this.GetPropertyModelicaValue(defProperty, true)
                    };

                    componentAssembly_mo.Parameters.Add(parameter_mo);
                }
            }

            foreach (var metric in ca.Children.MetricCollection)
            {
                var metric_mo = new Metric()
                {
                    Name = metric.Name,
                    Description = metric.Attributes.Description,
                };

                componentAssembly_mo.Metrics.Add(metric_mo);
            }

            // ------- ComponentAssemblies -------
            foreach (var innerComponentAssembly in ca.Children.ComponentAssemblyCollection)
            {
                if (this.ContainsDynamicComponents(innerComponentAssembly) == false)
                {
                    this.Logger.WriteWarning(
                        "Component Assembly '{0}' inside '{1}' does not contain any dynamic models, it will not be generated.", 
                        innerComponentAssembly.Name,
                        ca.Name);
                    continue;
                }

                var innerCAFullName = componentAssembly_mo.FullName.Substring(0, componentAssembly_mo.FullName.LastIndexOf('.'));

                bool innerCAHasChildren = innerComponentAssembly.Children.ComponentAssemblyCollection.Count() > 0;
                if (innerCAHasChildren)
                {
                    innerCAFullName += "." + innerComponentAssembly.Name;
                }

                innerCAFullName += "." + innerComponentAssembly.Name;

                var innerComponentAssembly_mo = new ComponentAssembly(innerComponentAssembly)
                {
                    FullName = innerCAFullName,
                    ParentComponentAssembly = componentAssembly_mo,
                    HasInnerCAs = innerCAHasChildren,
                    ConstrainedBys = this.modelicaSettings.GenerateConstrainedBys
                };

                this.testBench_mo.ComponentAssemblies.Add(innerComponentAssembly_mo);

                // Make sure there are margins to the upper- and left-border
                int canvasX = innerComponentAssembly.GenericAspect.X > ScaleFactor * 3 * ComponentIconSize ? innerComponentAssembly.GenericAspect.X : ScaleFactor * 3 * ComponentIconSize;
                int canvasY = innerComponentAssembly.GenericAspect.Y > ScaleFactor * 2 * ComponentIconSize ? innerComponentAssembly.GenericAspect.Y : ScaleFactor * 2 * ComponentIconSize;

                // Make sure there are margins to the bottom- and right-border
                componentAssembly_mo.CanvasXMax = canvasX + (ScaleFactor * 3 * ComponentIconSize) > componentAssembly_mo.CanvasXMax ? canvasX + (ScaleFactor * 3 * ComponentIconSize) : componentAssembly_mo.CanvasXMax;
                componentAssembly_mo.CanvasYMax = canvasY + (ScaleFactor * 2 * ComponentIconSize) > componentAssembly_mo.CanvasYMax ? canvasY + (ScaleFactor * 2 * ComponentIconSize) : componentAssembly_mo.CanvasYMax;

                var innerComponentAssemblyInstance_mo = new ComponentAssemblyInstance(innerComponentAssembly)
                {
                    InstanceOf = innerComponentAssembly_mo,
                    CanvasX = canvasX,
                    CanvasY = canvasY
                };

                foreach (var parameter in innerComponentAssembly.Children.ParameterCollection)
                {
                    var vf = parameter.SrcConnections.ValueFlowCollection.FirstOrDefault();
                    if (vf != null && vf.ParentContainer.ID == ca.ID)
                    {
                        var parameter_mo = this.GetArgumentParameter(ca.ID, parameter, vf);
                        innerComponentAssemblyInstance_mo.Parameters.Add(parameter_mo);
                    }
                }

                componentAssembly_mo.ComponentAssemblyInstances.Add(innerComponentAssemblyInstance_mo);

                string componentAssemblyInstanceURI = componentAssembly_mo.Name + "." + innerComponentAssemblyInstance_mo.Name;
                var parentCA = parentComponentAssembly_mo;
                while (parentCA != null)
                {
                    componentAssemblyInstanceURI = parentCA.Name + "." + componentAssemblyInstanceURI;
                    parentCA = parentCA.ParentComponentAssembly;
                }

                var componentAssemblyInfo = new ComponentInfo(innerComponentAssembly.Impl as GME.MGA.IMgaFCO, "PlantAssembly", this.traceability);

                this.instanceURIMap.Add(string.Format("{0}.TestBenches.{1}.{2}", MainPackage, this.testBench_mo.Name, componentAssemblyInstanceURI), componentAssemblyInfo);
                this.modelURIMap.Add(innerComponentAssembly_mo.FullName, componentAssemblyInfo);

                this.BuildUpComponentAssembly(innerComponentAssembly_mo, componentAssembly_mo);
            }

            // ------- Components -------
            foreach (var component in ca.Children.ComponentCollection)
            {
                if (this.ComponentIsDynamic(component) == false)
                {
                    this.Logger.WriteWarning(
                        "Component '{0}' inside '{1}' does not contain any dynamic models, it will not be generated.",
                        component.Name,
                        ca.Name);
                    continue;
                }

                if (this.treeComponents.ContainsKey(component.DerivedFrom().ID) == false)
                {
                    this.Logger.WriteDebug(
                        "Component-instance {0}, does not have a generated component. Probably since the component does not have a ModelicaModel.",
                        component.Name);
                    continue;
                }

                this.AddComponent(componentAssembly_mo, parentComponentAssembly_mo, component);
            }

            // ------- ModelicaConnectors -------
            foreach (var connector in ca.Children.ModelicaConnectorCollection)
            {
                this.AddModelicaConnector(componentAssembly_mo, parentComponentAssembly_mo, connector);
            }

            // ------- Connectors -------
            foreach (var connectorContainer in ca.Children.ConnectorCollection)
            {
                if (connectorContainer.Children.ModelicaConnectorCollection.Count() != 1)
                {
                    continue;
                }

                this.AddConnector(componentAssembly_mo, parentComponentAssembly_mo, connectorContainer);
            }
        }