private void TraverseComponentAssembly(CyPhy.ComponentAssembly componentasm)
        {
            foreach (CyPhy.ComponentRef cref in componentasm.Children.ComponentRefCollection)
            {
                throw new Exception("Model not fully elaborated, contains ComponentRef [" + cref.Path +  "]");
            }

            foreach (CyPhy.ComponentAssembly cainst in componentasm.Children.ComponentAssemblyCollection)
            {
                TraverseComponentAssembly(cainst);
            }

            foreach (CyPhy.Component cint in componentasm.Children.ComponentCollection)
            {
                foreach (CyPhy.ManufacturingModel manModel in cint.Children.ManufacturingModelCollection)
                {
                    string manfilename;
                    if ( ! manModel.TryGetResourcePath(out manfilename) || 
                           String.IsNullOrWhiteSpace(manfilename))
                    {
                        GMEConsole.Warning.Write("ManufacturingModel's FileLocation does not have a valid file name [" + manModel.Path + "]");
                        continue;
                    }

                    string componentjsonpath = cint.GetDirectoryPath();

                    // for xml data
                    ComponentManufacturingData mfdata = new ComponentManufacturingData();
                    mfdata.AVMID = cint.Attributes.AVMID;
                    mfdata.RevID = "";
                    mfdata.VerID = cint.Attributes.Version;
                    mfdata.GUID = cint.Attributes.InstanceGUID;
                    mfdata.Name = cint.Name;
                    //mfdata.Location = Path.Combine(this.ProjectRootDirectory, fullfilepath, manModel.Attributes.Location);         // form path
                    mfdata.Location = Path.Combine(this.ProjectRootDirectory, componentjsonpath, manfilename);         // form path
                    mfdata.NewLocation = Path.Combine(this.OutputDirectory, "ManufacturingModels");

                    foreach (CyPhy.ManufacturingModelParameter param in manModel.Children.ManufacturingModelParameterCollection)
                    {
                        int srcCount = param.AllSrcConnections.Count();
                        if (srcCount > 1)
                            throw new Exception("ManufacturingModelParameter is connected to >1 value flow targets [" + param.Path + "]");

                        if (String.IsNullOrEmpty(param.Attributes.Value))
                        {
                            if (String.IsNullOrEmpty(param.Attributes.DefaultValue))
                                continue;
                            else
                                mfdata.ManufacturingParamters.Add(param.Name, param.Attributes.DefaultValue);
                        }
                        else
                            mfdata.ManufacturingParamters.Add(param.Name, param.Attributes.Value);
                    }

                    this.ComponentManufacturingDataList.Add(mfdata);

                    // for manifest data
                    DesignManufactureManifest.ComponentManufactureManifestData componentmanifestdata = new DesignManufactureManifest.ComponentManufactureManifestData(cint.Attributes.InstanceGUID, mfdata.NewLocation);
                    char[] charsToTrim = { '{', '}' };
                    string fileName = cint.Attributes.InstanceGUID.Trim(charsToTrim) + ".xml";
                    componentmanifestdata.ManufacturingModel = "ManufacturingModels/" + fileName;
                    this.ManufacturingManifestData.ComponentManufactureList.Add(componentmanifestdata);
                }
            }
        }
示例#2
0
        private void TraverseComponentAssembly(CyPhy.ComponentAssembly componentasm)
        {
            foreach (CyPhy.ComponentRef cref in componentasm.Children.ComponentRefCollection)
            {
                throw new Exception("Model not fully elaborated, contains ComponentRef [" + cref.Path + "]");
            }

            foreach (CyPhy.ComponentAssembly cainst in componentasm.Children.ComponentAssemblyCollection)
            {
                TraverseComponentAssembly(cainst);
            }

            foreach (CyPhy.Component cint in componentasm.Children.ComponentCollection)
            {
                foreach (CyPhy.ManufacturingModel manModel in cint.Children.ManufacturingModelCollection)
                {
                    string manfilename;
                    if (!manModel.TryGetResourcePath(out manfilename) ||
                        String.IsNullOrWhiteSpace(manfilename))
                    {
                        GMEConsole.Warning.Write("ManufacturingModel's FileLocation does not have a valid file name [" + manModel.Path + "]");
                        continue;
                    }

                    string componentjsonpath = cint.GetDirectoryPath();

                    // for xml data
                    ComponentManufacturingData mfdata = new ComponentManufacturingData();
                    mfdata.AVMID = cint.Attributes.AVMID;
                    mfdata.RevID = "";
                    mfdata.VerID = cint.Attributes.Version;
                    mfdata.GUID  = cint.Attributes.InstanceGUID;
                    mfdata.Name  = cint.Name;
                    //mfdata.Location = Path.Combine(this.ProjectRootDirectory, fullfilepath, manModel.Attributes.Location);         // form path
                    mfdata.Location    = Path.Combine(this.ProjectRootDirectory, componentjsonpath, manfilename);      // form path
                    mfdata.NewLocation = Path.Combine(this.OutputDirectory, "ManufacturingModels");

                    foreach (CyPhy.ManufacturingModelParameter param in manModel.Children.ManufacturingModelParameterCollection)
                    {
                        int srcCount = param.AllSrcConnections.Count();
                        if (srcCount > 1)
                        {
                            throw new Exception("ManufacturingModelParameter is connected to >1 value flow targets [" + param.Path + "]");
                        }

                        if (String.IsNullOrEmpty(param.Attributes.Value))
                        {
                            if (String.IsNullOrEmpty(param.Attributes.DefaultValue))
                            {
                                continue;
                            }
                            else
                            {
                                mfdata.ManufacturingParamters.Add(param.Name, param.Attributes.DefaultValue);
                            }
                        }
                        else
                        {
                            mfdata.ManufacturingParamters.Add(param.Name, param.Attributes.Value);
                        }
                    }

                    this.ComponentManufacturingDataList.Add(mfdata);

                    // for manifest data
                    DesignManufactureManifest.ComponentManufactureManifestData componentmanifestdata = new DesignManufactureManifest.ComponentManufactureManifestData(cint.Attributes.InstanceGUID, mfdata.NewLocation);
                    char[] charsToTrim = { '{', '}' };
                    string fileName    = cint.Attributes.InstanceGUID.Trim(charsToTrim) + ".xml";
                    componentmanifestdata.ManufacturingModel = "ManufacturingModels/" + fileName;
                    this.ManufacturingManifestData.ComponentManufactureList.Add(componentmanifestdata);
                }
            }
        }