cgma
InitCGMA.cpp
Go to the documentation of this file.
00001 #include "InitCGMA.hpp"
00002 #include "CGMApp.hpp"
00003 #include "VirtualQueryEngine.hpp"
00004 #include "FacetQueryEngine.hpp"
00005 #include "FacetModifyEngine.hpp"
00006 #include "GeometryQueryTool.hpp"
00007 #include "GeometryModifyTool.hpp"
00008 #include "CubitUtil.hpp"
00009 #include "CADefines.hpp"
00010 #include "CubitAttrib.hpp"
00011 
00012 #include <ctype.h>
00013 
00014 // This is for fixing the segmentation fault with writing Attribute 43 (must be removed for future versions)
00015 class CAAssemblyData : public CubitAttrib
00016 {
00017 public:
00018   CAAssemblyData(RefEntity*, const CubitSimpleAttrib&) : CubitAttrib(NULL) {}
00019 
00020   CubitSimpleAttrib cubit_simple_attrib() { return CubitSimpleAttrib(NULL, NULL, NULL); }
00021 
00022   CubitStatus actuate() { return CUBIT_SUCCESS; }
00023 
00024   CubitStatus update() { return CUBIT_SUCCESS; }
00025 
00026   int int_attrib_type() { return CA_ASSEMBLY_DATA; }
00027 
00028   CubitStatus reset() { return CUBIT_SUCCESS; }
00029 };
00030 
00031 CubitAttrib* CAAssemblyData_creator(RefEntity* entity, const CubitSimpleAttrib& p_csa)
00032 {
00033   return new CAAssemblyData(entity, p_csa);
00034 }
00035 
00036 
00037 #if defined(HAVE_OCC) 
00038 #include "OCCQueryEngine.hpp"
00039 #include "OCCModifyEngine.hpp"
00040 #endif
00041 
00042 
00043 static bool streq_nocase( const char* s, const char* t )
00044 {
00045   for (; *s; ++s, ++t) 
00046     if (tolower(*s) != tolower(*t))
00047       return false;
00048   return !*t;
00049 }
00050 
00051 static bool has_been_initialized = false;
00052 static char* first_engine_name = NULL;
00053 
00054 
00055 CubitStatus InitCGMA::initialize_cgma( const char* default_engine_name )
00056 {
00057   if( has_been_initialized ){
00058     // CGM is already initialized.  Return success if previous initialization had
00059     // the same parameter, failure otherwise.
00060     if( default_engine_name == first_engine_name ){
00061       return CUBIT_SUCCESS;
00062     }
00063     else if( default_engine_name && first_engine_name && 
00064          streq_nocase( default_engine_name, first_engine_name )){
00065       return CUBIT_SUCCESS;
00066     }
00067     else{
00068       PRINT_ERROR( "initialize_cgma() called again, but default engines differ.\n" );
00069       return CUBIT_FAILURE;
00070     }
00071   }
00072 
00073   std::vector<CubitString> args;
00074   CGMApp::instance()->startup( args );
00075   GeometryModifyEngine* default_engine = 0;
00076   bool ignore_default = false;
00077 
00078   // Now register attribute 43 (must be removed as the bug in CUBIT is fixed in future versions)
00079   // Register CA_ASSEMBLY_DATA (a dummy attribute)
00080   CGMApp::instance()->attrib_manager()->register_attrib_type(CA_ASSEMBLY_DATA, "assembly data", "ASSEMBLY_DATA",
00081     CAAssemblyData_creator, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE);
00082 
00083 #ifdef HAVE_OCC  
00084   OCCQueryEngine::instance();
00085   OCCModifyEngine::instance();
00086   if (default_engine_name && streq_nocase("OCC",default_engine_name))
00087     default_engine = OCCModifyEngine::instance();
00088 #endif  
00089 
00090   FacetQueryEngine::instance();
00091   FacetModifyEngine::instance();
00092   VirtualQueryEngine::instance()->register_attributes();
00093 
00094   if (default_engine_name && streq_nocase("FACET",default_engine_name)) {
00095     default_engine = FacetModifyEngine::instance();
00096     FacetModifyEngine::instance()->set_modify_enabled(CUBIT_TRUE);
00097   }
00098 
00099   if(default_engine_name && !ignore_default) {
00100     if (!default_engine) {
00101       PRINT_ERROR("Invalid or unsupported engine: '%s'\n", default_engine_name);
00102       return CUBIT_FAILURE;
00103     }
00104     
00105     CubitStatus rval;
00106     rval = GeometryModifyTool::instance()->set_default_gme(default_engine);
00107     if (CUBIT_SUCCESS != rval)
00108       return rval;
00109     rval = GeometryQueryTool::instance()->set_default_gqe(default_engine->get_gqe());
00110     if (CUBIT_SUCCESS != rval)
00111       return rval;
00112   }
00113   
00114   // set has_been_initialized only if everything worked
00115   if( default_engine_name ){
00116     first_engine_name = CubitUtil::util_strdup(default_engine_name); 
00117   }
00118   has_been_initialized = true;
00119 
00120   return CUBIT_SUCCESS;
00121 }
00122 
00123 CubitStatus InitCGMA::deinitialize_cgma() 
00124 {
00125   CGMApp::instance()->shutdown();
00126   has_been_initialized = false;
00127   return CUBIT_SUCCESS;
00128 }
00129 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines