Salome HOME
a6cae5391c7d9287a4e4f1708c32e2976d9fbeba
[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 #include "SMDS_VertexPosition.hxx"
31 #include "SMDS_EdgePosition.hxx"
32 #include "SMDS_FacePosition.hxx"
33 #include <TopExp_Explorer.hxx>
34 #include <TopExp.hxx>
35
36 #include "utilities.h"
37 //=======================================================================
38 //function : Create
39 //purpose  : 
40 //=======================================================================
41 SMESHDS_Mesh::SMESHDS_Mesh(int MeshID):myMeshID(MeshID)
42 {
43         myScript = new SMESHDS_Script();
44 }
45
46 //=======================================================================
47 //function : ShapeToMesh
48 //purpose  : 
49 //=======================================================================
50 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
51 {
52         myShape = S;
53         TopExp::MapShapes(myShape, myIndexToShape);
54 }
55
56 //=======================================================================
57 //function : AddHypothesis
58 //purpose  : 
59 //=======================================================================
60
61 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
62         const SMESHDS_Hypothesis * H)
63 {
64         list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis[SS];
65
66         //Check if the Hypothesis is still present
67         list<const SMESHDS_Hypothesis*>::iterator ith=alist.begin();
68
69         for (; ith!=alist.end(); ith++)
70                 if (H == *ith) return false;
71
72         alist.push_back(H);
73         return true;
74 }
75
76 //=======================================================================
77 //function : RemoveHypothesis
78 //purpose  : 
79 //=======================================================================
80
81 bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S,
82         const SMESHDS_Hypothesis * H)
83 {
84         ShapeToHypothesis::iterator its=myShapeToHypothesis.find(S);
85         if(its!=myShapeToHypothesis.end())
86         {
87                 list<const SMESHDS_Hypothesis*>::iterator ith=(*its).second.begin();
88
89                 for (; ith!=(*its).second.end(); ith++)
90                         if (H == *ith)
91                         {
92                                 (*its).second.erase(ith);
93                                 return true;
94                         }
95         }
96         return false;
97 }
98
99 //=======================================================================
100 //function : AddNode
101 //purpose  : 
102 //=======================================================================
103 SMDS_MeshNode* SMESHDS_Mesh::AddNode(double x, double y, double z){
104   SMDS_MeshNode* node = SMDS_Mesh::AddNode(x, y, z);
105   if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
106   return node;
107 }
108
109 SMDS_MeshNode* SMESHDS_Mesh::AddNodeWithID(double x, double y, double z, int ID){
110   SMDS_MeshNode* node = SMDS_Mesh::AddNodeWithID(x,y,z,ID);
111   if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
112   return node;
113 }
114
115 //=======================================================================
116 //function : MoveNode
117 //purpose  : 
118 //=======================================================================
119 void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
120 {
121   SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
122   node->setXYZ(x,y,z);
123   myScript->MoveNode(n->GetID(), x, y, z);
124 }
125
126 //=======================================================================
127 //function : AddEdge
128 //purpose  : 
129 //=======================================================================
130 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
131 {
132   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
133   if(anElem) myScript->AddEdge(ID,n1,n2);
134   return anElem;
135 }
136
137 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
138                                            const SMDS_MeshNode * n2, 
139                                            int ID)
140 {
141   return AddEdgeWithID(n1->GetID(),
142                        n2->GetID(),
143                        ID);
144 }
145
146 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
147                                      const SMDS_MeshNode * n2)
148 {
149   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
150   if(anElem) myScript->AddEdge(anElem->GetID(), 
151                                n1->GetID(), 
152                                n2->GetID());
153   return anElem;
154 }
155
156 //=======================================================================
157 //function :AddFace
158 //purpose  : 
159 //=======================================================================
160 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
161 {
162   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
163   if(anElem) myScript->AddFace(ID,n1,n2,n3);
164   return anElem;
165 }
166
167 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
168                                            const SMDS_MeshNode * n2,
169                                            const SMDS_MeshNode * n3, 
170                                            int ID)
171 {
172   return AddFaceWithID(n1->GetID(),
173                        n2->GetID(),
174                        n3->GetID(),
175                        ID);
176 }
177
178 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
179                                       const SMDS_MeshNode * n2,
180                                       const SMDS_MeshNode * n3)
181 {
182   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
183   if(anElem) myScript->AddFace(anElem->GetID(), 
184                                n1->GetID(), 
185                                n2->GetID(),
186                                n3->GetID());
187   return anElem;
188 }
189
190 //=======================================================================
191 //function :AddFace
192 //purpose  : 
193 //=======================================================================
194 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
195 {
196   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
197   if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
198   return anElem;
199 }
200
201 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
202                                            const SMDS_MeshNode * n2,
203                                            const SMDS_MeshNode * n3,
204                                            const SMDS_MeshNode * n4, 
205                                            int ID)
206 {
207   return AddFaceWithID(n1->GetID(),
208                        n2->GetID(),
209                        n3->GetID(),
210                        n4->GetID(),
211                        ID);
212 }
213
214 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
215                                      const SMDS_MeshNode * n2,
216                                      const SMDS_MeshNode * n3,
217                                      const SMDS_MeshNode * n4)
218 {
219   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
220   if(anElem) myScript->AddFace(anElem->GetID(), 
221                                n1->GetID(), 
222                                n2->GetID(), 
223                                n3->GetID(),
224                                n4->GetID());
225   return anElem;
226 }
227
228 //=======================================================================
229 //function :AddVolume
230 //purpose  : 
231 //=======================================================================
232 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
233 {
234   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
235   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
236   return anElem;
237 }
238
239 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
240                                                const SMDS_MeshNode * n2,
241                                                const SMDS_MeshNode * n3,
242                                                const SMDS_MeshNode * n4, 
243                                                int ID)
244 {
245   return AddVolumeWithID(n1->GetID(), 
246                          n2->GetID(), 
247                          n3->GetID(),
248                          n4->GetID(),
249                          ID);
250 }
251
252 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
253                                          const SMDS_MeshNode * n2,
254                                          const SMDS_MeshNode * n3,
255                                          const SMDS_MeshNode * n4)
256 {
257   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
258   if(anElem) myScript->AddVolume(anElem->GetID(), 
259                                  n1->GetID(), 
260                                  n2->GetID(), 
261                                  n3->GetID(),
262                                  n4->GetID());
263   return anElem;
264 }
265
266 //=======================================================================
267 //function :AddVolume
268 //purpose  : 
269 //=======================================================================
270 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
271 {
272   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
273   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
274   return anElem;
275 }
276
277 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
278                                                const SMDS_MeshNode * n2,
279                                                const SMDS_MeshNode * n3,
280                                                const SMDS_MeshNode * n4,
281                                                const SMDS_MeshNode * n5, 
282                                                int ID)
283 {
284   return AddVolumeWithID(n1->GetID(), 
285                          n2->GetID(), 
286                          n3->GetID(),
287                          n4->GetID(), 
288                          n5->GetID(),
289                          ID);
290 }
291
292 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
293                                          const SMDS_MeshNode * n2,
294                                          const SMDS_MeshNode * n3,
295                                          const SMDS_MeshNode * n4,
296                                          const SMDS_MeshNode * n5)
297 {
298   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
299   if(anElem) myScript->AddVolume(anElem->GetID(), 
300                                  n1->GetID(), 
301                                  n2->GetID(), 
302                                  n3->GetID(),
303                                  n4->GetID(), 
304                                  n5->GetID());
305   return anElem;
306 }
307
308 //=======================================================================
309 //function :AddVolume
310 //purpose  : 
311 //=======================================================================
312 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
313 {
314   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
315   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
316   return anElem;
317 }
318
319 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
320                                                const SMDS_MeshNode * n2,
321                                                const SMDS_MeshNode * n3,
322                                                const SMDS_MeshNode * n4,
323                                                const SMDS_MeshNode * n5,
324                                                const SMDS_MeshNode * n6, 
325                                                int ID)
326 {
327   return AddVolumeWithID(n1->GetID(), 
328                          n2->GetID(), 
329                          n3->GetID(),
330                          n4->GetID(), 
331                          n5->GetID(), 
332                          n6->GetID(),
333                          ID);
334 }
335
336 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
337                                          const SMDS_MeshNode * n2,
338                                          const SMDS_MeshNode * n3,
339                                          const SMDS_MeshNode * n4,
340                                          const SMDS_MeshNode * n5,
341                                          const SMDS_MeshNode * n6)
342 {
343   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
344   if(anElem) myScript->AddVolume(anElem->GetID(), 
345                                  n1->GetID(), 
346                                  n2->GetID(), 
347                                  n3->GetID(),
348                                  n4->GetID(), 
349                                  n5->GetID(), 
350                                  n6->GetID());
351   return anElem;
352 }
353
354 //=======================================================================
355 //function :AddVolume
356 //purpose  : 
357 //=======================================================================
358 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
359 {
360   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
361   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
362   return anElem;
363 }
364
365 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
366                                                const SMDS_MeshNode * n2,
367                                                const SMDS_MeshNode * n3,
368                                                const SMDS_MeshNode * n4,
369                                                const SMDS_MeshNode * n5,
370                                                const SMDS_MeshNode * n6,
371                                                const SMDS_MeshNode * n7,
372                                                const SMDS_MeshNode * n8, 
373                                                int ID)
374 {
375   return AddVolumeWithID(n1->GetID(), 
376                          n2->GetID(), 
377                          n3->GetID(),
378                          n4->GetID(), 
379                          n5->GetID(), 
380                          n6->GetID(), 
381                          n7->GetID(), 
382                          n8->GetID(),
383                          ID);
384 }
385
386 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
387                                          const SMDS_MeshNode * n2,
388                                          const SMDS_MeshNode * n3,
389                                          const SMDS_MeshNode * n4,
390                                          const SMDS_MeshNode * n5,
391                                          const SMDS_MeshNode * n6,
392                                          const SMDS_MeshNode * n7,
393                                          const SMDS_MeshNode * n8)
394 {
395   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
396   if(anElem) myScript->AddVolume(anElem->GetID(), 
397                                  n1->GetID(), 
398                                  n2->GetID(), 
399                                  n3->GetID(),
400                                  n4->GetID(), 
401                                  n5->GetID(), 
402                                  n6->GetID(), 
403                                  n7->GetID(), 
404                                  n8->GetID());
405   return anElem;
406 }
407 //=======================================================================
408 //function : removeFromSubMeshes
409 //purpose  : 
410 //=======================================================================
411
412 static void removeFromSubMeshes (map<int,SMESHDS_SubMesh*> &      theSubMeshes,
413                                  list<const SMDS_MeshElement *> & theElems,
414                                  const bool                       isNode)
415 {
416   if ( theElems.empty() )
417     return;
418     
419   map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
420   for ( ; SubIt != theSubMeshes.end(); SubIt++ )
421   {
422     list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
423     while ( elIt != theElems.end() )
424     {
425       bool removed = false;
426       if ( isNode )
427         removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
428       else
429         removed = (*SubIt).second->RemoveElement( *elIt );
430
431       if (removed)
432       {
433         elIt = theElems.erase( elIt );
434         if ( theElems.empty() )
435           return; // all elements are found and removed
436       }
437       else
438       {
439         elIt++ ;
440       }
441     }
442   }
443 }
444   
445 //=======================================================================
446 //function : RemoveNode
447 //purpose  : 
448 //=======================================================================
449 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
450 {
451   myScript->RemoveNode(n->GetID());
452   
453   list<const SMDS_MeshElement *> removedElems;
454   list<const SMDS_MeshElement *> removedNodes;
455
456   SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
457
458   removeFromSubMeshes( myShapeIndexToSubMesh, removedElems, false );
459   removeFromSubMeshes( myShapeIndexToSubMesh, removedNodes, true );
460 }
461
462 //=======================================================================
463 //function : RemoveElement
464 //purpose  : 
465 //========================================================================
466 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
467 {
468   if (elt->GetType() == SMDSAbs_Node)
469   {
470     RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
471     return;
472   }
473
474   myScript->RemoveElement(elt->GetID());
475
476   list<const SMDS_MeshElement *> removedElems;
477   list<const SMDS_MeshElement *> removedNodes;
478
479   SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
480   
481   removeFromSubMeshes( myShapeIndexToSubMesh, removedElems, false );
482 }
483
484 //=======================================================================
485 //function : SetNodeOnVolume
486 //purpose  : 
487 //=======================================================================
488 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
489         const TopoDS_Shell & S)
490 {
491         if (myShape.IsNull()) MESSAGE("myShape is NULL");
492
493         int Index = myIndexToShape.FindIndex(S);
494
495         //Set Position on Node
496         //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
497         //aNode->SetPosition(aPos);
498
499         //Update or build submesh
500         map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
501         if (it==myShapeIndexToSubMesh.end())
502                 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
503
504         myShapeIndexToSubMesh[Index]->AddNode(aNode);
505 }
506
507 //=======================================================================
508 //function : SetNodeOnFace
509 //purpose  : 
510 //=======================================================================
511 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode * aNode,
512         const TopoDS_Face & S)
513 {
514         if (myShape.IsNull()) MESSAGE("myShape is NULL");
515
516         int Index = myIndexToShape.FindIndex(S);
517
518         //Set Position on Node
519         aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
520
521         //Update or build submesh
522         map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
523         if (it==myShapeIndexToSubMesh.end())
524                 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
525
526         myShapeIndexToSubMesh[Index]->AddNode(aNode);
527 }
528
529 //=======================================================================
530 //function : SetNodeOnEdge
531 //purpose  : 
532 //=======================================================================
533 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode * aNode,
534         const TopoDS_Edge & S)
535 {
536         if (myShape.IsNull()) MESSAGE("myShape is NULL");
537
538         int Index = myIndexToShape.FindIndex(S);
539
540         //Set Position on Node
541         aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
542
543         //Update or build submesh
544         map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
545         if (it==myShapeIndexToSubMesh.end())
546                 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
547
548         myShapeIndexToSubMesh[Index]->AddNode(aNode);
549 }
550
551 //=======================================================================
552 //function : SetNodeOnVertex
553 //purpose  : 
554 //=======================================================================
555 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode * aNode,
556         const TopoDS_Vertex & S)
557 {
558         if (myShape.IsNull()) MESSAGE("myShape is NULL");
559
560         int Index = myIndexToShape.FindIndex(S);
561
562         //Set Position on Node
563         aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
564
565         //Update or build submesh
566         map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
567         if (it==myShapeIndexToSubMesh.end())
568                 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
569
570         myShapeIndexToSubMesh[Index]->AddNode(aNode);
571 }
572
573 //=======================================================================
574 //function : UnSetNodeOnShape
575 //purpose  : 
576 //=======================================================================
577 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
578 {
579         MESSAGE("not implemented");
580 }
581
582 //=======================================================================
583 //function : SetMeshElementOnShape
584 //purpose  : 
585 //=======================================================================
586 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
587         const TopoDS_Shape & S)
588 {
589         if (myShape.IsNull()) MESSAGE("myShape is NULL");
590
591         int Index = myIndexToShape.FindIndex(S);
592
593         if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
594                 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
595
596         myShapeIndexToSubMesh[Index]->AddElement(anElement);
597 }
598
599 //=======================================================================
600 //function : UnSetMeshElementOnShape
601 //purpose  : 
602 //=======================================================================
603 void SMESHDS_Mesh::
604 UnSetMeshElementOnShape(const SMDS_MeshElement * anElement,
605         const TopoDS_Shape & S)
606 {
607         if (myShape.IsNull()) MESSAGE("myShape is NULL");
608
609         int Index = myIndexToShape.FindIndex(S);
610
611         if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
612                 myShapeIndexToSubMesh[Index]->RemoveElement(anElement);
613 }
614
615 //=======================================================================
616 //function : ShapeToMesh
617 //purpose  : 
618 //=======================================================================
619 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
620 {
621         return myShape;
622 }
623
624 ///////////////////////////////////////////////////////////////////////////////
625 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
626 /// TopoDS_Shape is unknown
627 ///////////////////////////////////////////////////////////////////////////////
628 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S)
629 {
630   if (myShape.IsNull()) MESSAGE("myShape is NULL");
631
632   int Index = myIndexToShape.FindIndex(S);
633   if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
634     return myShapeIndexToSubMesh[Index];
635   else
636     return NULL;
637 }
638
639 ///////////////////////////////////////////////////////////////////////////////
640 /// Return the sub mesh by Id of shape it is linked to
641 ///////////////////////////////////////////////////////////////////////////////
642 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
643 {
644   if (myShape.IsNull()) MESSAGE("myShape is NULL");
645
646   if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
647     return myShapeIndexToSubMesh[Index];
648   else
649     return NULL;
650 }
651
652 //=======================================================================
653 //function : SubMeshIndices
654 //purpose  : 
655 //=======================================================================
656 list<int> SMESHDS_Mesh::SubMeshIndices()
657 {
658   list<int> anIndices;
659   std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
660   for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
661     anIndices.push_back((*anIter).first);
662   }
663   return anIndices;
664 }
665
666 //=======================================================================
667 //function : GetHypothesis
668 //purpose  : 
669 //=======================================================================
670
671 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
672         const TopoDS_Shape & S) const
673 {
674         if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
675                 return myShapeToHypothesis.find(S)->second;
676
677         static list<const SMESHDS_Hypothesis*> empty;
678         return empty;
679 }
680
681 //=======================================================================
682 //function : GetScript
683 //purpose  : 
684 //=======================================================================
685 SMESHDS_Script* SMESHDS_Mesh::GetScript()
686 {
687         return myScript;
688 }
689
690 //=======================================================================
691 //function : ClearScript
692 //purpose  : 
693 //=======================================================================
694 void SMESHDS_Mesh::ClearScript()
695 {
696         myScript->Clear();
697 }
698
699 //=======================================================================
700 //function : HasMeshElements
701 //purpose  : 
702 //=======================================================================
703 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
704 {
705         if (myShape.IsNull()) MESSAGE("myShape is NULL");
706         int Index = myIndexToShape.FindIndex(S);
707         return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
708 }
709
710 //=======================================================================
711 //function : HasHypothesis
712 //purpose  : 
713 //=======================================================================
714 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
715 {
716         return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
717 }
718
719 //=======================================================================
720 //function : NewSubMesh 
721 //purpose  : 
722 //=======================================================================
723 void SMESHDS_Mesh::NewSubMesh(int Index)
724 {
725         if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
726         {
727                 SMESHDS_SubMesh* SM = new SMESHDS_SubMesh();
728                 myShapeIndexToSubMesh[Index]=SM;
729         }
730 }
731
732 //=======================================================================
733 //function : IndexToShape
734 //purpose  : 
735 //=======================================================================
736 TopoDS_Shape SMESHDS_Mesh::IndexToShape(int ShapeIndex)
737 {
738         return myIndexToShape.FindKey(ShapeIndex);
739 }
740
741 //=======================================================================
742 //function : ShapeToIndex
743 //purpose  : 
744 //=======================================================================
745 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S)
746 {
747         if (myShape.IsNull()) MESSAGE("myShape is NULL");
748         return myIndexToShape.FindIndex(S);
749 }
750
751 //=======================================================================
752 //function : SetNodeOnVolume
753 //purpose  : 
754 //=======================================================================
755 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
756 {
757         //Set Position on Node
758         //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
759         //aNode->SetPosition(aPos);
760
761         //Update or build submesh
762         if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
763                 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
764
765         myShapeIndexToSubMesh[Index]->AddNode(aNode);
766 }
767
768 //=======================================================================
769 //function : SetNodeOnFace
770 //purpose  : 
771 //=======================================================================
772 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index)
773 {
774         //Set Position on Node
775         aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
776
777         //Update or build submesh
778         if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
779                 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
780
781         myShapeIndexToSubMesh[Index]->AddNode(aNode);
782 }
783
784 //=======================================================================
785 //function : SetNodeOnEdge
786 //purpose  : 
787 //=======================================================================
788 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode, int Index)
789 {
790         //Set Position on Node
791         aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
792
793         //Update or build submesh
794         if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
795                 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
796
797         myShapeIndexToSubMesh[Index]->AddNode(aNode);
798 }
799
800 //=======================================================================
801 //function : SetNodeOnVertex
802 //purpose  : 
803 //=======================================================================
804 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
805 {
806         //Set Position on Node
807         aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
808
809         //Update or build submesh
810         if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
811                 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
812
813         myShapeIndexToSubMesh[Index]->AddNode(aNode);
814 }
815
816 //=======================================================================
817 //function : SetMeshElementOnShape
818 //purpose  : 
819 //=======================================================================
820 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
821         int Index)
822 {
823         if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
824                 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
825
826         myShapeIndexToSubMesh[Index]->AddElement(anElement);
827 }
828
829 SMESHDS_Mesh::~SMESHDS_Mesh()
830 {
831 }