cgma
|
00001 00010 #undef NDEBUG 00011 #include <cassert> 00012 #include <string> 00013 #include <cctype> 00014 #include <iostream> 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 #ifdef HAVE_OCC 00038 #define FILENAME "s5.stp" 00039 #endif 00040 // forward declare some functions used and defined later 00041 CubitStatus read_geometry(int, char **, bool local = false); 00042 CubitStatus make_Point(); 00043 // macro for printing a separator line 00044 #define PRINT_SEPARATOR PRINT_INFO("=======================================\n"); 00045 00046 int findString(const char *filename, std::string search) 00047 { 00048 std::ifstream Myfile; 00049 Myfile.open (filename); 00050 int found = 0; 00051 std::string line; 00052 size_t offset; 00053 if(Myfile.is_open()) 00054 { 00055 while(!Myfile.eof()) 00056 { 00057 getline(Myfile,line); 00058 if ((offset = line.find(search, 0)) != std::string::npos) 00059 found ++; 00060 } 00061 Myfile.close(); 00062 } 00063 return found; 00064 } 00065 // main program - initialize, then send to proper function 00066 int main (int argc, char **argv) 00067 { 00068 CubitStatus status = InitCGMA::initialize_cgma(); 00069 if (CUBIT_SUCCESS != status) return 1; 00070 00071 //Do make point. 00072 status = make_Point(); 00073 if (status == CUBIT_FAILURE) 00074 PRINT_INFO("Operation Failed"); 00075 00076 int ret_val = ( CubitMessage::instance()->error_count() ); 00077 if ( ret_val > 0 ) 00078 { 00079 PRINT_ERROR("Errors found during Mergechk session.\n"); 00080 } 00081 return ret_val; 00082 00083 } 00084 00085 std::string type_from_file_name( const std::string& filename ) 00086 { 00087 size_t dot_pos = filename.find_last_of( '.' ); 00088 if (dot_pos == std::string::npos) 00089 return std::string(); 00090 00091 std::string extension = filename.substr( dot_pos + 1 ); 00092 std::transform( extension.begin(), extension.end(), extension.begin(), ::tolower ); 00093 if (extension == "occ" || extension == "brep") 00094 return "OCC"; 00095 else if (extension == "step" || extension == "stp") 00096 return "STEP"; 00097 else if (extension == "iges" || extension == "igs") 00098 return "IGES"; 00099 else 00100 return std::string(); 00101 } 00102 00107 CubitStatus read_geometry(int num_files, const char **argv, bool local) 00108 { 00109 CubitStatus status = CUBIT_SUCCESS; 00110 GeometryQueryTool *gti = GeometryQueryTool::instance(); 00111 assert(gti); 00112 int i; 00113 00114 PRINT_SEPARATOR; 00115 00116 for (i = 0; i < num_files; i++) { 00117 std::string type = type_from_file_name( argv[i] ); 00118 if (type.empty()) // just guess OCC 00119 type = "OCC"; 00120 std::string filename( local ? "./" : SRCPATH ); 00121 char const* local_name = argv[i]; 00122 filename += local_name; 00123 status = CubitCompat_import_solid_model(filename.c_str(), type.c_str()); 00124 if (status != CUBIT_SUCCESS) { 00125 PRINT_ERROR("Problems reading geometry file %s.\n", filename.c_str()); 00126 abort(); 00127 } 00128 } 00129 PRINT_SEPARATOR; 00130 00131 return CUBIT_SUCCESS; 00132 } 00133 00134 CubitStatus make_Point() 00135 { 00136 GeometryQueryTool *gti = GeometryQueryTool::instance(); 00137 GeometryModifyTool *gmti = GeometryModifyTool::instance(); 00138 00139 DLIList<Body*> bodies, single_body, all_bodies, neighbor_list, new_bodies; 00140 DLIList<RefEntity*> free_entities; 00141 00142 const char *argstep = FILENAME; 00143 CubitStatus stat = read_geometry(1, &argstep, false); 00144 //Constructed 12 Volumes: 8 to 19 00145 if (stat == CUBIT_FAILURE) exit(1); 00146 00147 //get all the bodies, use bodies 1-6 to unite and use united body to 00148 //subtract from body 7. 00149 gti->bodies(bodies); 00150 Body* brick = bodies.pop(); 00151 all_bodies.append(brick); 00152 00153 stat = gmti->unite(bodies, single_body, CUBIT_FALSE); 00154 assert(CUBIT_SUCCESS == stat && single_body.size() == 1); 00155 00156 stat = gmti->subtract(single_body.get(), all_bodies, new_bodies, CUBIT_FALSE,CUBIT_FALSE); 00157 assert(CUBIT_SUCCESS == stat); 00158 00159 std::cout << "Number of resulting bodies = " << new_bodies.size() << std::endl; 00160 assert(new_bodies.size() == 1); 00161 //delete all entities 00162 bodies.clean_out(); 00163 gti->bodies(bodies); 00164 gti->delete_Body(bodies); 00165 00166 free_entities.clean_out(); 00167 gti->get_free_ref_entities(free_entities); 00168 assert(free_entities.size() ==0); 00169 return CUBIT_SUCCESS; 00170 }