2 //=============================================================================
3 // File : SMESH_Mesh.cxx
5 // Author : Yves FRICAUD, OCC
7 // Copyright : OCC 2002
9 //=============================================================================
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>
21 #include <Standard_NullObject.hxx>
22 #include "utilities.h"
24 //=======================================================================
27 //=======================================================================
28 SMESHDS_Mesh::SMESHDS_Mesh(const Standard_Integer MeshID) : myMeshID( MeshID)
30 myScript = new SMESHDS_Script();
33 //=======================================================================
34 //function : ShapeToMesh
36 //=======================================================================
37 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape& S)
40 TopExp::MapShapes(myShape,myIndexToShape);
44 //=======================================================================
45 //function : AddHypothesis
47 //=======================================================================
49 Standard_Boolean SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape& SS,
50 const SMESHDS_PtrHypothesis& H)
52 if (!myShapeToHypothesis.IsBound(SS)){
53 SMESHDS_ListOfPtrHypothesis empty;
54 myShapeToHypothesis.Bind(SS,empty);
57 //Check if the Hypothesis is still present
58 SMESHDS_ListOfPtrHypothesis& Hypos = myShapeToHypothesis.ChangeFind (SS);
60 for (SMESHDS_ListIteratorOfListOfPtrHypothesis it(Hypos); it.More(); it.Next()) {
61 if (H == it.Value()) {
62 return Standard_False;
66 myShapeToHypothesis(SS).Append(H);
70 //=======================================================================
71 //function : RemoveHypothesis
73 //=======================================================================
75 Standard_Boolean SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape& S,
76 const SMESHDS_PtrHypothesis& H)
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()) {
87 return Standard_False;
91 //=======================================================================
94 //=======================================================================
95 Standard_Integer SMESHDS_Mesh::AddNode(const Standard_Real x,
96 const Standard_Real y,
97 const Standard_Real z)
99 Standard_Integer NodeID = SMDS_Mesh::AddNode(x,y,z);
100 myScript->AddNode(NodeID,x,y,z);
104 //=======================================================================
105 //function : MoveNode
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)
114 Handle(SMDS_MeshNode) Node = Handle(SMDS_MeshNode)::DownCast(FindNode(ID));
117 myScript->MoveNode(ID,x,y,z);
122 //=======================================================================
125 //=======================================================================
126 Standard_Integer SMESHDS_Mesh::AddEdge(const Standard_Integer idnode1,
127 const Standard_Integer idnode2)
129 Standard_Integer ID = SMDS_Mesh::AddEdge(idnode1,idnode2);
130 myScript->AddEdge (ID,idnode1,idnode2);
135 //=======================================================================
138 //=======================================================================
139 Standard_Integer SMESHDS_Mesh::AddFace(const Standard_Integer idnode1,
140 const Standard_Integer idnode2,
141 const Standard_Integer idnode3)
143 Standard_Integer ID = SMDS_Mesh::AddFace(idnode1,idnode2,idnode3);
144 myScript->AddFace (ID,idnode1,idnode2,idnode3);
148 //=======================================================================
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)
157 Standard_Integer ID = SMDS_Mesh::AddFace(idnode1,idnode2,idnode3,idnode4);
158 myScript->AddFace (ID,idnode1,idnode2,idnode3,idnode4);
163 //=======================================================================
164 //function :AddVolume
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)
172 Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4);
173 myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4);
178 //=======================================================================
179 //function :AddVolume
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)
188 Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4,idnode5);
189 myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4,idnode5);
194 //=======================================================================
195 //function :AddVolume
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)
205 Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
206 myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
210 //=======================================================================
211 //function :AddVolume
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)
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);
229 //=======================================================================
230 //function : RemoveNode
232 //=======================================================================
233 void SMESHDS_Mesh::RemoveNode(const Standard_Integer ID)
235 SMDS_Mesh::RemoveNode (ID);
236 myScript->RemoveNode (ID);
241 //=======================================================================
242 //function : RemoveElement
244 //========================================================================
245 void SMESHDS_Mesh::RemoveElement(const Standard_Integer ID)
247 SMDS_Mesh::RemoveElement (ID);
248 myScript->RemoveElement (ID);
251 //=======================================================================
252 //function : SetNodeOnVolume
254 //=======================================================================
255 void SMESHDS_Mesh::SetNodeInVolume (const Handle(SMDS_MeshNode)& aNode,
256 const TopoDS_Shell& S)
258 if (myShape.IsNull())
259 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVolume");
261 Standard_Integer Index = myIndexToShape.FindIndex(S);
263 //Set Position on Node
264 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
265 //aNode->SetPosition(aPos);
267 //Update or build submesh
268 if (!myShapeIndexToSubMesh.IsBound(Index)) {
269 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
270 myShapeIndexToSubMesh.Bind(Index,SM);
272 myShapeIndexToSubMesh(Index)->AddNode (aNode);
275 //=======================================================================
276 //function : SetNodeOnFace
278 //=======================================================================
279 void SMESHDS_Mesh::SetNodeOnFace (const Handle(SMDS_MeshNode)& aNode,
280 const TopoDS_Face& S)
282 if (myShape.IsNull())
283 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnFace");
285 Standard_Integer Index = myIndexToShape.FindIndex(S);
287 //Set Position on Node
288 Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (Index,0.,0.);;
289 aNode->SetPosition(aPos);
291 //Update or build submesh
292 if (!myShapeIndexToSubMesh.IsBound(Index)) {
293 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
294 myShapeIndexToSubMesh.Bind(Index,SM);
296 myShapeIndexToSubMesh(Index)->AddNode (aNode);
299 //=======================================================================
300 //function : SetNodeOnEdge
302 //=======================================================================
303 void SMESHDS_Mesh::SetNodeOnEdge (const Handle(SMDS_MeshNode)& aNode,
304 const TopoDS_Edge& S)
306 if (myShape.IsNull())
307 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnEdge");
309 Standard_Integer Index = myIndexToShape.FindIndex(S);
311 //Set Position on Node
312 Handle (SMDS_EdgePosition) aPos = new SMDS_EdgePosition (Index,0.);;
313 aNode->SetPosition(aPos);
315 //Update or build submesh
316 if (!myShapeIndexToSubMesh.IsBound(Index)) {
317 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
318 myShapeIndexToSubMesh.Bind(Index,SM);
320 myShapeIndexToSubMesh(Index)->AddNode (aNode);
324 //=======================================================================
325 //function : SetNodeOnVertex
327 //=======================================================================
328 void SMESHDS_Mesh::SetNodeOnVertex (const Handle(SMDS_MeshNode)& aNode,
329 const TopoDS_Vertex& S)
331 if (myShape.IsNull())
332 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVertex");
334 Standard_Integer Index = myIndexToShape.FindIndex(S);
336 //Set Position on Node
337 Handle (SMDS_VertexPosition) aPos = new SMDS_VertexPosition (Index);;
338 aNode->SetPosition(aPos);
340 //Update or build submesh
341 if (!myShapeIndexToSubMesh.IsBound(Index)) {
342 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
343 myShapeIndexToSubMesh.Bind(Index,SM);
345 myShapeIndexToSubMesh(Index)->AddNode (aNode);
349 //=======================================================================
350 //function : UnSetNodeOnShape
352 //=======================================================================
353 void SMESHDS_Mesh::UnSetNodeOnShape(const Handle(SMDS_MeshNode)& aNode)
355 MESSAGE("not implemented");
359 //=======================================================================
360 //function : SetMeshElementOnShape
362 //=======================================================================
363 void SMESHDS_Mesh::SetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
364 const TopoDS_Shape& S)
366 if (myShape.IsNull())
367 Standard_NullObject::Raise("SMESHDS_Mesh::SetMeshElementOnShape");
369 Standard_Integer Index = myIndexToShape.FindIndex(S);
372 if (!myShapeIndexToSubMesh.IsBound(Index)) {
373 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
374 myShapeIndexToSubMesh.Bind(Index,SM);
376 myShapeIndexToSubMesh(Index)->AddElement (anElement);
379 //=======================================================================
380 //function : UnSetMeshElementOnShape
382 //=======================================================================
383 void SMESHDS_Mesh::UnSetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
384 const TopoDS_Shape& S)
387 if (myShape.IsNull())
388 Standard_NullObject::Raise("SMESHDS_Mesh::UnSetMeshElementOnShape");
390 Standard_Integer Index = myIndexToShape.FindIndex(S);
392 if (myShapeIndexToSubMesh.IsBound(Index))
393 myShapeIndexToSubMesh(Index)->RemoveElement (anElement);
396 //=======================================================================
397 //function : ShapeToMesh
399 //=======================================================================
400 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh()
405 //=======================================================================
406 //function : MeshElements
408 //=======================================================================
409 Handle_SMESHDS_SubMesh SMESHDS_Mesh::MeshElements(const TopoDS_Shape& S)
411 if (myShape.IsNull())
412 Standard_NullObject::Raise("SMESHDS_Mesh::MeshElements");
414 Standard_Integer Index = myIndexToShape.FindIndex(S);
416 if (myShapeIndexToSubMesh.IsBound(Index))
417 return myShapeIndexToSubMesh(Index);
418 Handle(SMESHDS_SubMesh) SM;
422 //=======================================================================
423 //function : GetHypothesis
425 //=======================================================================
426 const SMESHDS_ListOfPtrHypothesis& SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape& S)
428 if (myShapeToHypothesis.IsBound(S))
429 return myShapeToHypothesis(S);
431 static SMESHDS_ListOfPtrHypothesis empty;
435 //=======================================================================
436 //function : GetScript
438 //=======================================================================
439 const Handle (SMESHDS_Script)& SMESHDS_Mesh::GetScript()
444 //=======================================================================
445 //function : ClearScript
447 //=======================================================================
448 void SMESHDS_Mesh::ClearScript()
453 //=======================================================================
454 //function : HasMeshElements
456 //=======================================================================
457 Standard_Boolean SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape& S)
459 if (myShape.IsNull())
460 Standard_NullObject::Raise("SMESHDS_Mesh::MeshElements");
462 Standard_Integer Index = myIndexToShape.FindIndex(S);
464 return myShapeIndexToSubMesh.IsBound(Index);
467 //=======================================================================
468 //function : HasHypothesis
470 //=======================================================================
471 Standard_Boolean SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape& S)
473 return myShapeToHypothesis.IsBound(S);
476 //=======================================================================
477 //function : NewSubMesh
479 //=======================================================================
480 void SMESHDS_Mesh::NewSubMesh(const Standard_Integer Index)
482 if (!myShapeIndexToSubMesh.IsBound(Index)) {
483 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
484 myShapeIndexToSubMesh.Bind(Index,SM);
488 //=======================================================================
489 //function : IndexToShape
491 //=======================================================================
492 TopoDS_Shape SMESHDS_Mesh::IndexToShape(const Standard_Integer ShapeIndex)
494 return myIndexToShape.FindKey(ShapeIndex);
497 //=======================================================================
498 //function : ShapeToIndex
500 //=======================================================================
501 Standard_Integer SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape& S)
503 if (myShape.IsNull())
504 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVolume");
506 return myIndexToShape.FindIndex(S);
509 //=======================================================================
510 //function : SetNodeOnVolume
512 //=======================================================================
513 void SMESHDS_Mesh::SetNodeInVolume (const Handle(SMDS_MeshNode)& aNode,
514 const Standard_Integer Index)
517 //Set Position on Node
518 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
519 //aNode->SetPosition(aPos);
521 //Update or build submesh
522 if (!myShapeIndexToSubMesh.IsBound(Index)) {
523 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
524 myShapeIndexToSubMesh.Bind(Index,SM);
526 myShapeIndexToSubMesh(Index)->AddNode (aNode);
529 //=======================================================================
530 //function : SetNodeOnFace
532 //=======================================================================
533 void SMESHDS_Mesh::SetNodeOnFace (const Handle(SMDS_MeshNode)& aNode,
534 const Standard_Integer Index)
537 //Set Position on Node
538 Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (Index,0.,0.);;
539 aNode->SetPosition(aPos);
541 //Update or build submesh
542 if (!myShapeIndexToSubMesh.IsBound(Index)) {
543 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
544 myShapeIndexToSubMesh.Bind(Index,SM);
546 myShapeIndexToSubMesh(Index)->AddNode (aNode);
549 //=======================================================================
550 //function : SetNodeOnEdge
552 //=======================================================================
553 void SMESHDS_Mesh::SetNodeOnEdge (const Handle(SMDS_MeshNode)& aNode,
554 const Standard_Integer Index)
557 //Set Position on Node
558 Handle (SMDS_EdgePosition) aPos = new SMDS_EdgePosition (Index,0.);;
559 aNode->SetPosition(aPos);
561 //Update or build submesh
562 if (!myShapeIndexToSubMesh.IsBound(Index)) {
563 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
564 myShapeIndexToSubMesh.Bind(Index,SM);
566 myShapeIndexToSubMesh(Index)->AddNode (aNode);
570 //=======================================================================
571 //function : SetNodeOnVertex
573 //=======================================================================
574 void SMESHDS_Mesh::SetNodeOnVertex (const Handle(SMDS_MeshNode)& aNode,
575 const Standard_Integer Index)
577 //Set Position on Node
578 Handle (SMDS_VertexPosition) aPos = new SMDS_VertexPosition (Index);;
579 aNode->SetPosition(aPos);
581 //Update or build submesh
582 if (!myShapeIndexToSubMesh.IsBound(Index)) {
583 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
584 myShapeIndexToSubMesh.Bind(Index,SM);
586 myShapeIndexToSubMesh(Index)->AddNode (aNode);
589 //=======================================================================
590 //function : SetMeshElementOnShape
592 //=======================================================================
593 void SMESHDS_Mesh::SetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
594 const Standard_Integer Index)
596 if (!myShapeIndexToSubMesh.IsBound(Index)) {
597 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
598 myShapeIndexToSubMesh.Bind(Index,SM);
600 myShapeIndexToSubMesh(Index)->AddElement (anElement);