1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : SMESH_Mesh.cxx
24 // Author : Paul RASCLE, EDF
27 #include "SMESH_Mesh.hxx"
28 #include "SMESH_subMesh.hxx"
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_Hypothesis.hxx"
31 #include "SMESH_Group.hxx"
32 #include "SMESH_HypoFilter.hxx"
33 #include "SMESHDS_Group.hxx"
34 #include "SMESHDS_Script.hxx"
35 #include "SMESHDS_GroupOnGeom.hxx"
36 #include "SMESHDS_Document.hxx"
37 #include "SMDS_MeshVolume.hxx"
38 #include "SMDS_SetIterator.hxx"
40 #include "utilities.h"
42 #include "DriverMED_W_SMESHDS_Mesh.h"
43 #include "DriverDAT_W_SMDS_Mesh.h"
44 #include "DriverUNV_W_SMDS_Mesh.h"
45 #include "DriverSTL_W_SMDS_Mesh.h"
47 #include "DriverMED_R_SMESHDS_Mesh.h"
48 #include "DriverUNV_R_SMDS_Mesh.h"
49 #include "DriverSTL_R_SMDS_Mesh.h"
51 #undef _Precision_HeaderFile
52 #include <BRepBndLib.hxx>
53 #include <BRepPrimAPI_MakeBox.hxx>
54 #include <Bnd_Box.hxx>
56 #include <TopExp_Explorer.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58 #include <TopTools_ListOfShape.hxx>
59 #include <TopTools_MapOfShape.hxx>
60 #include <TopoDS_Iterator.hxx>
62 #include "Utils_ExceptHandlers.hxx"
64 // maximum stored group name length in MED file
65 #define MAX_MED_GROUP_NAME_LENGTH 80
68 static int MYDEBUG = 0;
70 static int MYDEBUG = 0;
73 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
75 typedef SMESH_HypoFilter THypType;
77 //=============================================================================
81 //=============================================================================
83 SMESH_Mesh::SMESH_Mesh(int theLocalId,
86 bool theIsEmbeddedMode,
87 SMESHDS_Document* theDocument):
88 _groupId( 0 ), _nbSubShapes( 0 )
90 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
92 _studyId = theStudyId;
94 _myDocument = theDocument;
95 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
96 _myMeshDS = theDocument->GetMesh(_idDoc);
97 _isShapeToMesh = false;
100 _myMeshDS->ShapeToMesh( PseudoShape() );
103 //=============================================================================
107 //=============================================================================
109 SMESH_Mesh::~SMESH_Mesh()
111 INFOS("SMESH_Mesh::~SMESH_Mesh");
113 // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
114 // Notify event listeners at least that something happens
115 if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
116 sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
119 std::map < int, SMESH_Group * >::iterator itg;
120 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
121 SMESH_Group *aGroup = (*itg).second;
127 //=============================================================================
129 * \brief Set geometry to be meshed
131 //=============================================================================
133 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
135 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
137 if ( !aShape.IsNull() && _isShapeToMesh ) {
138 if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
139 _myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
140 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
142 // clear current data
143 if ( !_myMeshDS->ShapeToMesh().IsNull() )
145 // removal of a shape to mesh, delete objects referring to sub-shapes:
147 std::map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
148 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
151 // - groups on geometry
152 std::map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
153 while ( i_gr != _mapGroup.end() ) {
154 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
155 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
157 _mapGroup.erase( i_gr++ );
162 _mapAncestors.Clear();
165 TopoDS_Shape aNullShape;
166 _myMeshDS->ShapeToMesh( aNullShape );
168 _shapeDiagonal = 0.0;
171 // set a new geometry
172 if ( !aShape.IsNull() )
174 _myMeshDS->ShapeToMesh(aShape);
175 _isShapeToMesh = true;
176 _nbSubShapes = _myMeshDS->MaxShapeIndex();
178 // fill map of ancestors
179 fillAncestorsMap(aShape);
183 _isShapeToMesh = false;
184 _shapeDiagonal = 0.0;
185 _myMeshDS->ShapeToMesh( PseudoShape() );
189 //=======================================================================
191 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
193 //=======================================================================
195 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
197 return _myMeshDS->ShapeToMesh();
200 //=======================================================================
202 * \brief Return a solid which is returned by GetShapeToMesh() if
203 * a real geometry to be meshed was not set
205 //=======================================================================
207 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
209 static TopoDS_Solid aSolid;
210 if ( aSolid.IsNull() )
212 aSolid = BRepPrimAPI_MakeBox(1,1,1);
217 //=======================================================================
219 * \brief Return diagonal size of bounding box of a shape
221 //=======================================================================
223 double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
225 if ( !aShape.IsNull() ) {
227 BRepBndLib::Add(aShape, Box);
228 return sqrt( Box.SquareExtent() );
233 //=======================================================================
235 * \brief Return diagonal size of bounding box of shape to mesh
237 //=======================================================================
239 double SMESH_Mesh::GetShapeDiagonalSize() const
241 if ( _shapeDiagonal == 0. && _isShapeToMesh )
242 const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
244 return _shapeDiagonal;
247 //=======================================================================
249 * \brief Remove all nodes and elements
251 //=======================================================================
253 void SMESH_Mesh::Clear()
256 _myMeshDS->ClearMesh();
258 // update compute state of submeshes
259 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) {
260 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
261 /*complexShapeFirst=*/false);
262 while ( smIt->more() ) {
264 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
268 // // clear sub-meshes; get ready to re-compute as a side-effect
270 // if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
272 // SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
273 // /*complexShapeFirst=*/false);
274 // while ( smIt->more() )
276 // sm = smIt->next();
277 // TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
278 // if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
279 // // all other shapes depends on vertices so they are already cleaned
280 // sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
281 // // to recompute even if failed
282 // sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
286 // // clear entities not on sub-meshes
288 // SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator();
289 // while ( vIt->more() )
290 // _myMeshDS->RemoveFreeElement( vIt->next(), 0 );
292 // SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator();
293 // while ( fIt->more() )
294 // _myMeshDS->RemoveFreeElement( fIt->next(), 0 );
296 // SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator();
297 // while ( eIt->more() )
298 // _myMeshDS->RemoveFreeElement( eIt->next(), 0 );
300 // SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator();
301 // while ( nIt->more() ) {
302 // const SMDS_MeshNode * node = nIt->next();
303 // if ( node->NbInverseElements() == 0 )
304 // _myMeshDS->RemoveFreeNode( node, 0 );
306 // _myMeshDS->RemoveNode(node);
310 //=======================================================================
312 * \brief Remove all nodes and elements of indicated shape
314 //=======================================================================
316 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
318 // clear sub-meshes; get ready to re-compute as a side-effect
319 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
321 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
322 /*complexShapeFirst=*/false);
323 while ( smIt->more() )
326 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
327 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
328 // all other shapes depends on vertices so they are already cleaned
329 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
330 // to recompute even if failed
331 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
336 //=======================================================================
337 //function : UNVToMesh
339 //=======================================================================
341 int SMESH_Mesh::UNVToMesh(const char* theFileName)
343 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
345 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
346 _isShapeToMesh = false;
347 DriverUNV_R_SMDS_Mesh myReader;
348 myReader.SetMesh(_myMeshDS);
349 myReader.SetFile(theFileName);
350 myReader.SetMeshId(-1);
353 MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
354 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
355 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
356 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
358 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
360 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
361 //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
362 aGroup->InitSubGroupsIterator();
363 while (aGroup->MoreSubGroups()) {
364 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
365 std::string aName = aGroupNames[aSubGroup];
368 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
370 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
371 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
373 aGroupDS->SetStoreName(aName.c_str());
374 aSubGroup->InitIterator();
375 const SMDS_MeshElement* aElement = 0;
376 while (aSubGroup->More()) {
377 aElement = aSubGroup->Next();
379 aGroupDS->SMDSGroup().Add(aElement);
383 aGroupDS->SetType(aElement->GetType());
391 //=======================================================================
392 //function : MEDToMesh
394 //=======================================================================
396 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
398 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
400 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
401 _isShapeToMesh = false;
402 DriverMED_R_SMESHDS_Mesh myReader;
403 myReader.SetMesh(_myMeshDS);
404 myReader.SetMeshId(-1);
405 myReader.SetFile(theFileName);
406 myReader.SetMeshName(theMeshName);
407 Driver_Mesh::Status status = myReader.Perform();
409 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
410 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
411 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
412 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
415 // Reading groups (sub-meshes are out of scope of MED import functionality)
416 std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
417 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
419 std::list<TNameAndType>::iterator name_type = aGroupNames.begin();
420 for ( ; name_type != aGroupNames.end(); name_type++ ) {
421 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
423 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
424 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
426 aGroupDS->SetStoreName( name_type->first.c_str() );
427 myReader.GetGroup( aGroupDS );
434 //=======================================================================
435 //function : STLToMesh
437 //=======================================================================
439 int SMESH_Mesh::STLToMesh(const char* theFileName)
441 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
443 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
444 _isShapeToMesh = false;
445 DriverSTL_R_SMDS_Mesh myReader;
446 myReader.SetMesh(_myMeshDS);
447 myReader.SetFile(theFileName);
448 myReader.SetMeshId(-1);
451 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
452 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
453 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
454 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
459 //=============================================================================
463 //=============================================================================
465 SMESH_Hypothesis::Hypothesis_Status
466 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
467 int anHypId ) throw(SALOME_Exception)
469 Unexpect aCatch(SalomeException);
470 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
472 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
473 if ( !subMesh || !subMesh->GetId())
474 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
476 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
477 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
479 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
484 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
487 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
488 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
490 bool isGlobalHyp = IsMainShape( aSubShape );
492 // NotConformAllowed can be only global
495 string hypName = anHyp->GetName();
496 if ( hypName == "NotConformAllowed" )
498 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
499 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
505 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
506 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
508 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
511 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
512 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
514 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
516 SMESH_Hypothesis::Hypothesis_Status ret2 =
517 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
521 // check concurent hypotheses on ansestors
522 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
524 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
525 while ( smIt->more() ) {
526 SMESH_subMesh* sm = smIt->next();
527 if ( sm->IsApplicableHypotesis( anHyp )) {
528 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
538 if(MYDEBUG) subMesh->DumpAlgoState(true);
543 //=============================================================================
547 //=============================================================================
549 SMESH_Hypothesis::Hypothesis_Status
550 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
551 int anHypId)throw(SALOME_Exception)
553 Unexpect aCatch(SalomeException);
554 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
556 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
557 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
558 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
560 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
561 int hypType = anHyp->GetType();
562 if(MYDEBUG) SCRUTE(hypType);
566 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
567 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
569 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
571 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
573 // there may appear concurrent hyps that were covered by the removed hyp
574 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
575 subMesh->IsApplicableHypotesis( anHyp ) &&
576 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
577 ret = SMESH_Hypothesis::HYP_CONCURENT;
580 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
581 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
583 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
585 SMESH_Hypothesis::Hypothesis_Status ret2 =
586 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
587 if (ret2 > ret) // more severe
590 // check concurent hypotheses on ansestors
591 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
593 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
594 while ( smIt->more() ) {
595 SMESH_subMesh* sm = smIt->next();
596 if ( sm->IsApplicableHypotesis( anHyp )) {
597 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
607 if(MYDEBUG) subMesh->DumpAlgoState(true);
608 if(MYDEBUG) SCRUTE(ret);
612 //=============================================================================
616 //=============================================================================
618 const std::list<const SMESHDS_Hypothesis*>&
619 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
620 throw(SALOME_Exception)
622 Unexpect aCatch(SalomeException);
623 return _myMeshDS->GetHypothesis(aSubShape);
626 //=======================================================================
628 * \brief Return the hypothesis assigned to the shape
629 * \param aSubShape - the shape to check
630 * \param aFilter - the hypothesis filter
631 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
632 * \param assignedTo - to return the shape the found hypo is assigned to
633 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
635 //=======================================================================
637 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
638 const SMESH_HypoFilter& aFilter,
639 const bool andAncestors,
640 TopoDS_Shape* assignedTo) const
643 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
644 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
645 for ( ; hyp != hypList.end(); hyp++ ) {
646 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
647 if ( aFilter.IsOk( h, aSubShape)) {
648 if ( assignedTo ) *assignedTo = aSubShape;
655 // user sorted submeshes of ancestors, according to stored submesh priority
656 const std::list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
657 std::list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
658 for ( ; smIt != smList.end(); smIt++ )
660 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
661 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
662 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
663 for ( ; hyp != hypList.end(); hyp++ ) {
664 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
665 if (aFilter.IsOk( h, curSh )) {
666 if ( assignedTo ) *assignedTo = curSh;
675 //================================================================================
677 * \brief Return hypothesis assigned to the shape
678 * \param aSubShape - the shape to check
679 * \param aFilter - the hypothesis filter
680 * \param aHypList - the list of the found hypotheses
681 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
682 * \retval int - number of unique hypos in aHypList
684 //================================================================================
686 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
687 const SMESH_HypoFilter& aFilter,
688 list <const SMESHDS_Hypothesis * >& aHypList,
689 const bool andAncestors) const
691 set<string> hypTypes; // to exclude same type hypos from the result list
694 // only one main hypothesis is allowed
695 bool mainHypFound = false;
698 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp;
699 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
700 if ( hypTypes.insert( (*hyp)->GetName() ).second )
702 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
706 // get hypos from aSubShape
708 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
709 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
710 if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
711 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
712 hypTypes.insert( (*hyp)->GetName() ).second )
714 aHypList.push_back( *hyp );
716 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
721 // get hypos from ancestors of aSubShape
724 TopTools_MapOfShape map;
726 // user sorted submeshes of ancestors, according to stored submesh priority
727 const std::list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
728 std::list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
729 for ( ; smIt != smList.end(); smIt++ )
731 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
732 if ( !map.Add( curSh ))
734 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
735 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
736 if (aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh ) &&
737 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
738 hypTypes.insert( (*hyp)->GetName() ).second )
740 aHypList.push_back( *hyp );
742 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
750 //=============================================================================
754 //=============================================================================
756 const std::list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
758 Unexpect aCatch(SalomeException);
759 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
760 return _myMeshDS->GetScript()->GetCommands();
763 //=============================================================================
767 //=============================================================================
768 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
770 Unexpect aCatch(SalomeException);
771 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
772 _myMeshDS->GetScript()->Clear();
775 //=============================================================================
777 * Get or Create the SMESH_subMesh object implementation
779 //=============================================================================
781 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
782 throw(SALOME_Exception)
784 Unexpect aCatch(SalomeException);
785 SMESH_subMesh *aSubMesh;
786 int index = _myMeshDS->ShapeToIndex(aSubShape);
788 // for submeshes on GEOM Group
789 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
790 TopoDS_Iterator it( aSubShape );
793 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
794 if ( index > _nbSubShapes ) _nbSubShapes = index; // not to create sm for this group again
796 // fill map of Ancestors
797 fillAncestorsMap(aSubShape);
801 // return NULL; // neither sub-shape nor a group
803 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
804 if ( i_sm != _mapSubMesh.end())
806 aSubMesh = i_sm->second;
810 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
811 _mapSubMesh[index] = aSubMesh;
817 //=============================================================================
819 * Get the SMESH_subMesh object implementation. Dont create it, return null
820 * if it does not exist.
822 //=============================================================================
824 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
825 throw(SALOME_Exception)
827 Unexpect aCatch(SalomeException);
828 SMESH_subMesh *aSubMesh = NULL;
830 int index = _myMeshDS->ShapeToIndex(aSubShape);
832 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
833 if ( i_sm != _mapSubMesh.end())
834 aSubMesh = i_sm->second;
838 //=============================================================================
840 * Get the SMESH_subMesh object implementation. Dont create it, return null
841 * if it does not exist.
843 //=============================================================================
845 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
846 throw(SALOME_Exception)
848 Unexpect aCatch(SalomeException);
850 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(aShapeID);
851 if (i_sm == _mapSubMesh.end())
855 //================================================================================
857 * \brief Return submeshes of groups containing the given subshape
859 //================================================================================
861 std::list<SMESH_subMesh*>
862 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
863 throw(SALOME_Exception)
865 Unexpect aCatch(SalomeException);
866 std::list<SMESH_subMesh*> found;
868 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
872 // submeshes of groups have max IDs, so search from the map end
873 std::map<int, SMESH_subMesh *>::const_reverse_iterator i_sm;
874 for ( i_sm = _mapSubMesh.rbegin(); i_sm != _mapSubMesh.rend(); ++i_sm) {
875 SMESHDS_SubMesh * ds = i_sm->second->GetSubMeshDS();
876 if ( ds && ds->IsComplexSubmesh() ) {
877 TopExp_Explorer exp( i_sm->second->GetSubShape(), aSubShape.ShapeType() );
878 for ( ; exp.More(); exp.Next() ) {
879 if ( aSubShape.IsSame( exp.Current() )) {
880 found.push_back( i_sm->second );
890 //=======================================================================
891 //function : IsUsedHypothesis
892 //purpose : Return True if anHyp is used to mesh aSubShape
893 //=======================================================================
895 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
896 const SMESH_subMesh* aSubMesh)
898 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
900 // check if anHyp can be used to mesh aSubMesh
901 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
904 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
906 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
909 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
910 return ( anHyp == algo );
912 // algorithm parameter
915 // look trough hypotheses used by algo
916 SMESH_HypoFilter hypoKind;
917 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
918 list <const SMESHDS_Hypothesis * > usedHyps;
919 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
920 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
924 // look through all assigned hypotheses
925 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
926 return false; //GetHypothesis( aSubShape, filter, true );
929 //=============================================================================
933 //=============================================================================
935 const list < SMESH_subMesh * >&
936 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
937 throw(SALOME_Exception)
939 Unexpect aCatch(SalomeException);
940 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
941 map < int, SMESH_subMesh * >::iterator itsm;
942 _subMeshesUsingHypothesisList.clear();
943 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
945 SMESH_subMesh *aSubMesh = (*itsm).second;
946 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
947 _subMeshesUsingHypothesisList.push_back(aSubMesh);
949 return _subMeshesUsingHypothesisList;
952 //=======================================================================
953 //function : NotifySubMeshesHypothesisModification
954 //purpose : Say all submeshes using theChangedHyp that it has been modified
955 //=======================================================================
957 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
959 Unexpect aCatch(SalomeException);
961 const SMESH_Algo *foundAlgo = 0;
962 SMESH_HypoFilter algoKind, compatibleHypoKind;
963 list <const SMESHDS_Hypothesis * > usedHyps;
966 map < int, SMESH_subMesh * >::iterator itsm;
967 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
969 SMESH_subMesh *aSubMesh = (*itsm).second;
970 if ( aSubMesh->IsApplicableHypotesis( hyp ))
972 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
974 if ( !foundAlgo ) // init filter for algo search
975 algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape ));
977 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
978 ( GetHypothesis( aSubShape, algoKind, true ));
982 bool sameAlgo = ( algo == foundAlgo );
983 if ( !sameAlgo && foundAlgo )
984 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
986 if ( !sameAlgo ) { // init filter for used hypos search
987 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
988 continue; // algo does not use any hypothesis
992 // check if hyp is used by algo
994 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
995 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
997 aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
998 const_cast< SMESH_Hypothesis*>( hyp ));
1005 //=============================================================================
1007 * Auto color functionality
1009 //=============================================================================
1010 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
1012 Unexpect aCatch(SalomeException);
1013 _isAutoColor = theAutoColor;
1016 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
1018 Unexpect aCatch(SalomeException);
1019 return _isAutoColor;
1022 //=============================================================================
1023 /*! Export* methods.
1024 * To store mesh contents on disk in different formats.
1026 //=============================================================================
1028 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
1030 set<string> aGroupNames;
1031 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1032 SMESH_Group* aGroup = it->second;
1033 std::string aGroupName = aGroup->GetName();
1034 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1035 if (!aGroupNames.insert(aGroupName).second)
1042 void SMESH_Mesh::ExportMED(const char *file,
1043 const char* theMeshName,
1046 throw(SALOME_Exception)
1048 Unexpect aCatch(SalomeException);
1050 DriverMED_W_SMESHDS_Mesh myWriter;
1051 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1052 myWriter.SetMesh ( _myMeshDS );
1054 myWriter.SetMeshId ( _idDoc );
1056 myWriter.SetMeshId ( -1 );
1057 myWriter.SetMeshName( theMeshName );
1060 if ( theAutoGroups ) {
1061 myWriter.AddGroupOfNodes();
1062 myWriter.AddGroupOfEdges();
1063 myWriter.AddGroupOfFaces();
1064 myWriter.AddGroupOfVolumes();
1067 // Pass groups to writer. Provide unique group names.
1068 set<string> aGroupNames;
1070 int maxNbIter = 10000; // to guarantee cycle finish
1071 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1072 SMESH_Group* aGroup = it->second;
1073 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1075 string aGroupName0 = aGroup->GetName();
1076 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1077 string aGroupName = aGroupName0;
1078 for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) {
1079 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1080 aGroupName = aString;
1081 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1083 aGroupDS->SetStoreName( aGroupName.c_str() );
1084 myWriter.AddGroup( aGroupDS );
1092 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
1094 Unexpect aCatch(SalomeException);
1095 DriverDAT_W_SMDS_Mesh myWriter;
1096 myWriter.SetFile(string(file));
1097 myWriter.SetMesh(_myMeshDS);
1098 myWriter.SetMeshId(_idDoc);
1102 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
1104 Unexpect aCatch(SalomeException);
1105 DriverUNV_W_SMDS_Mesh myWriter;
1106 myWriter.SetFile(string(file));
1107 myWriter.SetMesh(_myMeshDS);
1108 myWriter.SetMeshId(_idDoc);
1109 // myWriter.SetGroups(_mapGroup);
1111 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1112 SMESH_Group* aGroup = it->second;
1113 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1115 std::string aGroupName = aGroup->GetName();
1116 aGroupDS->SetStoreName( aGroupName.c_str() );
1117 myWriter.AddGroup( aGroupDS );
1123 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
1125 Unexpect aCatch(SalomeException);
1126 DriverSTL_W_SMDS_Mesh myWriter;
1127 myWriter.SetFile(string(file));
1128 myWriter.SetIsAscii( isascii );
1129 myWriter.SetMesh(_myMeshDS);
1130 myWriter.SetMeshId(_idDoc);
1134 //================================================================================
1136 * \brief Return number of nodes in the mesh
1138 //================================================================================
1140 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
1142 Unexpect aCatch(SalomeException);
1143 return _myMeshDS->NbNodes();
1146 //================================================================================
1148 * \brief Return number of edges of given order in the mesh
1150 //================================================================================
1152 int SMESH_Mesh::Nb0DElements() throw(SALOME_Exception)
1154 Unexpect aCatch(SalomeException);
1155 return _myMeshDS->GetMeshInfo().Nb0DElements();
1158 //================================================================================
1160 * \brief Return number of edges of given order in the mesh
1162 //================================================================================
1164 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1166 Unexpect aCatch(SalomeException);
1167 return _myMeshDS->GetMeshInfo().NbEdges(order);
1170 //================================================================================
1172 * \brief Return number of faces of given order in the mesh
1174 //================================================================================
1176 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1178 Unexpect aCatch(SalomeException);
1179 return _myMeshDS->GetMeshInfo().NbFaces(order);
1182 //================================================================================
1184 * \brief Return the number of faces in the mesh
1186 //================================================================================
1188 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1190 Unexpect aCatch(SalomeException);
1191 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1194 //================================================================================
1196 * \brief Return the number nodes faces in the mesh
1198 //================================================================================
1200 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1202 Unexpect aCatch(SalomeException);
1203 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1206 //================================================================================
1208 * \brief Return the number of polygonal faces in the mesh
1210 //================================================================================
1212 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1214 Unexpect aCatch(SalomeException);
1215 return _myMeshDS->GetMeshInfo().NbPolygons();
1218 //================================================================================
1220 * \brief Return number of volumes of given order in the mesh
1222 //================================================================================
1224 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1226 Unexpect aCatch(SalomeException);
1227 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1230 //================================================================================
1232 * \brief Return number of tetrahedrons of given order in the mesh
1234 //================================================================================
1236 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1238 Unexpect aCatch(SalomeException);
1239 return _myMeshDS->GetMeshInfo().NbTetras(order);
1242 //================================================================================
1244 * \brief Return number of hexahedrons of given order in the mesh
1246 //================================================================================
1248 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1250 Unexpect aCatch(SalomeException);
1251 return _myMeshDS->GetMeshInfo().NbHexas(order);
1254 //================================================================================
1256 * \brief Return number of pyramids of given order in the mesh
1258 //================================================================================
1260 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1262 Unexpect aCatch(SalomeException);
1263 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1266 //================================================================================
1268 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1270 //================================================================================
1272 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1274 Unexpect aCatch(SalomeException);
1275 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1278 //================================================================================
1280 * \brief Return number of polyhedrons in the mesh
1282 //================================================================================
1284 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1286 Unexpect aCatch(SalomeException);
1287 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1290 //================================================================================
1292 * \brief Return number of submeshes in the mesh
1294 //================================================================================
1296 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1298 Unexpect aCatch(SalomeException);
1299 return _myMeshDS->NbSubMesh();
1302 //=======================================================================
1303 //function : IsNotConformAllowed
1304 //purpose : check if a hypothesis alowing notconform mesh is present
1305 //=======================================================================
1307 bool SMESH_Mesh::IsNotConformAllowed() const
1309 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1311 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1312 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1315 //=======================================================================
1316 //function : IsMainShape
1318 //=======================================================================
1320 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1322 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1325 //=============================================================================
1329 //=============================================================================
1331 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1332 const char* theName,
1334 const TopoDS_Shape& theShape)
1336 if (_mapGroup.find(_groupId) != _mapGroup.end())
1339 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1340 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1341 _mapGroup[_groupId++] = aGroup;
1345 //================================================================================
1347 * \brief Return iterator on all existing groups
1349 //================================================================================
1351 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
1353 typedef map <int, SMESH_Group *> TMap;
1354 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
1357 //=============================================================================
1359 * \brief Return a group by ID
1361 //=============================================================================
1363 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1365 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1367 return _mapGroup[theGroupID];
1371 //=============================================================================
1373 * \brief Return IDs of all groups
1375 //=============================================================================
1377 std::list<int> SMESH_Mesh::GetGroupIds() const
1379 std::list<int> anIds;
1380 for ( std::map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1381 anIds.push_back( it->first );
1387 //=============================================================================
1391 //=============================================================================
1393 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1395 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1397 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1398 delete _mapGroup[theGroupID];
1399 _mapGroup.erase (theGroupID);
1402 //=======================================================================
1403 //function : GetAncestors
1404 //purpose : return list of ancestors of theSubShape in the order
1405 // that lower dimention shapes come first.
1406 //=======================================================================
1408 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1410 if ( _mapAncestors.Contains( theS ) )
1411 return _mapAncestors.FindFromKey( theS );
1413 static TopTools_ListOfShape emptyList;
1417 //=======================================================================
1419 //purpose : dumps contents of mesh to stream [ debug purposes ]
1420 //=======================================================================
1422 ostream& SMESH_Mesh::Dump(ostream& save)
1425 save << "========================== Dump contents of mesh ==========================" << endl << endl;
1426 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
1427 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
1428 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
1429 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
1430 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
1431 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
1432 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
1434 string orderStr = isQuadratic ? "quadratic" : "linear";
1435 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
1437 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
1438 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
1439 if ( NbFaces(order) > 0 ) {
1440 int nb3 = NbTriangles(order);
1441 int nb4 = NbQuadrangles(order);
1442 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
1443 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
1444 if ( nb3 + nb4 != NbFaces(order) ) {
1445 std::map<int,int> myFaceMap;
1446 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1447 while( itFaces->more( ) ) {
1448 int nbNodes = itFaces->next()->NbNodes();
1449 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1450 myFaceMap[ nbNodes ] = 0;
1451 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1453 save << clause << ".3) Faces in detail: " << endl;
1454 map <int,int>::iterator itF;
1455 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1456 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
1459 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
1460 if ( NbVolumes(order) > 0 ) {
1461 int nb8 = NbHexas(order);
1462 int nb4 = NbTetras(order);
1463 int nb5 = NbPyramids(order);
1464 int nb6 = NbPrisms(order);
1465 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
1466 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
1467 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
1468 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
1469 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
1470 std::map<int,int> myVolumesMap;
1471 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1472 while( itVolumes->more( ) ) {
1473 int nbNodes = itVolumes->next()->NbNodes();
1474 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1475 myVolumesMap[ nbNodes ] = 0;
1476 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1478 save << clause << ".5) Volumes in detail: " << endl;
1479 map <int,int>::iterator itV;
1480 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1481 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
1486 save << "===========================================================================" << endl;
1490 //=======================================================================
1491 //function : GetElementType
1492 //purpose : Returns type of mesh element with certain id
1493 //=======================================================================
1495 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1497 return _myMeshDS->GetElementType( id, iselem );
1500 //=============================================================================
1502 * \brief Convert group on geometry into standalone group
1504 //=============================================================================
1506 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
1508 SMESH_Group* aGroup = 0;
1509 std::map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
1510 if ( itg == _mapGroup.end() )
1513 SMESH_Group* anOldGrp = (*itg).second;
1514 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
1515 if ( !anOldGrp || !anOldGrpDS )
1518 // create new standalone group
1519 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
1520 _mapGroup[theGroupID] = aGroup;
1522 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1523 GetMeshDS()->RemoveGroup( anOldGrpDS );
1524 GetMeshDS()->AddGroup( aNewGrpDS );
1526 // add elements (or nodes) into new created group
1527 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
1528 while ( anItr->more() )
1529 aNewGrpDS->Add( (anItr->next())->GetID() );
1537 //=============================================================================
1539 * \brief remove submesh order from Mesh
1541 //=============================================================================
1543 void SMESH_Mesh::ClearMeshOrder()
1545 _mySubMeshOrder.clear();
1548 //=============================================================================
1550 * \brief remove submesh order from Mesh
1552 //=============================================================================
1554 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
1556 _mySubMeshOrder = theOrder;
1559 //=============================================================================
1561 * \brief return submesh order if any
1563 //=============================================================================
1565 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
1567 return _mySubMeshOrder;
1570 //=============================================================================
1572 * \brief fillAncestorsMap
1574 //=============================================================================
1576 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
1578 // fill _mapAncestors
1579 int desType, ancType;
1580 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
1581 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
1582 TopExp::MapShapesAndAncestors ( theShape,
1583 (TopAbs_ShapeEnum) desType,
1584 (TopAbs_ShapeEnum) ancType,
1588 //=============================================================================
1590 * \brief sort submeshes according to stored mesh order
1591 * \param theListToSort in out list to be sorted
1592 * \return FALSE if nothing sorted
1594 //=============================================================================
1596 bool SMESH_Mesh::SortByMeshOrder(std::list<SMESH_subMesh*>& theListToSort) const
1598 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
1602 std::list<SMESH_subMesh*> onlyOrderedList;
1603 // collect all ordered submeshes in one list as pointers
1604 TListOfListOfInt::const_iterator listIddIt = _mySubMeshOrder.begin();
1605 for( ; listIddIt != _mySubMeshOrder.end(); listIddIt++) {
1606 const TListOfInt& listOfId = *listIddIt;
1607 TListOfInt::const_iterator idIt = listOfId.begin();
1608 for ( ; idIt != listOfId.end(); idIt++ ) {
1609 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(*idIt);
1610 if ( i_sm != _mapSubMesh.end() )
1611 onlyOrderedList.push_back(i_sm->second);
1614 if (!onlyOrderedList.size())
1617 std::list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
1618 std::list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
1620 // check positions where ordered submeshes should be in result list
1621 std::set<int> setOfPos; // remember positions of in set
1622 std::list<SMESH_subMesh*>::const_iterator smIt = theListToSort.begin();
1624 for( ; smIt != theListToSort.end(); i++, smIt++ )
1625 if ( find( onlyBIt, onlyEIt, *smIt ) != onlyEIt )
1628 if ( !setOfPos.size() )
1631 // new list of all submeshes to be sorted
1632 std::list<SMESH_subMesh*> aNewList;
1633 // iterates on submeshes and insert ordered in detected positions
1634 for ( i = 0, smIt = theListToSort.begin(); smIt != theListToSort.end(); i++, smIt++ )
1635 if ( setOfPos.find( i ) != setOfPos.end() &&
1636 onlyBIt != onlyEIt ) { // position of ordered submesh detected
1637 aNewList.push_back( *onlyBIt ); // ordered submesh
1641 aNewList.push_back( *smIt ); // other submesh from list
1643 theListToSort = aNewList;
1647 //=============================================================================
1649 * \brief sort submeshes according to stored mesh order
1650 * \param theListToSort in out list to be sorted
1651 * \return FALSE if nothing sorted
1653 //=============================================================================
1655 std::list<SMESH_subMesh*> SMESH_Mesh::getAncestorsSubMeshes
1656 (const TopoDS_Shape& theSubShape) const
1658 std::list<SMESH_subMesh*> listOfSubMesh;
1659 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
1660 for (; it.More(); it.Next() ) {
1661 int index = _myMeshDS->ShapeToIndex(it.Value());
1662 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
1663 if (i_sm != _mapSubMesh.end())
1664 listOfSubMesh.push_back(i_sm->second);
1667 // sort submeshes according to stored mesh order
1668 SortByMeshOrder( listOfSubMesh );
1670 return listOfSubMesh;