Example #1
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));
            }
        }
Example #2
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);
            }
        }