CreateCADDataContainer() public method

public CreateCADDataContainer ( string configID, string assemblyName ) : CADContainer
configID string
assemblyName string
return CyPhy2CAD_CSharp.DataRep.CADContainer
Esempio n. 1
0
        private void ProcessCAD(MgaFCO currentobj)
        {
            string outputdir = this.mainParameters.OutputDirectory;
            if (!Directory.Exists(outputdir))
                Directory.CreateDirectory(outputdir);

            string debuglogdir = Path.Combine(outputdir, "log");
            if (!Directory.Exists(debuglogdir))
                Directory.CreateDirectory(debuglogdir);

            string projectdir = this.mainParameters.ProjectDirectory;

            CyPhy2CADSettings cadSetting = (CyPhy2CADSettings)this.mainParameters.config;
            string cadauxdir = cadSetting.AuxiliaryDirectory;

            CyPhy.ComponentAssembly curassembly;

            
            string curObjMetaBase = currentobj.MetaBase.Name;
            if (curObjMetaBase == "TestBench" || curObjMetaBase == "BallisticTestBench" || curObjMetaBase == "CFDTestBench" || curObjMetaBase == "BlastTestBench" || curObjMetaBase == "KinematicTestBench")
            {
                CyPhy.TestBenchType tb = CyPhyClasses.TestBenchType.Cast(currentobj);
                if (result != null && curObjMetaBase == "BlastTestBench")
                {
                    result.Labels = JobManager.Job.DefaultLabels + "&&SwRI_Blast";
                }
                if (result != null && curObjMetaBase == "KinematicTestBench")
                {
                    result.Labels = JobManager.Job.DefaultLabels + "&&Adams";
                }

                var catlsut = tb.Children.ComponentAssemblyCollection.FirstOrDefault();     // should be an instance b/c elaborate was called earlier
                if (catlsut == null)
                {
                    result.Success = false;
                    throw new Exception("There is no elaborated system under test component assembly in the model!");
                }

                curassembly = catlsut;

                if (curassembly == null)
                {
                    result.Success = false;
                    throw new Exception("No Valid Component Assembly.");
                }

                // META-1971: ADM + ACM file export for blast + ballistics
                if (curObjMetaBase == "BallisticTestBench" || curObjMetaBase == "BlastTestBench")
                {
                    // ADM: Export DDP 2.x version (XML)
                    {
                        var design = CyPhy2DesignInterchange.CyPhy2DesignInterchange.Convert(catlsut);
                        string TestBenchName = tb.Name;

                        string admDir = Path.Combine(cadSetting.OutputDirectory, "DesignADM");
                        if (!Directory.Exists(admDir))
                            Directory.CreateDirectory(admDir);
                        XSD2CSharp.AvmXmlSerializer.SaveToFile(Path.Combine(admDir, TestBenchName + ".adm"), design);
                    }
                }
                // end META-1971

                // META-2987 
                GenerateCADParameterMapping(tb,
                                            outputdir);

                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(curassembly);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(curassembly.Attributes.ConfigurationUniqueID,
                                                                                       UtilityHelpers.CleanString2(curassembly.Name));

                using (StreamWriter writer = new StreamWriter(Path.Combine(outputdir, "log", "CyPhy2CAD_Graphviz_Representation.gv")))
                {
                    writer.WriteLine(cadcontainer.ToGraphviz(true));
                }

                if (!cadcontainer.IsAnalyzable() && curObjMetaBase != "TestBench")
                {                    
                    result.Success = false;
                    //Logger.Instance.AddLogMessage("Test Bench can not proceed because the test bench contains islands and/or orphans! Please see graphviz file in /log directory for details.", Severity.Error);
                    throw new META.InterpreterException("Test Bench can not proceed because the test bench contains islands and/or orphans, see graphviz file in /log/CyPhy2CAD_Graphviz_Representation.gv for details. Please remove islands/orphans and try again.");
                }

                TestBenchModel.TestBenchBase testBenchRep = TestBenchModelFactory.CreateTestBenchModel(curObjMetaBase,
                                                                                                     cadSetting,
                                                                                                     outputdir,
                                                                                                     projectdir,
                                                                                                     Automation);

                testBenchRep.cadDataContainer = cadcontainer;
                testBenchRep.CopySTL = this.CopySTL;

                if (curObjMetaBase != "ComponentAssembly")
                    testBenchRep.TraverseTestBench(tb);

                testBenchRep.CollectDirectories();
                result.Success = testBenchRep.GenerateOutputFiles();   

            }
            else if (curObjMetaBase == "CADTestBench")
            {
                CyPhy.CADTestBench tb = CyPhyClasses.CADTestBench.Cast(currentobj);
                // META-1701: label for Abaqus
                if (result != null)
                {
                    Dictionary<CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum, string> labelMap = new Dictionary<CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum,string>()
                    {
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.ABAQUS_Deck_Based, "Abaqus"},
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.ABAQUS_Model_Based, "Abaqus"},
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.NASTRAN, "Nastran"},
                    };
                    string label = "Abaqus";
                    labelMap.TryGetValue(tb.Attributes.SolverType, out label);
                    result.Labels += "&&" + label;
                }
                var toplevelSUT = tb.Children.ComponentAssemblyCollection.FirstOrDefault();     // should be an instance b/c elaborate was called earlier
                if (toplevelSUT == null)
                {
                    result.Success = false;
                    throw new Exception("There is no elaborated system under test component assembly in the model!");
                }

                // META-2987
                GenerateCADParameterMapping(tb,
                                            outputdir);

                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(tb,
                                           toplevelSUT.Path);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(tb.Guid.ToString(),
                                                                                       UtilityHelpers.CleanString2(tb.Name));

                using (StreamWriter writer = new StreamWriter(Path.Combine(outputdir, "log", "CyPhy2CAD_Graphviz_Representation.gv")))
                {
                    writer.WriteLine(cadcontainer.ToGraphviz(true));
                }
                result.Success = false;

                if (!cadcontainer.IsAnalyzable())
                {
                    //Logger.Instance.AddLogMessage("FEA Test Bench can not proceed because the test bench contains islands and/or orphans! Please see graphviz file in /log directory for details.", Severity.Error);
                    throw new META.InterpreterException("FEA Test Bench can not proceed because the test bench contains islands and/or orphans, see graphviz file in /log/CyPhy2CAD_Graphviz_Representation.gv for details. Please remove islands/orphans and try again.");
                }

                TestBenchModel.TestBenchBase testBenchRep = TestBenchModelFactory.CreateTestBenchModel(curObjMetaBase,
                                                                                                       cadSetting,
                                                                                                       outputdir,
                                                                                                       projectdir,
                                                                                                       Automation);
                testBenchRep.cadDataContainer = cadcontainer;
                testBenchRep.CopySTL = this.CopySTL;
                testBenchRep.TraverseTestBench(tb);
                testBenchRep.CollectDirectories();
                result.Success = testBenchRep.GenerateOutputFiles();
            }
            else if (curObjMetaBase == "ComponentAssembly")
            {
                curassembly = CyPhyClasses.ComponentAssembly.Cast(currentobj);
                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(curassembly);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(curassembly.Guid.ToString(),
                                                                                       UtilityHelpers.CleanString2(curassembly.Name));

                TestBenchModel.TestBenchBase testbenchbase = new TestBenchModel.TestBenchBase(cadSetting,
                                                                                              outputdir,
                                                                                              projectdir);
                testbenchbase.cadDataContainer = cadcontainer;
                testbenchbase.CopySTL = this.CopySTL;
                testbenchbase.CollectDirectories();
            }
            else
            {
                result.Success = false;
                throw new NotImplementedException(String.Format("Running Cyphy2CAD on {0} is not implemented.", curObjMetaBase));
            }  

        }
Esempio n. 2
0
        private void ProcessCAD(MgaFCO currentobj)
        {
            string outputdir = this.mainParameters.OutputDirectory;

            if (!Directory.Exists(outputdir))
            {
                Directory.CreateDirectory(outputdir);
            }

            string debuglogdir = Path.Combine(outputdir, "log");

            if (!Directory.Exists(debuglogdir))
            {
                Directory.CreateDirectory(debuglogdir);
            }

            string projectdir = this.mainParameters.ProjectDirectory;

            CyPhy2CADSettings cadSetting = (CyPhy2CADSettings)this.mainParameters.config;
            string            cadauxdir  = cadSetting.AuxiliaryDirectory;

            CyPhy.ComponentAssembly curassembly;


            string curObjMetaBase = currentobj.MetaBase.Name;

            if (curObjMetaBase == "TestBench" || curObjMetaBase == "BallisticTestBench" || curObjMetaBase == "CFDTestBench" || curObjMetaBase == "BlastTestBench" || curObjMetaBase == "KinematicTestBench")
            {
                CyPhy.TestBenchType tb = CyPhyClasses.TestBenchType.Cast(currentobj);
                if (result != null && curObjMetaBase == "BlastTestBench")
                {
                    result.Labels = JobManager.Job.DefaultLabels + "&&SwRI_Blast";
                }
                if (result != null && curObjMetaBase == "KinematicTestBench")
                {
                    result.Labels = JobManager.Job.DefaultLabels + "&&Adams";
                }

                var catlsut = tb.Children.ComponentAssemblyCollection.FirstOrDefault();     // should be an instance b/c elaborate was called earlier
                if (catlsut == null)
                {
                    result.Success = false;
                    throw new Exception("There is no elaborated system under test component assembly in the model!");
                }

                curassembly = catlsut;

                if (curassembly == null)
                {
                    result.Success = false;
                    throw new Exception("No Valid Component Assembly.");
                }

                // META-1971: ADM + ACM file export for blast + ballistics
                if (curObjMetaBase == "BallisticTestBench" || curObjMetaBase == "BlastTestBench")
                {
                    // ADM: Export DDP 2.x version (XML)
                    {
                        var    design        = CyPhy2DesignInterchange.CyPhy2DesignInterchange.Convert(catlsut, this.result.Traceability);
                        string TestBenchName = tb.Name;

                        string admDir = Path.Combine(cadSetting.OutputDirectory, "DesignADM");
                        if (!Directory.Exists(admDir))
                        {
                            Directory.CreateDirectory(admDir);
                        }
                        OpenMETA.Interchange.AvmXmlSerializer.SaveToFile(Path.Combine(admDir, TestBenchName + ".adm"), design);
                    }
                }
                // end META-1971

                // META-2987
                GenerateCADParameterMapping(tb,
                                            outputdir, new List <object>());

                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory, CadFormat);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(curassembly);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(curassembly.Attributes.ConfigurationUniqueID,
                                                                                       UtilityHelpers.CleanString2(curassembly.Name));

                using (StreamWriter writer = new StreamWriter(Path.Combine(outputdir, "log", "CyPhy2CAD_Graphviz_Representation.gv")))
                {
                    writer.WriteLine(cadcontainer.ToGraphviz(true));
                }

                if (!cadcontainer.IsAnalyzable() && curObjMetaBase != "TestBench")
                {
                    result.Success = false;
                    //Logger.Instance.AddLogMessage("Test Bench can not proceed because the test bench contains islands and/or orphans! Please see graphviz file in /log directory for details.", Severity.Error);
                    throw new META.InterpreterException("Test Bench can not proceed because the test bench contains islands and/or orphans, see graphviz file in /log/CyPhy2CAD_Graphviz_Representation.gv for details. Please remove islands/orphans and try again.");
                }

                TestBenchModel.TestBenchBase testBenchRep = TestBenchModelFactory.CreateTestBenchModel(curObjMetaBase,
                                                                                                       cadSetting,
                                                                                                       outputdir,
                                                                                                       projectdir,
                                                                                                       Automation);

                testBenchRep.cadDataContainer = cadcontainer;
                testBenchRep.CopySTL          = this.CopySTL;

                if (curObjMetaBase != "ComponentAssembly")
                {
                    testBenchRep.TraverseTestBench(tb);
                }

                testBenchRep.CollectDirectories();
                result.Success = testBenchRep.GenerateOutputFiles();
            }
            else if (curObjMetaBase == "CADTestBench")
            {
                CyPhy.CADTestBench tb = CyPhyClasses.CADTestBench.Cast(currentobj);
                // META-1701: label for Abaqus
                if (result != null)
                {
                    Dictionary <CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum, string> labelMap = new Dictionary <CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum, string>()
                    {
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.ABAQUS_Deck_Based, "Abaqus" },
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.ABAQUS_Model_Based, "Abaqus" },
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.NASTRAN, "Nastran" },
                    };
                    string label = "Abaqus";
                    labelMap.TryGetValue(tb.Attributes.SolverType, out label);
                    result.Labels += "&&" + label;
                }
                var toplevelSUT = tb.Children.ComponentAssemblyCollection.FirstOrDefault();     // should be an instance b/c elaborate was called earlier
                if (toplevelSUT == null)
                {
                    result.Success = false;
                    throw new Exception("There is no elaborated system under test component assembly in the model!");
                }

                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory, CadFormat);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(tb,
                                           toplevelSUT.Path);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(tb.Guid.ToString(),
                                                                                       UtilityHelpers.CleanString2(tb.Name));

                using (StreamWriter writer = new StreamWriter(Path.Combine(outputdir, "log", "CyPhy2CAD_Graphviz_Representation.gv")))
                {
                    writer.WriteLine(cadcontainer.ToGraphviz(true));
                }
                result.Success = false;

                if (!cadcontainer.IsAnalyzable())
                {
                    //Logger.Instance.AddLogMessage("FEA Test Bench can not proceed because the test bench contains islands and/or orphans! Please see graphviz file in /log directory for details.", Severity.Error);
                    throw new META.InterpreterException("FEA Test Bench can not proceed because the test bench contains islands and/or orphans, see graphviz file in /log/CyPhy2CAD_Graphviz_Representation.gv for details. Please remove islands/orphans and try again.");
                }

                TestBenchModel.TestBenchBase testBenchRep = TestBenchModelFactory.CreateTestBenchModel(curObjMetaBase,
                                                                                                       cadSetting,
                                                                                                       outputdir,
                                                                                                       projectdir,
                                                                                                       Automation);
                testBenchRep.cadDataContainer = cadcontainer;
                testBenchRep.CopySTL          = this.CopySTL;
                testBenchRep.TraverseTestBench(tb);
                testBenchRep.CollectDirectories();
                result.Success = testBenchRep.GenerateOutputFiles();

                List <object> mappings = new List <object>();
                if (testBenchRep is TestBenchModel.FEATestBench)
                {
                    var feaRep = (TestBenchModel.FEATestBench)testBenchRep;
                    mappings = feaRep.TestBenchParameterMappings;
                }
                // META-2987
                GenerateCADParameterMapping(tb, outputdir, mappings);
            }
            else if (curObjMetaBase == "ComponentAssembly")
            {
                curassembly = CyPhyClasses.ComponentAssembly.Cast(currentobj);
                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory, CadFormat);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(curassembly);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(curassembly.Guid.ToString(),
                                                                                       UtilityHelpers.CleanString2(curassembly.Name));

                TestBenchModel.TestBenchBase testbenchbase = new TestBenchModel.TestBenchBase(cadSetting,
                                                                                              outputdir,
                                                                                              projectdir);
                testbenchbase.cadDataContainer = cadcontainer;
                testbenchbase.CopySTL          = this.CopySTL;
                testbenchbase.CollectDirectories();
            }
            else
            {
                result.Success = false;
                throw new NotImplementedException(String.Format("Running Cyphy2CAD on {0} is not implemented.", curObjMetaBase));
            }
        }