Salome HOME
Fix regression of SALOME_TESTS/Grids/smesh/3D_mesh_Extrusion_01/B2
[modules/smesh.git] / src / SMESHDS / SMESHDS_Mesh.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESHDS : management of mesh data and SMESH document
24 //  File   : SMESH_Mesh.cxx
25 //  Author : Yves FRICAUD, OCC
26 //  Module : SMESH
27 //
28 #include "SMESHDS_Mesh.hxx"
29
30 #include "SMDS_Downward.hxx"
31 #include "SMDS_EdgePosition.hxx"
32 #include "SMDS_FacePosition.hxx"
33 #include "SMDS_SpacePosition.hxx"
34 #include "SMDS_VertexPosition.hxx"
35 #include "SMESHDS_Group.hxx"
36 #include "SMESHDS_GroupOnGeom.hxx"
37 #include "SMESHDS_Script.hxx"
38 #include "SMESHDS_TSubMeshHolder.hxx"
39
40 #include <Standard_ErrorHandler.hxx>
41 #include <Standard_OutOfRange.hxx>
42 #include <TopExp.hxx>
43 #include <TopExp_Explorer.hxx>
44 #include <TopoDS_Edge.hxx>
45 #include <TopoDS_Face.hxx>
46 #include <TopoDS_Iterator.hxx>
47 #include <TopoDS_Shell.hxx>
48 #include <TopoDS_Solid.hxx>
49 #include <TopoDS_Vertex.hxx>
50
51 #include "utilities.h"
52
53 using namespace std;
54
55 class SMESHDS_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< const SMESHDS_SubMesh >
56 {
57 };
58
59 //=======================================================================
60 //function : Create
61 //purpose  : 
62 //=======================================================================
63 SMESHDS_Mesh::SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode):
64   myMeshID(theMeshID),
65   mySubMeshHolder( new SubMeshHolder ),
66   myIsEmbeddedMode(theIsEmbeddedMode)
67 {
68   myScript = new SMESHDS_Script(theIsEmbeddedMode);
69   SetPersistentId(theMeshID);
70 }
71
72 //=======================================================================
73 bool SMESHDS_Mesh::IsEmbeddedMode()
74 {
75   return myIsEmbeddedMode;
76 }
77
78 //================================================================================
79 /*!
80  * \brief Store ID persistent during lifecycle
81  *
82  * Initially it was used to have a persistent reference to the mesh from the hypothesis
83  */
84 //================================================================================
85
86 void SMESHDS_Mesh::SetPersistentId(int id)
87 {
88   if (NbNodes() == 0)
89     myPersistentID = id;
90 }
91 //================================================================================
92 /*!
93  * \brief Return ID persistent during lifecycle
94  */
95 //================================================================================
96
97 int SMESHDS_Mesh::GetPersistentId() const
98 {
99   return myPersistentID;
100 }
101
102 //=======================================================================
103 //function : ShapeToMesh
104 //purpose  : 
105 //=======================================================================
106 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
107 {
108   if ( !myShape.IsNull() && S.IsNull() )
109   {
110     // removal of a shape to mesh, delete ...
111     // - hypotheses
112     myShapeToHypothesis.Clear();
113     // - shape indices in SMDS_Position of nodes
114     SMESHDS_SubMeshIteratorPtr smIt = SubMeshes();
115     while ( SMESHDS_SubMesh* sm = const_cast< SMESHDS_SubMesh* >( smIt->next() )) {
116       if ( !sm->IsComplexSubmesh() ) {
117         SMDS_NodeIteratorPtr nIt = sm->GetNodes();
118         while ( nIt->more() )
119           sm->RemoveNode(nIt->next(), false);
120       }
121     }
122     // - sub-meshes
123     mySubMeshHolder->DeleteAll();
124
125     myIndexToShape.Clear();
126     // - groups on geometry
127     set<SMESHDS_GroupBase*>::iterator gr = myGroups.begin();
128     while ( gr != myGroups.end() ) {
129       if ( dynamic_cast<SMESHDS_GroupOnGeom*>( *gr ))
130         myGroups.erase( gr++ );
131       else
132         gr++;
133     }
134   }
135   else {
136     myShape = S;
137     if ( !S.IsNull() )
138       TopExp::MapShapes(myShape, myIndexToShape);
139   }
140 }
141
142 //=======================================================================
143 //function : AddHypothesis
144 //purpose  : 
145 //=======================================================================
146
147 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
148                                  const SMESHDS_Hypothesis * H)
149 {
150   if (!myShapeToHypothesis.IsBound(SS/*.Oriented(TopAbs_FORWARD)*/)) {
151     list<const SMESHDS_Hypothesis *> aList;
152     myShapeToHypothesis.Bind(SS/*.Oriented(TopAbs_FORWARD)*/, aList);
153   }
154   list<const SMESHDS_Hypothesis *>& alist =
155     myShapeToHypothesis(SS/*.Oriented(TopAbs_FORWARD)*/); // ignore orientation of SS
156
157   //Check if the Hypothesis is still present
158   list<const SMESHDS_Hypothesis*>::iterator ith = find(alist.begin(),alist.end(), H );
159
160   if (alist.end() != ith) return false;
161
162   alist.push_back(H);
163   return true;
164 }
165
166 //=======================================================================
167 //function : RemoveHypothesis
168 //purpose  : 
169 //=======================================================================
170
171 bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape &       S,
172                                     const SMESHDS_Hypothesis * H)
173 {
174   if( myShapeToHypothesis.IsBound( S/*.Oriented(TopAbs_FORWARD)*/ ) )
175   {
176     list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis.ChangeFind( S/*.Oriented(TopAbs_FORWARD)*/ );
177     list<const SMESHDS_Hypothesis*>::iterator ith=find(alist.begin(),alist.end(), H );
178     if (ith != alist.end())
179     {
180       alist.erase(ith);
181       return true;
182     }
183   }
184   return false;
185 }
186
187 //=======================================================================
188 //function : AddNode
189 //purpose  : 
190 //=======================================================================
191 SMDS_MeshNode* SMESHDS_Mesh::AddNode(double x, double y, double z){
192   SMDS_MeshNode* node = SMDS_Mesh::AddNode(x, y, z);
193   if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
194   return node;
195 }
196
197 SMDS_MeshNode* SMESHDS_Mesh::AddNodeWithID(double x, double y, double z, int ID){
198   SMDS_MeshNode* node = SMDS_Mesh::AddNodeWithID(x,y,z,ID);
199   if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
200   return node;
201 }
202
203 //=======================================================================
204 //function : MoveNode
205 //purpose  : 
206 //=======================================================================
207
208 void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
209 {
210   SMDS_Mesh::MoveNode( n, x, y, z );
211   myScript->MoveNode(n->GetID(), x, y, z);
212 }
213
214 //=======================================================================
215 //function : ChangeElementNodes
216 //purpose  : Changed nodes of an element provided that nb of nodes does not change
217 //=======================================================================
218
219 bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
220                                       const SMDS_MeshNode    * nodes[],
221                                       const int                nbnodes)
222 {
223   if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes ))
224     return false;
225
226   vector<int> IDs( nbnodes );
227   for ( int i = 0; i < nbnodes; i++ )
228     IDs [ i ] = nodes[ i ]->GetID();
229   myScript->ChangeElementNodes( elem->GetID(), &IDs[0], nbnodes);
230
231   return true;
232 }
233
234 //=======================================================================
235 //function : ChangePolygonNodes
236 //purpose  : 
237 //=======================================================================
238 bool SMESHDS_Mesh::ChangePolygonNodes
239                    (const SMDS_MeshElement *     elem,
240                     vector<const SMDS_MeshNode*> nodes)
241 {
242   ASSERT(nodes.size() > 3);
243
244   return ChangeElementNodes(elem, &nodes[0], nodes.size());
245 }
246
247 //=======================================================================
248 //function : ChangePolyhedronNodes
249 //purpose  : 
250 //=======================================================================
251 bool SMESHDS_Mesh::ChangePolyhedronNodes
252                    (const SMDS_MeshElement * elem,
253                     std::vector<const SMDS_MeshNode*> nodes,
254                     std::vector<int>                  quantities)
255 {
256   ASSERT(nodes.size() > 3);
257
258   if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
259     return false;
260
261   int i, len = nodes.size();
262   std::vector<int> nodes_ids (len);
263   for (i = 0; i < len; i++) {
264     nodes_ids[i] = nodes[i]->GetID();
265   }
266   myScript->ChangePolyhedronNodes(elem->GetID(), nodes_ids, quantities);
267
268   return true;
269 }
270
271 //=======================================================================
272 //function : Renumber
273 //purpose  : 
274 //=======================================================================
275
276 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
277 {
278   // TODO not possible yet to have node numbers not starting to O and continuous.
279   if (!this->isCompacted())
280     this->compactMesh();
281 //  SMDS_Mesh::Renumber( isNodes, startID, deltaID );
282 //  myScript->Renumber( isNodes, startID, deltaID );
283 }
284
285 //=======================================================================
286 //function : Add0DElement
287 //purpose  :
288 //=======================================================================
289 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElementWithID(int nodeID, int ID)
290 {
291   SMDS_Mesh0DElement* anElem = SMDS_Mesh::Add0DElementWithID(nodeID, ID);
292   if (anElem) myScript->Add0DElement(ID, nodeID);
293   return anElem;
294 }
295
296 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElementWithID
297                                   (const SMDS_MeshNode * node, int ID)
298 {
299   return Add0DElementWithID(node->GetID(), ID);
300 }
301
302 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
303 {
304   SMDS_Mesh0DElement* anElem = SMDS_Mesh::Add0DElement(node);
305   if (anElem) myScript->Add0DElement(anElem->GetID(), node->GetID());
306   return anElem;
307 }
308
309 //=======================================================================
310 //function :AddBallWithID
311 //purpose  : 
312 //=======================================================================
313
314 SMDS_BallElement* SMESHDS_Mesh::AddBallWithID(int node, double diameter, int ID)
315 {
316   SMDS_BallElement* anElem = SMDS_Mesh::AddBallWithID(node,diameter,ID);
317   if (anElem) myScript->AddBall(anElem->GetID(), node, diameter);
318   return anElem;
319 }
320
321 SMDS_BallElement* SMESHDS_Mesh::AddBallWithID(const SMDS_MeshNode * node,
322                                               double                diameter,
323                                               int                   ID)
324 {
325   SMDS_BallElement* anElem = SMDS_Mesh::AddBallWithID(node,diameter,ID);
326   if (anElem) myScript->AddBall(anElem->GetID(), node->GetID(), diameter);
327   return anElem;
328 }
329
330 SMDS_BallElement* SMESHDS_Mesh::AddBall (const SMDS_MeshNode * node,
331                                          double                diameter)
332 {
333   SMDS_BallElement* anElem = SMDS_Mesh::AddBall(node,diameter);
334   if (anElem) myScript->AddBall(anElem->GetID(), node->GetID(), diameter);
335   return anElem;
336 }
337
338 //=======================================================================
339 //function :AddEdgeWithID
340 //purpose  : 
341 //=======================================================================
342
343 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
344 {
345   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
346   if(anElem) myScript->AddEdge(ID,n1,n2);
347   return anElem;
348 }
349
350 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
351                                            const SMDS_MeshNode * n2, 
352                                            int ID)
353 {
354   return AddEdgeWithID(n1->GetID(),
355                        n2->GetID(),
356                        ID);
357 }
358
359 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
360                                      const SMDS_MeshNode * n2)
361 {
362   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
363   if(anElem) myScript->AddEdge(anElem->GetID(), 
364                                n1->GetID(), 
365                                n2->GetID());
366   return anElem;
367 }
368
369 //=======================================================================
370 //function :AddFace
371 //purpose  : 
372 //=======================================================================
373 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
374 {
375   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
376   if(anElem) myScript->AddFace(ID,n1,n2,n3);
377   return anElem;
378 }
379
380 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
381                                            const SMDS_MeshNode * n2,
382                                            const SMDS_MeshNode * n3, 
383                                            int ID)
384 {
385   return AddFaceWithID(n1->GetID(),
386                        n2->GetID(),
387                        n3->GetID(),
388                        ID);
389 }
390
391 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
392                                       const SMDS_MeshNode * n2,
393                                       const SMDS_MeshNode * n3)
394 {
395   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
396   if(anElem) myScript->AddFace(anElem->GetID(), 
397                                n1->GetID(), 
398                                n2->GetID(),
399                                n3->GetID());
400   return anElem;
401 }
402
403 //=======================================================================
404 //function :AddFace
405 //purpose  : 
406 //=======================================================================
407 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
408 {
409   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
410   if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
411   return anElem;
412 }
413
414 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
415                                            const SMDS_MeshNode * n2,
416                                            const SMDS_MeshNode * n3,
417                                            const SMDS_MeshNode * n4, 
418                                            int ID)
419 {
420   return AddFaceWithID(n1->GetID(),
421                        n2->GetID(),
422                        n3->GetID(),
423                        n4->GetID(),
424                        ID);
425 }
426
427 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
428                                      const SMDS_MeshNode * n2,
429                                      const SMDS_MeshNode * n3,
430                                      const SMDS_MeshNode * n4)
431 {
432   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
433   if(anElem) myScript->AddFace(anElem->GetID(), 
434                                n1->GetID(), 
435                                n2->GetID(), 
436                                n3->GetID(),
437                                n4->GetID());
438   return anElem;
439 }
440
441 //=======================================================================
442 //function :AddVolume
443 //purpose  : 
444 //=======================================================================
445 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
446 {
447   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
448   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
449   return anElem;
450 }
451
452 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
453                                                const SMDS_MeshNode * n2,
454                                                const SMDS_MeshNode * n3,
455                                                const SMDS_MeshNode * n4, 
456                                                int ID)
457 {
458   return AddVolumeWithID(n1->GetID(), 
459                          n2->GetID(), 
460                          n3->GetID(),
461                          n4->GetID(),
462                          ID);
463 }
464
465 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
466                                          const SMDS_MeshNode * n2,
467                                          const SMDS_MeshNode * n3,
468                                          const SMDS_MeshNode * n4)
469 {
470   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
471   if(anElem) myScript->AddVolume(anElem->GetID(), 
472                                  n1->GetID(), 
473                                  n2->GetID(), 
474                                  n3->GetID(),
475                                  n4->GetID());
476   return anElem;
477 }
478
479 //=======================================================================
480 //function :AddVolume
481 //purpose  : 
482 //=======================================================================
483 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
484 {
485   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
486   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
487   return anElem;
488 }
489
490 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
491                                                const SMDS_MeshNode * n2,
492                                                const SMDS_MeshNode * n3,
493                                                const SMDS_MeshNode * n4,
494                                                const SMDS_MeshNode * n5, 
495                                                int ID)
496 {
497   return AddVolumeWithID(n1->GetID(), 
498                          n2->GetID(), 
499                          n3->GetID(),
500                          n4->GetID(), 
501                          n5->GetID(),
502                          ID);
503 }
504
505 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
506                                          const SMDS_MeshNode * n2,
507                                          const SMDS_MeshNode * n3,
508                                          const SMDS_MeshNode * n4,
509                                          const SMDS_MeshNode * n5)
510 {
511   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
512   if(anElem) myScript->AddVolume(anElem->GetID(), 
513                                  n1->GetID(), 
514                                  n2->GetID(), 
515                                  n3->GetID(),
516                                  n4->GetID(), 
517                                  n5->GetID());
518   return anElem;
519 }
520
521 //=======================================================================
522 //function :AddVolume
523 //purpose  : 
524 //=======================================================================
525 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
526 {
527   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
528   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
529   return anElem;
530 }
531
532 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
533                                                const SMDS_MeshNode * n2,
534                                                const SMDS_MeshNode * n3,
535                                                const SMDS_MeshNode * n4,
536                                                const SMDS_MeshNode * n5,
537                                                const SMDS_MeshNode * n6, 
538                                                int ID)
539 {
540   return AddVolumeWithID(n1->GetID(), 
541                          n2->GetID(), 
542                          n3->GetID(),
543                          n4->GetID(), 
544                          n5->GetID(), 
545                          n6->GetID(),
546                          ID);
547 }
548
549 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
550                                          const SMDS_MeshNode * n2,
551                                          const SMDS_MeshNode * n3,
552                                          const SMDS_MeshNode * n4,
553                                          const SMDS_MeshNode * n5,
554                                          const SMDS_MeshNode * n6)
555 {
556   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
557   if(anElem) myScript->AddVolume(anElem->GetID(), 
558                                  n1->GetID(), 
559                                  n2->GetID(), 
560                                  n3->GetID(),
561                                  n4->GetID(), 
562                                  n5->GetID(), 
563                                  n6->GetID());
564   return anElem;
565 }
566
567 //=======================================================================
568 //function :AddVolume
569 //purpose  : 
570 //=======================================================================
571 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
572 {
573   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
574   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
575   return anElem;
576 }
577
578 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
579                                                const SMDS_MeshNode * n2,
580                                                const SMDS_MeshNode * n3,
581                                                const SMDS_MeshNode * n4,
582                                                const SMDS_MeshNode * n5,
583                                                const SMDS_MeshNode * n6,
584                                                const SMDS_MeshNode * n7,
585                                                const SMDS_MeshNode * n8, 
586                                                int ID)
587 {
588   return AddVolumeWithID(n1->GetID(), 
589                          n2->GetID(), 
590                          n3->GetID(),
591                          n4->GetID(), 
592                          n5->GetID(), 
593                          n6->GetID(), 
594                          n7->GetID(), 
595                          n8->GetID(),
596                          ID);
597 }
598
599 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
600                                          const SMDS_MeshNode * n2,
601                                          const SMDS_MeshNode * n3,
602                                          const SMDS_MeshNode * n4,
603                                          const SMDS_MeshNode * n5,
604                                          const SMDS_MeshNode * n6,
605                                          const SMDS_MeshNode * n7,
606                                          const SMDS_MeshNode * n8)
607 {
608   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
609   if(anElem) myScript->AddVolume(anElem->GetID(), 
610                                  n1->GetID(), 
611                                  n2->GetID(), 
612                                  n3->GetID(),
613                                  n4->GetID(), 
614                                  n5->GetID(), 
615                                  n6->GetID(), 
616                                  n7->GetID(), 
617                                  n8->GetID());
618   return anElem;
619 }
620
621
622 //=======================================================================
623 //function :AddVolume
624 //purpose  : add hexagonal prism
625 //=======================================================================
626 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
627                                                int n5, int n6, int n7, int n8,
628                                                int n9, int n10, int n11, int n12,
629                                                int ID)
630 {
631   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, ID);
632   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
633   return anElem;
634 }
635
636 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
637                                                const SMDS_MeshNode * n2,
638                                                const SMDS_MeshNode * n3,
639                                                const SMDS_MeshNode * n4,
640                                                const SMDS_MeshNode * n5,
641                                                const SMDS_MeshNode * n6,
642                                                const SMDS_MeshNode * n7,
643                                                const SMDS_MeshNode * n8, 
644                                                const SMDS_MeshNode * n9, 
645                                                const SMDS_MeshNode * n10, 
646                                                const SMDS_MeshNode * n11, 
647                                                const SMDS_MeshNode * n12, 
648                                                int ID)
649 {
650   return AddVolumeWithID(n1->GetID(), 
651                          n2->GetID(),
652                          n3->GetID(),
653                          n4->GetID(),
654                          n5->GetID(),
655                          n6->GetID(),
656                          n7->GetID(),
657                          n8->GetID(),
658                          n9->GetID(),
659                          n10->GetID(),
660                          n11->GetID(),
661                          n12->GetID(),
662                          ID);
663 }
664
665 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
666                                          const SMDS_MeshNode * n2,
667                                          const SMDS_MeshNode * n3,
668                                          const SMDS_MeshNode * n4,
669                                          const SMDS_MeshNode * n5,
670                                          const SMDS_MeshNode * n6,
671                                          const SMDS_MeshNode * n7,
672                                          const SMDS_MeshNode * n8, 
673                                          const SMDS_MeshNode * n9, 
674                                          const SMDS_MeshNode * n10, 
675                                          const SMDS_MeshNode * n11, 
676                                          const SMDS_MeshNode * n12)
677 {
678   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
679   if(anElem) myScript->AddVolume(anElem->GetID(), 
680                                  n1->GetID(),
681                                  n2->GetID(),
682                                  n3->GetID(),
683                                  n4->GetID(),
684                                  n5->GetID(),
685                                  n6->GetID(),
686                                  n7->GetID(),
687                                  n8->GetID(),
688                                  n9->GetID(),
689                                  n10->GetID(),
690                                  n11->GetID(),
691                                  n12->GetID());
692   return anElem;
693 }
694
695
696 //=======================================================================
697 //function : AddPolygonalFace
698 //purpose  : 
699 //=======================================================================
700 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (const std::vector<int>& nodes_ids,
701                                                      const int               ID)
702 {
703   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes_ids, ID);
704   if (anElem) {
705     myScript->AddPolygonalFace(ID, nodes_ids);
706   }
707   return anElem;
708 }
709
710 SMDS_MeshFace*
711 SMESHDS_Mesh::AddPolygonalFaceWithID (const std::vector<const SMDS_MeshNode*>& nodes,
712                                       const int                                ID)
713 {
714   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
715   if (anElem) {
716     int i, len = nodes.size();
717     std::vector<int> nodes_ids (len);
718     for (i = 0; i < len; i++) {
719       nodes_ids[i] = nodes[i]->GetID();
720     }
721     myScript->AddPolygonalFace(ID, nodes_ids);
722   }
723   return anElem;
724 }
725
726 SMDS_MeshFace*
727 SMESHDS_Mesh::AddPolygonalFace (const std::vector<const SMDS_MeshNode*>& nodes)
728 {
729   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
730   if (anElem) {
731     int i, len = nodes.size();
732     std::vector<int> nodes_ids (len);
733     for (i = 0; i < len; i++) {
734       nodes_ids[i] = nodes[i]->GetID();
735     }
736     myScript->AddPolygonalFace(anElem->GetID(), nodes_ids);
737   }
738   return anElem;
739 }
740
741
742 //=======================================================================
743 //function : AddQuadPolygonalFace
744 //purpose  : 
745 //=======================================================================
746 SMDS_MeshFace* SMESHDS_Mesh::AddQuadPolygonalFaceWithID (const std::vector<int>& nodes_ids,
747                                                          const int               ID)
748 {
749   SMDS_MeshFace *anElem = SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes_ids, ID);
750   if (anElem) {
751     myScript->AddQuadPolygonalFace(ID, nodes_ids);
752   }
753   return anElem;
754 }
755
756 SMDS_MeshFace*
757 SMESHDS_Mesh::AddQuadPolygonalFaceWithID (const std::vector<const SMDS_MeshNode*>& nodes,
758                                           const int                                ID)
759 {
760   SMDS_MeshFace *anElem = SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, ID);
761   if (anElem) {
762     int i, len = nodes.size();
763     std::vector<int> nodes_ids (len);
764     for (i = 0; i < len; i++) {
765       nodes_ids[i] = nodes[i]->GetID();
766     }
767     myScript->AddQuadPolygonalFace(ID, nodes_ids);
768   }
769   return anElem;
770 }
771
772 SMDS_MeshFace*
773 SMESHDS_Mesh::AddQuadPolygonalFace (const std::vector<const SMDS_MeshNode*>& nodes)
774 {
775   SMDS_MeshFace *anElem = SMDS_Mesh::AddQuadPolygonalFace(nodes);
776   if (anElem) {
777     int i, len = nodes.size();
778     std::vector<int> nodes_ids (len);
779     for (i = 0; i < len; i++) {
780       nodes_ids[i] = nodes[i]->GetID();
781     }
782     myScript->AddQuadPolygonalFace(anElem->GetID(), nodes_ids);
783   }
784   return anElem;
785 }
786
787
788 //=======================================================================
789 //function : AddPolyhedralVolume
790 //purpose  : 
791 //=======================================================================
792 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (const std::vector<int>& nodes_ids,
793                                                           const std::vector<int>& quantities,
794                                                           const int               ID)
795 {
796   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes_ids, quantities, ID);
797   if (anElem) {
798     myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
799   }
800   return anElem;
801 }
802
803 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID
804                                (const std::vector<const SMDS_MeshNode*>& nodes,
805                                 const std::vector<int>&                  quantities,
806                                 const int                                ID)
807 {
808   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
809   if (anElem) {
810     int i, len = nodes.size();
811     std::vector<int> nodes_ids (len);
812     for (i = 0; i < len; i++) {
813       nodes_ids[i] = nodes[i]->GetID();
814     }
815     myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
816   }
817   return anElem;
818 }
819
820 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume
821                                (const std::vector<const SMDS_MeshNode*>& nodes,
822                                 const std::vector<int>&                  quantities)
823 {
824   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities);
825   if (anElem) {
826     int i, len = nodes.size();
827     std::vector<int> nodes_ids (len);
828     for (i = 0; i < len; i++) {
829       nodes_ids[i] = nodes[i]->GetID();
830     }
831     myScript->AddPolyhedralVolume(anElem->GetID(), nodes_ids, quantities);
832   }
833   return anElem;
834 }
835
836 //=======================================================================
837 //function : removeFromContainers
838 //purpose  : 
839 //=======================================================================
840
841 static void removeFromContainers (SMESHDS_Mesh*                  theMesh,
842                                   set<SMESHDS_GroupBase*>&       theGroups,
843                                   list<const SMDS_MeshElement*>& theElems,
844                                   const bool                     isNode)
845 {
846   if ( theElems.empty() )
847     return;
848
849   // Rm from group
850   // Element can belong to several groups
851   if ( !theGroups.empty() )
852   {
853     set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
854     for ( ; GrIt != theGroups.end(); GrIt++ )
855     {
856       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
857       if ( !group || group->IsEmpty() ) continue;
858
859       list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
860       for ( ; elIt != theElems.end(); elIt++ )
861       {
862         group->SMDSGroup().Remove( *elIt );
863         if ( group->IsEmpty() ) break;
864       }
865     }
866   }
867
868   const bool deleted=true;
869
870   // Rm from sub-meshes
871   // Element should belong to only one sub-mesh
872   if ( theMesh->SubMeshes()->more() )
873   {
874     list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
875     if ( isNode ) {
876       for ( ; elIt != theElems.end(); ++elIt )
877         if ( SMESHDS_SubMesh* sm = theMesh->MeshElements( (*elIt)->getshapeId() ))
878           sm->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt), deleted );
879     }
880     else {
881       for ( ; elIt != theElems.end(); ++elIt )
882         if ( SMESHDS_SubMesh* sm = theMesh->MeshElements( (*elIt)->getshapeId() ))
883           sm->RemoveElement( *elIt, deleted );
884     }
885   }
886 }
887
888 //=======================================================================
889 //function : RemoveNode
890 //purpose  :
891 //=======================================================================
892 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
893 {
894   if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces()))
895   {
896     RemoveFreeNode( n, 0, true );
897     return;
898   }
899
900   myScript->RemoveNode(n->GetID());
901
902   list<const SMDS_MeshElement *> removedElems;
903   list<const SMDS_MeshElement *> removedNodes;
904
905   SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
906
907   removeFromContainers( this, myGroups, removedElems, false );
908   removeFromContainers( this, myGroups, removedNodes, true );
909 }
910
911 //=======================================================================
912 //function : RemoveFreeNode
913 //purpose  : 
914 //=======================================================================
915 void SMESHDS_Mesh::RemoveFreeNode(const SMDS_MeshNode * n,
916                                   SMESHDS_SubMesh *     subMesh,
917                                   bool                  fromGroups)
918 {
919   myScript->RemoveNode(n->GetID());
920
921   // Rm from group
922   // Node can belong to several groups
923   if (fromGroups && !myGroups.empty()) {
924     set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
925     for (; GrIt != myGroups.end(); GrIt++) {
926       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
927       if (group && !group->IsEmpty())
928         group->SMDSGroup().Remove(n);
929     }
930   }
931
932   // Rm from sub-mesh
933   // Node should belong to only one sub-mesh
934   if ( !subMesh || !subMesh->RemoveNode(n,/*deleted=*/false))
935     if (( subMesh = MeshElements( n->getshapeId() )))
936       subMesh->RemoveNode(n,/*deleted=*/false );
937
938   SMDS_Mesh::RemoveFreeElement(n);
939 }
940
941 //=======================================================================
942 //function : RemoveElement
943 //purpose  : 
944 //========================================================================
945 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
946 {
947   if (elt->GetType() == SMDSAbs_Node)
948   {
949     RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
950     return;
951   }
952   if (!hasConstructionEdges() && !hasConstructionFaces())
953   {
954     SMESHDS_SubMesh* subMesh=0;
955     if ( elt->getshapeId() > 0 )
956       subMesh = MeshElements( elt->getshapeId() );
957
958     RemoveFreeElement( elt, subMesh, true );
959     return;
960   }
961  
962   myScript->RemoveElement(elt->GetID());
963
964   list<const SMDS_MeshElement *> removedElems;
965   list<const SMDS_MeshElement *> removedNodes;
966
967   SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false );
968   
969   removeFromContainers( this, myGroups, removedElems, false );
970 }
971
972 //=======================================================================
973 //function : RemoveFreeElement
974 //purpose  : 
975 //========================================================================
976 void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt,
977                                      SMESHDS_SubMesh *        subMesh,
978                                      bool                     fromGroups)
979 {
980   if (elt->GetType() == SMDSAbs_Node) {
981     RemoveFreeNode( static_cast<const SMDS_MeshNode*>(elt), subMesh, fromGroups);
982     return;
983   }
984
985   if (hasConstructionEdges() || hasConstructionFaces())
986     // this methods is only for meshes without descendants
987     return;
988
989   myScript->RemoveElement(elt->GetID());
990
991   // Rm from group
992   // Element can belong to several groups
993   if ( fromGroups && !myGroups.empty() ) {
994     set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
995     for (; GrIt != myGroups.end(); GrIt++) {
996       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
997       if (group && !group->IsEmpty())
998         group->SMDSGroup().Remove(elt);
999     }
1000   }
1001
1002   // Rm from sub-mesh
1003   // Element should belong to only one sub-mesh
1004   if ( !subMesh && elt->getshapeId() > 0 )
1005     subMesh = MeshElements( elt->getshapeId() );
1006   if ( subMesh )
1007     subMesh->RemoveElement( elt, /*deleted=*/false );
1008
1009   SMDS_Mesh::RemoveFreeElement( elt );
1010 }
1011
1012 //================================================================================
1013 /*!
1014  * \brief Remove all data from the mesh
1015  */
1016 //================================================================================
1017
1018 void SMESHDS_Mesh::ClearMesh()
1019 {
1020   myScript->ClearMesh();
1021   SMDS_Mesh::Clear();
1022
1023   // clear submeshes
1024   SMESHDS_SubMeshIteratorPtr smIt = SubMeshes();
1025   while ( SMESHDS_SubMesh* sm = const_cast< SMESHDS_SubMesh* >( smIt->next() ))
1026     sm->Clear();
1027
1028   // clear groups
1029   TGroups::iterator group, groupEnd = myGroups.end();
1030   for ( group = myGroups.begin(); group != groupEnd; ++group ) {
1031     if ( SMESHDS_Group* g = dynamic_cast<SMESHDS_Group*>(*group)) {
1032       SMDSAbs_ElementType groupType = g->GetType();
1033       g->Clear();
1034       g->SetType( groupType );
1035     }
1036     else
1037     {
1038       (*group)->Extent(); // to free cashed elements in GroupOnFilter's
1039     }
1040   }
1041 }
1042
1043 //================================================================================
1044 /*!
1045  * \brief return submesh by shape
1046   * \param shape - the sub-shape
1047   * \retval SMESHDS_SubMesh* - the found submesh
1048  */
1049 //================================================================================
1050
1051 SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const TopoDS_Shape & shape )
1052 {
1053   if ( shape.IsNull() )
1054     return 0;
1055
1056   return NewSubMesh( ShapeToIndex( shape ));
1057 }
1058
1059 //================================================================================
1060 /*!
1061  * \brief Add element or node to submesh
1062   * \param elem - element to add
1063   * \param subMesh - submesh to be filled in
1064  */
1065 //================================================================================
1066
1067 bool SMESHDS_Mesh::add(const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh )
1068 {
1069   if ( elem && subMesh ) {
1070     if ( elem->GetType() == SMDSAbs_Node )
1071       subMesh->AddNode( static_cast<const SMDS_MeshNode* >( elem ));
1072     else
1073       subMesh->AddElement( elem );
1074     return true;
1075   }
1076   return false;
1077 }
1078
1079 //=======================================================================
1080 //function : SetNodeOnVolume
1081 //purpose  : 
1082 //=======================================================================
1083 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode,
1084                                    const TopoDS_Shell & S)
1085 {
1086   if ( add( aNode, getSubmesh(S) ))
1087     const_cast< SMDS_MeshNode* >
1088       ( aNode )->SetPosition( SMDS_SpacePosition::originSpacePosition() );
1089 }
1090
1091 //=======================================================================
1092 //function : SetNodeOnVolume
1093 //purpose  : 
1094 //=======================================================================
1095 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode *      aNode,
1096                                    const TopoDS_Solid & S)
1097 {
1098   if ( add( aNode, getSubmesh(S) ))
1099     const_cast< SMDS_MeshNode* >
1100       ( aNode )->SetPosition( SMDS_SpacePosition::originSpacePosition() );
1101 }
1102
1103 //=======================================================================
1104 //function : SetNodeOnFace
1105 //purpose  : 
1106 //=======================================================================
1107 void SMESHDS_Mesh::SetNodeOnFace(const SMDS_MeshNode *     aNode,
1108                                  const TopoDS_Face & S,
1109                                  double              u,
1110                                  double              v)
1111 {
1112   if ( add( aNode, getSubmesh(S) ))
1113     const_cast< SMDS_MeshNode* >
1114       ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v)));
1115 }
1116
1117 //=======================================================================
1118 //function : SetNodeOnEdge
1119 //purpose  : 
1120 //=======================================================================
1121 void SMESHDS_Mesh::SetNodeOnEdge(const SMDS_MeshNode *     aNode,
1122                                  const TopoDS_Edge & S,
1123                                  double              u)
1124 {
1125   if ( add( aNode, getSubmesh(S) ))
1126     const_cast< SMDS_MeshNode* >
1127       ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u)));
1128 }
1129
1130 //=======================================================================
1131 //function : SetNodeOnVertex
1132 //purpose  : 
1133 //=======================================================================
1134 void SMESHDS_Mesh::SetNodeOnVertex(const SMDS_MeshNode *       aNode,
1135                                    const TopoDS_Vertex & S)
1136 {
1137   if ( add( aNode, getSubmesh(S) ))
1138     const_cast< SMDS_MeshNode* >
1139       ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition()));
1140 }
1141
1142 //=======================================================================
1143 //function : UnSetNodeOnShape
1144 //purpose  : 
1145 //=======================================================================
1146 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
1147 {
1148   int shapeId = aNode->getshapeId();
1149   if (shapeId > 0)
1150     if ( SMESHDS_SubMesh* sm = MeshElements( shapeId ))
1151       sm->RemoveNode(aNode, /*deleted=*/false);
1152 }
1153
1154 //=======================================================================
1155 //function : SetMeshElementOnShape
1156 //purpose  : 
1157 //=======================================================================
1158 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
1159                                          const TopoDS_Shape &     S)
1160 {
1161   add( anElement, getSubmesh(S) );
1162 }
1163
1164 //=======================================================================
1165 //function : UnSetMeshElementOnShape
1166 //purpose  : 
1167 //=======================================================================
1168 void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem,
1169                                            const TopoDS_Shape &     S)
1170 {
1171   if ( SMESHDS_SubMesh* sm = MeshElements( S ))
1172   {
1173     if (elem->GetType() == SMDSAbs_Node)
1174       sm->RemoveNode(static_cast<const SMDS_MeshNode*> (elem), /*deleted=*/false);
1175     else
1176       sm->RemoveElement(elem, /*deleted=*/false);
1177   }
1178 }
1179
1180 //=======================================================================
1181 //function : ShapeToMesh
1182 //purpose  : 
1183 //=======================================================================
1184 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
1185 {
1186   return myShape;
1187 }
1188
1189 //=======================================================================
1190 //function : IsGroupOfSubShapes
1191 //purpose  : return true if at least one sub-shape of theShape is a sub-shape
1192 //           of myShape or theShape == myShape
1193 //=======================================================================
1194
1195 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
1196 {
1197   if ( myIndexToShape.Contains(theShape) )
1198     return true;
1199
1200   for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1201     if (IsGroupOfSubShapes( it.Value() ))
1202       return true;
1203
1204   return false;
1205 }
1206
1207 ///////////////////////////////////////////////////////////////////////////////
1208 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
1209 /// TopoDS_Shape is unknown
1210 ///////////////////////////////////////////////////////////////////////////////
1211 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const
1212 {
1213   int Index = ShapeToIndex(S);
1214   return (SMESHDS_SubMesh *) ( Index ? mySubMeshHolder->Get( Index ) : 0 );
1215 }
1216
1217 ///////////////////////////////////////////////////////////////////////////////
1218 /// Return the sub mesh by Id of shape it is linked to
1219 ///////////////////////////////////////////////////////////////////////////////
1220 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index) const
1221 {
1222   return const_cast< SMESHDS_SubMesh* >( mySubMeshHolder->Get( Index ));
1223 }
1224
1225 //=======================================================================
1226 //function : SubMeshIndices
1227 //purpose  : 
1228 //=======================================================================
1229 list<int> SMESHDS_Mesh::SubMeshIndices() const
1230 {
1231   list<int> anIndices;
1232   SMESHDS_SubMeshIteratorPtr smIt = SubMeshes();
1233   while ( const SMESHDS_SubMesh* sm = smIt->next() )
1234     anIndices.push_back( sm->GetID() );
1235
1236   return anIndices;
1237 }
1238
1239 //=======================================================================
1240 //function : SubMeshes
1241 //purpose  : 
1242 //=======================================================================
1243
1244 SMESHDS_SubMeshIteratorPtr SMESHDS_Mesh::SubMeshes() const
1245 {
1246   return SMESHDS_SubMeshIteratorPtr( mySubMeshHolder->GetIterator() );
1247 }
1248
1249 //=======================================================================
1250 //function : GetHypothesis
1251 //purpose  : 
1252 //=======================================================================
1253
1254 const list<const SMESHDS_Hypothesis*>&
1255 SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape & S) const
1256 {
1257   if ( myShapeToHypothesis.IsBound( S/*.Oriented(TopAbs_FORWARD)*/ ) ) // ignore orientation of S
1258      return myShapeToHypothesis.Find( S/*.Oriented(TopAbs_FORWARD)*/ );
1259
1260   static list<const SMESHDS_Hypothesis*> empty;
1261   return empty;
1262 }
1263
1264 //================================================================================
1265 /*!
1266  * \brief returns true if the hypothesis is assigned to any sub-shape
1267  */
1268 //================================================================================
1269
1270 bool SMESHDS_Mesh::IsUsedHypothesis(const SMESHDS_Hypothesis * H) const
1271 {
1272   ShapeToHypothesis::Iterator s2h( myShapeToHypothesis );
1273   for ( ; s2h.More(); s2h.Next() )
1274     if ( std::find( s2h.Value().begin(), s2h.Value().end(), H ) != s2h.Value().end() )
1275       return true;
1276   return false;
1277 }
1278
1279 //=======================================================================
1280 //function : GetScript
1281 //purpose  : 
1282 //=======================================================================
1283 SMESHDS_Script* SMESHDS_Mesh::GetScript()
1284 {
1285         return myScript;
1286 }
1287
1288 //=======================================================================
1289 //function : ClearScript
1290 //purpose  : 
1291 //=======================================================================
1292 void SMESHDS_Mesh::ClearScript()
1293 {
1294         myScript->Clear();
1295 }
1296
1297 //=======================================================================
1298 //function : HasMeshElements
1299 //purpose  : 
1300 //=======================================================================
1301 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S) const
1302 {
1303   int Index = myIndexToShape.FindIndex(S);
1304   return mySubMeshHolder->Get( Index );
1305 }
1306
1307 //=======================================================================
1308 //function : HasHypothesis
1309 //purpose  : 
1310 //=======================================================================
1311 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
1312 {
1313   return myShapeToHypothesis.IsBound(S/*.Oriented(TopAbs_FORWARD)*/);
1314 }
1315
1316 //=======================================================================
1317 //function : NewSubMesh 
1318 //purpose  : 
1319 //=======================================================================
1320 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
1321 {
1322   SMESHDS_SubMesh* SM = MeshElements( Index );
1323   if ( !SM )
1324   {
1325     SM = new SMESHDS_SubMesh(this, Index);
1326     mySubMeshHolder->Add( Index, SM );
1327   }
1328   return SM;
1329 }
1330
1331 //=======================================================================
1332 //function : AddCompoundSubmesh
1333 //purpose  : 
1334 //=======================================================================
1335
1336 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
1337                                      TopAbs_ShapeEnum    type)
1338 {
1339   int aMainIndex = 0;
1340   if ( IsGroupOfSubShapes( S ))
1341   {
1342     aMainIndex = myIndexToShape.Add( S );
1343     bool all = ( type == TopAbs_SHAPE );
1344     if ( all ) // corresponding simple submesh may exist
1345       aMainIndex = -aMainIndex;
1346     SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
1347     if ( !aNewSub->IsComplexSubmesh() ) // is empty
1348     {
1349       int shapeType = Max( TopAbs_SOLID, all ? myShape.ShapeType() : type );
1350       int typeLimit = all ? TopAbs_VERTEX : type;
1351       for ( ; shapeType <= typeLimit; shapeType++ )
1352       {
1353         TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
1354         for ( ; exp.More(); exp.Next() )
1355         {
1356           int index = myIndexToShape.FindIndex( exp.Current() );
1357           if ( index )
1358             aNewSub->AddSubMesh( NewSubMesh( index ));
1359         }
1360       }
1361     }
1362   }
1363   return aMainIndex;
1364 }
1365
1366 //=======================================================================
1367 //function : IndexToShape
1368 //purpose  : 
1369 //=======================================================================
1370 const TopoDS_Shape& SMESHDS_Mesh::IndexToShape(int ShapeIndex) const
1371 {
1372   try
1373   {
1374     if ( ShapeIndex > 0 )
1375       return myIndexToShape.FindKey(ShapeIndex);
1376   }
1377   catch ( Standard_OutOfRange )
1378   {
1379   }
1380   static TopoDS_Shape nullShape;
1381   return nullShape;
1382 }
1383
1384 //================================================================================
1385 /*!
1386  * \brief Return max index of sub-mesh
1387  */
1388 //================================================================================
1389
1390 int SMESHDS_Mesh::MaxSubMeshIndex() const
1391 {
1392   return mySubMeshHolder->GetMaxID();
1393 }
1394
1395 //=======================================================================
1396 //function : ShapeToIndex
1397 //purpose  : 
1398 //=======================================================================
1399 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
1400 {
1401   int index = myIndexToShape.FindIndex(S);
1402   return index;
1403 }
1404
1405 //=======================================================================
1406 //function : SetNodeOnVolume
1407 //purpose  : 
1408 //=======================================================================
1409 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
1410 {
1411   if ( add( aNode, NewSubMesh( Index )))
1412     ((SMDS_MeshNode*) aNode)->SetPosition( SMDS_SpacePosition::originSpacePosition());
1413 }
1414
1415 //=======================================================================
1416 //function : SetNodeOnFace
1417 //purpose  : 
1418 //=======================================================================
1419 void SMESHDS_Mesh::SetNodeOnFace(const SMDS_MeshNode* aNode, int Index, double u, double v)
1420 {
1421   //Set Position on Node
1422   if ( add( aNode, NewSubMesh( Index )))
1423     const_cast< SMDS_MeshNode* >
1424       ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v)));
1425 }
1426
1427 //=======================================================================
1428 //function : SetNodeOnEdge
1429 //purpose  : 
1430 //=======================================================================
1431 void SMESHDS_Mesh::SetNodeOnEdge(const SMDS_MeshNode* aNode,
1432                                  int                  Index,
1433                                  double               u)
1434 {
1435   //Set Position on Node
1436   if ( add( aNode, NewSubMesh( Index )))
1437     const_cast< SMDS_MeshNode* >
1438       ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u)));
1439 }
1440
1441 //=======================================================================
1442 //function : SetNodeOnVertex
1443 //purpose  : 
1444 //=======================================================================
1445 void SMESHDS_Mesh::SetNodeOnVertex(const SMDS_MeshNode* aNode, int Index)
1446 {
1447   //Set Position on Node
1448   if ( add( aNode, NewSubMesh( Index )))
1449     const_cast< SMDS_MeshNode* >
1450       ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition()));
1451 }
1452
1453 //=======================================================================
1454 //function : SetMeshElementOnShape
1455 //purpose  : 
1456 //=======================================================================
1457 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
1458                                          int                     Index)
1459 {
1460   add( anElement, NewSubMesh( Index ));
1461 }
1462
1463 //=======================================================================
1464 //function : ~SMESHDS_Mesh
1465 //purpose  : 
1466 //=======================================================================
1467 SMESHDS_Mesh::~SMESHDS_Mesh()
1468 {
1469   // myScript
1470   delete myScript;
1471   // submeshes
1472   delete mySubMeshHolder;
1473 }
1474
1475
1476 //********************************************************************
1477 //********************************************************************
1478 //********                                                   *********
1479 //*****       Methods for addition of quadratic elements        ******
1480 //********                                                   *********
1481 //********************************************************************
1482 //********************************************************************
1483
1484 //=======================================================================
1485 //function : AddEdgeWithID
1486 //purpose  : 
1487 //=======================================================================
1488 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID) 
1489 {
1490   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,n12,ID);
1491   if(anElem) myScript->AddEdge(ID,n1,n2,n12);
1492   return anElem;
1493 }
1494
1495 //=======================================================================
1496 //function : AddEdge
1497 //purpose  : 
1498 //=======================================================================
1499 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
1500                                      const SMDS_MeshNode* n2,
1501                                      const SMDS_MeshNode* n12)
1502 {
1503   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2,n12);
1504   if(anElem) myScript->AddEdge(anElem->GetID(), 
1505                                n1->GetID(), 
1506                                n2->GetID(),
1507                                n12->GetID());
1508   return anElem;
1509 }
1510
1511 //=======================================================================
1512 //function : AddEdgeWithID
1513 //purpose  : 
1514 //=======================================================================
1515 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
1516                                            const SMDS_MeshNode * n2, 
1517                                            const SMDS_MeshNode * n12, 
1518                                            int ID)
1519 {
1520   return AddEdgeWithID(n1->GetID(),
1521                        n2->GetID(),
1522                        n12->GetID(),
1523                        ID);
1524 }
1525
1526
1527 //=======================================================================
1528 //function : AddFace
1529 //purpose  : 
1530 //=======================================================================
1531 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1532                                      const SMDS_MeshNode * n2,
1533                                      const SMDS_MeshNode * n3,
1534                                      const SMDS_MeshNode * n12,
1535                                      const SMDS_MeshNode * n23,
1536                                      const SMDS_MeshNode * n31)
1537 {
1538   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n12,n23,n31);
1539   if(anElem) myScript->AddFace(anElem->GetID(), 
1540                                n1->GetID(), n2->GetID(), n3->GetID(),
1541                                n12->GetID(), n23->GetID(), n31->GetID());
1542   return anElem;
1543 }
1544
1545 //=======================================================================
1546 //function : AddFaceWithID
1547 //purpose  : 
1548 //=======================================================================
1549 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
1550                                            int n12,int n23,int n31, int ID)
1551 {
1552   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,ID);
1553   if(anElem) myScript->AddFace(ID,n1,n2,n3,n12,n23,n31);
1554   return anElem;
1555 }
1556
1557 //=======================================================================
1558 //function : AddFaceWithID
1559 //purpose  : 
1560 //=======================================================================
1561 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1562                                            const SMDS_MeshNode * n2,
1563                                            const SMDS_MeshNode * n3,
1564                                            const SMDS_MeshNode * n12,
1565                                            const SMDS_MeshNode * n23,
1566                                            const SMDS_MeshNode * n31, 
1567                                            int ID)
1568 {
1569   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1570                        n12->GetID(), n23->GetID(), n31->GetID(),
1571                        ID);
1572 }
1573
1574 //=======================================================================
1575 //function : AddFace
1576 //purpose  : 
1577 //=======================================================================
1578 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1579                                      const SMDS_MeshNode * n2,
1580                                      const SMDS_MeshNode * n3,
1581                                      const SMDS_MeshNode * n12,
1582                                      const SMDS_MeshNode * n23,
1583                                      const SMDS_MeshNode * n31,
1584                                      const SMDS_MeshNode * nCenter)
1585 {
1586   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n12,n23,n31,nCenter);
1587   if(anElem) myScript->AddFace(anElem->GetID(), 
1588                                n1->GetID(), n2->GetID(), n3->GetID(),
1589                                n12->GetID(), n23->GetID(), n31->GetID(),
1590                                nCenter->GetID());
1591   return anElem;
1592 }
1593
1594 //=======================================================================
1595 //function : AddFaceWithID
1596 //purpose  : 
1597 //=======================================================================
1598 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
1599                                            int n12,int n23,int n31, int nCenter, int ID)
1600 {
1601   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,nCenter,ID);
1602   if(anElem) myScript->AddFace(ID,n1,n2,n3,n12,n23,n31,nCenter);
1603   return anElem;
1604 }
1605
1606 //=======================================================================
1607 //function : AddFaceWithID
1608 //purpose  : 
1609 //=======================================================================
1610 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1611                                            const SMDS_MeshNode * n2,
1612                                            const SMDS_MeshNode * n3,
1613                                            const SMDS_MeshNode * n12,
1614                                            const SMDS_MeshNode * n23,
1615                                            const SMDS_MeshNode * n31, 
1616                                            const SMDS_MeshNode * nCenter, 
1617                                            int ID)
1618 {
1619   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1620                        n12->GetID(), n23->GetID(), n31->GetID(),
1621                        nCenter->GetID(), ID);
1622 }
1623
1624
1625 //=======================================================================
1626 //function : AddFace
1627 //purpose  : 
1628 //=======================================================================
1629 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1630                                      const SMDS_MeshNode * n2,
1631                                      const SMDS_MeshNode * n3,
1632                                      const SMDS_MeshNode * n4,
1633                                      const SMDS_MeshNode * n12,
1634                                      const SMDS_MeshNode * n23,
1635                                      const SMDS_MeshNode * n34,
1636                                      const SMDS_MeshNode * n41)
1637 {
1638   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n4,n12,n23,n34,n41);
1639   if(anElem) myScript->AddFace(anElem->GetID(), 
1640                                n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1641                                n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID());
1642   return anElem;
1643 }
1644
1645 //=======================================================================
1646 //function : AddFaceWithID
1647 //purpose  : 
1648 //=======================================================================
1649 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
1650                                            int n12,int n23,int n34,int n41, int ID)
1651 {
1652   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,ID);
1653   if(anElem) myScript->AddFace(ID,n1,n2,n3,n4,n12,n23,n34,n41);
1654   return anElem;
1655 }
1656
1657 //=======================================================================
1658 //function : AddFaceWithID
1659 //purpose  : 
1660 //=======================================================================
1661 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1662                                            const SMDS_MeshNode * n2,
1663                                            const SMDS_MeshNode * n3,
1664                                            const SMDS_MeshNode * n4,
1665                                            const SMDS_MeshNode * n12,
1666                                            const SMDS_MeshNode * n23,
1667                                            const SMDS_MeshNode * n34, 
1668                                            const SMDS_MeshNode * n41, 
1669                                            int ID)
1670 {
1671   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1672                        n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1673                        ID);
1674 }
1675
1676
1677 //=======================================================================
1678 //function : AddFace
1679 //purpose  : 
1680 //=======================================================================
1681 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1682                                      const SMDS_MeshNode * n2,
1683                                      const SMDS_MeshNode * n3,
1684                                      const SMDS_MeshNode * n4,
1685                                      const SMDS_MeshNode * n12,
1686                                      const SMDS_MeshNode * n23,
1687                                      const SMDS_MeshNode * n34,
1688                                      const SMDS_MeshNode * n41, 
1689                                      const SMDS_MeshNode * nCenter)
1690 {
1691   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n4,n12,n23,n34,n41,nCenter);
1692   if(anElem) myScript->AddFace(anElem->GetID(), 
1693                                n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1694                                n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1695                                nCenter->GetID());
1696   return anElem;
1697 }
1698
1699 //=======================================================================
1700 //function : AddFaceWithID
1701 //purpose  : 
1702 //=======================================================================
1703 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
1704                                            int n12,int n23,int n34,int n41,
1705                                            int nCenter, int ID)
1706 {
1707   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,nCenter,ID);
1708   if(anElem) myScript->AddFace(ID,n1,n2,n3,n4,n12,n23,n34,n41,nCenter);
1709   return anElem;
1710 }
1711
1712 //=======================================================================
1713 //function : AddFaceWithID
1714 //purpose  : 
1715 //=======================================================================
1716 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1717                                            const SMDS_MeshNode * n2,
1718                                            const SMDS_MeshNode * n3,
1719                                            const SMDS_MeshNode * n4,
1720                                            const SMDS_MeshNode * n12,
1721                                            const SMDS_MeshNode * n23,
1722                                            const SMDS_MeshNode * n34, 
1723                                            const SMDS_MeshNode * n41, 
1724                                            const SMDS_MeshNode * nCenter, 
1725                                            int ID)
1726 {
1727   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1728                        n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1729                        nCenter->GetID(), ID);
1730 }
1731
1732
1733 //=======================================================================
1734 //function : AddVolume
1735 //purpose  : 
1736 //=======================================================================
1737 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1738                                          const SMDS_MeshNode * n2, 
1739                                          const SMDS_MeshNode * n3,
1740                                          const SMDS_MeshNode * n4,
1741                                          const SMDS_MeshNode * n12,
1742                                          const SMDS_MeshNode * n23,
1743                                          const SMDS_MeshNode * n31,
1744                                          const SMDS_MeshNode * n14, 
1745                                          const SMDS_MeshNode * n24,
1746                                          const SMDS_MeshNode * n34)
1747 {
1748   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
1749   if(anElem) myScript->AddVolume(anElem->GetID(), 
1750                                  n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1751                                  n12->GetID(), n23->GetID(), n31->GetID(),
1752                                  n14->GetID(), n24->GetID(), n34->GetID());
1753   return anElem;
1754 }
1755
1756 //=======================================================================
1757 //function : AddVolumeWithID
1758 //purpose  : 
1759 //=======================================================================
1760 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
1761                                                int n12,int n23,int n31,
1762                                                int n14,int n24,int n34, int ID)
1763 {
1764   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n12,n23,
1765                                                        n31,n14,n24,n34,ID);
1766   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
1767   return anElem;
1768 }
1769         
1770 //=======================================================================
1771 //function : AddVolumeWithID
1772 //purpose  : 2d order tetrahedron of 10 nodes
1773 //=======================================================================
1774 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1775                                                const SMDS_MeshNode * n2,
1776                                                const SMDS_MeshNode * n3,
1777                                                const SMDS_MeshNode * n4,
1778                                                const SMDS_MeshNode * n12,
1779                                                const SMDS_MeshNode * n23,
1780                                                const SMDS_MeshNode * n31,
1781                                                const SMDS_MeshNode * n14, 
1782                                                const SMDS_MeshNode * n24,
1783                                                const SMDS_MeshNode * n34,
1784                                                int ID)
1785 {
1786   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1787                          n12->GetID(), n23->GetID(), n31->GetID(),
1788                          n14->GetID(), n24->GetID(), n34->GetID(), ID);
1789 }
1790
1791
1792 //=======================================================================
1793 //function : AddVolume
1794 //purpose  : 
1795 //=======================================================================
1796 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1797                                          const SMDS_MeshNode * n2, 
1798                                          const SMDS_MeshNode * n3,
1799                                          const SMDS_MeshNode * n4,
1800                                          const SMDS_MeshNode * n5, 
1801                                          const SMDS_MeshNode * n12,
1802                                          const SMDS_MeshNode * n23,
1803                                          const SMDS_MeshNode * n34,
1804                                          const SMDS_MeshNode * n41,
1805                                          const SMDS_MeshNode * n15, 
1806                                          const SMDS_MeshNode * n25,
1807                                          const SMDS_MeshNode * n35,
1808                                          const SMDS_MeshNode * n45)
1809 {
1810   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n12,n23,n34,n41,
1811                                                  n15,n25,n35,n45);
1812   if(anElem)
1813     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1814                         n3->GetID(), n4->GetID(), n5->GetID(),
1815                         n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1816                         n15->GetID(), n25->GetID(), n35->GetID(), n45->GetID());
1817   return anElem;
1818 }
1819
1820 //=======================================================================
1821 //function : AddVolumeWithID
1822 //purpose  : 
1823 //=======================================================================
1824 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
1825                                                int n12,int n23,int n34,int n41,
1826                                                int n15,int n25,int n35,int n45, int ID)
1827 {
1828   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,
1829                                                        n12,n23,n34,n41,
1830                                                        n15,n25,n35,n45,ID);
1831   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n12,n23,n34,n41,
1832                                  n15,n25,n35,n45);
1833   return anElem;
1834 }
1835         
1836 //=======================================================================
1837 //function : AddVolumeWithID
1838 //purpose  : 2d order pyramid of 13 nodes
1839 //=======================================================================
1840 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1841                                                const SMDS_MeshNode * n2,
1842                                                const SMDS_MeshNode * n3,
1843                                                const SMDS_MeshNode * n4,
1844                                                const SMDS_MeshNode * n5, 
1845                                                const SMDS_MeshNode * n12,
1846                                                const SMDS_MeshNode * n23,
1847                                                const SMDS_MeshNode * n34,
1848                                                const SMDS_MeshNode * n41,
1849                                                const SMDS_MeshNode * n15, 
1850                                                const SMDS_MeshNode * n25,
1851                                                const SMDS_MeshNode * n35,
1852                                                const SMDS_MeshNode * n45,
1853                                                int ID)
1854 {
1855   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1856                          n4->GetID(), n5->GetID(),
1857                          n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1858                          n15->GetID(), n25->GetID(), n35->GetID(), n45->GetID(),
1859                          ID);
1860 }
1861
1862
1863 //=======================================================================
1864 //function : AddVolume
1865 //purpose  : 
1866 //=======================================================================
1867 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1868                                          const SMDS_MeshNode * n2, 
1869                                          const SMDS_MeshNode * n3,
1870                                          const SMDS_MeshNode * n4,
1871                                          const SMDS_MeshNode * n5, 
1872                                          const SMDS_MeshNode * n6, 
1873                                          const SMDS_MeshNode * n12,
1874                                          const SMDS_MeshNode * n23,
1875                                          const SMDS_MeshNode * n31, 
1876                                          const SMDS_MeshNode * n45,
1877                                          const SMDS_MeshNode * n56,
1878                                          const SMDS_MeshNode * n64, 
1879                                          const SMDS_MeshNode * n14,
1880                                          const SMDS_MeshNode * n25,
1881                                          const SMDS_MeshNode * n36)
1882 {
1883   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n12,n23,n31,
1884                                                  n45,n56,n64,n14,n25,n36);
1885   if(anElem)
1886     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1887                         n3->GetID(), n4->GetID(), n5->GetID(), n6->GetID(),
1888                         n12->GetID(), n23->GetID(), n31->GetID(),
1889                         n45->GetID(), n56->GetID(), n64->GetID(),
1890                         n14->GetID(), n25->GetID(), n36->GetID());
1891   return anElem;
1892 }
1893
1894 //=======================================================================
1895 //function : AddVolumeWithID
1896 //purpose  : 
1897 //=======================================================================
1898 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
1899                                                int n4, int n5, int n6,
1900                                                int n12,int n23,int n31,
1901                                                int n45,int n56,int n64,
1902                                                int n14,int n25,int n36, int ID)
1903 {
1904   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,
1905                                                        n12,n23,n31,
1906                                                        n45,n56,n64,
1907                                                        n14,n25,n36,ID);
1908   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n12,n23,n31,
1909                                  n45,n56,n64,n14,n25,n36);
1910   return anElem;
1911 }
1912         
1913 //=======================================================================
1914 //function : AddVolumeWithID
1915 //purpose  : 2d order Pentahedron with 15 nodes
1916 //=======================================================================
1917 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1918                                                const SMDS_MeshNode * n2,
1919                                                const SMDS_MeshNode * n3,
1920                                                const SMDS_MeshNode * n4,
1921                                                const SMDS_MeshNode * n5, 
1922                                                const SMDS_MeshNode * n6, 
1923                                                const SMDS_MeshNode * n12,
1924                                                const SMDS_MeshNode * n23,
1925                                                const SMDS_MeshNode * n31, 
1926                                                const SMDS_MeshNode * n45,
1927                                                const SMDS_MeshNode * n56,
1928                                                const SMDS_MeshNode * n64, 
1929                                                const SMDS_MeshNode * n14,
1930                                                const SMDS_MeshNode * n25,
1931                                                const SMDS_MeshNode * n36,
1932                                                int ID)
1933 {
1934   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1935                          n4->GetID(), n5->GetID(), n6->GetID(),
1936                          n12->GetID(), n23->GetID(), n31->GetID(),
1937                          n45->GetID(), n56->GetID(), n64->GetID(),
1938                          n14->GetID(), n25->GetID(), n36->GetID(),
1939                          ID);
1940 }
1941
1942
1943 //=======================================================================
1944 //function : AddVolume
1945 //purpose  : add quadratic hexahedron
1946 //=======================================================================
1947 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1948                                          const SMDS_MeshNode * n2, 
1949                                          const SMDS_MeshNode * n3,
1950                                          const SMDS_MeshNode * n4,
1951                                          const SMDS_MeshNode * n5, 
1952                                          const SMDS_MeshNode * n6, 
1953                                          const SMDS_MeshNode * n7,
1954                                          const SMDS_MeshNode * n8, 
1955                                          const SMDS_MeshNode * n12,
1956                                          const SMDS_MeshNode * n23,
1957                                          const SMDS_MeshNode * n34,
1958                                          const SMDS_MeshNode * n41, 
1959                                          const SMDS_MeshNode * n56,
1960                                          const SMDS_MeshNode * n67,
1961                                          const SMDS_MeshNode * n78,
1962                                          const SMDS_MeshNode * n85, 
1963                                          const SMDS_MeshNode * n15,
1964                                          const SMDS_MeshNode * n26,
1965                                          const SMDS_MeshNode * n37,
1966                                          const SMDS_MeshNode * n48)
1967 {
1968   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,
1969                                                  n12,n23,n34,n41,
1970                                                  n56,n67,n78,n85,
1971                                                  n15,n26,n37,n48);
1972   if(anElem)
1973     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1974                         n3->GetID(), n4->GetID(), n5->GetID(),
1975                         n6->GetID(), n7->GetID(), n8->GetID(),
1976                         n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1977                         n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
1978                         n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID());
1979   return anElem;
1980 }
1981
1982 //=======================================================================
1983 //function : AddVolumeWithID
1984 //purpose  : 
1985 //=======================================================================
1986 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
1987                                                int n5, int n6, int n7, int n8,
1988                                                int n12,int n23,int n34,int n41,
1989                                                int n56,int n67,int n78,int n85,
1990                                                int n15,int n26,int n37,int n48, int ID)
1991 {
1992   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,
1993                                                        n12,n23,n34,n41,
1994                                                        n56,n67,n78,n85,
1995                                                        n15,n26,n37,n48,ID);
1996   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
1997                                  n56,n67,n78,n85,n15,n26,n37,n48);
1998   return anElem;
1999 }
2000         
2001 //=======================================================================
2002 //function : AddVolumeWithID
2003 //purpose  : 2d order Hexahedrons with 20 nodes
2004 //=======================================================================
2005 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
2006                                                const SMDS_MeshNode * n2,
2007                                                const SMDS_MeshNode * n3,
2008                                                const SMDS_MeshNode * n4,
2009                                                const SMDS_MeshNode * n5, 
2010                                                const SMDS_MeshNode * n6, 
2011                                                const SMDS_MeshNode * n7,
2012                                                const SMDS_MeshNode * n8, 
2013                                                const SMDS_MeshNode * n12,
2014                                                const SMDS_MeshNode * n23,
2015                                                const SMDS_MeshNode * n34,
2016                                                const SMDS_MeshNode * n41, 
2017                                                const SMDS_MeshNode * n56,
2018                                                const SMDS_MeshNode * n67,
2019                                                const SMDS_MeshNode * n78,
2020                                                const SMDS_MeshNode * n85, 
2021                                                const SMDS_MeshNode * n15,
2022                                                const SMDS_MeshNode * n26,
2023                                                const SMDS_MeshNode * n37,
2024                                                const SMDS_MeshNode * n48,
2025                                                int ID)
2026 {
2027   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
2028                          n5->GetID(), n6->GetID(), n7->GetID(), n8->GetID(),
2029                          n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
2030                          n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
2031                          n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
2032                          ID);
2033 }
2034
2035 //=======================================================================
2036 //function : AddVolume
2037 //purpose  : add tri-quadratic hexahedron of 27 nodes
2038 //=======================================================================
2039
2040 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
2041                                          const SMDS_MeshNode * n2, 
2042                                          const SMDS_MeshNode * n3,
2043                                          const SMDS_MeshNode * n4,
2044                                          const SMDS_MeshNode * n5, 
2045                                          const SMDS_MeshNode * n6, 
2046                                          const SMDS_MeshNode * n7,
2047                                          const SMDS_MeshNode * n8, 
2048                                          const SMDS_MeshNode * n12,
2049                                          const SMDS_MeshNode * n23,
2050                                          const SMDS_MeshNode * n34,
2051                                          const SMDS_MeshNode * n41, 
2052                                          const SMDS_MeshNode * n56,
2053                                          const SMDS_MeshNode * n67,
2054                                          const SMDS_MeshNode * n78,
2055                                          const SMDS_MeshNode * n85, 
2056                                          const SMDS_MeshNode * n15,
2057                                          const SMDS_MeshNode * n26,
2058                                          const SMDS_MeshNode * n37,
2059                                          const SMDS_MeshNode * n48, 
2060                                          const SMDS_MeshNode * n1234,
2061                                          const SMDS_MeshNode * n1256,
2062                                          const SMDS_MeshNode * n2367,
2063                                          const SMDS_MeshNode * n3478,
2064                                          const SMDS_MeshNode * n1458,
2065                                          const SMDS_MeshNode * n5678,
2066                                          const SMDS_MeshNode * nCenter)
2067 {
2068   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,
2069                                                  n12,n23,n34,n41,
2070                                                  n56,n67,n78,n85,
2071                                                  n15,n26,n37,n48,
2072                                                  n1234,n1256,n2367,n3478,n1458,n5678,nCenter);
2073   if(anElem)
2074     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
2075                         n3->GetID(), n4->GetID(), n5->GetID(),
2076                         n6->GetID(), n7->GetID(), n8->GetID(),
2077                         n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
2078                         n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
2079                         n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
2080                         n1234->GetID(),n1256->GetID(),n2367->GetID(),n3478->GetID(),
2081                         n1458->GetID(),n5678->GetID(),nCenter->GetID());
2082   return anElem;
2083 }
2084
2085 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
2086                                                int n5, int n6, int n7, int n8,
2087                                                int n12,int n23,int n34,int n41,
2088                                                int n56,int n67,int n78,int n85,
2089                                                int n15,int n26,int n37,int n48,
2090                                                int n1234,int n1256,int n2367,int n3478,
2091                                                int n1458,int n5678,int nCenter,
2092                                                int ID)
2093 {
2094   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,
2095                                                        n12,n23,n34,n41,
2096                                                        n56,n67,n78,n85,
2097                                                        n15,n26,n37,n48,
2098                                                        n1234, n1256, n2367, n3478,
2099                                                        n1458, n5678, nCenter,
2100                                                        ID);
2101   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
2102                                  n56,n67,n78,n85,n15,n26,n37,n48,
2103                                  n1234, n1256, n2367, n3478,
2104                                  n1458, n5678, nCenter);
2105   return anElem;
2106 }
2107
2108 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
2109                                                const SMDS_MeshNode * n2,
2110                                                const SMDS_MeshNode * n3,
2111                                                const SMDS_MeshNode * n4,
2112                                                const SMDS_MeshNode * n5,
2113                                                const SMDS_MeshNode * n6,
2114                                                const SMDS_MeshNode * n7,
2115                                                const SMDS_MeshNode * n8,
2116                                                const SMDS_MeshNode * n12,
2117                                                const SMDS_MeshNode * n23,
2118                                                const SMDS_MeshNode * n34,
2119                                                const SMDS_MeshNode * n41,
2120                                                const SMDS_MeshNode * n56,
2121                                                const SMDS_MeshNode * n67,
2122                                                const SMDS_MeshNode * n78,
2123                                                const SMDS_MeshNode * n85,
2124                                                const SMDS_MeshNode * n15,
2125                                                const SMDS_MeshNode * n26,
2126                                                const SMDS_MeshNode * n37,
2127                                                const SMDS_MeshNode * n48, 
2128                                                const SMDS_MeshNode * n1234,
2129                                                const SMDS_MeshNode * n1256,
2130                                                const SMDS_MeshNode * n2367,
2131                                                const SMDS_MeshNode * n3478,
2132                                                const SMDS_MeshNode * n1458,
2133                                                const SMDS_MeshNode * n5678,
2134                                                const SMDS_MeshNode * nCenter,
2135                                                int ID)
2136 {
2137   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
2138                          n5->GetID(), n6->GetID(), n7->GetID(), n8->GetID(),
2139                          n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
2140                          n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
2141                          n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
2142                          n1234->GetID(),n1256->GetID(),n2367->GetID(),n3478->GetID(),
2143                          n1458->GetID(),n5678->GetID(),nCenter->GetID(), ID);
2144 }
2145
2146 void SMESHDS_Mesh::compactMesh()
2147 {
2148   int newNodeSize = 0;
2149   int nbNodes = myNodes.size();
2150   int nbVtkNodes = myGrid->GetNumberOfPoints();
2151   //MESSAGE("nbNodes=" << nbNodes << " nbVtkNodes=" << nbVtkNodes);
2152   int nbNodeTemp = nbVtkNodes;
2153   if (nbNodes > nbVtkNodes)
2154     nbNodeTemp = nbNodes;
2155   vector<int> idNodesOldToNew;
2156   idNodesOldToNew.clear();
2157   idNodesOldToNew.resize(nbNodeTemp, -1); // all unused id will be -1
2158
2159   for (int i = 0; i < nbNodes; i++)
2160   {
2161     if (myNodes[i])
2162     {
2163       int vtkid = myNodes[i]->getVtkId();
2164       idNodesOldToNew[vtkid] = i; // old vtkId --> old smdsId (valid smdsId are >= 0)
2165       newNodeSize++;
2166     }
2167   }
2168   bool areNodesModified = (newNodeSize < nbVtkNodes);
2169   //MESSAGE("------------------------- compactMesh Nodes Modified: " << areNodesModified);
2170   areNodesModified = true;
2171
2172   int newCellSize = 0;
2173   int nbCells = myCells.size();
2174   int nbVtkCells = myGrid->GetNumberOfCells();
2175   //MESSAGE("nbCells=" << nbCells << " nbVtkCells=" << nbVtkCells);
2176   int nbCellTemp = nbVtkCells;
2177   if (nbCells > nbVtkCells)
2178     nbCellTemp = nbCells;
2179   vector<int> idCellsOldToNew;
2180   idCellsOldToNew.clear();
2181   idCellsOldToNew.resize(nbCellTemp, -1); // all unused id will be -1
2182
2183   for (int i = 0; i < nbCells; i++)
2184   {
2185     if (myCells[i])
2186     {
2187       //          //idCellsOldToNew[i] = myCellIdVtkToSmds[i]; // valid vtk indexes are > = 0
2188       //          int vtkid = myCells[i]->getVtkId();
2189       //          idCellsOldToNew[vtkid] = i; // old vtkId --> old smdsId (not used in input)
2190       newCellSize++;
2191     }
2192   }
2193   if (areNodesModified)
2194     myGrid->compactGrid(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize);
2195   else
2196     myGrid->compactGrid(idNodesOldToNew, 0, idCellsOldToNew, newCellSize);
2197
2198   int nbVtkPts = myGrid->GetNumberOfPoints();
2199   nbVtkCells = myGrid->GetNumberOfCells();
2200   if (nbVtkPts != newNodeSize)
2201   {
2202     MESSAGE("===> nbVtkPts != newNodeSize " << nbVtkPts << " " << newNodeSize);
2203     if (nbVtkPts > newNodeSize) newNodeSize = nbVtkPts; // several points with same SMDS Id
2204   }
2205   if (nbVtkCells != newCellSize)
2206   {
2207     MESSAGE("===> nbVtkCells != newCellSize " << nbVtkCells << " " << newCellSize);
2208     if (nbVtkCells > newCellSize) newCellSize = nbVtkCells; // several cells with same SMDS Id
2209   }
2210
2211   // --- SMDS_MeshNode and myNodes (id in SMDS and in VTK are the same), myNodeIdFactory
2212
2213   if (areNodesModified)
2214   {
2215     //MESSAGE("-------------- modify myNodes");
2216     SetOfNodes newNodes;
2217     newNodes.resize(newNodeSize+1,0); // 0 not used, SMDS numbers 1..n
2218     int newSmdsId = 0;
2219     for (int i = 0; i < nbNodes; i++)
2220     {
2221       if (myNodes[i])
2222       {
2223         newSmdsId++; // SMDS id start to 1
2224         int oldVtkId = myNodes[i]->getVtkId();
2225         int newVtkId = idNodesOldToNew[oldVtkId];
2226         //MESSAGE("myNodes["<< i << "] vtkId " << oldVtkId << " --> " << newVtkId);
2227         myNodes[i]->setVtkId(newVtkId);
2228         myNodes[i]->setId(newSmdsId);
2229         newNodes[newSmdsId] = myNodes[i];
2230         //MESSAGE("myNodes["<< i << "] --> newNodes[" << newSmdsId << "]");
2231       }
2232     }
2233     myNodes.swap(newNodes);
2234     this->myNodeIDFactory->emptyPool(newSmdsId); // newSmdsId = number of nodes
2235     //MESSAGE("myNodes.size " << myNodes.size());
2236   }
2237
2238   // --- SMDS_MeshCell, myCellIdVtkToSmds, myCellIdSmdsToVtk, myCells
2239
2240   int vtkIndexSize = myCellIdVtkToSmds.size();
2241   int maxVtkId = -1;
2242   for (int oldVtkId = 0; oldVtkId < vtkIndexSize; oldVtkId++)
2243   {
2244     int oldSmdsId = this->myCellIdVtkToSmds[oldVtkId];
2245     if (oldSmdsId > 0)
2246     {
2247       int newVtkId = idCellsOldToNew[oldVtkId];
2248       if (newVtkId > maxVtkId)
2249         maxVtkId = newVtkId;
2250       //MESSAGE("myCells["<< oldSmdsId << "] vtkId " << oldVtkId << " --> " << newVtkId);
2251       myCells[oldSmdsId]->setVtkId(newVtkId);
2252     }
2253   }
2254   //  MESSAGE("myCells.size()=" << myCells.size()
2255   //          << " myCellIdSmdsToVtk.size()=" << myCellIdSmdsToVtk.size()
2256   //          << " myCellIdVtkToSmds.size()=" << myCellIdVtkToSmds.size() );
2257
2258   SetOfCells newCells;
2259   //vector<int> newSmdsToVtk;
2260   vector<int> newVtkToSmds;
2261
2262   assert(maxVtkId < newCellSize);
2263   newCells.resize(newCellSize+1, 0); // 0 not used, SMDS numbers 1..n
2264   //newSmdsToVtk.resize(newCellSize+1, -1);
2265   newVtkToSmds.resize(newCellSize+1, -1);
2266
2267   int myCellsSize = myCells.size();
2268   int newSmdsId = 0;
2269   for (int i = 0; i < myCellsSize; i++)
2270   {
2271     if ( myCells[i] )
2272     {
2273       newSmdsId++; // SMDS id start to 1
2274       assert(newSmdsId <= newCellSize);
2275       newCells[newSmdsId] = myCells[i];
2276       newCells[newSmdsId]->setId(newSmdsId);
2277       //MESSAGE("myCells["<< i << "] --> newCells[" << newSmdsId << "]");
2278       int idvtk = myCells[i]->getVtkId();
2279       //newSmdsToVtk[newSmdsId] = idvtk;
2280       assert(idvtk < newCellSize);
2281       newVtkToSmds[idvtk] = newSmdsId;
2282     }
2283   }
2284
2285   myCells.swap(newCells);
2286   //myCellIdSmdsToVtk.swap(newSmdsToVtk);
2287   myCellIdVtkToSmds.swap(newVtkToSmds);
2288   //MESSAGE("myCells.size()="<< myCells.size()<<" myCellIdVtkToSmds.size()="<<myCellIdVtkToSmds.size() );
2289   this->myElementIDFactory->emptyPool(newSmdsId);
2290
2291   this->myScript->SetModified(true); // notify GUI client for buildPrs when update
2292
2293   // --- compact list myNodes and myElements in submeshes
2294
2295   SMESHDS_SubMeshIteratorPtr smIt = SubMeshes();
2296   while ( SMESHDS_SubMesh* sm = const_cast< SMESHDS_SubMesh* >( smIt->next() ))
2297     sm->compactList();
2298 }
2299
2300 void SMESHDS_Mesh::CleanDownWardConnectivity()
2301 {
2302   myGrid->CleanDownwardConnectivity();
2303 }
2304
2305 void SMESHDS_Mesh::BuildDownWardConnectivity(bool withEdges)
2306 {
2307   myGrid->BuildDownwardConnectivity(withEdges);
2308 }
2309
2310 /*! change some nodes in cell without modifying type or internal connectivity.
2311  * Nodes inverse connectivity is maintained up to date.
2312  * @param vtkVolId vtk id of the cell.
2313  * @param localClonedNodeIds map old node id to new node id.
2314  * @return ok if success.
2315  */
2316 bool SMESHDS_Mesh::ModifyCellNodes(int vtkVolId, std::map<int,int> localClonedNodeIds)
2317 {
2318   myGrid->ModifyCellNodes(vtkVolId, localClonedNodeIds);
2319   return true;
2320 }