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 //=======================================================================
47 //=======================================================================
48 SMESHDS_Mesh::SMESHDS_Mesh(int MeshID):myMeshID(MeshID)
50 myScript = new SMESHDS_Script();
53 //=======================================================================
54 //function : ShapeToMesh
56 //=======================================================================
57 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
59 if ( !myShape.IsNull() && S.IsNull() )
61 // removal of a shape to mesh, delete ...
63 myShapeToHypothesis.clear();
64 // - shape indices in SMDS_Position of nodes
65 map<int,SMESHDS_SubMesh*>::iterator i_sub = myShapeIndexToSubMesh.begin();
66 for ( ; i_sub != myShapeIndexToSubMesh.end(); i_sub++ ) {
67 if ( !i_sub->second->IsComplexSubmesh() ) {
68 SMDS_NodeIteratorPtr nIt = i_sub->second->GetNodes();
70 nIt->next()->GetPosition()->SetShapeId( 0 );
74 myIndexToShape.Clear();
75 myShapeIndexToSubMesh.clear();
76 // - groups on geometry
77 set<SMESHDS_GroupBase*>::iterator gr = myGroups.begin();
78 while ( gr != myGroups.end() ) {
79 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( *gr ))
80 myGroups.erase( gr++ );
88 TopExp::MapShapes(myShape, myIndexToShape);
92 //=======================================================================
93 //function : AddHypothesis
95 //=======================================================================
97 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
98 const SMESHDS_Hypothesis * H)
100 list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis[SS];
102 //Check if the Hypothesis is still present
103 list<const SMESHDS_Hypothesis*>::iterator ith=alist.begin();
105 for (; ith!=alist.end(); ith++)
106 if (H == *ith) return false;
112 //=======================================================================
113 //function : RemoveHypothesis
115 //=======================================================================
117 bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S,
118 const SMESHDS_Hypothesis * H)
120 ShapeToHypothesis::iterator its=myShapeToHypothesis.find(S);
121 if(its!=myShapeToHypothesis.end())
123 list<const SMESHDS_Hypothesis*>::iterator ith=(*its).second.begin();
125 for (; ith!=(*its).second.end(); ith++)
128 (*its).second.erase(ith);
135 //=======================================================================
138 //=======================================================================
139 SMDS_MeshNode* SMESHDS_Mesh::AddNode(double x, double y, double z){
140 SMDS_MeshNode* node = SMDS_Mesh::AddNode(x, y, z);
141 if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
145 SMDS_MeshNode* SMESHDS_Mesh::AddNodeWithID(double x, double y, double z, int ID){
146 SMDS_MeshNode* node = SMDS_Mesh::AddNodeWithID(x,y,z,ID);
147 if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
151 //=======================================================================
152 //function : MoveNode
154 //=======================================================================
155 void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
157 SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
159 myScript->MoveNode(n->GetID(), x, y, z);
162 //=======================================================================
163 //function : ChangeElementNodes
165 //=======================================================================
167 bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
168 const SMDS_MeshNode * nodes[],
171 if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes ))
174 vector<int> IDs( nbnodes );
175 for ( int i = 0; i < nbnodes; i++ )
176 IDs [ i ] = nodes[ i ]->GetID();
177 myScript->ChangeElementNodes( elem->GetID(), &IDs[0], nbnodes);
182 //=======================================================================
183 //function : ChangePolygonNodes
185 //=======================================================================
186 bool SMESHDS_Mesh::ChangePolygonNodes
187 (const SMDS_MeshElement * elem,
188 vector<const SMDS_MeshNode*> nodes)
190 ASSERT(nodes.size() > 3);
192 return ChangeElementNodes(elem, &nodes[0], nodes.size());
195 //=======================================================================
196 //function : ChangePolyhedronNodes
198 //=======================================================================
199 bool SMESHDS_Mesh::ChangePolyhedronNodes
200 (const SMDS_MeshElement * elem,
201 std::vector<const SMDS_MeshNode*> nodes,
202 std::vector<int> quantities)
204 ASSERT(nodes.size() > 3);
206 if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
209 int i, len = nodes.size();
210 std::vector<int> nodes_ids (len);
211 for (i = 0; i < len; i++) {
212 nodes_ids[i] = nodes[i]->GetID();
214 myScript->ChangePolyhedronNodes(elem->GetID(), nodes_ids, quantities);
219 //=======================================================================
220 //function : Renumber
222 //=======================================================================
224 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
226 SMDS_Mesh::Renumber( isNodes, startID, deltaID );
227 myScript->Renumber( isNodes, startID, deltaID );
230 //=======================================================================
231 //function :AddEdgeWithID
233 //=======================================================================
234 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
236 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
237 if(anElem) myScript->AddEdge(ID,n1,n2);
241 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
242 const SMDS_MeshNode * n2,
245 return AddEdgeWithID(n1->GetID(),
250 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
251 const SMDS_MeshNode * n2)
253 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
254 if(anElem) myScript->AddEdge(anElem->GetID(),
260 //=======================================================================
263 //=======================================================================
264 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
266 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
267 if(anElem) myScript->AddFace(ID,n1,n2,n3);
271 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
272 const SMDS_MeshNode * n2,
273 const SMDS_MeshNode * n3,
276 return AddFaceWithID(n1->GetID(),
282 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
283 const SMDS_MeshNode * n2,
284 const SMDS_MeshNode * n3)
286 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
287 if(anElem) myScript->AddFace(anElem->GetID(),
294 //=======================================================================
297 //=======================================================================
298 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
300 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
301 if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
305 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
306 const SMDS_MeshNode * n2,
307 const SMDS_MeshNode * n3,
308 const SMDS_MeshNode * n4,
311 return AddFaceWithID(n1->GetID(),
318 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
319 const SMDS_MeshNode * n2,
320 const SMDS_MeshNode * n3,
321 const SMDS_MeshNode * n4)
323 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
324 if(anElem) myScript->AddFace(anElem->GetID(),
332 //=======================================================================
333 //function :AddVolume
335 //=======================================================================
336 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
338 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
339 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
343 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
344 const SMDS_MeshNode * n2,
345 const SMDS_MeshNode * n3,
346 const SMDS_MeshNode * n4,
349 return AddVolumeWithID(n1->GetID(),
356 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
357 const SMDS_MeshNode * n2,
358 const SMDS_MeshNode * n3,
359 const SMDS_MeshNode * n4)
361 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
362 if(anElem) myScript->AddVolume(anElem->GetID(),
370 //=======================================================================
371 //function :AddVolume
373 //=======================================================================
374 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
376 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
377 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
381 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
382 const SMDS_MeshNode * n2,
383 const SMDS_MeshNode * n3,
384 const SMDS_MeshNode * n4,
385 const SMDS_MeshNode * n5,
388 return AddVolumeWithID(n1->GetID(),
396 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
397 const SMDS_MeshNode * n2,
398 const SMDS_MeshNode * n3,
399 const SMDS_MeshNode * n4,
400 const SMDS_MeshNode * n5)
402 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
403 if(anElem) myScript->AddVolume(anElem->GetID(),
412 //=======================================================================
413 //function :AddVolume
415 //=======================================================================
416 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
418 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
419 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
423 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
424 const SMDS_MeshNode * n2,
425 const SMDS_MeshNode * n3,
426 const SMDS_MeshNode * n4,
427 const SMDS_MeshNode * n5,
428 const SMDS_MeshNode * n6,
431 return AddVolumeWithID(n1->GetID(),
440 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
441 const SMDS_MeshNode * n2,
442 const SMDS_MeshNode * n3,
443 const SMDS_MeshNode * n4,
444 const SMDS_MeshNode * n5,
445 const SMDS_MeshNode * n6)
447 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
448 if(anElem) myScript->AddVolume(anElem->GetID(),
458 //=======================================================================
459 //function :AddVolume
461 //=======================================================================
462 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
464 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
465 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
469 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
470 const SMDS_MeshNode * n2,
471 const SMDS_MeshNode * n3,
472 const SMDS_MeshNode * n4,
473 const SMDS_MeshNode * n5,
474 const SMDS_MeshNode * n6,
475 const SMDS_MeshNode * n7,
476 const SMDS_MeshNode * n8,
479 return AddVolumeWithID(n1->GetID(),
490 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
491 const SMDS_MeshNode * n2,
492 const SMDS_MeshNode * n3,
493 const SMDS_MeshNode * n4,
494 const SMDS_MeshNode * n5,
495 const SMDS_MeshNode * n6,
496 const SMDS_MeshNode * n7,
497 const SMDS_MeshNode * n8)
499 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
500 if(anElem) myScript->AddVolume(anElem->GetID(),
512 //=======================================================================
513 //function : AddPolygonalFace
515 //=======================================================================
516 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
519 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes_ids, ID);
521 myScript->AddPolygonalFace(ID, nodes_ids);
526 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
527 (std::vector<const SMDS_MeshNode*> nodes,
530 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
532 int i, len = nodes.size();
533 std::vector<int> nodes_ids (len);
534 for (i = 0; i < len; i++) {
535 nodes_ids[i] = nodes[i]->GetID();
537 myScript->AddPolygonalFace(ID, nodes_ids);
542 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
543 (std::vector<const SMDS_MeshNode*> nodes)
545 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
547 int i, len = nodes.size();
548 std::vector<int> nodes_ids (len);
549 for (i = 0; i < len; i++) {
550 nodes_ids[i] = nodes[i]->GetID();
552 myScript->AddPolygonalFace(anElem->GetID(), nodes_ids);
557 //=======================================================================
558 //function : AddPolyhedralVolume
560 //=======================================================================
561 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (std::vector<int> nodes_ids,
562 std::vector<int> quantities,
565 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes_ids, quantities, ID);
567 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
572 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID
573 (std::vector<const SMDS_MeshNode*> nodes,
574 std::vector<int> quantities,
577 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
579 int i, len = nodes.size();
580 std::vector<int> nodes_ids (len);
581 for (i = 0; i < len; i++) {
582 nodes_ids[i] = nodes[i]->GetID();
584 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
589 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume
590 (std::vector<const SMDS_MeshNode*> nodes,
591 std::vector<int> quantities)
593 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities);
595 int i, len = nodes.size();
596 std::vector<int> nodes_ids (len);
597 for (i = 0; i < len; i++) {
598 nodes_ids[i] = nodes[i]->GetID();
600 myScript->AddPolyhedralVolume(anElem->GetID(), nodes_ids, quantities);
605 //=======================================================================
606 //function : removeFromContainers
608 //=======================================================================
610 static void removeFromContainers (map<int,SMESHDS_SubMesh*> & theSubMeshes,
611 set<SMESHDS_GroupBase*>& theGroups,
612 list<const SMDS_MeshElement *> & theElems,
615 if ( theElems.empty() )
619 // Element can belong to several groups
620 if ( !theGroups.empty() )
622 set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
623 for ( ; GrIt != theGroups.end(); GrIt++ )
625 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
626 if ( !group || group->IsEmpty() ) continue;
628 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
629 for ( ; elIt != theElems.end(); elIt++ )
631 group->SMDSGroup().Remove( *elIt );
632 if ( group->IsEmpty() ) break;
637 // Rm from sub-meshes
638 // Element should belong to only one sub-mesh
639 map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
640 for ( ; SubIt != theSubMeshes.end(); SubIt++ )
642 int size = isNode ? (*SubIt).second->NbNodes() : (*SubIt).second->NbElements();
643 if ( size == 0 ) continue;
645 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
646 while ( elIt != theElems.end() )
648 bool removed = false;
650 removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
652 removed = (*SubIt).second->RemoveElement( *elIt );
656 elIt = theElems.erase( elIt );
657 if ( theElems.empty() )
658 return; // all elements are found and removed
668 //=======================================================================
669 //function : RemoveNode
671 //=======================================================================
672 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
674 myScript->RemoveNode(n->GetID());
676 list<const SMDS_MeshElement *> removedElems;
677 list<const SMDS_MeshElement *> removedNodes;
679 SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
681 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
682 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
685 //=======================================================================
686 //function : RemoveElement
688 //========================================================================
689 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
691 if (elt->GetType() == SMDSAbs_Node)
693 RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
697 myScript->RemoveElement(elt->GetID());
699 list<const SMDS_MeshElement *> removedElems;
700 list<const SMDS_MeshElement *> removedNodes;
702 SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
704 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
707 //=======================================================================
708 //function : SetNodeOnVolume
710 //=======================================================================
711 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
712 const TopoDS_Shell & S)
714 SetNodeInVolume( aNode, myIndexToShape.FindIndex(S) );
716 //=======================================================================
717 //function : SetNodeOnVolume
719 //=======================================================================
720 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
721 const TopoDS_Solid & S)
723 SetNodeInVolume( aNode, myIndexToShape.FindIndex(S) );
726 //=======================================================================
727 //function : SetNodeOnFace
729 //=======================================================================
730 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode * aNode,
731 const TopoDS_Face & S,
735 SetNodeOnFace( aNode, myIndexToShape.FindIndex(S), u, v );
738 //=======================================================================
739 //function : SetNodeOnEdge
741 //=======================================================================
742 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode * aNode,
743 const TopoDS_Edge & S,
746 SetNodeOnEdge( aNode, myIndexToShape.FindIndex(S), u );
749 //=======================================================================
750 //function : SetNodeOnVertex
752 //=======================================================================
753 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode * aNode,
754 const TopoDS_Vertex & S)
756 SetNodeOnVertex( aNode, myIndexToShape.FindIndex(S));
759 //=======================================================================
760 //function : UnSetNodeOnShape
762 //=======================================================================
763 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
765 MESSAGE("not implemented");
768 //=======================================================================
769 //function : SetMeshElementOnShape
771 //=======================================================================
772 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
773 const TopoDS_Shape & S)
775 if (myShape.IsNull()) MESSAGE("myShape is NULL");
777 int Index = myIndexToShape.FindIndex(S);
779 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
780 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
782 myShapeIndexToSubMesh[Index]->AddElement(anElement);
785 //=======================================================================
786 //function : UnSetMeshElementOnShape
788 //=======================================================================
790 UnSetMeshElementOnShape(const SMDS_MeshElement * anElement,
791 const TopoDS_Shape & S)
793 if (myShape.IsNull()) MESSAGE("myShape is NULL");
795 int Index = myIndexToShape.FindIndex(S);
797 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
798 myShapeIndexToSubMesh[Index]->RemoveElement(anElement);
801 //=======================================================================
802 //function : ShapeToMesh
804 //=======================================================================
805 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
810 //=======================================================================
811 //function : IsGroupOfSubShapes
812 //purpose : return true if at least one subshape of theShape is a subshape
813 // of myShape or theShape == myShape
814 //=======================================================================
816 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
818 if ( myShape.IsSame( theShape ))
821 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() ) {
822 if (myIndexToShape.Contains( it.Value() ) ||
823 IsGroupOfSubShapes( it.Value() ))
830 ///////////////////////////////////////////////////////////////////////////////
831 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
832 /// TopoDS_Shape is unknown
833 ///////////////////////////////////////////////////////////////////////////////
834 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const
836 if (myShape.IsNull()) MESSAGE("myShape is NULL");
838 int Index = ShapeToIndex(S);
839 TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
840 if (anIter != myShapeIndexToSubMesh.end())
841 return anIter->second;
846 ///////////////////////////////////////////////////////////////////////////////
847 /// Return the sub mesh by Id of shape it is linked to
848 ///////////////////////////////////////////////////////////////////////////////
849 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
851 if (myShape.IsNull()) MESSAGE("myShape is NULL");
853 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
854 return myShapeIndexToSubMesh[Index];
859 //=======================================================================
860 //function : SubMeshIndices
862 //=======================================================================
863 list<int> SMESHDS_Mesh::SubMeshIndices()
866 std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
867 for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
868 anIndices.push_back((*anIter).first);
873 //=======================================================================
874 //function : GetHypothesis
876 //=======================================================================
878 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
879 const TopoDS_Shape & S) const
881 if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
882 return myShapeToHypothesis.find(S)->second;
884 static list<const SMESHDS_Hypothesis*> empty;
888 //=======================================================================
889 //function : GetScript
891 //=======================================================================
892 SMESHDS_Script* SMESHDS_Mesh::GetScript()
897 //=======================================================================
898 //function : ClearScript
900 //=======================================================================
901 void SMESHDS_Mesh::ClearScript()
906 //=======================================================================
907 //function : HasMeshElements
909 //=======================================================================
910 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
912 if (myShape.IsNull()) MESSAGE("myShape is NULL");
913 int Index = myIndexToShape.FindIndex(S);
914 return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
917 //=======================================================================
918 //function : HasHypothesis
920 //=======================================================================
921 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
923 return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
926 //=======================================================================
927 //function : NewSubMesh
929 //=======================================================================
930 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
932 SMESHDS_SubMesh* SM = 0;
933 TShapeIndexToSubMesh::iterator anIter = myShapeIndexToSubMesh.find(Index);
934 if (anIter == myShapeIndexToSubMesh.end())
936 SM = new SMESHDS_SubMesh();
937 myShapeIndexToSubMesh[Index]=SM;
944 //=======================================================================
945 //function : AddCompoundSubmesh
947 //=======================================================================
949 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
950 TopAbs_ShapeEnum type)
953 if ( IsGroupOfSubShapes( S ) || (S.ShapeType() == TopAbs_VERTEX && myIndexToShape.Contains(S)) )
955 aMainIndex = myIndexToShape.Add( S );
956 bool all = ( type == TopAbs_SHAPE );
957 if ( all ) // corresponding simple submesh may exist
958 aMainIndex = -aMainIndex;
959 //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
960 SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
961 if ( !aNewSub->IsComplexSubmesh() ) // is empty
963 int shapeType = all ? myShape.ShapeType() : type;
964 int typeLimit = all ? TopAbs_VERTEX : type;
965 for ( ; shapeType <= typeLimit; shapeType++ )
967 TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
968 for ( ; exp.More(); exp.Next() )
970 int index = myIndexToShape.FindIndex( exp.Current() );
972 aNewSub->AddSubMesh( NewSubMesh( index ));
980 //=======================================================================
981 //function : IndexToShape
983 //=======================================================================
984 TopoDS_Shape SMESHDS_Mesh::IndexToShape(int ShapeIndex)
986 return myIndexToShape.FindKey(ShapeIndex);
989 //=======================================================================
990 //function : ShapeToIndex
992 //=======================================================================
993 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
995 if (myShape.IsNull())
996 MESSAGE("myShape is NULL");
998 int index = myIndexToShape.FindIndex(S);
1003 //=======================================================================
1004 //function : SetNodeOnVolume
1006 //=======================================================================
1007 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
1009 addNodeToSubmesh( aNode, Index );
1012 //=======================================================================
1013 //function : SetNodeOnFace
1015 //=======================================================================
1016 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index, double u, double v)
1018 //Set Position on Node
1019 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, u, v)));
1021 addNodeToSubmesh( aNode, Index );
1024 //=======================================================================
1025 //function : SetNodeOnEdge
1027 //=======================================================================
1028 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode,
1032 //Set Position on Node
1033 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, u)));
1035 addNodeToSubmesh( aNode, Index );
1038 //=======================================================================
1039 //function : SetNodeOnVertex
1041 //=======================================================================
1042 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
1044 //Set Position on Node
1045 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
1047 addNodeToSubmesh( aNode, Index );
1050 //=======================================================================
1051 //function : SetMeshElementOnShape
1053 //=======================================================================
1054 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
1057 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1058 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1060 myShapeIndexToSubMesh[Index]->AddElement(anElement);
1063 SMESHDS_Mesh::~SMESHDS_Mesh()