示例#1
0
        private static bool AddExtrusion(CyPhy.Extrusion extrusion, List <KeyValuePair <string, string> > featureList)           // only extrusion with polygon is supported
        {
            if (extrusion.Children.PolygonCollection.Any())
            {
                CyPhy.Polygon polygon = extrusion.Children.PolygonCollection.FirstOrDefault();
                if (polygon != null)
                {
                    AddPolygon(polygon,
                               featureList);
                    List <MgaFCO> height = FindByRole((extrusion.Impl as MgaModel), "ExtrusionHeight");
                    if (height.Count < 1)
                    {
                        Logger.Instance.AddLogMessage(String.Format("Extrusion geometry must contain exactly 1 ExtrusionHeight point: {0}", extrusion.ToHyperLink()), Severity.Error);
                        return(false);
                    }

                    CyPhy.Point offset = CyPhyClasses.Point.Cast(height[0]);
                    if (CreateFeatureFromPoint(offset,
                                               featureList))
                    {
                        return(true);
                    }
                    else
                    {
                        Logger.Instance.AddLogMessage(String.Format("Extrusion geometry's ExtrusionHeight must connect to a Point datum inside a CADModel: {0}", extrusion.ToHyperLink()), Severity.Error);
                        return(false);
                    }
                }
            }

            return(false);
        }
示例#2
0
        private void TraverseComposites(CyPhy.Component component)
        {
            foreach (var material in component.Children.MaterialContentsCollection)
            {
                CAD.ElementType cadElement = new CAD.ElementType()
                {
                    _id          = UtilityHelpers.MakeUdmID(),
                    ElementType1 = "SURFACE"
                };

                MgaModel      materialMga = material.Impl as MgaModel;
                List <MgaFCO> startDirPts = new List <MgaFCO>();
                List <MgaFCO> endDirPts   = new List <MgaFCO>();

                startDirPts = CyPhy2CAD_CSharp.DataRep.CADGeometry.FindByRole(materialMga, "Start_Direction");
                endDirPts   = CyPhy2CAD_CSharp.DataRep.CADGeometry.FindByRole(materialMga, "End_Direction");

                if (startDirPts.Count != 1 && endDirPts.Count != 1)
                {
                    Logger.Instance.AddLogMessage("Material Content must contain one Start_Direction and one End_Direction point.", Severity.Warning);
                    continue;
                }


                CyPhy.Point startDirPt          = CyPhyClasses.Point.Cast(startDirPts[0]);
                string      startDirPtDatumName = GetFeatureName(startDirPt);

                CyPhy.Point endDirPt          = CyPhyClasses.Point.Cast(endDirPts[0]);
                string      endDirPtDatumName = GetFeatureName(endDirPt);

                CAD.OrientationType cadOrientation = new CAD.OrientationType()
                {
                    _id = UtilityHelpers.MakeUdmID()
                };
                CAD.GeometryType cadGeometry = new CAD.GeometryType()
                {
                    _id = UtilityHelpers.MakeUdmID()
                };


                CAD.FeatureType cadStartFeature = new CAD.FeatureType()
                {
                    _id         = UtilityHelpers.MakeUdmID(),
                    ComponentID = DisplayID,
                    Name        = startDirPtDatumName,
                    MetricID    = DisplayID + ":" + startDirPtDatumName
                };
                TestBenchModel.TBComputation startFeatureComputation = new TestBenchModel.TBComputation()
                {
                    ComponentID        = DisplayID,
                    ComputationType    = TestBenchModel.TBComputation.Type.POINTCOORDINATES,
                    Details            = startDirPtDatumName,
                    FeatureDatumName   = startDirPtDatumName,
                    MetricID           = DisplayID + ":" + startDirPtDatumName,
                    RequestedValueType = "Vector"
                };
                pointCoordinatesList.Add(startFeatureComputation);
                if (String.IsNullOrEmpty(startDirPtDatumName))
                {
                    Logger.Instance.AddLogMessage("Empty point datum name [" + startDirPt.Path + "]", Severity.Warning);
                }

                CAD.FeatureType cadEndFeature = new CAD.FeatureType()
                {
                    _id         = UtilityHelpers.MakeUdmID(),
                    ComponentID = DisplayID,
                    Name        = endDirPtDatumName,
                    MetricID    = DisplayID + ":" + endDirPtDatumName
                };
                TestBenchModel.TBComputation endFeatureComputation = new TestBenchModel.TBComputation()
                {
                    ComponentID        = DisplayID,
                    ComputationType    = TestBenchModel.TBComputation.Type.POINTCOORDINATES,
                    Details            = endDirPtDatumName,
                    FeatureDatumName   = endDirPtDatumName,
                    MetricID           = DisplayID + ":" + endDirPtDatumName,
                    RequestedValueType = "Vector"
                };
                pointCoordinatesList.Add(endFeatureComputation);
                if (String.IsNullOrEmpty(endDirPtDatumName))
                {
                    Logger.Instance.AddLogMessage("Empty point datum name [" + endDirPt.Path + "]", Severity.Warning);
                }

                CAD.FeaturesType cadFeatures = new CAD.FeaturesType()
                {
                    _id                        = UtilityHelpers.MakeUdmID(),
                    FeatureID                  = material.ID,
                    GeometryType               = "Vector",
                    FeatureInterfaceType       = "CAD_DATUM",
                    FeatureGeometryType        = "POINT",
                    PrimaryGeometryQualifier   = "",
                    SecondaryGeometryQualifier = ""
                };

                cadFeatures.Feature     = new CAD.FeatureType[2];
                cadFeatures.Feature[0]  = cadStartFeature;
                cadFeatures.Feature[1]  = cadEndFeature;
                cadGeometry.Features    = new CAD.FeaturesType[1];
                cadGeometry.Features[0] = cadFeatures;
                cadOrientation.Geometry = cadGeometry;


                // Material Layups
                CAD.MaterialLayupType cadLayers = new CAD.MaterialLayupType()
                {
                    _id       = UtilityHelpers.MakeUdmID(),
                    Position  = material.Attributes.Position.ToString().ToUpper(),
                    Offset    = (material.Attributes.Position.ToString().ToUpper() != "OFFSET_BY_VALUE") ? 0 : (material.Attributes.PositionOffset),
                    Direction = material.Attributes.MaterialLayupDirection.ToString().ToUpper()
                };

                int layerCnt = material.Children.MaterialLayerCollection.Count();
                if (layerCnt > 0)
                {
                    cadLayers.Layer = new CAD.LayerType[layerCnt];

                    int k = 0;
                    foreach (var layer in material.Children.MaterialLayerCollection.OrderBy(i => i.Attributes.LayerID))
                    {
                        CAD.LayerType cadLayer = new CAD.LayerType()
                        {
                            _id           = UtilityHelpers.MakeUdmID(),
                            ID            = layer.Attributes.LayerID,
                            Drop_Order    = layer.Attributes.DropOrder,
                            Material_Name = layer.Attributes.LayerMaterial,
                            Orientation   = layer.Attributes.LayerOrientation,
                            Thickness     = layer.Attributes.LayerThickness
                        };

                        cadLayers.Layer[k] = cadLayer;
                        k++;
                    }
                }

                CAD.ElementContentsType cadElementContents = new CAD.ElementContentsType();
                cadElementContents._id           = UtilityHelpers.MakeUdmID();
                cadElementContents.Orientation   = cadOrientation;
                cadElementContents.MaterialLayup = cadLayers;
                cadElement.ElementContents       = cadElementContents;


                if (material.DstConnections.ContentsToGeometryCollection.Count() < 1 || material.DstConnections.ContentsToGeometryCollection.Count() > 1)
                {
                    Logger.Instance.AddLogMessage("Material Content need to connect to one Face geometry.", Severity.Warning);
                    continue;
                }


                // Face, Polygon, or Extrusion Geometry
                CyPhy.ContentsToGeometry conn = material.DstConnections.ContentsToGeometryCollection.FirstOrDefault();
                if (conn != null)
                {
                    CyPhy.Face      faceGeometry      = conn.DstEnds.Face;
                    CyPhy.Polygon   polgonGeometry    = conn.DstEnds.Polygon;
                    CyPhy.Extrusion extrusionGeometry = conn.DstEnds.Extrusion;


                    int countGeometryTypes = 0;

                    if (faceGeometry != null)
                    {
                        ++countGeometryTypes;
                    }
                    if (polgonGeometry != null)
                    {
                        ++countGeometryTypes;
                    }
                    if (extrusionGeometry != null)
                    {
                        ++countGeometryTypes;
                    }

                    if (countGeometryTypes != 1)
                    {
                        Logger.Instance.AddLogMessage("MaterialContents must be connected to one and only one geometry type (i.e. FACE, POLOGON, or EXTRUSION).", Severity.Warning);
                        continue;
                    }


                    // Approach when only FACE was supported
                    //String primBoundaryQ = faceGeometry.Attributes.BoundaryQualifier.ToString().Replace("_", string.Empty);
                    //MgaModel faceMga = faceGeometry.Impl as MgaModel;
                    //List<MgaFCO> normalDirPts = new List<MgaFCO>();
                    //normalDirPts = CyPhy2CAD_CSharp.DataRep.CADGeometry.FindByRole(faceMga, "Direction_Reference_Point");

                    String        primBoundaryQ = "";
                    MgaModel      faceMga;
                    List <MgaFCO> normalDirPts = new List <MgaFCO>();

                    if (faceGeometry != null)
                    {
                        primBoundaryQ = faceGeometry.Attributes.BoundaryQualifier.ToString().Replace("_", string.Empty);
                        faceMga       = faceGeometry.Impl as MgaModel;
                        normalDirPts  = CyPhy2CAD_CSharp.DataRep.CADGeometry.FindByRole(faceMga, "Direction_Reference_Point");
                    }
                    else if (polgonGeometry != null)
                    {
                        primBoundaryQ = polgonGeometry.Attributes.BoundaryQualifier.ToString().Replace("_", string.Empty);
                        faceMga       = polgonGeometry.Impl as MgaModel;
                        normalDirPts  = CyPhy2CAD_CSharp.DataRep.CADGeometry.FindByRole(faceMga, "Direction_Reference_Point");
                    }
                    else if (extrusionGeometry != null)
                    {
                        primBoundaryQ = extrusionGeometry.Attributes.BoundaryQualifier.ToString().Replace("_", string.Empty);
                        faceMga       = extrusionGeometry.Impl as MgaModel;
                        normalDirPts  = CyPhy2CAD_CSharp.DataRep.CADGeometry.FindByRole(faceMga, "Direction_Reference_Point");
                    }

                    if (normalDirPts.Count != 1)
                    {
                        Logger.Instance.AddLogMessage("Geometry (FACE, POLYGON, or EXTRUSION) can contain only one Direction_Reference_Point point.", Severity.Warning);
                        continue;
                    }

                    CyPhy.Point normalDirPt         = CyPhyClasses.Point.Cast(normalDirPts.FirstOrDefault());
                    string      normalPtFeatureName = GetFeatureName(normalDirPt);
                    if (String.IsNullOrEmpty(normalPtFeatureName))
                    {
                        Logger.Instance.AddLogMessage("Direction_Reference_Point point of the Face/Ploygon/Extrusion geometry doesn't have a datum name. Make sure it is connected to a valid point inside a CADModel.", Severity.Warning);
                        continue;
                    }

                    CyPhy2CAD_CSharp.DataRep.CADGeometry faceOrExtruOrPolyGeometryRep = null;
                    if (faceGeometry != null)
                    {
                        faceOrExtruOrPolyGeometryRep = CyPhy2CAD_CSharp.DataRep.CADGeometry.CreateGeometry(faceGeometry);
                        if (faceOrExtruOrPolyGeometryRep == null)
                        {
                            Logger.Instance.AddLogMessage("Unsuccessfully created a representation of a Face Geometry.", Severity.Warning);
                            continue;
                        }
                    }
                    else if (polgonGeometry != null)
                    {
                        faceOrExtruOrPolyGeometryRep = CyPhy2CAD_CSharp.DataRep.CADGeometry.CreateGeometry(polgonGeometry);
                        if (faceOrExtruOrPolyGeometryRep == null)
                        {
                            Logger.Instance.AddLogMessage("Unsuccessfully created a representation of a Polygon Geometry.", Severity.Warning);
                            continue;
                        }
                    }
                    else if (extrusionGeometry != null)
                    {
                        faceOrExtruOrPolyGeometryRep = CyPhy2CAD_CSharp.DataRep.CADGeometry.CreateGeometry(extrusionGeometry);
                        if (faceOrExtruOrPolyGeometryRep == null)
                        {
                            Logger.Instance.AddLogMessage("Unsuccessfully created a representation of a Extrusion Geometry.", Severity.Warning);
                            continue;
                        }
                    }

                    // Element/Geometry
                    CAD.GeometryType cadFaceOrExtruOrPolyGeometryOut = faceOrExtruOrPolyGeometryRep.ToCADXMLOutput();
                    if (cadFaceOrExtruOrPolyGeometryOut == null)
                    {
                        Logger.Instance.AddLogMessage("Unsuccessfully converted a representation of a Face/Ploygon/Extrusion Geometry to CAD xml.", Severity.Warning);
                        continue;
                    }


                    cadElement.Geometry = cadFaceOrExtruOrPolyGeometryOut;
                    foreach (var faceOrExtruOrPolyGeomFeatures in cadFaceOrExtruOrPolyGeometryOut.Features)
                    {
                        foreach (var feature_temp in faceOrExtruOrPolyGeomFeatures.Feature)
                        {
                            TestBenchModel.TBComputation faceGeometryComputation = new TestBenchModel.TBComputation()
                            {
                                ComponentID        = DisplayID,
                                ComputationType    = TestBenchModel.TBComputation.Type.POINTCOORDINATES,
                                Details            = feature_temp.Name,
                                FeatureDatumName   = feature_temp.Name,
                                MetricID           = feature_temp.MetricID,
                                RequestedValueType = "Vector"
                            };
                            pointCoordinatesList.Add(faceGeometryComputation);
                        }
                    }

                    // Element/Geometry

                    string direction_temp = "";

                    if (faceGeometry != null)
                    {
                        direction_temp = (faceGeometry.Attributes.NormalDirection == CyPhyClasses.Face.AttributesClass.NormalDirection_enum.Toward_Reference_Point) ? "TOWARD" : "AWAY";
                    }
                    else if (polgonGeometry != null)
                    {
                        direction_temp = (polgonGeometry.Attributes.NormalDirection == CyPhyClasses.Polygon.AttributesClass.NormalDirection_enum.Toward_Reference_Point) ? "TOWARD" : "AWAY";
                    }
                    else if (extrusionGeometry != null)
                    {
                        direction_temp = (extrusionGeometry.Attributes.NormalDirection == CyPhyClasses.Extrusion.AttributesClass.NormalDirection_enum.Toward_Reference_Point) ? "TOWARD" : "AWAY";
                    }

                    CAD.SurfaceNormalType cadSurfaceNormal = new CAD.SurfaceNormalType()
                    {
                        _id       = UtilityHelpers.MakeUdmID(),
                        Direction = direction_temp
                    };

                    CAD.FeaturesType cadSurfaceNormFeatures = new CAD.FeaturesType()
                    {
                        _id                        = UtilityHelpers.MakeUdmID(),
                        FeatureID                  = normalDirPt.ID,
                        GeometryType               = "POINT",
                        FeatureInterfaceType       = "CAD_DATUM",
                        FeatureGeometryType        = "POINT",
                        Feature                    = new CAD.FeatureType[1],
                        PrimaryGeometryQualifier   = primBoundaryQ,
                        SecondaryGeometryQualifier = ""
                    };

                    cadSurfaceNormFeatures.Feature[0] = new CAD.FeatureType()
                    {
                        _id         = UtilityHelpers.MakeUdmID(),
                        Name        = normalPtFeatureName,
                        ComponentID = DisplayID,
                        MetricID    = DisplayID + ":" + normalPtFeatureName
                    };
                    TestBenchModel.TBComputation surfNormalComputation = new TestBenchModel.TBComputation()
                    {
                        ComponentID        = DisplayID,
                        ComputationType    = TestBenchModel.TBComputation.Type.POINTCOORDINATES,
                        Details            = normalPtFeatureName,
                        FeatureDatumName   = normalPtFeatureName,
                        MetricID           = DisplayID + ":" + normalPtFeatureName,
                        RequestedValueType = "Vector"
                    };
                    pointCoordinatesList.Add(surfNormalComputation);
                    if (String.IsNullOrEmpty(normalPtFeatureName))
                    {
                        Logger.Instance.AddLogMessage("Empty point datum name [" + normalDirPt.Path + "]", Severity.Warning);
                    }

                    CAD.GeometryType cadSurfaceNormGeom = new CAD.GeometryType()
                    {
                        _id      = UtilityHelpers.MakeUdmID(),
                        Features = new CAD.FeaturesType[1],
                    };

                    cadSurfaceNormGeom.Features[0] = cadSurfaceNormFeatures;
                    cadSurfaceNormal.Geometry      = cadSurfaceNormGeom;
                    cadElement.SurfaceNormal       = cadSurfaceNormal;
                }

                this.CadElementsList.Add(cadElement);
            }
        }
