MOAB: Mesh Oriented datABase  (version 5.2.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, iBase_EntityHandle** entities, int* entities_alloc,
00091                                          int* entities_size )
00092 {
00093     int this_type = ( dimension == -1 ? iBase_ALL_TYPES : dimension );
00094     int result;
00095 
00096     iGeom_getEntities( instance_, 0, this_type, entities, entities_alloc, entities_size, &result );
00097     PROCESS_ERROR;
00098     RETURNR( iBase_SUCCESS );
00099 }
00100 
00101 int GeomAssocPairSide::get_all_sets( iBase_EntitySetHandle** sets, int* sets_alloc, int* sets_size )
00102 {
00103     int result;
00104 
00105     iGeom_getEntSets( instance_, 0, 0, sets, sets_alloc, sets_size, &result );
00106     PROCESS_ERROR;
00107     RETURNR( iBase_SUCCESS );
00108 }
00109 
00110 int GeomAssocPairSide::get_entities( int dimension, iBase_EntitySetHandle set_handle, iBase_EntityHandle** entities,
00111                                      int* entities_alloc, int* entities_size )
00112 {
00113     int this_type = ( dimension == -1 ? iBase_ALL_TYPES : dimension );
00114     int result;
00115 
00116     iGeom_getEntities( instance_, set_handle, this_type, entities, entities_alloc, entities_size, &result );
00117     PROCESS_ERROR;
00118     RETURNR( iBase_SUCCESS );
00119 }
00120 
00121 int GeomAssocPairSide::get_ents_dims( iBase_EntityHandle* entities, int entities_size, int** ent_types,
00122                                       int* ent_types_alloc, int* ent_types_size )
00123 {
00124     int result;
00125 
00126     iGeom_getArrType( instance_, entities, entities_size, ent_types, ent_types_alloc, ent_types_size, &result );
00127     PROCESS_ERROR;
00128     RETURNR( iBase_SUCCESS );
00129 }
00130 
00131 int GeomAssocPairSide::get_related_ents( iBase_EntityHandle** /*entities*/, int* /*entities_alloc*/,
00132                                          int* /*entities_size*/ )
00133 {
00134     RETURNR( iBase_FAILURE );
00135 }
00136 
00137 int GeomAssocPairSide::get_related_sets( iBase_EntitySetHandle** /*sets*/, int* /*sets_alloc*/, int* /*sets_size*/ )
00138 {
00139     RETURNR( iBase_FAILURE );
00140 }
00141 
00142 int GeomAssocPairSide::get_relation_side( iBase_EntityHandle* entities, int num_entities, void* values )
00143 {
00144     int values_alloc = num_entities * sizeof( iBase_EntityHandle );
00145     int values_size;
00146     int result;
00147 
00148     iGeom_getArrData( instance_, entities, num_entities, relation_tag, &values, &values_alloc, &values_size, &result );
00149     PROCESS_ERROR;
00150     RETURNR( iBase_SUCCESS );
00151 }
00152 
00153 int GeomAssocPairSide::get_relation_side( iBase_EntitySetHandle* sets, int num_sets, void* values )
00154 {
00155     char* data       = static_cast< char* >( values );
00156     int values_alloc = sizeof( iBase_EntityHandle );
00157     int values_size;
00158     int result;
00159 
00160     for( int i = 0; i < num_sets; i++ )
00161     {
00162         iGeom_getEntSetData( instance_, sets[i], relation_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00163                              &values_size, &result );
00164         data += values_size;
00165         PROCESS_ERROR;
00166     }
00167     RETURNR( iBase_SUCCESS );
00168 }
00169 
00170 int GeomAssocPairSide::set_relation_side( iBase_EntityHandle* entities, int num_entities, const void* values )
00171 {
00172     int result;
00173 
00174     iGeom_setArrData( instance_, entities, num_entities, relation_tag, static_cast< const char* >( values ),
00175                       num_entities * sizeof( iBase_EntityHandle ), &result );
00176     PROCESS_ERROR;
00177     RETURNR( iBase_SUCCESS );
00178 }
00179 
00180 int GeomAssocPairSide::set_relation_side( iBase_EntitySetHandle* sets, int num_sets, const void* values )
00181 {
00182     const char* data = static_cast< const char* >( values );
00183     int size         = sizeof( iBase_EntityHandle );
00184     int result;
00185 
00186     for( int i = 0; i < num_sets; i++ )
00187     {
00188         iGeom_setEntSetData( instance_, sets[i], relation_tag, data, size, &result );
00189         data += size;
00190         PROCESS_ERROR;
00191     }
00192     RETURNR( iBase_SUCCESS );
00193 }
00194 
00195 int GeomAssocPairSide::rmv_relation_side( iBase_EntityHandle* entities, int num_entities )
00196 {
00197     int result;
00198 
00199     iGeom_rmvArrTag( instance_, entities, num_entities, relation_tag, &result );
00200     PROCESS_ERROR;
00201     RETURNR( iBase_SUCCESS );
00202 }
00203 
00204 int GeomAssocPairSide::rmv_relation_side( iBase_EntitySetHandle* sets, int num_sets )
00205 {
00206     int result;
00207 
00208     for( int i = 0; i < num_sets; i++ )
00209     {
00210         iGeom_rmvEntSetTag( instance_, sets[i], relation_tag, &result );
00211         PROCESS_ERROR;
00212     }
00213 
00214     RETURNR( iBase_SUCCESS );
00215 }
00216 
00217 int GeomAssocPairSide::get_iterator( iBase_EntitySetHandle set, iBase_EntityIterator* iter )
00218 {
00219     int result;
00220     iGeom_initEntIter( instance_, set, iBase_ALL_TYPES, iter, &result );
00221     RETURNR( iBase_SUCCESS );
00222 }
00223 
00224 int GeomAssocPairSide::get_gids( iBase_EntityHandle* entities, int num_entities, int* values )
00225 {
00226     int values_alloc = num_entities * sizeof( int );
00227     int values_size;
00228     int result;
00229 
00230     iGeom_getArrData( instance_, entities, num_entities, gid_tag, reinterpret_cast< void** >( &values ), &values_alloc,
00231                       &values_size, &result );
00232     PROCESS_ERROR;
00233     RETURNR( iBase_SUCCESS );
00234 }
00235 
00236 int GeomAssocPairSide::get_gids( iBase_EntitySetHandle* sets, int num_sets, int* values )
00237 {
00238     char* data       = reinterpret_cast< char* >( values );
00239     int values_alloc = sizeof( int );
00240     int values_size;
00241     int result;
00242 
00243     for( int i = 0; i < num_sets; i++ )
00244     {
00245         iGeom_getEntSetData( instance_, sets[i], gid_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00246                              &values_size, &result );
00247         data += values_size;
00248         PROCESS_ERROR;
00249     }
00250     RETURNR( iBase_SUCCESS );
00251 }
00252 
00253 int GeomAssocPairSide::get_dims( iBase_EntityHandle* /*entities*/, int /*num_entities*/, int* /*values*/ )
00254 {
00255     RETURNR( iBase_FAILURE );
00256 }
00257 
00258 int GeomAssocPairSide::get_dims( iBase_EntitySetHandle* /*sets*/, int /*num_sets*/, int* /*values*/ )
00259 {
00260     RETURNR( iBase_FAILURE );
00261 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines