Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/smesh.git] / src / SMESHDS / SMESHDS_Mesh.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SMESH_Mesh.cxx
4 // Created   : 
5 // Author    : Yves FRICAUD, OCC
6 // Project   : SALOME
7 // Copyright : OCC 2002
8 // $Header: 
9 //=============================================================================
10
11 #include "SMESHDS_Mesh.ixx"
12 #include "SMESHDS_Hypothesis.hxx"
13 #include "SMESHDS_DataMapOfShapeListOfPtrHypothesis.hxx"
14 #include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
15 #include "SMDS_VertexPosition.hxx"
16 #include "SMDS_EdgePosition.hxx"
17 #include "SMDS_FacePosition.hxx"
18 #include <TopExp_Explorer.hxx>
19 #include <TopExp.hxx>
20
21 #include <Standard_NullObject.hxx>
22 #include "utilities.h"
23
24 //=======================================================================
25 //function : Create
26 //purpose  : 
27 //=======================================================================
28 SMESHDS_Mesh::SMESHDS_Mesh(const Standard_Integer MeshID) : myMeshID( MeshID)
29 {
30   myScript = new SMESHDS_Script();
31 }
32
33 //=======================================================================
34 //function : ShapeToMesh
35 //purpose  : 
36 //=======================================================================
37 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape& S) 
38 {
39   myShape = S;
40   TopExp::MapShapes(myShape,myIndexToShape);
41 }
42   
43   
44 //=======================================================================
45 //function : AddHypothesis
46 //purpose  : 
47 //=======================================================================
48
49 Standard_Boolean SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape& SS,
50                                              const SMESHDS_PtrHypothesis& H) 
51 {
52   if (!myShapeToHypothesis.IsBound(SS)){
53     SMESHDS_ListOfPtrHypothesis empty;
54     myShapeToHypothesis.Bind(SS,empty);
55   }
56   else {
57     //Check if the Hypothesis is still present
58     SMESHDS_ListOfPtrHypothesis& Hypos = myShapeToHypothesis.ChangeFind (SS);
59
60     for (SMESHDS_ListIteratorOfListOfPtrHypothesis it(Hypos); it.More(); it.Next()) {
61       if (H == it.Value()) {
62         return Standard_False;
63       }
64     }
65   }
66   myShapeToHypothesis(SS).Append(H);
67   return Standard_True;
68 }
69
70 //=======================================================================
71 //function : RemoveHypothesis
72 //purpose  : 
73 //=======================================================================
74
75 Standard_Boolean SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape& S,
76                                                 const SMESHDS_PtrHypothesis& H) 
77 {
78   if (myShapeToHypothesis.IsBound(S)){
79     SMESHDS_ListOfPtrHypothesis& Hypos = myShapeToHypothesis.ChangeFind (S);
80     for (SMESHDS_ListIteratorOfListOfPtrHypothesis it(Hypos); it.More(); it.Next()) {
81       if (H == it.Value()) {
82         Hypos.Remove(it);
83         return Standard_True;
84       }
85     }
86   }
87   return Standard_False;
88 }
89   
90   
91 //=======================================================================
92 //function : AddNode
93 //purpose  : 
94 //=======================================================================
95 Standard_Integer SMESHDS_Mesh::AddNode(const Standard_Real x,
96                                        const Standard_Real y,
97                                        const Standard_Real z) 
98 {
99   Standard_Integer NodeID = SMDS_Mesh::AddNode(x,y,z);
100   myScript->AddNode(NodeID,x,y,z);
101   return NodeID;
102 }
103
104 //=======================================================================
105 //function : MoveNode
106 //purpose  : 
107 //=======================================================================
108 void SMESHDS_Mesh::MoveNode(const Standard_Integer ID,
109                                         const Standard_Real x,
110                                         const Standard_Real y,
111                                         const Standard_Real z) 
112 {
113
114   Handle(SMDS_MeshNode) Node = Handle(SMDS_MeshNode)::DownCast(FindNode(ID));
115   gp_Pnt P(x,y,z);
116   Node->SetPnt(P);
117   myScript->MoveNode(ID,x,y,z);
118 }
119
120
121
122 //=======================================================================
123 //function : AddEdge
124 //purpose  : 
125 //=======================================================================
126 Standard_Integer SMESHDS_Mesh::AddEdge(const Standard_Integer idnode1,
127                                        const Standard_Integer idnode2) 
128 {
129   Standard_Integer ID = SMDS_Mesh::AddEdge(idnode1,idnode2);
130   myScript->AddEdge (ID,idnode1,idnode2);
131   return ID;
132 }
133
134
135 //=======================================================================
136 //function :AddFace
137 //purpose  : 
138 //=======================================================================
139 Standard_Integer SMESHDS_Mesh::AddFace(const Standard_Integer idnode1,
140                                        const Standard_Integer idnode2,
141                                        const Standard_Integer idnode3) 
142 {
143   Standard_Integer ID = SMDS_Mesh::AddFace(idnode1,idnode2,idnode3);
144   myScript->AddFace (ID,idnode1,idnode2,idnode3);
145   return ID;
146 }
147
148 //=======================================================================
149 //function :AddFace
150 //purpose  : 
151 //=======================================================================
152 Standard_Integer SMESHDS_Mesh::AddFace(const Standard_Integer idnode1,
153                                        const Standard_Integer idnode2,
154                                        const Standard_Integer idnode3,
155                                        const Standard_Integer idnode4) 
156 {
157   Standard_Integer ID = SMDS_Mesh::AddFace(idnode1,idnode2,idnode3,idnode4);
158   myScript->AddFace (ID,idnode1,idnode2,idnode3,idnode4);
159   return ID;
160 }
161
162
163 //=======================================================================
164 //function :AddVolume
165 //purpose  : 
166 //=======================================================================
167 Standard_Integer SMESHDS_Mesh::AddVolume(const Standard_Integer idnode1,
168                                          const Standard_Integer idnode2,
169                                          const Standard_Integer idnode3,
170                                          const Standard_Integer idnode4) 
171 {
172   Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4);
173   myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4);
174   return ID;
175 }
176
177
178 //=======================================================================
179 //function :AddVolume
180 //purpose  : 
181 //=======================================================================
182 Standard_Integer SMESHDS_Mesh::AddVolume(const Standard_Integer idnode1,
183                                          const Standard_Integer idnode2,
184                                          const Standard_Integer idnode3,
185                                          const Standard_Integer idnode4,
186                                          const Standard_Integer idnode5) 
187 {
188   Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4,idnode5);
189   myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4,idnode5);
190   return ID;
191 }
192
193
194 //=======================================================================
195 //function :AddVolume
196 //purpose  : 
197 //=======================================================================
198 Standard_Integer SMESHDS_Mesh::AddVolume(const Standard_Integer idnode1,
199                                          const Standard_Integer idnode2,
200                                          const Standard_Integer idnode3,
201                                          const Standard_Integer idnode4,
202                                          const Standard_Integer idnode5,
203                                          const Standard_Integer idnode6) 
204 {
205   Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
206   myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
207   return ID;
208 }
209
210 //=======================================================================
211 //function :AddVolume
212 //purpose  : 
213 //=======================================================================
214 Standard_Integer SMESHDS_Mesh::AddVolume(const Standard_Integer idnode1,
215                                          const Standard_Integer idnode2,
216                                          const Standard_Integer idnode3,
217                                          const Standard_Integer idnode4,
218                                          const Standard_Integer idnode5,
219                                          const Standard_Integer idnode6,
220                                          const Standard_Integer idnode7,
221                                          const Standard_Integer idnode8) 
222 {
223   Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4,idnode5,idnode6,idnode7,idnode8);
224   myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4,idnode5,idnode6,idnode7,idnode8);
225   return ID;
226 }
227
228
229 //=======================================================================
230 //function : RemoveNode
231 //purpose  : 
232 //=======================================================================
233 void SMESHDS_Mesh::RemoveNode(const Standard_Integer ID) 
234 {
235   SMDS_Mesh::RemoveNode (ID);
236   myScript->RemoveNode  (ID);
237 }
238
239
240
241 //=======================================================================
242 //function : RemoveElement
243 //purpose  : 
244 //========================================================================
245 void SMESHDS_Mesh::RemoveElement(const Standard_Integer ID) 
246 {
247   SMDS_Mesh::RemoveElement (ID);
248   myScript->RemoveElement  (ID);
249 }
250
251 //=======================================================================
252 //function : SetNodeOnVolume
253 //purpose  : 
254 //=======================================================================
255 void SMESHDS_Mesh::SetNodeInVolume (const Handle(SMDS_MeshNode)& aNode,
256                                     const TopoDS_Shell& S) 
257 {
258   if (myShape.IsNull()) 
259     Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVolume");
260   
261   Standard_Integer Index = myIndexToShape.FindIndex(S);
262   
263   //Set Position on Node
264   //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
265   //aNode->SetPosition(aPos);
266   
267   //Update or build submesh
268   if (!myShapeIndexToSubMesh.IsBound(Index)) {
269     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
270     myShapeIndexToSubMesh.Bind(Index,SM);
271   }
272   myShapeIndexToSubMesh(Index)->AddNode (aNode);
273 }
274
275 //=======================================================================
276 //function : SetNodeOnFace
277 //purpose  : 
278 //=======================================================================
279 void SMESHDS_Mesh::SetNodeOnFace (const Handle(SMDS_MeshNode)& aNode,
280                                   const TopoDS_Face& S) 
281 {
282   if (myShape.IsNull()) 
283     Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnFace");
284   
285   Standard_Integer Index = myIndexToShape.FindIndex(S);
286   
287   //Set Position on Node
288   Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (Index,0.,0.);;
289   aNode->SetPosition(aPos);
290   
291   //Update or build submesh
292   if (!myShapeIndexToSubMesh.IsBound(Index)) {
293     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
294     myShapeIndexToSubMesh.Bind(Index,SM);
295   }
296   myShapeIndexToSubMesh(Index)->AddNode (aNode);
297 }
298
299 //=======================================================================
300 //function : SetNodeOnEdge
301 //purpose  : 
302 //=======================================================================
303 void SMESHDS_Mesh::SetNodeOnEdge (const Handle(SMDS_MeshNode)& aNode,
304                                   const TopoDS_Edge& S) 
305 {
306   if (myShape.IsNull()) 
307     Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnEdge");
308   
309   Standard_Integer Index = myIndexToShape.FindIndex(S);
310   
311   //Set Position on Node
312   Handle (SMDS_EdgePosition) aPos = new SMDS_EdgePosition (Index,0.);;
313   aNode->SetPosition(aPos);
314   
315   //Update or build submesh
316   if (!myShapeIndexToSubMesh.IsBound(Index)) {
317     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
318     myShapeIndexToSubMesh.Bind(Index,SM);
319   }
320   myShapeIndexToSubMesh(Index)->AddNode (aNode);
321   
322 }
323
324 //=======================================================================
325 //function : SetNodeOnVertex
326 //purpose  : 
327 //=======================================================================
328 void SMESHDS_Mesh::SetNodeOnVertex (const Handle(SMDS_MeshNode)& aNode,
329                                     const TopoDS_Vertex& S) 
330
331   if (myShape.IsNull()) 
332     Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVertex");
333   
334   Standard_Integer Index = myIndexToShape.FindIndex(S);
335   
336   //Set Position on Node
337   Handle (SMDS_VertexPosition) aPos = new SMDS_VertexPosition (Index);;
338   aNode->SetPosition(aPos);
339   
340   //Update or build submesh
341   if (!myShapeIndexToSubMesh.IsBound(Index)) {
342     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
343     myShapeIndexToSubMesh.Bind(Index,SM);
344   }
345   myShapeIndexToSubMesh(Index)->AddNode (aNode);
346 }
347
348
349 //=======================================================================
350 //function : UnSetNodeOnShape
351 //purpose  : 
352 //=======================================================================
353 void SMESHDS_Mesh::UnSetNodeOnShape(const Handle(SMDS_MeshNode)& aNode) 
354
355   MESSAGE("not implemented");
356 }
357
358
359 //=======================================================================
360 //function : SetMeshElementOnShape
361 //purpose  : 
362 //=======================================================================
363 void SMESHDS_Mesh::SetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
364                                            const TopoDS_Shape& S) 
365 {
366   if (myShape.IsNull()) 
367     Standard_NullObject::Raise("SMESHDS_Mesh::SetMeshElementOnShape");
368   
369   Standard_Integer Index = myIndexToShape.FindIndex(S);
370   
371
372   if (!myShapeIndexToSubMesh.IsBound(Index)) {
373     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
374     myShapeIndexToSubMesh.Bind(Index,SM);
375   }
376   myShapeIndexToSubMesh(Index)->AddElement (anElement);
377 }
378
379 //=======================================================================
380 //function : UnSetMeshElementOnShape
381 //purpose  : 
382 //=======================================================================
383 void SMESHDS_Mesh::UnSetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
384                                              const TopoDS_Shape& S)
385   
386 {
387   if (myShape.IsNull()) 
388     Standard_NullObject::Raise("SMESHDS_Mesh::UnSetMeshElementOnShape");
389   
390   Standard_Integer Index = myIndexToShape.FindIndex(S);
391
392   if (myShapeIndexToSubMesh.IsBound(Index)) 
393     myShapeIndexToSubMesh(Index)->RemoveElement (anElement);
394 }
395
396 //=======================================================================
397 //function : ShapeToMesh
398 //purpose  : 
399 //=======================================================================
400 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() 
401 {
402   return myShape;
403 }
404
405 //=======================================================================
406 //function : MeshElements
407 //purpose  : 
408 //=======================================================================
409 Handle_SMESHDS_SubMesh SMESHDS_Mesh::MeshElements(const TopoDS_Shape& S) 
410 {
411   if (myShape.IsNull()) 
412     Standard_NullObject::Raise("SMESHDS_Mesh::MeshElements");
413   
414   Standard_Integer Index = myIndexToShape.FindIndex(S);
415
416   if (myShapeIndexToSubMesh.IsBound(Index)) 
417     return myShapeIndexToSubMesh(Index);
418   Handle(SMESHDS_SubMesh) SM;
419   return SM;
420 }
421
422 //=======================================================================
423 //function : GetHypothesis
424 //purpose  : 
425 //=======================================================================
426 const SMESHDS_ListOfPtrHypothesis&  SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape& S) 
427 {
428   if (myShapeToHypothesis.IsBound(S))
429     return myShapeToHypothesis(S);
430  
431   static SMESHDS_ListOfPtrHypothesis empty;
432   return empty;
433 }
434
435 //=======================================================================
436 //function : GetScript
437 //purpose  : 
438 //=======================================================================
439 const Handle (SMESHDS_Script)&  SMESHDS_Mesh::GetScript() 
440 {
441   return myScript;
442 }
443
444 //=======================================================================
445 //function : ClearScript
446 //purpose  : 
447 //=======================================================================
448 void SMESHDS_Mesh::ClearScript() 
449 {
450   myScript->Clear();
451 }
452
453 //=======================================================================
454 //function : HasMeshElements
455 //purpose  : 
456 //=======================================================================
457 Standard_Boolean SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape& S) 
458 {
459   if (myShape.IsNull()) 
460     Standard_NullObject::Raise("SMESHDS_Mesh::MeshElements");
461   
462   Standard_Integer Index = myIndexToShape.FindIndex(S);
463
464   return myShapeIndexToSubMesh.IsBound(Index);
465 }
466
467 //=======================================================================
468 //function : HasHypothesis
469 //purpose  : 
470 //=======================================================================
471 Standard_Boolean SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape& S) 
472 {
473   return myShapeToHypothesis.IsBound(S);
474 }
475
476 //=======================================================================
477 //function : NewSubMesh 
478 //purpose  : 
479 //=======================================================================
480 void SMESHDS_Mesh::NewSubMesh(const Standard_Integer Index) 
481 {
482   if (!myShapeIndexToSubMesh.IsBound(Index)) {
483     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
484     myShapeIndexToSubMesh.Bind(Index,SM);
485   }
486 }
487
488 //=======================================================================
489 //function : IndexToShape
490 //purpose  : 
491 //=======================================================================
492 TopoDS_Shape SMESHDS_Mesh::IndexToShape(const Standard_Integer ShapeIndex)
493 {
494   return  myIndexToShape.FindKey(ShapeIndex);
495
496
497 //=======================================================================
498 //function : ShapeToIndex
499 //purpose  : 
500 //=======================================================================
501 Standard_Integer SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape& S) 
502 {
503   if (myShape.IsNull()) 
504     Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVolume");
505   
506   return  myIndexToShape.FindIndex(S);
507 }
508
509 //=======================================================================
510 //function : SetNodeOnVolume
511 //purpose  : 
512 //=======================================================================
513 void SMESHDS_Mesh::SetNodeInVolume (const Handle(SMDS_MeshNode)& aNode,
514                                     const Standard_Integer Index) 
515 {
516   
517   //Set Position on Node
518   //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
519   //aNode->SetPosition(aPos);
520   
521   //Update or build submesh
522   if (!myShapeIndexToSubMesh.IsBound(Index)) {
523     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
524     myShapeIndexToSubMesh.Bind(Index,SM);
525   }
526   myShapeIndexToSubMesh(Index)->AddNode (aNode);
527 }
528
529 //=======================================================================
530 //function : SetNodeOnFace
531 //purpose  : 
532 //=======================================================================
533 void SMESHDS_Mesh::SetNodeOnFace (const Handle(SMDS_MeshNode)& aNode,
534                                   const Standard_Integer Index) 
535 {
536   
537   //Set Position on Node
538   Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (Index,0.,0.);;
539   aNode->SetPosition(aPos);
540   
541   //Update or build submesh
542   if (!myShapeIndexToSubMesh.IsBound(Index)) {
543     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
544     myShapeIndexToSubMesh.Bind(Index,SM);
545   }
546   myShapeIndexToSubMesh(Index)->AddNode (aNode);
547 }
548
549 //=======================================================================
550 //function : SetNodeOnEdge
551 //purpose  : 
552 //=======================================================================
553 void SMESHDS_Mesh::SetNodeOnEdge (const Handle(SMDS_MeshNode)& aNode,
554                                   const Standard_Integer Index) 
555 {
556   
557   //Set Position on Node
558   Handle (SMDS_EdgePosition) aPos = new SMDS_EdgePosition (Index,0.);;
559   aNode->SetPosition(aPos);
560   
561   //Update or build submesh
562   if (!myShapeIndexToSubMesh.IsBound(Index)) {
563     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
564     myShapeIndexToSubMesh.Bind(Index,SM);
565   }
566   myShapeIndexToSubMesh(Index)->AddNode (aNode);
567   
568 }
569
570 //=======================================================================
571 //function : SetNodeOnVertex
572 //purpose  : 
573 //=======================================================================
574 void SMESHDS_Mesh::SetNodeOnVertex (const Handle(SMDS_MeshNode)& aNode,
575                                     const Standard_Integer Index) 
576
577   //Set Position on Node
578   Handle (SMDS_VertexPosition) aPos = new SMDS_VertexPosition (Index);;
579   aNode->SetPosition(aPos);
580   
581   //Update or build submesh
582   if (!myShapeIndexToSubMesh.IsBound(Index)) {
583     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
584     myShapeIndexToSubMesh.Bind(Index,SM);
585   }
586   myShapeIndexToSubMesh(Index)->AddNode (aNode);
587 }
588
589 //=======================================================================
590 //function : SetMeshElementOnShape
591 //purpose  : 
592 //=======================================================================
593 void SMESHDS_Mesh::SetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
594                                           const Standard_Integer Index) 
595 {
596   if (!myShapeIndexToSubMesh.IsBound(Index)) {
597     Handle(SMESHDS_SubMesh) SM = new  SMESHDS_SubMesh (this);
598     myShapeIndexToSubMesh.Bind(Index,SM);
599   }
600   myShapeIndexToSubMesh(Index)->AddElement (anElement);
601 }