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