MOAB: Mesh Oriented datABase  (version 5.2.1)
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, iBase_EntityHandle** entities, int* entities_alloc,
00097                                          int* entities_size )
00098 {
00099     int this_type = ( dimension == -1 ? iBase_ALL_TYPES : dimension );
00100     int result;
00101 
00102     iMesh_getEntities( instance_, 0, this_type, iMesh_ALL_TOPOLOGIES, entities, entities_alloc, entities_size,
00103                        &result );
00104     PROCESS_ERROR;
00105     RETURNR( iBase_SUCCESS );
00106 }
00107 
00108 int MeshAssocPairSide::get_all_sets( iBase_EntitySetHandle** sets, int* sets_alloc, int* sets_size )
00109 {
00110     int result;
00111 
00112     iMesh_getEntSets( instance_, 0, 0, sets, sets_alloc, sets_size, &result );
00113     PROCESS_ERROR;
00114     RETURNR( iBase_SUCCESS );
00115 }
00116 
00117 int MeshAssocPairSide::get_entities( int dimension, iBase_EntitySetHandle set_handle, iBase_EntityHandle** entities,
00118                                      int* entities_alloc, int* entities_size )
00119 {
00120     int this_type = ( dimension == -1 ? iBase_ALL_TYPES : dimension );
00121     int result;
00122 
00123     iMesh_getEntities( instance_, set_handle, this_type, iMesh_ALL_TOPOLOGIES, entities, entities_alloc, entities_size,
00124                        &result );
00125     PROCESS_ERROR;
00126     RETURNR( iBase_SUCCESS );
00127 }
00128 
00129 int MeshAssocPairSide::get_ents_dims( iBase_EntityHandle* entities, int entities_size, int** ent_types,
00130                                       int* ent_types_alloc, int* ent_types_size )
00131 {
00132     int result;
00133 
00134     iMesh_getEntArrType( instance_, entities, entities_size, ent_types, ent_types_alloc, ent_types_size, &result );
00135     PROCESS_ERROR;
00136     RETURNR( iBase_SUCCESS );
00137 }
00138 
00139 int MeshAssocPairSide::get_related_ents( iBase_EntityHandle** entities, int* entities_alloc, int* entities_size )
00140 {
00141     int result;
00142     iMesh_getEntsByTagsRec( instance_, 0, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &relation_tag, NULL, 1, false,
00143                             entities, entities_alloc, entities_size, &result );
00144     PROCESS_ERROR;
00145     RETURNR( iBase_SUCCESS );
00146 }
00147 
00148 int MeshAssocPairSide::get_related_sets( iBase_EntitySetHandle** sets, int* sets_alloc, int* sets_size )
00149 {
00150     int result;
00151     iMesh_getEntSetsByTagsRec( instance_, 0, &relation_tag, NULL, 1, false, sets, sets_alloc, sets_size, &result );
00152     PROCESS_ERROR;
00153     RETURNR( iBase_SUCCESS );
00154 }
00155 
00156 int MeshAssocPairSide::get_relation_side( iBase_EntityHandle* entities, int num_entities, void* values )
00157 {
00158     int values_alloc = num_entities * sizeof( iBase_EntityHandle );
00159     int values_size;
00160     int result;
00161 
00162     iMesh_getArrData( instance_, entities, num_entities, relation_tag, &values, &values_alloc, &values_size, &result );
00163     PROCESS_ERROR;
00164     RETURNR( iBase_SUCCESS );
00165 }
00166 
00167 int MeshAssocPairSide::get_relation_side( iBase_EntitySetHandle* sets, int num_sets, void* values )
00168 {
00169     char* data       = static_cast< char* >( values );
00170     int values_alloc = sizeof( iBase_EntityHandle );
00171     int values_size;
00172     int result;
00173 
00174     for( int i = 0; i < num_sets; i++ )
00175     {
00176         iMesh_getEntSetData( instance_, sets[i], relation_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00177                              &values_size, &result );
00178         data += values_size;
00179         PROCESS_ERROR;
00180     }
00181     RETURNR( iBase_SUCCESS );
00182 }
00183 
00184 int MeshAssocPairSide::set_relation_side( iBase_EntityHandle* entities, int num_entities, const void* values )
00185 {
00186     int result;
00187 
00188     iMesh_setArrData( instance_, entities, num_entities, relation_tag, static_cast< const char* >( values ),
00189                       num_entities * sizeof( iBase_EntityHandle ), &result );
00190     PROCESS_ERROR;
00191     RETURNR( iBase_SUCCESS );
00192 }
00193 
00194 int MeshAssocPairSide::set_relation_side( iBase_EntitySetHandle* sets, int num_sets, const void* values )
00195 {
00196     const char* data = static_cast< const char* >( values );
00197     int size         = sizeof( iBase_EntityHandle );
00198     int result;
00199 
00200     for( int i = 0; i < num_sets; i++ )
00201     {
00202         iMesh_setEntSetData( instance_, sets[i], relation_tag, data, size, &result );
00203         data += size;
00204         PROCESS_ERROR;
00205     }
00206     RETURNR( iBase_SUCCESS );
00207 }
00208 
00209 int MeshAssocPairSide::rmv_relation_side( iBase_EntityHandle* entities, int num_entities )
00210 {
00211     int result;
00212 
00213     iMesh_rmvArrTag( instance_, entities, num_entities, relation_tag, &result );
00214     PROCESS_ERROR;
00215     RETURNR( iBase_SUCCESS );
00216 }
00217 
00218 int MeshAssocPairSide::rmv_relation_side( iBase_EntitySetHandle* sets, int num_sets )
00219 {
00220     int result;
00221 
00222     for( int i = 0; i < num_sets; i++ )
00223     {
00224         iMesh_rmvEntSetTag( instance_, sets[i], relation_tag, &result );
00225         PROCESS_ERROR;
00226     }
00227 
00228     RETURNR( iBase_SUCCESS );
00229 }
00230 
00231 int MeshAssocPairSide::get_iterator( iBase_EntitySetHandle set, iBase_EntityIterator* iter )
00232 {
00233     int result;
00234     int resilient = 0;
00235     iMesh_initEntIter( instance_, set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, resilient, iter, &result );
00236     RETURNR( iBase_SUCCESS );
00237 }
00238 
00239 int MeshAssocPairSide::get_gids( iBase_EntityHandle* entities, int num_entities, int* values )
00240 {
00241     int values_alloc = num_entities * sizeof( int );
00242     int values_size;
00243     int result;
00244 
00245     iMesh_getArrData( instance_, entities, num_entities, gid_tag, &values, &values_alloc, &values_size, &result );
00246     PROCESS_ERROR;
00247     RETURNR( iBase_SUCCESS );
00248 }
00249 
00250 int MeshAssocPairSide::get_gids( iBase_EntitySetHandle* sets, int num_sets, int* values )
00251 {
00252     char* data       = reinterpret_cast< char* >( values );
00253     int values_alloc = sizeof( int );
00254     int values_size;
00255     int result;
00256 
00257     for( int i = 0; i < num_sets; i++ )
00258     {
00259         iMesh_getEntSetData( instance_, sets[i], gid_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00260                              &values_size, &result );
00261         data += values_size;
00262         PROCESS_ERROR;
00263     }
00264     RETURNR( iBase_SUCCESS );
00265 }
00266 
00267 int MeshAssocPairSide::get_dims( iBase_EntityHandle* entities, int num_entities, int* values )
00268 {
00269     int values_alloc = num_entities * sizeof( int );
00270     int values_size;
00271     int result;
00272 
00273     iMesh_getArrData( instance_, entities, num_entities, dim_tag, &values, &values_alloc, &values_size, &result );
00274     PROCESS_ERROR;
00275     RETURNR( iBase_SUCCESS );
00276 }
00277 
00278 int MeshAssocPairSide::get_dims( iBase_EntitySetHandle* sets, int num_sets, int* values )
00279 {
00280     char* data       = reinterpret_cast< char* >( values );
00281     int values_alloc = sizeof( int );
00282     int values_size;
00283     int result;
00284 
00285     for( int i = 0; i < num_sets; i++ )
00286     {
00287         iMesh_getEntSetData( instance_, sets[i], dim_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00288                              &values_size, &result );
00289         data += values_size;
00290         PROCESS_ERROR;
00291     }
00292     RETURNR( iBase_SUCCESS );
00293 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines