MOAB: Mesh Oriented datABase  (version 5.4.0)
MeshAssocPairSide.cpp
Go to the documentation of this file.
00001 #include "MeshAssocPairSide.hpp"
00002 
00003 #include <cstring>
00004 #include <sstream>
00005 #include <string>
00006 
00007 #include <iMesh_extensions.h>
00008 
00009 #include "Lasso.hpp"
00010 #include "iRel_Lasso.hpp"
00011 
00012 #define PROCESS_ERROR                                           \
00013     do                                                          \
00014     {                                                           \
00015         if( iBase_SUCCESS != result )                           \
00016         {                                                       \
00017             char this_descr[120];                               \
00018             iMesh_getDescription( instance_, this_descr, 120 ); \
00019             ERRORR( result, this_descr );                       \
00020         }                                                       \
00021     } while( false )
00022 
00023 // Redefine LASSOI
00024 #undef LASSOI
00025 #define LASSOI lasso_instance( relation )
00026 
00027 static const char* GLOBAL_ID_TAG_NAME      = "GLOBAL_ID";
00028 static const char* MESH_DIMENSION_TAG_NAME = "GEOM_DIMENSION";
00029 static const char* RELATION_TAG_NAME       = "__MESH_ASSOCIATION";
00030 
00031 MeshAssocPairSide::MeshAssocPairSide( iRel_Instance p_relation, iBase_Instance p_instance, int p_id )
00032     : relation( p_relation ), instance_( reinterpret_cast< iMesh_Instance >( p_instance ) ), id( p_id )
00033 {
00034     int result;
00035 
00036     create_relation_side();
00037 
00038     iMesh_getTagHandle( instance_, GLOBAL_ID_TAG_NAME, &gid_tag, &result, strlen( GLOBAL_ID_TAG_NAME ) );
00039     if( result == iBase_TAG_NOT_FOUND )
00040     {
00041         iMesh_createTag( instance_, GLOBAL_ID_TAG_NAME, 1, iBase_INTEGER, &gid_tag, &result,
00042                          strlen( GLOBAL_ID_TAG_NAME ) );
00043     }
00044 
00045     iMesh_getTagHandle( instance_, MESH_DIMENSION_TAG_NAME, &dim_tag, &result, strlen( MESH_DIMENSION_TAG_NAME ) );
00046     if( result == iBase_TAG_NOT_FOUND ) dim_tag = NULL;
00047 }
00048 
00049 MeshAssocPairSide::~MeshAssocPairSide()
00050 {
00051     destroy_relation_side();
00052 }
00053 
00054 iBase_Instance MeshAssocPairSide::instance() const
00055 {
00056     return instance_;
00057 }
00058 
00059 iRel_IfaceType MeshAssocPairSide::type() const
00060 {
00061     return iRel_IMESH_IFACE;
00062 }
00063 
00064 int MeshAssocPairSide::create_relation_side()
00065 {
00066     int result;
00067     std::stringstream ss;
00068     ss << RELATION_TAG_NAME << id;
00069     std::string rel_tag_name( ss.str() );
00070 
00071     iMesh_getTagHandle( instance_, rel_tag_name.c_str(), &relation_tag, &result, rel_tag_name.size() );
00072     if( result == iBase_TAG_NOT_FOUND )
00073     {
00074         iMesh_createTag( instance_, rel_tag_name.c_str(), 1, iBase_ENTITY_HANDLE, &relation_tag, &result,
00075                          rel_tag_name.size() );
00076     }
00077 
00078     PROCESS_ERROR;
00079     RETURNR( iBase_SUCCESS );
00080 }
00081 
00082 int MeshAssocPairSide::destroy_relation_side()
00083 {
00084     if( relation_tag )
00085     {
00086         int result;
00087 
00088         iMesh_destroyTag( instance_, relation_tag, true, &result );
00089         relation_tag = NULL;
00090 
00091         PROCESS_ERROR;
00092     }
00093     RETURNR( iBase_SUCCESS );
00094 }
00095 
00096 int MeshAssocPairSide::get_all_entities( int dimension,
00097                                          iBase_EntityHandle** entities,
00098                                          int* entities_alloc,
00099                                          int* entities_size )
00100 {
00101     int this_type = ( dimension == -1 ? iBase_ALL_TYPES : dimension );
00102     int result;
00103 
00104     iMesh_getEntities( instance_, 0, this_type, iMesh_ALL_TOPOLOGIES, entities, entities_alloc, entities_size,
00105                        &result );
00106     PROCESS_ERROR;
00107     RETURNR( iBase_SUCCESS );
00108 }
00109 
00110 int MeshAssocPairSide::get_all_sets( iBase_EntitySetHandle** sets, int* sets_alloc, int* sets_size )
00111 {
00112     int result;
00113 
00114     iMesh_getEntSets( instance_, 0, 0, sets, sets_alloc, sets_size, &result );
00115     PROCESS_ERROR;
00116     RETURNR( iBase_SUCCESS );
00117 }
00118 
00119 int MeshAssocPairSide::get_entities( int dimension,
00120                                      iBase_EntitySetHandle set_handle,
00121                                      iBase_EntityHandle** entities,
00122                                      int* entities_alloc,
00123                                      int* entities_size )
00124 {
00125     int this_type = ( dimension == -1 ? iBase_ALL_TYPES : dimension );
00126     int result;
00127 
00128     iMesh_getEntities( instance_, set_handle, this_type, iMesh_ALL_TOPOLOGIES, entities, entities_alloc, entities_size,
00129                        &result );
00130     PROCESS_ERROR;
00131     RETURNR( iBase_SUCCESS );
00132 }
00133 
00134 int MeshAssocPairSide::get_ents_dims( iBase_EntityHandle* entities,
00135                                       int entities_size,
00136                                       int** ent_types,
00137                                       int* ent_types_alloc,
00138                                       int* ent_types_size )
00139 {
00140     int result;
00141 
00142     iMesh_getEntArrType( instance_, entities, entities_size, ent_types, ent_types_alloc, ent_types_size, &result );
00143     PROCESS_ERROR;
00144     RETURNR( iBase_SUCCESS );
00145 }
00146 
00147 int MeshAssocPairSide::get_related_ents( iBase_EntityHandle** entities, int* entities_alloc, int* entities_size )
00148 {
00149     int result;
00150     iMesh_getEntsByTagsRec( instance_, 0, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &relation_tag, NULL, 1, false,
00151                             entities, entities_alloc, entities_size, &result );
00152     PROCESS_ERROR;
00153     RETURNR( iBase_SUCCESS );
00154 }
00155 
00156 int MeshAssocPairSide::get_related_sets( iBase_EntitySetHandle** sets, int* sets_alloc, int* sets_size )
00157 {
00158     int result;
00159     iMesh_getEntSetsByTagsRec( instance_, 0, &relation_tag, NULL, 1, false, sets, sets_alloc, sets_size, &result );
00160     PROCESS_ERROR;
00161     RETURNR( iBase_SUCCESS );
00162 }
00163 
00164 int MeshAssocPairSide::get_relation_side( iBase_EntityHandle* entities, int num_entities, void* values )
00165 {
00166     int values_alloc = num_entities * sizeof( iBase_EntityHandle );
00167     int values_size;
00168     int result;
00169 
00170     iMesh_getArrData( instance_, entities, num_entities, relation_tag, &values, &values_alloc, &values_size, &result );
00171     PROCESS_ERROR;
00172     RETURNR( iBase_SUCCESS );
00173 }
00174 
00175 int MeshAssocPairSide::get_relation_side( iBase_EntitySetHandle* sets, int num_sets, void* values )
00176 {
00177     char* data       = static_cast< char* >( values );
00178     int values_alloc = sizeof( iBase_EntityHandle );
00179     int values_size;
00180     int result;
00181 
00182     for( int i = 0; i < num_sets; i++ )
00183     {
00184         iMesh_getEntSetData( instance_, sets[i], relation_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00185                              &values_size, &result );
00186         data += values_size;
00187         PROCESS_ERROR;
00188     }
00189     RETURNR( iBase_SUCCESS );
00190 }
00191 
00192 int MeshAssocPairSide::set_relation_side( iBase_EntityHandle* entities, int num_entities, const void* values )
00193 {
00194     int result;
00195 
00196     iMesh_setArrData( instance_, entities, num_entities, relation_tag, static_cast< const char* >( values ),
00197                       num_entities * sizeof( iBase_EntityHandle ), &result );
00198     PROCESS_ERROR;
00199     RETURNR( iBase_SUCCESS );
00200 }
00201 
00202 int MeshAssocPairSide::set_relation_side( iBase_EntitySetHandle* sets, int num_sets, const void* values )
00203 {
00204     const char* data = static_cast< const char* >( values );
00205     int size         = sizeof( iBase_EntityHandle );
00206     int result;
00207 
00208     for( int i = 0; i < num_sets; i++ )
00209     {
00210         iMesh_setEntSetData( instance_, sets[i], relation_tag, data, size, &result );
00211         data += size;
00212         PROCESS_ERROR;
00213     }
00214     RETURNR( iBase_SUCCESS );
00215 }
00216 
00217 int MeshAssocPairSide::rmv_relation_side( iBase_EntityHandle* entities, int num_entities )
00218 {
00219     int result;
00220 
00221     iMesh_rmvArrTag( instance_, entities, num_entities, relation_tag, &result );
00222     PROCESS_ERROR;
00223     RETURNR( iBase_SUCCESS );
00224 }
00225 
00226 int MeshAssocPairSide::rmv_relation_side( iBase_EntitySetHandle* sets, int num_sets )
00227 {
00228     int result;
00229 
00230     for( int i = 0; i < num_sets; i++ )
00231     {
00232         iMesh_rmvEntSetTag( instance_, sets[i], relation_tag, &result );
00233         PROCESS_ERROR;
00234     }
00235 
00236     RETURNR( iBase_SUCCESS );
00237 }
00238 
00239 int MeshAssocPairSide::get_iterator( iBase_EntitySetHandle set, iBase_EntityIterator* iter )
00240 {
00241     int result;
00242     int resilient = 0;
00243     iMesh_initEntIter( instance_, set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, resilient, iter, &result );
00244     RETURNR( iBase_SUCCESS );
00245 }
00246 
00247 int MeshAssocPairSide::get_gids( iBase_EntityHandle* entities, int num_entities, int* values )
00248 {
00249     int values_alloc = num_entities * sizeof( int );
00250     int values_size;
00251     int result;
00252 
00253     iMesh_getArrData( instance_, entities, num_entities, gid_tag, &values, &values_alloc, &values_size, &result );
00254     PROCESS_ERROR;
00255     RETURNR( iBase_SUCCESS );
00256 }
00257 
00258 int MeshAssocPairSide::get_gids( iBase_EntitySetHandle* sets, int num_sets, int* values )
00259 {
00260     char* data       = reinterpret_cast< char* >( values );
00261     int values_alloc = sizeof( int );
00262     int values_size;
00263     int result;
00264 
00265     for( int i = 0; i < num_sets; i++ )
00266     {
00267         iMesh_getEntSetData( instance_, sets[i], gid_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00268                              &values_size, &result );
00269         data += values_size;
00270         PROCESS_ERROR;
00271     }
00272     RETURNR( iBase_SUCCESS );
00273 }
00274 
00275 int MeshAssocPairSide::get_dims( iBase_EntityHandle* entities, int num_entities, int* values )
00276 {
00277     int values_alloc = num_entities * sizeof( int );
00278     int values_size;
00279     int result;
00280 
00281     iMesh_getArrData( instance_, entities, num_entities, dim_tag, &values, &values_alloc, &values_size, &result );
00282     PROCESS_ERROR;
00283     RETURNR( iBase_SUCCESS );
00284 }
00285 
00286 int MeshAssocPairSide::get_dims( iBase_EntitySetHandle* sets, int num_sets, int* values )
00287 {
00288     char* data       = reinterpret_cast< char* >( values );
00289     int values_alloc = sizeof( int );
00290     int values_size;
00291     int result;
00292 
00293     for( int i = 0; i < num_sets; i++ )
00294     {
00295         iMesh_getEntSetData( instance_, sets[i], dim_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00296                              &values_size, &result );
00297         data += values_size;
00298         PROCESS_ERROR;
00299     }
00300     RETURNR( iBase_SUCCESS );
00301 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines