1 // Copyright (C) 2007-2013 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 // File : SMESH_Client.cxx
23 // Author : Pavel TELKOV
26 #include "SMESH_Client.hxx"
27 #include "SMESH_Mesh.hxx"
28 #include "SMESHDS_Script.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 : AddBallsWithID
130 //=======================================================================
131 inline void AddBallsWithID(SMDS_Mesh* theMesh,
132 SMESH::log_array_var& theSeq,
135 const SMESH::double_array& aDiameter = theSeq[theId].coords;
136 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
137 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
138 if (2*aNbElems != anIndexes.length() )
139 EXCEPTION(runtime_error,"AddEdgeWithID - 2*aNbElems != anIndexes.length()");
140 if (aNbElems != aDiameter.length())
141 EXCEPTION(runtime_error,"AddEdgeWithID - aNbElems != aDiameter.length()");
142 CORBA::Long anIndexId = 0;
143 for (; anElemId < aNbElems; anElemId++, anIndexId+=2)
145 SMDS_MeshElement* anElem = theMesh->AddBallWithID(anIndexes[anIndexId+1],
147 anIndexes[anIndexId]);
149 EXCEPTION(runtime_error,"cannot SMDS_Mesh::AddBallsWithID for ID = "<<anElemId);
154 //=======================================================================
155 //function : AddEdgesWithID
156 //=======================================================================
157 inline void AddEdgesWithID(SMDS_Mesh* theMesh,
158 SMESH::log_array_var& theSeq,
161 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
162 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
163 if(3*aNbElems != anIndexes.length())
164 EXCEPTION(runtime_error,"AddEdgeWithID - 3*aNbElems != aCoords.length()");
165 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=3){
166 SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
167 anIndexes[anIndexId+2],
168 anIndexes[anIndexId]);
170 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
175 //=======================================================================
176 //function : AddTriasWithID
177 //=======================================================================
178 inline void AddTriasWithID(SMDS_Mesh* theMesh,
179 SMESH::log_array_var& theSeq,
182 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
183 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
184 if(4*aNbElems != anIndexes.length())
185 EXCEPTION(runtime_error,"AddTriasWithID - 4*aNbElems != anIndexes.length()");
186 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
187 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
188 anIndexes[anIndexId+2],
189 anIndexes[anIndexId+3],
190 anIndexes[anIndexId]);
192 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
197 //=======================================================================
198 //function : AddQuadsWithID
199 //=======================================================================
200 inline void AddQuadsWithID(SMDS_Mesh* theMesh,
201 SMESH::log_array_var theSeq,
204 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
205 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
206 if(5*aNbElems != anIndexes.length())
207 EXCEPTION(runtime_error,"AddQuadsWithID - 4*aNbElems != anIndexes.length()");
208 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
209 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
210 anIndexes[anIndexId+2],
211 anIndexes[anIndexId+3],
212 anIndexes[anIndexId+4],
213 anIndexes[anIndexId]);
215 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
220 //=======================================================================
221 //function : AddPolygonsWithID
222 //=======================================================================
223 inline void AddPolygonsWithID(SMDS_Mesh* theMesh,
224 SMESH::log_array_var& theSeq,
227 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
228 CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
230 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
231 int aFaceId = anIndexes[anIndexId++];
233 int aNbNodes = anIndexes[anIndexId++];
234 std::vector<int> nodes_ids (aNbNodes);
235 for (int i = 0; i < aNbNodes; i++) {
236 nodes_ids[i] = anIndexes[anIndexId++];
239 SMDS_MeshElement* anElem = theMesh->AddPolygonalFaceWithID(nodes_ids, aFaceId);
241 EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolygonalFaceWithID for ID = "
247 //=======================================================================
248 //function : AddTetrasWithID
249 //=======================================================================
250 inline void AddTetrasWithID(SMDS_Mesh* theMesh,
251 SMESH::log_array_var& theSeq,
254 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
255 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
256 if(5*aNbElems != anIndexes.length())
257 EXCEPTION(runtime_error,"AddTetrasWithID - 5*aNbElems != anIndexes.length()");
258 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
259 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
260 anIndexes[anIndexId+2],
261 anIndexes[anIndexId+3],
262 anIndexes[anIndexId+4],
263 anIndexes[anIndexId]);
265 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
270 //=======================================================================
271 //function : AddPiramidsWithID
272 //=======================================================================
273 inline void AddPiramidsWithID(SMDS_Mesh* theMesh,
274 SMESH::log_array_var& theSeq,
277 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
278 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
279 if(6*aNbElems != anIndexes.length())
280 EXCEPTION(runtime_error,"AddPiramidsWithID - 6*aNbElems != anIndexes.length()");
281 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=6){
282 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
283 anIndexes[anIndexId+2],
284 anIndexes[anIndexId+3],
285 anIndexes[anIndexId+4],
286 anIndexes[anIndexId+5],
287 anIndexes[anIndexId]);
289 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
294 //=======================================================================
295 //function : AddPrismsWithID
296 //=======================================================================
297 inline void AddPrismsWithID(SMDS_Mesh* theMesh,
298 SMESH::log_array_var& theSeq,
301 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
302 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
303 if(7*aNbElems != anIndexes.length())
304 EXCEPTION(runtime_error,"AddPrismsWithID - 7*aNbElems != anIndexes.length()");
305 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
306 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
307 anIndexes[anIndexId+2],
308 anIndexes[anIndexId+3],
309 anIndexes[anIndexId+4],
310 anIndexes[anIndexId+5],
311 anIndexes[anIndexId+6],
312 anIndexes[anIndexId]);
314 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
319 //=======================================================================
320 //function : AddHexasWithID
321 //=======================================================================
322 inline void AddHexasWithID(SMDS_Mesh* theMesh,
323 SMESH::log_array_var& theSeq,
326 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
327 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
328 if(9*aNbElems != anIndexes.length())
329 EXCEPTION(runtime_error,"AddHexasWithID - 9*aNbElems != anIndexes.length()");
330 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
331 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
332 anIndexes[anIndexId+2],
333 anIndexes[anIndexId+3],
334 anIndexes[anIndexId+4],
335 anIndexes[anIndexId+5],
336 anIndexes[anIndexId+6],
337 anIndexes[anIndexId+7],
338 anIndexes[anIndexId+8],
339 anIndexes[anIndexId]);
341 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
345 //=======================================================================
346 //function : AddHexPrismWithID
347 //=======================================================================
348 inline void AddHexPrismWithID(SMDS_Mesh* theMesh,
349 SMESH::log_array_var& theSeq,
352 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
353 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
354 if(13*aNbElems != anIndexes.length())
355 EXCEPTION(runtime_error,"AddHexPrismWithID - 13*aNbElems != anIndexes.length()");
356 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=13){
357 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
358 anIndexes[anIndexId+2],
359 anIndexes[anIndexId+3],
360 anIndexes[anIndexId+4],
361 anIndexes[anIndexId+5],
362 anIndexes[anIndexId+6],
363 anIndexes[anIndexId+7],
364 anIndexes[anIndexId+8],
365 anIndexes[anIndexId+9],
366 anIndexes[anIndexId+10],
367 anIndexes[anIndexId+11],
368 anIndexes[anIndexId+12],
369 anIndexes[anIndexId]);
371 EXCEPTION(runtime_error,"AddHexPrismWithID - cannot AddVolumeWithID for ID = "<<anElemId);
376 //=======================================================================
377 //function : AddPolyhedronsWithID
378 //=======================================================================
379 inline void AddPolyhedronsWithID (SMDS_Mesh* theMesh,
380 SMESH::log_array_var& theSeq,
383 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
384 CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
386 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
387 int aFaceId = anIndexes[anIndexId++];
389 int aNbNodes = anIndexes[anIndexId++];
390 std::vector<int> nodes_ids (aNbNodes);
391 for (int i = 0; i < aNbNodes; i++) {
392 nodes_ids[i] = anIndexes[anIndexId++];
395 int aNbFaces = anIndexes[anIndexId++];
396 std::vector<int> quantities (aNbFaces);
397 for (int i = 0; i < aNbFaces; i++) {
398 quantities[i] = anIndexes[anIndexId++];
401 SMDS_MeshElement* anElem =
402 theMesh->AddPolyhedralVolumeWithID(nodes_ids, quantities, aFaceId);
404 EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolyhedralVolumeWithID for ID = "
410 //=======================================================================
411 //function : AddQuadEdgesWithID
412 //=======================================================================
413 inline void AddQuadEdgesWithID(SMDS_Mesh* theMesh,
414 SMESH::log_array_var& theSeq,
417 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
418 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
419 if(4*aNbElems != anIndexes.length())
420 EXCEPTION(runtime_error,"AddQuadEdgeWithID - 4*aNbElems != aCoords.length()");
421 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
422 SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
423 anIndexes[anIndexId+2],
424 anIndexes[anIndexId+3],
425 anIndexes[anIndexId]);
427 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
432 //=======================================================================
433 //function : AddQuadTriasWithID
434 //=======================================================================
435 inline void AddQuadTriasWithID(SMDS_Mesh* theMesh,
436 SMESH::log_array_var& theSeq,
439 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
440 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
441 if(7*aNbElems != anIndexes.length())
442 EXCEPTION(runtime_error,"AddQuadTriasWithID - 7*aNbElems != anIndexes.length()");
443 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
444 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
445 anIndexes[anIndexId+2],
446 anIndexes[anIndexId+3],
447 anIndexes[anIndexId+4],
448 anIndexes[anIndexId+5],
449 anIndexes[anIndexId+6],
450 anIndexes[anIndexId]);
452 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
457 //=======================================================================
458 //function : AddQuadQuadsWithID
459 //=======================================================================
460 inline void AddQuadQuadsWithID(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(9*aNbElems != anIndexes.length())
467 EXCEPTION(runtime_error,"AddQuadQuadsWithID - 9*aNbElems != anIndexes.length()");
468 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
469 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(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]);
479 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
483 //=======================================================================
484 //function : AddBiQuadQuadsWithID
485 //=======================================================================
486 inline void AddBiQuadQuadsWithID(SMDS_Mesh* theMesh,
487 SMESH::log_array_var theSeq,
490 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
491 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
492 if(10*aNbElems != anIndexes.length())
493 EXCEPTION(runtime_error,"AddBiQuadQuadsWithID - 10*aNbElems != anIndexes.length()");
494 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=10){
495 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
496 anIndexes[anIndexId+2],
497 anIndexes[anIndexId+3],
498 anIndexes[anIndexId+4],
499 anIndexes[anIndexId+5],
500 anIndexes[anIndexId+6],
501 anIndexes[anIndexId+7],
502 anIndexes[anIndexId+8],
503 anIndexes[anIndexId+9],
504 anIndexes[anIndexId]);
506 EXCEPTION(runtime_error,"AddBiQuadQuadsWithID() - cannot AddFaceWithID for ID = "<<anElemId);
510 //=======================================================================
511 //function : AddBiQuadTriasWithID
512 //=======================================================================
513 inline void AddBiQuadTriasWithID(SMDS_Mesh* theMesh,
514 SMESH::log_array_var theSeq,
517 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
518 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
519 if(8*aNbElems != anIndexes.length())
520 EXCEPTION(runtime_error,"AddBiQuadTriasWithID - 8*aNbElems != anIndexes.length()");
521 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=8){
522 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
523 anIndexes[anIndexId+2],
524 anIndexes[anIndexId+3],
525 anIndexes[anIndexId+4],
526 anIndexes[anIndexId+5],
527 anIndexes[anIndexId+6],
528 anIndexes[anIndexId+7],
529 anIndexes[anIndexId]);
531 EXCEPTION(runtime_error,"AddBiQuadTriasWithID() - cannot AddFaceWithID for ID = "<<anElemId);
536 //=======================================================================
537 //function : AddQuadTetrasWithID
538 //=======================================================================
539 inline void AddQuadTetrasWithID(SMDS_Mesh* theMesh,
540 SMESH::log_array_var& theSeq,
543 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
544 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
545 if(11*aNbElems != anIndexes.length())
546 EXCEPTION(runtime_error,"AddQuadTetrasWithID - 11*aNbElems != anIndexes.length()");
547 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=11){
548 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
549 anIndexes[anIndexId+2],
550 anIndexes[anIndexId+3],
551 anIndexes[anIndexId+4],
552 anIndexes[anIndexId+5],
553 anIndexes[anIndexId+6],
554 anIndexes[anIndexId+7],
555 anIndexes[anIndexId+8],
556 anIndexes[anIndexId+9],
557 anIndexes[anIndexId+10],
558 anIndexes[anIndexId]);
560 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
565 //=======================================================================
566 //function : AddQuadPiramidsWithID
567 //=======================================================================
568 inline void AddQuadPiramidsWithID(SMDS_Mesh* theMesh,
569 SMESH::log_array_var& theSeq,
572 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
573 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
574 if(14*aNbElems != anIndexes.length())
575 EXCEPTION(runtime_error,"AddQuadPiramidsWithID - 14*aNbElems != anIndexes.length()");
576 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=14){
577 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
578 anIndexes[anIndexId+2],
579 anIndexes[anIndexId+3],
580 anIndexes[anIndexId+4],
581 anIndexes[anIndexId+5],
582 anIndexes[anIndexId+6],
583 anIndexes[anIndexId+7],
584 anIndexes[anIndexId+8],
585 anIndexes[anIndexId+9],
586 anIndexes[anIndexId+10],
587 anIndexes[anIndexId+11],
588 anIndexes[anIndexId+12],
589 anIndexes[anIndexId+13],
590 anIndexes[anIndexId]);
592 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
597 //=======================================================================
598 //function : AddQuadPentasWithID
599 //=======================================================================
600 inline void AddQuadPentasWithID(SMDS_Mesh* theMesh,
601 SMESH::log_array_var& theSeq,
604 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
605 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
606 if(16*aNbElems != anIndexes.length())
607 EXCEPTION(runtime_error,"AddQuadPentasWithID - 16*aNbElems != anIndexes.length()");
608 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=16){
609 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
610 anIndexes[anIndexId+2],
611 anIndexes[anIndexId+3],
612 anIndexes[anIndexId+4],
613 anIndexes[anIndexId+5],
614 anIndexes[anIndexId+6],
615 anIndexes[anIndexId+7],
616 anIndexes[anIndexId+8],
617 anIndexes[anIndexId+9],
618 anIndexes[anIndexId+10],
619 anIndexes[anIndexId+11],
620 anIndexes[anIndexId+12],
621 anIndexes[anIndexId+13],
622 anIndexes[anIndexId+14],
623 anIndexes[anIndexId+15],
624 anIndexes[anIndexId]);
626 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
631 //=======================================================================
632 //function : AddQuadHexasWithID
633 //=======================================================================
634 inline void AddQuadHexasWithID(SMDS_Mesh* theMesh,
635 SMESH::log_array_var& theSeq,
638 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
639 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
640 if(21*aNbElems != anIndexes.length())
641 EXCEPTION(runtime_error,"AddQuadHexasWithID - 21*aNbElems != anIndexes.length()");
642 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=21){
643 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
644 anIndexes[anIndexId+2],
645 anIndexes[anIndexId+3],
646 anIndexes[anIndexId+4],
647 anIndexes[anIndexId+5],
648 anIndexes[anIndexId+6],
649 anIndexes[anIndexId+7],
650 anIndexes[anIndexId+8],
651 anIndexes[anIndexId+9],
652 anIndexes[anIndexId+10],
653 anIndexes[anIndexId+11],
654 anIndexes[anIndexId+12],
655 anIndexes[anIndexId+13],
656 anIndexes[anIndexId+14],
657 anIndexes[anIndexId+15],
658 anIndexes[anIndexId+16],
659 anIndexes[anIndexId+17],
660 anIndexes[anIndexId+18],
661 anIndexes[anIndexId+19],
662 anIndexes[anIndexId+20],
663 anIndexes[anIndexId]);
665 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
669 //=======================================================================
670 //function : AddTriQuadHexasWithID
671 //=======================================================================
672 inline void AddTriQuadHexasWithID(SMDS_Mesh* theMesh,
673 SMESH::log_array_var& theSeq,
676 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
677 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
678 if(28*aNbElems != anIndexes.length())
679 EXCEPTION(runtime_error,"AddTriQuadHexasWithID - 28*aNbElems != anIndexes.length()");
680 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=28){
681 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
682 anIndexes[anIndexId+2],
683 anIndexes[anIndexId+3],
684 anIndexes[anIndexId+4],
685 anIndexes[anIndexId+5],
686 anIndexes[anIndexId+6],
687 anIndexes[anIndexId+7],
688 anIndexes[anIndexId+8],
689 anIndexes[anIndexId+9],
690 anIndexes[anIndexId+10],
691 anIndexes[anIndexId+11],
692 anIndexes[anIndexId+12],
693 anIndexes[anIndexId+13],
694 anIndexes[anIndexId+14],
695 anIndexes[anIndexId+15],
696 anIndexes[anIndexId+16],
697 anIndexes[anIndexId+17],
698 anIndexes[anIndexId+18],
699 anIndexes[anIndexId+19],
700 anIndexes[anIndexId+20],
701 anIndexes[anIndexId+21],
702 anIndexes[anIndexId+22],
703 anIndexes[anIndexId+23],
704 anIndexes[anIndexId+24],
705 anIndexes[anIndexId+25],
706 anIndexes[anIndexId+26],
707 anIndexes[anIndexId+27],
708 anIndexes[anIndexId]);
710 EXCEPTION(runtime_error,"AddTriQuadHexasWithID() - cannot AddVolumeWithID for ID = "<<anElemId);
715 //=======================================================================
716 //function : ChangePolyhedronNodes
717 //=======================================================================
718 inline void ChangePolyhedronNodes (SMDS_Mesh* theMesh,
719 SMESH::log_array_var& theSeq,
722 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
723 CORBA::Long iind = 0, aNbElems = theSeq[theId].number;
725 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++)
728 const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]);
730 int nbNodes = anIndexes[iind++];
732 std::vector<const SMDS_MeshNode*> aNodes (nbNodes);
733 for (int iNode = 0; iNode < nbNodes; iNode++) {
734 aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]);
737 int nbFaces = anIndexes[iind++];
739 std::vector<int> quantities (nbFaces);
740 for (int iFace = 0; iFace < nbFaces; iFace++) {
741 quantities[iFace] = anIndexes[iind++];
744 theMesh->ChangePolyhedronNodes(elem, aNodes, quantities);
749 //=======================================================================
751 SMESH_Client::GetSMESHGen(CORBA::ORB_ptr theORB,
752 CORBA::Boolean& theIsEmbeddedMode)
754 static SMESH::SMESH_Gen_var aMeshGen;
756 if(CORBA::is_nil(aMeshGen.in())){
758 long aClientPID = (long)_getpid();
760 long aClientPID = (long)getpid();
763 SALOME_NamingService aNamingService(theORB);
764 SALOME_LifeCycleCORBA aLifeCycleCORBA(&aNamingService);
765 Engines::EngineComponent_var aComponent = aLifeCycleCORBA.FindOrLoad_Component("FactoryServer","SMESH");
766 aMeshGen = SMESH::SMESH_Gen::_narrow(aComponent);
768 std::string aClientHostName = Kernel_Utils::GetHostname();
769 Engines::Container_var aServerContainer = aMeshGen->GetContainerRef();
770 CORBA::String_var aServerHostName = aServerContainer->getHostName();
771 CORBA::Long aServerPID = aServerContainer->getPID();
772 aMeshGen->SetEmbeddedMode((aClientPID == aServerPID) && (aClientHostName == aServerHostName.in()));
774 theIsEmbeddedMode = aMeshGen->IsEmbeddedMode();
780 //=======================================================================
781 // function : Create()
783 //=======================================================================
784 SMESH_Client::SMESH_Client(CORBA::ORB_ptr theORB,
785 SMESH::SMESH_Mesh_ptr theMesh):
786 myMeshServer(SMESH::SMESH_Mesh::_duplicate(theMesh)),
790 MESSAGE("SMESH_Client::SMESH_Client");
791 myMeshServer->Register();
793 CORBA::Boolean anIsEmbeddedMode;
794 GetSMESHGen(theORB,anIsEmbeddedMode);
795 if(anIsEmbeddedMode){
797 MESSAGE("Info: The same process, update mesh by pointer ");
798 // just set client mesh pointer to server mesh pointer
799 //SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*>(theMesh->GetMeshPtr());
800 CORBA::LongLong pointeur = theMesh->GetMeshPtr();
802 MESSAGE("SMESH_Client::SMESH_Client pointeur "<<pointeur);
803 SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*> (pointeur);
805 MESSAGE("SMESH_Client::SMESH_Client aMesh "<<aMesh);
806 //if(aMesh->GetMeshDS()->IsEmbeddedMode()){
807 if(anIsEmbeddedMode){
808 mySMESHDSMesh = aMesh->GetMeshDS();
809 mySMDSMesh = mySMESHDSMesh;
813 mySMDSMesh = new SMDS_Mesh();
817 //=================================================================================
818 // function : ~SMESH_Client
819 // purpose : Destructor
820 //=================================================================================
821 SMESH_Client::~SMESH_Client()
823 myMeshServer->UnRegister();
829 //=================================================================================
831 SMESH_Client::GetMesh() const
837 //=================================================================================
839 SMESH_Client::operator->() const
845 //=================================================================================
846 SMESH::SMESH_Mesh_ptr
847 SMESH_Client::GetMeshServer()
849 return myMeshServer.in();
853 //=================================================================================
854 // function : SMESH_Client
855 // purpose : Update mesh
856 //=================================================================================
858 SMESH_Client::Update(bool theIsClear)
860 bool anIsModified = true;
862 MESSAGE("Update mySMESHDSMesh");
863 SMESHDS_Script* aScript = mySMESHDSMesh->GetScript();
864 anIsModified = aScript->IsModified();
865 aScript->SetModified(false);
867 MESSAGE("Update CORBA");
868 SMESH::log_array_var aSeq = myMeshServer->GetLog( theIsClear );
869 CORBA::Long aLength = aSeq->length();
870 anIsModified = aLength > 0;
872 MESSAGE( "Update: length of the script is "<<aLength );
877 // update client mesh structure by logged changes commands
880 for ( CORBA::Long anId = 0; anId < aLength; anId++)
882 const SMESH::double_array& aCoords = aSeq[anId].coords;
883 const SMESH::long_array& anIndexes = aSeq[anId].indexes;
884 CORBA::Long anElemId = 0, aNbElems = aSeq[anId].number;
885 CORBA::Long aCommand = aSeq[anId].commandType;
889 case SMESH::ADD_NODE : AddNodesWithID ( mySMDSMesh, aSeq, anId ); break;
890 case SMESH::ADD_EDGE : AddEdgesWithID ( mySMDSMesh, aSeq, anId ); break;
891 case SMESH::ADD_TRIANGLE : AddTriasWithID ( mySMDSMesh, aSeq, anId ); break;
892 case SMESH::ADD_QUADRANGLE : AddQuadsWithID ( mySMDSMesh, aSeq, anId ); break;
893 case SMESH::ADD_POLYGON : AddPolygonsWithID ( mySMDSMesh, aSeq, anId ); break;
894 case SMESH::ADD_TETRAHEDRON : AddTetrasWithID ( mySMDSMesh, aSeq, anId ); break;
895 case SMESH::ADD_PYRAMID : AddPiramidsWithID ( mySMDSMesh, aSeq, anId ); break;
896 case SMESH::ADD_PRISM : AddPrismsWithID ( mySMDSMesh, aSeq, anId ); break;
897 case SMESH::ADD_HEXAHEDRON : AddHexasWithID ( mySMDSMesh, aSeq, anId ); break;
898 case SMESH::ADD_HEXAGONAL_PRISM : AddHexPrismWithID ( mySMDSMesh, aSeq, anId ); break;
899 case SMESH::ADD_POLYHEDRON : AddPolyhedronsWithID( mySMDSMesh, aSeq, anId ); break;
900 case SMESH::ADD_ELEM0D : Add0DElementsWithID ( mySMDSMesh, aSeq, anId ); break;
901 case SMESH::ADD_BALL : AddBallsWithID ( mySMDSMesh, aSeq, anId ); break;
903 case SMESH::ADD_QUADEDGE : AddQuadEdgesWithID ( mySMDSMesh, aSeq, anId ); break;
904 case SMESH::ADD_QUADTRIANGLE : AddQuadTriasWithID ( mySMDSMesh, aSeq, anId ); break;
905 case SMESH::ADD_QUADQUADRANGLE : AddQuadQuadsWithID ( mySMDSMesh, aSeq, anId ); break;
906 case SMESH::ADD_QUADTETRAHEDRON : AddQuadTetrasWithID ( mySMDSMesh, aSeq, anId ); break;
907 case SMESH::ADD_QUADPYRAMID : AddQuadPiramidsWithID( mySMDSMesh, aSeq, anId ); break;
908 case SMESH::ADD_QUADPENTAHEDRON : AddQuadPentasWithID ( mySMDSMesh, aSeq, anId ); break;
909 case SMESH::ADD_QUADHEXAHEDRON : AddQuadHexasWithID ( mySMDSMesh, aSeq, anId ); break;
911 case SMESH::ADD_BIQUAD_QUADRANGLE: AddBiQuadQuadsWithID ( mySMDSMesh, aSeq, anId ); break;
912 case SMESH::ADD_BIQUAD_TRIANGLE : AddBiQuadTriasWithID ( mySMDSMesh, aSeq, anId ); break;
913 case SMESH::ADD_TRIQUAD_HEXA : AddTriQuadHexasWithID( mySMDSMesh, aSeq, anId ); break;
915 case SMESH::CLEAR_MESH:
919 case SMESH::REMOVE_NODE:
920 for( ; anElemId < aNbElems; anElemId++ )
921 mySMDSMesh->RemoveNode( FindNode( mySMDSMesh, anIndexes[anElemId] ) );
924 case SMESH::REMOVE_ELEMENT:
925 for( ; anElemId < aNbElems; anElemId++ )
926 mySMDSMesh->RemoveElement( FindElement( mySMDSMesh, anIndexes[anElemId] ) );
929 case SMESH::MOVE_NODE:
930 for(CORBA::Long aCoordId=0; anElemId < aNbElems; anElemId++, aCoordId+=3)
932 SMDS_MeshNode* node =
933 const_cast<SMDS_MeshNode*>( FindNode( mySMDSMesh, anIndexes[anElemId] ));
934 node->setXYZ( aCoords[aCoordId], aCoords[aCoordId+1], aCoords[aCoordId+2] );
938 case SMESH::CHANGE_ELEMENT_NODES:
939 for ( CORBA::Long i = 0; anElemId < aNbElems; anElemId++ )
942 const SMDS_MeshElement* elem = FindElement( mySMDSMesh, anIndexes[i++] );
944 int nbNodes = anIndexes[i++];
946 //ASSERT( nbNodes < 9 );
947 vector<const SMDS_MeshNode*> aNodes( nbNodes );
948 for ( int iNode = 0; iNode < nbNodes; iNode++ )
949 aNodes[ iNode ] = FindNode( mySMDSMesh, anIndexes[i++] );
951 mySMDSMesh->ChangeElementNodes( elem, &aNodes[0], nbNodes );
955 case SMESH::CHANGE_POLYHEDRON_NODES:
956 ChangePolyhedronNodes(mySMDSMesh, aSeq, anId);
958 case SMESH::RENUMBER:
959 for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3)
961 mySMDSMesh->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] );
969 catch ( SALOME::SALOME_Exception& exc )
971 INFOS("Following exception was cought:\n\t"<<exc.details.text);
973 catch( const std::exception& exc)
975 INFOS("Following exception was cought:\n\t"<<exc.what());
979 INFOS("Unknown exception was cought !!!");
982 if ( MYDEBUG && mySMDSMesh )
984 MESSAGE("Update - mySMDSMesh->NbNodes() = "<<mySMDSMesh->NbNodes());
985 MESSAGE("Update - mySMDSMesh->Nb0DElements() = "<<mySMDSMesh->Nb0DElements());
986 MESSAGE("Update - mySMDSMesh->NbEdges() = "<<mySMDSMesh->NbEdges());
987 MESSAGE("Update - mySMDSMesh->NbFaces() = "<<mySMDSMesh->NbFaces());
988 MESSAGE("Update - mySMDSMesh->NbVolumes() = "<<mySMDSMesh->NbVolumes());
990 } // end of update mesh by log script