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); }
private static bool AddSphere(CyPhy.Sphere sphere, List <KeyValuePair <string, string> > featureList) { List <MgaFCO> centerPts = new List <MgaFCO>(); centerPts = FindByRole((sphere.Impl as MgaModel), "SphereCenter"); List <MgaFCO> edgePts = new List <MgaFCO>(); edgePts = FindByRole((sphere.Impl as MgaModel), "SphereEdge"); if (centerPts.Count != 1 || edgePts.Count != 1) { Logger.Instance.AddLogMessage(String.Format("Sphere geometry must contain 1 SphereEdge and 1 SphereCenter: {0}", sphere.ToHyperLink()), Severity.Error); return(false); } CyPhy.Point centerPt = CyPhyClasses.Point.Cast(centerPts[0]); if (!CreateFeatureFromPoint(centerPt, featureList)) { Logger.Instance.AddLogMessage(String.Format("Sphere geometry's SphereCenter point must connect to a Point datum inside a CADModel: {0}", sphere.ToHyperLink()), Severity.Error); return(false); } CyPhy.Point edge = CyPhyClasses.Point.Cast(edgePts[0]); if (!CreateFeatureFromPoint(edge, featureList)) { Logger.Instance.AddLogMessage(String.Format("Sphere geometry's SphereEdge point must connect to a Point datum inside a CADModel: {0}", sphere.ToHyperLink()), Severity.Error); return(false); } return(true); }
private static bool AddCylinder(CyPhy.Cylinder cylinder, List <KeyValuePair <string, string> > featureList) { bool status = true; if (cylinder != null) { // start, end, radius MgaModel cylinderMga = cylinder.Impl as MgaModel; List <MgaFCO> startPts = new List <MgaFCO>(); startPts = FindByRole(cylinderMga, "CylinderStart"); List <MgaFCO> endPts = new List <MgaFCO>(); endPts = FindByRole(cylinderMga, "CylinderEnd"); List <MgaFCO> radiusPts = new List <MgaFCO>(); radiusPts = FindByRole(cylinderMga, "CylinderRadius"); if (startPts.Count != 1 || endPts.Count != 1 || radiusPts.Count != 1) { Logger.Instance.AddLogMessage(String.Format("Cylinder geometry must contain 1 CylinderStart, 1 CylinderEnd, and 1 CylinderRadius: {0}", cylinder.ToHyperLink()), Severity.Error); return(false); } CyPhy.Point startPt = CyPhyClasses.Point.Cast(startPts[0]); if (!CreateFeatureFromPoint(startPt, featureList)) { Logger.Instance.AddLogMessage(String.Format("Cylinder geometry's CylinderStart point must connect to a Point datum inside a CADModel: {0}", cylinder.ToHyperLink()), Severity.Error); return(false); } CyPhy.Point endPt = CyPhyClasses.Point.Cast(endPts[0]); if (!CreateFeatureFromPoint(endPt, featureList)) { Logger.Instance.AddLogMessage(String.Format("Cylinder geometry's CylinderEnd point must connect to a Point datum inside a CADModel: {0}", cylinder.ToHyperLink()), Severity.Error); return(false); } CyPhy.Point radiusPt = CyPhyClasses.Point.Cast(radiusPts[0]); if (!CreateFeatureFromPoint(radiusPt, featureList)) { Logger.Instance.AddLogMessage(String.Format("Cylinder geometry's CylinderRadius point must connect to a Point datum inside a CADModel: {0}", cylinder.ToHyperLink()), Severity.Error); return(false); } } else { status = false; } //var height = (extrusion.Impl as MgaModel).ChildFCOs.Cast<MgaFCO>().Where(x => x.MetaRole.Name == "ExtrusionHeight").FirstOrDefault(); return(status); }
private static bool AddCircle(CyPhy.Circle circle, List <KeyValuePair <string, string> > featureList) { bool status = true; List <MgaFCO> edgePts = new List <MgaFCO>(); edgePts = FindByRole((circle.Impl as MgaModel), "CircleEdge"); List <MgaFCO> centerPts = new List <MgaFCO>(); centerPts = FindByRole((circle.Impl as MgaModel), "CircleCenter"); if (centerPts.Count != 1 || edgePts.Count != 2) { Logger.Instance.AddLogMessage(String.Format("Circle geometry must contain 2 CircleEdge and 1 CircleCenter points: {0}", circle.ToHyperLink()), Severity.Error); return(false); } CyPhy.Point centerPt = CyPhyClasses.Point.Cast(centerPts[0]); CyPhy.Point edge1 = CyPhyClasses.Point.Cast(edgePts[0]); CyPhy.Point edge2 = CyPhyClasses.Point.Cast(edgePts[1]); // Should be checked /*if (edge1.Guid.Equals(edge2.Guid)) * { * Logger.Instance.AddLogMessage(String.Format("Circle is defined by equivalend edge points. These 2 points must be different to be able to identify a plane: {0}", circle.ToHyperLink()), Severity.Error); * return false; * }*/ if (!CreateFeatureFromPoint(centerPt, featureList)) { Logger.Instance.AddLogMessage(String.Format("Circle geometry's CircleCenter point must connect to a Point datum inside a CADModel: {0}", circle.ToHyperLink()), Severity.Error); return(false); } if (!CreateFeatureFromPoint(edge1, featureList)) { Logger.Instance.AddLogMessage(String.Format("Circle geometry's CircleEdge point must connect to a Point datum inside a CADModel: {0}", circle.ToHyperLink()), Severity.Error); return(false); } if (!CreateFeatureFromPoint(edge2, featureList)) { Logger.Instance.AddLogMessage(String.Format("Circle geometry's CircleEdge point must connect to a Point datum inside a CADModel: {0}", circle.ToHyperLink()), Severity.Error); return(false); } return(status); }
private static bool AddFace(CyPhy.Face face, List <KeyValuePair <string, string> > featureList, out CADGeometry.FeatureTypeEnum type) { List <MgaFCO> referencePts = new List <MgaFCO>(); referencePts = FindByRole(face.Impl as MgaModel, "ReferencePoint"); int ptCnt = referencePts.Count(); int surfCnt = face.Children.SurfaceCollection.Count(); type = CADGeometry.FeatureTypeEnum.POINT; if ((ptCnt + surfCnt) > 1) { // insert error message Logger.Instance.AddLogMessage(String.Format("Face geometry must contain a ReferencePoint or a ReferenceSurface: {0}", face.ToHyperLink()), Severity.Error); return(false); } if (ptCnt > 0) // Plane { type = CADGeometry.FeatureTypeEnum.POINT; CyPhy.Point point = CyPhyClasses.Point.Cast(referencePts.First()); if (CreateFeatureFromPoint(point, featureList)) { return(true); } else { Logger.Instance.AddLogMessage(String.Format("Face geometry's ReferencePoint must connect to a Point datum inside a CADModel: {0}", face.ToHyperLink()), Severity.Error); return(false); } } if (surfCnt > 0) // Surface { type = CADGeometry.FeatureTypeEnum.SURFACE; CyPhy.Surface surface = face.Children.SurfaceCollection.First(); if (CreateFeatureFromPoint(surface, featureList)) { return(true); } else { Logger.Instance.AddLogMessage(String.Format("Face geometry's ReferenceSurface must connect to a Surface datum inside a CADModel: {0}", face.ToHyperLink()), Severity.Error); return(false); } } return(false); }
private void CreatePointCoordinatesList(CyPhy.Component component) { CyPhy.CADModel cadmodel = component.Children.CADModelCollection.FirstOrDefault(x => x.Attributes.FileFormat.ToString() == "Creo"); if (cadmodel == null) { return; } string componentID = component.ID; string cadmodelID = cadmodel.ID; /* * var conns = component.Children.PortCompositionCollection * .Where(x => x.SrcEnd.Kind == "Point" && x.DstEnd.Kind == "Point") * .Cast<IMgaSimpleConnection>() * .Where(x => (x.Src.ParentModel.ID == componentID || x.Src.ParentModel.ID == cadmodelID) && (x.Dst.ParentModel.ID == componentID || x.Dst.ParentModel.ID == cadmodelID)); */ foreach (var p in cadmodel.Children.PointCollection) { MgaFCO pointFCO = p.Impl as MgaFCO; var connPt = pointFCO.PartOfConns .Cast <IMgaConnPoint>() .Select(x => x.Owner) .Cast <IMgaSimpleConnection>() .Where(x => ((x.Src.ID == pointFCO.ID) && (x.Dst.ParentModel.ID == componentID)) || ((x.Dst.ID == pointFCO.ID) && (x.Src.ParentModel.ID == componentID))); if (connPt.Count() > 0) { CyPhy.Point point = CyPhyClasses.Point.Cast(pointFCO); if (point != null) { TestBenchModel.TBComputation computation = new TestBenchModel.TBComputation() { ComponentID = DisplayID, ComputationType = TestBenchModel.TBComputation.Type.POINTCOORDINATES, Details = point.Attributes.DatumName, MetricID = DisplayID + ":" + point.Attributes.DatumName, RequestedValueType = "Vector" }; this.PointCoordinatesList.Add(computation); } } } }
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); } }
public override void TraverseTestBench(CyPhy.TestBenchType testBenchBase) { string stepFormat = "AP203_E2_Single_File"; if (!STEP_DataExchangeFormats.Contains(stepFormat, StringComparer.OrdinalIgnoreCase)) { STEP_DataExchangeFormats.Add(stepFormat); } CyPhy.BallisticTestBench testBench = testBenchBase as CyPhy.BallisticTestBench; if (testBench == null) { testBench = CyPhyClasses.BallisticTestBench.Cast(testBenchBase.Impl); } base.TraverseTestBench(testBenchBase); //AnalysisID = testBench.ID; foreach (var item in testBench.Children.BallisticComputation2MetricCollection) { TBComputation tbcomputation = new TBComputation(); if (item.SrcEnds.TotalIntersections != null) { tbcomputation.ComputationType = TBComputation.Type.TOTALINTERSECTIONS; } else if (item.SrcEnds.TotalKills != null) { tbcomputation.ComputationType = TBComputation.Type.TOTALKILLS; } else if (item.SrcEnds.TotalPerforations != null) { tbcomputation.ComputationType = TBComputation.Type.TOTALPERFORATIONS; } else if (item.SrcEnds.TotalShots != null) { tbcomputation.ComputationType = TBComputation.Type.TOTALSHOTS; } else { Logger.Instance.AddLogMessage("Unknown Ballistic calculation: " + item.SrcEnd.Impl.Name, Severity.Error); } tbcomputation.MetricID = item.DstEnds.Metric.ID; tbcomputation.MetricName = item.Name; tbcomputation.RequestedValueType = ""; Computations.Add(tbcomputation); } int predefinedCnt = testBench.Children.PredefinedBallisticSuiteCollection.Count(); int customCnt = testBench.Children.ShotlineModelCollection.Count(); if (predefinedCnt > 0) { if (predefinedCnt > 1) { Logger.Instance.AddLogMessage("Ballistic testbench can only have at most 1 predefined shotline suite.", Severity.Error); return; } if (customCnt > 0) { Logger.Instance.AddLogMessage("Ballistic testbench can not have both predefined and custom shotline suites.", Severity.Error); return; } } // reference plane if (testBench.Children.ReferencePlaneCollection.Any()) { if (testBench.Children.ReferencePlaneCollection.First().Attributes.ReferencePlaneType == 0) { referencePlaneType = Survivability.ReferencePlaneTypeEnum.Ground; } else { referencePlaneType = Survivability.ReferencePlaneTypeEnum.Waterline; } } // analysis Survivability.BallisticConfig.Analysis ballisticAnalysis = new Survivability.BallisticConfig.Analysis(); ballisticAnalysis.ID = AnalysisID; if (predefinedCnt > 0) { ballisticAnalysis.suiteName = testBench.Children.PredefinedBallisticSuiteCollection.First().Attributes.Name; } else { ballisticAnalysis.suiteName = testBench.Name; } if (ballisticAnalysis.suiteName.Length == 0) { Logger.Instance.AddLogMessage("Ballistic analysis suite has no name specified.", Severity.Warning); } ballisticAnalysis.tier = (int)testBench.Attributes.Tier + 1; // starts at 0 ballisticConfig.analysis = ballisticAnalysis; // ballistic threat foreach (var item in testBench.Children.BallisticThreatCollection) { VerifyBallisticThreat(item); Survivability.BallisticConfig.BallisticThreat threat = new Survivability.BallisticConfig.BallisticThreat(); threat.diameter_meters = item.Attributes.Diameter; threat.length_meters = item.Attributes.Length; threat.materialRef = item.Attributes.Material; threat.speed_metersPerSec = item.Attributes.Speed; if (item.Kind == "ProjectileBallisticThreat") { threat.type = Survivability.BallisticConfig.BallisticThreat.BallisticThreatTypeEnum.Ballistic; } else if (item.Kind == "ShapedChargeJetBallisticThreat") { threat.type = Survivability.BallisticConfig.BallisticThreat.BallisticThreatTypeEnum.ShapedChargeJet; threat.standoff_meters = (item as CyPhy.ShapedChargeJetBallisticThreat).Attributes.Standoff; int chargeq = (int)(item as CyPhy.ShapedChargeJetBallisticThreat).Attributes.ChargeQuality; threat.chargeQuality = (Survivability.BallisticConfig.BallisticThreat.ChargeQualityEnum)(chargeq); } threat.name = item.ID; ballisticConfig.ballisticThreats.Add(threat); } // critical components foreach (var item in testBench.Children.CriticalComponentCollection) { int type = (int)item.Attributes.Type; CyPhy.TIPRefBase refbase = item.Referred.TIPRefBase; if (refbase != null) { if (refbase.Kind != "Component") { Logger.Instance.AddLogMessage(String.Format("Critical component must refer to a component: {0}", refbase.Name), Severity.Error); } else { Survivability.BallisticConfig.CriticalComponent criticalcomponent = new Survivability.BallisticConfig.CriticalComponent(); criticalcomponent.componentID = (refbase as CyPhy.Component).Attributes.InstanceGUID; criticalcomponent.type = (Survivability.BallisticConfig.CriticalComponent.CriticalityTypeEnum)(type); ballisticConfig.criticalComponents.Add(criticalcomponent); } } } // file location // see GenerateCADXmlOutput(); // custom shotline foreach (var item in testBench.Children.ShotlineModelCollection) { if (VerifyShotLineModel(item)) { continue; } string componentid = ""; string datumname = ""; CyPhy.ShotlineTarget target = item.DstConnections.ShotlineTargetCollection.First(); CyPhy.Point ap = target.DstEnds.Point; PointMetricTraversal traverser = new PointMetricTraversal(ap); if (!traverser.portsFound.Any()) { Logger.Instance.AddLogMessage("Shotline Model is connected to an AnalysisPoint which does not end in a PointGeometry [" + item.Path + "]", Severity.Error); continue; } datumname = (traverser.portsFound.First() as CyPhy.Point).Attributes.DatumName; CyPhy.Component targetComponent = CyPhyClasses.Component.Cast(traverser.portsFound.First().ParentContainer.ParentContainer.Impl); componentid = targetComponent.Attributes.InstanceGUID; foreach (var conn in item.SrcConnections.Threat2ShotlineSuiteCollection) { CyPhy.BallisticThreat threat = conn.SrcEnds.BallisticThreat; CustomShotline customshotline = new CustomShotline(); customshotline.Azimuth = item.Children.AzimuthAngleCollection.First().Attributes.Value; customshotline.Elevation = item.Children.ElevationAngleCollection.First().Attributes.Value; customshotline.BallisticThreatRef = threat.ID; customshotline.ComponentID = componentid; customshotline.DatumPoint = datumname; customshotline.ShotlineName = item.Attributes.Name; customShotlineList.Add(customshotline); } } }
public override void TraverseTestBench(CyPhy.TestBenchType testBenchBase) { CyPhy.TestBench testBench = testBenchBase as CyPhy.TestBench; if (testBench == null) { testBench = CyPhyClasses.TestBench.Cast(testBenchBase.Impl); } base.TraverseTestBench(testBenchBase); //AnalysisID = testBench.ID; // R.O. added 11/15/2016, because the MSD_CAD.xme/TestBench_Valid was failing because the schema for CADAssmbly.xml requires // that ComponentID be set for Metrics/Metric attributes. For Mass, CenterOfGravity, BoundingBox, and Interference, // the metric applies to the entire assembly; therefore, we will use the top-level assembly as the ComponentID. var catlsut = testBench.Children.ComponentAssemblyCollection.FirstOrDefault(); // should be an instance b/c elaborate was called earlier if (catlsut == null) { // This check occurs earlier in ProcessCAD(), but will repeat here in case someone changes the code to not // test this earlier. throw new Exception("There is no elaborated system under test component assembly in the model!"); } // "|1" is set in other places in the code for the top-level assembly. Search on "|" to see those places. // If someone changes to another system ( different suffix than "|1") and does not change the following // line, then the CreateAssembly program will throw an exception. This will be caught by the build tests // (e.g. MSD_CAD.xme/TestBench_Valid). string topLevelAssemblyComponentInstanceID_temp = catlsut.Attributes.ConfigurationUniqueID + "|" + "1"; // CADComputations Metrics foreach (var conn in testBench.Children.CADComputation2MetricCollection) { CyPhy.CADComputationType cadcomputation = conn.SrcEnds.CADComputationType; TBComputation tbcomputation = new TBComputation(); tbcomputation.MetricID = conn.DstEnds.Metric.ID; if (cadcomputation is CyPhy.CenterOfGravity) { tbcomputation.ComponentID = topLevelAssemblyComponentInstanceID_temp; tbcomputation.RequestedValueType = (cadcomputation as CyPhy.CenterOfGravity).Attributes.CADComputationRequestedValue.ToString(); tbcomputation.ComputationType = TBComputation.Type.CENTEROFGRAVITY; } else if (cadcomputation is CyPhy.BoundingBox) { tbcomputation.ComponentID = topLevelAssemblyComponentInstanceID_temp; tbcomputation.RequestedValueType = (cadcomputation as CyPhy.BoundingBox).Attributes.CADComputationRequestedValue.ToString(); tbcomputation.ComputationType = TBComputation.Type.BOUNDINGBOX; } else if (cadcomputation is CyPhy.InterferenceCount) { tbcomputation.ComponentID = topLevelAssemblyComponentInstanceID_temp; tbcomputation.RequestedValueType = "Scalar"; tbcomputation.ComputationType = TBComputation.Type.INTERFERENCECOUNT; } else if (cadcomputation is CyPhy.Mass) { tbcomputation.ComponentID = topLevelAssemblyComponentInstanceID_temp; tbcomputation.RequestedValueType = "Scalar"; tbcomputation.ComputationType = TBComputation.Type.MASS; } this.StaticAnalysisMetrics.Add(tbcomputation); } // PointCoordinate Metrics foreach (var metric in testBench.Children.MetricCollection) { List <CyPhy.Point> points_list = new List <CyPhy.Point>(); foreach (var pt in metric.SrcConnections.PointCoordinates2MetricCollection) { points_list.Add(pt.SrcEnds.Point); } foreach (var pt in metric.DstConnections.PointCoordinates2MetricCollection) { points_list.Add(pt.DstEnds.Point); } if (points_list.Any()) { if (points_list.Count() > 1) { Logger.Instance.AddLogMessage("Metric should not be connected to multiple Point datums in a test bench.", Severity.Error); } CyPhy.Point point = points_list.First(); PointMetricTraversal traverser = new PointMetricTraversal(point); if (traverser.portsFound.Count() == 1) { TBComputation tbcomputation = new TBComputation(); tbcomputation.ComputationType = TBComputation.Type.POINTCOORDINATES; tbcomputation.MetricID = metric.ID; tbcomputation.RequestedValueType = "Vector"; tbcomputation.Details = (traverser.portsFound.First() as CyPhy.Point).Attributes.DatumName; tbcomputation.ComponentID = CyPhyClasses.Component.Cast(traverser.portsFound.First().ParentContainer.ParentContainer.Impl).Attributes.InstanceGUID; tbcomputation.MetricName = metric.Name; StaticAnalysisMetrics.Add(tbcomputation); } } } // Post Processing Blocks foreach (var postprocess in testBench.Children.PostProcessingCollection) { PostProcessScripts.Add(postprocess.Attributes.ScriptPath); } }