Example #1
0
        public string ProduceAraTemplateJson(AbstractClasses.Design design)
        {
            string jsonResult = "";
            Dictionary <string, string> templateCadMap = new Dictionary <string, string>();

            AbstractClasses.AraTemplateComponent template = design.AllComponents.OfType <AbstractClasses.AraTemplateComponent>().First();

            templateCadMap.Add("template_cadpath", template.cadModels.First().path);

            // Get list of parameter names at the test bench level
            List <string> tb_param_names = new List <string>();

            foreach (var tbp in design.tb_parameters)
            {
                tb_param_names.Add(tbp.Name);
            }

            // Loop through template parameter names to see if any match that of testbench level parameters
            foreach (string param in template.parameters)
            {
                if (tb_param_names.Contains(param))
                {
                    // Override with CAD file whose path is the value.
                    templateCadMap.Add(param, design.tb_parameters.Find(x => x.Name == param).Attributes.Value);
                }
                else if (String.Compare(param, "PCB") == 0)
                {
                    templateCadMap.Add(param, design.Name + ".FCStd");
                }
                else
                {
                    templateCadMap.Add(param, "stock");
                }
            }

            if (templateCadMap.Count() > 0)
            {
                jsonResult = JsonConvert.SerializeObject(templateCadMap, Formatting.Indented,
                                                         new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
            }

            return(jsonResult);
        }
Example #2
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);
            }
        }
Example #3
0
        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);
        }