1 // SMESH SMESH : implementaion of SMESH idl descriptions
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 : Paul RASCLE, EDF
29 #include "SMESH_Mesh.hxx"
30 #include "SMESH_subMesh.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Hypothesis.hxx"
33 #include "SMESH_Group.hxx"
34 #include "SMESHDS_Group.hxx"
35 #include "SMESHDS_Script.hxx"
36 #include "SMDS_MeshVolume.hxx"
38 #include "utilities.h"
40 #include "Mesh_Writer.h"
41 #include "DriverMED_W_SMESHDS_Mesh.h"
42 #include "DriverDAT_W_SMESHDS_Mesh.h"
43 #include "DriverUNV_W_SMESHDS_Mesh.h"
45 #include "DriverMED_R_SMESHDS_Mesh.h"
47 #include <TCollection_AsciiString.hxx>
49 #include <TopTools_ListOfShape.hxx>
51 #include <TopTools_ListIteratorOfListOfShape.hxx>
52 #include "Utils_ExceptHandlers.hxx"
55 //=============================================================================
59 //=============================================================================
61 SMESH_Mesh::SMESH_Mesh()
63 MESSAGE("SMESH_Mesh::SMESH_Mesh");
68 //=============================================================================
72 //=============================================================================
74 SMESH_Mesh::SMESH_Mesh(int localId, int studyId, SMESH_Gen * gen, SMESHDS_Document * myDocument)
77 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
81 _myDocument = myDocument;
82 _idDoc = _myDocument->NewMesh();
83 _myMeshDS = _myDocument->GetMesh(_idDoc);
84 _isShapeToMesh = false;
87 //=============================================================================
91 //=============================================================================
93 SMESH_Mesh::~SMESH_Mesh()
95 MESSAGE("SMESH_Mesh::~SMESH_Mesh");
98 map < int, SMESH_Group * >::iterator itg;
99 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
100 SMESH_Group *aGroup = (*itg).second;
105 //=============================================================================
109 //=============================================================================
111 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape){
112 MESSAGE("SMESH_Mesh::ShapeToMesh");
115 SALOME_Exception(LOCALIZED
116 ("a shape to mesh as already been defined"));
117 _isShapeToMesh = true;
118 _myMeshDS->ShapeToMesh(aShape);
121 TopExp::MapShapes(aShape, _subShapes);
124 //=======================================================================
125 //function : MEDToMesh
127 //=======================================================================
129 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
131 MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
133 throw SALOME_Exception(LOCALIZED("a shape to mesh as already been defined"));
134 _isShapeToMesh = true;
135 std::auto_ptr<DriverMED_R_SMESHDS_Mesh> myReader(new DriverMED_R_SMESHDS_Mesh);
136 myReader->SetMesh(_myMeshDS);
137 myReader->SetMeshId(-1);
138 myReader->SetFile(theFileName);
139 myReader->SetMeshName(theMeshName);
140 DriverMED_R_SMESHDS_Mesh::ReadStatus status = myReader->ReadMySelf();
141 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
142 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
143 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
144 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
146 // Reading groups (sub-meshes are out of scope of MED import functionality)
147 list<string> aGroupNames = myReader->GetGroupNames();
148 MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
150 for ( list<string>::iterator it = aGroupNames.begin(); it != aGroupNames.end(); it++ ) {
151 SMESH_Group* aGroup = AddGroup( SMDSAbs_All, it->c_str(), anId );
153 MESSAGE("MEDToMesh - group added: "<<it->c_str());
154 SMESHDS_Group* aGroupDS = aGroup->GetGroupDS();
155 aGroupDS->SetStoreName( it->c_str() );
156 myReader->GetGroup( aGroupDS );
162 //=============================================================================
166 //=============================================================================
168 SMESH_Hypothesis::Hypothesis_Status
169 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
170 int anHypId) throw(SALOME_Exception)
172 Unexpect aCatch(SalomeException);
173 MESSAGE("SMESH_Mesh::AddHypothesis");
175 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
176 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
178 MESSAGE("Hypothesis ID does not give an hypothesis");
181 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
184 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
185 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
186 SCRUTE( anHyp->GetName() );
189 bool isGlobalHyp = IsMainShape( aSubShape );
191 // NotConformAllowed can be only global
194 string hypName = anHyp->GetName();
195 if ( hypName == "NotConformAllowed" )
197 MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
198 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
204 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
205 event = SMESH_subMesh::ADD_HYP;
207 event = SMESH_subMesh::ADD_ALGO;
208 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
211 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
212 !subMesh->IsApplicableHypotesis( anHyp )) // is added on father
214 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
215 event = SMESH_subMesh::ADD_FATHER_HYP;
217 event = SMESH_subMesh::ADD_FATHER_ALGO;
218 SMESH_Hypothesis::Hypothesis_Status ret2 =
219 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
224 subMesh->DumpAlgoState(true);
229 //=============================================================================
233 //=============================================================================
235 SMESH_Hypothesis::Hypothesis_Status
236 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
237 int anHypId)throw(SALOME_Exception)
239 Unexpect aCatch(SalomeException);
240 MESSAGE("SMESH_Mesh::RemoveHypothesis");
242 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
243 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
244 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
246 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
247 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
248 int hypType = anHyp->GetType();
254 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
255 event = SMESH_subMesh::REMOVE_HYP;
257 event = SMESH_subMesh::REMOVE_ALGO;
258 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
261 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
262 !subMesh->IsApplicableHypotesis( anHyp )) // is removed from father
264 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
265 event = SMESH_subMesh::REMOVE_FATHER_HYP;
267 event = SMESH_subMesh::REMOVE_FATHER_ALGO;
268 SMESH_Hypothesis::Hypothesis_Status ret2 =
269 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
270 if (ret2 > ret) // more severe
274 subMesh->DumpAlgoState(true);
279 //=============================================================================
283 //=============================================================================
285 SMESHDS_Mesh * SMESH_Mesh::GetMeshDS()
290 //=============================================================================
294 //=============================================================================
296 const list<const SMESHDS_Hypothesis*>&
297 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
298 throw(SALOME_Exception)
300 Unexpect aCatch(SalomeException);
301 // MESSAGE("SMESH_Mesh::GetHypothesisList");
302 // _subShapeHypothesisList.clear();
303 // const list<const SMESHDS_Hypothesis*>& listHyp =
304 // _myMeshDS->GetHypothesis(aSubShape);
306 // list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
307 // while (it!=listHyp.end())
309 // const SMESHDS_Hypothesis *anHyp = *it;
310 // _subShapeHypothesisList.push_back(anHyp);
313 // return _subShapeHypothesisList;
314 return _myMeshDS->GetHypothesis(aSubShape);
317 //=============================================================================
321 //=============================================================================
323 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
325 Unexpect aCatch(SalomeException);
326 MESSAGE("SMESH_Mesh::GetLog");
327 return _myMeshDS->GetScript()->GetCommands();
330 //=============================================================================
334 //=============================================================================
335 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
337 Unexpect aCatch(SalomeException);
338 MESSAGE("SMESH_Mesh::ClearLog");
339 _myMeshDS->GetScript()->Clear();
342 //=============================================================================
346 //=============================================================================
348 int SMESH_Mesh::GetId()
350 MESSAGE("SMESH_Mesh::GetId");
354 //=============================================================================
358 //=============================================================================
360 SMESH_Gen *SMESH_Mesh::GetGen()
365 //=============================================================================
367 * Get or Create the SMESH_subMesh object implementation
369 //=============================================================================
371 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
372 throw(SALOME_Exception)
374 Unexpect aCatch(SalomeException);
375 //MESSAGE("SMESH_Mesh::GetSubMesh");
376 SMESH_subMesh *aSubMesh;
377 int index = _subShapes.FindIndex(aSubShape);
379 if (_mapSubMesh.find(index) != _mapSubMesh.end())
381 aSubMesh = _mapSubMesh[index];
385 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
386 _mapSubMesh[index] = aSubMesh;
391 * if (_subShapes.Contains(aSubShape))
393 * index = _subShapes.FindIndex(aSubShape);
394 * ASSERT(_mapSubMesh.find(index) != _mapSubMesh.end());
395 * aSubMesh = _mapSubMesh[index];
396 * //MESSAGE("found submesh " << index);
400 * index = _subShapes.Add(aSubShape);
401 * aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
402 * _mapSubMesh[index] = aSubMesh;
403 * //MESSAGE("created submesh " << index);
409 //=============================================================================
411 * Get the SMESH_subMesh object implementation. Dont create it, return null
412 * if it does not exist.
414 //=============================================================================
416 // * Given a subShape, find if there is a subMesh associated to this subShape
417 // * or to a collection of shapes containing this subShape. Collection =
418 // * compsolid, shell, wire.
420 // * WARNING : with arg = compsolid, shell or wire returns always NULL.
421 // * with a face inside a shell, and submesh created for both, if arg is face,
422 // * returns first created submesh of the two.
423 // * subMesh is not created, return may be NULL.
425 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
426 throw(SALOME_Exception)
428 Unexpect aCatch(SalomeException);
429 //MESSAGE("SMESH_Mesh::GetSubMeshContaining");
430 bool isFound = false;
431 SMESH_subMesh *aSubMesh = NULL;
433 int index = _subShapes.FindIndex(aSubShape);
434 if (_mapSubMesh.find(index) != _mapSubMesh.end())
436 aSubMesh = _mapSubMesh[index];
442 * if (_subShapes.Contains(aSubShape))
444 * index = _subShapes.FindIndex(aSubShape);
445 * ASSERT(_mapSubMesh.find(index) != _mapSubMesh.end());
446 * aSubMesh = _mapSubMesh[index];
448 * //MESSAGE("found submesh " << index);
452 // map<int, SMESH_subMesh*>::iterator itsm;
453 // for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
455 // aSubMesh = (*itsm).second;
456 // isFound = aSubMesh->Contains(aSubShape);
457 // if (isFound) break;
465 //=======================================================================
466 //function : IsUsedHypothesis
467 //purpose : Return True if anHyp is used to mesh aSubShape
468 //=======================================================================
470 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
471 const TopoDS_Shape & aSubShape)
473 //MESSAGE( "SMESH_Mesh::IsUsedHypothesis" );
475 // check if anHyp is applicable to aSubShape
476 SMESH_subMesh * subMesh = GetSubMeshContaining( aSubShape );
478 !subMesh->IsApplicableHypotesis(static_cast<SMESH_Hypothesis*>(anHyp)))
481 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape);
484 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
485 return ( anHyp == algo );
487 // algorithm parameter
490 // look trough hypotheses used by algo
491 const list <const SMESHDS_Hypothesis * >&usedHyps =
492 algo->GetUsedHypothesis(*this, aSubShape);
493 list <const SMESHDS_Hypothesis * >::const_iterator itl;
494 for (itl = usedHyps.begin(); itl != usedHyps.end(); itl++)
500 // look through all assigned hypotheses
502 const list <const SMESHDS_Hypothesis * >&usedHyps =
503 _myMeshDS->GetHypothesis( aSubShape );
504 list <const SMESHDS_Hypothesis * >::const_iterator itl;
505 for (itl = usedHyps.begin(); itl != usedHyps.end(); itl++)
511 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
512 for (; it.More(); it.Next())
514 const list <const SMESHDS_Hypothesis * >&usedHyps =
515 _myMeshDS->GetHypothesis( aSubShape );
516 list <const SMESHDS_Hypothesis * >::const_iterator itl;
517 for (itl = usedHyps.begin(); itl != usedHyps.end(); itl++)
527 //=============================================================================
531 //=============================================================================
533 const list < SMESH_subMesh * >&
534 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
535 throw(SALOME_Exception)
537 Unexpect aCatch(SalomeException);
538 MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
539 map < int, SMESH_subMesh * >::iterator itsm;
540 _subMeshesUsingHypothesisList.clear();
541 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
543 SMESH_subMesh *aSubMesh = (*itsm).second;
544 if ( IsUsedHypothesis ( anHyp, aSubMesh->GetSubShape() ))
545 _subMeshesUsingHypothesisList.push_back(aSubMesh);
547 return _subMeshesUsingHypothesisList;
550 //=============================================================================
554 //=============================================================================
556 void SMESH_Mesh::ExportMED(const char *file, const char* theMeshName, bool theAutoGroups) throw(SALOME_Exception)
558 Unexpect aCatch(SalomeException);
559 std::auto_ptr<DriverMED_W_SMESHDS_Mesh> myWriter(new DriverMED_W_SMESHDS_Mesh);
560 myWriter ->SetFile ( file );
561 myWriter ->SetMesh ( _myMeshDS );
563 myWriter->SetMeshId ( _idDoc );
565 myWriter->SetMeshId ( -1 );
566 myWriter->SetMeshName( theMeshName );
569 if ( theAutoGroups ) {
570 myWriter->AddGroupOfNodes();
571 myWriter->AddGroupOfEdges();
572 myWriter->AddGroupOfFaces();
573 myWriter->AddGroupOfVolumes();
576 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
577 SMESH_Group* aGroup = it->second;
578 SMESHDS_Group* aGroupDS = aGroup->GetGroupDS();
579 aGroupDS->SetStoreName( aGroup->GetName() );
580 myWriter->AddGroup( aGroupDS );
586 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
588 Unexpect aCatch(SalomeException);
589 Mesh_Writer *myWriter = new DriverDAT_W_SMESHDS_Mesh;
590 myWriter->SetFile(string(file));
591 myWriter->SetMesh(_myMeshDS);
592 myWriter->SetMeshId(_idDoc);
596 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
598 Unexpect aCatch(SalomeException);
599 Mesh_Writer *myWriter = new DriverUNV_W_SMESHDS_Mesh;
600 myWriter->SetFile(string(file));
601 myWriter->SetMesh(_myMeshDS);
602 myWriter->SetMeshId(_idDoc);
606 //=============================================================================
610 //=============================================================================
611 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
613 Unexpect aCatch(SalomeException);
614 return _myMeshDS->NbNodes();
617 //=============================================================================
621 //=============================================================================
622 int SMESH_Mesh::NbEdges() throw(SALOME_Exception)
624 Unexpect aCatch(SalomeException);
625 return _myMeshDS->NbEdges();
628 //=============================================================================
632 //=============================================================================
633 int SMESH_Mesh::NbFaces() throw(SALOME_Exception)
635 Unexpect aCatch(SalomeException);
636 return _myMeshDS->NbFaces();
639 ///////////////////////////////////////////////////////////////////////////////
640 /// Return the number of 3 nodes faces in the mesh. This method run in O(n)
641 ///////////////////////////////////////////////////////////////////////////////
642 int SMESH_Mesh::NbTriangles() throw(SALOME_Exception)
644 Unexpect aCatch(SalomeException);
647 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
648 while(itFaces->more()) if(itFaces->next()->NbNodes()==3) Nb++;
652 ///////////////////////////////////////////////////////////////////////////////
653 /// Return the number of 4 nodes faces in the mesh. This method run in O(n)
654 ///////////////////////////////////////////////////////////////////////////////
655 int SMESH_Mesh::NbQuadrangles() throw(SALOME_Exception)
657 Unexpect aCatch(SalomeException);
660 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
661 while(itFaces->more()) if(itFaces->next()->NbNodes()==4) Nb++;
665 //=============================================================================
669 //=============================================================================
670 int SMESH_Mesh::NbVolumes() throw(SALOME_Exception)
672 Unexpect aCatch(SalomeException);
673 return _myMeshDS->NbVolumes();
676 int SMESH_Mesh::NbTetras() throw(SALOME_Exception)
678 Unexpect aCatch(SalomeException);
680 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
681 while(itVolumes->more()) if(itVolumes->next()->NbNodes()==4) Nb++;
685 int SMESH_Mesh::NbHexas() throw(SALOME_Exception)
687 Unexpect aCatch(SalomeException);
689 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
690 while(itVolumes->more()) if(itVolumes->next()->NbNodes()==8) Nb++;
694 int SMESH_Mesh::NbPyramids() throw(SALOME_Exception)
696 Unexpect aCatch(SalomeException);
698 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
699 while(itVolumes->more()) if(itVolumes->next()->NbNodes()==5) Nb++;
703 int SMESH_Mesh::NbPrisms() throw(SALOME_Exception)
705 Unexpect aCatch(SalomeException);
707 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
708 while(itVolumes->more()) if(itVolumes->next()->NbNodes()==6) Nb++;
712 //=============================================================================
716 //=============================================================================
717 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
719 Unexpect aCatch(SalomeException);
720 return _myMeshDS->NbSubMesh();
723 //=======================================================================
724 //function : IsNotConformAllowed
725 //purpose : check if a hypothesis alowing notconform mesh is present
726 //=======================================================================
728 bool SMESH_Mesh::IsNotConformAllowed() const
730 MESSAGE("SMESH_Mesh::IsNotConformAllowed");
732 const list<const SMESHDS_Hypothesis*>& listHyp =
733 _myMeshDS->GetHypothesis( _myMeshDS->ShapeToMesh() );
734 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
735 while (it!=listHyp.end())
737 const SMESHDS_Hypothesis *aHyp = *it;
738 string hypName = aHyp->GetName();
739 if ( hypName == "NotConformAllowed" )
746 //=======================================================================
747 //function : IsMainShape
749 //=======================================================================
751 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
753 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
756 //=============================================================================
760 //=============================================================================
762 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
766 if (_mapGroup.find(_groupId) != _mapGroup.end())
768 SMESH_Group* aGroup = new SMESH_Group (this, theType, theName);
770 _mapGroup[_groupId++] = aGroup;
774 //=============================================================================
778 //=============================================================================
780 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
782 if (_mapGroup.find(theGroupID) == _mapGroup.end())
784 return _mapGroup[theGroupID];
788 //=============================================================================
792 //=============================================================================
794 list<int> SMESH_Mesh::GetGroupIds()
797 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
798 anIds.push_back( it->first );
804 //=============================================================================
808 //=============================================================================
810 void SMESH_Mesh::RemoveGroup (const int theGroupID)
812 if (_mapGroup.find(theGroupID) == _mapGroup.end())
814 delete _mapGroup[theGroupID];
815 _mapGroup.erase (theGroupID);
818 //=======================================================================
819 //function : GetAncestors
820 //purpose : return list of ancestors of theSubShape in the order
821 // that lower dimention shapes come first.
822 //=======================================================================
824 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS)
826 if ( _mapAncestors.IsEmpty() )
828 // fill _mapAncestors
829 int desType, ancType;
830 for ( desType = TopAbs_EDGE; desType > TopAbs_COMPOUND; desType-- )
831 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
832 TopExp::MapShapesAndAncestors (_myMeshDS->ShapeToMesh(),
833 (TopAbs_ShapeEnum) desType,
834 (TopAbs_ShapeEnum) ancType,
838 if ( _mapAncestors.Contains( theS ) )
839 return _mapAncestors.FindFromKey( theS );
841 static TopTools_ListOfShape emptyList;
845 //=======================================================================
847 //purpose : dumps contents of mesh to stream [ debug purposes ]
848 //=======================================================================
849 ostream& SMESH_Mesh::Dump(ostream& save)
851 save << "========================== Dump contents of mesh ==========================" << endl;
852 save << "1) Total number of nodes: " << NbNodes() << endl;
853 save << "2) Total number of edges: " << NbEdges() << endl;
854 save << "3) Total number of faces: " << NbFaces() << endl;
855 if ( NbFaces() > 0 ) {
856 int nb3 = NbTriangles();
857 int nb4 = NbQuadrangles();
858 save << "3.1.) Number of triangles: " << nb3 << endl;
859 save << "3.2.) Number of quadrangles: " << nb4 << endl;
860 if ( nb3 + nb4 != NbFaces() ) {
861 map<int,int> myFaceMap;
862 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
863 while( itFaces->more( ) ) {
864 int nbNodes = itFaces->next()->NbNodes();
865 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
866 myFaceMap[ nbNodes ] = 0;
867 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
869 save << "3.3.) Faces in detail: " << endl;
870 map <int,int>::iterator itF;
871 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
872 save << "--> nb nodes: " << itF->first << " - nb elemens: " << itF->second << endl;
875 save << "4) Total number of volumes: " << NbVolumes() << endl;
876 if ( NbVolumes() > 0 ) {
878 int nb4 = NbTetras();
879 int nb5 = NbPyramids();
880 int nb6 = NbPrisms();
881 save << "4.1.) Number of hexahedrons: " << nb8 << endl;
882 save << "4.2.) Number of tetrahedrons: " << nb4 << endl;
883 save << "4.3.) Number of prisms: " << nb6 << endl;
884 save << "4.4.) Number of pyramides: " << nb5 << endl;
885 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes() ) {
886 map<int,int> myVolumesMap;
887 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
888 while( itVolumes->more( ) ) {
889 int nbNodes = itVolumes->next()->NbNodes();
890 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
891 myVolumesMap[ nbNodes ] = 0;
892 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
894 save << "4.5.) Volumes in detail: " << endl;
895 map <int,int>::iterator itV;
896 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
897 save << "--> nb nodes: " << itV->first << " - nb elemens: " << itV->second << endl;
900 save << "===========================================================================" << endl;