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 ASSERT( nbnodes < 9 );
176 for ( i = 0; i < nbnodes; i++ )
177 IDs [ i ] = nodes[ i ]->GetID();
178 myScript->ChangeElementNodes( elem->GetID(), IDs, nbnodes);
183 //=======================================================================
184 //function : Renumber
186 //=======================================================================
188 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
190 SMDS_Mesh::Renumber( isNodes, startID, deltaID );
191 myScript->Renumber( isNodes, startID, deltaID );
194 //=======================================================================
195 //function :AddEdgeWithID
197 //=======================================================================
198 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
200 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
201 if(anElem) myScript->AddEdge(ID,n1,n2);
205 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
206 const SMDS_MeshNode * n2,
209 return AddEdgeWithID(n1->GetID(),
214 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
215 const SMDS_MeshNode * n2)
217 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
218 if(anElem) myScript->AddEdge(anElem->GetID(),
224 //=======================================================================
227 //=======================================================================
228 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
230 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
231 if(anElem) myScript->AddFace(ID,n1,n2,n3);
235 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
236 const SMDS_MeshNode * n2,
237 const SMDS_MeshNode * n3,
240 return AddFaceWithID(n1->GetID(),
246 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
247 const SMDS_MeshNode * n2,
248 const SMDS_MeshNode * n3)
250 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
251 if(anElem) myScript->AddFace(anElem->GetID(),
258 //=======================================================================
261 //=======================================================================
262 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
264 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
265 if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
269 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
270 const SMDS_MeshNode * n2,
271 const SMDS_MeshNode * n3,
272 const SMDS_MeshNode * n4,
275 return AddFaceWithID(n1->GetID(),
282 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
283 const SMDS_MeshNode * n2,
284 const SMDS_MeshNode * n3,
285 const SMDS_MeshNode * n4)
287 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
288 if(anElem) myScript->AddFace(anElem->GetID(),
296 //=======================================================================
297 //function :AddVolume
299 //=======================================================================
300 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
302 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
303 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
307 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
308 const SMDS_MeshNode * n2,
309 const SMDS_MeshNode * n3,
310 const SMDS_MeshNode * n4,
313 return AddVolumeWithID(n1->GetID(),
320 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
321 const SMDS_MeshNode * n2,
322 const SMDS_MeshNode * n3,
323 const SMDS_MeshNode * n4)
325 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
326 if(anElem) myScript->AddVolume(anElem->GetID(),
334 //=======================================================================
335 //function :AddVolume
337 //=======================================================================
338 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
340 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
341 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
345 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
346 const SMDS_MeshNode * n2,
347 const SMDS_MeshNode * n3,
348 const SMDS_MeshNode * n4,
349 const SMDS_MeshNode * n5,
352 return AddVolumeWithID(n1->GetID(),
360 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
361 const SMDS_MeshNode * n2,
362 const SMDS_MeshNode * n3,
363 const SMDS_MeshNode * n4,
364 const SMDS_MeshNode * n5)
366 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
367 if(anElem) myScript->AddVolume(anElem->GetID(),
376 //=======================================================================
377 //function :AddVolume
379 //=======================================================================
380 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
382 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
383 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
387 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
388 const SMDS_MeshNode * n2,
389 const SMDS_MeshNode * n3,
390 const SMDS_MeshNode * n4,
391 const SMDS_MeshNode * n5,
392 const SMDS_MeshNode * n6,
395 return AddVolumeWithID(n1->GetID(),
404 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
405 const SMDS_MeshNode * n2,
406 const SMDS_MeshNode * n3,
407 const SMDS_MeshNode * n4,
408 const SMDS_MeshNode * n5,
409 const SMDS_MeshNode * n6)
411 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
412 if(anElem) myScript->AddVolume(anElem->GetID(),
422 //=======================================================================
423 //function :AddVolume
425 //=======================================================================
426 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
428 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
429 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
433 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
434 const SMDS_MeshNode * n2,
435 const SMDS_MeshNode * n3,
436 const SMDS_MeshNode * n4,
437 const SMDS_MeshNode * n5,
438 const SMDS_MeshNode * n6,
439 const SMDS_MeshNode * n7,
440 const SMDS_MeshNode * n8,
443 return AddVolumeWithID(n1->GetID(),
454 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
455 const SMDS_MeshNode * n2,
456 const SMDS_MeshNode * n3,
457 const SMDS_MeshNode * n4,
458 const SMDS_MeshNode * n5,
459 const SMDS_MeshNode * n6,
460 const SMDS_MeshNode * n7,
461 const SMDS_MeshNode * n8)
463 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
464 if(anElem) myScript->AddVolume(anElem->GetID(),
475 //=======================================================================
476 //function : removeFromContainers
478 //=======================================================================
480 static void removeFromContainers (map<int,SMESHDS_SubMesh*> & theSubMeshes,
481 set<SMESHDS_GroupBase*>& theGroups,
482 list<const SMDS_MeshElement *> & theElems,
485 if ( theElems.empty() )
489 // Element can belong to several groups
490 if ( !theGroups.empty() )
492 set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
493 for ( ; GrIt != theGroups.end(); GrIt++ )
495 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
496 if ( !group || group->IsEmpty() ) continue;
498 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
499 for ( ; elIt != theElems.end(); elIt++ )
501 group->SMDSGroup().Remove( *elIt );
502 if ( group->IsEmpty() ) break;
507 // Rm from sub-meshes
508 // Element should belong to only one sub-mesh
509 map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
510 for ( ; SubIt != theSubMeshes.end(); SubIt++ )
512 int size = isNode ? (*SubIt).second->NbNodes() : (*SubIt).second->NbElements();
513 if ( size == 0 ) continue;
515 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
516 while ( elIt != theElems.end() )
518 bool removed = false;
520 removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
522 removed = (*SubIt).second->RemoveElement( *elIt );
526 elIt = theElems.erase( elIt );
527 if ( theElems.empty() )
528 return; // all elements are found and removed
538 //=======================================================================
539 //function : RemoveNode
541 //=======================================================================
542 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
544 myScript->RemoveNode(n->GetID());
546 list<const SMDS_MeshElement *> removedElems;
547 list<const SMDS_MeshElement *> removedNodes;
549 SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
551 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
552 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
555 //=======================================================================
556 //function : RemoveElement
558 //========================================================================
559 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
561 if (elt->GetType() == SMDSAbs_Node)
563 RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
567 myScript->RemoveElement(elt->GetID());
569 list<const SMDS_MeshElement *> removedElems;
570 list<const SMDS_MeshElement *> removedNodes;
572 SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
574 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
577 //=======================================================================
578 //function : SetNodeOnVolume
580 //=======================================================================
581 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
582 const TopoDS_Shell & S)
584 if (myShape.IsNull()) MESSAGE("myShape is NULL");
586 int Index = myIndexToShape.FindIndex(S);
588 //Set Position on Node
589 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
590 //aNode->SetPosition(aPos);
592 //Update or build submesh
593 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
594 if (it==myShapeIndexToSubMesh.end())
595 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
597 myShapeIndexToSubMesh[Index]->AddNode(aNode);
600 //=======================================================================
601 //function : SetNodeOnFace
603 //=======================================================================
604 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode * aNode,
605 const TopoDS_Face & S)
607 if (myShape.IsNull()) MESSAGE("myShape is NULL");
609 int Index = myIndexToShape.FindIndex(S);
611 //Set Position on Node
612 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
614 //Update or build submesh
615 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
616 if (it==myShapeIndexToSubMesh.end())
617 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
619 myShapeIndexToSubMesh[Index]->AddNode(aNode);
622 //=======================================================================
623 //function : SetNodeOnEdge
625 //=======================================================================
626 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode * aNode,
627 const TopoDS_Edge & S)
629 if (myShape.IsNull()) MESSAGE("myShape is NULL");
631 int Index = myIndexToShape.FindIndex(S);
633 //Set Position on Node
634 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
636 //Update or build submesh
637 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
638 if (it==myShapeIndexToSubMesh.end())
639 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
641 myShapeIndexToSubMesh[Index]->AddNode(aNode);
644 //=======================================================================
645 //function : SetNodeOnVertex
647 //=======================================================================
648 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode * aNode,
649 const TopoDS_Vertex & S)
651 if (myShape.IsNull()) MESSAGE("myShape is NULL");
653 int Index = myIndexToShape.FindIndex(S);
655 //Set Position on Node
656 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
658 //Update or build submesh
659 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
660 if (it==myShapeIndexToSubMesh.end())
661 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
663 myShapeIndexToSubMesh[Index]->AddNode(aNode);
666 //=======================================================================
667 //function : UnSetNodeOnShape
669 //=======================================================================
670 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
672 MESSAGE("not implemented");
675 //=======================================================================
676 //function : SetMeshElementOnShape
678 //=======================================================================
679 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
680 const TopoDS_Shape & S)
682 if (myShape.IsNull()) MESSAGE("myShape is NULL");
684 int Index = myIndexToShape.FindIndex(S);
686 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
687 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
689 myShapeIndexToSubMesh[Index]->AddElement(anElement);
692 //=======================================================================
693 //function : UnSetMeshElementOnShape
695 //=======================================================================
697 UnSetMeshElementOnShape(const SMDS_MeshElement * anElement,
698 const TopoDS_Shape & S)
700 if (myShape.IsNull()) MESSAGE("myShape is NULL");
702 int Index = myIndexToShape.FindIndex(S);
704 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
705 myShapeIndexToSubMesh[Index]->RemoveElement(anElement);
708 //=======================================================================
709 //function : ShapeToMesh
711 //=======================================================================
712 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
717 //=======================================================================
718 //function : IsGroupOfSubShapes
719 //purpose : return true if at least one subshape of theShape is a subshape
720 // of myShape or theShape == myShape
721 //=======================================================================
723 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
725 if ( myShape.IsSame( theShape ))
728 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() ) {
729 if (myIndexToShape.Contains( it.Value() ) ||
730 IsGroupOfSubShapes( it.Value() ))
737 ///////////////////////////////////////////////////////////////////////////////
738 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
739 /// TopoDS_Shape is unknown
740 ///////////////////////////////////////////////////////////////////////////////
741 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S)
743 if (myShape.IsNull()) MESSAGE("myShape is NULL");
745 int Index = ShapeToIndex(S);
746 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
747 return myShapeIndexToSubMesh[Index];
752 ///////////////////////////////////////////////////////////////////////////////
753 /// Return the sub mesh by Id of shape it is linked to
754 ///////////////////////////////////////////////////////////////////////////////
755 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
757 if (myShape.IsNull()) MESSAGE("myShape is NULL");
759 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
760 return myShapeIndexToSubMesh[Index];
765 //=======================================================================
766 //function : SubMeshIndices
768 //=======================================================================
769 list<int> SMESHDS_Mesh::SubMeshIndices()
772 std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
773 for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
774 anIndices.push_back((*anIter).first);
779 //=======================================================================
780 //function : GetHypothesis
782 //=======================================================================
784 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
785 const TopoDS_Shape & S) const
787 if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
788 return myShapeToHypothesis.find(S)->second;
790 static list<const SMESHDS_Hypothesis*> empty;
794 //=======================================================================
795 //function : GetScript
797 //=======================================================================
798 SMESHDS_Script* SMESHDS_Mesh::GetScript()
803 //=======================================================================
804 //function : ClearScript
806 //=======================================================================
807 void SMESHDS_Mesh::ClearScript()
812 //=======================================================================
813 //function : HasMeshElements
815 //=======================================================================
816 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
818 if (myShape.IsNull()) MESSAGE("myShape is NULL");
819 int Index = myIndexToShape.FindIndex(S);
820 return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
823 //=======================================================================
824 //function : HasHypothesis
826 //=======================================================================
827 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
829 return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
832 //=======================================================================
833 //function : NewSubMesh
835 //=======================================================================
836 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
838 SMESHDS_SubMesh* SM = 0;
839 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
841 SM = new SMESHDS_SubMesh();
842 myShapeIndexToSubMesh[Index]=SM;
845 SM = myShapeIndexToSubMesh[Index];
849 //=======================================================================
850 //function : AddCompoundSubmesh
852 //=======================================================================
854 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
855 TopAbs_ShapeEnum type)
858 if ( IsGroupOfSubShapes( S ) || (S.ShapeType() == TopAbs_VERTEX && myIndexToShape.Contains(S)) )
860 aMainIndex = myIndexToShape.Add( S );
861 bool all = ( type == TopAbs_SHAPE );
862 if ( all ) // corresponding simple submesh may exist
863 aMainIndex = -aMainIndex;
864 //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
865 SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
866 if ( !aNewSub->IsComplexSubmesh() ) // is empty
868 int shapeType = all ? myShape.ShapeType() : type;
869 int typeLimit = all ? TopAbs_VERTEX : type;
870 for ( ; shapeType <= typeLimit; shapeType++ )
872 TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
873 for ( ; exp.More(); exp.Next() )
875 int index = myIndexToShape.FindIndex( exp.Current() );
877 aNewSub->AddSubMesh( NewSubMesh( index ));
885 //=======================================================================
886 //function : IndexToShape
888 //=======================================================================
889 TopoDS_Shape SMESHDS_Mesh::IndexToShape(int ShapeIndex)
891 return myIndexToShape.FindKey(ShapeIndex);
894 //=======================================================================
895 //function : ShapeToIndex
897 //=======================================================================
898 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S)
900 if (myShape.IsNull())
901 MESSAGE("myShape is NULL");
903 int index = myIndexToShape.FindIndex(S);
908 //=======================================================================
909 //function : SetNodeOnVolume
911 //=======================================================================
912 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
914 //Set Position on Node
915 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
916 //aNode->SetPosition(aPos);
918 //Update or build submesh
919 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
920 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
922 myShapeIndexToSubMesh[Index]->AddNode(aNode);
925 //=======================================================================
926 //function : SetNodeOnFace
928 //=======================================================================
929 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index)
931 //Set Position on Node
932 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
934 //Update or build submesh
935 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
936 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
938 myShapeIndexToSubMesh[Index]->AddNode(aNode);
941 //=======================================================================
942 //function : SetNodeOnEdge
944 //=======================================================================
945 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode, int Index)
947 //Set Position on Node
948 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
950 //Update or build submesh
951 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
952 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
954 myShapeIndexToSubMesh[Index]->AddNode(aNode);
957 //=======================================================================
958 //function : SetNodeOnVertex
960 //=======================================================================
961 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
963 //Set Position on Node
964 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
966 //Update or build submesh
967 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
968 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
970 myShapeIndexToSubMesh[Index]->AddNode(aNode);
973 //=======================================================================
974 //function : SetMeshElementOnShape
976 //=======================================================================
977 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
980 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
981 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
983 myShapeIndexToSubMesh[Index]->AddElement(anElement);
986 SMESHDS_Mesh::~SMESHDS_Mesh()