コード例 #1
0
        public override void visit(TestBench obj)
        {
            if (CodeGenerator.verbose) CodeGenerator.GMEConsole.Info.WriteLine("CyPhyBuildVisitor::visit TestBench: {0}", obj.Name);

            var testBench = obj.Impl;
            
            if (testBench.Children.ComponentAssemblyCollection.Count() == 0)
            {
                CodeGenerator.GMEConsole.Error.WriteLine("No valid component assembly in testbench {0}", obj.Name);
                return;
            }

            foreach (var ca in testBench.Children.ComponentAssemblyCollection)
            {
                var componentAssembly_obj = new ComponentAssembly(ca);
                obj.ComponentAssemblies.Add(componentAssembly_obj);
            }

            foreach (var tc in testBench.Children.TestComponentCollection)
            {
                var testComponent_obj = new Component(tc);
                obj.TestComponents.Add(testComponent_obj);
            }

            // Save CyPhy TestBench parameters, such as "simulationTime", in the CyPhy2SystemC testbench object.  MOT-516
            foreach (var p in testBench.Children.ParameterCollection)
            {
                string paramName = p.Name;
                if (!obj.TestParameters.ContainsKey(paramName))
                {
                    obj.TestParameters[paramName] = p;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 往工作部件中添加组件并移动
        /// </summary>
        /// <param name="componentAssembly"></param>
        /// <param name="partToAdd">要添加的数模</param>
        /// <param name="locateOrigin">要添加到的原点</param>
        /// <param name="orientation">方位</param>
        /// <param name="layer">要添加到的图层,默认为-1,即原始图层,0表示工作图层,其余表示特定图层</param>
        /// <returns></returns>
        public static Component AddComponent(this ComponentAssembly componentAssembly, Part partToAdd, Point3d locateOrigin, Matrix3x3 orientation, int layer = -1)
        {
            PartLoadStatus loadStatus;

            Component component;

            if (ManagedMode == true)
            {
                string partNumber = partToAdd.GetID();

                string partRevision = partToAdd.GetRevision();

                if (partRevision == "N/A")
                {
                    partRevision = partToAdd.GetLatestRevision();
                }

                component = componentAssembly.AddComponent("@DB/" + partNumber + @"/" + partRevision, "Entire Part", partNumber, locateOrigin, orientation, layer, out loadStatus);
            }
            else
            {
                // 添加本地组件
                component = componentAssembly.AddComponent(partToAdd.FullPath, "Entire Part", partToAdd.GetID(), locateOrigin, orientation, layer, out loadStatus);
            }
            return(component);
        }
コード例 #3
0
 private List<Component> CollectGroundNodes(ComponentAssembly obj)
 {
     var gnds = obj.ComponentInstances.Where(t =>
         Grounds.Any(GetSpiceType(t).Item2.Contains)
         ).ToList();
     var cgnds = obj.ComponentAssemblyInstances.SelectMany(ca => CollectGroundNodes(ca)).ToList();
     return gnds.Union(cgnds).ToList();
 }
コード例 #4
0
    public static int Startup(string[] args)
    {
        int retValue = 0;

        try
        {
            theProgram = new Program();

            PartLoadStatus pld;
            string         partPath = @"D:\ACCEPTED_NX_MODELS\Q5\TEST\TEST.prt";
            Part           workPart = theSession.Parts.OpenBaseDisplay(partPath, out pld) as Part;

            ComponentAssembly assembly      = workPart.ComponentAssembly;
            Component         rootComponent = assembly.RootComponent;

            theProgram.Traverse(rootComponent);
            theSession.ListingWindow.Open();

            foreach (Component leaf in theProgram.leafList)
            {
                Part   leafPart   = leaf.Prototype as Part;
                Body[] leafBodies = leafPart.Bodies.ToArray();

                if (leafBodies.Length != 0)
                {
                    Body             leafBody         = leafBodies[0];
                    Promotion        promoteBody      = null;
                    PromotionBuilder promotionBuider1 = workPart.Features.CreatePromotionBuilder(promoteBody);
                    leafBody = leaf.FindOccurrence(leafBody) as Body;
                    bool     added     = promotionBuider1.Body.Add(leafBody);
                    bool     validated = promotionBuider1.Validate();
                    NXObject objects   = promotionBuider1.Commit();
                    promotionBuider1.Destroy();
                    theSession.ListingWindow.WriteLine(leaf.Name + "\t" + leafBodies.Length.ToString() + "\t" + leafBody.Name.ToString());
                }
            }

            PartSaveStatus ps;
            bool           partSaved;
            theSession.Parts.SaveAll(out partSaved, out ps);

            theUFSession.Part.CloseAll();
            theProgram.Dispose();
        }
        catch (NXOpen.NXException ex)
        {
            theUFSession.Part.CloseAll();

            theSession.ListingWindow.Open();
            theSession.ListingWindow.WriteLine(ex.ToString());

            // ---- Enter your exception handling code here -----
        }
        return(retValue);
    }
コード例 #5
0
 public override void visit(ComponentAssembly obj)
 {
     var layoutFile = (obj.Impl.Impl as GME.MGA.MgaFCO).RegistryValue["layoutFile"];
     if (layoutFile != null)
     {
         var pathLayoutFile = Path.Combine(obj.Impl.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE), layoutFile);
         var layoutParser = new Layout.LayoutParser(pathLayoutFile,
             CodeGenerator.Logger)
             {
                 parentInstanceGUID = (obj.Impl.Impl as GME.MGA.MgaFCO).
                 RegistryValue["Elaborator/InstanceGUID_Chain"]
             };
         Logger.WriteDebug("Parent GUID : {0}", layoutParser.parentInstanceGUID);
         layoutParser.BuildMaps();
         CodeGenerator.preRouted.Add(obj, layoutParser);
     }
 }
コード例 #6
0
        /// <summary>
        /// 往指定部件中添加组件并移动到指定位置,方向为默认
        /// </summary>
        /// <param name="componentAssembly"></param>
        /// <param name="partNumber">要添加的数模号,若为本地,则需要指定完整路径</param>
        /// <param name="partRevision">要添加的数模版本,仅用于 Teamcenter 集成环境,本地模式忽略此参数,若版本为空或null,则添加最新版本</param>
        /// <param name="locateOrigin">要添加到的原点</param>
        /// <param name="orientation">组件方位</param>
        /// <param name="layer">要添加到的图层,默认为-1,即原始图层,0表示工作图层,其余表示特定图层</param>
        /// <returns></returns>
        public static Component AddComponent(this ComponentAssembly componentAssembly, string partNumber, string partRevision, Point3d locateOrigin, Matrix3x3 orientation, int layer = -1)
        {
            PartLoadStatus loadStatus;

            NXOpen.Assemblies.Component component;

            if (ManagedMode == true)
            {
                if (string.IsNullOrEmpty(partRevision) || partRevision == "N/A")
                {
                    partRevision = PartEx.GetLatestRevision(partNumber);
                }

                component = componentAssembly.AddComponent("@DB/" + partNumber + @"/" + partRevision, "Entire Part", partNumber, locateOrigin, orientation, layer, out loadStatus);
            }
            else
            {
                // 添加本地组件
                component = componentAssembly.AddComponent(partNumber, "Entire Part", partNumber, locateOrigin, orientation, layer, out loadStatus);
            }
            return(component);
        }
コード例 #7
0
    // Highlights or Unhighlights a component. Depending on the the state of the drawAll
    // flag, this will either draw just the individual component, or the component plus
    // all of the equivalent components in other subassemblies.
    //
    // To see this in action, load the ToyCar assembly, and select the LEFT_WHEEL
    // component from the front axle. If drawAll is set to true, then the LEFT_WHEEL
    // component on the rear axle will be highlit as well.


    private void HighlightComponent(Component component, bool highlight)
    {
        if (component != null)
        {
            if (highlight)
            {
                component.Highlight();
            }
            else
            {
                component.Unhighlight();
            }


            if (drawAll)
            {
                // To find the equivalent, map "component" onto the equivalent component
                // in its owning part. Then map this equivalent component onto the array
                // of equivalents in the displayed part.

                ComponentAssembly owner      = component.DirectOwner;
                Component         mapped     = owner.MapComponentFromParent(component);
                ComponentAssembly topOwner   = theSession.Parts.Display.ComponentAssembly;
                Component[]       mappedBack = topOwner.MapComponentsFromSubassembly(mapped);
                for (int i = 0; i < mappedBack.Length; i++)
                {
                    if (highlight)
                    {
                        mappedBack[i].Highlight();
                    }
                    else
                    {
                        mappedBack[i].Unhighlight();
                    }
                }
            }
        }
    }
コード例 #8
0
        public static void AddComponentsFromAssembly(Assembly assembly)
        {
            if (assembly == typeof(System.Windows.Forms.Form).Assembly || assembly == typeof(int).Assembly)
            {
                return;
            }
            var  types         = assembly.GetTypes();
            var  control_types = new List <Type>();
            Type controlType   = typeof(System.Windows.Forms.Control);

            foreach (Type type in types)
            {
                if (type.IsSubclassOf(controlType))
                {
                    control_types.Add(type);
                }
            }
            if (control_types.Count > 0)
            {
                string assemblyName = assembly.FullName;
                int    ind          = assemblyName.IndexOf(',');
                if (ind != -1)
                {
                    assemblyName = assemblyName.Substring(0, ind).Trim();
                }
                Category          cat = new Category(assemblyName);
                ComponentAssembly cas = new ComponentAssembly(assembly.FullName);
                foreach (Type type in control_types)
                {
                    cat.ToolComponents.Add(new ToolComponent(type.FullName, cas, true));
                }
                var dynamicTab = new SideTabDesigner(sideBar, cat, toolboxService);
                dynamicTab.ItemRemoved    += SideTabItemRemoved;
                dynamicTab.ItemsExchanged += SideTabItemsExchanged;
                sideBar.Tabs.Add(dynamicTab);
            }
        }
コード例 #9
0
        public override void visit(TestBench obj)
        {
            Logger.WriteDebug("CyPhyBuildVisitor::visit({0})", obj.Impl.Path);

            var testBench = obj.Impl;
            var ca = testBench.Children.ComponentAssemblyCollection.FirstOrDefault();
            if (ca == null)
            {
                Logger.WriteFailed("No valid component assembly in testbench {0}", obj.Name);
                return;
            }
            var componentAssembly_obj = new ComponentAssembly(ca);
            obj.ComponentAssemblies.Add(componentAssembly_obj);

            var tcs = testBench.Children.TestComponentCollection;
            foreach (var tc in tcs)
            {
                var component_obj = new Component(tc);
                obj.TestComponents.Add(component_obj);
                CyPhyBuildVisitor.Components.Add(tc.ID, component_obj);   // Add to global component list, are these instance ID-s or component type ID-s?
            }

            foreach (var param in testBench.Children.ParameterCollection)
            {
                var param_obj = new Parameter()
                {
                    Name = param.Name,
                    Value = param.Attributes.Value
                };
                obj.Parameters.Add(param_obj);
            }

            // solver parameters - currently using Dymola Solver object
            var solver = testBench.Children.SolverSettingsCollection.FirstOrDefault();
            if (solver != null)
                obj.SolverParameters.Add("SpiceAnalysis", solver.Attributes.ToolSpecificAnnotations);
        }
コード例 #10
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));
            }
        }
コード例 #11
0
        /// <summary>
        /// Adds connectorContainer (Connector containing a ModelicaConnector) to componentAssembly_mo.
        /// </summary>
        /// <param name="componentAssembly_mo">ComponentAssembly that contains the component.</param>
        /// <param name="parentComponentAssembly_mo">ComponentAssembly that contains componentAssembly_mo.</param>
        /// <param name="connectorContainer">CyPhy Connector to add.</param>
        private void AddConnector(ComponentAssembly componentAssembly_mo, ComponentAssembly parentComponentAssembly_mo, CyPhy.Connector connectorContainer)
        {
            var ca = componentAssembly_mo.Impl;
            var containedConnector = connectorContainer.Children.ModelicaConnectorCollection.FirstOrDefault();

            // Connectors do not need margins at the borders
            int canvasX = connectorContainer.GenericAspect.X;
            int canvasY = connectorContainer.GenericAspect.Y;

            componentAssembly_mo.CanvasXMax = canvasX > componentAssembly_mo.CanvasXMax ? canvasX : componentAssembly_mo.CanvasXMax;
            componentAssembly_mo.CanvasYMax = canvasY > componentAssembly_mo.CanvasYMax ? canvasY : componentAssembly_mo.CanvasYMax;

            var connector_mo = new Connector(containedConnector)
            {
                ModelicaURI = containedConnector.Attributes.Class,
                CanvasX = canvasX,
                CanvasY = canvasY
            };

            connector_mo.Name = connectorContainer.Name.Replace(' ', '_');

            foreach (var parameter in containedConnector.Children.ModelicaParameterCollection)
            {
                var value = this.GetModelicaParameterValue(parameter);
                if (string.IsNullOrWhiteSpace(value) == false)
                {
                    connector_mo.Parameters.Add(
                        new UnitParameter()
                        {
                            Name = parameter.Name,
                            Value = new ModelicaValue(value)
                        });
                }
            }

            foreach (var redeclareParameter in containedConnector.Children.ModelicaRedeclareCollection)
            {
                var value = redeclareParameter.Attributes.Value;

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

            componentAssembly_mo.Connectors.Add(connector_mo);

            // Iterate over all ports that are connected FROM the connector. 
            foreach (var dstPortContainer in connectorContainer.DstConnections.ConnectorCompositionCollection.Select(c => c.DstEnds.Connector))
            {
                var srcConnectorContainer = connectorContainer;
                var srcContainedConnector = containedConnector;

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

                    var dstConnector = this.GetModelicaModelConnectorFromComponentPortContainer(dstPortContainer);

                    if (dstConnector == null)
                    {
                        continue;
                    }

                    var connection_mo = new Connection(srcConnectorContainer.Name, dstConnector.Name)
                    {
                        DstInstanceName = dstPortContainer.ParentContainer.Name,
                        Type = srcContainedConnector.Attributes.Class
                    };

                    if (portComponent.ParentContainer.ID.Equals(ca.ID))
                    {
                        // Component is within current Component Assembly
                        componentAssembly_mo.Connections.Add(connection_mo);
                    }
                    else
                    {
                        // Component is within the parent Component Assembly
                        connection_mo.SrcInstanceName = componentAssembly_mo.Name;
                        parentComponentAssembly_mo.Connections.Add(connection_mo);
                    }
                }
                else if (dstPortContainer.ParentContainer is CyPhy.ComponentAssembly)
                {
                    var portCA = dstPortContainer.ParentContainer as CyPhy.ComponentAssembly;
                    if (this.ContainsDynamicComponents(portCA) == false)
                    {
                        this.Logger.WriteWarning("'{0}' does not contain any dynamic-components, connections to it skipped.", portCA.Name);
                        continue;
                    }

                    var componentAssemblyIDList = componentAssembly_mo.ComponentAssemblyInstances.Select(c => c.Impl.ID);

                    if (componentAssemblyIDList.Contains(portCA.ID))
                    {
                        // Case 1: The connected ComponentAssembly is contained within the current one
                        var connection_mo = new Connection(srcConnectorContainer.Name, dstPortContainer.Name)
                        {
                            DstInstanceName = dstPortContainer.ParentContainer.Name,
                            Type = srcContainedConnector.Attributes.Class
                        };

                        componentAssembly_mo.Connections.Add(connection_mo);
                    }
                    else if (portCA.ID.Equals(ca.ID))
                    {
                        // Case 2: The connected ComponentAssembly is itself (Connector to Connector - not pretty modelling)
                        var connection_mo = new Connection(srcConnectorContainer.Name, dstPortContainer.Name)
                        {
                            Type = srcContainedConnector.Attributes.Class
                        };

                        componentAssembly_mo.Connections.Add(connection_mo);
                    }
                    else if (parentComponentAssembly_mo != null)
                    {
                        // Case 3: The connected ComponentAssembly is the current one's parent
                        if (portCA.ID.Equals(parentComponentAssembly_mo.Impl.ID))
                        {
                            var connection_mo = new Connection(srcConnectorContainer.Name, dstPortContainer.Name)
                            {
                                SrcInstanceName = componentAssembly_mo.Name,
                                Type = srcContainedConnector.Attributes.Class
                            };

                            parentComponentAssembly_mo.Connections.Add(connection_mo);
                        }
                        else
                        {
                            // Case 4: (By exclusion) The connected ComponentAssembly is at the same level (i.e. within the parent ComponentAssembly)
                            var connection_mo = new Connection(srcConnectorContainer.Name, dstPortContainer.Name)
                            {
                                SrcInstanceName = componentAssembly_mo.Name,
                                DstInstanceName = dstPortContainer.ParentContainer.Name,
                                Type = srcContainedConnector.Attributes.Class
                            };

                            parentComponentAssembly_mo.Connections.Add(connection_mo);
                        }
                    }
                }
                else if (dstPortContainer.ParentContainer is CyPhy.TestComponent)
                {
                    var dstConnector = this.GetModelicaModelConnectorFromComponentPortContainer(dstPortContainer);
                    if (dstConnector == null)
                    {
                        continue;
                    }

                    var connection_mo = new Connection(srcConnectorContainer.Name, dstConnector.Name)
                    {
                        SrcInstanceName = componentAssembly_mo.Name,
                        DstInstanceName = dstPortContainer.ParentContainer.Name,
                        Type = srcContainedConnector.Attributes.Class
                    };

                    this.testBench_mo.Connections.Add(connection_mo);
                }
                else if (dstPortContainer.ParentContainer is CyPhy.Environment)
                {
                    this.Logger.WriteDebug("Environment connected in Connector-chains not supported!");
                    continue;
                }
            }
        }
コード例 #12
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);

            }
        }
コード例 #13
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);
            }
        }
コード例 #14
0
    //------------------------------------------------------------------------------
    //  NX Startup
    //      This entry point activates the application at NX startup

    //Will work when complete path of the dll is provided to Environment Variable
    //USER_STARTUP or USER_DEFAULT
    //------------------------------------------------------------------------------
    public static int Startup()
    {
        int retValue = 0;

        try
        {
            theProgram = new Program();

            //string partPath = @"F:\TEST.prt";
            //string partPath = @"F:\CASE\ASM.prt";
            string         partPath = @"F:\CASE1\Case_1-1_stp.prt";
            PartLoadStatus PLD;
            Part           workPart = theSession.Parts.OpenBaseDisplay(partPath, out PLD) as Part;

            if (workPart != null)
            {
                ComponentAssembly assembly      = workPart.ComponentAssembly;
                Component         rootComponent = assembly.RootComponent;
                //try {object flange1 = assembly.FindObject("FLANGE(10K_150A_G)_K3029930#1");}
                //catch(Exception ex) { theUI.NXMessageBox.Show("Null", NXMessageBox.DialogType.Error, ex.Message); }

                theProgram.Traverse(rootComponent);

                Component comp1_1 = rootComponent.FindObject("COMPONENT OIL_PIPE_TYPE1_ASSY-01 2") as Component;
                Component comp1   = comp1_1.FindObject("COMPONENT FLANGE(10K_150A_G)_K3029930#1 1") as Component;
                Component comp2_1 = rootComponent.FindObject("COMPONENT OIL_PIPE_TYPE1_ASSY-01 3") as Component;
                Component comp2   = comp2_1.FindObject("COMPONENT FLANGE(10K_150A_N)_K3034074#1 1") as Component;

                Part one = comp1.Prototype as Part;
                Part two = comp2.Prototype as Part;

                DatumPlane oneXY = null;
                DatumPlane twoXY = null;

                //foreach(Component leaf in theProgram.leafList)
                //{
                //    if(leaf.DisplayName == "FLANGE(10K_150A_G)_K3029930#1")
                //    {
                //        //comp1 = leaf;
                //        one = leaf.Prototype as Part;
                //    }

                //    if (leaf.DisplayName == "FLANGE(10K_150A_N)_K3034074#1")
                //    {
                //        //comp2 = leaf;
                //        two = leaf.Prototype as Part;
                //    }
                //}

                if (one != null && two != null)
                {
                    theProgram.GetXYPlane(one, out oneXY);
                    theProgram.GetXYPlane(two, out twoXY);

                    oneXY = comp1.FindOccurrence(oneXY) as DatumPlane;
                    twoXY = comp2.FindOccurrence(twoXY) as DatumPlane;
                }

                //Tag tag1 = theUfSession.Assem.AskPartOccurrence(oneXY.Tag);

                try
                {
                    ComponentPositioner positioner1 = assembly.Positioner;
                    positioner1.BeginAssemblyConstraints();

                    Constraint          constraint1          = positioner1.CreateConstraint(true);
                    ComponentConstraint componentConstraint1 = constraint1 as ComponentConstraint;

                    componentConstraint1.ConstraintAlignment = Constraint.Alignment.ContraAlign;
                    componentConstraint1.ConstraintType      = Constraint.Type.Touch;
                    ConstraintReference ref1 = componentConstraint1.CreateConstraintReference(comp1, oneXY, false, false, false);
                    ConstraintReference ref2 = componentConstraint1.CreateConstraintReference(comp2, twoXY, false, false, false);
                    //componentConstraint1.FlipAlignment();
                    //componentConstraint1.SetAlignmentHint(NXOpen.Positioning.Constraint.Alignment.ContraAlign);
                }
                catch (Exception E)
                {
                    theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, E.Message);
                }
            }


            PartSaveStatus ps;
            bool           partSaved;
            theSession.Parts.SaveAll(out partSaved, out ps);

            theUfSession.Part.CloseAll();
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----
            theUI.NXMessageBox.Show("UI Styler", NXMessageBox.DialogType.Error, ex.Message);
        }
        return(retValue);
    }
