private void AddCadModelToComponent(CyPhy.CAD2EDATransform xform, CyPhy.CADModel cadModel, CyPhy.Component component, AbstractClasses.Component rtn) { string cadPath; bool retVal = cadModel.TryGetResourcePath(out cadPath, ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT); if (retVal == false) { logger.WriteError("Unable to get CADModel's associated resource file path for component {0}", component.Name); } if (cadModel.Attributes.FileFormat == CyPhyClasses.CADModel.AttributesClass.FileFormat_enum.AP_203 || cadModel.Attributes.FileFormat == CyPhyClasses.CADModel.AttributesClass.FileFormat_enum.AP_214) { rtn.cadModels.Add(new AbstractClasses.STEPModel() { path = cadPath, rotationVector = new XYZTuple <Double, Double, Double>(xform.Attributes.RotationX, xform.Attributes.RotationY, xform.Attributes.RotationZ), translationVector = new XYZTuple <Double, Double, Double>(xform.Attributes.TranslationX, xform.Attributes.TranslationY, xform.Attributes.TranslationZ), scalingVector = new XYZTuple <Double, Double, Double>(xform.Attributes.ScaleX, xform.Attributes.ScaleY, xform.Attributes.ScaleZ), }); } else if (cadModel.Attributes.FileFormat == CyPhyClasses.CADModel.AttributesClass.FileFormat_enum.STL) { rtn.cadModels.Add(new AbstractClasses.STLModel() { path = cadPath, rotationVector = new XYZTuple <Double, Double, Double>(xform.Attributes.RotationX, xform.Attributes.RotationY, xform.Attributes.RotationZ), translationVector = new XYZTuple <Double, Double, Double>(xform.Attributes.TranslationX, xform.Attributes.TranslationY, xform.Attributes.TranslationZ), scalingVector = new XYZTuple <Double, Double, Double>(xform.Attributes.ScaleX, xform.Attributes.ScaleY, xform.Attributes.ScaleZ), }); } else { logger.WriteError("Visualizer currently only supports STP & STL files. Component {0} has an " + "EDAModel connected to a non-STEP/STL formatted CADModel.", component.Name); } }
private AbstractClasses.Component ParseCyPhyComponent(CyPhy.Component component) { string classification = component.Attributes.Classifications.ToString(); if (String.Compare(classification, "ara_template") == 0 || String.Compare(classification, "template.ara_module_template") == 0) { // Stock module present for component replacement. AbstractClasses.AraTemplateComponent template = new AbstractClasses.AraTemplateComponent() { name = component.Attributes.InstanceGUID, classification = classification }; ParseAraTemplateComponent(component, template); return(template); } AbstractClasses.Component rtn = new AbstractClasses.Component() { // MOT-656 Switch to using component GUID as map key. Each component guaranteed to have a GUID, no need to check. name = component.Attributes.InstanceGUID, classification = classification }; // Check for only one EDAModel IEnumerable <CyPhy.EDAModel> edas = component.Children.EDAModelCollection; if (edas.Count() > 1) { logger.WriteError("Multiple EDAModels found for component {0}. Component should " + "only have one EDAModel.", component.Name); return(null); } IEnumerable <CyPhy.CAD2EDATransform> xforms = component.Children.CAD2EDATransformCollection; if (xforms.Count() == 0) { if (edas.Count() == 0) { logger.WriteInfo("Skipping component {0}, no EDAModel or CAD2EDATransform objects found.", component.Name); } else { logger.WriteWarning("EDAModel found for component {0} with no CAD2EDATransform, will generate " + "placeholder in visualizer based on EDAModel dimensions.", component.Name); CyPhy.EDAModel edaModel = edas.First(); } } else { // At this point you know all transforms point to the same EDAModel. The language also only // allows for one transform connection per CAD model, so you know there are no duplicate // transforms. foreach (var xform in xforms) { CyPhy.CADModel cadModel = xform.SrcEnds.CADModel; AddCadModelToComponent(xform, cadModel, component, rtn); } } return(rtn); }