lasso
|
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 do { \ 00011 if (iBase_SUCCESS != result) { \ 00012 char this_descr[120]; \ 00013 iGeom_getDescription(instance_, this_descr, 120); \ 00014 ERRORR(result, this_descr); \ 00015 } \ 00016 } while(false) 00017 00018 // Redefine LASSOI 00019 #undef LASSOI 00020 #define LASSOI lasso_instance(relation) 00021 00022 static const char *GLOBAL_ID_TAG_NAME = "GLOBAL_ID"; 00023 static const char *RELATION_TAG_NAME = "__GEOM_ASSOCIATION"; 00024 00025 GeomAssocPairSide::GeomAssocPairSide(iRel_Instance relation, 00026 iBase_Instance instance, int id) : 00027 relation(relation), 00028 instance_(reinterpret_cast<iGeom_Instance>(instance)), 00029 id(id) 00030 { 00031 int result; 00032 00033 create_relation_side(); 00034 00035 iGeom_getTagHandle(instance_, GLOBAL_ID_TAG_NAME, &gid_tag, &result, 00036 strlen(GLOBAL_ID_TAG_NAME)); 00037 if (result == iBase_TAG_NOT_FOUND) { 00038 iGeom_createTag(instance_, GLOBAL_ID_TAG_NAME, 1, iBase_INTEGER, 00039 &gid_tag, &result, 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, 00066 rel_tag_name.size()); 00067 if (result == iBase_TAG_NOT_FOUND) { 00068 iGeom_createTag(instance_, rel_tag_name.c_str(), 1, iBase_ENTITY_HANDLE, 00069 &relation_tag, &result, 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 int result; 00080 00081 iGeom_destroyTag(instance_, relation_tag, true, &result); 00082 relation_tag = NULL; 00083 00084 PROCESS_ERROR; 00085 } 00086 RETURNR(iBase_SUCCESS); 00087 } 00088 00089 int GeomAssocPairSide::get_all_entities(int dimension, 00090 iBase_EntityHandle **entities, 00091 int *entities_alloc, 00092 int *entities_size) 00093 { 00094 int this_type = (dimension == -1 ? iBase_ALL_TYPES : dimension); 00095 int result; 00096 00097 iGeom_getEntities(instance_, 0, this_type, entities, entities_alloc, 00098 entities_size, &result); 00099 PROCESS_ERROR; 00100 RETURNR(iBase_SUCCESS); 00101 } 00102 00103 int GeomAssocPairSide::get_all_sets(iBase_EntitySetHandle **sets, 00104 int *sets_alloc, int *sets_size) 00105 { 00106 int result; 00107 00108 iGeom_getEntSets(instance_, 0, 0, sets, sets_alloc, sets_size, &result); 00109 PROCESS_ERROR; 00110 RETURNR(iBase_SUCCESS); 00111 } 00112 00113 int GeomAssocPairSide::get_entities(int dimension, 00114 iBase_EntitySetHandle set_handle, 00115 iBase_EntityHandle **entities, 00116 int *entities_alloc, 00117 int *entities_size) 00118 { 00119 int this_type = (dimension == -1 ? iBase_ALL_TYPES : dimension); 00120 int result; 00121 00122 iGeom_getEntities(instance_, set_handle, this_type, entities, entities_alloc, 00123 entities_size, &result); 00124 PROCESS_ERROR; 00125 RETURNR(iBase_SUCCESS); 00126 } 00127 00128 int GeomAssocPairSide::get_ents_dims(iBase_EntityHandle *entities, 00129 int entities_size, 00130 int **ent_types, 00131 int *ent_types_alloc, 00132 int *ent_types_size) 00133 { 00134 int result; 00135 00136 iGeom_getArrType(instance_, entities, entities_size, ent_types, 00137 ent_types_alloc, ent_types_size, &result); 00138 PROCESS_ERROR; 00139 RETURNR(iBase_SUCCESS); 00140 } 00141 00142 int GeomAssocPairSide::get_related_ents(iBase_EntityHandle **entities, 00143 int *entities_alloc, int *entities_size) 00144 { 00145 RETURNR(iBase_FAILURE); 00146 } 00147 00148 int GeomAssocPairSide::get_related_sets(iBase_EntitySetHandle **sets, 00149 int *sets_alloc, int *sets_size) 00150 { 00151 RETURNR(iBase_FAILURE); 00152 } 00153 00154 int GeomAssocPairSide::get_relation_side(iBase_EntityHandle *entities, 00155 int num_entities, void *values) 00156 { 00157 int values_alloc = num_entities * sizeof(iBase_EntityHandle); 00158 int values_size; 00159 int result; 00160 00161 iGeom_getArrData(instance_, entities, num_entities, relation_tag, 00162 &values, &values_alloc, &values_size, &result); 00163 PROCESS_ERROR; 00164 RETURNR(iBase_SUCCESS); 00165 } 00166 00167 int GeomAssocPairSide::get_relation_side(iBase_EntitySetHandle *sets, 00168 int num_sets, void *values) 00169 { 00170 char *data = static_cast<char*>(values); 00171 int values_alloc = sizeof(iBase_EntityHandle); 00172 int values_size; 00173 int result; 00174 00175 for (int i = 0; i < num_sets; i++) { 00176 iGeom_getEntSetData(instance_, sets[i], relation_tag, 00177 reinterpret_cast<void**>(&data), 00178 &values_alloc, &values_size, &result); 00179 data += values_size; 00180 PROCESS_ERROR; 00181 } 00182 RETURNR(iBase_SUCCESS); 00183 } 00184 00185 int GeomAssocPairSide::set_relation_side(iBase_EntityHandle *entities, 00186 int num_entities, const void *values) 00187 { 00188 int result; 00189 00190 iGeom_setArrData(instance_, entities, num_entities, relation_tag, 00191 static_cast<const char*>(values), 00192 num_entities*sizeof(iBase_EntityHandle), &result); 00193 PROCESS_ERROR; 00194 RETURNR(iBase_SUCCESS); 00195 } 00196 00197 int GeomAssocPairSide::set_relation_side(iBase_EntitySetHandle *sets, 00198 int num_sets, const void *values) 00199 { 00200 const char *data = static_cast<const char*>(values); 00201 int size = sizeof(iBase_EntityHandle); 00202 int result; 00203 00204 for (int i = 0; i < num_sets; i++) { 00205 iGeom_setEntSetData(instance_, sets[i], relation_tag, data, size, &result); 00206 data += size; 00207 PROCESS_ERROR; 00208 } 00209 RETURNR(iBase_SUCCESS); 00210 } 00211 00212 int GeomAssocPairSide::rmv_relation_side(iBase_EntityHandle *entities, 00213 int num_entities) 00214 { 00215 int result; 00216 00217 iGeom_rmvArrTag(instance_, entities, num_entities, relation_tag, &result); 00218 PROCESS_ERROR; 00219 RETURNR(iBase_SUCCESS); 00220 } 00221 00222 int GeomAssocPairSide::rmv_relation_side(iBase_EntitySetHandle *sets, 00223 int num_sets) 00224 { 00225 int result; 00226 00227 for (int i = 0; i < num_sets; i++) { 00228 iGeom_rmvEntSetTag(instance_, sets[i], relation_tag, &result); 00229 PROCESS_ERROR; 00230 } 00231 00232 RETURNR(iBase_SUCCESS); 00233 } 00234 00235 int GeomAssocPairSide::get_iterator(iBase_EntitySetHandle set, 00236 iBase_EntityIterator *iter) 00237 { 00238 int result; 00239 iGeom_initEntIter(instance_, set, iBase_ALL_TYPES, iter, &result); 00240 RETURNR(iBase_SUCCESS); 00241 } 00242 00243 int GeomAssocPairSide::get_gids(iBase_EntityHandle *entities, int num_entities, 00244 int *values) 00245 { 00246 int values_alloc = num_entities * sizeof(int); 00247 int values_size; 00248 int result; 00249 00250 iGeom_getArrData(instance_, entities, num_entities, gid_tag, 00251 reinterpret_cast<void**>(&values), &values_alloc, 00252 &values_size, &result); 00253 PROCESS_ERROR; 00254 RETURNR(iBase_SUCCESS); 00255 } 00256 00257 int GeomAssocPairSide::get_gids(iBase_EntitySetHandle *sets, int num_sets, 00258 int *values) 00259 { 00260 char *data = reinterpret_cast<char*>(values); 00261 int values_alloc = sizeof(int); 00262 int values_size; 00263 int result; 00264 00265 for (int i = 0; i < num_sets; i++) { 00266 iGeom_getEntSetData(instance_, sets[i], gid_tag, 00267 reinterpret_cast<void**>(&data), 00268 &values_alloc, &values_size, &result); 00269 data += values_size; 00270 PROCESS_ERROR; 00271 } 00272 RETURNR(iBase_SUCCESS); 00273 } 00274 00275 int GeomAssocPairSide::get_dims(iBase_EntityHandle *entities, int num_entities, 00276 int *values) 00277 { 00278 RETURNR(iBase_FAILURE); 00279 } 00280 00281 int GeomAssocPairSide::get_dims(iBase_EntitySetHandle *sets, int num_sets, 00282 int *values) 00283 { 00284 RETURNR(iBase_FAILURE); 00285 }