コード例 #15
0
ファイル: ReportsController.cs プロジェクト: dvhoeck/tmp
        /// <summary>
        /// Reports the on assemblies.
        /// </summary>
        /// <param name="baseModelId">The base model identifier.</param>
        /// <param name="modelId">The model identifier.</param>
        /// <param name="componentName">Name of the component.</param>
        /// <param name="componentNameFreeInput">The component name free input.</param>
        /// <param name="componentValue">The component value.</param>
        /// <param name="productSerial">The product serial.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <returns></returns>
        public ActionResult ReportOnAssemblies(Guid?baseModelId, Guid?modelId, Guid?componentId, string componentNameFreeInput, string componentValue, string productSerial, DateTime?startDate, DateTime endDate)
        {
            _logger.LogInfo("User {0} attempts to generate a report on assemblies. User filter params: baseModelId = '{1}', modelId = '{2}', componentId = '{3}',  componentNameFreeInput = '{4}', componentValue = '{5}', productSerial = '{6}', start date = '{7}', end data = '{8}'",
                            User.Identity.Name,     // 0
                            baseModelId,            // 1
                            modelId,                // 2
                            componentId,            // 3
                            componentNameFreeInput, // 4
                            componentValue,         // 5
                            productSerial,          // 6
                            startDate,              // 7
                            endDate);               // 8

            try
            {
                var searchCriteria = UnitOfWorkSession.CreateCriteria <ProductAssembly>();

                // check for product serial user input
                if (!string.IsNullOrEmpty(productSerial))
                {
                    productSerial  = productSerial.Replace('*', '%');
                    searchCriteria = searchCriteria.Add(Expression.Like("ProductSerial", productSerial));
                }

                // start date
                if (startDate != null && startDate != DateTime.MinValue && startDate != DateTime.MaxValue)
                {
                    searchCriteria = searchCriteria.Add(Expression.Gt("StartDate", startDate));
                }
                else
                {
                    searchCriteria = searchCriteria.Add(Expression.Gt("StartDate", _minDate));
                }

                // end date
                if (endDate != null && endDate != DateTime.MinValue && endDate != DateTime.MaxValue)
                {
                    searchCriteria = searchCriteria.Add(Expression.Lt("EndDate", endDate) || Expression.Eq("EndDate", _finalEndDate)); //searchCriteria = searchCriteria.Add(Expression.Lt("EndDate", endDate) || Expression.Lt("EndDate", _finalEndDate));
                }
                else
                {
                    searchCriteria = searchCriteria.Add(Expression.Lt("EndDate", _finalEndDate));
                }

                // check for component user input
                if (!string.IsNullOrEmpty(componentValue))
                {
                    componentValue         = componentValue.Replace('*', '%');
                    componentNameFreeInput = componentNameFreeInput?.Replace('*', '%');

                    // filter on ComponentAssemblies
                    searchCriteria = searchCriteria.CreateCriteria("ComponentAssemblies");

                    // use component value to filter, if needed
                    searchCriteria = searchCriteria.Add(Expression.Like("Revision", componentValue) || Expression.Like("Serial", componentValue));

                    // check component id vs component name entries
                    searchCriteria = searchCriteria.CreateCriteria("ProductComponent");
                    if (componentId != null && componentId != Guid.Empty)
                    {
                        searchCriteria = searchCriteria.Add(Expression.Eq("Id", componentId));
                    }
                    else if (!string.IsNullOrEmpty(componentNameFreeInput))
                    {
                        searchCriteria = searchCriteria.Add(Expression.Like("ComponentName", componentNameFreeInput));
                    }
                }

                // check model selection
                if (modelId != null && modelId != Guid.Empty)
                {
                    searchCriteria = searchCriteria.CreateCriteria("ProductModel").Add(Expression.Eq("Id", modelId));
                }
                else if (baseModelId != null && baseModelId != Guid.Empty)
                {
                    searchCriteria = searchCriteria.CreateCriteria("ProductModel").Add(Expression.Eq("BaseModelId", baseModelId));
                }

                // retrieve results
                var results = searchCriteria.List <ProductAssembly>();

                IEnumerable <dynamic> assemblies = null;

                // check if we need to include a component value (= if a component value is entered by the user)
                if (!string.IsNullOrEmpty(componentValue))
                {
                    var tmpAssemblyList = new List <dynamic>();
                    results.ToList <ProductAssembly>().ForEach(x =>
                    {
                        string componentName, ComponentDataRevision, ComponentDataSerial = null;
                        ComponentAssembly componentAssembly = null;

                        // use either the component id input parameter or the free text entry component namee
                        if (componentId != null && componentId != Guid.Empty)
                        {
                            componentAssembly = x.ComponentAssemblies.Where(componentAssy => componentAssy.ProductComponent.Id == componentId).Single();
                        }
                        else
                        {
                            componentAssembly = x.ComponentAssemblies.Where(componentAssy => componentAssy.ProductComponent.ComponentName.Contains(componentNameFreeInput.Remove(componentNameFreeInput.IndexOf('%'), 1))).Single();
                        }

                        // use the retrieved component assembly
                        componentName           = componentAssembly?.ProductComponent.ComponentName;
                        ComponentDataRevision   = componentAssembly?.Revision;
                        ComponentDataSerial     = componentAssembly?.Serial;
                        var ComponentChangeDate = componentAssembly?.AssemblyDateTime;

                        var assy = new
                        {
                            Id                    = x.Id,
                            StartDate             = x.StartDate,
                            LastUpdate            = x.ComponentAssemblies.ToList().OrderByDescending(ca => ca.AssemblyDateTime).FirstOrDefault()?.AssemblyDateTime,
                            Name                  = x.ProductModel.Name,
                            ProductSerial         = x.ProductSerial,
                            PublicProductSerial   = x.PublicProductSerial,
                            Configurations        = CreateModelConfigurationString(x.ProductModelConfigurations),
                            ModelType             = x.ProductModel.ModelType.ToString(),
                            State                 = x.ProductModelState.Name,
                            Progress              = x.Progress,
                            FinalState            = x.Evaluation,
                            ModelVersion          = x.ProductModel.Version,
                            ComponentName         = componentName,
                            ComponentDataRevision = ComponentDataRevision,
                            ComponentDataSerial   = ComponentDataSerial,
                            ComponentChangeDate   = ComponentChangeDate
                        };

                        tmpAssemblyList.Add(assy);

                        assemblies = tmpAssemblyList.OrderBy(y => y.StartDate);
                    });
                }
                else
                {
                    assemblies = results.Select(x => new
                    {
                        Id                  = x.Id,
                        StartDate           = x.StartDate,
                        LastUpdate          = x.ComponentAssemblies.ToList().OrderByDescending(ca => ca.AssemblyDateTime).FirstOrDefault()?.AssemblyDateTime,
                        Name                = x.ProductModel.Name,
                        ProductSerial       = x.ProductSerial,
                        PublicProductSerial = x.PublicProductSerial,
                        Configurations      = CreateModelConfigurationString(x.ProductModelConfigurations),
                        ModelType           = x.ProductModel.ModelType.ToString(),
                        State               = x.ProductModelState.Name,
                        Progress            = x.Progress,
                        FinalState          = x.Evaluation,
                        ModelVersion        = x.ProductModel.Version
                    }).OrderBy(x => x.StartDate);
                }

                return(SerializeForWeb(assemblies));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
                throw;
            }
        }
