Exemplo n.º 1
0
        private Edit CreateComponentEditMessage(string instanceId, CyPhyML.Component component, CyPhyML.CADModel cadModel)
        {
            string cadModelRelativePath = "";

            if (false == cadModel.TryGetResourcePath(out cadModelRelativePath) || cadModelRelativePath == "")
            {
                // TODO log
                //return null;
            }

            var message = new Edit()
            {
                editMode = MetaLinkProtobuf.Edit.EditMode.POST,
                guid     = Guid.NewGuid().ToString(),
                //sequence = 0,
            };

            message.origin.Add(GMEOrigin);
            message.topic.Add(instanceId);
            edu.vanderbilt.isis.meta.Action action = new edu.vanderbilt.isis.meta.Action();
            message.actions.Add(action);
            action.actionMode = MetaLinkProtobuf.Action.ActionMode.UPDATE_CAD_COMPONENT;
            action.subjectID  = component.Attributes.AVMID;
            action.environment.Add(new edu.vanderbilt.isis.meta.Environment()
            {
                name = SearchPathStr,
            });
            AddSearchPathToEnvironment(component, action.environment[0]);
            if (cadModelRelativePath.Length != 0)
            {
                action.payload = new Payload();
                CADComponentType cadComponent = new CADComponentType()
                {
                    AvmComponentID = component.Attributes.AVMID,
                    CADModelID     = CyphyMetaLinkUtils.GetResourceID(cadModel),             // Using CADModelID to transport this information (the resource id)
                    Name           = Path.GetFileNameWithoutExtension(cadModelRelativePath), // the partial creo file name (less .prt or .asm)
                    Type           = (Path.GetExtension(cadModelRelativePath).EndsWith(".prt") || Path.GetExtension(cadModelRelativePath).EndsWith(".PRT")) ? "PART" : "ASSEMBLY"
                };
                foreach (var connector in component.Children.ConnectorCollection)
                {
                    cadComponent.Connectors.Add(new ConnectorType()
                    {
                        ID = connector.Guid.ToString(), DisplayName = connector.Name
                    });
                }
                foreach (var datum in cadModel.Children.CADDatumCollection)
                {
                    cadComponent.Datums.Add(new ConnectorDatumType()
                    {
                        ID = datum.Attributes.DatumName, DisplayName = datum.Name
                    });
                }
                action.payload.components.Add(cadComponent);
            }
            return(message);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        private void ParseAraTemplateComponent(CyPhy.Component component, AbstractClasses.AraTemplateComponent rtn)
        {
            // 1) Check only one CADModel (must be STEP)
            // 2) Grab CADModel resource (path to stock STEP file)
            // 3) Grab parameters in CADModel

            // 1
            IEnumerable <CyPhy.CADModel> cadModels = component.Children.CADModelCollection;

            if (cadModels.Count() == 0 || cadModels.Count() > 1)
            {
                logger.WriteError("Ara template component {0} must have one and only one CADModel.", component.Name);
            }
            CyPhy.CADModel cadModel = cadModels.First();
            if (cadModel.Attributes.FileFormat != CyPhyClasses.CADModel.AttributesClass.FileFormat_enum.AP_203 &&
                cadModel.Attributes.FileFormat != CyPhyClasses.CADModel.AttributesClass.FileFormat_enum.AP_214)
            {
                logger.WriteError("Ara template component {0} points to a non-STEP formatted component. Template " +
                                  "components must reference a STEP file only.", component.Name);
            }

            // 2
            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);
            }
            rtn.cadModels.Add(new AbstractClasses.STEPModel()
            {
                path = Path.Combine("..", "..", cadPath)
            });

            // 3
            rtn.parameters = new List <string>();
            foreach (var param in cadModel.Children.CADParameterCollection)
            {
                rtn.parameters.Add(param.Name);
            }
        }
Exemplo n.º 4
0
        private void CreateStructuralInterfaceEquivalent(CyPhy.Component cyphycomp)
        {
            CyPhy.CADModel cadmodel = cyphycomp.Children.CADModelCollection.FirstOrDefault(x => x.Attributes.FileFormat.ToString() == "Creo");
            if (cadmodel != null)
            {
                string uri;
                cadmodel.TryGetResourcePath(out uri);
                char[] start = new char[] { '/', '\\' };
                if (!String.IsNullOrEmpty(uri))
                {
                    uri = uri.TrimStart(start);

                    string absPath;
                    cadmodel.TryGetResourcePath(out absPath, ComponentLibraryManager.PathConvention.ABSOLUTE);
                    var hyperlink = cyphycomp.ToHyperLink(Traceability);
                    missingFile = Task.Run(() => CheckFileExists(hyperlink, uri, absPath));

                    // META-1382
                    //ModelName = UtilityHelpers.CleanString2(Path.GetFileNameWithoutExtension(uri));
                    ModelName = Path.GetFileName(uri);
                    List <string> tokens_2 = ModelName.Split('.').ToList <string>();
                    int           index    = tokens_2.FindIndex(x => x.ToUpper() == "PRT");
                    if (index != -1)
                    {
                        ModelType = "Part";
                        ModelName = string.Join("", tokens_2.GetRange(0, index).ToArray());
                    }
                    else
                    {
                        index = tokens_2.FindIndex(x => x.ToUpper() == "ASM");
                        if (index != -1)
                        {
                            ModelType = "Assembly";
                            ModelName = string.Join("", tokens_2.GetRange(0, index).ToArray());
                        }
                    }
                    // It shouldn't be an empty string
                    if (ModelType.Length == 0)
                    {
                        ModelType = "Part";
                    }
                }
                else
                {
                    Logger.Instance.AddLogMessage("CADModel Resource Path information unavailable for component [" + cyphycomp.Path + "," + DisplayID + "]!", Severity.Warning);
                }

                ModelURI = uri.Length > 0 ? Path.GetDirectoryName(uri) : "";
                //ModelType = cadmodel.Attributes.FileType.ToString();

                foreach (var param in cadmodel.Children.CADParameterCollection)
                {
                    CADParameter acadparam = new CADParameter(param);
                    CadParameters.Add(acadparam);
                }

                // META-947: Connector replaced StructuralInterface
                //           Not dealing with nested Connectors right now.
                // foreach (var item in cyphycomp.Children.StructuralInterfaceCollection)
                foreach (CyPhy.Connector item in cyphycomp.Children.ConnectorCollection)
                {
                    FindMatchingSolidModelingFeatures(item, cadmodel);
                }

                foreach (CyPhy.CADDatum item in cyphycomp.Children.CADDatumCollection)
                {
                    // only Coordinate System is supported
                    if (item is CyPhy.CoordinateSystem)
                    {
                        FindMatchingSolidModelingFeatures(item, cadmodel);
                    }
                    //else
                    //    Logger.Instance.AddLogMessage("Only CoordinateSystem datums outside of a Connector are supported, other datum types not supported.", Severity.Warning);
                }

                // Materials
                if (cyphycomp.Children.MaterialRefCollection.Any())
                {
                    CyPhy.MaterialRef matRef   = cyphycomp.Children.MaterialRefCollection.First();
                    CyPhy.Material    material = matRef.Referred.Material;
                    if (material != null)
                    {
                        this.MaterialName = material.Attributes.Name;
                    }
                }
            }
        }