示例#3
0
        public static CADGeometry CreateGeometry(CyPhy.GeometryTypes geometryBase)
        {
            List <KeyValuePair <string, string> > featureList = new List <KeyValuePair <string, string> >();
            string      geometryType = geometryBase.Kind;
            CADGeometry geometryRep  = new CADGeometry
            {
                FeatureID        = geometryBase.ID,
                GeometryType     = geometryType.ToUpper(),
                PrimaryQualifier = geometryBase.Attributes.BoundaryQualifier.ToString().Replace("_", string.Empty)
            };

            if (geometryType == "Sphere")
            {
                CyPhy.Sphere sphere = CyPhyClasses.Sphere.Cast(geometryBase.Impl);
                if (AddSphere(sphere, featureList))
                {
                    geometryRep.CreateGeometryFeature(featureList);
                }
                else
                {
                    geometryRep = null;
                }
            }
            else if (geometryType == "Cylinder")
            {
                CyPhy.Cylinder cylinder = CyPhyClasses.Cylinder.Cast(geometryBase.Impl);
                geometryRep.SecondaryQualifier = cylinder.Attributes.EndCapInclusionQualifier.ToString();
                if (AddCylinder(cylinder, featureList))
                {
                    geometryRep.CreateGeometryFeature(featureList);
                }
                else
                {
                    geometryRep = null;
                }
            }
            else if (geometryType == "Extrusion")
            {
                CyPhy.Extrusion extrusion = CyPhyClasses.Extrusion.Cast(geometryBase.Impl);
                if (AddExtrusion(extrusion, featureList))
                {
                    geometryRep.CreateGeometryFeature(featureList);
                }
                else
                {
                    geometryRep = null;
                }
            }
            else if (geometryType == "Polygon")
            {
                CyPhy.Polygon polygon = CyPhyClasses.Polygon.Cast(geometryBase.Impl);
                if (AddPolygon(polygon, featureList))
                {
                    geometryRep.CreateGeometryFeature(featureList);
                }
                else
                {
                    geometryRep = null;
                }
            }
            else if (geometryType == "Circle")
            {
                CyPhy.Circle circle = CyPhyClasses.Circle.Cast(geometryBase.Impl);
                if (AddCircle(circle, featureList))
                {
                    geometryRep.CreateGeometryFeature(featureList);
                }
                else
                {
                    geometryRep = null;
                }
            }
            else if (geometryType == "Face")
            {
                CyPhy.Face face = CyPhyClasses.Face.Cast(geometryBase.Impl);
                CADGeometry.FeatureTypeEnum type;
                if (AddFace(face,
                            featureList,
                            out type))
                {
                    geometryRep.featureType = type;
                    geometryRep.CreateGeometryFeature(featureList);
                }
                else
                {
                    geometryRep = null;
                }
            }
            else
            {
                Logger.Instance.AddLogMessage("Geometry shape not supported [" + geometryType + "]", Severity.Warning);
                geometryRep = null;
            }

            return(geometryRep);
        }