Esempio n. 1
0
        public CAD.AssembliesType ToCADXMLOutput(TestBenchModel.TestBenchBase tb, bool metalink = false)
        {
            CAD.AssembliesType outputAssembliesType = new CAD.AssembliesType();
            outputAssembliesType.VersionInfo = "";

            List<CAD.AssemblyType> asmlist = new List<CAD.AssemblyType>();
            foreach (var item in assemblies.Values)
            {
                CAD.AssemblyType assembly = item.ToCADXMLOutput(tb);
                asmlist.Add(assembly);
                pointCoordinatesList.AddRange(item.PointCoordinatesList);
            }

            if (asmlist.Count > 1 && metalink)
            {
                Logger.Instance.AddLogMessage("There's more than one unconnected assembly in the model. Meta-Link may not work with this model.", Severity.Warning);
            }

            if (orphans.Any())
            {
                if (metalink)
                {
                    CAD.AssemblyType topAssembly = asmlist.First();
                    List<CAD.CADComponentType> cadcomponentlist = topAssembly.CADComponent.CADComponent.ToList();
                    foreach (var orphan in orphans)
                    {
                        cadcomponentlist.Add(orphan.ToCADXMLOutput(tb.GetRepresentation(orphan)));
                    }
                    topAssembly.CADComponent.CADComponent = cadcomponentlist.ToArray();
                }
                else
                {
                    List<CAD.CADComponentType> orphanlist = new List<CAD.CADComponentType>();
                    CAD.UnassembledComponentsType orphancomponentParent = new CAD.UnassembledComponentsType();
                    orphancomponentParent._id = UtilityHelpers.MakeUdmID();

                    foreach (var orphan in orphans)
                    {
                        orphanlist.Add(orphan.ToCADXMLOutput(tb.GetRepresentation(orphan)));
                    }
                    orphancomponentParent.CADComponent = orphanlist.ToArray();
                    outputAssembliesType.UnassembledComponents = orphancomponentParent;
                }
            }

            outputAssembliesType.Assembly = asmlist.ToArray();

            return outputAssembliesType;
        }
        public CAD.AssemblyType ToCADXMLOutput(TestBenchModel.TestBenchBase tb)
        {
            CAD.AssemblyType cadassemblyoutput = new CAD.AssemblyType();
            cadassemblyoutput._id = UtilityHelpers.MakeUdmID();
            cadassemblyoutput.ConfigurationID = ConfigID;

            CAD.CADComponentType cadassemblycomponentoutput = new CAD.CADComponentType();
            cadassemblycomponentoutput._id = UtilityHelpers.MakeUdmID();
            cadassemblycomponentoutput.ComponentID = ConfigID;
            cadassemblycomponentoutput.Type = "ASSEMBLY";
            cadassemblycomponentoutput.Standalone = false;
            cadassemblycomponentoutput.SpecialInstruction = "";
            cadassemblycomponentoutput.Name = this.Name;
            cadassemblycomponentoutput.DisplayName = DisplayName;
            cadassemblycomponentoutput.MaterialID = "";
            cadassemblycomponentoutput.Representation = "";
            cadassemblycomponentoutput.Classification = "";

            
            Dictionary<string, List<CAD.ConstraintType>> compidToConstraint = new Dictionary<string, List<CAD.ConstraintType>>();       // Dictionary<Id, List<Constraints>>
            var sortedEdges = ChildEdges.OrderBy(x => x.DstPortName).ToList();
            foreach (CADEdge edge in sortedEdges)        //foreach (CADEdge edge in ChildEdges)
            {
                CAD.ConstraintType constraintout = edge.ToCADXMLOutput(tb);
                if (!compidToConstraint.ContainsKey(edge.Dst.Id))
                {
                    compidToConstraint.Add(edge.Dst.Id, new List<CAD.ConstraintType>());
                }
                compidToConstraint[edge.Dst.Id].Add(constraintout);
            }

            var sortedS2FEdges = ChildSize2FitEdges.OrderBy(x => x.DstPortName).ToList();
            foreach (CADEdge edge in sortedS2FEdges)        //foreach (CADEdge edge in ChildSize2FitEdges)
            {
                CAD.ConstraintType constraintout = edge.ToCADXMLOutput(tb);
                if (!compidToConstraint.ContainsKey(edge.Dst.Id))
                {
                    compidToConstraint.Add(edge.Dst.Id, new List<CAD.ConstraintType>());
                }
                compidToConstraint[edge.Dst.Id].Add(constraintout);
            }

            // META-2885
            //Dictionary<string, CAD.CADComponentType> tmpComponents = new Dictionary<string, CAD.CADComponentType>();
            List<CAD.CADComponentType> tmpComponents = new List<CAD.CADComponentType>();
            var sortedComponents = ChildComponents.OrderBy(x => x.Value.Name).ToDictionary(x => x.Key, x => x.Value).Values.ToList();
            foreach (CADComponent component in sortedComponents)      //foreach (CADComponent component in ChildComponents.Values)
            {
                CAD.CADComponentType componentout = component.ToCADXMLOutput(tb.GetRepresentation(component));

                // root constraint
                if (component.Id == RootComponentID)
                {
                    bool rootIsAsmType = component.ModelType == "Assembly";     //bool rootIsAsmType = component.ModelType == "PART";
                    List<CAD.PairType> pairlist = new List<CAD.PairType>();
                    CAD.ConstraintType rootconstraintout = new CAD.ConstraintType();
                    rootconstraintout._id = UtilityHelpers.MakeUdmID();

                    // front pair
                    pairlist.Add(MakeRootConstraint("FRONT",
                                                    component.DisplayID,
                                                    ConfigID,
                                                    rootIsAsmType));

                    // top pair
                    pairlist.Add(MakeRootConstraint("TOP",
                                                    component.DisplayID,
                                                    ConfigID,
                                                    rootIsAsmType));

                    // right pair
                    pairlist.Add(MakeRootConstraint("RIGHT",
                                                    component.DisplayID,
                                                    ConfigID,
                                                    rootIsAsmType));

                    rootconstraintout.Pair = pairlist.ToArray();

                    componentout.Constraint = new CAD.ConstraintType[1];
                    componentout.Constraint[0] = rootconstraintout;
                }
                else
                {
                    if (compidToConstraint.ContainsKey(component.Id))
                    {
                        componentout.Constraint = compidToConstraint[component.Id].ToArray();
                    }
                }

                //tmpComponents[component.Id] = componentout;
                tmpComponents.Add(componentout);

            }
            
            var size2fitCompSorted = ChildSize2FitComponents.OrderBy(x => x.Value.Name).ToDictionary(x => x.Key, x => x.Value).Values.ToList();
            foreach (CADComponent component in size2fitCompSorted)//foreach (CADComponent component in ChildSize2FitComponents.Values)      // META-2885
            {
                CAD.CADComponentType componentout = component.ToCADXMLOutput(tb.GetRepresentation(component));
                if (compidToConstraint.ContainsKey(component.Id))
                {
                    componentout.Constraint = compidToConstraint[component.Id].ToArray();
                }

                //tmpComponents[component.Id] = componentout;
                tmpComponents.Add(componentout);
            }

            // Fill MetaLinkData. Only needed in case if data is prepared for Meta-Link communication
            if (MetaLinkData != null && MetaLinkData.Components.Count>0)
            {
                cadassemblyoutput.MetaLinkData = new CAD.MetaLinkDataType();
                cadassemblyoutput.MetaLinkData.CadComponentMLData = new CAD.CadComponentMLDataType[MetaLinkData.Components.Count];
                int i  = 0;
                foreach (MetaLinkData.Component comp in MetaLinkData.Components)
                {
                    cadassemblyoutput.MetaLinkData.CadComponentMLData[i] = new CAD.CadComponentMLDataType();
                    cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ID = comp.ID;
                    cadassemblyoutput.MetaLinkData.CadComponentMLData[i].AvmID = comp.AvmID;
                    if (comp.Connectors.Count>0)
                    {
                        cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ConnectorMLData = new CAD.ConnectorMLDataType[comp.Connectors.Count];
                        int j = 0;
                        foreach (MetaLinkData.Connector conn in comp.Connectors)
                        {
                            cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ConnectorMLData[j] = new CAD.ConnectorMLDataType();
                            cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ConnectorMLData[j].ID = conn.ID;
                            cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ConnectorMLData[j].DisplayName = conn.DisplayName;
                            if (conn.Datums.Count > 0)
                            {
                                cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ConnectorMLData[j].DatumMLData = new CAD.DatumMLDataType[conn.Datums.Count];
                                int k = 0;
                                foreach (MetaLinkData.Datum d in conn.Datums)
                                {
                                    cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ConnectorMLData[j].DatumMLData[k] = new CAD.DatumMLDataType();
                                    cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ConnectorMLData[j].DatumMLData[k].ID = d.ID;
                                    cadassemblyoutput.MetaLinkData.CadComponentMLData[i].ConnectorMLData[j].DatumMLData[k].DisplayName = d.DisplayName;
                                    k++;
                                }
                            }
                            j++;
                        }
                    }
                    i++;
                }
            }

            cadassemblycomponentoutput.CADComponent = tmpComponents.ToArray();       //cadassemblycomponentoutput.CADComponent = tmpComponents.Values.ToArray();
            cadassemblyoutput.CADComponent = cadassemblycomponentoutput;

            CAD.PropertiesType asmproperties = new CAD.PropertiesType();
            asmproperties._id = UtilityHelpers.MakeUdmID();
            CAD.UnitsType asmunit = new CAD.UnitsType();
            asmunit._id = UtilityHelpers.MakeUdmID();
            asmunit.Value = "value1";
            asmproperties.Units = asmunit;
            cadassemblyoutput.Properties = asmproperties;
            return cadassemblyoutput;
        }
        public CAD.ConstraintType ToCADXMLOutput(TestBenchModel.TestBenchBase testBenchBase)
        {
            CAD.ConstraintType constraintout = new CAD.ConstraintType();
            constraintout._id = UtilityHelpers.MakeUdmID();
            CADComponent src = Src as CADComponent;
            CADComponent dst = Dst as CADComponent;

            string srcid = src.DisplayID;
            string dstid = dst.DisplayID;

            if (ConstraintPairs.Any())
            {
                List<CAD.PairType> pairlist = new List<CAD.PairType>();

                foreach (var item in ConstraintPairs)
                {
                    List<CAD.ConstraintFeatureType> constrainfeaturelist = new List<CAD.ConstraintFeatureType>();
                    CAD.PairType pair = new CAD.PairType();
                    pair._id = UtilityHelpers.MakeUdmID();
                    pair.FeatureAlignmentType = item.Item1.Alignment;
                    pair.FeatureGeometryType = item.Item1.Type.ToString().ToUpper();
                    pair.FeatureInterfaceType = "CAD_DATUM";
                    if (item.Item1.Guide || item.Item2.Guide)
                    {
                        pair.Guide = "True";
                    }
                    
                    CAD.ConstraintFeatureType afeature = new CAD.ConstraintFeatureType();
                    afeature._id = UtilityHelpers.MakeUdmID();
                    afeature.ComponentID = item.Item1.ComponentID;
                    afeature.FeatureName = item.Item1.DatumName;
                    afeature.FeatureOrientationType = item.Item1.Orientation;
                    if (item.Item1.Marker != null)
                    {
                        afeature.GeometryMarker = item.Item1.Marker.ToCADXml();
                    }

                    CAD.ConstraintFeatureType bfeature = new CAD.ConstraintFeatureType();
                    bfeature._id = UtilityHelpers.MakeUdmID();
                    bfeature.ComponentID = item.Item2.ComponentID;
                    bfeature.FeatureName = item.Item2.DatumName;
                    bfeature.FeatureOrientationType = item.Item2.Orientation;
                    if (item.Item2.Marker != null)
                    {
                        bfeature.GeometryMarker = item.Item2.Marker.ToCADXml();
                    }

                    constrainfeaturelist.Add(afeature);
                    constrainfeaturelist.Add(bfeature);
                    pair.ConstraintFeature = constrainfeaturelist.ToArray();
                    pairlist.Add(pair);

                }
                constraintout.Pair = pairlist.ToArray();

                // META-3124
                if (KinematicJointPair != null)
                {
                   constraintout.Joint = KinematicJointPair.ToCADXMLOutput();
                }

                // Associated geomnetries
                List<CAD.GeometryType> geoms = new List<CAD.GeometryType>();
                foreach (var geom in SrcIntf.Geometry.Union(DstIntf.Geometry))
                {
                    geoms.Add(geom.ToCADXMLOutput());
                }
                constraintout.Geometry = geoms.ToArray();

                // Adjoining surface treatment (if any)
                if (testBenchBase is TestBenchModel.FEATestBench)
                {
                    string surftreatment = GetAdjoiningSurfaceTreatment(testBenchBase as TestBenchModel.FEATestBench);
                    constraintout.AdjoiningSurfaceType = surftreatment;
                }
            }


            return constraintout;
        }
 private string GetAdjoiningSurfaceTreatment(TestBenchModel.FEATestBench testBench)
 {
     CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum src = CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Testbench_Default;
     CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum dst = CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Testbench_Default;
     bool srcset = false;
     bool dstset = false;
     // Are the 2 settings compatible?
     if (SrcIntf.AdjSurfTreatment.HasValue)
     {
         srcset = true;
         src = CombineAdjoiningValue(SrcIntf.AdjSurfTreatment.Value, testBench);
     }
     if (DstIntf.AdjSurfTreatment.HasValue)
     {
         dstset = true;
         dst = CombineAdjoiningValue(DstIntf.AdjSurfTreatment.Value, testBench);
     }
     if (srcset && dstset)
     {
         if (src != dst)
         {
             Logger.Instance.AddLogMessage("Conflicting adjoning surface settings. Component A: " + SrcIntf.CyPhyImpl.ToHyperLink() + ", Type: " + src.ToString() + "; Component B: " + DstIntf.CyPhyImpl.ToHyperLink() + ", Type: " + dst.ToString(), Severity.Error);
             return null;
         }
         else
         {
             return AdjoiningEnumToCADString(src);
         }
     }
     else if (srcset && !dstset)
     {
         return AdjoiningEnumToCADString(src);
     }
     else if (!srcset && dstset)
     {
         return AdjoiningEnumToCADString(dst);
     }
     else
     {
         switch (testBench.AdjSurfTreatment)
         {
             case CyPhyClasses.CADTestBench.AttributesClass.AdjoiningTreatment_enum.Bonded:
                 return AdjoiningEnumToCADString(CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Bonded);
             case CyPhyClasses.CADTestBench.AttributesClass.AdjoiningTreatment_enum.Contacted:
                 return AdjoiningEnumToCADString(CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Contacted);
             case CyPhyClasses.CADTestBench.AttributesClass.AdjoiningTreatment_enum.Free:
                 return AdjoiningEnumToCADString(CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Free);
             case CyPhyClasses.CADTestBench.AttributesClass.AdjoiningTreatment_enum.Joint_Implied:
                 return AdjoiningEnumToCADString(SrcIntf.ImliedSurfTreatment);
         }
     }
     // Shouldn't get here
     return null;
 }
 private CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum CombineAdjoiningValue(CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum input, TestBenchModel.FEATestBench testBench)
 {
     switch (input)
     {
         case CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Testbench_Default:
             switch (testBench.AdjSurfTreatment)
             {
                 case CyPhyClasses.CADTestBench.AttributesClass.AdjoiningTreatment_enum.Bonded:
                     return CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Bonded;
                 case CyPhyClasses.CADTestBench.AttributesClass.AdjoiningTreatment_enum.Contacted:
                     return CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Contacted;
                 case CyPhyClasses.CADTestBench.AttributesClass.AdjoiningTreatment_enum.Free:
                     return CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Free;
                 case CyPhyClasses.CADTestBench.AttributesClass.AdjoiningTreatment_enum.Joint_Implied:
                     return SrcIntf.ImliedSurfTreatment;
             }
             break;
         case CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Joint_Implied:
             return SrcIntf.ImliedSurfTreatment;
         case CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Bonded:
             return CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Bonded;
         case CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Contacted:
             return CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Contacted;
         case CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Free:
             return CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Free;
     }
     // Shouldn't get here
     return CyPhyClasses.AdjoiningSurfacesTreatment.AttributesClass.Type_enum.Free;
 }