Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/smesh.git] / src / SMESHDS / SMESHDS_Mesh.cxx
1 //  SMESH SMESHDS : management of mesh data and SMESH document
2 //
3 //  Copyright (C) 2003  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. 
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_Mesh.cxx
25 //  Author : Yves FRICAUD, OCC
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHDS_Mesh.hxx"
30
31 #include "SMESHDS_Group.hxx"
32 #include "SMDS_VertexPosition.hxx"
33 #include "SMDS_EdgePosition.hxx"
34 #include "SMDS_FacePosition.hxx"
35 #include "SMESHDS_GroupOnGeom.hxx"
36 #include <TopExp_Explorer.hxx>
37 #include <TopExp.hxx>
38 #include <TopoDS_Iterator.hxx>
39
40 #include "utilities.h"
41
42 using namespace std;
43
44 //=======================================================================
45 //function : Create
46 //purpose  : 
47 //=======================================================================
48 SMESHDS_Mesh::SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode):
49   myIsEmbeddedMode(theIsEmbeddedMode),
50   myMeshID(theMeshID)
51 {
52   myScript = new SMESHDS_Script(theIsEmbeddedMode);
53 }
54
55 //=======================================================================
56 bool SMESHDS_Mesh::IsEmbeddedMode()
57 {
58   return myIsEmbeddedMode;
59 }
60
61 //=======================================================================
62 //function : ShapeToMesh
63 //purpose  : 
64 //=======================================================================
65 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
66 {
67   if ( !myShape.IsNull() && S.IsNull() )
68   {
69     // removal of a shape to mesh, delete ...
70     // - hypotheses
71     myShapeToHypothesis.clear();
72     // - shape indices in SMDS_Position of nodes
73     map<int,SMESHDS_SubMesh*>::iterator i_sub = myShapeIndexToSubMesh.begin();
74     for ( ; i_sub != myShapeIndexToSubMesh.end(); i_sub++ ) {
75       if ( !i_sub->second->IsComplexSubmesh() ) {
76         SMDS_NodeIteratorPtr nIt = i_sub->second->GetNodes();
77         while ( nIt->more() )
78           nIt->next()->GetPosition()->SetShapeId( 0 );
79       }
80     }
81     // - sub-meshes
82     myIndexToShape.Clear();
83     myShapeIndexToSubMesh.clear();
84     // - groups on geometry
85     set<SMESHDS_GroupBase*>::iterator gr = myGroups.begin();
86     while ( gr != myGroups.end() ) {
87       if ( dynamic_cast<SMESHDS_GroupOnGeom*>( *gr ))
88         myGroups.erase( gr++ );
89       else
90         gr++;
91     }
92   }
93   else {
94     myShape = S;
95     if ( !S.IsNull() )
96       TopExp::MapShapes(myShape, myIndexToShape);
97   }
98 }
99
100 //=======================================================================
101 //function : AddHypothesis
102 //purpose  : 
103 //=======================================================================
104
105 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
106         const SMESHDS_Hypothesis * H)
107 {
108         list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis[SS];
109
110         //Check if the Hypothesis is still present
111         list<const SMESHDS_Hypothesis*>::iterator ith=alist.begin();
112
113         for (; ith!=alist.end(); ith++)
114                 if (H == *ith) return false;
115
116         alist.push_back(H);
117         return true;
118 }
119
120 //=======================================================================
121 //function : RemoveHypothesis
122 //purpose  : 
123 //=======================================================================
124
125 bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S,
126         const SMESHDS_Hypothesis * H)
127 {
128         ShapeToHypothesis::iterator its=myShapeToHypothesis.find(S);
129         if(its!=myShapeToHypothesis.end())
130         {
131                 list<const SMESHDS_Hypothesis*>::iterator ith=(*its).second.begin();
132
133                 for (; ith!=(*its).second.end(); ith++)
134                         if (H == *ith)
135                         {
136                                 (*its).second.erase(ith);
137                                 return true;
138                         }
139         }
140         return false;
141 }
142
143 //=======================================================================
144 //function : AddNode
145 //purpose  : 
146 //=======================================================================
147 SMDS_MeshNode* SMESHDS_Mesh::AddNode(double x, double y, double z){
148   SMDS_MeshNode* node = SMDS_Mesh::AddNode(x, y, z);
149   if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
150   return node;
151 }
152
153 SMDS_MeshNode* SMESHDS_Mesh::AddNodeWithID(double x, double y, double z, int ID){
154   SMDS_MeshNode* node = SMDS_Mesh::AddNodeWithID(x,y,z,ID);
155   if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
156   return node;
157 }
158
159 //=======================================================================
160 //function : MoveNode
161 //purpose  : 
162 //=======================================================================
163 void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
164 {
165   SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
166   node->setXYZ(x,y,z);
167   myScript->MoveNode(n->GetID(), x, y, z);
168 }
169
170 //=======================================================================
171 //function : ChangeElementNodes
172 //purpose  : 
173 //=======================================================================
174
175 bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
176                                       const SMDS_MeshNode    * nodes[],
177                                       const int                nbnodes)
178 {
179   if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes ))
180     return false;
181
182   vector<int> IDs( nbnodes );
183   for ( int i = 0; i < nbnodes; i++ )
184     IDs [ i ] = nodes[ i ]->GetID();
185   myScript->ChangeElementNodes( elem->GetID(), &IDs[0], nbnodes);
186
187   return true;
188 }
189
190 //=======================================================================
191 //function : ChangePolygonNodes
192 //purpose  : 
193 //=======================================================================
194 bool SMESHDS_Mesh::ChangePolygonNodes
195                    (const SMDS_MeshElement *     elem,
196                     vector<const SMDS_MeshNode*> nodes)
197 {
198   ASSERT(nodes.size() > 3);
199
200   return ChangeElementNodes(elem, &nodes[0], nodes.size());
201 }
202
203 //=======================================================================
204 //function : ChangePolyhedronNodes
205 //purpose  : 
206 //=======================================================================
207 bool SMESHDS_Mesh::ChangePolyhedronNodes
208                    (const SMDS_MeshElement * elem,
209                     std::vector<const SMDS_MeshNode*> nodes,
210                     std::vector<int>                  quantities)
211 {
212   ASSERT(nodes.size() > 3);
213
214   if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
215     return false;
216
217   int i, len = nodes.size();
218   std::vector<int> nodes_ids (len);
219   for (i = 0; i < len; i++) {
220     nodes_ids[i] = nodes[i]->GetID();
221   }
222   myScript->ChangePolyhedronNodes(elem->GetID(), nodes_ids, quantities);
223
224   return true;
225 }
226
227 //=======================================================================
228 //function : Renumber
229 //purpose  : 
230 //=======================================================================
231
232 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
233 {
234   SMDS_Mesh::Renumber( isNodes, startID, deltaID );
235   myScript->Renumber( isNodes, startID, deltaID );
236 }
237
238 //=======================================================================
239 //function :AddEdgeWithID
240 //purpose  : 
241 //=======================================================================
242 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
243 {
244   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
245   if(anElem) myScript->AddEdge(ID,n1,n2);
246   return anElem;
247 }
248
249 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
250                                            const SMDS_MeshNode * n2, 
251                                            int ID)
252 {
253   return AddEdgeWithID(n1->GetID(),
254                        n2->GetID(),
255                        ID);
256 }
257
258 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
259                                      const SMDS_MeshNode * n2)
260 {
261   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
262   if(anElem) myScript->AddEdge(anElem->GetID(), 
263                                n1->GetID(), 
264                                n2->GetID());
265   return anElem;
266 }
267
268 //=======================================================================
269 //function :AddFace
270 //purpose  : 
271 //=======================================================================
272 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
273 {
274   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
275   if(anElem) myScript->AddFace(ID,n1,n2,n3);
276   return anElem;
277 }
278
279 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
280                                            const SMDS_MeshNode * n2,
281                                            const SMDS_MeshNode * n3, 
282                                            int ID)
283 {
284   return AddFaceWithID(n1->GetID(),
285                        n2->GetID(),
286                        n3->GetID(),
287                        ID);
288 }
289
290 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
291                                       const SMDS_MeshNode * n2,
292                                       const SMDS_MeshNode * n3)
293 {
294   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
295   if(anElem) myScript->AddFace(anElem->GetID(), 
296                                n1->GetID(), 
297                                n2->GetID(),
298                                n3->GetID());
299   return anElem;
300 }
301
302 //=======================================================================
303 //function :AddFace
304 //purpose  : 
305 //=======================================================================
306 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
307 {
308   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
309   if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
310   return anElem;
311 }
312
313 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
314                                            const SMDS_MeshNode * n2,
315                                            const SMDS_MeshNode * n3,
316                                            const SMDS_MeshNode * n4, 
317                                            int ID)
318 {
319   return AddFaceWithID(n1->GetID(),
320                        n2->GetID(),
321                        n3->GetID(),
322                        n4->GetID(),
323                        ID);
324 }
325
326 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
327                                      const SMDS_MeshNode * n2,
328                                      const SMDS_MeshNode * n3,
329                                      const SMDS_MeshNode * n4)
330 {
331   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
332   if(anElem) myScript->AddFace(anElem->GetID(), 
333                                n1->GetID(), 
334                                n2->GetID(), 
335                                n3->GetID(),
336                                n4->GetID());
337   return anElem;
338 }
339
340 //=======================================================================
341 //function :AddVolume
342 //purpose  : 
343 //=======================================================================
344 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
345 {
346   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
347   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
348   return anElem;
349 }
350
351 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
352                                                const SMDS_MeshNode * n2,
353                                                const SMDS_MeshNode * n3,
354                                                const SMDS_MeshNode * n4, 
355                                                int ID)
356 {
357   return AddVolumeWithID(n1->GetID(), 
358                          n2->GetID(), 
359                          n3->GetID(),
360                          n4->GetID(),
361                          ID);
362 }
363
364 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
365                                          const SMDS_MeshNode * n2,
366                                          const SMDS_MeshNode * n3,
367                                          const SMDS_MeshNode * n4)
368 {
369   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
370   if(anElem) myScript->AddVolume(anElem->GetID(), 
371                                  n1->GetID(), 
372                                  n2->GetID(), 
373                                  n3->GetID(),
374                                  n4->GetID());
375   return anElem;
376 }
377
378 //=======================================================================
379 //function :AddVolume
380 //purpose  : 
381 //=======================================================================
382 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
383 {
384   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
385   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
386   return anElem;
387 }
388
389 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
390                                                const SMDS_MeshNode * n2,
391                                                const SMDS_MeshNode * n3,
392                                                const SMDS_MeshNode * n4,
393                                                const SMDS_MeshNode * n5, 
394                                                int ID)
395 {
396   return AddVolumeWithID(n1->GetID(), 
397                          n2->GetID(), 
398                          n3->GetID(),
399                          n4->GetID(), 
400                          n5->GetID(),
401                          ID);
402 }
403
404 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
405                                          const SMDS_MeshNode * n2,
406                                          const SMDS_MeshNode * n3,
407                                          const SMDS_MeshNode * n4,
408                                          const SMDS_MeshNode * n5)
409 {
410   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
411   if(anElem) myScript->AddVolume(anElem->GetID(), 
412                                  n1->GetID(), 
413                                  n2->GetID(), 
414                                  n3->GetID(),
415                                  n4->GetID(), 
416                                  n5->GetID());
417   return anElem;
418 }
419
420 //=======================================================================
421 //function :AddVolume
422 //purpose  : 
423 //=======================================================================
424 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
425 {
426   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
427   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
428   return anElem;
429 }
430
431 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
432                                                const SMDS_MeshNode * n2,
433                                                const SMDS_MeshNode * n3,
434                                                const SMDS_MeshNode * n4,
435                                                const SMDS_MeshNode * n5,
436                                                const SMDS_MeshNode * n6, 
437                                                int ID)
438 {
439   return AddVolumeWithID(n1->GetID(), 
440                          n2->GetID(), 
441                          n3->GetID(),
442                          n4->GetID(), 
443                          n5->GetID(), 
444                          n6->GetID(),
445                          ID);
446 }
447
448 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
449                                          const SMDS_MeshNode * n2,
450                                          const SMDS_MeshNode * n3,
451                                          const SMDS_MeshNode * n4,
452                                          const SMDS_MeshNode * n5,
453                                          const SMDS_MeshNode * n6)
454 {
455   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
456   if(anElem) myScript->AddVolume(anElem->GetID(), 
457                                  n1->GetID(), 
458                                  n2->GetID(), 
459                                  n3->GetID(),
460                                  n4->GetID(), 
461                                  n5->GetID(), 
462                                  n6->GetID());
463   return anElem;
464 }
465
466 //=======================================================================
467 //function :AddVolume
468 //purpose  : 
469 //=======================================================================
470 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
471 {
472   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
473   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
474   return anElem;
475 }
476
477 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
478                                                const SMDS_MeshNode * n2,
479                                                const SMDS_MeshNode * n3,
480                                                const SMDS_MeshNode * n4,
481                                                const SMDS_MeshNode * n5,
482                                                const SMDS_MeshNode * n6,
483                                                const SMDS_MeshNode * n7,
484                                                const SMDS_MeshNode * n8, 
485                                                int ID)
486 {
487   return AddVolumeWithID(n1->GetID(), 
488                          n2->GetID(), 
489                          n3->GetID(),
490                          n4->GetID(), 
491                          n5->GetID(), 
492                          n6->GetID(), 
493                          n7->GetID(), 
494                          n8->GetID(),
495                          ID);
496 }
497
498 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
499                                          const SMDS_MeshNode * n2,
500                                          const SMDS_MeshNode * n3,
501                                          const SMDS_MeshNode * n4,
502                                          const SMDS_MeshNode * n5,
503                                          const SMDS_MeshNode * n6,
504                                          const SMDS_MeshNode * n7,
505                                          const SMDS_MeshNode * n8)
506 {
507   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
508   if(anElem) myScript->AddVolume(anElem->GetID(), 
509                                  n1->GetID(), 
510                                  n2->GetID(), 
511                                  n3->GetID(),
512                                  n4->GetID(), 
513                                  n5->GetID(), 
514                                  n6->GetID(), 
515                                  n7->GetID(), 
516                                  n8->GetID());
517   return anElem;
518 }
519
520 //=======================================================================
521 //function : AddPolygonalFace
522 //purpose  : 
523 //=======================================================================
524 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
525                                                      const int        ID)
526 {
527   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes_ids, ID);
528   if (anElem) {
529     myScript->AddPolygonalFace(ID, nodes_ids);
530   }
531   return anElem;
532 }
533
534 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
535                              (std::vector<const SMDS_MeshNode*> nodes,
536                               const int                         ID)
537 {
538   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
539   if (anElem) {
540     int i, len = nodes.size();
541     std::vector<int> nodes_ids (len);
542     for (i = 0; i < len; i++) {
543       nodes_ids[i] = nodes[i]->GetID();
544     }
545     myScript->AddPolygonalFace(ID, nodes_ids);
546   }
547   return anElem;
548 }
549
550 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
551                              (std::vector<const SMDS_MeshNode*> nodes)
552 {
553   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
554   if (anElem) {
555     int i, len = nodes.size();
556     std::vector<int> nodes_ids (len);
557     for (i = 0; i < len; i++) {
558       nodes_ids[i] = nodes[i]->GetID();
559     }
560     myScript->AddPolygonalFace(anElem->GetID(), nodes_ids);
561   }
562   return anElem;
563 }
564
565 //=======================================================================
566 //function : AddPolyhedralVolume
567 //purpose  : 
568 //=======================================================================
569 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (std::vector<int> nodes_ids,
570                                                           std::vector<int> quantities,
571                                                           const int        ID)
572 {
573   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes_ids, quantities, ID);
574   if (anElem) {
575     myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
576   }
577   return anElem;
578 }
579
580 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID
581                                (std::vector<const SMDS_MeshNode*> nodes,
582                                 std::vector<int>                  quantities,
583                                 const int                         ID)
584 {
585   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
586   if (anElem) {
587     int i, len = nodes.size();
588     std::vector<int> nodes_ids (len);
589     for (i = 0; i < len; i++) {
590       nodes_ids[i] = nodes[i]->GetID();
591     }
592     myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
593   }
594   return anElem;
595 }
596
597 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume
598                                (std::vector<const SMDS_MeshNode*> nodes,
599                                 std::vector<int>                  quantities)
600 {
601   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities);
602   if (anElem) {
603     int i, len = nodes.size();
604     std::vector<int> nodes_ids (len);
605     for (i = 0; i < len; i++) {
606       nodes_ids[i] = nodes[i]->GetID();
607     }
608     myScript->AddPolyhedralVolume(anElem->GetID(), nodes_ids, quantities);
609   }
610   return anElem;
611 }
612
613 //=======================================================================
614 //function : removeFromContainers
615 //purpose  : 
616 //=======================================================================
617
618 static void removeFromContainers (map<int,SMESHDS_SubMesh*>&     theSubMeshes,
619                                   set<SMESHDS_GroupBase*>&       theGroups,
620                                   list<const SMDS_MeshElement*>& theElems,
621                                   const bool                     isNode)
622 {
623   if ( theElems.empty() )
624     return;
625
626   // Rm from group
627   // Element can belong to several groups
628   if ( !theGroups.empty() )
629   {
630     set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
631     for ( ; GrIt != theGroups.end(); GrIt++ )
632     {
633       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
634       if ( !group || group->IsEmpty() ) continue;
635
636       list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
637       for ( ; elIt != theElems.end(); elIt++ )
638       {
639         group->SMDSGroup().Remove( *elIt );
640         if ( group->IsEmpty() ) break;
641       }
642     }
643   }
644
645   // Rm from sub-meshes
646   // Element should belong to only one sub-mesh
647   map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
648   for ( ; SubIt != theSubMeshes.end(); SubIt++ )
649   {
650     int size = isNode ? (*SubIt).second->NbNodes() : (*SubIt).second->NbElements();
651     if ( size == 0 ) continue;
652
653     list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
654     while ( elIt != theElems.end() )
655     {
656       bool removed = false;
657       if ( isNode )
658         removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
659       else
660         removed = (*SubIt).second->RemoveElement( *elIt );
661
662       if (removed)
663       {
664         elIt = theElems.erase( elIt );
665         if ( theElems.empty() )
666           return; // all elements are found and removed
667       }
668       else
669       {
670         elIt++ ;
671       }
672     }
673   }
674 }
675   
676 //=======================================================================
677 //function : RemoveNode
678 //purpose  : 
679 //=======================================================================
680 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
681 {
682   myScript->RemoveNode(n->GetID());
683   
684   list<const SMDS_MeshElement *> removedElems;
685   list<const SMDS_MeshElement *> removedNodes;
686
687   SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
688
689   removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
690   removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
691 }
692
693 //=======================================================================
694 //function : RemoveFreeNode
695 //purpose  : 
696 //=======================================================================
697 void SMESHDS_Mesh::RemoveFreeNode(const SMDS_MeshNode * n, SMESHDS_SubMesh * subMesh)
698 {
699   myScript->RemoveNode(n->GetID());
700
701   // Rm from group
702   // Node can belong to several groups
703   if (!myGroups.empty()) {
704     set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
705     for (; GrIt != myGroups.end(); GrIt++) {
706       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
707       if (!group || group->IsEmpty()) continue;
708       group->SMDSGroup().Remove(n);
709     }
710   }
711
712   // Rm from sub-mesh
713   // Node should belong to only one sub-mesh
714   subMesh->RemoveNode(n);
715
716   SMDS_Mesh::RemoveFreeElement(n);
717 }
718
719 //=======================================================================
720 //function : RemoveElement
721 //purpose  : 
722 //========================================================================
723 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
724 {
725   if (elt->GetType() == SMDSAbs_Node)
726   {
727     RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
728     return;
729   }
730
731   myScript->RemoveElement(elt->GetID());
732
733   list<const SMDS_MeshElement *> removedElems;
734   list<const SMDS_MeshElement *> removedNodes;
735
736   SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
737   
738   removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
739 }
740
741 //=======================================================================
742 //function : RemoveFreeElement
743 //purpose  : 
744 //========================================================================
745 void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, SMESHDS_SubMesh * subMesh)
746 {
747   if (elt->GetType() == SMDSAbs_Node) {
748     RemoveFreeNode( static_cast<const SMDS_MeshNode*>(elt), subMesh);
749     return;
750   }
751
752   if (hasConstructionEdges() || hasConstructionFaces())
753     // this methods is only for meshes without descendants
754     return;
755
756   myScript->RemoveElement(elt->GetID());
757
758   // Rm from group
759   // Node can belong to several groups
760   if (!myGroups.empty()) {
761     set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
762     for (; GrIt != myGroups.end(); GrIt++) {
763       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
764       if (!group || group->IsEmpty()) continue;
765       group->SMDSGroup().Remove(elt);
766     }
767   }
768
769   // Rm from sub-mesh
770   // Element should belong to only one sub-mesh
771   subMesh->RemoveElement(elt);
772
773   SMDS_Mesh::RemoveFreeElement(elt);
774 }
775
776 //================================================================================
777 /*!
778  * \brief return submesh by shape
779   * \param shape - the subshape
780   * \retval SMESHDS_SubMesh* - the found submesh
781   *
782  * search of submeshes is optimized
783  */
784 //================================================================================
785
786 SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const TopoDS_Shape & shape )
787 {
788   if ( shape.IsNull() )
789     return 0;
790
791   if ( !myCurSubShape.IsNull() && shape.IsSame( myCurSubShape ))
792     return myCurSubMesh;
793
794   getSubmesh( ShapeToIndex( shape ));
795   myCurSubShape = shape;
796   return myCurSubMesh;
797 }
798
799 //================================================================================
800 /*!
801  * \brief return submesh by subshape index
802   * \param Index - the subshape index
803   * \retval SMESHDS_SubMesh* - the found submesh
804  * search of submeshes is optimized
805  */
806 //================================================================================
807
808 SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const int Index )
809 {
810   //Update or build submesh
811   if ( Index != myCurSubID ) {
812     map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
813     if ( it == myShapeIndexToSubMesh.end() )
814       it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh() )).first;
815     myCurSubMesh = it->second;
816     myCurSubID = Index;
817     myCurSubShape.Nullify(); // myCurSubShape no more corresponds to submesh
818   }
819   return myCurSubMesh;
820 }
821
822 //================================================================================
823 /*!
824  * \brief Add element or node to submesh
825   * \param elem - element to add
826   * \param subMesh - submesh to be filled in
827  */
828 //================================================================================
829
830 bool SMESHDS_Mesh::add(const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh )
831 {
832   if ( elem && subMesh ) {
833     if ( elem->GetType() == SMDSAbs_Node )
834       subMesh->AddNode( static_cast<const SMDS_MeshNode* >( elem ));
835     else
836       subMesh->AddElement( elem );
837     return true;
838   }
839   return false;
840 }
841
842 //=======================================================================
843 //function : SetNodeOnVolume
844 //purpose  : 
845 //=======================================================================
846 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode *      aNode,
847                                    const TopoDS_Shell & S)
848 {
849   add( aNode, getSubmesh(S) );
850 }
851 //=======================================================================
852 //function : SetNodeOnVolume
853 //purpose  : 
854 //=======================================================================
855 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode *      aNode,
856                                    const TopoDS_Solid & S)
857 {
858   add( aNode, getSubmesh(S) );
859 }
860
861 //=======================================================================
862 //function : SetNodeOnFace
863 //purpose  : 
864 //=======================================================================
865 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode *     aNode,
866                                  const TopoDS_Face & S,
867                                  double              u,
868                                  double              v)
869 {
870   if ( add( aNode, getSubmesh(S) ))
871     aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(myCurSubID, u, v)));
872 }
873
874 //=======================================================================
875 //function : SetNodeOnEdge
876 //purpose  : 
877 //=======================================================================
878 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode *     aNode,
879                                  const TopoDS_Edge & S,
880                                  double              u)
881 {
882   if ( add( aNode, getSubmesh(S) ))
883     aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(myCurSubID, u)));
884 }
885
886 //=======================================================================
887 //function : SetNodeOnVertex
888 //purpose  : 
889 //=======================================================================
890 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode *       aNode,
891                                    const TopoDS_Vertex & S)
892 {
893   if ( add( aNode, getSubmesh(S) ))
894     aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(myCurSubID)));
895 }
896
897 //=======================================================================
898 //function : UnSetNodeOnShape
899 //purpose  : 
900 //=======================================================================
901 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
902 {
903   if ( aNode && aNode->GetPosition() ) {
904     map<int,SMESHDS_SubMesh*>::iterator it =
905       myShapeIndexToSubMesh.find( aNode->GetPosition()->GetShapeId() );
906     if ( it != myShapeIndexToSubMesh.end() )
907       it->second->RemoveNode( aNode );
908   }
909 }
910
911 //=======================================================================
912 //function : SetMeshElementOnShape
913 //purpose  : 
914 //=======================================================================
915 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
916                                          const TopoDS_Shape &     S)
917 {
918   add( anElement, getSubmesh(S) );
919 }
920
921 //=======================================================================
922 //function : UnSetMeshElementOnShape
923 //purpose  : 
924 //=======================================================================
925 void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem,
926                                            const TopoDS_Shape &     S)
927 {
928   int Index = myIndexToShape.FindIndex(S);
929
930   map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
931   if ( it != myShapeIndexToSubMesh.end() )
932     if ( elem->GetType() == SMDSAbs_Node )
933       it->second->RemoveNode( static_cast<const SMDS_MeshNode* >( elem ));
934     else
935       it->second->RemoveElement( elem );
936 }
937
938 //=======================================================================
939 //function : ShapeToMesh
940 //purpose  : 
941 //=======================================================================
942 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
943 {
944         return myShape;
945 }
946
947 //=======================================================================
948 //function : IsGroupOfSubShapes
949 //purpose  : return true if at least one subshape of theShape is a subshape
950 //           of myShape or theShape == myShape
951 //=======================================================================
952
953 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
954 {
955   if ( myShape.IsSame( theShape ))
956     return true;
957
958   for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() ) {
959     if (myIndexToShape.Contains( it.Value() ) ||
960         IsGroupOfSubShapes( it.Value() ))
961       return true;
962   }
963   
964   return false;
965 }
966
967 ///////////////////////////////////////////////////////////////////////////////
968 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
969 /// TopoDS_Shape is unknown
970 ///////////////////////////////////////////////////////////////////////////////
971 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const
972 {
973   int Index = ShapeToIndex(S);
974   TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
975   if (anIter != myShapeIndexToSubMesh.end())
976     return anIter->second;
977   else
978     return NULL;
979 }
980
981 ///////////////////////////////////////////////////////////////////////////////
982 /// Return the sub mesh by Id of shape it is linked to
983 ///////////////////////////////////////////////////////////////////////////////
984 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
985 {
986   TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
987   if (anIter != myShapeIndexToSubMesh.end())
988     return anIter->second;
989   else
990     return NULL;
991 }
992
993 //=======================================================================
994 //function : SubMeshIndices
995 //purpose  : 
996 //=======================================================================
997 list<int> SMESHDS_Mesh::SubMeshIndices()
998 {
999   list<int> anIndices;
1000   std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
1001   for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
1002     anIndices.push_back((*anIter).first);
1003   }
1004   return anIndices;
1005 }
1006
1007 //=======================================================================
1008 //function : GetHypothesis
1009 //purpose  : 
1010 //=======================================================================
1011
1012 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
1013         const TopoDS_Shape & S) const
1014 {
1015         if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
1016                 return myShapeToHypothesis.find(S)->second;
1017
1018         static list<const SMESHDS_Hypothesis*> empty;
1019         return empty;
1020 }
1021
1022 //=======================================================================
1023 //function : GetScript
1024 //purpose  : 
1025 //=======================================================================
1026 SMESHDS_Script* SMESHDS_Mesh::GetScript()
1027 {
1028         return myScript;
1029 }
1030
1031 //=======================================================================
1032 //function : ClearScript
1033 //purpose  : 
1034 //=======================================================================
1035 void SMESHDS_Mesh::ClearScript()
1036 {
1037         myScript->Clear();
1038 }
1039
1040 //=======================================================================
1041 //function : HasMeshElements
1042 //purpose  : 
1043 //=======================================================================
1044 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
1045 {
1046         if (myShape.IsNull()) MESSAGE("myShape is NULL");
1047         int Index = myIndexToShape.FindIndex(S);
1048         return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
1049 }
1050
1051 //=======================================================================
1052 //function : HasHypothesis
1053 //purpose  : 
1054 //=======================================================================
1055 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
1056 {
1057         return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
1058 }
1059
1060 //=======================================================================
1061 //function : NewSubMesh 
1062 //purpose  : 
1063 //=======================================================================
1064 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
1065 {
1066   SMESHDS_SubMesh* SM = 0;
1067   TShapeIndexToSubMesh::iterator anIter = myShapeIndexToSubMesh.find(Index);
1068   if (anIter == myShapeIndexToSubMesh.end())
1069   {
1070     SM = new SMESHDS_SubMesh();
1071     myShapeIndexToSubMesh[Index]=SM;
1072   }
1073   else
1074     SM = anIter->second;
1075   return SM;
1076 }
1077
1078 //=======================================================================
1079 //function : AddCompoundSubmesh
1080 //purpose  : 
1081 //=======================================================================
1082
1083 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
1084                                      TopAbs_ShapeEnum    type)
1085 {
1086   int aMainIndex = 0;
1087   if ( IsGroupOfSubShapes( S ) || (S.ShapeType() == TopAbs_VERTEX && myIndexToShape.Contains(S)) )
1088   {
1089     aMainIndex = myIndexToShape.Add( S );
1090     bool all = ( type == TopAbs_SHAPE );
1091     if ( all ) // corresponding simple submesh may exist
1092       aMainIndex = -aMainIndex;
1093     //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
1094     SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
1095     if ( !aNewSub->IsComplexSubmesh() ) // is empty
1096     {
1097       int shapeType = all ? myShape.ShapeType() : type;
1098       int typeLimit = all ? TopAbs_VERTEX : type;
1099       for ( ; shapeType <= typeLimit; shapeType++ )
1100       {
1101         TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
1102         for ( ; exp.More(); exp.Next() )
1103         {
1104           int index = myIndexToShape.FindIndex( exp.Current() );
1105           if ( index )
1106             aNewSub->AddSubMesh( NewSubMesh( index ));
1107         }
1108       }
1109     }
1110   }
1111   return aMainIndex;
1112 }
1113
1114 //=======================================================================
1115 //function : IndexToShape
1116 //purpose  : 
1117 //=======================================================================
1118 const TopoDS_Shape& SMESHDS_Mesh::IndexToShape(int ShapeIndex) const
1119 {
1120         return myIndexToShape.FindKey(ShapeIndex);
1121 }
1122
1123 //=======================================================================
1124 //function : ShapeToIndex
1125 //purpose  : 
1126 //=======================================================================
1127 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
1128 {
1129   if (myShape.IsNull())
1130     MESSAGE("myShape is NULL");
1131
1132   int index = myIndexToShape.FindIndex(S);
1133   
1134   return index;
1135 }
1136
1137 //=======================================================================
1138 //function : SetNodeOnVolume
1139 //purpose  : 
1140 //=======================================================================
1141 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
1142 {
1143   add( aNode, getSubmesh( Index ));
1144 }
1145
1146 //=======================================================================
1147 //function : SetNodeOnFace
1148 //purpose  : 
1149 //=======================================================================
1150 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index, double u, double v)
1151 {
1152   //Set Position on Node
1153   if ( add( aNode, getSubmesh( Index )))
1154     aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, u, v)));
1155 }
1156
1157 //=======================================================================
1158 //function : SetNodeOnEdge
1159 //purpose  : 
1160 //=======================================================================
1161 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode,
1162                                  int            Index,
1163                                  double         u)
1164 {
1165   //Set Position on Node
1166   if ( add( aNode, getSubmesh( Index )))
1167     aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, u)));
1168 }
1169
1170 //=======================================================================
1171 //function : SetNodeOnVertex
1172 //purpose  : 
1173 //=======================================================================
1174 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
1175 {
1176   //Set Position on Node
1177   if ( add( aNode, getSubmesh( Index )))
1178     aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
1179 }
1180
1181 //=======================================================================
1182 //function : SetMeshElementOnShape
1183 //purpose  : 
1184 //=======================================================================
1185 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
1186                                          int                     Index)
1187 {
1188   add( anElement, getSubmesh( Index ));
1189 }
1190
1191 SMESHDS_Mesh::~SMESHDS_Mesh()
1192 {
1193   delete myScript;
1194 }
1195
1196
1197
1198 //********************************************************************
1199 //********************************************************************
1200 //********                                                   *********
1201 //*****       Methods for addition of quadratic elements        ******
1202 //********                                                   *********
1203 //********************************************************************
1204 //********************************************************************
1205
1206 //=======================================================================
1207 //function : AddEdgeWithID
1208 //purpose  : 
1209 //=======================================================================
1210 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID) 
1211 {
1212   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,n12,ID);
1213   if(anElem) myScript->AddEdge(ID,n1,n2,n12);
1214   return anElem;
1215 }
1216
1217 //=======================================================================
1218 //function : AddEdge
1219 //purpose  : 
1220 //=======================================================================
1221 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
1222                                      const SMDS_MeshNode* n2,
1223                                      const SMDS_MeshNode* n12)
1224 {
1225   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2,n12);
1226   if(anElem) myScript->AddEdge(anElem->GetID(), 
1227                                n1->GetID(), 
1228                                n2->GetID(),
1229                                n12->GetID());
1230   return anElem;
1231 }
1232
1233 //=======================================================================
1234 //function : AddEdgeWithID
1235 //purpose  : 
1236 //=======================================================================
1237 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
1238                                            const SMDS_MeshNode * n2, 
1239                                            const SMDS_MeshNode * n12, 
1240                                            int ID)
1241 {
1242   return AddEdgeWithID(n1->GetID(),
1243                        n2->GetID(),
1244                        n12->GetID(),
1245                        ID);
1246 }
1247
1248
1249 //=======================================================================
1250 //function : AddFace
1251 //purpose  : 
1252 //=======================================================================
1253 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1254                                      const SMDS_MeshNode * n2,
1255                                      const SMDS_MeshNode * n3,
1256                                      const SMDS_MeshNode * n12,
1257                                      const SMDS_MeshNode * n23,
1258                                      const SMDS_MeshNode * n31)
1259 {
1260   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n12,n23,n31);
1261   if(anElem) myScript->AddFace(anElem->GetID(), 
1262                                n1->GetID(), n2->GetID(), n3->GetID(),
1263                                n12->GetID(), n23->GetID(), n31->GetID());
1264   return anElem;
1265 }
1266
1267 //=======================================================================
1268 //function : AddFaceWithID
1269 //purpose  : 
1270 //=======================================================================
1271 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
1272                                            int n12,int n23,int n31, int ID)
1273 {
1274   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,ID);
1275   if(anElem) myScript->AddFace(ID,n1,n2,n3,n12,n23,n31);
1276   return anElem;
1277 }
1278
1279 //=======================================================================
1280 //function : AddFaceWithID
1281 //purpose  : 
1282 //=======================================================================
1283 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1284                                            const SMDS_MeshNode * n2,
1285                                            const SMDS_MeshNode * n3,
1286                                            const SMDS_MeshNode * n12,
1287                                            const SMDS_MeshNode * n23,
1288                                            const SMDS_MeshNode * n31, 
1289                                            int ID)
1290 {
1291   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1292                        n12->GetID(), n23->GetID(), n31->GetID(),
1293                        ID);
1294 }
1295
1296
1297 //=======================================================================
1298 //function : AddFace
1299 //purpose  : 
1300 //=======================================================================
1301 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1302                                      const SMDS_MeshNode * n2,
1303                                      const SMDS_MeshNode * n3,
1304                                      const SMDS_MeshNode * n4,
1305                                      const SMDS_MeshNode * n12,
1306                                      const SMDS_MeshNode * n23,
1307                                      const SMDS_MeshNode * n34,
1308                                      const SMDS_MeshNode * n41)
1309 {
1310   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n4,n12,n23,n34,n41);
1311   if(anElem) myScript->AddFace(anElem->GetID(), 
1312                                n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1313                                n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID());
1314   return anElem;
1315 }
1316
1317 //=======================================================================
1318 //function : AddFaceWithID
1319 //purpose  : 
1320 //=======================================================================
1321 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
1322                                            int n12,int n23,int n34,int n41, int ID)
1323 {
1324   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,ID);
1325   if(anElem) myScript->AddFace(ID,n1,n2,n3,n4,n12,n23,n34,n41);
1326   return anElem;
1327 }
1328
1329 //=======================================================================
1330 //function : AddFaceWithID
1331 //purpose  : 
1332 //=======================================================================
1333 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1334                                            const SMDS_MeshNode * n2,
1335                                            const SMDS_MeshNode * n3,
1336                                            const SMDS_MeshNode * n4,
1337                                            const SMDS_MeshNode * n12,
1338                                            const SMDS_MeshNode * n23,
1339                                            const SMDS_MeshNode * n34, 
1340                                            const SMDS_MeshNode * n41, 
1341                                            int ID)
1342 {
1343   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1344                        n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1345                        ID);
1346 }
1347
1348
1349 //=======================================================================
1350 //function : AddVolume
1351 //purpose  : 
1352 //=======================================================================
1353 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1354                                          const SMDS_MeshNode * n2, 
1355                                          const SMDS_MeshNode * n3,
1356                                          const SMDS_MeshNode * n4,
1357                                          const SMDS_MeshNode * n12,
1358                                          const SMDS_MeshNode * n23,
1359                                          const SMDS_MeshNode * n31,
1360                                          const SMDS_MeshNode * n14, 
1361                                          const SMDS_MeshNode * n24,
1362                                          const SMDS_MeshNode * n34)
1363 {
1364   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
1365   if(anElem) myScript->AddVolume(anElem->GetID(), 
1366                                  n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1367                                  n12->GetID(), n23->GetID(), n31->GetID(),
1368                                  n14->GetID(), n24->GetID(), n34->GetID());
1369   return anElem;
1370 }
1371
1372 //=======================================================================
1373 //function : AddVolumeWithID
1374 //purpose  : 
1375 //=======================================================================
1376 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
1377                                                int n12,int n23,int n31,
1378                                                int n14,int n24,int n34, int ID)
1379 {
1380   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n12,n23,
1381                                                        n31,n14,n24,n34,ID);
1382   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
1383   return anElem;
1384 }
1385         
1386 //=======================================================================
1387 //function : AddVolumeWithID
1388 //purpose  : 2d order tetrahedron of 10 nodes
1389 //=======================================================================
1390 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1391                                                const SMDS_MeshNode * n2,
1392                                                const SMDS_MeshNode * n3,
1393                                                const SMDS_MeshNode * n4,
1394                                                const SMDS_MeshNode * n12,
1395                                                const SMDS_MeshNode * n23,
1396                                                const SMDS_MeshNode * n31,
1397                                                const SMDS_MeshNode * n14, 
1398                                                const SMDS_MeshNode * n24,
1399                                                const SMDS_MeshNode * n34,
1400                                                int ID)
1401 {
1402   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1403                          n12->GetID(), n23->GetID(), n31->GetID(),
1404                          n14->GetID(), n24->GetID(), n34->GetID(), ID);
1405 }
1406
1407
1408 //=======================================================================
1409 //function : AddVolume
1410 //purpose  : 
1411 //=======================================================================
1412 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1413                                          const SMDS_MeshNode * n2, 
1414                                          const SMDS_MeshNode * n3,
1415                                          const SMDS_MeshNode * n4,
1416                                          const SMDS_MeshNode * n5, 
1417                                          const SMDS_MeshNode * n12,
1418                                          const SMDS_MeshNode * n23,
1419                                          const SMDS_MeshNode * n34,
1420                                          const SMDS_MeshNode * n41,
1421                                          const SMDS_MeshNode * n15, 
1422                                          const SMDS_MeshNode * n25,
1423                                          const SMDS_MeshNode * n35,
1424                                          const SMDS_MeshNode * n45)
1425 {
1426   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n12,n23,n34,n41,
1427                                                  n15,n25,n35,n45);
1428   if(anElem)
1429     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1430                         n3->GetID(), n4->GetID(), n5->GetID(),
1431                         n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1432                         n15->GetID(), n25->GetID(), n35->GetID(), n45->GetID());
1433   return anElem;
1434 }
1435
1436 //=======================================================================
1437 //function : AddVolumeWithID
1438 //purpose  : 
1439 //=======================================================================
1440 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
1441                                                int n12,int n23,int n34,int n41,
1442                                                int n15,int n25,int n35,int n45, int ID)
1443 {
1444   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,
1445                                                        n12,n23,n34,n41,
1446                                                        n15,n25,n35,n45,ID);
1447   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n12,n23,n34,n41,
1448                                  n15,n25,n35,n45);
1449   return anElem;
1450 }
1451         
1452 //=======================================================================
1453 //function : AddVolumeWithID
1454 //purpose  : 2d order pyramid of 13 nodes
1455 //=======================================================================
1456 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1457                                                const SMDS_MeshNode * n2,
1458                                                const SMDS_MeshNode * n3,
1459                                                const SMDS_MeshNode * n4,
1460                                                const SMDS_MeshNode * n5, 
1461                                                const SMDS_MeshNode * n12,
1462                                                const SMDS_MeshNode * n23,
1463                                                const SMDS_MeshNode * n34,
1464                                                const SMDS_MeshNode * n41,
1465                                                const SMDS_MeshNode * n15, 
1466                                                const SMDS_MeshNode * n25,
1467                                                const SMDS_MeshNode * n35,
1468                                                const SMDS_MeshNode * n45,
1469                                                int ID)
1470 {
1471   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1472                          n4->GetID(), n5->GetID(),
1473                          n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1474                          n15->GetID(), n25->GetID(), n35->GetID(), n45->GetID(),
1475                          ID);
1476 }
1477
1478
1479 //=======================================================================
1480 //function : AddVolume
1481 //purpose  : 
1482 //=======================================================================
1483 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1484                                          const SMDS_MeshNode * n2, 
1485                                          const SMDS_MeshNode * n3,
1486                                          const SMDS_MeshNode * n4,
1487                                          const SMDS_MeshNode * n5, 
1488                                          const SMDS_MeshNode * n6, 
1489                                          const SMDS_MeshNode * n12,
1490                                          const SMDS_MeshNode * n23,
1491                                          const SMDS_MeshNode * n31, 
1492                                          const SMDS_MeshNode * n45,
1493                                          const SMDS_MeshNode * n56,
1494                                          const SMDS_MeshNode * n64, 
1495                                          const SMDS_MeshNode * n14,
1496                                          const SMDS_MeshNode * n25,
1497                                          const SMDS_MeshNode * n36)
1498 {
1499   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n12,n23,n31,
1500                                                  n45,n56,n64,n14,n25,n36);
1501   if(anElem)
1502     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1503                         n3->GetID(), n4->GetID(), n5->GetID(), n6->GetID(),
1504                         n12->GetID(), n23->GetID(), n31->GetID(),
1505                         n45->GetID(), n56->GetID(), n64->GetID(),
1506                         n14->GetID(), n25->GetID(), n36->GetID());
1507   return anElem;
1508 }
1509
1510 //=======================================================================
1511 //function : AddVolumeWithID
1512 //purpose  : 
1513 //=======================================================================
1514 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
1515                                                int n4, int n5, int n6,
1516                                                int n12,int n23,int n31,
1517                                                int n45,int n56,int n64,
1518                                                int n14,int n25,int n36, int ID)
1519 {
1520   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,
1521                                                        n12,n23,n31,
1522                                                        n45,n56,n64,
1523                                                        n14,n25,n36,ID);
1524   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n12,n23,n31,
1525                                  n45,n56,n64,n14,n25,n36);
1526   return anElem;
1527 }
1528         
1529 //=======================================================================
1530 //function : AddVolumeWithID
1531 //purpose  : 2d order Pentahedron with 15 nodes
1532 //=======================================================================
1533 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1534                                                const SMDS_MeshNode * n2,
1535                                                const SMDS_MeshNode * n3,
1536                                                const SMDS_MeshNode * n4,
1537                                                const SMDS_MeshNode * n5, 
1538                                                const SMDS_MeshNode * n6, 
1539                                                const SMDS_MeshNode * n12,
1540                                                const SMDS_MeshNode * n23,
1541                                                const SMDS_MeshNode * n31, 
1542                                                const SMDS_MeshNode * n45,
1543                                                const SMDS_MeshNode * n56,
1544                                                const SMDS_MeshNode * n64, 
1545                                                const SMDS_MeshNode * n14,
1546                                                const SMDS_MeshNode * n25,
1547                                                const SMDS_MeshNode * n36,
1548                                                int ID)
1549 {
1550   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1551                          n4->GetID(), n5->GetID(), n6->GetID(),
1552                          n12->GetID(), n23->GetID(), n31->GetID(),
1553                          n45->GetID(), n56->GetID(), n64->GetID(),
1554                          n14->GetID(), n25->GetID(), n36->GetID(),
1555                          ID);
1556 }
1557
1558
1559 //=======================================================================
1560 //function : AddVolume
1561 //purpose  : 
1562 //=======================================================================
1563 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1564                                          const SMDS_MeshNode * n2, 
1565                                          const SMDS_MeshNode * n3,
1566                                          const SMDS_MeshNode * n4,
1567                                          const SMDS_MeshNode * n5, 
1568                                          const SMDS_MeshNode * n6, 
1569                                          const SMDS_MeshNode * n7,
1570                                          const SMDS_MeshNode * n8, 
1571                                          const SMDS_MeshNode * n12,
1572                                          const SMDS_MeshNode * n23,
1573                                          const SMDS_MeshNode * n34,
1574                                          const SMDS_MeshNode * n41, 
1575                                          const SMDS_MeshNode * n56,
1576                                          const SMDS_MeshNode * n67,
1577                                          const SMDS_MeshNode * n78,
1578                                          const SMDS_MeshNode * n85, 
1579                                          const SMDS_MeshNode * n15,
1580                                          const SMDS_MeshNode * n26,
1581                                          const SMDS_MeshNode * n37,
1582                                          const SMDS_MeshNode * n48)
1583 {
1584   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,
1585                                                  n12,n23,n34,n41,
1586                                                  n56,n67,n78,n85,
1587                                                  n15,n26,n37,n48);
1588   if(anElem)
1589     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1590                         n3->GetID(), n4->GetID(), n5->GetID(),
1591                         n6->GetID(), n7->GetID(), n8->GetID(),
1592                         n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1593                         n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
1594                         n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID());
1595   return anElem;
1596 }
1597
1598 //=======================================================================
1599 //function : AddVolumeWithID
1600 //purpose  : 
1601 //=======================================================================
1602 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
1603                                                int n5, int n6, int n7, int n8,
1604                                                int n12,int n23,int n34,int n41,
1605                                                int n56,int n67,int n78,int n85,
1606                                                int n15,int n26,int n37,int n48, int ID)
1607 {
1608   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,
1609                                                        n12,n23,n34,n41,
1610                                                        n56,n67,n78,n85,
1611                                                        n15,n26,n37,n48,ID);
1612   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
1613                                  n56,n67,n78,n85,n15,n26,n37,n48);
1614   return anElem;
1615 }
1616         
1617 //=======================================================================
1618 //function : AddVolumeWithID
1619 //purpose  : 2d order Hexahedrons with 20 nodes
1620 //=======================================================================
1621 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1622                                                const SMDS_MeshNode * n2,
1623                                                const SMDS_MeshNode * n3,
1624                                                const SMDS_MeshNode * n4,
1625                                                const SMDS_MeshNode * n5, 
1626                                                const SMDS_MeshNode * n6, 
1627                                                const SMDS_MeshNode * n7,
1628                                                const SMDS_MeshNode * n8, 
1629                                                const SMDS_MeshNode * n12,
1630                                                const SMDS_MeshNode * n23,
1631                                                const SMDS_MeshNode * n34,
1632                                                const SMDS_MeshNode * n41, 
1633                                                const SMDS_MeshNode * n56,
1634                                                const SMDS_MeshNode * n67,
1635                                                const SMDS_MeshNode * n78,
1636                                                const SMDS_MeshNode * n85, 
1637                                                const SMDS_MeshNode * n15,
1638                                                const SMDS_MeshNode * n26,
1639                                                const SMDS_MeshNode * n37,
1640                                                const SMDS_MeshNode * n48,
1641                                                int ID)
1642 {
1643   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1644                          n5->GetID(), n6->GetID(), n7->GetID(), n8->GetID(),
1645                          n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1646                          n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
1647                          n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
1648                          ID);
1649 }
1650
1651