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
29 #include "SMESHDS_Mesh.hxx"
31 #include "SMESHDS_Group.hxx"
32 #include "SMDS_VertexPosition.hxx"
33 #include "SMDS_EdgePosition.hxx"
34 #include "SMDS_FacePosition.hxx"
35 #include "SMESHDS_GroupOnGeom.hxx"
36 #include <TopExp_Explorer.hxx>
38 #include <TopoDS_Iterator.hxx>
40 #include "utilities.h"
44 /*Standard_Boolean IsEqual( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
46 return S1.IsSame( S2 );
49 //=======================================================================
52 //=======================================================================
53 SMESHDS_Mesh::SMESHDS_Mesh(int MeshID):myMeshID(MeshID)
55 myScript = new SMESHDS_Script();
58 //=======================================================================
59 //function : ShapeToMesh
61 //=======================================================================
62 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
64 if ( !myShape.IsNull() && S.IsNull() )
66 // removal of a shape to mesh, delete ...
68 myShapeToHypothesis.Clear();
69 // - shape indices in SMDS_Position of nodes
70 map<int,SMESHDS_SubMesh*>::iterator i_sub = myShapeIndexToSubMesh.begin();
71 for ( ; i_sub != myShapeIndexToSubMesh.end(); i_sub++ ) {
72 if ( !i_sub->second->IsComplexSubmesh() ) {
73 SMDS_NodeIteratorPtr nIt = i_sub->second->GetNodes();
75 nIt->next()->GetPosition()->SetShapeId( 0 );
79 myIndexToShape.Clear();
80 myShapeIndexToSubMesh.clear();
81 // - groups on geometry
82 set<SMESHDS_GroupBase*>::iterator gr = myGroups.begin();
83 while ( gr != myGroups.end() ) {
84 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( *gr ))
85 myGroups.erase( gr++ );
93 TopExp::MapShapes(myShape, myIndexToShape);
97 //=======================================================================
98 //function : AddHypothesis
100 //=======================================================================
102 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
103 const SMESHDS_Hypothesis * H)
105 //list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis[SS];
107 if ( !myShapeToHypothesis.IsBound( SS ) )
108 myShapeToHypothesis.Bind( SS, list<const SMESHDS_Hypothesis *>() );
110 list<const SMESHDS_Hypothesis *>& alist = myShapeToHypothesis.ChangeFind( SS );
114 //Check if the Hypothesis is still present
115 list<const SMESHDS_Hypothesis*>::iterator ith=alist.begin();
117 for (; ith!=alist.end(); ith++)
118 if (H == *ith) return false;
124 //=======================================================================
125 //function : RemoveHypothesis
127 //=======================================================================
129 bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S,
130 const SMESHDS_Hypothesis * H)
132 /*ShapeToHypothesis::iterator its=myShapeToHypothesis.find(S);
133 if(its!=myShapeToHypothesis.end())
135 list<const SMESHDS_Hypothesis*>::iterator ith=(*its).second.begin();
137 for (; ith!=(*its).second.end(); ith++)
140 (*its).second.erase(ith);
144 if ( myShapeToHypothesis.IsBound( S ) )
146 list<const SMESHDS_Hypothesis *>& alist = myShapeToHypothesis.ChangeFind( S );
147 list<const SMESHDS_Hypothesis*>::iterator ith = alist.begin();
149 for (; ith != alist.end(); ith++)
159 //=======================================================================
162 //=======================================================================
163 SMDS_MeshNode* SMESHDS_Mesh::AddNode(double x, double y, double z){
164 SMDS_MeshNode* node = SMDS_Mesh::AddNode(x, y, z);
165 if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
169 SMDS_MeshNode* SMESHDS_Mesh::AddNodeWithID(double x, double y, double z, int ID){
170 SMDS_MeshNode* node = SMDS_Mesh::AddNodeWithID(x,y,z,ID);
171 if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
175 //=======================================================================
176 //function : MoveNode
178 //=======================================================================
179 void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
181 SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
183 myScript->MoveNode(n->GetID(), x, y, z);
186 //=======================================================================
187 //function : ChangeElementNodes
189 //=======================================================================
191 bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
192 const SMDS_MeshNode * nodes[],
195 if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes ))
198 vector<int> IDs( nbnodes );
199 for ( int i = 0; i < nbnodes; i++ )
200 IDs [ i ] = nodes[ i ]->GetID();
201 myScript->ChangeElementNodes( elem->GetID(), &IDs[0], nbnodes);
206 //=======================================================================
207 //function : ChangePolygonNodes
209 //=======================================================================
210 bool SMESHDS_Mesh::ChangePolygonNodes
211 (const SMDS_MeshElement * elem,
212 vector<const SMDS_MeshNode*> nodes)
214 ASSERT(nodes.size() > 3);
216 return ChangeElementNodes(elem, &nodes[0], nodes.size());
219 //=======================================================================
220 //function : ChangePolyhedronNodes
222 //=======================================================================
223 bool SMESHDS_Mesh::ChangePolyhedronNodes
224 (const SMDS_MeshElement * elem,
225 std::vector<const SMDS_MeshNode*> nodes,
226 std::vector<int> quantities)
228 ASSERT(nodes.size() > 3);
230 if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
233 int i, len = nodes.size();
234 std::vector<int> nodes_ids (len);
235 for (i = 0; i < len; i++) {
236 nodes_ids[i] = nodes[i]->GetID();
238 myScript->ChangePolyhedronNodes(elem->GetID(), nodes_ids, quantities);
243 //=======================================================================
244 //function : Renumber
246 //=======================================================================
248 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
250 SMDS_Mesh::Renumber( isNodes, startID, deltaID );
251 myScript->Renumber( isNodes, startID, deltaID );
254 //=======================================================================
255 //function :AddEdgeWithID
257 //=======================================================================
258 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
260 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
261 if(anElem) myScript->AddEdge(ID,n1,n2);
265 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
266 const SMDS_MeshNode * n2,
269 return AddEdgeWithID(n1->GetID(),
274 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
275 const SMDS_MeshNode * n2)
277 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
278 if(anElem) myScript->AddEdge(anElem->GetID(),
284 //=======================================================================
287 //=======================================================================
288 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
290 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
291 if(anElem) myScript->AddFace(ID,n1,n2,n3);
295 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
296 const SMDS_MeshNode * n2,
297 const SMDS_MeshNode * n3,
300 return AddFaceWithID(n1->GetID(),
306 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
307 const SMDS_MeshNode * n2,
308 const SMDS_MeshNode * n3)
310 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
311 if(anElem) myScript->AddFace(anElem->GetID(),
318 //=======================================================================
321 //=======================================================================
322 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
324 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
325 if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
329 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
330 const SMDS_MeshNode * n2,
331 const SMDS_MeshNode * n3,
332 const SMDS_MeshNode * n4,
335 return AddFaceWithID(n1->GetID(),
342 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
343 const SMDS_MeshNode * n2,
344 const SMDS_MeshNode * n3,
345 const SMDS_MeshNode * n4)
347 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
348 if(anElem) myScript->AddFace(anElem->GetID(),
356 //=======================================================================
357 //function :AddVolume
359 //=======================================================================
360 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
362 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
363 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
367 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
368 const SMDS_MeshNode * n2,
369 const SMDS_MeshNode * n3,
370 const SMDS_MeshNode * n4,
373 return AddVolumeWithID(n1->GetID(),
380 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
381 const SMDS_MeshNode * n2,
382 const SMDS_MeshNode * n3,
383 const SMDS_MeshNode * n4)
385 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
386 if(anElem) myScript->AddVolume(anElem->GetID(),
394 //=======================================================================
395 //function :AddVolume
397 //=======================================================================
398 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
400 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
401 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
405 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
406 const SMDS_MeshNode * n2,
407 const SMDS_MeshNode * n3,
408 const SMDS_MeshNode * n4,
409 const SMDS_MeshNode * n5,
412 return AddVolumeWithID(n1->GetID(),
420 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
421 const SMDS_MeshNode * n2,
422 const SMDS_MeshNode * n3,
423 const SMDS_MeshNode * n4,
424 const SMDS_MeshNode * n5)
426 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
427 if(anElem) myScript->AddVolume(anElem->GetID(),
436 //=======================================================================
437 //function :AddVolume
439 //=======================================================================
440 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
442 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
443 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
447 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
448 const SMDS_MeshNode * n2,
449 const SMDS_MeshNode * n3,
450 const SMDS_MeshNode * n4,
451 const SMDS_MeshNode * n5,
452 const SMDS_MeshNode * n6,
455 return AddVolumeWithID(n1->GetID(),
464 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
465 const SMDS_MeshNode * n2,
466 const SMDS_MeshNode * n3,
467 const SMDS_MeshNode * n4,
468 const SMDS_MeshNode * n5,
469 const SMDS_MeshNode * n6)
471 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
472 if(anElem) myScript->AddVolume(anElem->GetID(),
482 //=======================================================================
483 //function :AddVolume
485 //=======================================================================
486 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
488 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
489 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
493 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
494 const SMDS_MeshNode * n2,
495 const SMDS_MeshNode * n3,
496 const SMDS_MeshNode * n4,
497 const SMDS_MeshNode * n5,
498 const SMDS_MeshNode * n6,
499 const SMDS_MeshNode * n7,
500 const SMDS_MeshNode * n8,
503 return AddVolumeWithID(n1->GetID(),
514 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
515 const SMDS_MeshNode * n2,
516 const SMDS_MeshNode * n3,
517 const SMDS_MeshNode * n4,
518 const SMDS_MeshNode * n5,
519 const SMDS_MeshNode * n6,
520 const SMDS_MeshNode * n7,
521 const SMDS_MeshNode * n8)
523 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
524 if(anElem) myScript->AddVolume(anElem->GetID(),
536 //=======================================================================
537 //function : AddPolygonalFace
539 //=======================================================================
540 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
543 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes_ids, ID);
545 myScript->AddPolygonalFace(ID, nodes_ids);
550 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
551 (std::vector<const SMDS_MeshNode*> nodes,
554 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
556 int i, len = nodes.size();
557 std::vector<int> nodes_ids (len);
558 for (i = 0; i < len; i++) {
559 nodes_ids[i] = nodes[i]->GetID();
561 myScript->AddPolygonalFace(ID, nodes_ids);
566 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
567 (std::vector<const SMDS_MeshNode*> nodes)
569 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
571 int i, len = nodes.size();
572 std::vector<int> nodes_ids (len);
573 for (i = 0; i < len; i++) {
574 nodes_ids[i] = nodes[i]->GetID();
576 myScript->AddPolygonalFace(anElem->GetID(), nodes_ids);
581 //=======================================================================
582 //function : AddPolyhedralVolume
584 //=======================================================================
585 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (std::vector<int> nodes_ids,
586 std::vector<int> quantities,
589 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes_ids, quantities, ID);
591 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
596 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID
597 (std::vector<const SMDS_MeshNode*> nodes,
598 std::vector<int> quantities,
601 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
603 int i, len = nodes.size();
604 std::vector<int> nodes_ids (len);
605 for (i = 0; i < len; i++) {
606 nodes_ids[i] = nodes[i]->GetID();
608 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
613 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume
614 (std::vector<const SMDS_MeshNode*> nodes,
615 std::vector<int> quantities)
617 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities);
619 int i, len = nodes.size();
620 std::vector<int> nodes_ids (len);
621 for (i = 0; i < len; i++) {
622 nodes_ids[i] = nodes[i]->GetID();
624 myScript->AddPolyhedralVolume(anElem->GetID(), nodes_ids, quantities);
629 //=======================================================================
630 //function : removeFromContainers
632 //=======================================================================
634 static void removeFromContainers (map<int,SMESHDS_SubMesh*> & theSubMeshes,
635 set<SMESHDS_GroupBase*>& theGroups,
636 list<const SMDS_MeshElement *> & theElems,
639 if ( theElems.empty() )
643 // Element can belong to several groups
644 if ( !theGroups.empty() )
646 set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
647 for ( ; GrIt != theGroups.end(); GrIt++ )
649 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
650 if ( !group || group->IsEmpty() ) continue;
652 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
653 for ( ; elIt != theElems.end(); elIt++ )
655 group->SMDSGroup().Remove( *elIt );
656 if ( group->IsEmpty() ) break;
661 // Rm from sub-meshes
662 // Element should belong to only one sub-mesh
663 map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
664 for ( ; SubIt != theSubMeshes.end(); SubIt++ )
666 int size = isNode ? (*SubIt).second->NbNodes() : (*SubIt).second->NbElements();
667 if ( size == 0 ) continue;
669 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
670 while ( elIt != theElems.end() )
672 bool removed = false;
674 removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
676 removed = (*SubIt).second->RemoveElement( *elIt );
680 elIt = theElems.erase( elIt );
681 if ( theElems.empty() )
682 return; // all elements are found and removed
692 //=======================================================================
693 //function : RemoveNode
695 //=======================================================================
696 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
698 myScript->RemoveNode(n->GetID());
700 list<const SMDS_MeshElement *> removedElems;
701 list<const SMDS_MeshElement *> removedNodes;
703 SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
705 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
706 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
709 //=======================================================================
710 //function : RemoveElement
712 //========================================================================
713 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
715 if (elt->GetType() == SMDSAbs_Node)
717 RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
721 myScript->RemoveElement(elt->GetID());
723 list<const SMDS_MeshElement *> removedElems;
724 list<const SMDS_MeshElement *> removedNodes;
726 SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
728 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
731 //=======================================================================
732 //function : SetNodeOnVolume
734 //=======================================================================
735 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
736 const TopoDS_Shell & S)
738 SetNodeInVolume( aNode, myIndexToShape.FindIndex(S) );
740 //=======================================================================
741 //function : SetNodeOnVolume
743 //=======================================================================
744 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
745 const TopoDS_Solid & S)
747 SetNodeInVolume( aNode, myIndexToShape.FindIndex(S) );
750 //=======================================================================
751 //function : SetNodeOnFace
753 //=======================================================================
754 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode * aNode,
755 const TopoDS_Face & S,
759 SetNodeOnFace( aNode, myIndexToShape.FindIndex(S), u, v );
762 //=======================================================================
763 //function : SetNodeOnEdge
765 //=======================================================================
766 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode * aNode,
767 const TopoDS_Edge & S,
770 SetNodeOnEdge( aNode, myIndexToShape.FindIndex(S), u );
773 //=======================================================================
774 //function : SetNodeOnVertex
776 //=======================================================================
777 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode * aNode,
778 const TopoDS_Vertex & S)
780 SetNodeOnVertex( aNode, myIndexToShape.FindIndex(S));
783 //=======================================================================
784 //function : UnSetNodeOnShape
786 //=======================================================================
787 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
789 MESSAGE("not implemented");
792 //=======================================================================
793 //function : SetMeshElementOnShape
795 //=======================================================================
796 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
797 const TopoDS_Shape & S)
799 if (myShape.IsNull()) MESSAGE("myShape is NULL");
801 int Index = myIndexToShape.FindIndex(S);
803 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
804 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
806 myShapeIndexToSubMesh[Index]->AddElement(anElement);
809 //=======================================================================
810 //function : UnSetMeshElementOnShape
812 //=======================================================================
814 UnSetMeshElementOnShape(const SMDS_MeshElement * anElement,
815 const TopoDS_Shape & S)
817 if (myShape.IsNull()) MESSAGE("myShape is NULL");
819 int Index = myIndexToShape.FindIndex(S);
821 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
822 myShapeIndexToSubMesh[Index]->RemoveElement(anElement);
825 //=======================================================================
826 //function : ShapeToMesh
828 //=======================================================================
829 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
834 //=======================================================================
835 //function : IsGroupOfSubShapes
836 //purpose : return true if at least one subshape of theShape is a subshape
837 // of myShape or theShape == myShape
838 //=======================================================================
840 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
842 if ( myShape.IsSame( theShape ))
845 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() ) {
846 if (myIndexToShape.Contains( it.Value() ) ||
847 IsGroupOfSubShapes( it.Value() ))
854 ///////////////////////////////////////////////////////////////////////////////
855 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
856 /// TopoDS_Shape is unknown
857 ///////////////////////////////////////////////////////////////////////////////
858 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const
860 if (myShape.IsNull()) MESSAGE("myShape is NULL");
862 int Index = ShapeToIndex(S);
863 TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
864 if (anIter != myShapeIndexToSubMesh.end())
865 return anIter->second;
870 ///////////////////////////////////////////////////////////////////////////////
871 /// Return the sub mesh by Id of shape it is linked to
872 ///////////////////////////////////////////////////////////////////////////////
873 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
875 if (myShape.IsNull()) MESSAGE("myShape is NULL");
877 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
878 return myShapeIndexToSubMesh[Index];
883 //=======================================================================
884 //function : SubMeshIndices
886 //=======================================================================
887 list<int> SMESHDS_Mesh::SubMeshIndices()
890 std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
891 for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
892 anIndices.push_back((*anIter).first);
897 //=======================================================================
898 //function : GetHypothesis
900 //=======================================================================
902 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
903 const TopoDS_Shape & S) const
905 if ( myShapeToHypothesis.IsBound(S) )
906 return myShapeToHypothesis.Find(S);
908 static list<const SMESHDS_Hypothesis*> empty;
912 //=======================================================================
913 //function : GetScript
915 //=======================================================================
916 SMESHDS_Script* SMESHDS_Mesh::GetScript()
921 //=======================================================================
922 //function : ClearScript
924 //=======================================================================
925 void SMESHDS_Mesh::ClearScript()
930 //=======================================================================
931 //function : HasMeshElements
933 //=======================================================================
934 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
936 if (myShape.IsNull()) MESSAGE("myShape is NULL");
937 int Index = myIndexToShape.FindIndex(S);
938 return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
941 //=======================================================================
942 //function : HasHypothesis
944 //=======================================================================
945 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
947 return myShapeToHypothesis.IsBound(S);
950 //=======================================================================
951 //function : NewSubMesh
953 //=======================================================================
954 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
956 SMESHDS_SubMesh* SM = 0;
957 TShapeIndexToSubMesh::iterator anIter = myShapeIndexToSubMesh.find(Index);
958 if (anIter == myShapeIndexToSubMesh.end())
960 SM = new SMESHDS_SubMesh();
961 myShapeIndexToSubMesh[Index]=SM;
968 //=======================================================================
969 //function : AddCompoundSubmesh
971 //=======================================================================
973 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
974 TopAbs_ShapeEnum type)
977 if ( IsGroupOfSubShapes( S ) || (S.ShapeType() == TopAbs_VERTEX && myIndexToShape.Contains(S)) )
979 aMainIndex = myIndexToShape.Add( S );
980 bool all = ( type == TopAbs_SHAPE );
981 if ( all ) // corresponding simple submesh may exist
982 aMainIndex = -aMainIndex;
983 //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
984 SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
985 if ( !aNewSub->IsComplexSubmesh() ) // is empty
987 int shapeType = all ? myShape.ShapeType() : type;
988 int typeLimit = all ? TopAbs_VERTEX : type;
989 for ( ; shapeType <= typeLimit; shapeType++ )
991 TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
992 for ( ; exp.More(); exp.Next() )
994 int index = myIndexToShape.FindIndex( exp.Current() );
996 aNewSub->AddSubMesh( NewSubMesh( index ));
1004 //=======================================================================
1005 //function : IndexToShape
1007 //=======================================================================
1008 TopoDS_Shape SMESHDS_Mesh::IndexToShape(int ShapeIndex)
1010 return myIndexToShape.FindKey(ShapeIndex);
1013 //=======================================================================
1014 //function : ShapeToIndex
1016 //=======================================================================
1017 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
1019 if (myShape.IsNull())
1020 MESSAGE("myShape is NULL");
1022 int index = myIndexToShape.FindIndex(S);
1027 //=======================================================================
1028 //function : SetNodeOnVolume
1030 //=======================================================================
1031 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
1033 addNodeToSubmesh( aNode, Index );
1036 //=======================================================================
1037 //function : SetNodeOnFace
1039 //=======================================================================
1040 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index, double u, double v)
1042 //Set Position on Node
1043 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, u, v)));
1045 addNodeToSubmesh( aNode, Index );
1048 //=======================================================================
1049 //function : SetNodeOnEdge
1051 //=======================================================================
1052 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode,
1056 //Set Position on Node
1057 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, u)));
1059 addNodeToSubmesh( aNode, Index );
1062 //=======================================================================
1063 //function : SetNodeOnVertex
1065 //=======================================================================
1066 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
1068 //Set Position on Node
1069 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
1071 addNodeToSubmesh( aNode, Index );
1074 //=======================================================================
1075 //function : SetMeshElementOnShape
1077 //=======================================================================
1078 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
1081 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1082 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1084 myShapeIndexToSubMesh[Index]->AddElement(anElement);
1087 SMESHDS_Mesh::~SMESHDS_Mesh()