コード例 #16
0
        public override void visit(ComponentAssembly obj)
        {
            CodeGenerator.Logger.WriteDebug(
                    "SpiceVisitor::visit({0})",
                    obj.Name);

            // create a signal container for this assembly
            var siginfo_obj = new Spice.SignalContainer()
            {
                name = obj.Name,
                gmeid = obj.Impl.ID
            };
            ObjectSiginfoMap.Add(obj, siginfo_obj);
            var siginfo_parent = this.siginfo_obj;
            if (obj.Parent != null && ObjectSiginfoMap.ContainsKey(obj.Parent))
            {
                siginfo_parent = ObjectSiginfoMap[obj.Parent] as Spice.SignalContainer;
            }
            siginfo_parent.signals.Add(siginfo_obj);
        }
コード例 #17
0
        public override void visit(ComponentAssembly obj)
        {
            Logger.WriteDebug("CyPhyBuildVisitor::visit({0})", obj.Impl.Path);

            var ca = obj.Impl;

            // ------- ComponentAssemblies -------
            foreach (var innerComponentAssembly in ca.Children.ComponentAssemblyCollection)
            {
                var innerComponentAssembly_obj = new ComponentAssembly(innerComponentAssembly)
                {
                    Parent = obj,
                };
                obj.ComponentAssemblyInstances.Add(innerComponentAssembly_obj);
            }

            // ------- Components -------
            foreach (var component in ca.Children.ComponentCollection)
            {
                var component_obj = new Component(component)
                {
                    Parent = obj,
                };
                obj.ComponentInstances.Add(component_obj);
                CyPhyBuildVisitor.Components.Add(component.ID, component_obj);   // Add to global component list, component type ID-s?
                CyPhyBuildVisitor.ComponentInstanceGUIDs.Add(component.Attributes.InstanceGUID, component_obj);   // component instance guid-s?
            }
        }
コード例 #18
0
        // This class computes the layout of the flat schematic diagram starting from GME hierarchical diagrams
        public override void upVisit(ComponentAssembly obj)
        {
            SortedList<Tuple<float, float>, object> nodes = new SortedList<Tuple<float, float>, object>();

            // we have already visited all child nodes, and know their extents (canvasWidth and canvasHeight)
            // now sort all child objects by their GME object location, and use the GME location as their initial position
            foreach (var ca in obj.ComponentAssemblyInstances)
            {
                var allAspect = ca.Impl.Aspects.Where(a => a.Name.Equals("All")).FirstOrDefault();
                float x = (allAspect != null) ? ((float)allAspect.X) / gme2Eagle : defSize;
                float y = (allAspect != null) ? ((float)allAspect.Y) / gme2Eagle : defSize;
                ca.CanvasX = (float)Math.Round(x / gridSize) * gridSize;
                ca.CanvasY = (float)Math.Round(y / gridSize) * gridSize;
                Tuple<float, float> location = new Tuple<float, float>(ca.CanvasX, ca.CanvasY);
                nodes.Add(location, ca);

            }
            foreach (var ca in obj.ComponentInstances)
            {
                var allAspect = ca.Impl.Aspects.Where(a => a.Name.Equals("All")).FirstOrDefault();
                float x = allAspect != null ? ((float)allAspect.X) / gme2Eagle : defSize;
                float y = allAspect != null ? ((float)allAspect.Y) / gme2Eagle : defSize;
                ca.CanvasX = (float)Math.Round(x / gridSize) * gridSize;
                ca.CanvasY = (float)Math.Round(y / gridSize) * gridSize;
                Tuple<float, float> location = new Tuple<float, float>(ca.CanvasX, ca.CanvasY);
                nodes.Add(location, ca);
            }

            object[] nodeArr = nodes.Values.ToArray();
            float maxWidth = 0;
            float maxHeight = 0;
            for (int i = 0; i < nodes.Count; i++)
            {
                var node = nodeArr[i];
                var nx = node is Component ? (node as Component).CanvasX : (node as ComponentAssembly).CanvasX;
                var ny = node is Component ? (node as Component).CanvasY : (node as ComponentAssembly).CanvasY;

                for (int j = 0; j < i; j++)
                {
                    var nodePre = nodeArr[j];
                    float npxw, npyh;
                    if (nodePre is Component)
                    {
                        var c = nodePre as Component;
                        npxw = c.CanvasX + c.CanvasWidth; 
                        npyh = c.CanvasY + c.CanvasHeight;
                    }
                    else
                    {
                        var c = nodePre as ComponentAssembly;
                        npxw = c.CanvasX + c.CanvasWidth; 
                        npyh = c.CanvasY + c.CanvasHeight;
                    }
                    if ( (nx - symSpace) <= npxw && (ny - symSpace) <= npyh)       // overlap
                    {
                        if (j % 2 == 0)
                            nx = npxw + symSpace;
                        else
                            ny = npyh + symSpace;
                    }
                }
                float nxw, nyh;
                if (node is Component)
                {
                    var c = node as Component;
                    c.CanvasX = nx;
                    c.CanvasY = ny;
                    nxw = nx + c.CanvasWidth;
                    nyh = ny + c.CanvasHeight;
                    Logger.WriteDebug("Placing Node {0} in Assembly {1}: @ {2},{3}",
                                      c.Name, obj.Name, nx, ny);
                }
                else
                {
                    var c = node as ComponentAssembly;
                    c.CanvasX = nx;
                    c.CanvasY = ny;
                    nxw = nx + c.CanvasWidth;
                    nyh = ny + c.CanvasHeight;
                }
                maxWidth = Math.Max(maxWidth, nxw);
                maxHeight = Math.Max(maxHeight, nyh);
            }
            // set the size of this container
            obj.CanvasWidth = (float)Math.Round(maxWidth/(2.0f*gridSize))*2.0f*gridSize;
            obj.CanvasHeight = (float)Math.Round(maxHeight/(2.0f*gridSize))*2.0f*gridSize;
        }
コード例 #19
0
 /// <summary>
 /// 往指定部件中添加组件并移动到指定位置,方向为默认
 /// </summary>
 /// <param name="componentAssembly"></param>
 /// <param name="partNumber">要添加的数模号,若为本地,则需要指定完整路径</param>
 /// <param name="partRevision">要添加的数模版本,仅用于 Teamcenter 集成环境,本地模式忽略此参数,若版本为空或null,则添加最新版本</param>
 /// <param name="locateOrigin">要添加到的原点</param>
 /// <param name="layer">要添加到的图层,默认为-1,即原始图层,0表示工作图层,其余表示特定图层</param>
 /// <returns></returns>
 public static Component AddComponent(this ComponentAssembly componentAssembly, string partNumber, string partRevision, Point3d locateOrigin, int layer = -1) => AddComponent(componentAssembly, partNumber, partRevision, locateOrigin, Matrix3x3Ex.Identity, layer);
コード例 #20
0
 public override void visit(ComponentAssembly obj)
 {
     if (obj.Parent != null)
     {
         obj.CanvasX += obj.Parent.CanvasX;
         obj.CanvasY += obj.Parent.CanvasY;
     }
 }
コード例 #21
0
 /// <summary>
 /// 往指定部件中添加组件并移动
 /// </summary>
 /// <param name="componentAssembly"></param>
 /// <param name="partToAdd">要添加的数模</param>
 /// <param name="locateOrigin">要添加到的原点</param>
 /// <param name="layer">要添加到的图层,默认为-1,即原始图层,0表示工作图层,其余表示特定图层</param>
 /// <returns></returns>
 public static Component AddComponent(this ComponentAssembly componentAssembly, Part partToAdd, Point3d locateOrigin, int layer = -1) => AddComponent(componentAssembly, partToAdd, locateOrigin, Matrix3x3Ex.Identity, layer);
コード例 #22
0
 public virtual void upVisit(ComponentAssembly obj)
 {
 }
コード例 #23
0
        public int HandlePreRoutedAsm(ComponentAssembly obj, int pkg_idx)
        {
            if (CodeGenerator.preRouted.ContainsKey(obj))
            {
                var layoutBox = (obj.Impl.Impl as GME.MGA.MgaFCO).RegistryValue["layoutBox"];
                // format x1,y1,w1,h1; x2,y2,w2,h2; x3,y3,w3,h3
                // NOTE: if there are multiple bounding boxes 
                // - we expect the first one to be at the origin of the reference frame
                // - this minor limitation would be easy to address later by adding code to identify 
                // - the bounding box at origin even if its not the first one

                var bBoxs = layoutBox.Split(';');
                int bbidx = 0;
                int origPkgIdx = 0;
                foreach (var bbox in bBoxs)
                {
                    Package pkg = new Package();
                    pkg.pkg_idx = pkg_idx++;
                    pkg.name = obj.Name;
                    pkg.package = "__spaceClaim__";
                    pkg.ComponentID = (obj.Impl.Impl as GME.MGA.MgaFCO)
                        .RegistryValue["Elaborator/InstanceGUID_Chain"];
                    var pts = bbox.Split(',');
                    if (pts.Length >= 4)
                    {
                        double d = Double.NaN;
                        if (Double.TryParse(pts[0], out d))
                            pkg.x = d;
                        if (Double.TryParse(pts[1], out d))
                            pkg.y = d;
                        if (Double.TryParse(pts[2], out d))
                            pkg.width = d;
                        if (Double.TryParse(pts[3], out d))
                            pkg.height = d;
                    }
                    if (bbidx == 0)
                    {
                        preroutedPkgMap.Add(obj, pkg);
                        origPkgIdx = (int)pkg.pkg_idx;
                    }
                    else
                    {
                        pkg.ComponentID += "." + bbidx.ToString();
                        // add constraint relative to first bounding box
                        var pcons = new RelativeConstraint();
                        pcons.type = "relative-pkg";
                        pcons.x = pkg.x;
                        pcons.y = pkg.y;
                        pcons.pkg_idx = origPkgIdx;
                        if (pkg.constraints == null)
                            pkg.constraints = new List<Constraint>();
                        pkg.constraints.Add(pcons);
                    }

                    boardLayout.packages.Add(pkg);
                    bbidx++;
                }
                // TBD SKN figure out relative constraint between multiple bboxes
            }
            foreach (var ca in obj.ComponentAssemblyInstances)
            {
                pkg_idx = HandlePreRoutedAsm(ca, pkg_idx);
            }
            return pkg_idx;
        }
コード例 #24
0
        public override void visit(ComponentAssembly obj)
        {
            if (CodeGenerator.verbose) CodeGenerator.GMEConsole.Info.WriteLine("CyPhyBuildVisitor::visit ComponentAssembly: {0}", obj.Name);

            var ca = obj.Impl;

            // ------- ComponentAssemblies -------
            foreach (var innerComponentAssembly in ca.Children.ComponentAssemblyCollection)
            {
                var innerComponentAssembly_obj = new ComponentAssembly(innerComponentAssembly)
                {
                    Parent = obj,
                };
                obj.ComponentAssemblyInstances.Add(innerComponentAssembly_obj);
            }

            // ------- Components -------
            Component component_obj;
            foreach (var component in ca.Children.ComponentCollection)
            {
                // heuristics (nasty lookahead), will need to handle this properly with changes in CyPhyML
                var SystemCModel = component.Children.SystemCModelCollection.FirstOrDefault();
                if (SystemCModel != null && !String.IsNullOrWhiteSpace(SystemCModel.Attributes.ModuleName) &&
                            SystemCModel.Attributes.ModuleName.ToLower().StartsWith("arduino"))
                {
                    component_obj = new ArduinoComponent(component)
                    {
                        Parent = obj,
                    };
                }
                else
                {
                    component_obj = new Component(component)
                    {
                        Parent = obj,
                    };
                }

                obj.ComponentInstances.Add(component_obj);
                CyPhyBuildVisitor.Components.Add(component.ID, component_obj);   // Add to global component list, are these instance ID-s or component type ID-s?
            }

        }