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 <TopExp_Explorer.hxx>
37 #include <TopoDS_Iterator.hxx>
39 #include "utilities.h"
43 //=======================================================================
46 //=======================================================================
47 SMESHDS_Mesh::SMESHDS_Mesh(int 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);
62 //=======================================================================
63 //function : AddHypothesis
65 //=======================================================================
67 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
68 const SMESHDS_Hypothesis * H)
70 list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis[SS];
72 //Check if the Hypothesis is still present
73 list<const SMESHDS_Hypothesis*>::iterator ith=alist.begin();
75 for (; ith!=alist.end(); ith++)
76 if (H == *ith) return false;
82 //=======================================================================
83 //function : RemoveHypothesis
85 //=======================================================================
87 bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S,
88 const SMESHDS_Hypothesis * H)
90 ShapeToHypothesis::iterator its=myShapeToHypothesis.find(S);
91 if(its!=myShapeToHypothesis.end())
93 list<const SMESHDS_Hypothesis*>::iterator ith=(*its).second.begin();
95 for (; ith!=(*its).second.end(); ith++)
98 (*its).second.erase(ith);
105 //=======================================================================
108 //=======================================================================
109 SMDS_MeshNode* SMESHDS_Mesh::AddNode(double x, double y, double z){
110 SMDS_MeshNode* node = SMDS_Mesh::AddNode(x, y, z);
111 if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
115 SMDS_MeshNode* SMESHDS_Mesh::AddNodeWithID(double x, double y, double z, int ID){
116 SMDS_MeshNode* node = SMDS_Mesh::AddNodeWithID(x,y,z,ID);
117 if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
121 //=======================================================================
122 //function : MoveNode
124 //=======================================================================
125 void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
127 SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
129 myScript->MoveNode(n->GetID(), x, y, z);
132 //=======================================================================
133 //function : ChangeElementNodes
135 //=======================================================================
137 bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
138 const SMDS_MeshNode * nodes[],
141 if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes ))
144 ASSERT( nbnodes < 9 );
146 for ( i = 0; i < nbnodes; i++ )
147 IDs [ i ] = nodes[ i ]->GetID();
148 myScript->ChangeElementNodes( elem->GetID(), IDs, nbnodes);
153 //=======================================================================
154 //function : Renumber
156 //=======================================================================
158 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
160 SMDS_Mesh::Renumber( isNodes, startID, deltaID );
161 myScript->Renumber( isNodes, startID, deltaID );
164 //=======================================================================
165 //function :AddEdgeWithID
167 //=======================================================================
168 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
170 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
171 if(anElem) myScript->AddEdge(ID,n1,n2);
175 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
176 const SMDS_MeshNode * n2,
179 return AddEdgeWithID(n1->GetID(),
184 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
185 const SMDS_MeshNode * n2)
187 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
188 if(anElem) myScript->AddEdge(anElem->GetID(),
194 //=======================================================================
197 //=======================================================================
198 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
200 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
201 if(anElem) myScript->AddFace(ID,n1,n2,n3);
205 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
206 const SMDS_MeshNode * n2,
207 const SMDS_MeshNode * n3,
210 return AddFaceWithID(n1->GetID(),
216 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
217 const SMDS_MeshNode * n2,
218 const SMDS_MeshNode * n3)
220 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
221 if(anElem) myScript->AddFace(anElem->GetID(),
228 //=======================================================================
231 //=======================================================================
232 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
234 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
235 if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
239 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
240 const SMDS_MeshNode * n2,
241 const SMDS_MeshNode * n3,
242 const SMDS_MeshNode * n4,
245 return AddFaceWithID(n1->GetID(),
252 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
253 const SMDS_MeshNode * n2,
254 const SMDS_MeshNode * n3,
255 const SMDS_MeshNode * n4)
257 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
258 if(anElem) myScript->AddFace(anElem->GetID(),
266 //=======================================================================
267 //function :AddVolume
269 //=======================================================================
270 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
272 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
273 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
277 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
278 const SMDS_MeshNode * n2,
279 const SMDS_MeshNode * n3,
280 const SMDS_MeshNode * n4,
283 return AddVolumeWithID(n1->GetID(),
290 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
291 const SMDS_MeshNode * n2,
292 const SMDS_MeshNode * n3,
293 const SMDS_MeshNode * n4)
295 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
296 if(anElem) myScript->AddVolume(anElem->GetID(),
304 //=======================================================================
305 //function :AddVolume
307 //=======================================================================
308 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
310 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
311 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
315 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
316 const SMDS_MeshNode * n2,
317 const SMDS_MeshNode * n3,
318 const SMDS_MeshNode * n4,
319 const SMDS_MeshNode * n5,
322 return AddVolumeWithID(n1->GetID(),
330 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
331 const SMDS_MeshNode * n2,
332 const SMDS_MeshNode * n3,
333 const SMDS_MeshNode * n4,
334 const SMDS_MeshNode * n5)
336 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
337 if(anElem) myScript->AddVolume(anElem->GetID(),
346 //=======================================================================
347 //function :AddVolume
349 //=======================================================================
350 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
352 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
353 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
357 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
358 const SMDS_MeshNode * n2,
359 const SMDS_MeshNode * n3,
360 const SMDS_MeshNode * n4,
361 const SMDS_MeshNode * n5,
362 const SMDS_MeshNode * n6,
365 return AddVolumeWithID(n1->GetID(),
374 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
375 const SMDS_MeshNode * n2,
376 const SMDS_MeshNode * n3,
377 const SMDS_MeshNode * n4,
378 const SMDS_MeshNode * n5,
379 const SMDS_MeshNode * n6)
381 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
382 if(anElem) myScript->AddVolume(anElem->GetID(),
392 //=======================================================================
393 //function :AddVolume
395 //=======================================================================
396 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
398 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
399 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
403 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
404 const SMDS_MeshNode * n2,
405 const SMDS_MeshNode * n3,
406 const SMDS_MeshNode * n4,
407 const SMDS_MeshNode * n5,
408 const SMDS_MeshNode * n6,
409 const SMDS_MeshNode * n7,
410 const SMDS_MeshNode * n8,
413 return AddVolumeWithID(n1->GetID(),
424 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
425 const SMDS_MeshNode * n2,
426 const SMDS_MeshNode * n3,
427 const SMDS_MeshNode * n4,
428 const SMDS_MeshNode * n5,
429 const SMDS_MeshNode * n6,
430 const SMDS_MeshNode * n7,
431 const SMDS_MeshNode * n8)
433 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
434 if(anElem) myScript->AddVolume(anElem->GetID(),
445 //=======================================================================
446 //function : removeFromContainers
448 //=======================================================================
450 static void removeFromContainers (map<int,SMESHDS_SubMesh*> & theSubMeshes,
451 set<SMESHDS_Group*>& theGroups,
452 list<const SMDS_MeshElement *> & theElems,
455 if ( theElems.empty() )
459 // Element can belong to several groups
460 if ( !theGroups.empty() )
462 set<SMESHDS_Group*>::iterator GrIt = theGroups.begin();
463 for ( ; GrIt != theGroups.end(); GrIt++ )
465 SMESHDS_Group* group = *GrIt;
466 if ( group->IsEmpty() ) continue;
468 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
469 for ( ; elIt != theElems.end(); elIt++ )
471 (*GrIt)->SMDS_MeshGroup::Remove( *elIt );
472 if ( group->IsEmpty() ) break;
477 // Rm from sub-meshes
478 // Element should belong to only one sub-mesh
479 map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
480 for ( ; SubIt != theSubMeshes.end(); SubIt++ )
482 int size = isNode ? (*SubIt).second->NbNodes() : (*SubIt).second->NbElements();
483 if ( size == 0 ) continue;
485 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
486 while ( elIt != theElems.end() )
488 bool removed = false;
490 removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
492 removed = (*SubIt).second->RemoveElement( *elIt );
496 elIt = theElems.erase( elIt );
497 if ( theElems.empty() )
498 return; // all elements are found and removed
508 //=======================================================================
509 //function : RemoveNode
511 //=======================================================================
512 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
514 myScript->RemoveNode(n->GetID());
516 list<const SMDS_MeshElement *> removedElems;
517 list<const SMDS_MeshElement *> removedNodes;
519 SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
521 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
522 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
525 //=======================================================================
526 //function : RemoveElement
528 //========================================================================
529 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
531 if (elt->GetType() == SMDSAbs_Node)
533 RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
537 myScript->RemoveElement(elt->GetID());
539 list<const SMDS_MeshElement *> removedElems;
540 list<const SMDS_MeshElement *> removedNodes;
542 SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
544 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
547 //=======================================================================
548 //function : SetNodeOnVolume
550 //=======================================================================
551 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
552 const TopoDS_Shell & S)
554 if (myShape.IsNull()) MESSAGE("myShape is NULL");
556 int Index = myIndexToShape.FindIndex(S);
558 //Set Position on Node
559 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
560 //aNode->SetPosition(aPos);
562 //Update or build submesh
563 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
564 if (it==myShapeIndexToSubMesh.end())
565 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
567 myShapeIndexToSubMesh[Index]->AddNode(aNode);
570 //=======================================================================
571 //function : SetNodeOnFace
573 //=======================================================================
574 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode * aNode,
575 const TopoDS_Face & S)
577 if (myShape.IsNull()) MESSAGE("myShape is NULL");
579 int Index = myIndexToShape.FindIndex(S);
581 //Set Position on Node
582 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
584 //Update or build submesh
585 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
586 if (it==myShapeIndexToSubMesh.end())
587 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
589 myShapeIndexToSubMesh[Index]->AddNode(aNode);
592 //=======================================================================
593 //function : SetNodeOnEdge
595 //=======================================================================
596 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode * aNode,
597 const TopoDS_Edge & S)
599 if (myShape.IsNull()) MESSAGE("myShape is NULL");
601 int Index = myIndexToShape.FindIndex(S);
603 //Set Position on Node
604 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
606 //Update or build submesh
607 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
608 if (it==myShapeIndexToSubMesh.end())
609 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
611 myShapeIndexToSubMesh[Index]->AddNode(aNode);
614 //=======================================================================
615 //function : SetNodeOnVertex
617 //=======================================================================
618 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode * aNode,
619 const TopoDS_Vertex & S)
621 if (myShape.IsNull()) MESSAGE("myShape is NULL");
623 int Index = myIndexToShape.FindIndex(S);
625 //Set Position on Node
626 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
628 //Update or build submesh
629 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
630 if (it==myShapeIndexToSubMesh.end())
631 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
633 myShapeIndexToSubMesh[Index]->AddNode(aNode);
636 //=======================================================================
637 //function : UnSetNodeOnShape
639 //=======================================================================
640 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
642 MESSAGE("not implemented");
645 //=======================================================================
646 //function : SetMeshElementOnShape
648 //=======================================================================
649 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
650 const TopoDS_Shape & S)
652 if (myShape.IsNull()) MESSAGE("myShape is NULL");
654 int Index = myIndexToShape.FindIndex(S);
656 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
657 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
659 myShapeIndexToSubMesh[Index]->AddElement(anElement);
662 //=======================================================================
663 //function : UnSetMeshElementOnShape
665 //=======================================================================
667 UnSetMeshElementOnShape(const SMDS_MeshElement * anElement,
668 const TopoDS_Shape & S)
670 if (myShape.IsNull()) MESSAGE("myShape is NULL");
672 int Index = myIndexToShape.FindIndex(S);
674 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
675 myShapeIndexToSubMesh[Index]->RemoveElement(anElement);
678 //=======================================================================
679 //function : ShapeToMesh
681 //=======================================================================
682 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
687 //=======================================================================
688 //function : IsGroupOfSubShapes
690 //=======================================================================
692 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const
694 if ( aSubShape.ShapeType() != TopAbs_COMPOUND || myShape.IsSame( aSubShape ))
697 for ( TopoDS_Iterator it( aSubShape ); it.More(); it.Next() )
698 if ( !myIndexToShape.Contains( it.Value() ))
704 ///////////////////////////////////////////////////////////////////////////////
705 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
706 /// TopoDS_Shape is unknown
707 ///////////////////////////////////////////////////////////////////////////////
708 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S)
710 if (myShape.IsNull()) MESSAGE("myShape is NULL");
712 int Index = ShapeToIndex(S);
713 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
714 return myShapeIndexToSubMesh[Index];
719 ///////////////////////////////////////////////////////////////////////////////
720 /// Return the sub mesh by Id of shape it is linked to
721 ///////////////////////////////////////////////////////////////////////////////
722 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
724 if (myShape.IsNull()) MESSAGE("myShape is NULL");
726 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
727 return myShapeIndexToSubMesh[Index];
732 //=======================================================================
733 //function : SubMeshIndices
735 //=======================================================================
736 list<int> SMESHDS_Mesh::SubMeshIndices()
739 std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
740 for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
741 anIndices.push_back((*anIter).first);
746 //=======================================================================
747 //function : GetHypothesis
749 //=======================================================================
751 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
752 const TopoDS_Shape & S) const
754 if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
755 return myShapeToHypothesis.find(S)->second;
757 static list<const SMESHDS_Hypothesis*> empty;
761 //=======================================================================
762 //function : GetScript
764 //=======================================================================
765 SMESHDS_Script* SMESHDS_Mesh::GetScript()
770 //=======================================================================
771 //function : ClearScript
773 //=======================================================================
774 void SMESHDS_Mesh::ClearScript()
779 //=======================================================================
780 //function : HasMeshElements
782 //=======================================================================
783 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
785 if (myShape.IsNull()) MESSAGE("myShape is NULL");
786 int Index = myIndexToShape.FindIndex(S);
787 return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
790 //=======================================================================
791 //function : HasHypothesis
793 //=======================================================================
794 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
796 return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
799 //=======================================================================
800 //function : NewSubMesh
802 //=======================================================================
803 void SMESHDS_Mesh::NewSubMesh(int Index)
805 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
807 SMESHDS_SubMesh* SM = new SMESHDS_SubMesh();
808 myShapeIndexToSubMesh[Index]=SM;
812 //=======================================================================
813 //function : IndexToShape
815 //=======================================================================
816 TopoDS_Shape SMESHDS_Mesh::IndexToShape(int ShapeIndex)
818 return myIndexToShape.FindKey(ShapeIndex);
821 //=======================================================================
822 //function : ShapeToIndex
824 //=======================================================================
825 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S)
827 if (myShape.IsNull())
828 MESSAGE("myShape is NULL");
830 int index = myIndexToShape.FindIndex(S);
831 if ( index == 0 && IsGroupOfSubShapes( S ))
833 index = myIndexToShape.Add( S );
834 SMESHDS_SubMesh* aSubMesh = new SMESHDS_SubMesh;
835 myShapeIndexToSubMesh[index] = aSubMesh;
837 for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
839 int subIndex = myIndexToShape.FindIndex( it.Value() );
840 NewSubMesh( subIndex );
841 aSubMesh->AddSubMesh( MeshElements( subIndex ));
848 //=======================================================================
849 //function : SetNodeOnVolume
851 //=======================================================================
852 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
854 //Set Position on Node
855 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
856 //aNode->SetPosition(aPos);
858 //Update or build submesh
859 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
860 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
862 myShapeIndexToSubMesh[Index]->AddNode(aNode);
865 //=======================================================================
866 //function : SetNodeOnFace
868 //=======================================================================
869 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index)
871 //Set Position on Node
872 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
874 //Update or build submesh
875 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
876 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
878 myShapeIndexToSubMesh[Index]->AddNode(aNode);
881 //=======================================================================
882 //function : SetNodeOnEdge
884 //=======================================================================
885 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode, int Index)
887 //Set Position on Node
888 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
890 //Update or build submesh
891 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
892 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
894 myShapeIndexToSubMesh[Index]->AddNode(aNode);
897 //=======================================================================
898 //function : SetNodeOnVertex
900 //=======================================================================
901 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
903 //Set Position on Node
904 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
906 //Update or build submesh
907 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
908 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
910 myShapeIndexToSubMesh[Index]->AddNode(aNode);
913 //=======================================================================
914 //function : SetMeshElementOnShape
916 //=======================================================================
917 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
920 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
921 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
923 myShapeIndexToSubMesh[Index]->AddElement(anElement);
926 SMESHDS_Mesh::~SMESHDS_Mesh()