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