MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /** 00002 * Copyright 2006 Sandia Corporation. Under the terms of Contract 00003 * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government 00004 * retains certain rights in this software. 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 */ 00012 #include "iRel_Lasso.hpp" 00013 00014 #include "Lasso.hpp" 00015 #include "AssocPair.hpp" 00016 #include "ArrayManager.hpp" 00017 00018 #include <algorithm> 00019 #include <cmath> 00020 #include <cstdio> 00021 #include <iostream> 00022 #include <map> 00023 #include <vector> 00024 00025 const bool debug = false; 00026 00027 void iRel_getErrorType( iRel_Instance instance, int* error_type ) 00028 { 00029 if( instance == NULL ) 00030 *error_type = iBase_FAILURE; 00031 else 00032 *error_type = LASSOI->lastErrorType; 00033 } 00034 00035 void iRel_getDescription( iRel_Instance instance, char* descr, int descr_len ) 00036 { 00037 if( instance == NULL ) { strcpy( descr, "iRel_getDescription: Invalid instance" ); } 00038 else 00039 { 00040 unsigned int len = std::min( strlen( LASSOI->lastErrorDescription ), static_cast< size_t >( descr_len ) ); 00041 strncpy( descr, LASSOI->lastErrorDescription, len ); 00042 descr[len] = '\0'; 00043 } 00044 } 00045 00046 void iRel_create( /* in */ const char* /* options */, iRel_Instance* instance, int* err, const int options_len ) 00047 { 00048 if( 0 != options_len ) 00049 { 00050 *instance = NULL; 00051 *err = iBase_NOT_SUPPORTED; 00052 } 00053 00054 *instance = new Lasso(); 00055 *err = iBase_SUCCESS; 00056 } 00057 00058 void iRel_destroy( iRel_Instance instance, int* err ) 00059 { 00060 delete LASSOI; 00061 *err = iBase_SUCCESS; 00062 } 00063 00064 void iRel_createPair( iRel_Instance instance, iBase_Instance iface1, const int ent_or_set1, const int iface_type1, 00065 const int irel_status1, iBase_Instance iface2, const int ent_or_set2, const int iface_type2, 00066 const int irel_status2, iRel_PairHandle* pair, int* err ) 00067 { 00068 AssocPair* assoc_pair = new AssocPair( 00069 instance, iface1, static_cast< iRel_RelationType >( ent_or_set1 ), static_cast< iRel_IfaceType >( iface_type1 ), 00070 static_cast< iRel_RelationStatus >( irel_status1 ), iface2, static_cast< iRel_RelationType >( ent_or_set2 ), 00071 static_cast< iRel_IfaceType >( iface_type2 ), static_cast< iRel_RelationStatus >( irel_status2 ) ); 00072 LASSOI->insert_pair( assoc_pair ); 00073 00074 *pair = reinterpret_cast< iRel_PairHandle >( assoc_pair ); 00075 RETURN( iBase_SUCCESS ); 00076 } 00077 00078 void iRel_getPairInfo( iRel_Instance instance, iRel_PairHandle pair, iBase_Instance* iface1, int* ent_or_set1, 00079 int* iface_type1, int* irel_status1, iBase_Instance* iface2, int* ent_or_set2, int* iface_type2, 00080 int* irel_status2, int* err ) 00081 { 00082 CHK_PAIR(); 00083 00084 *iface1 = ASSOCPAIRI->iface_instance( 0 ); 00085 *ent_or_set1 = ASSOCPAIRI->relation_type( 0 ); 00086 *iface_type1 = ASSOCPAIRI->iface_type( 0 ); 00087 *irel_status1 = ASSOCPAIRI->relation_status( 0 ); 00088 *iface2 = ASSOCPAIRI->iface_instance( 1 ); 00089 *iface_type2 = ASSOCPAIRI->iface_type( 1 ); 00090 *ent_or_set2 = ASSOCPAIRI->relation_type( 1 ); 00091 *irel_status2 = ASSOCPAIRI->relation_status( 1 ); 00092 00093 RETURN( iBase_SUCCESS ); 00094 } 00095 00096 void iRel_changePairType( iRel_Instance instance, iRel_PairHandle pair, int ent_or_set1, int ent_or_set2, int* err ) 00097 { 00098 CHK_PAIR(); 00099 00100 CHK_ERROR( ASSOCPAIRI->change_type( 0, static_cast< iRel_RelationType >( ent_or_set1 ) ) );CHK_ERROR( ASSOCPAIRI->change_type( 1, static_cast< iRel_RelationType >( ent_or_set2 ) ) ); 00101 } 00102 00103 void iRel_changePairStatus( iRel_Instance instance, iRel_PairHandle pair, int irel_status1, int irel_status2, int* err ) 00104 { 00105 CHK_PAIR(); 00106 00107 CHK_ERROR( ASSOCPAIRI->change_status( 0, static_cast< iRel_RelationStatus >( irel_status1 ) ) );CHK_ERROR( ASSOCPAIRI->change_status( 1, static_cast< iRel_RelationStatus >( irel_status2 ) ) ); 00108 } 00109 00110 void iRel_destroyPair( iRel_Instance instance, iRel_PairHandle pair, int* err ) 00111 { 00112 CHK_PAIR(); 00113 00114 CHK_ERROR( LASSOI->erase_pair( ASSOCPAIRI ) ); 00115 } 00116 00117 void iRel_findPairs( iRel_Instance instance, iBase_Instance iface, iRel_PairHandle** pairs, int* pairs_allocated, 00118 int* pairs_size, int* err ) 00119 { 00120 std::vector< AssocPair* > tmp_pairs; 00121 LASSOI->find_pairs( iface, tmp_pairs ); 00122 00123 ALLOC_CHECK_ARRAY_NOFAIL( pairs, tmp_pairs.size() ); 00124 for( size_t i = 0; i < tmp_pairs.size(); ++i ) 00125 { 00126 ( *pairs )[i] = reinterpret_cast< iRel_PairHandle >( tmp_pairs[i] ); 00127 } 00128 00129 RETURN( iBase_SUCCESS ); 00130 } 00131 00132 void iRel_setEntEntRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle ent1, 00133 iBase_EntityHandle ent2, int* err ) 00134 { 00135 CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( ent1, ent2 ) ); 00136 } 00137 00138 void iRel_setEntSetRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle ent1, 00139 iBase_EntitySetHandle set2, int* err ) 00140 { 00141 CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( ent1, set2 ) ); 00142 } 00143 00144 void iRel_setSetEntRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle set1, 00145 iBase_EntityHandle ent2, int* err ) 00146 { 00147 CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( set1, ent2 ) ); 00148 } 00149 00150 void iRel_setSetSetRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle set1, 00151 iBase_EntitySetHandle set2, int* err ) 00152 { 00153 CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( set1, set2 ) ); 00154 } 00155 00156 void iRel_setEntArrEntArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* ent_array_1, 00157 int num_entities1, iBase_EntityHandle* ent_array_2, int num_entities2, int* err ) 00158 { 00159 CHK_PAIR(); 00160 00161 if( num_entities1 != num_entities2 ) 00162 ERROR( iBase_INVALID_ENTITY_COUNT, "setEntArrEntArrRelation doesn't support " 00163 "different #'s of entities." ); 00164 00165 int result = iBase_SUCCESS; 00166 char descr[200]; 00167 for( int i = 0; i < num_entities1; i++ ) 00168 { 00169 int tmp_result = ASSOCPAIRI->set_relation( ent_array_1[i], ent_array_2[i] ); 00170 if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS ) 00171 { 00172 result = tmp_result; 00173 iRel_getDescription( instance, descr, sizeof( descr ) ); 00174 } 00175 } 00176 00177 if( result != iBase_SUCCESS ) ERROR( result, descr ); 00178 RETURN( iBase_SUCCESS ); 00179 } 00180 00181 void iRel_setEntArrSetArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* ent_array_1, 00182 int num_entities1, iBase_EntitySetHandle* set_array_2, int num_sets2, int* err ) 00183 { 00184 CHK_PAIR(); 00185 00186 if( num_entities1 != num_sets2 ) 00187 ERROR( iBase_INVALID_ENTITY_COUNT, "setEntArrSetArrRelation doesn't support " 00188 "different #'s of entities." ); 00189 00190 int result = iBase_SUCCESS; 00191 char descr[200]; 00192 for( int i = 0; i < num_entities1; i++ ) 00193 { 00194 int tmp_result = ASSOCPAIRI->set_relation( ent_array_1[i], set_array_2[i] ); 00195 if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS ) 00196 { 00197 result = tmp_result; 00198 iRel_getDescription( instance, descr, sizeof( descr ) ); 00199 } 00200 } 00201 00202 if( result != iBase_SUCCESS ) ERROR( result, descr ); 00203 RETURN( iBase_SUCCESS ); 00204 } 00205 00206 void iRel_setSetArrEntArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle* set_array_1, 00207 int num_sets1, iBase_EntityHandle* ent_array_2, int num_entities2, int* err ) 00208 { 00209 CHK_PAIR(); 00210 00211 if( num_sets1 != num_entities2 ) 00212 ERROR( iBase_INVALID_ENTITY_COUNT, "setSetArrEntArrRelation doesn't support " 00213 "different #'s of entities." ); 00214 00215 int result = iBase_SUCCESS; 00216 char descr[200]; 00217 for( int i = 0; i < num_sets1; i++ ) 00218 { 00219 int tmp_result = ASSOCPAIRI->set_relation( set_array_1[i], ent_array_2[i] ); 00220 if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS ) 00221 { 00222 result = tmp_result; 00223 iRel_getDescription( instance, descr, sizeof( descr ) ); 00224 } 00225 } 00226 00227 if( result != iBase_SUCCESS ) ERROR( result, descr ); 00228 RETURN( iBase_SUCCESS ); 00229 } 00230 00231 void iRel_setSetArrSetArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle* set_array_1, 00232 int num_sets1, iBase_EntitySetHandle* set_array_2, int num_sets2, int* err ) 00233 { 00234 CHK_PAIR(); 00235 00236 if( num_sets1 != num_sets2 ) 00237 ERROR( iBase_INVALID_ENTITY_COUNT, "setSetArrSetArrRelation doesn't support " 00238 "different #'s of entities." ); 00239 00240 int result = iBase_SUCCESS; 00241 char descr[200]; 00242 for( int i = 0; i < num_sets1; i++ ) 00243 { 00244 int tmp_result = ASSOCPAIRI->set_relation( set_array_1[i], set_array_2[i] ); 00245 if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS ) 00246 { 00247 result = tmp_result; 00248 iRel_getDescription( instance, descr, sizeof( descr ) ); 00249 } 00250 } 00251 00252 if( result != iBase_SUCCESS ) ERROR( result, descr ); 00253 RETURN( iBase_SUCCESS ); 00254 } 00255 00256 void iRel_getEntEntRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle ent1, int switch_order, 00257 iBase_EntityHandle* ent2, int* err ) 00258 { 00259 CHK_PAIR(); 00260 00261 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, ent2 ) ); 00262 } 00263 00264 void iRel_getEntSetRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle ent1, int switch_order, 00265 iBase_EntitySetHandle* set2, int* err ) 00266 { 00267 CHK_PAIR(); 00268 00269 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, set2 ) ); 00270 } 00271 00272 void iRel_getSetEntRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle set1, int switch_order, 00273 iBase_EntityHandle* ent2, int* err ) 00274 { 00275 CHK_PAIR(); 00276 00277 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &set1, 1, ent2 ) ); 00278 } 00279 00280 void iRel_getSetSetRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle set1, int switch_order, 00281 iBase_EntitySetHandle* set2, int* err ) 00282 { 00283 CHK_PAIR(); 00284 00285 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &set1, 1, set2 ) ); 00286 } 00287 00288 void iRel_getEntSetIterRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle ent1, 00289 int switch_order, iBase_EntityIterator* entset2, int* err ) 00290 { 00291 CHK_PAIR(); 00292 00293 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, entset2 ) ); 00294 } 00295 00296 void iRel_getEntArrEntArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* ent_array_1, 00297 int ent_array_1_size, int switch_order, iBase_EntityHandle** ent_array_2, 00298 int* ent_array_2_allocated, int* ent_array_2_size, int* err ) 00299 { 00300 CHK_PAIR(); 00301 00302 int iface_no = ( switch_order ? 1 : 0 ); 00303 ALLOC_CHECK_ARRAY( ent_array_2, ent_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, ent_array_1, ent_array_1_size, *ent_array_2 ) ); 00304 00305 KEEP_ARRAY( ent_array_2 ); 00306 RETURN( iBase_SUCCESS ); 00307 } 00308 00309 void iRel_getEntArrSetArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* ent_array_1, 00310 int ent_array_1_size, int switch_order, iBase_EntitySetHandle** set_array_2, 00311 int* set_array_2_allocated, int* set_array_2_size, int* err ) 00312 { 00313 CHK_PAIR(); 00314 00315 int iface_no = ( switch_order ? 1 : 0 ); 00316 ALLOC_CHECK_ARRAY( set_array_2, ent_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, ent_array_1, ent_array_1_size, *set_array_2 ) ); 00317 00318 KEEP_ARRAY( set_array_2 ); 00319 RETURN( iBase_SUCCESS ); 00320 } 00321 00322 void iRel_getSetArrEntArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle* set_array_1, 00323 int set_array_1_size, int switch_order, iBase_EntityHandle** ent_array_2, 00324 int* ent_array_2_allocated, int* ent_array_2_size, int* err ) 00325 { 00326 CHK_PAIR(); 00327 00328 int iface_no = ( switch_order ? 1 : 0 ); 00329 ALLOC_CHECK_ARRAY( ent_array_2, set_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, set_array_1, set_array_1_size, *ent_array_2 ) ); 00330 00331 KEEP_ARRAY( ent_array_2 ); 00332 RETURN( iBase_SUCCESS ); 00333 } 00334 00335 void iRel_getSetArrSetArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle* set_array_1, 00336 int set_array_1_size, int switch_order, iBase_EntitySetHandle** set_array_2, 00337 int* set_array_2_allocated, int* set_array_2_size, int* err ) 00338 { 00339 CHK_PAIR(); 00340 00341 int iface_no = ( switch_order ? 1 : 0 ); 00342 ALLOC_CHECK_ARRAY( set_array_2, set_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, set_array_1, set_array_1_size, *set_array_2 ) ); 00343 00344 KEEP_ARRAY( set_array_2 ); 00345 RETURN( iBase_SUCCESS ); 00346 } 00347 00348 void iRel_getEntArrSetIterArrRelation( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* ent_array_1, 00349 int ent_array_1_size, int switch_order, iBase_EntityIterator** entiter, 00350 int* entiter_allocated, int* entiter_size, int* err ) 00351 { 00352 CHK_PAIR(); 00353 00354 int iface_no = ( switch_order ? 1 : 0 ); 00355 ; 00356 ALLOC_CHECK_ARRAY( entiter, ent_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, ent_array_1, ent_array_1_size, *entiter ) ); 00357 00358 KEEP_ARRAY( entiter ); 00359 RETURN( iBase_SUCCESS ); 00360 } 00361 00362 void iRel_rmvEntRelation( iRel_Instance instance, 00363 /*in*/ iRel_PairHandle pair, 00364 /*in*/ iBase_EntityHandle ent, 00365 /*in*/ int switch_order, 00366 /*out*/ int* err ) 00367 { 00368 CHK_PAIR(); 00369 00370 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, &ent, 1 ) ); 00371 } 00372 00373 void iRel_rmvSetRelation( iRel_Instance instance, 00374 /*in*/ iRel_PairHandle pair, 00375 /*in*/ iBase_EntitySetHandle entset, 00376 /*in*/ int switch_order, 00377 /*out*/ int* err ) 00378 { 00379 CHK_PAIR(); 00380 00381 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, &entset, 1 ) ); 00382 } 00383 00384 void iRel_rmvEntArrRelation( iRel_Instance instance, 00385 /*in*/ iRel_PairHandle pair, 00386 /*in*/ iBase_EntityHandle* ent_array, 00387 /*in*/ int num_ent, 00388 /*in*/ int switch_order, 00389 /*out*/ int* err ) 00390 { 00391 CHK_PAIR(); 00392 00393 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, ent_array, num_ent ) ); 00394 } 00395 00396 void iRel_rmvSetArrRelation( iRel_Instance instance, 00397 /*in*/ iRel_PairHandle pair, 00398 /*in*/ iBase_EntitySetHandle* entset_array, 00399 /*in*/ int num_ent, 00400 /*in*/ int switch_order, 00401 /*out*/ int* err ) 00402 { 00403 CHK_PAIR(); 00404 00405 int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, entset_array, num_ent ) ); 00406 } 00407 00408 static int get_gids_and_dims( iRel_PairHandle pair, int iface_no, iBase_EntityHandle* ents, int ents_size, 00409 int ent_or_set, std::vector< int >& ents_gids, std::vector< int >& ents_dims ) 00410 { 00411 int result; 00412 iBase_EntitySetHandle* sets = reinterpret_cast< iBase_EntitySetHandle* >( ents ); 00413 00414 ents_gids.resize( ents_size ); 00415 if( ent_or_set == iRel_ENTITY ) 00416 result = ASSOCPAIRI->get_gids( iface_no, ents, ents_size, &ents_gids[0] ); 00417 else 00418 result = ASSOCPAIRI->get_gids( iface_no, sets, ents_size, &ents_gids[0] ); 00419 00420 if( iBase_SUCCESS != result && iBase_TAG_NOT_FOUND != result ) return result; 00421 00422 ents_dims.resize( ents_size, -1 ); 00423 if( ent_or_set == iRel_ENTITY ) 00424 { 00425 int* ents_dims_ptr = &ents_dims[0]; 00426 int ents_dims_alloc = ents_dims.size(), ents_dims_size; 00427 result = 00428 ASSOCPAIRI->get_ents_dims( iface_no, ents, ents_size, &ents_dims_ptr, &ents_dims_alloc, &ents_dims_size ); 00429 } 00430 else 00431 { 00432 result = ASSOCPAIRI->get_dims( iface_no, sets, ents_size, &ents_dims[0] ); 00433 } 00434 00435 if( iBase_SUCCESS != result && iBase_TAG_NOT_FOUND != result ) return result; 00436 00437 return iBase_SUCCESS; 00438 } 00439 00440 static void iRel_inferArrArrRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* ents1, 00441 const int ents1_size, int ent_or_set1, iBase_EntityHandle* ents2, 00442 const int ents2_size, int ent_or_set2, int* err ) 00443 { 00444 int result; 00445 00446 std::vector< int > ents_gids, ents_dims; 00447 std::map< const int, iBase_EntityHandle > ents_gid_map[4]; 00448 00449 get_gids_and_dims( pair, 0, ents1, ents1_size, ent_or_set1, ents_gids, ents_dims ); 00450 for( int i = 0; i < ents1_size; i++ ) 00451 { 00452 int dim = ents_dims[i]; 00453 if( 0 <= dim && 3 >= dim ) ents_gid_map[dim][ents_gids[i]] = ents1[i]; 00454 } 00455 00456 get_gids_and_dims( pair, 1, ents2, ents2_size, ent_or_set2, ents_gids, ents_dims ); 00457 for( int i = 0; i < ents2_size; i++ ) 00458 { 00459 int dim = ents_dims[i]; 00460 00461 // only check entities for which the dimension entry is in a reasonable 00462 // range 00463 if( 0 > dim || 3 < dim ) continue; 00464 00465 // there's a match if there's an entity with that dimension with matching id 00466 std::map< const int, iBase_EntityHandle >::iterator iter = ents_gid_map[dim].find( ents_gids[i] ); 00467 00468 // if it matches, set the relation tags for those entities 00469 if( iter != ents_gid_map[dim].end() ) 00470 { 00471 if( ent_or_set1 == iRel_ENTITY && ent_or_set2 == iRel_ENTITY ) 00472 { result = ASSOCPAIRI->set_relation( ( *iter ).second, ents2[i] ); } 00473 else if( ent_or_set1 != iRel_ENTITY && ent_or_set2 == iRel_ENTITY ) 00474 { 00475 result = ASSOCPAIRI->set_relation( ( iBase_EntitySetHandle )( *iter ).second, ents2[i] ); 00476 } 00477 else if( ent_or_set1 == iRel_ENTITY && ent_or_set2 != iRel_ENTITY ) 00478 { 00479 result = ASSOCPAIRI->set_relation( ( *iter ).second, (iBase_EntitySetHandle)ents2[i] ); 00480 } 00481 else 00482 { // ent_or_set1 != iRel_ENTITY && ent_or_set2 != iRel_ENTITY 00483 result = ASSOCPAIRI->set_relation( ( iBase_EntitySetHandle )( *iter ).second, 00484 (iBase_EntitySetHandle)ents2[i] ); 00485 } 00486 00487 CHK_ERROR( result ); 00488 } 00489 } 00490 00491 RETURN( iBase_SUCCESS ); 00492 } 00493 00494 void iRel_inferEntArrEntArrRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* ents1, 00495 const int ents1_size, iBase_EntityHandle* ents2, const int ents2_size, int* err ) 00496 { 00497 iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, 0, ents2, ents2_size, 0, err ); 00498 } 00499 00500 void iRel_inferEntArrSetArrRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* ents1, 00501 const int ents1_size, iBase_EntitySetHandle* ents2, const int ents2_size, 00502 int* err ) 00503 { 00504 iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, 0, (iBase_EntityHandle*)ents2, ents2_size, 1, err ); 00505 } 00506 00507 void iRel_inferSetArrEntArrRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle* ents1, 00508 const int ents1_size, iBase_EntityHandle* ents2, const int ents2_size, int* err ) 00509 { 00510 iRel_inferArrArrRelations( instance, pair, (iBase_EntityHandle*)ents1, ents1_size, 1, ents2, ents2_size, 0, err ); 00511 } 00512 00513 void iRel_inferSetArrSetArrRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle* ents1, 00514 const int ents1_size, int /*is_set1*/, iBase_EntitySetHandle* ents2, 00515 const int ents2_size, int /*is_set2*/, int* err ) 00516 00517 { 00518 iRel_inferArrArrRelations( instance, pair, (iBase_EntityHandle*)ents1, ents1_size, 1, (iBase_EntityHandle*)ents2, 00519 ents2_size, 1, err ); 00520 } 00521 00522 void iRel_inferAllRelations( iRel_Instance instance, iRel_PairHandle pair, int* err ) 00523 { 00524 CHK_PAIR(); 00525 00526 // get all entities in those interfaces 00527 int result; 00528 00529 iBase_EntityHandle* ents1 = NULL; 00530 int ents1_alloc = 0, ents1_size; 00531 if( ASSOCPAIRI->relation_type( 0 ) != iRel_ENTITY ) 00532 result = ASSOCPAIRI->get_all_sets( 0, (iBase_EntitySetHandle**)&ents1, &ents1_alloc, &ents1_size ); 00533 else 00534 result = ASSOCPAIRI->get_all_entities( 0, -1, &ents1, &ents1_alloc, &ents1_size );CHK_ERROR( result ); 00535 00536 iBase_EntityHandle* ents2 = NULL; 00537 int ents2_alloc = 0, ents2_size; 00538 if( ASSOCPAIRI->relation_type( 1 ) != iRel_ENTITY ) 00539 result = ASSOCPAIRI->get_all_sets( 1, (iBase_EntitySetHandle**)&ents2, &ents2_alloc, &ents2_size ); 00540 else 00541 result = ASSOCPAIRI->get_all_entities( 1, -1, &ents2, &ents2_alloc, &ents2_size );CHK_ERROR( result ); 00542 00543 iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, ASSOCPAIRI->relation_type( 0 ), ents2, ents2_size, 00544 ASSOCPAIRI->relation_type( 1 ), &result ); 00545 00546 free( ents1 ); 00547 free( ents2 );CHK_ERROR( result ); 00548 } 00549 00550 void iRel_inferAllRelationsAndType( iRel_Instance instance, iRel_PairHandle* /*pair*/, int* err ) 00551 { 00552 ERROR( iBase_NOT_SUPPORTED, "Not currently supported." ); 00553 } 00554 00555 void iRel_inferEntRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle entity, int iface_no, 00556 int* err ) 00557 { 00558 iRel_inferEntArrRelations( instance, pair, &entity, 1, iface_no, err ); 00559 } 00560 00561 void iRel_inferSetRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle entity, int iface_no, 00562 int* err ) 00563 { 00564 iRel_inferSetArrRelations( instance, pair, &entity, 1, iface_no, err ); 00565 } 00566 00567 static void iRel_inferArrRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* entities, 00568 int entities_size, bool is_set, int iface_no, int* err ) 00569 { 00570 CHK_PAIR(); 00571 00572 if( 0 > iface_no || 1 < iface_no ) { ERROR( iBase_INVALID_ARGUMENT, "Interface number must be 0 or 1" ); } 00573 else if( ( is_set && ASSOCPAIRI->relation_type( iface_no ) == iRel_ENTITY ) || 00574 ( !is_set && ASSOCPAIRI->relation_type( iface_no ) != iRel_ENTITY ) ) 00575 { 00576 ERROR( iBase_INVALID_ARGUMENT, "is_set must match entOrSet in call to " 00577 "inferArrRelations" ); 00578 } 00579 00580 // get all entities in iface2 00581 int result; 00582 iBase_EntityHandle* ents1 = entities; 00583 int ents1_size = entities_size; 00584 iBase_EntityHandle* ents2 = NULL; 00585 int ents2_alloc = 0, ents2_size; 00586 if( ASSOCPAIRI->relation_type( 1 - iface_no ) != iRel_ENTITY ) 00587 result = ASSOCPAIRI->get_all_sets( !iface_no, (iBase_EntitySetHandle**)&ents2, &ents2_alloc, &ents2_size ); 00588 else 00589 result = ASSOCPAIRI->get_all_entities( !iface_no, -1, &ents2, &ents2_alloc, &ents2_size );CHK_ERROR( result ); 00590 00591 // switch so that entity lists always go into inferArrArrRelations in 00592 // forward order wrt pair 00593 if( 1 == iface_no ) 00594 { 00595 std::swap( ents1, ents2 ); 00596 std::swap( ents1_size, ents2_size ); 00597 } 00598 00599 iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, ASSOCPAIRI->relation_type( 0 ), ents2, ents2_size, 00600 ASSOCPAIRI->relation_type( 1 ), &result ); 00601 00602 free( 1 == iface_no ? ents1 : ents2 ); 00603 00604 CHK_ERROR( result ); 00605 } 00606 00607 void iRel_inferEntArrRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntityHandle* entities, 00608 int entities_size, int iface_no, int* err ) 00609 { 00610 iRel_inferArrRelations( instance, pair, entities, entities_size, false, iface_no, err ); 00611 } 00612 00613 void iRel_inferSetArrRelations( iRel_Instance instance, iRel_PairHandle pair, iBase_EntitySetHandle* entities, 00614 int entities_size, int iface_no, int* err ) 00615 { 00616 iRel_inferArrRelations( instance, pair, (iBase_EntityHandle*)entities, entities_size, true, iface_no, err ); 00617 }