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_GroupBase*>& 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_GroupBase*>::iterator GrIt = theGroups.begin();
463 for ( ; GrIt != theGroups.end(); GrIt++ )
465 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
466 if ( !group || group->IsEmpty() ) continue;
468 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
469 for ( ; elIt != theElems.end(); elIt++ )
471 group->SMDSGroup().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
689 //purpose : return true if at least one subshape of theShape is a subshape
690 // of myShape or theShape == myShape
691 //=======================================================================
693 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
695 if ( myShape.IsSame( theShape ))
698 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() ) {
699 if (myIndexToShape.Contains( it.Value() ) ||
700 IsGroupOfSubShapes( it.Value() ))
707 ///////////////////////////////////////////////////////////////////////////////
708 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
709 /// TopoDS_Shape is unknown
710 ///////////////////////////////////////////////////////////////////////////////
711 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S)
713 if (myShape.IsNull()) MESSAGE("myShape is NULL");
715 int Index = ShapeToIndex(S);
716 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
717 return myShapeIndexToSubMesh[Index];
722 ///////////////////////////////////////////////////////////////////////////////
723 /// Return the sub mesh by Id of shape it is linked to
724 ///////////////////////////////////////////////////////////////////////////////
725 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
727 if (myShape.IsNull()) MESSAGE("myShape is NULL");
729 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
730 return myShapeIndexToSubMesh[Index];
735 //=======================================================================
736 //function : SubMeshIndices
738 //=======================================================================
739 list<int> SMESHDS_Mesh::SubMeshIndices()
742 std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
743 for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
744 anIndices.push_back((*anIter).first);
749 //=======================================================================
750 //function : GetHypothesis
752 //=======================================================================
754 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
755 const TopoDS_Shape & S) const
757 if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
758 return myShapeToHypothesis.find(S)->second;
760 static list<const SMESHDS_Hypothesis*> empty;
764 //=======================================================================
765 //function : GetScript
767 //=======================================================================
768 SMESHDS_Script* SMESHDS_Mesh::GetScript()
773 //=======================================================================
774 //function : ClearScript
776 //=======================================================================
777 void SMESHDS_Mesh::ClearScript()
782 //=======================================================================
783 //function : HasMeshElements
785 //=======================================================================
786 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
788 if (myShape.IsNull()) MESSAGE("myShape is NULL");
789 int Index = myIndexToShape.FindIndex(S);
790 return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
793 //=======================================================================
794 //function : HasHypothesis
796 //=======================================================================
797 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
799 return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
802 //=======================================================================
803 //function : NewSubMesh
805 //=======================================================================
806 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
808 SMESHDS_SubMesh* SM = 0;
809 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
811 SM = new SMESHDS_SubMesh();
812 myShapeIndexToSubMesh[Index]=SM;
815 SM = myShapeIndexToSubMesh[Index];
819 //=======================================================================
820 //function : AddCompoundSubmesh
822 //=======================================================================
824 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
825 TopAbs_ShapeEnum type)
828 if ( IsGroupOfSubShapes( S ))
830 aMainIndex = myIndexToShape.Add( S );
831 bool all = ( type == TopAbs_SHAPE );
832 if ( all ) // corresponding simple submesh may exist
833 aMainIndex = -aMainIndex;
834 //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
835 SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
836 if ( !aNewSub->IsComplexSubmesh() ) // is empty
838 int shapeType = all ? myShape.ShapeType() : type;
839 int typeLimit = all ? TopAbs_VERTEX : type;
840 for ( ; shapeType <= typeLimit; shapeType++ )
842 TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
843 for ( ; exp.More(); exp.Next() )
845 int index = myIndexToShape.FindIndex( exp.Current() );
847 aNewSub->AddSubMesh( NewSubMesh( index ));
855 //=======================================================================
856 //function : IndexToShape
858 //=======================================================================
859 TopoDS_Shape SMESHDS_Mesh::IndexToShape(int ShapeIndex)
861 return myIndexToShape.FindKey(ShapeIndex);
864 //=======================================================================
865 //function : ShapeToIndex
867 //=======================================================================
868 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S)
870 if (myShape.IsNull())
871 MESSAGE("myShape is NULL");
873 int index = myIndexToShape.FindIndex(S);
878 //=======================================================================
879 //function : SetNodeOnVolume
881 //=======================================================================
882 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
884 //Set Position on Node
885 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
886 //aNode->SetPosition(aPos);
888 //Update or build submesh
889 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
890 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
892 myShapeIndexToSubMesh[Index]->AddNode(aNode);
895 //=======================================================================
896 //function : SetNodeOnFace
898 //=======================================================================
899 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index)
901 //Set Position on Node
902 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
904 //Update or build submesh
905 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
906 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
908 myShapeIndexToSubMesh[Index]->AddNode(aNode);
911 //=======================================================================
912 //function : SetNodeOnEdge
914 //=======================================================================
915 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode, int Index)
917 //Set Position on Node
918 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
920 //Update or build submesh
921 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
922 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
924 myShapeIndexToSubMesh[Index]->AddNode(aNode);
927 //=======================================================================
928 //function : SetNodeOnVertex
930 //=======================================================================
931 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
933 //Set Position on Node
934 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
936 //Update or build submesh
937 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
938 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
940 myShapeIndexToSubMesh[Index]->AddNode(aNode);
943 //=======================================================================
944 //function : SetMeshElementOnShape
946 //=======================================================================
947 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
950 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
951 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
953 myShapeIndexToSubMesh[Index]->AddElement(anElement);
956 SMESHDS_Mesh::~SMESHDS_Mesh()