MOAB: Mesh Oriented datABase  (version 5.2.1)
FBGeomAssocPairSide.cpp
Go to the documentation of this file.
00001 #include "FBGeomAssocPairSide.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             FBiGeom_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  = "__FBGEOM_ASSOCIATION";
00027 
00028 FBGeomAssocPairSide::FBGeomAssocPairSide( iRel_Instance p_relation, iBase_Instance p_instance, int p_id )
00029     : relation( p_relation ), instance_( reinterpret_cast< FBiGeom_Instance >( p_instance ) ), id( p_id )
00030 {
00031     int result;
00032 
00033     create_relation_side();
00034 
00035     FBiGeom_getTagHandle( instance_, GLOBAL_ID_TAG_NAME, &gid_tag, &result, strlen( GLOBAL_ID_TAG_NAME ) );
00036     if( result == iBase_TAG_NOT_FOUND )
00037     {
00038         FBiGeom_createTag( instance_, GLOBAL_ID_TAG_NAME, 1, iBase_INTEGER, &gid_tag, &result,
00039                            strlen( GLOBAL_ID_TAG_NAME ) );
00040     }
00041 }
00042 
00043 FBGeomAssocPairSide::~FBGeomAssocPairSide()
00044 {
00045     destroy_relation_side();
00046 }
00047 
00048 iBase_Instance FBGeomAssocPairSide::instance() const
00049 {
00050     return instance_;
00051 }
00052 
00053 iRel_IfaceType FBGeomAssocPairSide::type() const
00054 {
00055     return iRel_FBIGEOM_IFACE;
00056 }
00057 
00058 int FBGeomAssocPairSide::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     FBiGeom_getTagHandle( instance_, rel_tag_name.c_str(), &relation_tag, &result, rel_tag_name.size() );
00066     if( result == iBase_TAG_NOT_FOUND )
00067     {
00068         FBiGeom_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 FBGeomAssocPairSide::destroy_relation_side()
00077 {
00078     if( relation_tag )
00079     {
00080         int result;
00081 
00082         FBiGeom_destroyTag( instance_, relation_tag, true, &result );
00083         relation_tag = NULL;
00084 
00085         PROCESS_ERROR;
00086     }
00087     RETURNR( iBase_SUCCESS );
00088 }
00089 
00090 int FBGeomAssocPairSide::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     FBiGeom_getEntities( instance_, 0, this_type, entities, entities_alloc, entities_size, &result );
00097     PROCESS_ERROR;
00098     RETURNR( iBase_SUCCESS );
00099 }
00100 
00101 int FBGeomAssocPairSide::get_all_sets( iBase_EntitySetHandle** sets, int* sets_alloc, int* sets_size )
00102 {
00103     int result;
00104 
00105     FBiGeom_getEntSets( instance_, 0, 0, sets, sets_alloc, sets_size, &result );
00106     PROCESS_ERROR;
00107     RETURNR( iBase_SUCCESS );
00108 }
00109 
00110 int FBGeomAssocPairSide::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     FBiGeom_getEntities( instance_, set_handle, this_type, entities, entities_alloc, entities_size, &result );
00117     PROCESS_ERROR;
00118     RETURNR( iBase_SUCCESS );
00119 }
00120 
00121 int FBGeomAssocPairSide::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     FBiGeom_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 FBGeomAssocPairSide::get_related_ents( iBase_EntityHandle** /*entities*/, int* /*entities_alloc*/,
00132                                            int* /*entities_size*/ )
00133 {
00134     RETURNR( iBase_FAILURE );
00135 }
00136 
00137 int FBGeomAssocPairSide::get_related_sets( iBase_EntitySetHandle** /*sets*/, int* /*sets_alloc*/, int* /*sets_size*/ )
00138 {
00139     RETURNR( iBase_FAILURE );
00140 }
00141 
00142 int FBGeomAssocPairSide::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     FBiGeom_getArrData( instance_, entities, num_entities, relation_tag, &values, &values_alloc, &values_size,
00149                         &result );
00150     PROCESS_ERROR;
00151     RETURNR( iBase_SUCCESS );
00152 }
00153 
00154 int FBGeomAssocPairSide::get_relation_side( iBase_EntitySetHandle* sets, int num_sets, void* values )
00155 {
00156     char* data       = static_cast< char* >( values );
00157     int values_alloc = sizeof( iBase_EntityHandle );
00158     int values_size;
00159     int result;
00160 
00161     for( int i = 0; i < num_sets; i++ )
00162     {
00163         FBiGeom_getEntSetData( instance_, sets[i], relation_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00164                                &values_size, &result );
00165         data += values_size;
00166         PROCESS_ERROR;
00167     }
00168     RETURNR( iBase_SUCCESS );
00169 }
00170 
00171 int FBGeomAssocPairSide::set_relation_side( iBase_EntityHandle* entities, int num_entities, const void* values )
00172 {
00173     int result;
00174 
00175     FBiGeom_setArrData( instance_, entities, num_entities, relation_tag, static_cast< const char* >( values ),
00176                         num_entities * sizeof( iBase_EntityHandle ), &result );
00177     PROCESS_ERROR;
00178     RETURNR( iBase_SUCCESS );
00179 }
00180 
00181 int FBGeomAssocPairSide::set_relation_side( iBase_EntitySetHandle* sets, int num_sets, const void* values )
00182 {
00183     const char* data = static_cast< const char* >( values );
00184     int size         = sizeof( iBase_EntityHandle );
00185     int result;
00186 
00187     for( int i = 0; i < num_sets; i++ )
00188     {
00189         FBiGeom_setEntSetData( instance_, sets[i], relation_tag, data, size, &result );
00190         data += size;
00191         PROCESS_ERROR;
00192     }
00193     RETURNR( iBase_SUCCESS );
00194 }
00195 
00196 int FBGeomAssocPairSide::rmv_relation_side( iBase_EntityHandle* entities, int num_entities )
00197 {
00198     int result;
00199 
00200     FBiGeom_rmvArrTag( instance_, entities, num_entities, relation_tag, &result );
00201     PROCESS_ERROR;
00202     RETURNR( iBase_SUCCESS );
00203 }
00204 
00205 int FBGeomAssocPairSide::rmv_relation_side( iBase_EntitySetHandle* sets, int num_sets )
00206 {
00207     int result;
00208 
00209     for( int i = 0; i < num_sets; i++ )
00210     {
00211         FBiGeom_rmvEntSetTag( instance_, sets[i], relation_tag, &result );
00212         PROCESS_ERROR;
00213     }
00214 
00215     RETURNR( iBase_SUCCESS );
00216 }
00217 
00218 int FBGeomAssocPairSide::get_iterator( iBase_EntitySetHandle set, iBase_EntityIterator* iter )
00219 {
00220     int result;
00221     FBiGeom_initEntIter( instance_, set, iBase_ALL_TYPES, iter, &result );
00222     RETURNR( iBase_SUCCESS );
00223 }
00224 
00225 int FBGeomAssocPairSide::get_gids( iBase_EntityHandle* entities, int num_entities, int* values )
00226 {
00227     int values_alloc = num_entities * sizeof( int );
00228     int values_size;
00229     int result;
00230 
00231     FBiGeom_getArrData( instance_, entities, num_entities, gid_tag, reinterpret_cast< void** >( &values ),
00232                         &values_alloc, &values_size, &result );
00233     PROCESS_ERROR;
00234     RETURNR( iBase_SUCCESS );
00235 }
00236 
00237 int FBGeomAssocPairSide::get_gids( iBase_EntitySetHandle* sets, int num_sets, int* values )
00238 {
00239     char* data       = reinterpret_cast< char* >( values );
00240     int values_alloc = sizeof( int );
00241     int values_size;
00242     int result;
00243 
00244     for( int i = 0; i < num_sets; i++ )
00245     {
00246         FBiGeom_getEntSetData( instance_, sets[i], gid_tag, reinterpret_cast< void** >( &data ), &values_alloc,
00247                                &values_size, &result );
00248         data += values_size;
00249         PROCESS_ERROR;
00250     }
00251     RETURNR( iBase_SUCCESS );
00252 }
00253 
00254 int FBGeomAssocPairSide::get_dims( iBase_EntityHandle* /*entities*/, int /*num_entities*/, int* /*values*/ )
00255 {
00256     RETURNR( iBase_FAILURE );
00257 }
00258 
00259 int FBGeomAssocPairSide::get_dims( iBase_EntitySetHandle* /*sets*/, int /*num_sets*/, int* /*values*/ )
00260 {
00261     RETURNR( iBase_FAILURE );
00262 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines