コード例 #1
0
        public override void TraverseTestBench(CyPhy.TestBenchType testBenchBase)
        {
            CyPhy.KinematicTestBench testBench = testBenchBase as CyPhy.KinematicTestBench;
            if (testBench == null)
            {
                testBench = CyPhyClasses.KinematicTestBench.Cast(testBenchBase.Impl);
            }

            base.TraverseTestBench(testBenchBase);

            //NonSTEP_DataExchangeFormats.Add("Parasolid");

            Name           = testBench.Name;
            SimulationStep = testBench.Attributes.SimulationResolution;
            SimulationTime = testBench.Attributes.Duration;

            if (testBench.Children.GravityLoadCollection.Any())
            {
                CyPhy.GravityLoad load = testBench.Children.GravityLoadCollection.First();
                double            x    = 0;
                double            y    = 0;
                double            z    = 0;

                GetGravityLoadParam(load, "X", out x);
                GetGravityLoadParam(load, "Y", out y);
                GetGravityLoadParam(load, "Z", out z);
                Gravity = new KinematicGravity(x, y, z, load.Attributes.Active);
            }

            var terrain = testBench.Children.ComponentRefCollection.Where(c => ((MgaFCO)c.Impl).MetaRole.Name == "Terrain");

            if (terrain.Any())
            {
                CyPhy.Component terraincomp = terrain.First().AllReferred as CyPhy.Component;
                if (terraincomp == null)
                {
                    Logger.Instance.AddLogMessage("Terrain component reference must refer to a cyphy component.", Severity.Error);
                    return;
                }
                if (!terraincomp.Children.CADModelCollection.Any())
                {
                    Logger.Instance.AddLogMessage("Terrain component must contain a CAD model.", Severity.Error);
                    return;
                }
                TerrainFileName = terraincomp.Children.ResourceCollection.First().Attributes.Path;
                try
                {
                    File.Copy(Path.Combine(terraincomp.GetDirectoryPath(), TerrainFileName), Path.Combine(OutputDirectory, Path.GetFileName(TerrainFileName)));
                }
                catch (Exception e)
                {
                    Logger.Instance.AddLogMessage("Unable to copy terrain file: " + e.Message, Severity.Warning);
                }
                TerrainFileName = Path.GetFileNameWithoutExtension(TerrainFileName);
            }
            else
            {
                if (testBench.Children.AnchorCollection.Any())
                {
                    CyPhy.Anchor anchor    = testBench.Children.AnchorCollection.First();
                    var          pointList = anchor
                                             .DstConnections
                                             .SetAnchorCollection
                                             .Select(x => x.DstEnds.Point)
                                             .Concat(anchor
                                                     .SrcConnections
                                                     .SetAnchorCollection
                                                     .Select(x => x.SrcEnds.Point));

                    if (!pointList.Any())
                    {
                        Logger.Instance.AddLogMessage("Anchor is not connected to a point. Anchor should be connected to a datum point on one of the components.", Severity.Error);
                        return;
                    }

                    var point = pointList.First();
                    PointMetricTraversal traverser = new PointMetricTraversal(point);
                    foreach (var pointFound in traverser.portsFound)
                    {
                        string name        = (pointFound as CyPhy.Point).Attributes.DatumName;
                        string componentID = CyPhyClasses.Component.Cast((pointFound as CyPhy.Point).ParentContainer.ParentContainer.Impl).Attributes.InstanceGUID;
                        StaticAnalysisMetrics.Add(new TBComputation()
                        {
                            ComponentID = componentID, Details = name, MetricID = "Anchor", ComputationType = TBComputation.Type.POINTCOORDINATES, RequestedValueType = "Vector"
                        });
                        //Computations.Add(new TBComputation() { ComponentID = componentID, FeatureDatumName = name, MetricID = "Anchor", ComputationType = TBComputation.Type.POINTCOORDINATES, RequestedValueType = "Vector" });
                        GroundCyphyID = componentID;
                    }
                }
                else
                {
                    Logger.Instance.AddLogMessage("Anchor not found. There should be exactly one anchor in the testbench, to specify which body is fixed to the ground in the kinematic simnulation.", Severity.Error);
                    return;
                }
            }

            foreach (var motion in testBench.Children.MotionLoadCollection)
            {
                var connectorList = motion
                                    .SrcConnections
                                    .ApplyMotionToJointCollection
                                    .Select(x => x.SrcEnds.Connector)
                                    .Concat(motion
                                            .DstConnections
                                            .ApplyMotionToJointCollection
                                            .Select(x => x.DstEnds.Connector)
                                            );

                var toplevelSUT = testBench.Children.ComponentAssemblyCollection.FirstOrDefault();

                foreach (var connector in connectorList)
                {
                    OriginatingConnectorTraversal traverser = new OriginatingConnectorTraversal(connector);

                    if (traverser.result != null)
                    {
                        CyPhy.KinematicJoint joint = GetJoint(traverser.result);
                        if (joint != null)
                        {
                            Multibody.ModelLoadsMotion mbdMotion = new Multibody.ModelLoadsMotion();
                            mbdMotion.Active         = (motion.Attributes.Active) ? Multibody.ModelLoadsMotionActive.on : Multibody.ModelLoadsMotionActive.off;
                            mbdMotion.FreedomType    = (Multibody.ModelLoadsMotionFreedomType)((int)motion.Attributes.JointFreedomType);
                            mbdMotion.Function       = motion.Attributes.CustomFunction;
                            mbdMotion.JointID        = cadDataContainer.GetJointIDFromGMEID(joint.ID);
                            mbdMotion.MotionID       = motion.Name;
                            mbdMotion.TimeDerivative = (Multibody.ModelLoadsMotionTimeDerivative)((int)motion.Attributes.TimeDerivative);
                            mbdMotion.Type           = "JointMotion";

                            MotionList.Add(mbdMotion);
                        }
                        else
                        {
                            Logger.Instance.AddLogMessage("Kinematic motion is connected to a connector without joint information: " + connector.ToHyperLink(), Severity.Error);
                        }
                    }
                }
            }

            if (testBench.Children.AdamsScriptCollection.Any())
            {
                Scripts = new List <Multibody.ModelScript>();
                foreach (var script in testBench.Children.AdamsScriptCollection)
                {
                    Scripts.Add(new Multibody.ModelScript()
                    {
                        Path = script.Attributes.Path
                    });
                }
            }

            ProcessContacts(testBench);
        }
コード例 #2
0
        private void ProcessContacts(CyPhy.KinematicTestBench testBench)
        {
            List <Multibody.ModelContact> contactlist = new List <Multibody.ModelContact>();
            string cyphyid1, cyphyid2;

            foreach (CyPhy.Contact contact in testBench.Children.ContactCollection)
            {
                CyPhy.ComponentRef terrain = null;
                var tip1 = contact.SrcEnds.TestInjectionPoint;
                if (tip1 == null)
                {
                    terrain = contact.SrcEnds.ComponentRef;
                }
                var tip2 = contact.DstEnds.TestInjectionPoint;
                if (tip2 == null)
                {
                    terrain = contact.SrcEnds.ComponentRef;
                }
                if (terrain != null)
                {
                    var tip = tip1 == null ? tip2 : tip1;
                    if (tip.AllReferred == null)
                    {
                        Logger.Instance.AddLogMessage("TIP doesn't refer anything: " + tip.Path, Severity.Error);
                        continue;
                    }
                    if (!(tip.AllReferred is CyPhy.Component))
                    {
                        Logger.Instance.AddLogMessage("TIPs participating in contacts can only refer components: " + tip.Path, Severity.Error);
                        continue;
                    }
                    cyphyid1 = (tip.AllReferred as CyPhy.Component).Attributes.InstanceGUID;
                    cyphyid2 = "TERRAIN";
                }
                else
                {
                    if (tip1.AllReferred == null)
                    {
                        Logger.Instance.AddLogMessage("TIP doesn't refer anything: " + tip1.Path, Severity.Error);
                        continue;
                    }
                    if (tip2.AllReferred == null)
                    {
                        Logger.Instance.AddLogMessage("TIP doesn't refer anything: " + tip2.Path, Severity.Error);
                        continue;
                    }
                    if (!(tip1.AllReferred is CyPhy.Component))
                    {
                        Logger.Instance.AddLogMessage("TIPs participating in contacts can only refer components: " + tip1.Path, Severity.Error);
                        continue;
                    }
                    if (!(tip2.AllReferred is CyPhy.Component))
                    {
                        Logger.Instance.AddLogMessage("TIPs participating in contacts can only refer components: " + tip2.Path, Severity.Error);
                        continue;
                    }
                    cyphyid1 = (tip1.AllReferred as CyPhy.Component).Attributes.InstanceGUID;
                    cyphyid2 = (tip2.AllReferred as CyPhy.Component).Attributes.InstanceGUID;
                }
                contactlist.Add(new Multibody.ModelContact()
                {
                    CyphyId1 = cyphyid1, CyphyId2 = cyphyid2
                });
            }
            if (contactlist.Count > 0)
            {
                ContactList = contactlist;
            }
        }