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 int i, IDs[ nbnodes ];
177 for ( i = 0; i < nbnodes; i++ )
178 IDs [ i ] = nodes[ i ]->GetID();
179 myScript->ChangeElementNodes( elem->GetID(), IDs, nbnodes);
184 //=======================================================================
185 //function : ChangePolygonNodes
187 //=======================================================================
188 bool SMESHDS_Mesh::ChangePolygonNodes
189 (const SMDS_MeshElement * elem,
190 std::vector<const SMDS_MeshNode*> nodes)
192 ASSERT(nodes.size() > 3);
194 int nb = nodes.size();
195 const SMDS_MeshNode* nodes_array [nb];
196 for (int inode = 0; inode < nb; inode++) {
197 nodes_array[inode] = nodes[inode];
200 return ChangeElementNodes(elem, nodes_array, nb);
203 //=======================================================================
204 //function : ChangePolyhedronNodes
206 //=======================================================================
207 bool SMESHDS_Mesh::ChangePolyhedronNodes
208 (const SMDS_MeshElement * elem,
209 std::vector<const SMDS_MeshNode*> nodes,
210 std::vector<int> quantities)
212 ASSERT(nodes.size() > 3);
214 if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
217 int i, len = nodes.size();
218 std::vector<int> nodes_ids (len);
219 for (i = 0; i < len; i++) {
220 nodes_ids[i] = nodes[i]->GetID();
222 myScript->ChangePolyhedronNodes(elem->GetID(), nodes_ids, quantities);
227 //=======================================================================
228 //function : Renumber
230 //=======================================================================
232 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
234 SMDS_Mesh::Renumber( isNodes, startID, deltaID );
235 myScript->Renumber( isNodes, startID, deltaID );
238 //=======================================================================
239 //function :AddEdgeWithID
241 //=======================================================================
242 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
244 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
245 if(anElem) myScript->AddEdge(ID,n1,n2);
249 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
250 const SMDS_MeshNode * n2,
253 return AddEdgeWithID(n1->GetID(),
258 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
259 const SMDS_MeshNode * n2)
261 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
262 if(anElem) myScript->AddEdge(anElem->GetID(),
268 //=======================================================================
271 //=======================================================================
272 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
274 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
275 if(anElem) myScript->AddFace(ID,n1,n2,n3);
279 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
280 const SMDS_MeshNode * n2,
281 const SMDS_MeshNode * n3,
284 return AddFaceWithID(n1->GetID(),
290 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
291 const SMDS_MeshNode * n2,
292 const SMDS_MeshNode * n3)
294 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
295 if(anElem) myScript->AddFace(anElem->GetID(),
302 //=======================================================================
305 //=======================================================================
306 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
308 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
309 if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
313 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
314 const SMDS_MeshNode * n2,
315 const SMDS_MeshNode * n3,
316 const SMDS_MeshNode * n4,
319 return AddFaceWithID(n1->GetID(),
326 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
327 const SMDS_MeshNode * n2,
328 const SMDS_MeshNode * n3,
329 const SMDS_MeshNode * n4)
331 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
332 if(anElem) myScript->AddFace(anElem->GetID(),
340 //=======================================================================
341 //function :AddVolume
343 //=======================================================================
344 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
346 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
347 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
351 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
352 const SMDS_MeshNode * n2,
353 const SMDS_MeshNode * n3,
354 const SMDS_MeshNode * n4,
357 return AddVolumeWithID(n1->GetID(),
364 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
365 const SMDS_MeshNode * n2,
366 const SMDS_MeshNode * n3,
367 const SMDS_MeshNode * n4)
369 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
370 if(anElem) myScript->AddVolume(anElem->GetID(),
378 //=======================================================================
379 //function :AddVolume
381 //=======================================================================
382 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
384 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
385 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
389 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
390 const SMDS_MeshNode * n2,
391 const SMDS_MeshNode * n3,
392 const SMDS_MeshNode * n4,
393 const SMDS_MeshNode * n5,
396 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)
410 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
411 if(anElem) myScript->AddVolume(anElem->GetID(),
420 //=======================================================================
421 //function :AddVolume
423 //=======================================================================
424 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
426 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
427 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
431 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
432 const SMDS_MeshNode * n2,
433 const SMDS_MeshNode * n3,
434 const SMDS_MeshNode * n4,
435 const SMDS_MeshNode * n5,
436 const SMDS_MeshNode * n6,
439 return AddVolumeWithID(n1->GetID(),
448 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
449 const SMDS_MeshNode * n2,
450 const SMDS_MeshNode * n3,
451 const SMDS_MeshNode * n4,
452 const SMDS_MeshNode * n5,
453 const SMDS_MeshNode * n6)
455 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
456 if(anElem) myScript->AddVolume(anElem->GetID(),
466 //=======================================================================
467 //function :AddVolume
469 //=======================================================================
470 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
472 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
473 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
477 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
478 const SMDS_MeshNode * n2,
479 const SMDS_MeshNode * n3,
480 const SMDS_MeshNode * n4,
481 const SMDS_MeshNode * n5,
482 const SMDS_MeshNode * n6,
483 const SMDS_MeshNode * n7,
484 const SMDS_MeshNode * n8,
487 return AddVolumeWithID(n1->GetID(),
498 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
499 const SMDS_MeshNode * n2,
500 const SMDS_MeshNode * n3,
501 const SMDS_MeshNode * n4,
502 const SMDS_MeshNode * n5,
503 const SMDS_MeshNode * n6,
504 const SMDS_MeshNode * n7,
505 const SMDS_MeshNode * n8)
507 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
508 if(anElem) myScript->AddVolume(anElem->GetID(),
520 //=======================================================================
521 //function : AddPolygonalFace
523 //=======================================================================
524 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
527 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes_ids, ID);
529 myScript->AddPolygonalFace(ID, nodes_ids);
534 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
535 (std::vector<const SMDS_MeshNode*> nodes,
538 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
540 int i, len = nodes.size();
541 std::vector<int> nodes_ids (len);
542 for (i = 0; i < len; i++) {
543 nodes_ids[i] = nodes[i]->GetID();
545 myScript->AddPolygonalFace(ID, nodes_ids);
550 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
551 (std::vector<const SMDS_MeshNode*> nodes)
553 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
555 int i, len = nodes.size();
556 std::vector<int> nodes_ids (len);
557 for (i = 0; i < len; i++) {
558 nodes_ids[i] = nodes[i]->GetID();
560 myScript->AddPolygonalFace(anElem->GetID(), nodes_ids);
565 //=======================================================================
566 //function : AddPolyhedralVolume
568 //=======================================================================
569 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (std::vector<int> nodes_ids,
570 std::vector<int> quantities,
573 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes_ids, quantities, ID);
575 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
580 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID
581 (std::vector<const SMDS_MeshNode*> nodes,
582 std::vector<int> quantities,
585 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
587 int i, len = nodes.size();
588 std::vector<int> nodes_ids (len);
589 for (i = 0; i < len; i++) {
590 nodes_ids[i] = nodes[i]->GetID();
592 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
597 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume
598 (std::vector<const SMDS_MeshNode*> nodes,
599 std::vector<int> quantities)
601 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities);
603 int i, len = nodes.size();
604 std::vector<int> nodes_ids (len);
605 for (i = 0; i < len; i++) {
606 nodes_ids[i] = nodes[i]->GetID();
608 myScript->AddPolyhedralVolume(anElem->GetID(), nodes_ids, quantities);
613 //=======================================================================
614 //function : removeFromContainers
616 //=======================================================================
618 static void removeFromContainers (map<int,SMESHDS_SubMesh*> & theSubMeshes,
619 set<SMESHDS_GroupBase*>& theGroups,
620 list<const SMDS_MeshElement *> & theElems,
623 if ( theElems.empty() )
627 // Element can belong to several groups
628 if ( !theGroups.empty() )
630 set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
631 for ( ; GrIt != theGroups.end(); GrIt++ )
633 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
634 if ( !group || group->IsEmpty() ) continue;
636 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
637 for ( ; elIt != theElems.end(); elIt++ )
639 group->SMDSGroup().Remove( *elIt );
640 if ( group->IsEmpty() ) break;
645 // Rm from sub-meshes
646 // Element should belong to only one sub-mesh
647 map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
648 for ( ; SubIt != theSubMeshes.end(); SubIt++ )
650 int size = isNode ? (*SubIt).second->NbNodes() : (*SubIt).second->NbElements();
651 if ( size == 0 ) continue;
653 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
654 while ( elIt != theElems.end() )
656 bool removed = false;
658 removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
660 removed = (*SubIt).second->RemoveElement( *elIt );
664 elIt = theElems.erase( elIt );
665 if ( theElems.empty() )
666 return; // all elements are found and removed
676 //=======================================================================
677 //function : RemoveNode
679 //=======================================================================
680 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
682 myScript->RemoveNode(n->GetID());
684 list<const SMDS_MeshElement *> removedElems;
685 list<const SMDS_MeshElement *> removedNodes;
687 SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
689 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
690 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
693 //=======================================================================
694 //function : RemoveElement
696 //========================================================================
697 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
699 if (elt->GetType() == SMDSAbs_Node)
701 RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
705 myScript->RemoveElement(elt->GetID());
707 list<const SMDS_MeshElement *> removedElems;
708 list<const SMDS_MeshElement *> removedNodes;
710 SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
712 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
715 //=======================================================================
716 //function : SetNodeOnVolume
718 //=======================================================================
719 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
720 const TopoDS_Shell & S)
722 if (myShape.IsNull()) MESSAGE("myShape is NULL");
724 int Index = myIndexToShape.FindIndex(S);
726 //Set Position on Node
727 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
728 //aNode->SetPosition(aPos);
730 //Update or build submesh
731 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
732 if (it==myShapeIndexToSubMesh.end())
733 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
735 myShapeIndexToSubMesh[Index]->AddNode(aNode);
738 //=======================================================================
739 //function : SetNodeOnFace
741 //=======================================================================
742 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode * aNode,
743 const TopoDS_Face & S)
745 if (myShape.IsNull()) MESSAGE("myShape is NULL");
747 int Index = myIndexToShape.FindIndex(S);
749 //Set Position on Node
750 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
752 //Update or build submesh
753 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
754 if (it==myShapeIndexToSubMesh.end())
755 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
757 myShapeIndexToSubMesh[Index]->AddNode(aNode);
760 //=======================================================================
761 //function : SetNodeOnEdge
763 //=======================================================================
764 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode * aNode,
765 const TopoDS_Edge & S)
767 if (myShape.IsNull()) MESSAGE("myShape is NULL");
769 int Index = myIndexToShape.FindIndex(S);
771 //Set Position on Node
772 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
774 //Update or build submesh
775 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
776 if (it==myShapeIndexToSubMesh.end())
777 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
779 myShapeIndexToSubMesh[Index]->AddNode(aNode);
782 //=======================================================================
783 //function : SetNodeOnVertex
785 //=======================================================================
786 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode * aNode,
787 const TopoDS_Vertex & S)
789 if (myShape.IsNull()) MESSAGE("myShape is NULL");
791 int Index = myIndexToShape.FindIndex(S);
793 //Set Position on Node
794 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
796 //Update or build submesh
797 map<int,SMESHDS_SubMesh*>::iterator it=myShapeIndexToSubMesh.find(Index);
798 if (it==myShapeIndexToSubMesh.end())
799 myShapeIndexToSubMesh[Index]= new SMESHDS_SubMesh();
801 myShapeIndexToSubMesh[Index]->AddNode(aNode);
804 //=======================================================================
805 //function : UnSetNodeOnShape
807 //=======================================================================
808 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
810 MESSAGE("not implemented");
813 //=======================================================================
814 //function : SetMeshElementOnShape
816 //=======================================================================
817 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
818 const TopoDS_Shape & S)
820 if (myShape.IsNull()) MESSAGE("myShape is NULL");
822 int Index = myIndexToShape.FindIndex(S);
824 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
825 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
827 myShapeIndexToSubMesh[Index]->AddElement(anElement);
830 //=======================================================================
831 //function : UnSetMeshElementOnShape
833 //=======================================================================
835 UnSetMeshElementOnShape(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]->RemoveElement(anElement);
846 //=======================================================================
847 //function : ShapeToMesh
849 //=======================================================================
850 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
855 //=======================================================================
856 //function : IsGroupOfSubShapes
857 //purpose : return true if at least one subshape of theShape is a subshape
858 // of myShape or theShape == myShape
859 //=======================================================================
861 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
863 if ( myShape.IsSame( theShape ))
866 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() ) {
867 if (myIndexToShape.Contains( it.Value() ) ||
868 IsGroupOfSubShapes( it.Value() ))
875 ///////////////////////////////////////////////////////////////////////////////
876 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
877 /// TopoDS_Shape is unknown
878 ///////////////////////////////////////////////////////////////////////////////
879 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const
881 if (myShape.IsNull()) MESSAGE("myShape is NULL");
883 int Index = ShapeToIndex(S);
884 TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
885 if (anIter != myShapeIndexToSubMesh.end())
886 return anIter->second;
891 ///////////////////////////////////////////////////////////////////////////////
892 /// Return the sub mesh by Id of shape it is linked to
893 ///////////////////////////////////////////////////////////////////////////////
894 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index)
896 if (myShape.IsNull()) MESSAGE("myShape is NULL");
898 if (myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end())
899 return myShapeIndexToSubMesh[Index];
904 //=======================================================================
905 //function : SubMeshIndices
907 //=======================================================================
908 list<int> SMESHDS_Mesh::SubMeshIndices()
911 std::map<int,SMESHDS_SubMesh*>::iterator anIter = myShapeIndexToSubMesh.begin();
912 for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
913 anIndices.push_back((*anIter).first);
918 //=======================================================================
919 //function : GetHypothesis
921 //=======================================================================
923 const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
924 const TopoDS_Shape & S) const
926 if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
927 return myShapeToHypothesis.find(S)->second;
929 static list<const SMESHDS_Hypothesis*> empty;
933 //=======================================================================
934 //function : GetScript
936 //=======================================================================
937 SMESHDS_Script* SMESHDS_Mesh::GetScript()
942 //=======================================================================
943 //function : ClearScript
945 //=======================================================================
946 void SMESHDS_Mesh::ClearScript()
951 //=======================================================================
952 //function : HasMeshElements
954 //=======================================================================
955 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
957 if (myShape.IsNull()) MESSAGE("myShape is NULL");
958 int Index = myIndexToShape.FindIndex(S);
959 return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
962 //=======================================================================
963 //function : HasHypothesis
965 //=======================================================================
966 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
968 return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
971 //=======================================================================
972 //function : NewSubMesh
974 //=======================================================================
975 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
977 SMESHDS_SubMesh* SM = 0;
978 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
980 SM = new SMESHDS_SubMesh();
981 myShapeIndexToSubMesh[Index]=SM;
984 SM = myShapeIndexToSubMesh[Index];
988 //=======================================================================
989 //function : AddCompoundSubmesh
991 //=======================================================================
993 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
994 TopAbs_ShapeEnum type)
997 if ( IsGroupOfSubShapes( S ) || (S.ShapeType() == TopAbs_VERTEX && myIndexToShape.Contains(S)) )
999 aMainIndex = myIndexToShape.Add( S );
1000 bool all = ( type == TopAbs_SHAPE );
1001 if ( all ) // corresponding simple submesh may exist
1002 aMainIndex = -aMainIndex;
1003 //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
1004 SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
1005 if ( !aNewSub->IsComplexSubmesh() ) // is empty
1007 int shapeType = all ? myShape.ShapeType() : type;
1008 int typeLimit = all ? TopAbs_VERTEX : type;
1009 for ( ; shapeType <= typeLimit; shapeType++ )
1011 TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
1012 for ( ; exp.More(); exp.Next() )
1014 int index = myIndexToShape.FindIndex( exp.Current() );
1016 aNewSub->AddSubMesh( NewSubMesh( index ));
1024 //=======================================================================
1025 //function : IndexToShape
1027 //=======================================================================
1028 TopoDS_Shape SMESHDS_Mesh::IndexToShape(int ShapeIndex)
1030 return myIndexToShape.FindKey(ShapeIndex);
1033 //=======================================================================
1034 //function : ShapeToIndex
1036 //=======================================================================
1037 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
1039 if (myShape.IsNull())
1040 MESSAGE("myShape is NULL");
1042 int index = myIndexToShape.FindIndex(S);
1047 //=======================================================================
1048 //function : SetNodeOnVolume
1050 //=======================================================================
1051 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
1053 //Set Position on Node
1054 //Handle (SMDS_FacePosition) aPos = new SMDS_FacePosition (myFaceToId(S),0.,0.);;
1055 //aNode->SetPosition(aPos);
1057 //Update or build submesh
1058 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1059 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1061 myShapeIndexToSubMesh[Index]->AddNode(aNode);
1064 //=======================================================================
1065 //function : SetNodeOnFace
1067 //=======================================================================
1068 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index)
1070 //Set Position on Node
1071 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition(Index, 0., 0.)));
1073 //Update or build submesh
1074 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1075 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1077 myShapeIndexToSubMesh[Index]->AddNode(aNode);
1080 //=======================================================================
1081 //function : SetNodeOnEdge
1083 //=======================================================================
1084 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode, int Index)
1086 //Set Position on Node
1087 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(Index, 0.)));
1089 //Update or build submesh
1090 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1091 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1093 myShapeIndexToSubMesh[Index]->AddNode(aNode);
1096 //=======================================================================
1097 //function : SetNodeOnVertex
1099 //=======================================================================
1100 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
1102 //Set Position on Node
1103 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition(Index)));
1105 //Update or build submesh
1106 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1107 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1109 myShapeIndexToSubMesh[Index]->AddNode(aNode);
1112 //=======================================================================
1113 //function : SetMeshElementOnShape
1115 //=======================================================================
1116 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
1119 if (myShapeIndexToSubMesh.find(Index)==myShapeIndexToSubMesh.end())
1120 myShapeIndexToSubMesh[Index]=new SMESHDS_SubMesh();
1122 myShapeIndexToSubMesh[Index]->AddElement(anElement);
1125 SMESHDS_Mesh::~SMESHDS_Mesh()