1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHClient : tool to update client mesh structure by mesh from server
23 // File : SMESH_Client.cxx
24 // Author : Pavel TELKOV
27 #include "SMESH_Client.hxx"
28 #include "SMESH_Mesh.hxx"
30 #include "SALOME_NamingService.hxx"
31 #include "SALOME_LifeCycleCORBA.hxx"
33 #include <SALOMEconfig.h>
34 #include CORBA_SERVER_HEADER(SALOME_Component)
35 #include CORBA_SERVER_HEADER(SALOME_Exception)
37 #include "Basics_Utils.hxx"
38 #include "utilities.h"
49 #define EXCEPTION(TYPE, MSG) {\
50 std::ostringstream aStream;\
51 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
52 throw TYPE(aStream.str());\
57 static int MYDEBUG = 1;
59 static int MYDEBUG = 0;
65 //=======================================================================
67 //=======================================================================
68 inline const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, int theId){
69 if(const SMDS_MeshNode* anElem = theMesh->FindNode(theId)) return anElem;
70 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
74 //=======================================================================
75 //function : FindElement
76 //=======================================================================
77 inline const SMDS_MeshElement* FindElement(const SMDS_Mesh* theMesh, int theId){
78 if(const SMDS_MeshElement* anElem = theMesh->FindElement(theId)) return anElem;
79 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot find a SMDS_MeshElement for ID = "<<theId);
83 //=======================================================================
84 //function : AddNodesWithID
85 //=======================================================================
86 inline void AddNodesWithID(SMDS_Mesh* theMesh,
87 SMESH::log_array_var& theSeq,
90 const SMESH::double_array& aCoords = theSeq[theId].coords;
91 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
92 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
93 if(3*aNbElems != aCoords.length())
94 EXCEPTION(runtime_error,"AddNodesWithID - 3*aNbElems != aCoords.length()");
95 for(CORBA::Long aCoordId = 0; anElemId < aNbElems; anElemId++, aCoordId+=3){
96 SMDS_MeshElement* anElem = theMesh->AddNodeWithID(aCoords[aCoordId],
101 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddNodeWithID for ID = "<<anElemId);
106 //=======================================================================
107 //function : Add0DElementsWithID
108 //=======================================================================
109 inline void Add0DElementsWithID(SMDS_Mesh* theMesh,
110 SMESH::log_array_var& theSeq,
113 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
114 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
115 if (2*aNbElems != anIndexes.length())
116 EXCEPTION(runtime_error,"AddEdgeWithID - 2*aNbElems != aCoords.length()");
117 CORBA::Long anIndexId = 0;
118 for (; anElemId < aNbElems; anElemId++, anIndexId+=2)
120 SMDS_MeshElement* anElem = theMesh->Add0DElementWithID(anIndexes[anIndexId+1],
121 anIndexes[anIndexId]);
123 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot Add0DElementWithID for ID = "<<anElemId);
128 //=======================================================================
129 //function : AddEdgesWithID
130 //=======================================================================
131 inline void AddEdgesWithID(SMDS_Mesh* theMesh,
132 SMESH::log_array_var& theSeq,
135 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
136 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
137 if(3*aNbElems != anIndexes.length())
138 EXCEPTION(runtime_error,"AddEdgeWithID - 3*aNbElems != aCoords.length()");
139 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=3){
140 SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
141 anIndexes[anIndexId+2],
142 anIndexes[anIndexId]);
144 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
149 //=======================================================================
150 //function : AddTriasWithID
151 //=======================================================================
152 inline void AddTriasWithID(SMDS_Mesh* theMesh,
153 SMESH::log_array_var& theSeq,
156 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
157 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
158 if(4*aNbElems != anIndexes.length())
159 EXCEPTION(runtime_error,"AddTriasWithID - 4*aNbElems != anIndexes.length()");
160 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
161 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
162 anIndexes[anIndexId+2],
163 anIndexes[anIndexId+3],
164 anIndexes[anIndexId]);
166 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
171 //=======================================================================
172 //function : AddQuadsWithID
173 //=======================================================================
174 inline void AddQuadsWithID(SMDS_Mesh* theMesh,
175 SMESH::log_array_var theSeq,
178 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
179 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
180 if(5*aNbElems != anIndexes.length())
181 EXCEPTION(runtime_error,"AddQuadsWithID - 4*aNbElems != anIndexes.length()");
182 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
183 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
184 anIndexes[anIndexId+2],
185 anIndexes[anIndexId+3],
186 anIndexes[anIndexId+4],
187 anIndexes[anIndexId]);
189 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
194 //=======================================================================
195 //function : AddPolygonsWithID
196 //=======================================================================
197 inline void AddPolygonsWithID(SMDS_Mesh* theMesh,
198 SMESH::log_array_var& theSeq,
201 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
202 CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
204 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
205 int aFaceId = anIndexes[anIndexId++];
207 int aNbNodes = anIndexes[anIndexId++];
208 std::vector<int> nodes_ids (aNbNodes);
209 for (int i = 0; i < aNbNodes; i++) {
210 nodes_ids[i] = anIndexes[anIndexId++];
213 SMDS_MeshElement* anElem = theMesh->AddPolygonalFaceWithID(nodes_ids, aFaceId);
215 EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolygonalFaceWithID for ID = "
221 //=======================================================================
222 //function : AddTetrasWithID
223 //=======================================================================
224 inline void AddTetrasWithID(SMDS_Mesh* theMesh,
225 SMESH::log_array_var& theSeq,
228 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
229 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
230 if(5*aNbElems != anIndexes.length())
231 EXCEPTION(runtime_error,"AddTetrasWithID - 5*aNbElems != anIndexes.length()");
232 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
233 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
234 anIndexes[anIndexId+2],
235 anIndexes[anIndexId+3],
236 anIndexes[anIndexId+4],
237 anIndexes[anIndexId]);
239 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
244 //=======================================================================
245 //function : AddPiramidsWithID
246 //=======================================================================
247 inline void AddPiramidsWithID(SMDS_Mesh* theMesh,
248 SMESH::log_array_var& theSeq,
251 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
252 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
253 if(6*aNbElems != anIndexes.length())
254 EXCEPTION(runtime_error,"AddPiramidsWithID - 6*aNbElems != anIndexes.length()");
255 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=6){
256 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
257 anIndexes[anIndexId+2],
258 anIndexes[anIndexId+3],
259 anIndexes[anIndexId+4],
260 anIndexes[anIndexId+5],
261 anIndexes[anIndexId]);
263 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
268 //=======================================================================
269 //function : AddPrismsWithID
270 //=======================================================================
271 inline void AddPrismsWithID(SMDS_Mesh* theMesh,
272 SMESH::log_array_var& theSeq,
275 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
276 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
277 if(7*aNbElems != anIndexes.length())
278 EXCEPTION(runtime_error,"AddPrismsWithID - 7*aNbElems != anIndexes.length()");
279 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
280 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
281 anIndexes[anIndexId+2],
282 anIndexes[anIndexId+3],
283 anIndexes[anIndexId+4],
284 anIndexes[anIndexId+5],
285 anIndexes[anIndexId+6],
286 anIndexes[anIndexId]);
288 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
293 //=======================================================================
294 //function : AddHexasWithID
295 //=======================================================================
296 inline void AddHexasWithID(SMDS_Mesh* theMesh,
297 SMESH::log_array_var& theSeq,
300 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
301 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
302 if(9*aNbElems != anIndexes.length())
303 EXCEPTION(runtime_error,"AddHexasWithID - 9*aNbElems != anIndexes.length()");
304 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
305 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
306 anIndexes[anIndexId+2],
307 anIndexes[anIndexId+3],
308 anIndexes[anIndexId+4],
309 anIndexes[anIndexId+5],
310 anIndexes[anIndexId+6],
311 anIndexes[anIndexId+7],
312 anIndexes[anIndexId+8],
313 anIndexes[anIndexId]);
315 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
320 //=======================================================================
321 //function : AddPolyhedronsWithID
322 //=======================================================================
323 inline void AddPolyhedronsWithID (SMDS_Mesh* theMesh,
324 SMESH::log_array_var& theSeq,
327 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
328 CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
330 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
331 int aFaceId = anIndexes[anIndexId++];
333 int aNbNodes = anIndexes[anIndexId++];
334 std::vector<int> nodes_ids (aNbNodes);
335 for (int i = 0; i < aNbNodes; i++) {
336 nodes_ids[i] = anIndexes[anIndexId++];
339 int aNbFaces = anIndexes[anIndexId++];
340 std::vector<int> quantities (aNbFaces);
341 for (int i = 0; i < aNbFaces; i++) {
342 quantities[i] = anIndexes[anIndexId++];
345 SMDS_MeshElement* anElem =
346 theMesh->AddPolyhedralVolumeWithID(nodes_ids, quantities, aFaceId);
348 EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolyhedralVolumeWithID for ID = "
354 //=======================================================================
355 //function : AddQuadEdgesWithID
356 //=======================================================================
357 inline void AddQuadEdgesWithID(SMDS_Mesh* theMesh,
358 SMESH::log_array_var& theSeq,
361 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
362 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
363 if(4*aNbElems != anIndexes.length())
364 EXCEPTION(runtime_error,"AddQuadEdgeWithID - 4*aNbElems != aCoords.length()");
365 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
366 SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
367 anIndexes[anIndexId+2],
368 anIndexes[anIndexId+3],
369 anIndexes[anIndexId]);
371 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
376 //=======================================================================
377 //function : AddQuadTriasWithID
378 //=======================================================================
379 inline void AddQuadTriasWithID(SMDS_Mesh* theMesh,
380 SMESH::log_array_var& theSeq,
383 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
384 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
385 if(7*aNbElems != anIndexes.length())
386 EXCEPTION(runtime_error,"AddQuadTriasWithID - 7*aNbElems != anIndexes.length()");
387 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
388 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
389 anIndexes[anIndexId+2],
390 anIndexes[anIndexId+3],
391 anIndexes[anIndexId+4],
392 anIndexes[anIndexId+5],
393 anIndexes[anIndexId+6],
394 anIndexes[anIndexId]);
396 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
401 //=======================================================================
402 //function : AddQuadQuadsWithID
403 //=======================================================================
404 inline void AddQuadQuadsWithID(SMDS_Mesh* theMesh,
405 SMESH::log_array_var theSeq,
408 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
409 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
410 if(9*aNbElems != anIndexes.length())
411 EXCEPTION(runtime_error,"AddQuadQuadsWithID - 9*aNbElems != anIndexes.length()");
412 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
413 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
414 anIndexes[anIndexId+2],
415 anIndexes[anIndexId+3],
416 anIndexes[anIndexId+4],
417 anIndexes[anIndexId+5],
418 anIndexes[anIndexId+6],
419 anIndexes[anIndexId+7],
420 anIndexes[anIndexId+8],
421 anIndexes[anIndexId]);
423 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
428 //=======================================================================
429 //function : AddQuadTetrasWithID
430 //=======================================================================
431 inline void AddQuadTetrasWithID(SMDS_Mesh* theMesh,
432 SMESH::log_array_var& theSeq,
435 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
436 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
437 if(11*aNbElems != anIndexes.length())
438 EXCEPTION(runtime_error,"AddQuadTetrasWithID - 11*aNbElems != anIndexes.length()");
439 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=11){
440 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
441 anIndexes[anIndexId+2],
442 anIndexes[anIndexId+3],
443 anIndexes[anIndexId+4],
444 anIndexes[anIndexId+5],
445 anIndexes[anIndexId+6],
446 anIndexes[anIndexId+7],
447 anIndexes[anIndexId+8],
448 anIndexes[anIndexId+9],
449 anIndexes[anIndexId+10],
450 anIndexes[anIndexId]);
452 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
457 //=======================================================================
458 //function : AddQuadPiramidsWithID
459 //=======================================================================
460 inline void AddQuadPiramidsWithID(SMDS_Mesh* theMesh,
461 SMESH::log_array_var& theSeq,
464 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
465 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
466 if(14*aNbElems != anIndexes.length())
467 EXCEPTION(runtime_error,"AddQuadPiramidsWithID - 14*aNbElems != anIndexes.length()");
468 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=14){
469 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
470 anIndexes[anIndexId+2],
471 anIndexes[anIndexId+3],
472 anIndexes[anIndexId+4],
473 anIndexes[anIndexId+5],
474 anIndexes[anIndexId+6],
475 anIndexes[anIndexId+7],
476 anIndexes[anIndexId+8],
477 anIndexes[anIndexId+9],
478 anIndexes[anIndexId+10],
479 anIndexes[anIndexId+11],
480 anIndexes[anIndexId+12],
481 anIndexes[anIndexId+13],
482 anIndexes[anIndexId]);
484 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
489 //=======================================================================
490 //function : AddQuadPentasWithID
491 //=======================================================================
492 inline void AddQuadPentasWithID(SMDS_Mesh* theMesh,
493 SMESH::log_array_var& theSeq,
496 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
497 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
498 if(16*aNbElems != anIndexes.length())
499 EXCEPTION(runtime_error,"AddQuadPentasWithID - 16*aNbElems != anIndexes.length()");
500 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=16){
501 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
502 anIndexes[anIndexId+2],
503 anIndexes[anIndexId+3],
504 anIndexes[anIndexId+4],
505 anIndexes[anIndexId+5],
506 anIndexes[anIndexId+6],
507 anIndexes[anIndexId+7],
508 anIndexes[anIndexId+8],
509 anIndexes[anIndexId+9],
510 anIndexes[anIndexId+10],
511 anIndexes[anIndexId+11],
512 anIndexes[anIndexId+12],
513 anIndexes[anIndexId+13],
514 anIndexes[anIndexId+14],
515 anIndexes[anIndexId+15],
516 anIndexes[anIndexId]);
518 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
523 //=======================================================================
524 //function : AddQuadHexasWithID
525 //=======================================================================
526 inline void AddQuadHexasWithID(SMDS_Mesh* theMesh,
527 SMESH::log_array_var& theSeq,
530 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
531 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
532 if(21*aNbElems != anIndexes.length())
533 EXCEPTION(runtime_error,"AddQuadHexasWithID - 21*aNbElems != anIndexes.length()");
534 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=21){
535 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
536 anIndexes[anIndexId+2],
537 anIndexes[anIndexId+3],
538 anIndexes[anIndexId+4],
539 anIndexes[anIndexId+5],
540 anIndexes[anIndexId+6],
541 anIndexes[anIndexId+7],
542 anIndexes[anIndexId+8],
543 anIndexes[anIndexId+9],
544 anIndexes[anIndexId+10],
545 anIndexes[anIndexId+11],
546 anIndexes[anIndexId+12],
547 anIndexes[anIndexId+13],
548 anIndexes[anIndexId+14],
549 anIndexes[anIndexId+15],
550 anIndexes[anIndexId+16],
551 anIndexes[anIndexId+17],
552 anIndexes[anIndexId+18],
553 anIndexes[anIndexId+19],
554 anIndexes[anIndexId+20],
555 anIndexes[anIndexId]);
557 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
562 //=======================================================================
563 //function : ChangePolyhedronNodes
564 //=======================================================================
565 inline void ChangePolyhedronNodes (SMDS_Mesh* theMesh,
566 SMESH::log_array_var& theSeq,
569 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
570 CORBA::Long iind = 0, aNbElems = theSeq[theId].number;
572 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++)
575 const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]);
577 int nbNodes = anIndexes[iind++];
579 std::vector<const SMDS_MeshNode*> aNodes (nbNodes);
580 for (int iNode = 0; iNode < nbNodes; iNode++) {
581 aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]);
584 int nbFaces = anIndexes[iind++];
586 std::vector<int> quantities (nbFaces);
587 for (int iFace = 0; iFace < nbFaces; iFace++) {
588 quantities[iFace] = anIndexes[iind++];
591 theMesh->ChangePolyhedronNodes(elem, aNodes, quantities);
596 //=======================================================================
598 SMESH_Client::GetSMESHGen(CORBA::ORB_ptr theORB,
599 CORBA::Boolean& theIsEmbeddedMode)
601 static SMESH::SMESH_Gen_var aMeshGen;
603 if(CORBA::is_nil(aMeshGen.in())){
605 long aClientPID = (long)_getpid();
607 long aClientPID = (long)getpid();
610 SALOME_NamingService aNamingService(theORB);
611 SALOME_LifeCycleCORBA aLifeCycleCORBA(&aNamingService);
612 Engines::EngineComponent_var aComponent = aLifeCycleCORBA.FindOrLoad_Component("FactoryServer","SMESH");
613 aMeshGen = SMESH::SMESH_Gen::_narrow(aComponent);
615 std::string aClientHostName = Kernel_Utils::GetHostname();
616 Engines::Container_var aServerContainer = aMeshGen->GetContainerRef();
617 CORBA::String_var aServerHostName = aServerContainer->getHostName();
618 CORBA::Long aServerPID = aServerContainer->getPID();
619 aMeshGen->SetEmbeddedMode((aClientPID == aServerPID) && (aClientHostName == aServerHostName.in()));
621 theIsEmbeddedMode = aMeshGen->IsEmbeddedMode();
627 //=======================================================================
628 // function : Create()
630 //=======================================================================
631 SMESH_Client::SMESH_Client(CORBA::ORB_ptr theORB,
632 SMESH::SMESH_Mesh_ptr theMesh):
633 myMeshServer(SMESH::SMESH_Mesh::_duplicate(theMesh)),
637 MESSAGE("SMESH_Client::SMESH_Client");
638 myMeshServer->Register();
640 CORBA::Boolean anIsEmbeddedMode;
641 GetSMESHGen(theORB,anIsEmbeddedMode);
642 if(anIsEmbeddedMode){
644 MESSAGE("Info: The same process, update mesh by pointer ");
645 // just set client mesh pointer to server mesh pointer
646 //SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*>(theMesh->GetMeshPtr());
647 CORBA::LongLong pointeur = theMesh->GetMeshPtr();
649 MESSAGE("SMESH_Client::SMESH_Client pointeur "<<pointeur);
650 SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*> (pointeur);
652 MESSAGE("SMESH_Client::SMESH_Client aMesh "<<aMesh);
653 //if(aMesh->GetMeshDS()->IsEmbeddedMode()){
654 if(anIsEmbeddedMode){
655 mySMESHDSMesh = aMesh->GetMeshDS();
656 mySMDSMesh = mySMESHDSMesh;
660 mySMDSMesh = new SMDS_Mesh();
664 //=================================================================================
665 // function : ~SMESH_Client
666 // purpose : Destructor
667 //=================================================================================
668 SMESH_Client::~SMESH_Client()
670 myMeshServer->UnRegister();
676 //=================================================================================
678 SMESH_Client::GetMesh() const
684 //=================================================================================
686 SMESH_Client::operator->() const
692 //=================================================================================
693 SMESH::SMESH_Mesh_ptr
694 SMESH_Client::GetMeshServer()
696 return myMeshServer.in();
700 //=================================================================================
701 // function : SMESH_Client
702 // purpose : Update mesh
703 //=================================================================================
705 SMESH_Client::Update(bool theIsClear)
707 bool anIsModified = true;
709 MESSAGE("Update mySMESHDSMesh");
710 SMESHDS_Script* aScript = mySMESHDSMesh->GetScript();
711 anIsModified = aScript->IsModified();
712 aScript->SetModified(false);
714 MESSAGE("Update CORBA");
715 SMESH::log_array_var aSeq = myMeshServer->GetLog( theIsClear );
716 CORBA::Long aLength = aSeq->length();
717 anIsModified = aLength > 0;
719 MESSAGE( "Update: length of the script is "<<aLength );
724 // update client mesh structure by logged changes commands
727 for ( CORBA::Long anId = 0; anId < aLength; anId++)
729 const SMESH::double_array& aCoords = aSeq[anId].coords;
730 const SMESH::long_array& anIndexes = aSeq[anId].indexes;
731 CORBA::Long anElemId = 0, aNbElems = aSeq[anId].number;
732 CORBA::Long aCommand = aSeq[anId].commandType;
736 case SMESH::ADD_NODE : AddNodesWithID ( mySMDSMesh, aSeq, anId ); break;
737 case SMESH::ADD_ELEM0D : Add0DElementsWithID ( mySMDSMesh, aSeq, anId ); break;
738 case SMESH::ADD_EDGE : AddEdgesWithID ( mySMDSMesh, aSeq, anId ); break;
739 case SMESH::ADD_TRIANGLE : AddTriasWithID ( mySMDSMesh, aSeq, anId ); break;
740 case SMESH::ADD_QUADRANGLE : AddQuadsWithID ( mySMDSMesh, aSeq, anId ); break;
741 case SMESH::ADD_POLYGON : AddPolygonsWithID ( mySMDSMesh, aSeq, anId ); break;
742 case SMESH::ADD_TETRAHEDRON: AddTetrasWithID ( mySMDSMesh, aSeq, anId ); break;
743 case SMESH::ADD_PYRAMID : AddPiramidsWithID ( mySMDSMesh, aSeq, anId ); break;
744 case SMESH::ADD_PRISM : AddPrismsWithID ( mySMDSMesh, aSeq, anId ); break;
745 case SMESH::ADD_HEXAHEDRON : AddHexasWithID ( mySMDSMesh, aSeq, anId ); break;
746 case SMESH::ADD_POLYHEDRON : AddPolyhedronsWithID( mySMDSMesh, aSeq, anId ); break;
748 case SMESH::ADD_QUADEDGE : AddQuadEdgesWithID ( mySMDSMesh, aSeq, anId ); break;
749 case SMESH::ADD_QUADTRIANGLE : AddQuadTriasWithID ( mySMDSMesh, aSeq, anId ); break;
750 case SMESH::ADD_QUADQUADRANGLE : AddQuadQuadsWithID ( mySMDSMesh, aSeq, anId ); break;
751 case SMESH::ADD_QUADTETRAHEDRON: AddQuadTetrasWithID ( mySMDSMesh, aSeq, anId ); break;
752 case SMESH::ADD_QUADPYRAMID : AddQuadPiramidsWithID( mySMDSMesh, aSeq, anId ); break;
753 case SMESH::ADD_QUADPENTAHEDRON: AddQuadPentasWithID ( mySMDSMesh, aSeq, anId ); break;
754 case SMESH::ADD_QUADHEXAHEDRON : AddQuadHexasWithID ( mySMDSMesh, aSeq, anId ); break;
756 case SMESH::CLEAR_MESH:
760 case SMESH::REMOVE_NODE:
761 for( ; anElemId < aNbElems; anElemId++ )
762 mySMDSMesh->RemoveNode( FindNode( mySMDSMesh, anIndexes[anElemId] ) );
765 case SMESH::REMOVE_ELEMENT:
766 for( ; anElemId < aNbElems; anElemId++ )
767 mySMDSMesh->RemoveElement( FindElement( mySMDSMesh, anIndexes[anElemId] ) );
770 case SMESH::MOVE_NODE:
771 for(CORBA::Long aCoordId=0; anElemId < aNbElems; anElemId++, aCoordId+=3)
773 SMDS_MeshNode* node =
774 const_cast<SMDS_MeshNode*>( FindNode( mySMDSMesh, anIndexes[anElemId] ));
775 node->setXYZ( aCoords[aCoordId], aCoords[aCoordId+1], aCoords[aCoordId+2] );
779 case SMESH::CHANGE_ELEMENT_NODES:
780 for ( CORBA::Long i = 0; anElemId < aNbElems; anElemId++ )
783 const SMDS_MeshElement* elem = FindElement( mySMDSMesh, anIndexes[i++] );
785 int nbNodes = anIndexes[i++];
787 //ASSERT( nbNodes < 9 );
788 vector<const SMDS_MeshNode*> aNodes( nbNodes );
789 for ( int iNode = 0; iNode < nbNodes; iNode++ )
790 aNodes[ iNode ] = FindNode( mySMDSMesh, anIndexes[i++] );
792 mySMDSMesh->ChangeElementNodes( elem, &aNodes[0], nbNodes );
796 case SMESH::CHANGE_POLYHEDRON_NODES:
797 ChangePolyhedronNodes(mySMDSMesh, aSeq, anId);
799 case SMESH::RENUMBER:
800 for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3)
802 mySMDSMesh->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] );
810 catch ( SALOME::SALOME_Exception& exc )
812 INFOS("Following exception was cought:\n\t"<<exc.details.text);
814 catch( const std::exception& exc)
816 INFOS("Following exception was cought:\n\t"<<exc.what());
820 INFOS("Unknown exception was cought !!!");
823 if ( MYDEBUG && mySMDSMesh )
825 MESSAGE("Update - mySMDSMesh->NbNodes() = "<<mySMDSMesh->NbNodes());
826 MESSAGE("Update - mySMDSMesh->Nb0DElements() = "<<mySMDSMesh->Nb0DElements());
827 MESSAGE("Update - mySMDSMesh->NbEdges() = "<<mySMDSMesh->NbEdges());
828 MESSAGE("Update - mySMDSMesh->NbFaces() = "<<mySMDSMesh->NbFaces());
829 MESSAGE("Update - mySMDSMesh->NbVolumes() = "<<mySMDSMesh->NbVolumes());
831 } // end of update mesh by log script