cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : CGMApp.cpp 00003 // 00004 // Purpose : Init and cleanup for CGM 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : Byron Hanks 00009 // 00010 // Date : 01/09/2002 00011 // 00012 // Owner : 00013 //------------------------------------------------------------------------- 00014 00015 #include "CGMApp.hpp" 00016 #include "AppUtil.hpp" 00017 00018 #include "GeometryQueryTool.hpp" 00019 #include "GeometryModifyTool.hpp" 00020 #include "GeometryFeatureTool.hpp" 00021 #include "GeometryHealerTool.hpp" 00022 #include "BoundingBoxTool.hpp" 00023 #include "RefEntityName.hpp" 00024 #include "SurfaceOverlapTool.hpp" 00025 #include "CubitSimpleAttrib.hpp" 00026 #include "TDUniqueId.hpp" 00027 #include "MergeTool.hpp" 00028 #include "OldUnmergeCode.hpp" 00029 #include "ModelQueryEngine.hpp" 00030 00031 // TODO - I'm not sure this is the place to include all the attributes 00032 #include "CADefines.hpp" 00033 #include "CAMergePartner.hpp" 00034 #include "CAEntityName.hpp" 00035 #include "CAGroup.hpp" 00036 #include "CAEntityId.hpp" 00037 #include "CAUniqueId.hpp" 00038 #include "CADeferredAttrib.hpp" 00039 #include "CAEntityColor.hpp" 00040 #include "CAEntityTol.hpp" 00041 #include "CAMergeStatus.hpp" 00042 #include "CASourceFeature.hpp" 00043 #include "CAEntitySense.hpp" 00044 #ifdef CAT 00045 #include "CAProWeld.hpp" 00046 #endif 00047 00048 CGMApp* CGMApp::instance_ = NULL; 00049 00050 // Returns the singleton instance of the app object. 00051 CGMApp* CGMApp::instance() 00052 { 00053 if (instance_ == NULL) 00054 { 00055 instance_ = new CGMApp(); 00056 if (!instance_ ) 00057 { 00058 PRINT_ERROR(" *** Unable to initialize application ***\n"); 00059 exit(1); 00060 } 00061 } 00062 return instance_; 00063 } 00064 00065 CGMApp::CGMApp() 00066 { 00067 mAppStarted = CUBIT_FALSE; 00068 00069 // CGMApp depends on there being an AppUtil 00070 AppUtil::instance(); 00071 00072 // initialize my settings 00073 initialize_settings(); 00074 00075 caUpdateFlgs = NULL; 00076 caActuateFlgs = NULL; 00077 caWriteFlgs = NULL; 00078 caReadFlgs = NULL; 00079 } 00080 00081 CGMApp::~CGMApp() 00082 { 00083 instance_ = NULL; 00084 } 00085 00086 void CGMApp::startup(const std::vector<CubitString> &args) 00087 { 00088 if (mAppStarted) 00089 return; 00090 00091 // make sure apputil has started 00092 AppUtil::instance()->startup(); 00093 00094 // register attributes 00095 register_attributes(); 00096 00097 mAppStarted = CUBIT_TRUE; 00098 } 00099 00100 void CGMApp::shutdown() 00101 { 00102 GeometryHealerTool::delete_instance(); 00103 GeometryModifyTool::delete_instance(); 00104 GeometryQueryTool::delete_instance(); 00105 GeometryFeatureTool::delete_instance(); 00106 AnalyticGeometryTool::delete_instance(); 00107 RefEntityName::delete_instance(); 00108 MergeTool::delete_instance(); 00109 ModelQueryEngine::delete_instance(); 00110 00111 DAG::delete_instance(); 00112 mAppStarted = CUBIT_FALSE; 00113 } 00114 00115 void CGMApp::initialize_settings() 00116 { 00117 GeometryQueryTool::instance()->initialize_settings(); 00118 GeometryModifyTool::instance()->initialize_settings(); 00119 BoundingBoxTool::initialize_settings(); 00120 CubitSimpleAttrib::initialize_settings(); 00121 RefEntityName::initialize_settings(); 00122 SurfaceOverlapTool::initialize_settings(); 00123 MergeTool::initialize_settings(); 00124 OldUnmergeCode::initialize_settings(); 00125 00126 } 00127 00128 void CGMApp::register_attributes() 00129 { 00130 CubitStatus result; 00131 result = mAttribManager.register_attrib_type(CA_MERGE_PARTNER, "merge", "MERGE_PARTNER", 00132 CAMergePartner_creator, CUBIT_FALSE, 00133 CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE, 00134 CUBIT_FALSE, CUBIT_FALSE); 00135 if (CUBIT_SUCCESS != result) { 00136 PRINT_ERROR("Failed to register attribute type merge.\n"); 00137 return; 00138 } 00139 00140 result = mAttribManager.register_attrib_type(CA_ENTITY_NAME, "name", "ENTITY_NAME", 00141 CAEntityName_creator, CUBIT_TRUE, 00142 CUBIT_TRUE, CUBIT_TRUE, CUBIT_TRUE, 00143 CUBIT_TRUE, CUBIT_FALSE); 00144 if (CUBIT_SUCCESS != result) { 00145 PRINT_ERROR("Failed to register attribute type name.\n"); 00146 return; 00147 } 00148 00149 result = mAttribManager.register_attrib_type(CA_GROUP, "group", "GROUP", 00150 CAGroup_creator, CUBIT_FALSE, 00151 CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE, 00152 CUBIT_FALSE, CUBIT_FALSE); 00153 if (CUBIT_SUCCESS != result) { 00154 PRINT_ERROR("Failed to register attribute type group.\n"); 00155 return; 00156 } 00157 00158 result = mAttribManager.register_attrib_type(CA_ENTITY_ID, "id", "ENTITY_ID", 00159 CAEntityId_creator, CUBIT_FALSE, 00160 CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE, 00161 CUBIT_TRUE, CUBIT_FALSE); 00162 if (CUBIT_SUCCESS != result) { 00163 PRINT_ERROR("Failed to register attribute type id.\n"); 00164 return; 00165 } 00166 00167 result = mAttribManager.register_attrib_type(CA_ENTITY_TOL, "tolerance", "ENTITY_TOL", 00168 CAEntityTol_creator, CUBIT_FALSE, 00169 CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE, 00170 CUBIT_FALSE, CUBIT_TRUE); 00171 if (CUBIT_SUCCESS != result) { 00172 PRINT_ERROR("Failed to register attribute type tolerance.\n"); 00173 return; 00174 } 00175 00176 result = mAttribManager.register_attrib_type(CA_UNIQUE_ID, "unique id", "UNIQUE_ID", 00177 CAUniqueId_creator, CUBIT_FALSE, 00178 CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE, 00179 CUBIT_TRUE, CUBIT_FALSE); 00180 if (CUBIT_SUCCESS != result) { 00181 PRINT_ERROR("Failed to register attribute type unique id.\n"); 00182 return; 00183 } 00184 00185 result = mAttribManager.register_attrib_type(CA_DEFERRED_ATTRIB, "deferred attrib", "DEFERRED_ATTRIB", 00186 CADeferredAttrib_creator, CUBIT_FALSE, 00187 CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE, 00188 CUBIT_FALSE, CUBIT_FALSE); 00189 if (CUBIT_SUCCESS != result) { 00190 PRINT_ERROR("Failed to register attribute type deferred attrib.\n"); 00191 return; 00192 } 00193 00194 result = mAttribManager.register_attrib_type(CA_ENTITY_COLOR, "color", "ENTITY_COLOR", 00195 CAEntityColor_creator, CUBIT_FALSE, 00196 CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE, 00197 CUBIT_FALSE, CUBIT_TRUE); 00198 if (CUBIT_SUCCESS != result) { 00199 PRINT_ERROR("Failed to register attribute type color.\n"); 00200 return; 00201 } 00202 00203 result = mAttribManager.register_attrib_type(CA_MERGE_STATUS, "merge status", "MERGE_STATUS", 00204 CAMergeStatus_creator, CUBIT_FALSE, 00205 CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE, 00206 CUBIT_FALSE, CUBIT_FALSE); 00207 if (CUBIT_SUCCESS != result) { 00208 PRINT_ERROR("Failed to register attribute type merge status.\n"); 00209 return; 00210 } 00211 00212 result = mAttribManager.register_attrib_type(CA_SOURCE_FEATURE, "source feature", "SOURCE_FEATURE", 00213 CASourceFeature_creator, CUBIT_TRUE, 00214 CUBIT_TRUE, CUBIT_TRUE, CUBIT_TRUE, 00215 CUBIT_TRUE, CUBIT_FALSE); 00216 if (CUBIT_SUCCESS != result) { 00217 PRINT_ERROR("Failed to register attribute type source feature.\n"); 00218 return; 00219 } 00220 00221 result = mAttribManager.register_attrib_type(CA_ENTITY_SENSE, "entity sense", "ENTITY_SENSE", 00222 CAEntitySense_creator, CUBIT_TRUE, 00223 CUBIT_TRUE, CUBIT_TRUE, CUBIT_TRUE, 00224 CUBIT_FALSE, CUBIT_FALSE); 00225 if (CUBIT_SUCCESS != result) { 00226 PRINT_ERROR("Failed to register attribute type entity sense.\n"); 00227 return; 00228 } 00229 00230 #ifdef CAT 00231 result = mAttribManager.register_attrib_type(CA_PRO_WELD, "pro weld", "PRO_WELD", 00232 CAProWeld_creator, CUBIT_TRUE, 00233 CUBIT_TRUE, CUBIT_TRUE, CUBIT_TRUE, 00234 CUBIT_TRUE, CUBIT_FALSE); 00235 if (CUBIT_SUCCESS != result) { 00236 PRINT_ERROR("Failed to register attribute type pro weld.\n"); 00237 } 00238 #endif 00239 } 00240 00241 CubitAttribManager* CGMApp::attrib_manager() 00242 { 00243 return &mAttribManager; 00244 } 00245 00246 00247 void CGMApp::save_current_attribute_states() 00248 { 00249 //all pointers must be NULL 00250 if( !!caUpdateFlgs && !!caActuateFlgs && 00251 !!caWriteFlgs && !!caReadFlgs ) 00252 { 00253 PRINT_ERROR("Problem setting attribute flags\n"); 00254 return; 00255 } 00256 00257 DLIList<int> attrib_types; 00258 mAttribManager.get_registered_types(attrib_types); 00259 00260 caUpdateFlgs = new CubitBoolean[attrib_types.size()]; 00261 caActuateFlgs = new CubitBoolean[attrib_types.size()]; 00262 caWriteFlgs = new CubitBoolean[attrib_types.size()]; 00263 caReadFlgs = new CubitBoolean[attrib_types.size()]; 00264 00265 int num_att = attrib_types.size(); 00266 attrib_types.reset(); 00267 int i; 00268 for( i=0; i<num_att; i++ ) 00269 { 00270 int att_type = attrib_types.get(); 00271 caUpdateFlgs[i] = mAttribManager.auto_update_flag( att_type ); 00272 caActuateFlgs[i] = mAttribManager.auto_actuate_flag( att_type ); 00273 caWriteFlgs[i] = mAttribManager.auto_write_flag( att_type ); 00274 caReadFlgs[i] = mAttribManager.auto_read_flag( att_type ); 00275 attrib_types.step(); 00276 } 00277 } 00278 00279 void CGMApp::restore_previous_attribute_states() 00280 { 00281 DLIList<int> attrib_types; 00282 mAttribManager.get_registered_types(attrib_types); 00283 00284 int num_att = attrib_types.size(); 00285 attrib_types.reset(); 00286 int i; 00287 for( i=0; i<num_att; i++ ) 00288 { 00289 int att_type = attrib_types.get(); 00290 mAttribManager.set_auto_update_flag( att_type, caUpdateFlgs[i] ); 00291 mAttribManager.set_auto_actuate_flag( att_type, caActuateFlgs[i] ); 00292 mAttribManager.set_auto_write_flag( att_type, caWriteFlgs[i] ); 00293 mAttribManager.set_auto_read_flag( att_type, caReadFlgs[i] ); 00294 attrib_types.step(); 00295 } 00296 00297 delete [] caUpdateFlgs; 00298 delete [] caActuateFlgs; 00299 delete [] caWriteFlgs; 00300 delete [] caReadFlgs; 00301 00302 caUpdateFlgs = NULL; 00303 caActuateFlgs = NULL; 00304 caWriteFlgs = NULL; 00305 caReadFlgs = NULL; 00306 } 00307