cgma
merge_test.cpp
Go to the documentation of this file.
00001 #include "MergeTool.hpp"
00002 #include "InitCGMA.hpp"
00003 #include "GeometryModifyTool.hpp"
00004 #include "GeometryQueryTool.hpp"
00005 #include "Body.hpp"
00006 #include "CGMApp.hpp"
00007 #include "CubitAttribManager.hpp"
00008 #include "CubitCompat.hpp"
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 
00013 #if defined (TEST_OCC)
00014 #  define ENGINE "OCC"
00015 #  define FORMAT "OCC"
00016 #elif defined (TEST_FACET)
00017 #  define ENGINE "FACET"
00018 #  define FORMAT "FACET"
00019 #else
00020 #  error "Which engine to test?"
00021 #endif
00022 #define FILE_NAME "merge_test." FORMAT
00023 
00024 #define ASSERT(A) if (!(A)) failed(#A,__FILE__,__LINE__)
00025 void failed( const char* A, const char* FILE, int LINE )
00026 {
00027   printf( "Condition failed at %s:%d : %s\n", FILE, LINE, A );
00028   abort();
00029 }
00030 
00031 RefFace* shared_face( Body* bod1, Body* bod2 );
00032 
00033 int main()
00034 {
00035   CubitStatus s = InitCGMA::initialize_cgma( ENGINE );
00036   ASSERT(s);
00037   CGMApp::instance()->attrib_manager()->auto_flag( CUBIT_TRUE );
00038 
00039   Body *brick1, *brick2;
00040   brick1 = GeometryModifyTool::instance()->brick( 1, 1, 1 );
00041   brick2 = GeometryModifyTool::instance()->brick( 1, 1, 1 );
00042   ASSERT(brick1 && brick2);
00043   
00044   DLIList<Body*> bods;
00045   bods.append(brick2);
00046   s = GeometryQueryTool::instance()->translate( bods, CubitVector(1,0,0) );
00047   ASSERT(s);
00048   
00049   DLIList<Body*> merge_list;
00050   merge_list.append( brick1 );
00051   merge_list.append( brick2 );
00052   s = MergeTool::instance()->merge_bodies( merge_list );
00053   ASSERT(s);
00054   
00055   ASSERT( shared_face( brick1, brick2 ) );
00056   
00057   int junk;
00058   DLIList<RefEntity*> export_list;
00059   export_list.append( brick1 );
00060   export_list.append( brick2 );
00061   s = CubitCompat_export_solid_model( export_list,
00062                                       FILE_NAME,
00063                                       FORMAT,
00064                                       junk,
00065                                       CubitString(__FILE__) );
00066   ASSERT(s);
00067   
00068   
00069   DLIList<RefEntity*> import_list;
00070   s = CubitCompat_import_solid_model( FILE_NAME,
00071                                       FORMAT,
00072                                       NULL,
00073                                       CUBIT_FALSE,
00074                                       CUBIT_TRUE,
00075                                       CUBIT_TRUE,
00076                                       CUBIT_TRUE,
00077                                       CUBIT_TRUE,
00078                                       CUBIT_TRUE,
00079                                       &import_list );
00080   ASSERT(s);
00081   remove( FILE_NAME );
00082   
00083   DLIList<Body*> import_bodies;
00084   CAST_LIST( import_list, import_bodies, Body );
00085   ASSERT( 2 == import_bodies.size() );
00086   
00087   Body* new_bod1 = import_bodies.get_and_step();
00088   Body* new_bod2 = import_bodies.get_and_step();
00089   ASSERT( brick1 != new_bod1 && brick1 != new_bod2 );
00090   ASSERT( brick2 != new_bod1 && brick2 != new_bod2 );
00091   ASSERT( shared_face( new_bod1, new_bod2 ) );
00092   
00093   return 0;
00094 }
00095 
00096 RefFace* shared_face( Body* b1, Body* b2 )
00097 {
00098   DLIList<RefFace*> faces1, faces2;
00099   b1->ref_faces( faces1 );
00100   b2->ref_faces( faces2 );
00101   faces1.intersect( faces2 );
00102   if (faces1.size() == 1)
00103     return faces1.get();
00104   else
00105     return 0;
00106 }
00107 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines