cgma
|
00001 00010 #undef NDEBUG 00011 #include <cassert> 00012 #include <string> 00013 #include <cctype> 00014 #include <Standard_Version.hxx> 00015 00016 #include "GeometryModifyTool.hpp" 00017 #include "GeometryQueryTool.hpp" 00018 #include "CubitMessage.hpp" 00019 #include "Body.hpp" 00020 #include "RefVolume.hpp" 00021 #include "RefFace.hpp" 00022 #include "RefEdge.hpp" 00023 #include "RefVertex.hpp" 00024 #include "InitCGMA.hpp" 00025 #include "CubitCompat.hpp" 00026 00027 #include <algorithm> 00028 00029 #ifndef SRCDIR 00030 # define SRCDIR . 00031 #endif 00032 00033 #define STRINGIFY_(X) #X 00034 #define STRINGIFY(X) STRINGIFY_(X) 00035 #define SRCPATH STRINGIFY(SRCDIR) "/" 00036 00037 // forward declare some functions used and defined later 00038 CubitStatus read_geometry(int, char **, bool local = false); 00039 CubitStatus make_Point(); 00040 // macro for printing a separator line 00041 #define PRINT_SEPARATOR PRINT_INFO("=======================================\n"); 00042 00043 int findString(const char *filename, std::string search) 00044 { 00045 std::ifstream Myfile; 00046 Myfile.open (filename); 00047 int found = 0; 00048 std::string line; 00049 size_t offset; 00050 if(Myfile.is_open()) 00051 { 00052 while(!Myfile.eof()) 00053 { 00054 getline(Myfile,line); 00055 if ((offset = line.find(search, 0)) != std::string::npos) 00056 found ++; 00057 } 00058 Myfile.close(); 00059 } 00060 return found; 00061 } 00062 // main program - initialize, then send to proper function 00063 int main (int argc, char **argv) 00064 { 00065 CubitStatus status = InitCGMA::initialize_cgma("OCC"); 00066 if (CUBIT_SUCCESS != status) return 1; 00067 00068 //Do make point. 00069 status = make_Point(); 00070 if (status == CUBIT_FAILURE) 00071 PRINT_INFO("Operation Failed"); 00072 00073 int ret_val = ( CubitMessage::instance()->error_count() ); 00074 if ( ret_val > 0 ) 00075 { 00076 PRINT_ERROR("Errors found during Mergechk session.\n"); 00077 } 00078 return ret_val; 00079 00080 } 00081 00082 std::string type_from_file_name( const std::string& filename ) 00083 { 00084 size_t dot_pos = filename.find_last_of( '.' ); 00085 if (dot_pos == std::string::npos) 00086 return std::string(); 00087 00088 std::string extension = filename.substr( dot_pos + 1 ); 00089 std::transform( extension.begin(), extension.end(), extension.begin(), ::tolower ); 00090 if (extension == "occ" || extension == "brep") 00091 return "OCC"; 00092 else if (extension == "step" || extension == "stp") 00093 return "STEP"; 00094 else if (extension == "iges" || extension == "igs") 00095 return "IGES"; 00096 else 00097 return std::string(); 00098 } 00099 00104 CubitStatus read_geometry(int num_files, const char **argv, bool local) 00105 { 00106 CubitStatus status = CUBIT_SUCCESS; 00107 GeometryQueryTool *gti = GeometryQueryTool::instance(); 00108 assert(gti); 00109 int i; 00110 00111 PRINT_SEPARATOR; 00112 00113 for (i = 0; i < num_files; i++) { 00114 std::string type = type_from_file_name( argv[i] ); 00115 if (type.empty()) // just guess OCC 00116 type = "OCC"; 00117 std::string filename( local ? "./" : SRCPATH ); 00118 char const* local_name = argv[i]; 00119 filename += local_name; 00120 status = CubitCompat_import_solid_model(filename.c_str(), type.c_str()); 00121 if (status != CUBIT_SUCCESS) { 00122 PRINT_ERROR("Problems reading geometry file %s.\n", filename.c_str()); 00123 abort(); 00124 } 00125 } 00126 PRINT_SEPARATOR; 00127 00128 return CUBIT_SUCCESS; 00129 } 00130 00131 CubitStatus make_Point() 00132 { 00133 GeometryQueryTool *gti = GeometryQueryTool::instance(); 00134 GeometryModifyTool *gmti = GeometryModifyTool::instance(); 00135 00136 DLIList<Body*> bodies; 00137 DLIList<RefEntity*> free_entities; 00138 00139 //Read in the geometry from iges file 00140 const char *argiges = "ex3.iges"; 00141 CubitStatus status = read_geometry(1, &argiges, false); 00142 //Constructed 18 Free Curves: 1 to 18 00143 if (status == CUBIT_FAILURE) exit(1); 00144 00145 DLIList<RefEntity*> ref_entity_list; 00146 int num_ents_exported=0; 00147 const CubitString cubit_version="10.2"; 00148 const char * filename = "ex3.occ"; 00149 const char * filetype = "OCC"; 00150 00151 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00152 num_ents_exported, cubit_version); 00153 00154 //Exported: 18 OCC Curves to ex3.occ 00155 assert(num_ents_exported == 18); 00156 remove(filename); 00157 00158 filetype = "IGES"; 00159 filename = "ex3export.iges"; 00160 num_ents_exported=0; 00161 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00162 num_ents_exported, cubit_version); 00163 00164 //Exported: 18 OCC Curves to ex3export.iges 00165 assert(num_ents_exported == 18); 00166 remove(filename); 00167 00168 filetype = "STEP"; 00169 filename = "ex3export.step"; 00170 num_ents_exported=0; 00171 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00172 num_ents_exported, cubit_version); 00173 //Exported: 18 OCC Curves to ex3export.step 00174 assert(num_ents_exported == 18); 00175 remove(filename); 00176 00177 gti->bodies(bodies); 00178 00179 //delete all entities 00180 gti->delete_Body(bodies); 00181 00182 gti->get_free_ref_entities(free_entities); 00183 00184 for (int j = free_entities.size(); j--;) 00185 { 00186 gti->delete_RefEntity( free_entities.get_and_step()); 00187 } 00188 00189 00190 const char *argiges2 = "diffuser.iges"; 00191 status = read_geometry(1, &argiges2, false); 00192 //Constructed 7 Volumes: 1 to 7 00193 if (status == CUBIT_FAILURE) exit(1); 00194 00195 filetype = "OCC"; 00196 ref_entity_list.clean_out(); 00197 num_ents_exported=0; 00198 filename = "diffuser.occ"; 00199 00200 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00201 num_ents_exported, cubit_version); 00202 00203 //Exported: 7 OCC Bodies to diffuser.occ 00204 assert(num_ents_exported == 7); 00205 remove(filename); 00206 00207 gti->bodies(bodies); 00208 00209 //delete all entities 00210 gti->delete_Body(bodies); 00211 00212 free_entities.clean_out(); 00213 gti->get_free_ref_entities(free_entities); 00214 00215 for (int j = free_entities.size(); j--;) 00216 { 00217 gti->delete_RefEntity( free_entities.get_and_step()); 00218 } 00219 00220 const char *argstep = "proe.stp"; 00221 //const char *argstep = "cub_model.step"; 00222 status = read_geometry(1, &argstep, false); 00223 //Constructed 12 Volumes: 8 to 19 00224 if (status == CUBIT_FAILURE) exit(1); 00225 00226 filetype = "OCC"; 00227 ref_entity_list.clean_out(); 00228 num_ents_exported=0; 00229 filename = "proe.occ"; 00230 00231 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00232 num_ents_exported, cubit_version); 00233 //Exported: 12 OCC Bodies to proe.occ 00234 assert(num_ents_exported == 12); 00235 remove(filename); 00236 00237 filetype = "IGES"; 00238 filename = "proeexport.iges"; 00239 num_ents_exported=0; 00240 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00241 num_ents_exported, cubit_version); 00242 //Exported: 12 OCC Bodies to proeexport.iges 00243 assert(num_ents_exported == 12); 00244 remove(filename); 00245 00246 filetype = "STEP"; 00247 filename = "proeexport.step"; 00248 num_ents_exported=0; 00249 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00250 num_ents_exported, cubit_version); 00251 //Exported: 12 OCC Bodies to proeexport.step 00252 assert(num_ents_exported == 12); 00253 remove(filename); 00254 00255 gti->bodies(bodies); 00256 00257 //delete all entities 00258 gti->delete_Body(bodies); 00259 free_entities.clean_out(); 00260 gti->get_free_ref_entities(free_entities); 00261 00262 for (int j = free_entities.size(); j--;) 00263 { 00264 gti->delete_RefEntity( free_entities.get_and_step()); 00265 } 00266 00267 // Read in the geometry from files specified on the command line 00268 const char *argv = "stitch.name_occ"; 00269 status = read_geometry(1, &argv, false); 00270 if (status == CUBIT_FAILURE) exit(1); 00271 //Read in 2 volumes. 00272 00273 filetype = "OCC"; 00274 ref_entity_list.clean_out(); 00275 num_ents_exported=0; 00276 filename = "beforesub.occ"; 00277 00278 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00279 num_ents_exported, cubit_version); 00280 00281 assert(num_ents_exported == 2); 00282 std::string search = "6 face15"; 00283 int found = findString(filename, search); 00284 assert (found == 1); 00285 gti->bodies(bodies); 00286 00287 //delete all entities 00288 gti->delete_Body(bodies); 00289 00290 free_entities.clean_out(); 00291 gti->get_free_ref_entities(free_entities); 00292 00293 for (int j = free_entities.size(); j--;) 00294 { 00295 gti->delete_RefEntity( free_entities.get_and_step()); 00296 } 00297 00298 const char *argv1 = "beforesub.occ"; 00299 status = read_geometry(1, &argv1, true); 00300 if (status == CUBIT_FAILURE) exit(1); 00301 //Read in 2 volumes. 00302 remove(filename); 00303 00304 //export the newly read-in file 00305 filename = "beforesub2.occ"; 00306 ref_entity_list.clean_out(); 00307 num_ents_exported = 0; 00308 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00309 num_ents_exported, cubit_version); 00310 00311 assert(num_ents_exported == 2); 00312 found = findString(filename, search); 00313 assert (found == 1); 00314 remove(filename); 00315 00316 bodies.clean_out(); 00317 gti->bodies(bodies); 00318 DLIList<Body*> new_bodies; 00319 DLIList<Body*> from_bodies; 00320 from_bodies.append(bodies.get()); 00321 Body* tool_body = bodies.step_and_get(); 00322 gmti->subtract(tool_body,from_bodies, new_bodies, 00323 CUBIT_TRUE, CUBIT_FALSE); 00324 //Created volume(s): 24, 25 00325 //Destroyed volume(s): 22, 23 00326 double d = new_bodies.step_and_get()->measure(); 00327 CubitVector v = new_bodies.get()->center_point(); 00328 int n = new_bodies.get()->num_ref_faces(); 00329 assert (n == 12); 00330 CubitVector test_v(5, 5,0.5); 00331 assert (v == test_v); 00332 assert (60-d < 0.000000001); 00333 //new body has 2 volumes, one has a volume = 10 and the other has a 00334 //volume = 50; each of them has 6 ref_faces, of which 3 are new and 3 are 00335 //remaining (unchanged or modified). 00336 00337 filename = "aftersub.occ"; 00338 ref_entity_list.clean_out(); 00339 num_ents_exported = 0; 00340 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00341 num_ents_exported, cubit_version); 00342 00343 assert(num_ents_exported == 1); 00344 search = "5 face1"; 00345 found = findString(filename, search); 00346 assert (found == 1); 00347 00348 search = "5 face2"; 00349 found = findString(filename, search); 00350 assert (found == 1); 00351 00352 search = "5 face3"; 00353 found = findString(filename, search); 00354 assert (found == 1); 00355 00356 #if OCC_VERSION_MINOR < 6 00357 search = "5 face4"; 00358 found = findString(filename, search); 00359 assert (found == 1); 00360 #endif 00361 search = "5 face5"; 00362 found = findString(filename, search); 00363 assert (found == 1); 00364 00365 search = "5 face7"; 00366 found = findString(filename, search); 00367 assert (found == 1); 00368 00369 #if OCC_VERSION_MINOR < 6 00370 search = "5 face8"; 00371 found = findString(filename, search); 00372 assert (found == 1); 00373 #endif 00374 00375 search = "5 face9"; 00376 found = findString(filename, search); 00377 assert (found == 1); 00378 remove(filename); 00379 00380 bodies.clean_out(); 00381 gti->bodies(bodies); 00382 //delete all entities 00383 gti->delete_Body(bodies); 00384 00385 gti->get_free_ref_entities(free_entities); 00386 assert(free_entities.size() ==0); 00387 00388 // Read in the geometry from files specified on the command line 00389 const char *argv2 = "unite1.occ"; 00390 status = read_geometry(1, &argv2, false); 00391 if (status == CUBIT_FAILURE) exit(1); 00392 //Read in 2 volumes. 00393 00394 from_bodies.clean_out(); 00395 new_bodies.clean_out(); 00396 gti->bodies(from_bodies); 00397 status = gmti->unite(from_bodies, new_bodies, CUBIT_FALSE); 00398 assert(status); 00399 00400 filename = "unite2.occ"; 00401 ref_entity_list.clean_out(); 00402 num_ents_exported = 0; 00403 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00404 num_ents_exported, cubit_version); 00405 00406 assert(num_ents_exported == 1); 00407 //name attributes in unite2.occ is 00408 //CGM_ATTRIB 11 ENTITY_NAME 4 8 volume B 8 volume_B 8 volume A 8 volume_A 0 0 00409 //check that the two single volume bodys' attributes are exported as SINGLELUMP% 00410 search = "4 8 volume B 8 volume_B 8 volume A 8 volume_A"; 00411 found = findString(filename, search); 00412 00413 assert (found == 1); 00414 remove(filename); 00415 00416 bodies.clean_out(); 00417 gti->bodies(bodies); 00418 //delete all entities 00419 gti->delete_Body(bodies); 00420 00421 gti->get_free_ref_entities(free_entities); 00422 assert(free_entities.size() ==0); 00423 00424 // Read in the geometry from files specified on the command line 00425 const char *argv3 = "unite1.occ"; 00426 status = read_geometry(1, &argv3, false); 00427 if (status == CUBIT_FAILURE) exit(1); 00428 //Read in 2 volumes. 00429 00430 //change the order of the two bodies,and unite, see the united name changed. 00431 new_bodies.clean_out(); 00432 bodies.clean_out(); 00433 gti->bodies(bodies); 00434 from_bodies.clean_out(); 00435 from_bodies.append(bodies.step_and_get()); 00436 from_bodies.append(bodies.step_and_get()); 00437 00438 status = gmti->unite(from_bodies, new_bodies, CUBIT_FALSE); 00439 assert(status); 00440 filename = "unite3.occ"; 00441 ref_entity_list.clean_out(); 00442 num_ents_exported = 0; 00443 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00444 num_ents_exported, cubit_version); 00445 assert(num_ents_exported == 1); 00446 //CGM_ATTRIB 11 ENTITY_NAME 4 8 volume A 8 volume_A 8 volume B 8 volume_B 0 0 00447 // in unite3.occ 00448 search = "4 8 volume A 8 volume_A 8 volume B 8 volume_B"; 00449 found = findString(filename, search); 00450 00451 assert (found == 1); 00452 remove(filename); 00453 bodies.clean_out(); 00454 gti->bodies(bodies); 00455 //delete all entities 00456 gti->delete_Body(bodies); 00457 00458 gti->get_free_ref_entities(free_entities); 00459 assert(free_entities.size() ==0); 00460 00461 // Read in the geometry from files specified on the command line 00462 const char *argv4 = "unite4.occ"; 00463 status = read_geometry(1, &argv4, false); 00464 if (status == CUBIT_FAILURE) exit(1); 00465 //Read in 2 volumes. 00466 00467 from_bodies.clean_out(); 00468 new_bodies.clean_out(); 00469 gti->bodies(from_bodies); 00470 status = gmti->unite(from_bodies, new_bodies, CUBIT_FALSE); 00471 assert(status); 00472 00473 filename = "unite5.occ"; 00474 ref_entity_list.clean_out(); 00475 num_ents_exported = 0; 00476 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00477 num_ents_exported, cubit_version); 00478 00479 assert(num_ents_exported == 1); 00480 //CGM_ATTRIB 11 ENTITY_NAME 2 7 volumeA 7 volumeB 0 0 in unite5.occ 00481 search = "2 7 volumeA 7 volumeB"; 00482 found = findString(filename, search); 00483 00484 assert (found == 1); 00485 remove(filename); 00486 bodies.clean_out(); 00487 gti->bodies(bodies); 00488 //delete all entities 00489 gti->delete_Body(bodies); 00490 00491 gti->get_free_ref_entities(free_entities); 00492 assert(free_entities.size() ==0); 00493 00494 // Read in the geometry from files specified on the command line 00495 status = read_geometry(1, &argv4, false); 00496 if (status == CUBIT_FAILURE) exit(1); 00497 //Read in 2 volumes. 00498 00499 //change the order of the two bodies, and unite, see the name change. 00500 new_bodies.clean_out(); 00501 bodies.clean_out(); 00502 gti->bodies(bodies); 00503 from_bodies.clean_out(); 00504 from_bodies.append(bodies.step_and_get()); 00505 from_bodies.append(bodies.step_and_get()); 00506 00507 status = gmti->unite(from_bodies, new_bodies, CUBIT_FALSE); 00508 assert(status); 00509 filename = "unite6.occ"; 00510 ref_entity_list.clean_out(); 00511 num_ents_exported = 0; 00512 CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 00513 num_ents_exported, cubit_version); 00514 assert(num_ents_exported == 1); 00515 00516 //CGM_ATTRIB 11 ENTITY_NAME 2 7 volumeB 7 volumeA 0 0 in unite6.occ 00517 search = "2 7 volumeB 7 volumeA"; 00518 found = findString(filename, search); 00519 00520 assert (found == 1); 00521 remove(filename); 00522 bodies.clean_out(); 00523 gti->bodies(bodies); 00524 //delete all entities 00525 gti->delete_Body(bodies); 00526 00527 gti->get_free_ref_entities(free_entities); 00528 assert(free_entities.size() ==0); 00529 return CUBIT_SUCCESS; 00530 }