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