1 // Copyright (C) 2007-2011 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
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : SMESH_Mesh.cxx
25 // Author : Paul RASCLE, EDF
28 #include "SMESH_Mesh.hxx"
29 #include "SMESH_subMesh.hxx"
30 #include "SMESH_Gen.hxx"
31 #include "SMESH_Hypothesis.hxx"
32 #include "SMESH_Group.hxx"
33 #include "SMESH_HypoFilter.hxx"
34 #include "SMESHDS_Group.hxx"
35 #include "SMESHDS_Script.hxx"
36 #include "SMESHDS_GroupOnGeom.hxx"
37 #include "SMESHDS_Document.hxx"
38 #include "SMDS_MeshVolume.hxx"
39 #include "SMDS_SetIterator.hxx"
41 #include "utilities.h"
43 #include "DriverMED_W_SMESHDS_Mesh.h"
44 #include "DriverDAT_W_SMDS_Mesh.h"
45 #include "DriverUNV_W_SMDS_Mesh.h"
46 #include "DriverSTL_W_SMDS_Mesh.h"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
49 #include "DriverUNV_R_SMDS_Mesh.h"
50 #include "DriverSTL_R_SMDS_Mesh.h"
52 #undef _Precision_HeaderFile
53 #include <BRepBndLib.hxx>
54 #include <BRepPrimAPI_MakeBox.hxx>
55 #include <Bnd_Box.hxx>
57 #include <TopExp_Explorer.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TopTools_ListOfShape.hxx>
60 #include <TopTools_MapOfShape.hxx>
61 #include <TopoDS_Iterator.hxx>
63 #include "Utils_ExceptHandlers.hxx"
67 // maximum stored group name length in MED file
68 #define MAX_MED_GROUP_NAME_LENGTH 80
71 static int MYDEBUG = 0;
73 static int MYDEBUG = 0;
76 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
78 typedef SMESH_HypoFilter THypType;
80 //=============================================================================
84 //=============================================================================
86 SMESH_Mesh::SMESH_Mesh(int theLocalId,
89 bool theIsEmbeddedMode,
90 SMESHDS_Document* theDocument):
91 _groupId( 0 ), _nbSubShapes( 0 )
93 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
95 _studyId = theStudyId;
97 _myDocument = theDocument;
98 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
99 _myMeshDS = theDocument->GetMesh(_idDoc);
100 _isShapeToMesh = false;
101 _isAutoColor = false;
103 _shapeDiagonal = 0.0;
105 _myMeshDS->ShapeToMesh( PseudoShape() );
108 //================================================================================
110 * \brief Constructor of SMESH_Mesh being a base of some descendant class
112 //================================================================================
114 SMESH_Mesh::SMESH_Mesh():
115 _groupId( 0 ), _nbSubShapes( 0 )
118 _isShapeToMesh = false;
119 _isAutoColor = false;
121 _shapeDiagonal = 0.0;
125 //=============================================================================
129 //=============================================================================
131 SMESH_Mesh::~SMESH_Mesh()
133 MESSAGE("SMESH_Mesh::~SMESH_Mesh");
135 // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
136 // Notify event listeners at least that something happens
137 if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
138 sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
141 map < int, SMESH_Group * >::iterator itg;
142 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
143 SMESH_Group *aGroup = (*itg).second;
148 if ( _rmGroupCallUp) delete _rmGroupCallUp;
152 //=============================================================================
154 * \brief Set geometry to be meshed
156 //=============================================================================
158 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
160 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
162 if ( !aShape.IsNull() && _isShapeToMesh ) {
163 if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
164 _myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
165 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
167 // clear current data
168 if ( !_myMeshDS->ShapeToMesh().IsNull() )
170 // removal of a shape to mesh, delete objects referring to sub-shapes:
172 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
173 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
176 // - groups on geometry
177 map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
178 while ( i_gr != _mapGroup.end() ) {
179 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
180 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
182 _mapGroup.erase( i_gr++ );
187 _mapAncestors.Clear();
190 TopoDS_Shape aNullShape;
191 _myMeshDS->ShapeToMesh( aNullShape );
193 _shapeDiagonal = 0.0;
196 // set a new geometry
197 if ( !aShape.IsNull() )
199 _myMeshDS->ShapeToMesh(aShape);
200 _isShapeToMesh = true;
201 _nbSubShapes = _myMeshDS->MaxShapeIndex();
203 // fill map of ancestors
204 fillAncestorsMap(aShape);
208 _isShapeToMesh = false;
209 _shapeDiagonal = 0.0;
210 _myMeshDS->ShapeToMesh( PseudoShape() );
215 //=======================================================================
217 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
219 //=======================================================================
221 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
223 return _myMeshDS->ShapeToMesh();
226 //=======================================================================
228 * \brief Return a solid which is returned by GetShapeToMesh() if
229 * a real geometry to be meshed was not set
231 //=======================================================================
233 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
235 static TopoDS_Solid aSolid;
236 if ( aSolid.IsNull() )
238 aSolid = BRepPrimAPI_MakeBox(1,1,1);
243 //=======================================================================
245 * \brief Return diagonal size of bounding box of a shape
247 //=======================================================================
249 double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
251 if ( !aShape.IsNull() ) {
253 BRepBndLib::Add(aShape, Box);
254 return sqrt( Box.SquareExtent() );
259 //=======================================================================
261 * \brief Return diagonal size of bounding box of shape to mesh
263 //=======================================================================
265 double SMESH_Mesh::GetShapeDiagonalSize() const
267 if ( _shapeDiagonal == 0. && _isShapeToMesh )
268 const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
270 return _shapeDiagonal;
273 //=======================================================================
275 * \brief Remove all nodes and elements
277 //=======================================================================
279 void SMESH_Mesh::Clear()
282 _myMeshDS->ClearMesh();
284 // update compute state of submeshes
285 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
287 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
288 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
289 sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); // for event listeners (issue 0020918)
290 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
295 //=======================================================================
297 * \brief Remove all nodes and elements of indicated shape
299 //=======================================================================
301 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
303 // clear sub-meshes; get ready to re-compute as a side-effect
304 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
306 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
307 /*complexShapeFirst=*/false);
308 while ( smIt->more() )
311 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
312 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
313 // all other shapes depends on vertices so they are already cleaned
314 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
315 // to recompute even if failed
316 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
321 //=======================================================================
322 //function : UNVToMesh
324 //=======================================================================
326 int SMESH_Mesh::UNVToMesh(const char* theFileName)
328 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
330 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
331 _isShapeToMesh = false;
332 DriverUNV_R_SMDS_Mesh myReader;
333 myReader.SetMesh(_myMeshDS);
334 myReader.SetFile(theFileName);
335 myReader.SetMeshId(-1);
338 MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
339 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
340 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
341 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
343 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
345 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
346 //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
347 aGroup->InitSubGroupsIterator();
348 while (aGroup->MoreSubGroups()) {
349 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
350 string aName = aGroupNames[aSubGroup];
353 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
355 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
356 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
358 aGroupDS->SetStoreName(aName.c_str());
359 aSubGroup->InitIterator();
360 const SMDS_MeshElement* aElement = 0;
361 while (aSubGroup->More()) {
362 aElement = aSubGroup->Next();
364 aGroupDS->SMDSGroup().Add(aElement);
368 aGroupDS->SetType(aElement->GetType());
376 //=======================================================================
377 //function : MEDToMesh
379 //=======================================================================
381 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
383 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
385 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
386 _isShapeToMesh = false;
387 DriverMED_R_SMESHDS_Mesh myReader;
388 myReader.SetMesh(_myMeshDS);
389 myReader.SetMeshId(-1);
390 myReader.SetFile(theFileName);
391 myReader.SetMeshName(theMeshName);
392 Driver_Mesh::Status status = myReader.Perform();
394 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
395 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
396 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
397 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
400 // Reading groups (sub-meshes are out of scope of MED import functionality)
401 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
402 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
404 list<TNameAndType>::iterator name_type = aGroupNames.begin();
405 for ( ; name_type != aGroupNames.end(); name_type++ ) {
406 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
408 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
409 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
411 aGroupDS->SetStoreName( name_type->first.c_str() );
412 myReader.GetGroup( aGroupDS );
419 //=======================================================================
420 //function : STLToMesh
422 //=======================================================================
424 int SMESH_Mesh::STLToMesh(const char* theFileName)
426 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
428 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
429 _isShapeToMesh = false;
430 DriverSTL_R_SMDS_Mesh myReader;
431 myReader.SetMesh(_myMeshDS);
432 myReader.SetFile(theFileName);
433 myReader.SetMeshId(-1);
436 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
437 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
438 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
439 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
444 //=============================================================================
448 //=============================================================================
450 SMESH_Hypothesis::Hypothesis_Status
451 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
452 int anHypId ) throw(SALOME_Exception)
454 Unexpect aCatch(SalomeException);
455 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
457 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
458 if ( !subMesh || !subMesh->GetId())
459 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
461 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
462 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
464 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
469 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
472 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
473 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
475 bool isGlobalHyp = IsMainShape( aSubShape );
477 // NotConformAllowed can be only global
480 // NOTE: this is not a correct way to check a name of hypothesis,
481 // there should be an attribute of hypothesis saying that it can/can't
483 string hypName = anHyp->GetName();
484 if ( hypName == "NotConformAllowed" )
486 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
487 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
493 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
494 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
496 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
499 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
500 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
502 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
504 SMESH_Hypothesis::Hypothesis_Status ret2 =
505 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
509 // check concurent hypotheses on ancestors
510 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
512 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
513 while ( smIt->more() ) {
514 SMESH_subMesh* sm = smIt->next();
515 if ( sm->IsApplicableHypotesis( anHyp )) {
516 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
525 HasModificationsToDiscard(); // to reset _isModified flag if a mesh becomes empty
527 GetMeshDS()->Modified();
529 if(MYDEBUG) subMesh->DumpAlgoState(true);
530 if(MYDEBUG) SCRUTE(ret);
534 //=============================================================================
538 //=============================================================================
540 SMESH_Hypothesis::Hypothesis_Status
541 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
542 int anHypId)throw(SALOME_Exception)
544 Unexpect aCatch(SalomeException);
545 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
547 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
548 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
549 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
551 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
553 int hypType = anHyp->GetType();
559 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
560 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
562 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
564 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
566 // there may appear concurrent hyps that were covered by the removed hyp
567 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
568 subMesh->IsApplicableHypotesis( anHyp ) &&
569 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
570 ret = SMESH_Hypothesis::HYP_CONCURENT;
573 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
574 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
576 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
578 SMESH_Hypothesis::Hypothesis_Status ret2 =
579 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
580 if (ret2 > ret) // more severe
583 // check concurent hypotheses on ancestors
584 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
586 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
587 while ( smIt->more() ) {
588 SMESH_subMesh* sm = smIt->next();
589 if ( sm->IsApplicableHypotesis( anHyp )) {
590 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
600 HasModificationsToDiscard(); // to reset _isModified flag if mesh become empty
602 GetMeshDS()->Modified();
604 if(MYDEBUG) subMesh->DumpAlgoState(true);
605 if(MYDEBUG) SCRUTE(ret);
609 //=============================================================================
613 //=============================================================================
615 const list<const SMESHDS_Hypothesis*>&
616 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
617 throw(SALOME_Exception)
619 Unexpect aCatch(SalomeException);
620 return _myMeshDS->GetHypothesis(aSubShape);
623 //=======================================================================
625 * \brief Return the hypothesis assigned to the shape
626 * \param aSubShape - the shape to check
627 * \param aFilter - the hypothesis filter
628 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
629 * \param assignedTo - to return the shape the found hypo is assigned to
630 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
632 //=======================================================================
634 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
635 const SMESH_HypoFilter& aFilter,
636 const bool andAncestors,
637 TopoDS_Shape* assignedTo) const
640 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
641 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
642 for ( ; hyp != hypList.end(); hyp++ ) {
643 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
644 if ( aFilter.IsOk( h, aSubShape)) {
645 if ( assignedTo ) *assignedTo = aSubShape;
652 // user sorted submeshes of ancestors, according to stored submesh priority
653 const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
654 list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
655 for ( ; smIt != smList.end(); smIt++ )
657 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
658 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
659 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
660 for ( ; hyp != hypList.end(); hyp++ ) {
661 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
662 if (aFilter.IsOk( h, curSh )) {
663 if ( assignedTo ) *assignedTo = curSh;
672 //================================================================================
674 * \brief Return hypothesis assigned to the shape
675 * \param aSubShape - the shape to check
676 * \param aFilter - the hypothesis filter
677 * \param aHypList - the list of the found hypotheses
678 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
679 * \retval int - number of unique hypos in aHypList
681 //================================================================================
683 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
684 const SMESH_HypoFilter& aFilter,
685 list <const SMESHDS_Hypothesis * >& aHypList,
686 const bool andAncestors) const
688 set<string> hypTypes; // to exclude same type hypos from the result list
691 // only one main hypothesis is allowed
692 bool mainHypFound = false;
695 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
696 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
697 if ( hypTypes.insert( (*hyp)->GetName() ).second )
699 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
703 // get hypos from aSubShape
705 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
706 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
707 if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
708 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
709 hypTypes.insert( (*hyp)->GetName() ).second )
711 aHypList.push_back( *hyp );
713 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
718 // get hypos from ancestors of aSubShape
721 TopTools_MapOfShape map;
723 // user sorted submeshes of ancestors, according to stored submesh priority
724 const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
725 list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
726 for ( ; smIt != smList.end(); smIt++ )
728 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
729 if ( !map.Add( curSh ))
731 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
732 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
733 if (aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh ) &&
734 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
735 hypTypes.insert( (*hyp)->GetName() ).second )
737 aHypList.push_back( *hyp );
739 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
747 //=============================================================================
751 //=============================================================================
753 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
755 Unexpect aCatch(SalomeException);
756 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
757 return _myMeshDS->GetScript()->GetCommands();
760 //=============================================================================
764 //=============================================================================
765 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
767 Unexpect aCatch(SalomeException);
768 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
769 _myMeshDS->GetScript()->Clear();
772 //=============================================================================
774 * Get or Create the SMESH_subMesh object implementation
776 //=============================================================================
778 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
779 throw(SALOME_Exception)
781 Unexpect aCatch(SalomeException);
782 SMESH_subMesh *aSubMesh;
783 int index = _myMeshDS->ShapeToIndex(aSubShape);
785 // for submeshes on GEOM Group
786 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
787 TopoDS_Iterator it( aSubShape );
790 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
791 if ( index > _nbSubShapes ) _nbSubShapes = index; // not to create sm for this group again
793 // fill map of Ancestors
794 fillAncestorsMap(aSubShape);
798 // return NULL; // neither sub-shape nor a group
800 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
801 if ( i_sm != _mapSubMesh.end())
803 aSubMesh = i_sm->second;
807 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
808 _mapSubMesh[index] = aSubMesh;
814 //=============================================================================
816 * Get the SMESH_subMesh object implementation. Dont create it, return null
817 * if it does not exist.
819 //=============================================================================
821 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
822 throw(SALOME_Exception)
824 Unexpect aCatch(SalomeException);
825 SMESH_subMesh *aSubMesh = NULL;
827 int index = _myMeshDS->ShapeToIndex(aSubShape);
829 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
830 if ( i_sm != _mapSubMesh.end())
831 aSubMesh = i_sm->second;
835 //=============================================================================
837 * Get the SMESH_subMesh object implementation. Dont create it, return null
838 * if it does not exist.
840 //=============================================================================
842 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
843 throw(SALOME_Exception)
845 Unexpect aCatch(SalomeException);
847 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(aShapeID);
848 if (i_sm == _mapSubMesh.end())
852 //================================================================================
854 * \brief Return submeshes of groups containing the given subshape
856 //================================================================================
859 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
860 throw(SALOME_Exception)
862 Unexpect aCatch(SalomeException);
863 list<SMESH_subMesh*> found;
865 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
869 // submeshes of groups have max IDs, so search from the map end
870 map<int, SMESH_subMesh *>::const_reverse_iterator i_sm;
871 for ( i_sm = _mapSubMesh.rbegin(); i_sm != _mapSubMesh.rend(); ++i_sm) {
872 SMESHDS_SubMesh * ds = i_sm->second->GetSubMeshDS();
873 if ( ds && ds->IsComplexSubmesh() ) {
874 TopExp_Explorer exp( i_sm->second->GetSubShape(), aSubShape.ShapeType() );
875 for ( ; exp.More(); exp.Next() ) {
876 if ( aSubShape.IsSame( exp.Current() )) {
877 found.push_back( i_sm->second );
887 //=======================================================================
888 //function : IsUsedHypothesis
889 //purpose : Return True if anHyp is used to mesh aSubShape
890 //=======================================================================
892 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
893 const SMESH_subMesh* aSubMesh)
895 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
897 // check if anHyp can be used to mesh aSubMesh
898 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
901 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
903 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
906 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
907 return ( anHyp == algo );
909 // algorithm parameter
912 // look trough hypotheses used by algo
913 SMESH_HypoFilter hypoKind;
914 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
915 list <const SMESHDS_Hypothesis * > usedHyps;
916 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
917 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
921 // look through all assigned hypotheses
922 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
923 return false; //GetHypothesis( aSubShape, filter, true );
926 //=============================================================================
930 //=============================================================================
932 const list < SMESH_subMesh * >&
933 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
934 throw(SALOME_Exception)
936 Unexpect aCatch(SalomeException);
937 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
938 map < int, SMESH_subMesh * >::iterator itsm;
939 _subMeshesUsingHypothesisList.clear();
940 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
942 SMESH_subMesh *aSubMesh = (*itsm).second;
943 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
944 _subMeshesUsingHypothesisList.push_back(aSubMesh);
946 return _subMeshesUsingHypothesisList;
949 //=======================================================================
950 //function : NotifySubMeshesHypothesisModification
951 //purpose : Say all submeshes using theChangedHyp that it has been modified
952 //=======================================================================
954 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
956 Unexpect aCatch(SalomeException);
958 const SMESH_Algo *foundAlgo = 0;
959 SMESH_HypoFilter algoKind, compatibleHypoKind;
960 list <const SMESHDS_Hypothesis * > usedHyps;
963 map < int, SMESH_subMesh * >::iterator itsm;
964 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
966 SMESH_subMesh *aSubMesh = (*itsm).second;
967 if ( aSubMesh->IsApplicableHypotesis( hyp ))
969 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
971 if ( !foundAlgo ) // init filter for algo search
972 algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape ));
974 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
975 ( GetHypothesis( aSubShape, algoKind, true ));
979 bool sameAlgo = ( algo == foundAlgo );
980 if ( !sameAlgo && foundAlgo )
981 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
983 if ( !sameAlgo ) { // init filter for used hypos search
984 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
985 continue; // algo does not use any hypothesis
989 // check if hyp is used by algo
991 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
992 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
994 aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
995 const_cast< SMESH_Hypothesis*>( hyp ));
1000 HasModificationsToDiscard(); // to reset _isModified flag if mesh becomes empty
1001 GetMeshDS()->Modified();
1004 //=============================================================================
1006 * Auto color functionality
1008 //=============================================================================
1009 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
1011 Unexpect aCatch(SalomeException);
1012 _isAutoColor = theAutoColor;
1015 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
1017 Unexpect aCatch(SalomeException);
1018 return _isAutoColor;
1021 //=======================================================================
1022 //function : SetIsModified
1023 //purpose : Set the flag meaning that the mesh has been edited "manually"
1024 //=======================================================================
1026 void SMESH_Mesh::SetIsModified(bool isModified)
1028 _isModified = isModified;
1031 // check if mesh becomes empty as result of modification
1032 HasModificationsToDiscard();
1035 //=======================================================================
1036 //function : HasModificationsToDiscard
1037 //purpose : Return true if the mesh has been edited since a total re-compute
1038 // and those modifications may prevent successful partial re-compute.
1039 // As a side effect reset _isModified flag if mesh is empty
1041 //=======================================================================
1043 bool SMESH_Mesh::HasModificationsToDiscard() const
1045 if ( ! _isModified )
1048 // return true if the next Compute() will be partial and
1049 // existing but changed elements may prevent successful re-compute
1050 bool hasComputed = false, hasNotComputed = false;
1051 map <int, SMESH_subMesh*>::const_iterator i_sm = _mapSubMesh.begin();
1052 for ( ; i_sm != _mapSubMesh.end() ; ++i_sm )
1053 switch ( i_sm->second->GetSubShape().ShapeType() )
1058 if ( i_sm->second->IsMeshComputed() )
1061 hasNotComputed = true;
1062 if ( hasComputed && hasNotComputed)
1067 const_cast<SMESH_Mesh*>(this)->_isModified = false;
1072 //================================================================================
1074 * \brief Check if any groups of the same type have equal names
1076 //================================================================================
1078 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
1080 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
1081 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1082 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1084 SMESH_Group* aGroup = it->second;
1085 SMDSAbs_ElementType aType = aGroup->GetGroupDS()->GetType();
1086 string aGroupName = aGroup->GetName();
1087 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1088 if (!aGroupNames[aType].insert(aGroupName).second)
1095 //================================================================================
1097 * \brief Export the mesh to a med file
1099 //================================================================================
1101 void SMESH_Mesh::ExportMED(const char * file,
1102 const char* theMeshName,
1105 const SMESHDS_Mesh* meshPart)
1106 throw(SALOME_Exception)
1108 Unexpect aCatch(SalomeException);
1110 DriverMED_W_SMESHDS_Mesh myWriter;
1111 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1112 myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1114 myWriter.SetMeshId ( _idDoc );
1116 myWriter.SetMeshId ( -1 );
1117 myWriter.SetMeshName( theMeshName );
1120 if ( theAutoGroups ) {
1121 myWriter.AddGroupOfNodes();
1122 myWriter.AddGroupOfEdges();
1123 myWriter.AddGroupOfFaces();
1124 myWriter.AddGroupOfVolumes();
1127 // Pass groups to writer. Provide unique group names.
1128 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
1131 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1133 int maxNbIter = 10000; // to guarantee cycle finish
1134 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1135 SMESH_Group* aGroup = it->second;
1136 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1138 SMDSAbs_ElementType aType = aGroupDS->GetType();
1139 string aGroupName0 = aGroup->GetName();
1140 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1141 string aGroupName = aGroupName0;
1142 for (int i = 1; !aGroupNames[aType].insert(aGroupName).second && i < maxNbIter; i++) {
1143 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1144 aGroupName = aString;
1145 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1147 aGroupDS->SetStoreName( aGroupName.c_str() );
1148 myWriter.AddGroup( aGroupDS );
1156 //================================================================================
1158 * \brief Export the mesh to a DAT file
1160 //================================================================================
1162 void SMESH_Mesh::ExportDAT(const char * file,
1163 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1165 Unexpect aCatch(SalomeException);
1166 DriverDAT_W_SMDS_Mesh myWriter;
1167 myWriter.SetFile( file );
1168 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1169 myWriter.SetMeshId(_idDoc);
1173 //================================================================================
1175 * \brief Export the mesh to an UNV file
1177 //================================================================================
1179 void SMESH_Mesh::ExportUNV(const char * file,
1180 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1182 Unexpect aCatch(SalomeException);
1183 DriverUNV_W_SMDS_Mesh myWriter;
1184 myWriter.SetFile( file );
1185 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1186 myWriter.SetMeshId(_idDoc);
1187 // myWriter.SetGroups(_mapGroup);
1191 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1192 SMESH_Group* aGroup = it->second;
1193 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1195 string aGroupName = aGroup->GetName();
1196 aGroupDS->SetStoreName( aGroupName.c_str() );
1197 myWriter.AddGroup( aGroupDS );
1204 //================================================================================
1206 * \brief Export the mesh to an STL file
1208 //================================================================================
1210 void SMESH_Mesh::ExportSTL(const char * file,
1212 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1214 Unexpect aCatch(SalomeException);
1215 DriverSTL_W_SMDS_Mesh myWriter;
1216 myWriter.SetFile( file );
1217 myWriter.SetIsAscii( isascii );
1218 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS);
1219 myWriter.SetMeshId(_idDoc);
1223 //================================================================================
1225 * \brief Return number of nodes in the mesh
1227 //================================================================================
1229 int SMESH_Mesh::NbNodes() const throw(SALOME_Exception)
1231 Unexpect aCatch(SalomeException);
1232 return _myMeshDS->NbNodes();
1235 //================================================================================
1237 * \brief Return number of edges of given order in the mesh
1239 //================================================================================
1241 int SMESH_Mesh::Nb0DElements() const throw(SALOME_Exception)
1243 Unexpect aCatch(SalomeException);
1244 return _myMeshDS->GetMeshInfo().Nb0DElements();
1247 //================================================================================
1249 * \brief Return number of edges of given order in the mesh
1251 //================================================================================
1253 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1255 Unexpect aCatch(SalomeException);
1256 return _myMeshDS->GetMeshInfo().NbEdges(order);
1259 //================================================================================
1261 * \brief Return number of faces of given order in the mesh
1263 //================================================================================
1265 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1267 Unexpect aCatch(SalomeException);
1268 return _myMeshDS->GetMeshInfo().NbFaces(order);
1271 //================================================================================
1273 * \brief Return the number of faces in the mesh
1275 //================================================================================
1277 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1279 Unexpect aCatch(SalomeException);
1280 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1283 //================================================================================
1285 * \brief Return the number nodes faces in the mesh
1287 //================================================================================
1289 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1291 Unexpect aCatch(SalomeException);
1292 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1295 //================================================================================
1297 * \brief Return the number of polygonal faces in the mesh
1299 //================================================================================
1301 int SMESH_Mesh::NbPolygons() const throw(SALOME_Exception)
1303 Unexpect aCatch(SalomeException);
1304 return _myMeshDS->GetMeshInfo().NbPolygons();
1307 //================================================================================
1309 * \brief Return number of volumes of given order in the mesh
1311 //================================================================================
1313 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1315 Unexpect aCatch(SalomeException);
1316 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1319 //================================================================================
1321 * \brief Return number of tetrahedrons of given order in the mesh
1323 //================================================================================
1325 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1327 Unexpect aCatch(SalomeException);
1328 return _myMeshDS->GetMeshInfo().NbTetras(order);
1331 //================================================================================
1333 * \brief Return number of hexahedrons of given order in the mesh
1335 //================================================================================
1337 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1339 Unexpect aCatch(SalomeException);
1340 return _myMeshDS->GetMeshInfo().NbHexas(order);
1343 //================================================================================
1345 * \brief Return number of pyramids of given order in the mesh
1347 //================================================================================
1349 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1351 Unexpect aCatch(SalomeException);
1352 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1355 //================================================================================
1357 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1359 //================================================================================
1361 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1363 Unexpect aCatch(SalomeException);
1364 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1367 //================================================================================
1369 * \brief Return number of polyhedrons in the mesh
1371 //================================================================================
1373 int SMESH_Mesh::NbPolyhedrons() const throw(SALOME_Exception)
1375 Unexpect aCatch(SalomeException);
1376 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1379 //================================================================================
1381 * \brief Return number of submeshes in the mesh
1383 //================================================================================
1385 int SMESH_Mesh::NbSubMesh() const throw(SALOME_Exception)
1387 Unexpect aCatch(SalomeException);
1388 return _myMeshDS->NbSubMesh();
1391 //=======================================================================
1392 //function : IsNotConformAllowed
1393 //purpose : check if a hypothesis alowing notconform mesh is present
1394 //=======================================================================
1396 bool SMESH_Mesh::IsNotConformAllowed() const
1398 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1400 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1401 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1404 //=======================================================================
1405 //function : IsMainShape
1407 //=======================================================================
1409 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1411 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1414 //=============================================================================
1418 //=============================================================================
1420 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1421 const char* theName,
1423 const TopoDS_Shape& theShape,
1424 const SMESH_PredicatePtr& thePredicate)
1426 if (_mapGroup.count(_groupId))
1429 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape, thePredicate);
1430 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1431 _mapGroup[_groupId++] = aGroup;
1435 //================================================================================
1437 * \brief Return iterator on all existing groups
1439 //================================================================================
1441 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
1443 typedef map <int, SMESH_Group *> TMap;
1444 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
1447 //=============================================================================
1449 * \brief Return a group by ID
1451 //=============================================================================
1453 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1455 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1457 return _mapGroup[theGroupID];
1461 //=============================================================================
1463 * \brief Return IDs of all groups
1465 //=============================================================================
1467 list<int> SMESH_Mesh::GetGroupIds() const
1470 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1471 anIds.push_back( it->first );
1476 //================================================================================
1478 * \brief Set a caller of RemoveGroup() at level of CORBA API implementation.
1479 * The set upCaller will be deleted by SMESH_Mesh
1481 //================================================================================
1483 void SMESH_Mesh::SetRemoveGroupCallUp( TRmGroupCallUp* upCaller )
1485 if ( _rmGroupCallUp ) delete _rmGroupCallUp;
1486 _rmGroupCallUp = upCaller;
1489 //=============================================================================
1493 //=============================================================================
1495 bool SMESH_Mesh::RemoveGroup (const int theGroupID)
1497 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1499 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1500 delete _mapGroup[theGroupID];
1501 _mapGroup.erase (theGroupID);
1503 _rmGroupCallUp->RemoveGroup( theGroupID );
1507 //=======================================================================
1508 //function : GetAncestors
1509 //purpose : return list of ancestors of theSubShape in the order
1510 // that lower dimention shapes come first.
1511 //=======================================================================
1513 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1515 if ( _mapAncestors.Contains( theS ) )
1516 return _mapAncestors.FindFromKey( theS );
1518 static TopTools_ListOfShape emptyList;
1522 //=======================================================================
1524 //purpose : dumps contents of mesh to stream [ debug purposes ]
1525 //=======================================================================
1527 ostream& SMESH_Mesh::Dump(ostream& save)
1530 save << "========================== Dump contents of mesh ==========================" << endl << endl;
1531 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
1532 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
1533 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
1534 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
1535 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
1536 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
1537 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
1539 string orderStr = isQuadratic ? "quadratic" : "linear";
1540 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
1542 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
1543 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
1544 if ( NbFaces(order) > 0 ) {
1545 int nb3 = NbTriangles(order);
1546 int nb4 = NbQuadrangles(order);
1547 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
1548 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
1549 if ( nb3 + nb4 != NbFaces(order) ) {
1550 map<int,int> myFaceMap;
1551 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1552 while( itFaces->more( ) ) {
1553 int nbNodes = itFaces->next()->NbNodes();
1554 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1555 myFaceMap[ nbNodes ] = 0;
1556 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1558 save << clause << ".3) Faces in detail: " << endl;
1559 map <int,int>::iterator itF;
1560 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1561 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
1564 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
1565 if ( NbVolumes(order) > 0 ) {
1566 int nb8 = NbHexas(order);
1567 int nb4 = NbTetras(order);
1568 int nb5 = NbPyramids(order);
1569 int nb6 = NbPrisms(order);
1570 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
1571 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
1572 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
1573 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
1574 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
1575 map<int,int> myVolumesMap;
1576 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1577 while( itVolumes->more( ) ) {
1578 int nbNodes = itVolumes->next()->NbNodes();
1579 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1580 myVolumesMap[ nbNodes ] = 0;
1581 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1583 save << clause << ".5) Volumes in detail: " << endl;
1584 map <int,int>::iterator itV;
1585 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1586 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
1591 save << "===========================================================================" << endl;
1595 //=======================================================================
1596 //function : GetElementType
1597 //purpose : Returns type of mesh element with certain id
1598 //=======================================================================
1600 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1602 return _myMeshDS->GetElementType( id, iselem );
1605 //=============================================================================
1607 * \brief Convert group on geometry into standalone group
1609 //=============================================================================
1611 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
1613 SMESH_Group* aGroup = 0;
1614 map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
1615 if ( itg == _mapGroup.end() )
1618 SMESH_Group* anOldGrp = (*itg).second;
1619 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
1620 if ( !anOldGrp || !anOldGrpDS )
1623 // create new standalone group
1624 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
1625 _mapGroup[theGroupID] = aGroup;
1627 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1628 GetMeshDS()->RemoveGroup( anOldGrpDS );
1629 GetMeshDS()->AddGroup( aNewGrpDS );
1631 // add elements (or nodes) into new created group
1632 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
1633 while ( anItr->more() )
1634 aNewGrpDS->Add( (anItr->next())->GetID() );
1642 //=============================================================================
1644 * \brief remove submesh order from Mesh
1646 //=============================================================================
1648 void SMESH_Mesh::ClearMeshOrder()
1650 _mySubMeshOrder.clear();
1653 //=============================================================================
1655 * \brief remove submesh order from Mesh
1657 //=============================================================================
1659 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
1661 _mySubMeshOrder = theOrder;
1664 //=============================================================================
1666 * \brief return submesh order if any
1668 //=============================================================================
1670 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
1672 return _mySubMeshOrder;
1675 //=============================================================================
1677 * \brief fill _mapAncestors
1679 //=============================================================================
1681 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
1684 int desType, ancType;
1685 if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND )
1687 // a geom group is added. Insert it into lists of ancestors before
1688 // the first ancestor more complex than group members
1689 int memberType = TopoDS_Iterator( theShape ).Value().ShapeType();
1690 for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
1691 for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
1693 if ( !_mapAncestors.Contains( des.Current() )) continue;// issue 0020982
1694 TopTools_ListOfShape& ancList = _mapAncestors.ChangeFromKey( des.Current() );
1695 TopTools_ListIteratorOfListOfShape ancIt (ancList);
1696 while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType )
1699 ancList.InsertBefore( theShape, ancIt );
1703 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
1704 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
1705 TopExp::MapShapesAndAncestors ( theShape,
1706 (TopAbs_ShapeEnum) desType,
1707 (TopAbs_ShapeEnum) ancType,
1712 //=============================================================================
1714 * \brief sort submeshes according to stored mesh order
1715 * \param theListToSort in out list to be sorted
1716 * \return FALSE if nothing sorted
1718 //=============================================================================
1720 bool SMESH_Mesh::SortByMeshOrder(list<SMESH_subMesh*>& theListToSort) const
1722 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
1726 list<SMESH_subMesh*> onlyOrderedList;
1727 // collect all ordered submeshes in one list as pointers
1728 // and get their positions within theListToSort
1729 typedef list<SMESH_subMesh*>::iterator TPosInList;
1730 map< int, TPosInList > sortedPos;
1731 TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
1732 TListOfListOfInt::const_iterator listIddIt = _mySubMeshOrder.begin();
1733 for( ; listIddIt != _mySubMeshOrder.end(); listIddIt++) {
1734 const TListOfInt& listOfId = *listIddIt;
1735 TListOfInt::const_iterator idIt = listOfId.begin();
1736 for ( ; idIt != listOfId.end(); idIt++ ) {
1737 if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt )) {
1738 TPosInList smPos = find( smBeg, smEnd, sm );
1739 if ( smPos != smEnd ) {
1740 onlyOrderedList.push_back( sm );
1741 sortedPos[ distance( smBeg, smPos )] = smPos;
1746 if (onlyOrderedList.size() < 2)
1750 list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
1751 list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
1753 // iterates on ordered submeshes and insert them in detected positions
1754 map< int, TPosInList >::iterator i_pos = sortedPos.begin();
1755 for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
1756 *(i_pos->second) = *onlyBIt;
1761 //=============================================================================
1763 * \brief sort submeshes according to stored mesh order
1764 * \param theListToSort in out list to be sorted
1765 * \return FALSE if nothing sorted
1767 //=============================================================================
1769 list<SMESH_subMesh*> SMESH_Mesh::getAncestorsSubMeshes
1770 (const TopoDS_Shape& theSubShape) const
1772 list<SMESH_subMesh*> listOfSubMesh;
1773 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
1774 for (; it.More(); it.Next() )
1775 if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
1776 listOfSubMesh.push_back(sm);
1778 // sort submeshes according to stored mesh order
1779 SortByMeshOrder( listOfSubMesh );
1781 return listOfSubMesh;