lasso
MeshAssocPairSide.cpp
Go to the documentation of this file.
00001 #include "MeshAssocPairSide.hpp"
00002 
00003 #include <cstring>
00004 #include <sstream>
00005 #include <string>
00006 
00007 #include <iMesh_extensions.h>
00008 
00009 #include "Lasso.hpp"
00010 #include "iRel_Lasso.hpp"
00011 
00012 #define PROCESS_ERROR do {                              \
00013     if (iBase_SUCCESS != result) {                      \
00014       char this_descr[120];                             \
00015       iMesh_getDescription(instance_, this_descr, 120); \
00016       ERRORR(result, this_descr);                       \
00017     }                                                   \
00018   } while(false)
00019 
00020 // Redefine LASSOI
00021 #undef LASSOI
00022 #define LASSOI lasso_instance(relation)
00023 
00024 static const char *GLOBAL_ID_TAG_NAME = "GLOBAL_ID";
00025 static const char *MESH_DIMENSION_TAG_NAME = "GEOM_DIMENSION";
00026 static const char *RELATION_TAG_NAME = "__MESH_ASSOCIATION";
00027 
00028 MeshAssocPairSide::MeshAssocPairSide(iRel_Instance relation,
00029                                      iBase_Instance instance, int id) :
00030   relation(relation),
00031   instance_(reinterpret_cast<iMesh_Instance>(instance)),
00032   id(id)
00033 {
00034   int result;
00035 
00036   create_relation_side();
00037 
00038   iMesh_getTagHandle(instance_, GLOBAL_ID_TAG_NAME, &gid_tag, &result,
00039                      strlen(GLOBAL_ID_TAG_NAME));
00040   if (result == iBase_TAG_NOT_FOUND) {
00041     iMesh_createTag(instance_, GLOBAL_ID_TAG_NAME, 1, iBase_INTEGER,
00042                     &gid_tag, &result, strlen(GLOBAL_ID_TAG_NAME));
00043   }
00044 
00045   iMesh_getTagHandle(instance_, MESH_DIMENSION_TAG_NAME, &dim_tag, &result,
00046                      strlen(MESH_DIMENSION_TAG_NAME));
00047   if (result == iBase_TAG_NOT_FOUND)
00048     dim_tag = NULL;
00049 }
00050 
00051 MeshAssocPairSide::~MeshAssocPairSide()
00052 {
00053   destroy_relation_side();
00054 }
00055 
00056 iBase_Instance MeshAssocPairSide::instance() const
00057 {
00058   return instance_;
00059 }
00060 
00061 iRel_IfaceType MeshAssocPairSide::type() const
00062 {
00063   return iRel_IMESH_IFACE;
00064 }
00065 
00066 int MeshAssocPairSide::create_relation_side()
00067 {
00068   int result;
00069   std::stringstream ss;
00070   ss << RELATION_TAG_NAME << id;
00071   std::string rel_tag_name(ss.str());
00072 
00073   iMesh_getTagHandle(instance_, rel_tag_name.c_str(), &relation_tag, &result,
00074                      rel_tag_name.size());
00075   if (result == iBase_TAG_NOT_FOUND) {
00076     iMesh_createTag(instance_, rel_tag_name.c_str(), 1, iBase_ENTITY_HANDLE,
00077                     &relation_tag, &result, rel_tag_name.size());
00078   }
00079 
00080   PROCESS_ERROR;
00081   RETURNR(iBase_SUCCESS);
00082 }
00083 
00084 int MeshAssocPairSide::destroy_relation_side()
00085 {
00086   if (relation_tag) {
00087     int result;
00088 
00089     iMesh_destroyTag(instance_, relation_tag, true, &result);
00090     relation_tag = NULL;
00091 
00092     PROCESS_ERROR;
00093   }
00094   RETURNR(iBase_SUCCESS);
00095 }
00096 
00097 int MeshAssocPairSide::get_all_entities(int dimension,
00098                                         iBase_EntityHandle **entities,
00099                                         int *entities_alloc,
00100                                         int *entities_size)
00101 {
00102   int this_type = (dimension == -1 ? iBase_ALL_TYPES : dimension);
00103   int result;
00104 
00105   iMesh_getEntities(instance_, 0, this_type, iMesh_ALL_TOPOLOGIES,
00106                     entities, entities_alloc, entities_size, &result);
00107   PROCESS_ERROR;
00108   RETURNR(iBase_SUCCESS);
00109 }
00110 
00111 int MeshAssocPairSide::get_all_sets(iBase_EntitySetHandle **sets,
00112                                     int *sets_alloc, int *sets_size)
00113 {
00114   int result;
00115 
00116   iMesh_getEntSets(instance_, 0, 0, sets, sets_alloc, sets_size, &result);
00117   PROCESS_ERROR;
00118   RETURNR(iBase_SUCCESS);
00119 }
00120 
00121 int MeshAssocPairSide::get_entities(int dimension,
00122                                     iBase_EntitySetHandle set_handle,
00123                                     iBase_EntityHandle **entities,
00124                                     int *entities_alloc,
00125                                     int *entities_size)
00126 {
00127   int this_type = (dimension == -1 ? iBase_ALL_TYPES : dimension);
00128   int result;
00129 
00130   iMesh_getEntities(instance_, set_handle, this_type, iMesh_ALL_TOPOLOGIES,
00131                     entities, entities_alloc, entities_size, &result);
00132   PROCESS_ERROR;
00133   RETURNR(iBase_SUCCESS);
00134 }
00135 
00136 int MeshAssocPairSide::get_ents_dims(iBase_EntityHandle *entities,
00137                                      int entities_size,
00138                                      int **ent_types,
00139                                      int *ent_types_alloc,
00140                                      int *ent_types_size)
00141 {
00142   int result;
00143 
00144   iMesh_getEntArrType(instance_, entities, entities_size, ent_types,
00145                       ent_types_alloc, ent_types_size, &result);
00146   PROCESS_ERROR;
00147   RETURNR(iBase_SUCCESS);
00148 }
00149 
00150 int MeshAssocPairSide::get_related_ents(iBase_EntityHandle **entities,
00151                                         int *entities_alloc, int *entities_size)
00152 {
00153   int result;
00154   iMesh_getEntsByTagsRec(instance_, 0, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES,
00155                          &relation_tag, NULL, 1, false, entities,
00156                          entities_alloc, entities_size, &result);
00157   PROCESS_ERROR;
00158   RETURNR(iBase_SUCCESS);
00159 }
00160 
00161 int MeshAssocPairSide::get_related_sets(iBase_EntitySetHandle **sets,
00162                                         int *sets_alloc, int *sets_size)
00163 {
00164   int result;
00165   iMesh_getEntSetsByTagsRec(instance_, 0, &relation_tag, NULL, 1, false, sets,
00166                             sets_alloc, sets_size, &result);
00167   PROCESS_ERROR;
00168   RETURNR(iBase_SUCCESS);
00169 }
00170 
00171 int MeshAssocPairSide::get_relation_side(iBase_EntityHandle *entities,
00172                                          int num_entities, void *values)
00173 {
00174   int values_alloc = num_entities * sizeof(iBase_EntityHandle);
00175   int values_size;
00176   int result;
00177 
00178   iMesh_getArrData(instance_, entities, num_entities, relation_tag,
00179                    &values, &values_alloc, &values_size, &result);
00180   PROCESS_ERROR;
00181   RETURNR(iBase_SUCCESS);
00182 }
00183 
00184 int MeshAssocPairSide::get_relation_side(iBase_EntitySetHandle *sets, 
00185                                          int num_sets, void *values)
00186 {
00187   char *data = static_cast<char*>(values);
00188   int values_alloc = sizeof(iBase_EntityHandle);
00189   int values_size;
00190   int result;
00191 
00192   for (int i = 0; i < num_sets; i++) {
00193     iMesh_getEntSetData(instance_, sets[i], relation_tag,
00194                         reinterpret_cast<void**>(&data),
00195                         &values_alloc, &values_size, &result);
00196     data += values_size;
00197     PROCESS_ERROR;
00198   }
00199   RETURNR(iBase_SUCCESS);
00200 }
00201 
00202 int MeshAssocPairSide::set_relation_side(iBase_EntityHandle *entities,
00203                                          int num_entities, const void *values)
00204 {
00205   int result;
00206 
00207   iMesh_setArrData(instance_, entities, num_entities, relation_tag,
00208                    static_cast<const char*>(values),
00209                    num_entities*sizeof(iBase_EntityHandle), &result);
00210   PROCESS_ERROR;
00211   RETURNR(iBase_SUCCESS);
00212 }
00213 
00214 int MeshAssocPairSide::set_relation_side(iBase_EntitySetHandle *sets,
00215                                          int num_sets, const void *values)
00216 {
00217   const char *data = static_cast<const char*>(values);
00218   int size = sizeof(iBase_EntityHandle);
00219   int result;
00220 
00221   for (int i = 0; i < num_sets; i++) {
00222     iMesh_setEntSetData(instance_, sets[i], relation_tag, data, size, &result);
00223     data += size;
00224     PROCESS_ERROR;
00225   }
00226   RETURNR(iBase_SUCCESS);
00227 }
00228 
00229 int MeshAssocPairSide::rmv_relation_side(iBase_EntityHandle *entities,
00230                                          int num_entities)
00231 {
00232   int result;
00233 
00234   iMesh_rmvArrTag(instance_, entities, num_entities, relation_tag, &result);
00235   PROCESS_ERROR;
00236   RETURNR(iBase_SUCCESS);
00237 }
00238 
00239 int MeshAssocPairSide::rmv_relation_side(iBase_EntitySetHandle *sets,
00240                                          int num_sets)
00241 {
00242   int result;
00243 
00244   for (int i = 0; i < num_sets; i++) {
00245     iMesh_rmvEntSetTag(instance_, sets[i], relation_tag, &result);
00246     PROCESS_ERROR;
00247   }
00248 
00249   RETURNR(iBase_SUCCESS);
00250 }
00251 
00252 int MeshAssocPairSide::get_iterator(iBase_EntitySetHandle set,
00253                                     iBase_EntityIterator *iter)
00254 {
00255   int result;
00256   int resilient=0;
00257   iMesh_initEntIter(instance_, set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES,
00258                     resilient, iter, &result);
00259   RETURNR(iBase_SUCCESS);
00260 }
00261 
00262 int MeshAssocPairSide::get_gids(iBase_EntityHandle *entities, int num_entities,
00263                                 int *values)
00264 {
00265   int values_alloc = num_entities * sizeof(int);
00266   int values_size;
00267   int result;
00268 
00269   iMesh_getArrData(instance_, entities, num_entities, gid_tag,
00270                    &values, &values_alloc, &values_size, &result);
00271   PROCESS_ERROR;
00272   RETURNR(iBase_SUCCESS);
00273 }
00274 
00275 int MeshAssocPairSide::get_gids(iBase_EntitySetHandle *sets, int num_sets,
00276                                 int *values)
00277 {
00278   char *data = reinterpret_cast<char*>(values);
00279   int values_alloc = sizeof(int);
00280   int values_size;
00281   int result;
00282 
00283   for (int i = 0; i < num_sets; i++) {
00284     iMesh_getEntSetData(instance_, sets[i], gid_tag,
00285                         reinterpret_cast<void**>(&data),
00286                         &values_alloc, &values_size, &result);
00287     data += values_size;
00288     PROCESS_ERROR;
00289   }
00290   RETURNR(iBase_SUCCESS);
00291 }
00292 
00293 int MeshAssocPairSide::get_dims(iBase_EntityHandle *entities, int num_entities,
00294                                 int *values)
00295 {
00296   int values_alloc = num_entities * sizeof(int);
00297   int values_size;
00298   int result;
00299 
00300   iMesh_getArrData(instance_, entities, num_entities, dim_tag,
00301                    &values, &values_alloc, &values_size, &result);
00302   PROCESS_ERROR;
00303   RETURNR(iBase_SUCCESS);
00304 }
00305 
00306 int MeshAssocPairSide::get_dims(iBase_EntitySetHandle *sets, int num_sets,
00307                                 int *values)
00308 {
00309   char *data = reinterpret_cast<char*>(values);
00310   int values_alloc = sizeof(int);
00311   int values_size;
00312   int result;
00313 
00314   for (int i = 0; i < num_sets; i++) {
00315     iMesh_getEntSetData(instance_, sets[i], dim_tag,
00316                         reinterpret_cast<void**>(&data),
00317                         &values_alloc, &values_size, &result);
00318     data += values_size;
00319     PROCESS_ERROR;
00320   }
00321   RETURNR(iBase_SUCCESS);
00322 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines