00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "SMESH_Client.hxx"
00027 #include "SMESH_Mesh.hxx"
00028
00029 #include "SALOME_NamingService.hxx"
00030 #include "SALOME_LifeCycleCORBA.hxx"
00031
00032 #include <SALOMEconfig.h>
00033 #include CORBA_SERVER_HEADER(SALOME_Component)
00034 #include CORBA_SERVER_HEADER(SALOME_Exception)
00035
00036 #include "Basics_Utils.hxx"
00037 #include "utilities.h"
00038
00039 #ifdef WNT
00040 #include <process.h>
00041 #else
00042 #include <unistd.h>
00043 #endif
00044
00045 #include <stdexcept>
00046
00047 #ifndef EXCEPTION
00048 #define EXCEPTION(TYPE, MSG) {\
00049 std::ostringstream aStream;\
00050 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
00051 throw TYPE(aStream.str());\
00052 }
00053 #endif
00054
00055 #ifdef _DEBUG_
00056 static int MYDEBUG = 1;
00057 #else
00058 static int MYDEBUG = 0;
00059 #endif
00060
00061 namespace
00062 {
00063
00064
00065
00066
00067 inline const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, int theId){
00068 if(const SMDS_MeshNode* anElem = theMesh->FindNode(theId)) return anElem;
00069 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
00070 }
00071
00072
00073
00074
00075
00076 inline const SMDS_MeshElement* FindElement(const SMDS_Mesh* theMesh, int theId){
00077 if(const SMDS_MeshElement* anElem = theMesh->FindElement(theId)) return anElem;
00078 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot find a SMDS_MeshElement for ID = "<<theId);
00079 }
00080
00081
00082
00083
00084
00085 inline void AddNodesWithID(SMDS_Mesh* theMesh,
00086 SMESH::log_array_var& theSeq,
00087 CORBA::Long theId)
00088 {
00089 const SMESH::double_array& aCoords = theSeq[theId].coords;
00090 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00091 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00092 if(3*aNbElems != aCoords.length())
00093 EXCEPTION(runtime_error,"AddNodesWithID - 3*aNbElems != aCoords.length()");
00094 for(CORBA::Long aCoordId = 0; anElemId < aNbElems; anElemId++, aCoordId+=3){
00095 SMDS_MeshElement* anElem = theMesh->AddNodeWithID(aCoords[aCoordId],
00096 aCoords[aCoordId+1],
00097 aCoords[aCoordId+2],
00098 anIndexes[anElemId]);
00099 if(!anElem)
00100 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddNodeWithID for ID = "<<anElemId);
00101 }
00102 }
00103
00104
00105
00106
00107
00108 inline void Add0DElementsWithID(SMDS_Mesh* theMesh,
00109 SMESH::log_array_var& theSeq,
00110 CORBA::Long theId)
00111 {
00112 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00113 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00114 if (2*aNbElems != anIndexes.length())
00115 EXCEPTION(runtime_error,"AddEdgeWithID - 2*aNbElems != aCoords.length()");
00116 CORBA::Long anIndexId = 0;
00117 for (; anElemId < aNbElems; anElemId++, anIndexId+=2)
00118 {
00119 SMDS_MeshElement* anElem = theMesh->Add0DElementWithID(anIndexes[anIndexId+1],
00120 anIndexes[anIndexId]);
00121 if (!anElem)
00122 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot Add0DElementWithID for ID = "<<anElemId);
00123 }
00124 }
00125
00126
00127
00128
00129
00130 inline void AddEdgesWithID(SMDS_Mesh* theMesh,
00131 SMESH::log_array_var& theSeq,
00132 CORBA::Long theId)
00133 {
00134 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00135 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00136 if(3*aNbElems != anIndexes.length())
00137 EXCEPTION(runtime_error,"AddEdgeWithID - 3*aNbElems != aCoords.length()");
00138 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=3){
00139 SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
00140 anIndexes[anIndexId+2],
00141 anIndexes[anIndexId]);
00142 if(!anElem)
00143 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
00144 }
00145 }
00146
00147
00148
00149
00150
00151 inline void AddTriasWithID(SMDS_Mesh* theMesh,
00152 SMESH::log_array_var& theSeq,
00153 CORBA::Long theId)
00154 {
00155 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00156 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00157 if(4*aNbElems != anIndexes.length())
00158 EXCEPTION(runtime_error,"AddTriasWithID - 4*aNbElems != anIndexes.length()");
00159 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
00160 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00161 anIndexes[anIndexId+2],
00162 anIndexes[anIndexId+3],
00163 anIndexes[anIndexId]);
00164 if(!anElem)
00165 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
00166 }
00167 }
00168
00169
00170
00171
00172
00173 inline void AddQuadsWithID(SMDS_Mesh* theMesh,
00174 SMESH::log_array_var theSeq,
00175 CORBA::Long theId)
00176 {
00177 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00178 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00179 if(5*aNbElems != anIndexes.length())
00180 EXCEPTION(runtime_error,"AddQuadsWithID - 4*aNbElems != anIndexes.length()");
00181 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
00182 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00183 anIndexes[anIndexId+2],
00184 anIndexes[anIndexId+3],
00185 anIndexes[anIndexId+4],
00186 anIndexes[anIndexId]);
00187 if(!anElem)
00188 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
00189 }
00190 }
00191
00192
00193
00194
00195
00196 inline void AddPolygonsWithID(SMDS_Mesh* theMesh,
00197 SMESH::log_array_var& theSeq,
00198 CORBA::Long theId)
00199 {
00200 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00201 CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
00202
00203 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
00204 int aFaceId = anIndexes[anIndexId++];
00205
00206 int aNbNodes = anIndexes[anIndexId++];
00207 std::vector<int> nodes_ids (aNbNodes);
00208 for (int i = 0; i < aNbNodes; i++) {
00209 nodes_ids[i] = anIndexes[anIndexId++];
00210 }
00211
00212 SMDS_MeshElement* anElem = theMesh->AddPolygonalFaceWithID(nodes_ids, aFaceId);
00213 if (!anElem)
00214 EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolygonalFaceWithID for ID = "
00215 << anElemId);
00216 }
00217 }
00218
00219
00220
00221
00222
00223 inline void AddTetrasWithID(SMDS_Mesh* theMesh,
00224 SMESH::log_array_var& theSeq,
00225 CORBA::Long theId)
00226 {
00227 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00228 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00229 if(5*aNbElems != anIndexes.length())
00230 EXCEPTION(runtime_error,"AddTetrasWithID - 5*aNbElems != anIndexes.length()");
00231 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
00232 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00233 anIndexes[anIndexId+2],
00234 anIndexes[anIndexId+3],
00235 anIndexes[anIndexId+4],
00236 anIndexes[anIndexId]);
00237 if(!anElem)
00238 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00239 }
00240 }
00241
00242
00243
00244
00245
00246 inline void AddPiramidsWithID(SMDS_Mesh* theMesh,
00247 SMESH::log_array_var& theSeq,
00248 CORBA::Long theId)
00249 {
00250 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00251 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00252 if(6*aNbElems != anIndexes.length())
00253 EXCEPTION(runtime_error,"AddPiramidsWithID - 6*aNbElems != anIndexes.length()");
00254 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=6){
00255 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00256 anIndexes[anIndexId+2],
00257 anIndexes[anIndexId+3],
00258 anIndexes[anIndexId+4],
00259 anIndexes[anIndexId+5],
00260 anIndexes[anIndexId]);
00261 if(!anElem)
00262 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00263 }
00264 }
00265
00266
00267
00268
00269
00270 inline void AddPrismsWithID(SMDS_Mesh* theMesh,
00271 SMESH::log_array_var& theSeq,
00272 CORBA::Long theId)
00273 {
00274 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00275 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00276 if(7*aNbElems != anIndexes.length())
00277 EXCEPTION(runtime_error,"AddPrismsWithID - 7*aNbElems != anIndexes.length()");
00278 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
00279 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00280 anIndexes[anIndexId+2],
00281 anIndexes[anIndexId+3],
00282 anIndexes[anIndexId+4],
00283 anIndexes[anIndexId+5],
00284 anIndexes[anIndexId+6],
00285 anIndexes[anIndexId]);
00286 if(!anElem)
00287 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00288 }
00289 }
00290
00291
00292
00293
00294
00295 inline void AddHexasWithID(SMDS_Mesh* theMesh,
00296 SMESH::log_array_var& theSeq,
00297 CORBA::Long theId)
00298 {
00299 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00300 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00301 if(9*aNbElems != anIndexes.length())
00302 EXCEPTION(runtime_error,"AddHexasWithID - 9*aNbElems != anIndexes.length()");
00303 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
00304 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00305 anIndexes[anIndexId+2],
00306 anIndexes[anIndexId+3],
00307 anIndexes[anIndexId+4],
00308 anIndexes[anIndexId+5],
00309 anIndexes[anIndexId+6],
00310 anIndexes[anIndexId+7],
00311 anIndexes[anIndexId+8],
00312 anIndexes[anIndexId]);
00313 if(!anElem)
00314 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00315 }
00316 }
00317
00318
00319
00320
00321
00322 inline void AddPolyhedronsWithID (SMDS_Mesh* theMesh,
00323 SMESH::log_array_var& theSeq,
00324 CORBA::Long theId)
00325 {
00326 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00327 CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
00328
00329 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
00330 int aFaceId = anIndexes[anIndexId++];
00331
00332 int aNbNodes = anIndexes[anIndexId++];
00333 std::vector<int> nodes_ids (aNbNodes);
00334 for (int i = 0; i < aNbNodes; i++) {
00335 nodes_ids[i] = anIndexes[anIndexId++];
00336 }
00337
00338 int aNbFaces = anIndexes[anIndexId++];
00339 std::vector<int> quantities (aNbFaces);
00340 for (int i = 0; i < aNbFaces; i++) {
00341 quantities[i] = anIndexes[anIndexId++];
00342 }
00343
00344 SMDS_MeshElement* anElem =
00345 theMesh->AddPolyhedralVolumeWithID(nodes_ids, quantities, aFaceId);
00346 if (!anElem)
00347 EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolyhedralVolumeWithID for ID = "
00348 << anElemId);
00349 }
00350 }
00351
00352
00353
00354
00355
00356 inline void AddQuadEdgesWithID(SMDS_Mesh* theMesh,
00357 SMESH::log_array_var& theSeq,
00358 CORBA::Long theId)
00359 {
00360 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00361 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00362 if(4*aNbElems != anIndexes.length())
00363 EXCEPTION(runtime_error,"AddQuadEdgeWithID - 4*aNbElems != aCoords.length()");
00364 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
00365 SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
00366 anIndexes[anIndexId+2],
00367 anIndexes[anIndexId+3],
00368 anIndexes[anIndexId]);
00369 if(!anElem)
00370 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
00371 }
00372 }
00373
00374
00375
00376
00377
00378 inline void AddQuadTriasWithID(SMDS_Mesh* theMesh,
00379 SMESH::log_array_var& theSeq,
00380 CORBA::Long theId)
00381 {
00382 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00383 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00384 if(7*aNbElems != anIndexes.length())
00385 EXCEPTION(runtime_error,"AddQuadTriasWithID - 7*aNbElems != anIndexes.length()");
00386 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
00387 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00388 anIndexes[anIndexId+2],
00389 anIndexes[anIndexId+3],
00390 anIndexes[anIndexId+4],
00391 anIndexes[anIndexId+5],
00392 anIndexes[anIndexId+6],
00393 anIndexes[anIndexId]);
00394 if(!anElem)
00395 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
00396 }
00397 }
00398
00399
00400
00401
00402
00403 inline void AddQuadQuadsWithID(SMDS_Mesh* theMesh,
00404 SMESH::log_array_var theSeq,
00405 CORBA::Long theId)
00406 {
00407 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00408 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00409 if(9*aNbElems != anIndexes.length())
00410 EXCEPTION(runtime_error,"AddQuadQuadsWithID - 9*aNbElems != anIndexes.length()");
00411 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
00412 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00413 anIndexes[anIndexId+2],
00414 anIndexes[anIndexId+3],
00415 anIndexes[anIndexId+4],
00416 anIndexes[anIndexId+5],
00417 anIndexes[anIndexId+6],
00418 anIndexes[anIndexId+7],
00419 anIndexes[anIndexId+8],
00420 anIndexes[anIndexId]);
00421 if(!anElem)
00422 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
00423 }
00424 }
00425
00426
00427
00428
00429
00430 inline void AddQuadTetrasWithID(SMDS_Mesh* theMesh,
00431 SMESH::log_array_var& theSeq,
00432 CORBA::Long theId)
00433 {
00434 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00435 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00436 if(11*aNbElems != anIndexes.length())
00437 EXCEPTION(runtime_error,"AddQuadTetrasWithID - 11*aNbElems != anIndexes.length()");
00438 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=11){
00439 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00440 anIndexes[anIndexId+2],
00441 anIndexes[anIndexId+3],
00442 anIndexes[anIndexId+4],
00443 anIndexes[anIndexId+5],
00444 anIndexes[anIndexId+6],
00445 anIndexes[anIndexId+7],
00446 anIndexes[anIndexId+8],
00447 anIndexes[anIndexId+9],
00448 anIndexes[anIndexId+10],
00449 anIndexes[anIndexId]);
00450 if(!anElem)
00451 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00452 }
00453 }
00454
00455
00456
00457
00458
00459 inline void AddQuadPiramidsWithID(SMDS_Mesh* theMesh,
00460 SMESH::log_array_var& theSeq,
00461 CORBA::Long theId)
00462 {
00463 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00464 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00465 if(14*aNbElems != anIndexes.length())
00466 EXCEPTION(runtime_error,"AddQuadPiramidsWithID - 14*aNbElems != anIndexes.length()");
00467 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=14){
00468 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00469 anIndexes[anIndexId+2],
00470 anIndexes[anIndexId+3],
00471 anIndexes[anIndexId+4],
00472 anIndexes[anIndexId+5],
00473 anIndexes[anIndexId+6],
00474 anIndexes[anIndexId+7],
00475 anIndexes[anIndexId+8],
00476 anIndexes[anIndexId+9],
00477 anIndexes[anIndexId+10],
00478 anIndexes[anIndexId+11],
00479 anIndexes[anIndexId+12],
00480 anIndexes[anIndexId+13],
00481 anIndexes[anIndexId]);
00482 if(!anElem)
00483 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00484 }
00485 }
00486
00487
00488
00489
00490
00491 inline void AddQuadPentasWithID(SMDS_Mesh* theMesh,
00492 SMESH::log_array_var& theSeq,
00493 CORBA::Long theId)
00494 {
00495 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00496 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00497 if(16*aNbElems != anIndexes.length())
00498 EXCEPTION(runtime_error,"AddQuadPentasWithID - 16*aNbElems != anIndexes.length()");
00499 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=16){
00500 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00501 anIndexes[anIndexId+2],
00502 anIndexes[anIndexId+3],
00503 anIndexes[anIndexId+4],
00504 anIndexes[anIndexId+5],
00505 anIndexes[anIndexId+6],
00506 anIndexes[anIndexId+7],
00507 anIndexes[anIndexId+8],
00508 anIndexes[anIndexId+9],
00509 anIndexes[anIndexId+10],
00510 anIndexes[anIndexId+11],
00511 anIndexes[anIndexId+12],
00512 anIndexes[anIndexId+13],
00513 anIndexes[anIndexId+14],
00514 anIndexes[anIndexId+15],
00515 anIndexes[anIndexId]);
00516 if(!anElem)
00517 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00518 }
00519 }
00520
00521
00522
00523
00524
00525 inline void AddQuadHexasWithID(SMDS_Mesh* theMesh,
00526 SMESH::log_array_var& theSeq,
00527 CORBA::Long theId)
00528 {
00529 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00530 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00531 if(21*aNbElems != anIndexes.length())
00532 EXCEPTION(runtime_error,"AddQuadHexasWithID - 21*aNbElems != anIndexes.length()");
00533 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=21){
00534 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00535 anIndexes[anIndexId+2],
00536 anIndexes[anIndexId+3],
00537 anIndexes[anIndexId+4],
00538 anIndexes[anIndexId+5],
00539 anIndexes[anIndexId+6],
00540 anIndexes[anIndexId+7],
00541 anIndexes[anIndexId+8],
00542 anIndexes[anIndexId+9],
00543 anIndexes[anIndexId+10],
00544 anIndexes[anIndexId+11],
00545 anIndexes[anIndexId+12],
00546 anIndexes[anIndexId+13],
00547 anIndexes[anIndexId+14],
00548 anIndexes[anIndexId+15],
00549 anIndexes[anIndexId+16],
00550 anIndexes[anIndexId+17],
00551 anIndexes[anIndexId+18],
00552 anIndexes[anIndexId+19],
00553 anIndexes[anIndexId+20],
00554 anIndexes[anIndexId]);
00555 if(!anElem)
00556 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00557 }
00558 }
00559
00560
00561
00562
00563
00564 inline void ChangePolyhedronNodes (SMDS_Mesh* theMesh,
00565 SMESH::log_array_var& theSeq,
00566 CORBA::Long theId)
00567 {
00568 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00569 CORBA::Long iind = 0, aNbElems = theSeq[theId].number;
00570
00571 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++)
00572 {
00573
00574 const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]);
00575
00576 int nbNodes = anIndexes[iind++];
00577
00578 std::vector<const SMDS_MeshNode*> aNodes (nbNodes);
00579 for (int iNode = 0; iNode < nbNodes; iNode++) {
00580 aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]);
00581 }
00582
00583 int nbFaces = anIndexes[iind++];
00584
00585 std::vector<int> quantities (nbFaces);
00586 for (int iFace = 0; iFace < nbFaces; iFace++) {
00587 quantities[iFace] = anIndexes[iind++];
00588 }
00589
00590 theMesh->ChangePolyhedronNodes(elem, aNodes, quantities);
00591 }
00592 }
00593 }
00594
00595
00596 SMESH::SMESH_Gen_var
00597 SMESH_Client::GetSMESHGen(CORBA::ORB_ptr theORB,
00598 CORBA::Boolean& theIsEmbeddedMode)
00599 {
00600 static SMESH::SMESH_Gen_var aMeshGen;
00601
00602 if(CORBA::is_nil(aMeshGen.in())){
00603 #ifdef WNT
00604 long aClientPID = (long)_getpid();
00605 #else
00606 long aClientPID = (long)getpid();
00607 #endif
00608
00609 SALOME_NamingService aNamingService(theORB);
00610 SALOME_LifeCycleCORBA aLifeCycleCORBA(&aNamingService);
00611 Engines::EngineComponent_var aComponent = aLifeCycleCORBA.FindOrLoad_Component("FactoryServer","SMESH");
00612 aMeshGen = SMESH::SMESH_Gen::_narrow(aComponent);
00613
00614 std::string aClientHostName = Kernel_Utils::GetHostname();
00615 Engines::Container_var aServerContainer = aMeshGen->GetContainerRef();
00616 CORBA::String_var aServerHostName = aServerContainer->getHostName();
00617 CORBA::Long aServerPID = aServerContainer->getPID();
00618 aMeshGen->SetEmbeddedMode((aClientPID == aServerPID) && (aClientHostName == aServerHostName.in()));
00619 }
00620 theIsEmbeddedMode = aMeshGen->IsEmbeddedMode();
00621
00622 return aMeshGen;
00623 }
00624
00625
00626
00627
00628
00629
00630 SMESH_Client::SMESH_Client(CORBA::ORB_ptr theORB,
00631 SMESH::SMESH_Mesh_ptr theMesh):
00632 myMeshServer(SMESH::SMESH_Mesh::_duplicate(theMesh)),
00633 mySMESHDSMesh(NULL),
00634 mySMDSMesh(NULL)
00635 {
00636 MESSAGE("SMESH_Client::SMESH_Client");
00637 myMeshServer->Register();
00638
00639 CORBA::Boolean anIsEmbeddedMode;
00640 GetSMESHGen(theORB,anIsEmbeddedMode);
00641 if(anIsEmbeddedMode){
00642 if ( MYDEBUG )
00643 MESSAGE("Info: The same process, update mesh by pointer ");
00644
00645
00646 CORBA::LongLong pointeur = theMesh->GetMeshPtr();
00647 if( MYDEBUG )
00648 MESSAGE("SMESH_Client::SMESH_Client pointeur "<<pointeur);
00649 SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*> (pointeur);
00650 if ( MYDEBUG )
00651 MESSAGE("SMESH_Client::SMESH_Client aMesh "<<aMesh);
00652
00653 if(anIsEmbeddedMode){
00654 mySMESHDSMesh = aMesh->GetMeshDS();
00655 mySMDSMesh = mySMESHDSMesh;
00656 }
00657 }
00658 if(!mySMDSMesh)
00659 mySMDSMesh = new SMDS_Mesh();
00660 }
00661
00662
00663
00664
00665
00666
00667 SMESH_Client::~SMESH_Client()
00668 {
00669 myMeshServer->UnRegister();
00670 if(!mySMESHDSMesh)
00671 delete mySMDSMesh;
00672 }
00673
00674
00675
00676 SMDS_Mesh*
00677 SMESH_Client::GetMesh() const
00678 {
00679 return mySMDSMesh;
00680 }
00681
00682
00683
00684 SMDS_Mesh*
00685 SMESH_Client::operator->() const
00686 {
00687 return GetMesh();
00688 }
00689
00690
00691
00692 SMESH::SMESH_Mesh_ptr
00693 SMESH_Client::GetMeshServer()
00694 {
00695 return myMeshServer.in();
00696 }
00697
00698
00699
00700
00701
00702
00703 bool
00704 SMESH_Client::Update(bool theIsClear)
00705 {
00706 bool anIsModified = true;
00707 if(mySMESHDSMesh){
00708 MESSAGE("Update mySMESHDSMesh");
00709 SMESHDS_Script* aScript = mySMESHDSMesh->GetScript();
00710 anIsModified = aScript->IsModified();
00711 aScript->SetModified(false);
00712 }else{
00713 MESSAGE("Update CORBA");
00714 SMESH::log_array_var aSeq = myMeshServer->GetLog( theIsClear );
00715 CORBA::Long aLength = aSeq->length();
00716 anIsModified = aLength > 0;
00717 if( MYDEBUG )
00718 MESSAGE( "Update: length of the script is "<<aLength );
00719
00720 if(!anIsModified)
00721 return false;
00722
00723
00724 try
00725 {
00726 for ( CORBA::Long anId = 0; anId < aLength; anId++)
00727 {
00728 const SMESH::double_array& aCoords = aSeq[anId].coords;
00729 const SMESH::long_array& anIndexes = aSeq[anId].indexes;
00730 CORBA::Long anElemId = 0, aNbElems = aSeq[anId].number;
00731 CORBA::Long aCommand = aSeq[anId].commandType;
00732
00733 switch(aCommand)
00734 {
00735 case SMESH::ADD_NODE : AddNodesWithID ( mySMDSMesh, aSeq, anId ); break;
00736 case SMESH::ADD_ELEM0D : Add0DElementsWithID ( mySMDSMesh, aSeq, anId ); break;
00737 case SMESH::ADD_EDGE : AddEdgesWithID ( mySMDSMesh, aSeq, anId ); break;
00738 case SMESH::ADD_TRIANGLE : AddTriasWithID ( mySMDSMesh, aSeq, anId ); break;
00739 case SMESH::ADD_QUADRANGLE : AddQuadsWithID ( mySMDSMesh, aSeq, anId ); break;
00740 case SMESH::ADD_POLYGON : AddPolygonsWithID ( mySMDSMesh, aSeq, anId ); break;
00741 case SMESH::ADD_TETRAHEDRON: AddTetrasWithID ( mySMDSMesh, aSeq, anId ); break;
00742 case SMESH::ADD_PYRAMID : AddPiramidsWithID ( mySMDSMesh, aSeq, anId ); break;
00743 case SMESH::ADD_PRISM : AddPrismsWithID ( mySMDSMesh, aSeq, anId ); break;
00744 case SMESH::ADD_HEXAHEDRON : AddHexasWithID ( mySMDSMesh, aSeq, anId ); break;
00745 case SMESH::ADD_POLYHEDRON : AddPolyhedronsWithID( mySMDSMesh, aSeq, anId ); break;
00746
00747 case SMESH::ADD_QUADEDGE : AddQuadEdgesWithID ( mySMDSMesh, aSeq, anId ); break;
00748 case SMESH::ADD_QUADTRIANGLE : AddQuadTriasWithID ( mySMDSMesh, aSeq, anId ); break;
00749 case SMESH::ADD_QUADQUADRANGLE : AddQuadQuadsWithID ( mySMDSMesh, aSeq, anId ); break;
00750 case SMESH::ADD_QUADTETRAHEDRON: AddQuadTetrasWithID ( mySMDSMesh, aSeq, anId ); break;
00751 case SMESH::ADD_QUADPYRAMID : AddQuadPiramidsWithID( mySMDSMesh, aSeq, anId ); break;
00752 case SMESH::ADD_QUADPENTAHEDRON: AddQuadPentasWithID ( mySMDSMesh, aSeq, anId ); break;
00753 case SMESH::ADD_QUADHEXAHEDRON : AddQuadHexasWithID ( mySMDSMesh, aSeq, anId ); break;
00754
00755 case SMESH::CLEAR_MESH:
00756 mySMDSMesh->Clear();
00757 break;
00758
00759 case SMESH::REMOVE_NODE:
00760 for( ; anElemId < aNbElems; anElemId++ )
00761 mySMDSMesh->RemoveNode( FindNode( mySMDSMesh, anIndexes[anElemId] ) );
00762 break;
00763
00764 case SMESH::REMOVE_ELEMENT:
00765 for( ; anElemId < aNbElems; anElemId++ )
00766 mySMDSMesh->RemoveElement( FindElement( mySMDSMesh, anIndexes[anElemId] ) );
00767 break;
00768
00769 case SMESH::MOVE_NODE:
00770 for(CORBA::Long aCoordId=0; anElemId < aNbElems; anElemId++, aCoordId+=3)
00771 {
00772 SMDS_MeshNode* node =
00773 const_cast<SMDS_MeshNode*>( FindNode( mySMDSMesh, anIndexes[anElemId] ));
00774 node->setXYZ( aCoords[aCoordId], aCoords[aCoordId+1], aCoords[aCoordId+2] );
00775 }
00776 break;
00777
00778 case SMESH::CHANGE_ELEMENT_NODES:
00779 for ( CORBA::Long i = 0; anElemId < aNbElems; anElemId++ )
00780 {
00781
00782 const SMDS_MeshElement* elem = FindElement( mySMDSMesh, anIndexes[i++] );
00783
00784 int nbNodes = anIndexes[i++];
00785
00786
00787 vector<const SMDS_MeshNode*> aNodes( nbNodes );
00788 for ( int iNode = 0; iNode < nbNodes; iNode++ )
00789 aNodes[ iNode ] = FindNode( mySMDSMesh, anIndexes[i++] );
00790
00791 mySMDSMesh->ChangeElementNodes( elem, &aNodes[0], nbNodes );
00792 }
00793 break;
00794
00795 case SMESH::CHANGE_POLYHEDRON_NODES:
00796 ChangePolyhedronNodes(mySMDSMesh, aSeq, anId);
00797 break;
00798 case SMESH::RENUMBER:
00799 for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3)
00800 {
00801 mySMDSMesh->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] );
00802 }
00803 break;
00804
00805 default:;
00806 }
00807 }
00808 }
00809 catch ( SALOME::SALOME_Exception& exc )
00810 {
00811 INFOS("Following exception was cought:\n\t"<<exc.details.text);
00812 }
00813 catch( const std::exception& exc)
00814 {
00815 INFOS("Following exception was cought:\n\t"<<exc.what());
00816 }
00817 catch(...)
00818 {
00819 INFOS("Unknown exception was cought !!!");
00820 }
00821
00822 if ( MYDEBUG && mySMDSMesh )
00823 {
00824 MESSAGE("Update - mySMDSMesh->NbNodes() = "<<mySMDSMesh->NbNodes());
00825 MESSAGE("Update - mySMDSMesh->Nb0DElements() = "<<mySMDSMesh->Nb0DElements());
00826 MESSAGE("Update - mySMDSMesh->NbEdges() = "<<mySMDSMesh->NbEdges());
00827 MESSAGE("Update - mySMDSMesh->NbFaces() = "<<mySMDSMesh->NbFaces());
00828 MESSAGE("Update - mySMDSMesh->NbVolumes() = "<<mySMDSMesh->NbVolumes());
00829 }
00830 }
00831
00832 return anIsModified;
00833 }