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