1 // SMESH SMESHDS : management of mesh data and SMESH document
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Mesh.cxx
25 // Author : Yves FRICAUD, OCC
30 #include "SMESHDS_Mesh.ixx"
31 #include "SMESHDS_Hypothesis.hxx"
32 #include "SMESHDS_DataMapOfShapeListOfPtrHypothesis.hxx"
33 #include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
34 #include "SMDS_VertexPosition.hxx"
35 #include "SMDS_EdgePosition.hxx"
36 #include "SMDS_FacePosition.hxx"
37 #include <TopExp_Explorer.hxx>
40 #include <Standard_NullObject.hxx>
41 #include "utilities.h"
43 //=======================================================================
46 //=======================================================================
47 SMESHDS_Mesh::SMESHDS_Mesh(const Standard_Integer MeshID) : myMeshID( MeshID)
49 myScript = new SMESHDS_Script();
52 //=======================================================================
53 //function : ShapeToMesh
55 //=======================================================================
56 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape& S)
59 TopExp::MapShapes(myShape,myIndexToShape);
63 //=======================================================================
64 //function : AddHypothesis
66 //=======================================================================
68 Standard_Boolean SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape& SS,
69 const SMESHDS_PtrHypothesis& H)
71 if (!myShapeToHypothesis.IsBound(SS)){
72 SMESHDS_ListOfPtrHypothesis empty;
73 myShapeToHypothesis.Bind(SS,empty);
76 //Check if the Hypothesis is still present
77 SMESHDS_ListOfPtrHypothesis& Hypos = myShapeToHypothesis.ChangeFind (SS);
79 for (SMESHDS_ListIteratorOfListOfPtrHypothesis it(Hypos); it.More(); it.Next()) {
80 if (H == it.Value()) {
81 return Standard_False;
85 myShapeToHypothesis(SS).Append(H);
89 //=======================================================================
90 //function : RemoveHypothesis
92 //=======================================================================
94 Standard_Boolean SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape& S,
95 const SMESHDS_PtrHypothesis& H)
97 if (myShapeToHypothesis.IsBound(S)){
98 SMESHDS_ListOfPtrHypothesis& Hypos = myShapeToHypothesis.ChangeFind (S);
99 for (SMESHDS_ListIteratorOfListOfPtrHypothesis it(Hypos); it.More(); it.Next()) {
100 if (H == it.Value()) {
102 return Standard_True;
106 return Standard_False;
110 //=======================================================================
113 //=======================================================================
114 Standard_Integer SMESHDS_Mesh::AddNode(const Standard_Real x,
115 const Standard_Real y,
116 const Standard_Real z)
118 Standard_Integer NodeID = SMDS_Mesh::AddNode(x,y,z);
119 myScript->AddNode(NodeID,x,y,z);
123 //=======================================================================
124 //function : MoveNode
126 //=======================================================================
127 void SMESHDS_Mesh::MoveNode(const Standard_Integer ID,
128 const Standard_Real x,
129 const Standard_Real y,
130 const Standard_Real z)
133 Handle(SMDS_MeshNode) Node = Handle(SMDS_MeshNode)::DownCast(FindNode(ID));
136 myScript->MoveNode(ID,x,y,z);
141 //=======================================================================
144 //=======================================================================
145 Standard_Integer SMESHDS_Mesh::AddEdge(const Standard_Integer idnode1,
146 const Standard_Integer idnode2)
148 Standard_Integer ID = SMDS_Mesh::AddEdge(idnode1,idnode2);
149 myScript->AddEdge (ID,idnode1,idnode2);
154 //=======================================================================
157 //=======================================================================
158 Standard_Integer SMESHDS_Mesh::AddFace(const Standard_Integer idnode1,
159 const Standard_Integer idnode2,
160 const Standard_Integer idnode3)
162 Standard_Integer ID = SMDS_Mesh::AddFace(idnode1,idnode2,idnode3);
163 myScript->AddFace (ID,idnode1,idnode2,idnode3);
167 //=======================================================================
170 //=======================================================================
171 Standard_Integer SMESHDS_Mesh::AddFace(const Standard_Integer idnode1,
172 const Standard_Integer idnode2,
173 const Standard_Integer idnode3,
174 const Standard_Integer idnode4)
176 Standard_Integer ID = SMDS_Mesh::AddFace(idnode1,idnode2,idnode3,idnode4);
177 myScript->AddFace (ID,idnode1,idnode2,idnode3,idnode4);
182 //=======================================================================
183 //function :AddVolume
185 //=======================================================================
186 Standard_Integer SMESHDS_Mesh::AddVolume(const Standard_Integer idnode1,
187 const Standard_Integer idnode2,
188 const Standard_Integer idnode3,
189 const Standard_Integer idnode4)
191 Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4);
192 myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4);
197 //=======================================================================
198 //function :AddVolume
200 //=======================================================================
201 Standard_Integer SMESHDS_Mesh::AddVolume(const Standard_Integer idnode1,
202 const Standard_Integer idnode2,
203 const Standard_Integer idnode3,
204 const Standard_Integer idnode4,
205 const Standard_Integer idnode5)
207 Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4,idnode5);
208 myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4,idnode5);
213 //=======================================================================
214 //function :AddVolume
216 //=======================================================================
217 Standard_Integer SMESHDS_Mesh::AddVolume(const Standard_Integer idnode1,
218 const Standard_Integer idnode2,
219 const Standard_Integer idnode3,
220 const Standard_Integer idnode4,
221 const Standard_Integer idnode5,
222 const Standard_Integer idnode6)
224 Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
225 myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
229 //=======================================================================
230 //function :AddVolume
232 //=======================================================================
233 Standard_Integer SMESHDS_Mesh::AddVolume(const Standard_Integer idnode1,
234 const Standard_Integer idnode2,
235 const Standard_Integer idnode3,
236 const Standard_Integer idnode4,
237 const Standard_Integer idnode5,
238 const Standard_Integer idnode6,
239 const Standard_Integer idnode7,
240 const Standard_Integer idnode8)
242 Standard_Integer ID = SMDS_Mesh::AddVolume(idnode1,idnode2,idnode3,idnode4,idnode5,idnode6,idnode7,idnode8);
243 myScript->AddVolume (ID,idnode1,idnode2,idnode3,idnode4,idnode5,idnode6,idnode7,idnode8);
248 //=======================================================================
249 //function : RemoveNode
251 //=======================================================================
252 void SMESHDS_Mesh::RemoveNode(const Standard_Integer ID)
254 SMDS_Mesh::RemoveNode (ID);
255 myScript->RemoveNode (ID);
260 //=======================================================================
261 //function : RemoveElement
263 //========================================================================
264 void SMESHDS_Mesh::RemoveElement(const Standard_Integer ID)
266 SMDS_Mesh::RemoveElement (ID);
267 myScript->RemoveElement (ID);
270 //=======================================================================
271 //function : SetNodeOnVolume
273 //=======================================================================
274 void SMESHDS_Mesh::SetNodeInVolume (const Handle(SMDS_MeshNode)& aNode,
275 const TopoDS_Shell& S)
277 if (myShape.IsNull())
278 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVolume");
280 Standard_Integer Index = myIndexToShape.FindIndex(S);
282 //Set Position on Node
283 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
284 //aNode->SetPosition(aPos);
286 //Update or build submesh
287 if (!myShapeIndexToSubMesh.IsBound(Index)) {
288 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
289 myShapeIndexToSubMesh.Bind(Index,SM);
291 myShapeIndexToSubMesh(Index)->AddNode (aNode);
294 //=======================================================================
295 //function : SetNodeOnFace
297 //=======================================================================
298 void SMESHDS_Mesh::SetNodeOnFace (const Handle(SMDS_MeshNode)& aNode,
299 const TopoDS_Face& S)
301 if (myShape.IsNull())
302 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnFace");
304 Standard_Integer Index = myIndexToShape.FindIndex(S);
306 //Set Position on Node
307 Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (Index,0.,0.);;
308 aNode->SetPosition(aPos);
310 //Update or build submesh
311 if (!myShapeIndexToSubMesh.IsBound(Index)) {
312 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
313 myShapeIndexToSubMesh.Bind(Index,SM);
315 myShapeIndexToSubMesh(Index)->AddNode (aNode);
318 //=======================================================================
319 //function : SetNodeOnEdge
321 //=======================================================================
322 void SMESHDS_Mesh::SetNodeOnEdge (const Handle(SMDS_MeshNode)& aNode,
323 const TopoDS_Edge& S)
325 if (myShape.IsNull())
326 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnEdge");
328 Standard_Integer Index = myIndexToShape.FindIndex(S);
330 //Set Position on Node
331 Handle (SMDS_EdgePosition) aPos = new SMDS_EdgePosition (Index,0.);;
332 aNode->SetPosition(aPos);
334 //Update or build submesh
335 if (!myShapeIndexToSubMesh.IsBound(Index)) {
336 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
337 myShapeIndexToSubMesh.Bind(Index,SM);
339 myShapeIndexToSubMesh(Index)->AddNode (aNode);
343 //=======================================================================
344 //function : SetNodeOnVertex
346 //=======================================================================
347 void SMESHDS_Mesh::SetNodeOnVertex (const Handle(SMDS_MeshNode)& aNode,
348 const TopoDS_Vertex& S)
350 if (myShape.IsNull())
351 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVertex");
353 Standard_Integer Index = myIndexToShape.FindIndex(S);
355 //Set Position on Node
356 Handle (SMDS_VertexPosition) aPos = new SMDS_VertexPosition (Index);;
357 aNode->SetPosition(aPos);
359 //Update or build submesh
360 if (!myShapeIndexToSubMesh.IsBound(Index)) {
361 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
362 myShapeIndexToSubMesh.Bind(Index,SM);
364 myShapeIndexToSubMesh(Index)->AddNode (aNode);
368 //=======================================================================
369 //function : UnSetNodeOnShape
371 //=======================================================================
372 void SMESHDS_Mesh::UnSetNodeOnShape(const Handle(SMDS_MeshNode)& aNode)
374 MESSAGE("not implemented");
378 //=======================================================================
379 //function : SetMeshElementOnShape
381 //=======================================================================
382 void SMESHDS_Mesh::SetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
383 const TopoDS_Shape& S)
385 if (myShape.IsNull())
386 Standard_NullObject::Raise("SMESHDS_Mesh::SetMeshElementOnShape");
388 Standard_Integer Index = myIndexToShape.FindIndex(S);
391 if (!myShapeIndexToSubMesh.IsBound(Index)) {
392 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
393 myShapeIndexToSubMesh.Bind(Index,SM);
395 myShapeIndexToSubMesh(Index)->AddElement (anElement);
398 //=======================================================================
399 //function : UnSetMeshElementOnShape
401 //=======================================================================
402 void SMESHDS_Mesh::UnSetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
403 const TopoDS_Shape& S)
406 if (myShape.IsNull())
407 Standard_NullObject::Raise("SMESHDS_Mesh::UnSetMeshElementOnShape");
409 Standard_Integer Index = myIndexToShape.FindIndex(S);
411 if (myShapeIndexToSubMesh.IsBound(Index))
412 myShapeIndexToSubMesh(Index)->RemoveElement (anElement);
415 //=======================================================================
416 //function : ShapeToMesh
418 //=======================================================================
419 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh()
424 //=======================================================================
425 //function : MeshElements
427 //=======================================================================
428 Handle_SMESHDS_SubMesh SMESHDS_Mesh::MeshElements(const TopoDS_Shape& S)
430 if (myShape.IsNull())
431 Standard_NullObject::Raise("SMESHDS_Mesh::MeshElements");
433 Standard_Integer Index = myIndexToShape.FindIndex(S);
435 if (myShapeIndexToSubMesh.IsBound(Index))
436 return myShapeIndexToSubMesh(Index);
437 Handle(SMESHDS_SubMesh) SM;
441 //=======================================================================
442 //function : GetHypothesis
444 //=======================================================================
445 const SMESHDS_ListOfPtrHypothesis& SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape& S)
447 if (myShapeToHypothesis.IsBound(S))
448 return myShapeToHypothesis(S);
450 static SMESHDS_ListOfPtrHypothesis empty;
454 //=======================================================================
455 //function : GetScript
457 //=======================================================================
458 const Handle (SMESHDS_Script)& SMESHDS_Mesh::GetScript()
463 //=======================================================================
464 //function : ClearScript
466 //=======================================================================
467 void SMESHDS_Mesh::ClearScript()
472 //=======================================================================
473 //function : HasMeshElements
475 //=======================================================================
476 Standard_Boolean SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape& S)
478 if (myShape.IsNull())
479 Standard_NullObject::Raise("SMESHDS_Mesh::MeshElements");
481 Standard_Integer Index = myIndexToShape.FindIndex(S);
483 return myShapeIndexToSubMesh.IsBound(Index);
486 //=======================================================================
487 //function : HasHypothesis
489 //=======================================================================
490 Standard_Boolean SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape& S)
492 return myShapeToHypothesis.IsBound(S);
495 //=======================================================================
496 //function : NewSubMesh
498 //=======================================================================
499 void SMESHDS_Mesh::NewSubMesh(const Standard_Integer Index)
501 if (!myShapeIndexToSubMesh.IsBound(Index)) {
502 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
503 myShapeIndexToSubMesh.Bind(Index,SM);
507 //=======================================================================
508 //function : IndexToShape
510 //=======================================================================
511 TopoDS_Shape SMESHDS_Mesh::IndexToShape(const Standard_Integer ShapeIndex)
513 return myIndexToShape.FindKey(ShapeIndex);
516 //=======================================================================
517 //function : ShapeToIndex
519 //=======================================================================
520 Standard_Integer SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape& S)
522 if (myShape.IsNull())
523 Standard_NullObject::Raise("SMESHDS_Mesh::SetNodeOnVolume");
525 return myIndexToShape.FindIndex(S);
528 //=======================================================================
529 //function : SetNodeOnVolume
531 //=======================================================================
532 void SMESHDS_Mesh::SetNodeInVolume (const Handle(SMDS_MeshNode)& aNode,
533 const Standard_Integer Index)
536 //Set Position on Node
537 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
538 //aNode->SetPosition(aPos);
540 //Update or build submesh
541 if (!myShapeIndexToSubMesh.IsBound(Index)) {
542 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
543 myShapeIndexToSubMesh.Bind(Index,SM);
545 myShapeIndexToSubMesh(Index)->AddNode (aNode);
548 //=======================================================================
549 //function : SetNodeOnFace
551 //=======================================================================
552 void SMESHDS_Mesh::SetNodeOnFace (const Handle(SMDS_MeshNode)& aNode,
553 const Standard_Integer Index)
556 //Set Position on Node
557 Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (Index,0.,0.);;
558 aNode->SetPosition(aPos);
560 //Update or build submesh
561 if (!myShapeIndexToSubMesh.IsBound(Index)) {
562 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
563 myShapeIndexToSubMesh.Bind(Index,SM);
565 myShapeIndexToSubMesh(Index)->AddNode (aNode);
568 //=======================================================================
569 //function : SetNodeOnEdge
571 //=======================================================================
572 void SMESHDS_Mesh::SetNodeOnEdge (const Handle(SMDS_MeshNode)& aNode,
573 const Standard_Integer Index)
576 //Set Position on Node
577 Handle (SMDS_EdgePosition) aPos = new SMDS_EdgePosition (Index,0.);;
578 aNode->SetPosition(aPos);
580 //Update or build submesh
581 if (!myShapeIndexToSubMesh.IsBound(Index)) {
582 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
583 myShapeIndexToSubMesh.Bind(Index,SM);
585 myShapeIndexToSubMesh(Index)->AddNode (aNode);
589 //=======================================================================
590 //function : SetNodeOnVertex
592 //=======================================================================
593 void SMESHDS_Mesh::SetNodeOnVertex (const Handle(SMDS_MeshNode)& aNode,
594 const Standard_Integer Index)
596 //Set Position on Node
597 Handle (SMDS_VertexPosition) aPos = new SMDS_VertexPosition (Index);;
598 aNode->SetPosition(aPos);
600 //Update or build submesh
601 if (!myShapeIndexToSubMesh.IsBound(Index)) {
602 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
603 myShapeIndexToSubMesh.Bind(Index,SM);
605 myShapeIndexToSubMesh(Index)->AddNode (aNode);
608 //=======================================================================
609 //function : SetMeshElementOnShape
611 //=======================================================================
612 void SMESHDS_Mesh::SetMeshElementOnShape (const Handle(SMDS_MeshElement)& anElement,
613 const Standard_Integer Index)
615 if (!myShapeIndexToSubMesh.IsBound(Index)) {
616 Handle(SMESHDS_SubMesh) SM = new SMESHDS_SubMesh (this);
617 myShapeIndexToSubMesh.Bind(Index,SM);
619 myShapeIndexToSubMesh(Index)->AddElement (anElement);