cgma
subtract.cpp
Go to the documentation of this file.
00001 
00010 #undef NDEBUG
00011 #include <cassert>
00012 
00013 #include "GeometryModifyTool.hpp"
00014 #include "GeometryQueryTool.hpp"
00015 #include "OCCQueryEngine.hpp"
00016 #include "CubitMessage.hpp"
00017 #include "Body.hpp"
00018 #include "RefVolume.hpp"
00019 #include "RefFace.hpp"
00020 #include "RefEdge.hpp"
00021 #include "RefVertex.hpp"
00022 #include "CastTo.hpp"
00023 #include "OCCModifyEngine.hpp"
00024 #include "OCCLump.hpp"
00025 #include "OCCBody.hpp"
00026 #include "OCCSurface.hpp"
00027 #include "OCCCurve.hpp"
00028 #include "OCCShell.hpp"
00029 #include "TopoDS_Shape.hxx"
00030 #include "InitCGMA.hpp"
00031 #include "CubitCompat.hpp"
00032 
00033 #ifndef SRCDIR
00034 # define SRCDIR .
00035 #endif
00036 
00037 #define STRINGIFY_(X) #X
00038 #define STRINGIFY(X) STRINGIFY_(X)
00039 #define SRCPATH STRINGIFY(SRCDIR) "/"
00040 
00041 // forward declare some functions used and defined later
00042 CubitStatus read_geometry(int, const char **, bool local = false);
00043 CubitStatus make_Point();
00044 // macro for printing a separator line
00045 #define PRINT_SEPARATOR   PRINT_INFO("=======================================\n");
00046 
00047 
00048 // main program - initialize, then send to proper function
00049 int main (int argc, char **argv)
00050 {
00051   CubitStatus status = InitCGMA::initialize_cgma("OCC");
00052   if (CUBIT_SUCCESS != status) return 1;
00053 
00054   //Do make point.
00055   status = make_Point();
00056   if (status == CUBIT_FAILURE) 
00057      PRINT_INFO("Operation Failed");
00058 
00059   int ret_val = ( CubitMessage::instance()->error_count() );
00060   if ( ret_val != 0 )
00061   {
00062     PRINT_ERROR("Errors found during Mergechk session.\n");
00063   }
00064   else
00065     ret_val = 0;
00066 
00067   return ret_val;
00068   
00069 }
00070 
00075 CubitStatus read_geometry(int num_files, const char **argv, bool local)
00076 {
00077   CubitStatus status = CUBIT_SUCCESS;
00078   GeometryQueryTool *gti = GeometryQueryTool::instance();
00079   assert(gti);
00080   int i;
00081   
00082   PRINT_SEPARATOR;
00083 
00084   for (i = 0; i < num_files; i++) {
00085     std::string filename( local ? "./" : SRCPATH );
00086     filename += argv[i];
00087     status = CubitCompat_import_solid_model(filename.c_str(), "OCC");
00088     if (status != CUBIT_SUCCESS) {
00089       PRINT_ERROR("Problems reading geometry file %s.\n", filename.c_str());
00090       abort();
00091     }
00092   }
00093   PRINT_SEPARATOR;
00094 
00095   return CUBIT_SUCCESS;
00096 }
00097 
00098 CubitStatus make_Point()
00099 {
00100   GeometryQueryTool *gti = GeometryQueryTool::instance();
00101   GeometryModifyTool *gmti = GeometryModifyTool::instance();
00102 
00103   OCCQueryEngine::instance();
00104   //OCCModifyEngine* ome = OCCModifyEngine::instance();
00105 
00106   //test for tweak fillet and chamfer
00107   Body* body = gmti->brick(10, 10, 10);
00108   Body* body2 = gmti->brick(20,20,1);
00109   DLIList<Body*> from_bodies, new_bodies;
00110   from_bodies.append(body);
00111   CubitStatus rsl = gmti->subtract(body2, from_bodies, new_bodies,
00112                        CUBIT_TRUE, CUBIT_FALSE);
00113 
00114   int num_ents_exported=0;
00115   DLIList<RefEntity*> ref_entities;
00116   const CubitString cubit_version="10.2";
00117   const char * filename = "subtract.occ";
00118   const char * filetype = "OCC";
00119 
00120   gti->get_free_ref_entities(ref_entities);
00121   for(int i = 0; i < ref_entities.size(); i++)
00122     gti->delete_RefEntity(ref_entities.get_and_step());
00123 
00124   ref_entities.clean_out();
00125   rsl = CubitCompat_export_solid_model(ref_entities, filename, filetype,
00126                                  num_ents_exported, cubit_version);
00127   assert(num_ents_exported == 1);
00128 
00129   DLIList<Body*> bodies;
00130   gti->bodies(bodies);
00131   //delete all entities
00132   gti->delete_Body(bodies);
00133 
00134   DLIList<RefEntity*>  free_entities;
00135   gti->get_free_ref_entities(free_entities);
00136   for(int i = 0; i < free_entities.size(); i++)
00137     gti->delete_RefEntity(free_entities.get_and_step());
00138 
00139   const char *argv = "subtract.occ";
00140   rsl = read_geometry(1, &argv, true);
00141   if (rsl == CUBIT_FAILURE) exit(1);
00142 
00143   bodies.clean_out();
00144   gti->bodies(bodies);
00145   assert(bodies.size() == 1);
00146   //delete all entities
00147   gti->delete_Body(bodies);
00148   
00149   free_entities.clean_out();
00150   gti->get_free_ref_entities(free_entities);
00151   for(int i = 0; i < free_entities.size(); i++)
00152     gti->delete_RefEntity(free_entities.get_and_step());
00153 
00154   remove(filename);
00155   return CUBIT_SUCCESS;
00156 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines