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 );
177 int i, IDs[ nbnodes ];
180 IDs = new int[ nbnodes];
182 for ( i = 0; i < nbnodes; i++ )
183 IDs [ i ] = nodes[ i ]->GetID();
184 myScript->ChangeElementNodes( elem->GetID(), IDs, nbnodes);
193 //=======================================================================
194 //function : ChangePolygonNodes
196 //=======================================================================
197 bool SMESHDS_Mesh::ChangePolygonNodes
198 (const SMDS_MeshElement * elem,
199 std::vector<const SMDS_MeshNode*> nodes)
201 ASSERT(nodes.size() > 3);
203 int nb = nodes.size();
205 const SMDS_MeshNode* nodes_array [nb];
207 const SMDS_MeshNode** nodes_array = (const SMDS_MeshNode **)new SMDS_MeshNode*[nb];
209 for (int inode = 0; inode < nb; inode++) {
210 nodes_array[inode] = nodes[inode];
213 return ChangeElementNodes(elem, nodes_array, nb);
215 bool aRes = ChangeElementNodes(elem, nodes_array, nb);
216 delete [] nodes_array;
221 //=======================================================================
222 //function : ChangePolyhedronNodes
224 //=======================================================================
225 bool SMESHDS_Mesh::ChangePolyhedronNodes
226 (const SMDS_MeshElement * elem,
227 std::vector<const SMDS_MeshNode*> nodes,
228 std::vector<int> quantities)
230 ASSERT(nodes.size() > 3);
232 if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
235 int i, len = nodes.size();
236 std::vector<int> nodes_ids (len);
237 for (i = 0; i < len; i++) {
238 nodes_ids[i] = nodes[i]->GetID();
240 myScript->ChangePolyhedronNodes(elem->GetID(), nodes_ids, quantities);
245 //=======================================================================
246 //function : Renumber
248 //=======================================================================
250 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
252 SMDS_Mesh::Renumber( isNodes, startID, deltaID );
253 myScript->Renumber( isNodes, startID, deltaID );
256 //=======================================================================
257 //function :AddEdgeWithID
259 //=======================================================================
260 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
262 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
263 if(anElem) myScript->AddEdge(ID,n1,n2);
267 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
268 const SMDS_MeshNode * n2,
271 return AddEdgeWithID(n1->GetID(),
276 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
277 const SMDS_MeshNode * n2)
279 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
280 if(anElem) myScript->AddEdge(anElem->GetID(),
286 //=======================================================================
289 //=======================================================================
290 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
292 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
293 if(anElem) myScript->AddFace(ID,n1,n2,n3);
297 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
298 const SMDS_MeshNode * n2,
299 const SMDS_MeshNode * n3,
302 return AddFaceWithID(n1->GetID(),
308 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
309 const SMDS_MeshNode * n2,
310 const SMDS_MeshNode * n3)
312 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
313 if(anElem) myScript->AddFace(anElem->GetID(),
320 //=======================================================================
323 //=======================================================================
324 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
326 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
327 if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
331 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
332 const SMDS_MeshNode * n2,
333 const SMDS_MeshNode * n3,
334 const SMDS_MeshNode * n4,
337 return AddFaceWithID(n1->GetID(),
344 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
345 const SMDS_MeshNode * n2,
346 const SMDS_MeshNode * n3,
347 const SMDS_MeshNode * n4)
349 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
350 if(anElem) myScript->AddFace(anElem->GetID(),
358 //=======================================================================
359 //function :AddVolume
361 //=======================================================================
362 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
364 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
365 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
369 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
370 const SMDS_MeshNode * n2,
371 const SMDS_MeshNode * n3,
372 const SMDS_MeshNode * n4,
375 return AddVolumeWithID(n1->GetID(),
382 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
383 const SMDS_MeshNode * n2,
384 const SMDS_MeshNode * n3,
385 const SMDS_MeshNode * n4)
387 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
388 if(anElem) myScript->AddVolume(anElem->GetID(),
396 //=======================================================================
397 //function :AddVolume
399 //=======================================================================
400 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
402 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
403 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
407 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
408 const SMDS_MeshNode * n2,
409 const SMDS_MeshNode * n3,
410 const SMDS_MeshNode * n4,
411 const SMDS_MeshNode * n5,
414 return AddVolumeWithID(n1->GetID(),
422 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
423 const SMDS_MeshNode * n2,
424 const SMDS_MeshNode * n3,
425 const SMDS_MeshNode * n4,
426 const SMDS_MeshNode * n5)
428 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
429 if(anElem) myScript->AddVolume(anElem->GetID(),
438 //=======================================================================
439 //function :AddVolume
441 //=======================================================================
442 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
444 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
445 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
449 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
450 const SMDS_MeshNode * n2,
451 const SMDS_MeshNode * n3,
452 const SMDS_MeshNode * n4,
453 const SMDS_MeshNode * n5,
454 const SMDS_MeshNode * n6,
457 return AddVolumeWithID(n1->GetID(),
466 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
467 const SMDS_MeshNode * n2,
468 const SMDS_MeshNode * n3,
469 const SMDS_MeshNode * n4,
470 const SMDS_MeshNode * n5,
471 const SMDS_MeshNode * n6)
473 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
474 if(anElem) myScript->AddVolume(anElem->GetID(),
484 //=======================================================================
485 //function :AddVolume
487 //=======================================================================
488 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
490 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
491 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
495 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
496 const SMDS_MeshNode * n2,
497 const SMDS_MeshNode * n3,
498 const SMDS_MeshNode * n4,
499 const SMDS_MeshNode * n5,
500 const SMDS_MeshNode * n6,
501 const SMDS_MeshNode * n7,
502 const SMDS_MeshNode * n8,
505 return AddVolumeWithID(n1->GetID(),
516 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
517 const SMDS_MeshNode * n2,
518 const SMDS_MeshNode * n3,
519 const SMDS_MeshNode * n4,
520 const SMDS_MeshNode * n5,
521 const SMDS_MeshNode * n6,
522 const SMDS_MeshNode * n7,
523 const SMDS_MeshNode * n8)
525 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
526 if(anElem) myScript->AddVolume(anElem->GetID(),
538 //=======================================================================
539 //function : AddPolygonalFace
541 //=======================================================================
542 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
545 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes_ids, ID);
547 myScript->AddPolygonalFace(ID, nodes_ids);
552 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
553 (std::vector<const SMDS_MeshNode*> nodes,
556 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
558 int i, len = nodes.size();
559 std::vector<int> nodes_ids (len);
560 for (i = 0; i < len; i++) {
561 nodes_ids[i] = nodes[i]->GetID();
563 myScript->AddPolygonalFace(ID, nodes_ids);
568 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
569 (std::vector<const SMDS_MeshNode*> nodes)
571 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
573 int i, len = nodes.size();
574 std::vector<int> nodes_ids (len);
575 for (i = 0; i < len; i++) {
576 nodes_ids[i] = nodes[i]->GetID();
578 myScript->AddPolygonalFace(anElem->GetID(), nodes_ids);
583 //=======================================================================
584 //function : AddPolyhedralVolume
586 //=======================================================================
587 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (std::vector<int> nodes_ids,
588 std::vector<int> quantities,
591 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes_ids, quantities, ID);
593 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
598 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID
599 (std::vector<const SMDS_MeshNode*> nodes,
600 std::vector<int> quantities,
603 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
605 int i, len = nodes.size();
606 std::vector<int> nodes_ids (len);
607 for (i = 0; i < len; i++) {
608 nodes_ids[i] = nodes[i]->GetID();
610 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
615 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume
616 (std::vector<const SMDS_MeshNode*> nodes,
617 std::vector<int> quantities)
619 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities);
621 int i, len = nodes.size();
622 std::vector<int> nodes_ids (len);
623 for (i = 0; i < len; i++) {
624 nodes_ids[i] = nodes[i]->GetID();
626 myScript->AddPolyhedralVolume(anElem->GetID(), nodes_ids, quantities);
631 //=======================================================================
632 //function : removeFromContainers
634 //=======================================================================
636 static void removeFromContainers (map<int,SMESHDS_SubMesh*> & theSubMeshes,
637 set<SMESHDS_GroupBase*>& theGroups,
638 list<const SMDS_MeshElement *> & theElems,
641 if ( theElems.empty() )
645 // Element can belong to several groups
646 if ( !theGroups.empty() )
648 set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
649 for ( ; GrIt != theGroups.end(); GrIt++ )
651 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
652 if ( !group || group->IsEmpty() ) continue;
654 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
655 for ( ; elIt != theElems.end(); elIt++ )
657 group->SMDSGroup().Remove( *elIt );
658 if ( group->IsEmpty() ) break;
663 // Rm from sub-meshes
664 // Element should belong to only one sub-mesh
665 map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
666 for ( ; SubIt != theSubMeshes.end(); SubIt++ )
668 int size = isNode ? (*SubIt).second->NbNodes() : (*SubIt).second->NbElements();
669 if ( size == 0 ) continue;
671 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
672 while ( elIt != theElems.end() )
674 bool removed = false;
676 removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
678 removed = (*SubIt).second->RemoveElement( *elIt );
682 elIt = theElems.erase( elIt );
683 if ( theElems.empty() )
684 return; // all elements are found and removed
694 //=======================================================================
695 //function : RemoveNode
697 //=======================================================================
698 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
700 myScript->RemoveNode(n->GetID());
702 list<const SMDS_MeshElement *> removedElems;
703 list<const SMDS_MeshElement *> removedNodes;
705 SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
707 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
708 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
711 //=======================================================================
712 //function : RemoveElement
714 //========================================================================
715 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
717 if (elt->GetType() == SMDSAbs_Node)
719 RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
723 myScript->RemoveElement(elt->GetID());
725 list<const SMDS_MeshElement *> removedElems;
726 list<const SMDS_MeshElement *> removedNodes;
728 SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
730 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
733 //=======================================================================
734 //function : SetNodeOnVolume
736 //=======================================================================
737 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
738 const TopoDS_Shell & S)
740 if (myShape.IsNull()) MESSAGE("myShape is NULL");
742 int Index = myIndexToShape.FindIndex(S);
744 //Set Position on Node
745 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
746 //aNode->SetPosition(aPos);
748 //Update or build submesh
749 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
750 if (it==myShapeIndexToSubMesh.end())
751 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
753 myShapeIndexToSubMesh[Index]->AddNode(aNode);
756 //=======================================================================
757 //function : SetNodeOnFace
759 //=======================================================================
760 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode * aNode,
761 const TopoDS_Face & S)
763 if (myShape.IsNull()) MESSAGE("myShape is NULL");
765 int Index = myIndexToShape.FindIndex(S);
767 //Set Position on Node
768 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
770 //Update or build submesh
771 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
772 if (it==myShapeIndexToSubMesh.end())
773 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
775 myShapeIndexToSubMesh[Index]->AddNode(aNode);
778 //=======================================================================
779 //function : SetNodeOnEdge
781 //=======================================================================
782 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode * aNode,
783 const TopoDS_Edge & S)
785 if (myShape.IsNull()) MESSAGE("myShape is NULL");
787 int Index = myIndexToShape.FindIndex(S);
789 //Set Position on Node
790 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
792 //Update or build submesh
793 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
794 if (it==myShapeIndexToSubMesh.end())
795 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
797 myShapeIndexToSubMesh[Index]->AddNode(aNode);
800 //=======================================================================
801 //function : SetNodeOnVertex
803 //=======================================================================
804 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode * aNode,
805 const TopoDS_Vertex & S)
807 if (myShape.IsNull()) MESSAGE("myShape is NULL");
809 int Index = myIndexToShape.FindIndex(S);
811 //Set Position on Node
812 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
814 //Update or build submesh
815 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
816 if (it==myShapeIndexToSubMesh.end())
817 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
819 myShapeIndexToSubMesh[Index]->AddNode(aNode);
822 //=======================================================================
823 //function : UnSetNodeOnShape
825 //=======================================================================
826 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
828 MESSAGE("not implemented");
831 //=======================================================================
832 //function : SetMeshElementOnShape
834 //=======================================================================
835 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
836 const TopoDS_Shape & S)
838 if (myShape.IsNull()) MESSAGE("myShape is NULL");
840 int Index = myIndexToShape.FindIndex(S);
842 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
843 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
845 myShapeIndexToSubMesh[Index]->AddElement(anElement);
848 //=======================================================================
849 //function : UnSetMeshElementOnShape
851 //=======================================================================
853 UnSetMeshElementOnShape(const SMDS_MeshElement * anElement,
854 const TopoDS_Shape & S)
856 if (myShape.IsNull()) MESSAGE("myShape is NULL");
858 int Index = myIndexToShape.FindIndex(S);
860 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
861 myShapeIndexToSubMesh[Index]->RemoveElement(anElement);
864 //=======================================================================
865 //function : ShapeToMesh
867 //=======================================================================
868 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
873 //=======================================================================
874 //function : IsGroupOfSubShapes
875 //purpose : return true if at least one subshape of theShape is a subshape
876 // of myShape or theShape == myShape
877 //=======================================================================
879 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
881 if ( myShape.IsSame( theShape ))
884 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() ) {
885 if (myIndexToShape.Contains( it.Value() ) ||
886 IsGroupOfSubShapes( it.Value() ))
893 ///////////////////////////////////////////////////////////////////////////////
894 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
895 /// TopoDS_Shape is unknown
896 ///////////////////////////////////////////////////////////////////////////////
897 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const
899 if (myShape.IsNull()) MESSAGE("myShape is NULL");
901 int Index = ShapeToIndex(S);
902 TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
903 if (anIter != myShapeIndexToSubMesh.end())
904 return anIter->second;
909 ///////////////////////////////////////////////////////////////////////////////
910 /// Return the sub mesh by Id of shape it is linked to
911 ///////////////////////////////////////////////////////////////////////////////
912 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
914 if (myShape.IsNull()) MESSAGE("myShape is NULL");
916 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
917 return myShapeIndexToSubMesh[Index];
922 //=======================================================================
923 //function : SubMeshIndices
925 //=======================================================================
926 list<int> SMESHDS_Mesh::SubMeshIndices()
929 std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
930 for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
931 anIndices.push_back((*anIter).first);
936 //=======================================================================
937 //function : GetHypothesis
939 //=======================================================================
941 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
942 const TopoDS_Shape & S) const
944 if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
945 return myShapeToHypothesis.find(S)->second;
947 static list<const SMESHDS_Hypothesis*> empty;
951 //=======================================================================
952 //function : GetScript
954 //=======================================================================
955 SMESHDS_Script* SMESHDS_Mesh::GetScript()
960 //=======================================================================
961 //function : ClearScript
963 //=======================================================================
964 void SMESHDS_Mesh::ClearScript()
969 //=======================================================================
970 //function : HasMeshElements
972 //=======================================================================
973 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
975 if (myShape.IsNull()) MESSAGE("myShape is NULL");
976 int Index = myIndexToShape.FindIndex(S);
977 return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
980 //=======================================================================
981 //function : HasHypothesis
983 //=======================================================================
984 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
986 return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
989 //=======================================================================
990 //function : NewSubMesh
992 //=======================================================================
993 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
995 SMESHDS_SubMesh* SM = 0;
996 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
998 SM = new SMESHDS_SubMesh();
999 myShapeIndexToSubMesh[Index]=SM;
1002 SM = myShapeIndexToSubMesh[Index];
1006 //=======================================================================
1007 //function : AddCompoundSubmesh
1009 //=======================================================================
1011 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
1012 TopAbs_ShapeEnum type)
1015 if ( IsGroupOfSubShapes( S ) || (S.ShapeType() == TopAbs_VERTEX && myIndexToShape.Contains(S)) )
1017 aMainIndex = myIndexToShape.Add( S );
1018 bool all = ( type == TopAbs_SHAPE );
1019 if ( all ) // corresponding simple submesh may exist
1020 aMainIndex = -aMainIndex;
1021 //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
1022 SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
1023 if ( !aNewSub->IsComplexSubmesh() ) // is empty
1025 int shapeType = all ? myShape.ShapeType() : type;
1026 int typeLimit = all ? TopAbs_VERTEX : type;
1027 for ( ; shapeType <= typeLimit; shapeType++ )
1029 TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
1030 for ( ; exp.More(); exp.Next() )
1032 int index = myIndexToShape.FindIndex( exp.Current() );
1034 aNewSub->AddSubMesh( NewSubMesh( index ));
1042 //=======================================================================
1043 //function : IndexToShape
1045 //=======================================================================
1046 TopoDS_Shape SMESHDS_Mesh::IndexToShape(int ShapeIndex)
1048 return myIndexToShape.FindKey(ShapeIndex);
1051 //=======================================================================
1052 //function : ShapeToIndex
1054 //=======================================================================
1055 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
1057 if (myShape.IsNull())
1058 MESSAGE("myShape is NULL");
1060 int index = myIndexToShape.FindIndex(S);
1065 //=======================================================================
1066 //function : SetNodeOnVolume
1068 //=======================================================================
1069 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
1071 //Set Position on Node
1072 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
1073 //aNode->SetPosition(aPos);
1075 //Update or build submesh
1076 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1077 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1079 myShapeIndexToSubMesh[Index]->AddNode(aNode);
1082 //=======================================================================
1083 //function : SetNodeOnFace
1085 //=======================================================================
1086 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index)
1088 //Set Position on Node
1089 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
1091 //Update or build submesh
1092 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1093 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1095 myShapeIndexToSubMesh[Index]->AddNode(aNode);
1098 //=======================================================================
1099 //function : SetNodeOnEdge
1101 //=======================================================================
1102 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode, int Index)
1104 //Set Position on Node
1105 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
1107 //Update or build submesh
1108 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1109 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1111 myShapeIndexToSubMesh[Index]->AddNode(aNode);
1114 //=======================================================================
1115 //function : SetNodeOnVertex
1117 //=======================================================================
1118 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
1120 //Set Position on Node
1121 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
1123 //Update or build submesh
1124 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1125 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1127 myShapeIndexToSubMesh[Index]->AddNode(aNode);
1130 //=======================================================================
1131 //function : SetMeshElementOnShape
1133 //=======================================================================
1134 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
1137 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1138 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1140 myShapeIndexToSubMesh[Index]->AddElement(anElement);
1143 SMESHDS_Mesh::~SMESHDS_Mesh()