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"
66 // maximum stored group name length in MED file
67 #define MAX_MED_GROUP_NAME_LENGTH 80
70 static int MYDEBUG = 0;
72 static int MYDEBUG = 0;
75 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
77 typedef SMESH_HypoFilter THypType;
79 //=============================================================================
83 //=============================================================================
85 SMESH_Mesh::SMESH_Mesh(int theLocalId,
88 bool theIsEmbeddedMode,
89 SMESHDS_Document* theDocument):
90 _groupId( 0 ), _nbSubShapes( 0 )
92 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
94 _studyId = theStudyId;
96 _myDocument = theDocument;
97 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
98 _myMeshDS = theDocument->GetMesh(_idDoc);
99 _isShapeToMesh = false;
100 _isAutoColor = false;
101 _shapeDiagonal = 0.0;
102 _myMeshDS->ShapeToMesh( PseudoShape() );
105 //=============================================================================
109 //=============================================================================
111 SMESH_Mesh::~SMESH_Mesh()
113 INFOS("SMESH_Mesh::~SMESH_Mesh");
115 // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
116 // Notify event listeners at least that something happens
117 if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
118 sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
121 map < int, SMESH_Group * >::iterator itg;
122 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
123 SMESH_Group *aGroup = (*itg).second;
129 //=============================================================================
131 * \brief Set geometry to be meshed
133 //=============================================================================
135 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
137 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
139 if ( !aShape.IsNull() && _isShapeToMesh ) {
140 if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
141 _myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
142 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
144 // clear current data
145 if ( !_myMeshDS->ShapeToMesh().IsNull() )
147 // removal of a shape to mesh, delete objects referring to sub-shapes:
149 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
150 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
153 // - groups on geometry
154 map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
155 while ( i_gr != _mapGroup.end() ) {
156 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
157 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
159 _mapGroup.erase( i_gr++ );
164 _mapAncestors.Clear();
167 TopoDS_Shape aNullShape;
168 _myMeshDS->ShapeToMesh( aNullShape );
170 _shapeDiagonal = 0.0;
173 // set a new geometry
174 if ( !aShape.IsNull() )
176 _myMeshDS->ShapeToMesh(aShape);
177 _isShapeToMesh = true;
178 _nbSubShapes = _myMeshDS->MaxShapeIndex();
180 // fill map of ancestors
181 fillAncestorsMap(aShape);
185 _isShapeToMesh = false;
186 _shapeDiagonal = 0.0;
187 _myMeshDS->ShapeToMesh( PseudoShape() );
191 //=======================================================================
193 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
195 //=======================================================================
197 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
199 return _myMeshDS->ShapeToMesh();
202 //=======================================================================
204 * \brief Return a solid which is returned by GetShapeToMesh() if
205 * a real geometry to be meshed was not set
207 //=======================================================================
209 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
211 static TopoDS_Solid aSolid;
212 if ( aSolid.IsNull() )
214 aSolid = BRepPrimAPI_MakeBox(1,1,1);
219 //=======================================================================
221 * \brief Return diagonal size of bounding box of a shape
223 //=======================================================================
225 double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
227 if ( !aShape.IsNull() ) {
229 BRepBndLib::Add(aShape, Box);
230 return sqrt( Box.SquareExtent() );
235 //=======================================================================
237 * \brief Return diagonal size of bounding box of shape to mesh
239 //=======================================================================
241 double SMESH_Mesh::GetShapeDiagonalSize() const
243 if ( _shapeDiagonal == 0. && _isShapeToMesh )
244 const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
246 return _shapeDiagonal;
249 //=======================================================================
251 * \brief Remove all nodes and elements
253 //=======================================================================
255 void SMESH_Mesh::Clear()
258 _myMeshDS->ClearMesh();
260 // update compute state of submeshes
261 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) {
262 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
263 /*complexShapeFirst=*/false);
264 while ( smIt->more() ) {
266 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
270 // // clear sub-meshes; get ready to re-compute as a side-effect
272 // if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
274 // SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
275 // /*complexShapeFirst=*/false);
276 // while ( smIt->more() )
278 // sm = smIt->next();
279 // TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
280 // if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
281 // // all other shapes depends on vertices so they are already cleaned
282 // sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
283 // // to recompute even if failed
284 // sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
288 // // clear entities not on sub-meshes
290 // SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator();
291 // while ( vIt->more() )
292 // _myMeshDS->RemoveFreeElement( vIt->next(), 0 );
294 // SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator();
295 // while ( fIt->more() )
296 // _myMeshDS->RemoveFreeElement( fIt->next(), 0 );
298 // SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator();
299 // while ( eIt->more() )
300 // _myMeshDS->RemoveFreeElement( eIt->next(), 0 );
302 // SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator();
303 // while ( nIt->more() ) {
304 // const SMDS_MeshNode * node = nIt->next();
305 // if ( node->NbInverseElements() == 0 )
306 // _myMeshDS->RemoveFreeNode( node, 0 );
308 // _myMeshDS->RemoveNode(node);
312 //=======================================================================
314 * \brief Remove all nodes and elements of indicated shape
316 //=======================================================================
318 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
320 // clear sub-meshes; get ready to re-compute as a side-effect
321 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
323 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
324 /*complexShapeFirst=*/false);
325 while ( smIt->more() )
328 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
329 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
330 // all other shapes depends on vertices so they are already cleaned
331 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
332 // to recompute even if failed
333 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
338 //=======================================================================
339 //function : UNVToMesh
341 //=======================================================================
343 int SMESH_Mesh::UNVToMesh(const char* theFileName)
345 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
347 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
348 _isShapeToMesh = false;
349 DriverUNV_R_SMDS_Mesh myReader;
350 myReader.SetMesh(_myMeshDS);
351 myReader.SetFile(theFileName);
352 myReader.SetMeshId(-1);
355 MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
356 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
357 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
358 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
360 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
362 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
363 //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
364 aGroup->InitSubGroupsIterator();
365 while (aGroup->MoreSubGroups()) {
366 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
367 string aName = aGroupNames[aSubGroup];
370 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
372 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
373 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
375 aGroupDS->SetStoreName(aName.c_str());
376 aSubGroup->InitIterator();
377 const SMDS_MeshElement* aElement = 0;
378 while (aSubGroup->More()) {
379 aElement = aSubGroup->Next();
381 aGroupDS->SMDSGroup().Add(aElement);
385 aGroupDS->SetType(aElement->GetType());
393 //=======================================================================
394 //function : MEDToMesh
396 //=======================================================================
398 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
400 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
402 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
403 _isShapeToMesh = false;
404 DriverMED_R_SMESHDS_Mesh myReader;
405 myReader.SetMesh(_myMeshDS);
406 myReader.SetMeshId(-1);
407 myReader.SetFile(theFileName);
408 myReader.SetMeshName(theMeshName);
409 Driver_Mesh::Status status = myReader.Perform();
411 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
412 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
413 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
414 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
417 // Reading groups (sub-meshes are out of scope of MED import functionality)
418 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
419 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
421 list<TNameAndType>::iterator name_type = aGroupNames.begin();
422 for ( ; name_type != aGroupNames.end(); name_type++ ) {
423 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
425 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
426 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
428 aGroupDS->SetStoreName( name_type->first.c_str() );
429 myReader.GetGroup( aGroupDS );
436 //=======================================================================
437 //function : STLToMesh
439 //=======================================================================
441 int SMESH_Mesh::STLToMesh(const char* theFileName)
443 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
445 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
446 _isShapeToMesh = false;
447 DriverSTL_R_SMDS_Mesh myReader;
448 myReader.SetMesh(_myMeshDS);
449 myReader.SetFile(theFileName);
450 myReader.SetMeshId(-1);
453 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
454 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
455 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
456 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
461 //=============================================================================
465 //=============================================================================
467 SMESH_Hypothesis::Hypothesis_Status
468 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
469 int anHypId ) throw(SALOME_Exception)
471 Unexpect aCatch(SalomeException);
472 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
474 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
475 if ( !subMesh || !subMesh->GetId())
476 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
478 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
479 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
481 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
486 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
489 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
490 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
492 bool isGlobalHyp = IsMainShape( aSubShape );
494 // NotConformAllowed can be only global
497 string hypName = anHyp->GetName();
498 if ( hypName == "NotConformAllowed" )
500 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
501 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
507 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
508 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
510 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
513 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
514 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
516 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
518 SMESH_Hypothesis::Hypothesis_Status ret2 =
519 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
523 // check concurent hypotheses on ansestors
524 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
526 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
527 while ( smIt->more() ) {
528 SMESH_subMesh* sm = smIt->next();
529 if ( sm->IsApplicableHypotesis( anHyp )) {
530 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
540 if(MYDEBUG) subMesh->DumpAlgoState(true);
545 //=============================================================================
549 //=============================================================================
551 SMESH_Hypothesis::Hypothesis_Status
552 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
553 int anHypId)throw(SALOME_Exception)
555 Unexpect aCatch(SalomeException);
556 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
558 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
559 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
560 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
562 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
563 int hypType = anHyp->GetType();
564 if(MYDEBUG) SCRUTE(hypType);
568 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
569 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
571 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
573 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
575 // there may appear concurrent hyps that were covered by the removed hyp
576 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
577 subMesh->IsApplicableHypotesis( anHyp ) &&
578 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
579 ret = SMESH_Hypothesis::HYP_CONCURENT;
582 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
583 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
585 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
587 SMESH_Hypothesis::Hypothesis_Status ret2 =
588 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
589 if (ret2 > ret) // more severe
592 // check concurent hypotheses on ansestors
593 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
595 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
596 while ( smIt->more() ) {
597 SMESH_subMesh* sm = smIt->next();
598 if ( sm->IsApplicableHypotesis( anHyp )) {
599 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
609 if(MYDEBUG) subMesh->DumpAlgoState(true);
610 if(MYDEBUG) SCRUTE(ret);
614 //=============================================================================
618 //=============================================================================
620 const list<const SMESHDS_Hypothesis*>&
621 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
622 throw(SALOME_Exception)
624 Unexpect aCatch(SalomeException);
625 return _myMeshDS->GetHypothesis(aSubShape);
628 //=======================================================================
630 * \brief Return the hypothesis assigned to the shape
631 * \param aSubShape - the shape to check
632 * \param aFilter - the hypothesis filter
633 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
634 * \param assignedTo - to return the shape the found hypo is assigned to
635 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
637 //=======================================================================
639 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
640 const SMESH_HypoFilter& aFilter,
641 const bool andAncestors,
642 TopoDS_Shape* assignedTo) const
645 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
646 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
647 for ( ; hyp != hypList.end(); hyp++ ) {
648 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
649 if ( aFilter.IsOk( h, aSubShape)) {
650 if ( assignedTo ) *assignedTo = aSubShape;
657 // user sorted submeshes of ancestors, according to stored submesh priority
658 const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
659 list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
660 for ( ; smIt != smList.end(); smIt++ )
662 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
663 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
664 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
665 for ( ; hyp != hypList.end(); hyp++ ) {
666 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
667 if (aFilter.IsOk( h, curSh )) {
668 if ( assignedTo ) *assignedTo = curSh;
677 //================================================================================
679 * \brief Return hypothesis assigned to the shape
680 * \param aSubShape - the shape to check
681 * \param aFilter - the hypothesis filter
682 * \param aHypList - the list of the found hypotheses
683 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
684 * \retval int - number of unique hypos in aHypList
686 //================================================================================
688 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
689 const SMESH_HypoFilter& aFilter,
690 list <const SMESHDS_Hypothesis * >& aHypList,
691 const bool andAncestors) const
693 set<string> hypTypes; // to exclude same type hypos from the result list
696 // only one main hypothesis is allowed
697 bool mainHypFound = false;
700 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
701 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
702 if ( hypTypes.insert( (*hyp)->GetName() ).second )
704 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
708 // get hypos from aSubShape
710 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
711 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
712 if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
713 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
714 hypTypes.insert( (*hyp)->GetName() ).second )
716 aHypList.push_back( *hyp );
718 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
723 // get hypos from ancestors of aSubShape
726 TopTools_MapOfShape map;
728 // user sorted submeshes of ancestors, according to stored submesh priority
729 const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
730 list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
731 for ( ; smIt != smList.end(); smIt++ )
733 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
734 if ( !map.Add( curSh ))
736 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
737 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
738 if (aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh ) &&
739 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
740 hypTypes.insert( (*hyp)->GetName() ).second )
742 aHypList.push_back( *hyp );
744 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
752 //=============================================================================
756 //=============================================================================
758 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
760 Unexpect aCatch(SalomeException);
761 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
762 return _myMeshDS->GetScript()->GetCommands();
765 //=============================================================================
769 //=============================================================================
770 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
772 Unexpect aCatch(SalomeException);
773 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
774 _myMeshDS->GetScript()->Clear();
777 //=============================================================================
779 * Get or Create the SMESH_subMesh object implementation
781 //=============================================================================
783 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
784 throw(SALOME_Exception)
786 Unexpect aCatch(SalomeException);
787 SMESH_subMesh *aSubMesh;
788 int index = _myMeshDS->ShapeToIndex(aSubShape);
790 // for submeshes on GEOM Group
791 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
792 TopoDS_Iterator it( aSubShape );
795 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
796 if ( index > _nbSubShapes ) _nbSubShapes = index; // not to create sm for this group again
798 // fill map of Ancestors
799 fillAncestorsMap(aSubShape);
803 // return NULL; // neither sub-shape nor a group
805 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
806 if ( i_sm != _mapSubMesh.end())
808 aSubMesh = i_sm->second;
812 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
813 _mapSubMesh[index] = aSubMesh;
819 //=============================================================================
821 * Get the SMESH_subMesh object implementation. Dont create it, return null
822 * if it does not exist.
824 //=============================================================================
826 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
827 throw(SALOME_Exception)
829 Unexpect aCatch(SalomeException);
830 SMESH_subMesh *aSubMesh = NULL;
832 int index = _myMeshDS->ShapeToIndex(aSubShape);
834 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
835 if ( i_sm != _mapSubMesh.end())
836 aSubMesh = i_sm->second;
840 //=============================================================================
842 * Get the SMESH_subMesh object implementation. Dont create it, return null
843 * if it does not exist.
845 //=============================================================================
847 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
848 throw(SALOME_Exception)
850 Unexpect aCatch(SalomeException);
852 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(aShapeID);
853 if (i_sm == _mapSubMesh.end())
857 //================================================================================
859 * \brief Return submeshes of groups containing the given subshape
861 //================================================================================
864 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
865 throw(SALOME_Exception)
867 Unexpect aCatch(SalomeException);
868 list<SMESH_subMesh*> found;
870 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
874 // submeshes of groups have max IDs, so search from the map end
875 map<int, SMESH_subMesh *>::const_reverse_iterator i_sm;
876 for ( i_sm = _mapSubMesh.rbegin(); i_sm != _mapSubMesh.rend(); ++i_sm) {
877 SMESHDS_SubMesh * ds = i_sm->second->GetSubMeshDS();
878 if ( ds && ds->IsComplexSubmesh() ) {
879 TopExp_Explorer exp( i_sm->second->GetSubShape(), aSubShape.ShapeType() );
880 for ( ; exp.More(); exp.Next() ) {
881 if ( aSubShape.IsSame( exp.Current() )) {
882 found.push_back( i_sm->second );
892 //=======================================================================
893 //function : IsUsedHypothesis
894 //purpose : Return True if anHyp is used to mesh aSubShape
895 //=======================================================================
897 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
898 const SMESH_subMesh* aSubMesh)
900 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
902 // check if anHyp can be used to mesh aSubMesh
903 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
906 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
908 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
911 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
912 return ( anHyp == algo );
914 // algorithm parameter
917 // look trough hypotheses used by algo
918 SMESH_HypoFilter hypoKind;
919 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
920 list <const SMESHDS_Hypothesis * > usedHyps;
921 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
922 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
926 // look through all assigned hypotheses
927 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
928 return false; //GetHypothesis( aSubShape, filter, true );
931 //=============================================================================
935 //=============================================================================
937 const list < SMESH_subMesh * >&
938 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
939 throw(SALOME_Exception)
941 Unexpect aCatch(SalomeException);
942 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
943 map < int, SMESH_subMesh * >::iterator itsm;
944 _subMeshesUsingHypothesisList.clear();
945 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
947 SMESH_subMesh *aSubMesh = (*itsm).second;
948 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
949 _subMeshesUsingHypothesisList.push_back(aSubMesh);
951 return _subMeshesUsingHypothesisList;
954 //=======================================================================
955 //function : NotifySubMeshesHypothesisModification
956 //purpose : Say all submeshes using theChangedHyp that it has been modified
957 //=======================================================================
959 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
961 Unexpect aCatch(SalomeException);
963 const SMESH_Algo *foundAlgo = 0;
964 SMESH_HypoFilter algoKind, compatibleHypoKind;
965 list <const SMESHDS_Hypothesis * > usedHyps;
968 map < int, SMESH_subMesh * >::iterator itsm;
969 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
971 SMESH_subMesh *aSubMesh = (*itsm).second;
972 if ( aSubMesh->IsApplicableHypotesis( hyp ))
974 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
976 if ( !foundAlgo ) // init filter for algo search
977 algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape ));
979 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
980 ( GetHypothesis( aSubShape, algoKind, true ));
984 bool sameAlgo = ( algo == foundAlgo );
985 if ( !sameAlgo && foundAlgo )
986 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
988 if ( !sameAlgo ) { // init filter for used hypos search
989 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
990 continue; // algo does not use any hypothesis
994 // check if hyp is used by algo
996 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
997 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
999 aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
1000 const_cast< SMESH_Hypothesis*>( hyp ));
1007 //=============================================================================
1009 * Auto color functionality
1011 //=============================================================================
1012 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
1014 Unexpect aCatch(SalomeException);
1015 _isAutoColor = theAutoColor;
1018 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
1020 Unexpect aCatch(SalomeException);
1021 return _isAutoColor;
1024 //=============================================================================
1025 /*! Export* methods.
1026 * To store mesh contents on disk in different formats.
1028 //=============================================================================
1030 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
1032 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
1033 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1034 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1036 SMESH_Group* aGroup = it->second;
1037 SMDSAbs_ElementType aType = aGroup->GetGroupDS()->GetType();
1038 string aGroupName = aGroup->GetName();
1039 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1040 if (!aGroupNames[aType].insert(aGroupName).second)
1047 void SMESH_Mesh::ExportMED(const char *file,
1048 const char* theMeshName,
1051 throw(SALOME_Exception)
1053 Unexpect aCatch(SalomeException);
1055 DriverMED_W_SMESHDS_Mesh myWriter;
1056 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1057 myWriter.SetMesh ( _myMeshDS );
1059 myWriter.SetMeshId ( _idDoc );
1061 myWriter.SetMeshId ( -1 );
1062 myWriter.SetMeshName( theMeshName );
1065 if ( theAutoGroups ) {
1066 myWriter.AddGroupOfNodes();
1067 myWriter.AddGroupOfEdges();
1068 myWriter.AddGroupOfFaces();
1069 myWriter.AddGroupOfVolumes();
1072 // Pass groups to writer. Provide unique group names.
1073 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
1074 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1076 int maxNbIter = 10000; // to guarantee cycle finish
1077 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1078 SMESH_Group* aGroup = it->second;
1079 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1081 SMDSAbs_ElementType aType = aGroupDS->GetType();
1082 string aGroupName0 = aGroup->GetName();
1083 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1084 string aGroupName = aGroupName0;
1085 for (int i = 1; !aGroupNames[aType].insert(aGroupName).second && i < maxNbIter; i++) {
1086 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1087 aGroupName = aString;
1088 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1090 aGroupDS->SetStoreName( aGroupName.c_str() );
1091 myWriter.AddGroup( aGroupDS );
1099 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
1101 Unexpect aCatch(SalomeException);
1102 DriverDAT_W_SMDS_Mesh myWriter;
1103 myWriter.SetFile(string(file));
1104 myWriter.SetMesh(_myMeshDS);
1105 myWriter.SetMeshId(_idDoc);
1109 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
1111 Unexpect aCatch(SalomeException);
1112 DriverUNV_W_SMDS_Mesh myWriter;
1113 myWriter.SetFile(string(file));
1114 myWriter.SetMesh(_myMeshDS);
1115 myWriter.SetMeshId(_idDoc);
1116 // myWriter.SetGroups(_mapGroup);
1118 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1119 SMESH_Group* aGroup = it->second;
1120 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1122 string aGroupName = aGroup->GetName();
1123 aGroupDS->SetStoreName( aGroupName.c_str() );
1124 myWriter.AddGroup( aGroupDS );
1130 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
1132 Unexpect aCatch(SalomeException);
1133 DriverSTL_W_SMDS_Mesh myWriter;
1134 myWriter.SetFile(string(file));
1135 myWriter.SetIsAscii( isascii );
1136 myWriter.SetMesh(_myMeshDS);
1137 myWriter.SetMeshId(_idDoc);
1141 //================================================================================
1143 * \brief Return number of nodes in the mesh
1145 //================================================================================
1147 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
1149 Unexpect aCatch(SalomeException);
1150 return _myMeshDS->NbNodes();
1153 //================================================================================
1155 * \brief Return number of edges of given order in the mesh
1157 //================================================================================
1159 int SMESH_Mesh::Nb0DElements() throw(SALOME_Exception)
1161 Unexpect aCatch(SalomeException);
1162 return _myMeshDS->GetMeshInfo().Nb0DElements();
1165 //================================================================================
1167 * \brief Return number of edges of given order in the mesh
1169 //================================================================================
1171 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1173 Unexpect aCatch(SalomeException);
1174 return _myMeshDS->GetMeshInfo().NbEdges(order);
1177 //================================================================================
1179 * \brief Return number of faces of given order in the mesh
1181 //================================================================================
1183 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1185 Unexpect aCatch(SalomeException);
1186 return _myMeshDS->GetMeshInfo().NbFaces(order);
1189 //================================================================================
1191 * \brief Return the number of faces in the mesh
1193 //================================================================================
1195 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1197 Unexpect aCatch(SalomeException);
1198 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1201 //================================================================================
1203 * \brief Return the number nodes faces in the mesh
1205 //================================================================================
1207 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1209 Unexpect aCatch(SalomeException);
1210 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1213 //================================================================================
1215 * \brief Return the number of polygonal faces in the mesh
1217 //================================================================================
1219 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1221 Unexpect aCatch(SalomeException);
1222 return _myMeshDS->GetMeshInfo().NbPolygons();
1225 //================================================================================
1227 * \brief Return number of volumes of given order in the mesh
1229 //================================================================================
1231 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1233 Unexpect aCatch(SalomeException);
1234 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1237 //================================================================================
1239 * \brief Return number of tetrahedrons of given order in the mesh
1241 //================================================================================
1243 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1245 Unexpect aCatch(SalomeException);
1246 return _myMeshDS->GetMeshInfo().NbTetras(order);
1249 //================================================================================
1251 * \brief Return number of hexahedrons of given order in the mesh
1253 //================================================================================
1255 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1257 Unexpect aCatch(SalomeException);
1258 return _myMeshDS->GetMeshInfo().NbHexas(order);
1261 //================================================================================
1263 * \brief Return number of pyramids of given order in the mesh
1265 //================================================================================
1267 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1269 Unexpect aCatch(SalomeException);
1270 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1273 //================================================================================
1275 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1277 //================================================================================
1279 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1281 Unexpect aCatch(SalomeException);
1282 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1285 //================================================================================
1287 * \brief Return number of polyhedrons in the mesh
1289 //================================================================================
1291 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1293 Unexpect aCatch(SalomeException);
1294 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1297 //================================================================================
1299 * \brief Return number of submeshes in the mesh
1301 //================================================================================
1303 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1305 Unexpect aCatch(SalomeException);
1306 return _myMeshDS->NbSubMesh();
1309 //=======================================================================
1310 //function : IsNotConformAllowed
1311 //purpose : check if a hypothesis alowing notconform mesh is present
1312 //=======================================================================
1314 bool SMESH_Mesh::IsNotConformAllowed() const
1316 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1318 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1319 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1322 //=======================================================================
1323 //function : IsMainShape
1325 //=======================================================================
1327 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1329 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1332 //=============================================================================
1336 //=============================================================================
1338 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1339 const char* theName,
1341 const TopoDS_Shape& theShape)
1343 if (_mapGroup.find(_groupId) != _mapGroup.end())
1346 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1347 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1348 _mapGroup[_groupId++] = aGroup;
1352 //================================================================================
1354 * \brief Return iterator on all existing groups
1356 //================================================================================
1358 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
1360 typedef map <int, SMESH_Group *> TMap;
1361 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
1364 //=============================================================================
1366 * \brief Return a group by ID
1368 //=============================================================================
1370 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1372 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1374 return _mapGroup[theGroupID];
1378 //=============================================================================
1380 * \brief Return IDs of all groups
1382 //=============================================================================
1384 list<int> SMESH_Mesh::GetGroupIds() const
1387 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1388 anIds.push_back( it->first );
1394 //=============================================================================
1398 //=============================================================================
1400 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1402 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1404 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1405 delete _mapGroup[theGroupID];
1406 _mapGroup.erase (theGroupID);
1409 //=======================================================================
1410 //function : GetAncestors
1411 //purpose : return list of ancestors of theSubShape in the order
1412 // that lower dimention shapes come first.
1413 //=======================================================================
1415 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1417 if ( _mapAncestors.Contains( theS ) )
1418 return _mapAncestors.FindFromKey( theS );
1420 static TopTools_ListOfShape emptyList;
1424 //=======================================================================
1426 //purpose : dumps contents of mesh to stream [ debug purposes ]
1427 //=======================================================================
1429 ostream& SMESH_Mesh::Dump(ostream& save)
1432 save << "========================== Dump contents of mesh ==========================" << endl << endl;
1433 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
1434 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
1435 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
1436 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
1437 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
1438 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
1439 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
1441 string orderStr = isQuadratic ? "quadratic" : "linear";
1442 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
1444 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
1445 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
1446 if ( NbFaces(order) > 0 ) {
1447 int nb3 = NbTriangles(order);
1448 int nb4 = NbQuadrangles(order);
1449 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
1450 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
1451 if ( nb3 + nb4 != NbFaces(order) ) {
1452 map<int,int> myFaceMap;
1453 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1454 while( itFaces->more( ) ) {
1455 int nbNodes = itFaces->next()->NbNodes();
1456 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1457 myFaceMap[ nbNodes ] = 0;
1458 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1460 save << clause << ".3) Faces in detail: " << endl;
1461 map <int,int>::iterator itF;
1462 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1463 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
1466 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
1467 if ( NbVolumes(order) > 0 ) {
1468 int nb8 = NbHexas(order);
1469 int nb4 = NbTetras(order);
1470 int nb5 = NbPyramids(order);
1471 int nb6 = NbPrisms(order);
1472 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
1473 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
1474 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
1475 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
1476 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
1477 map<int,int> myVolumesMap;
1478 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1479 while( itVolumes->more( ) ) {
1480 int nbNodes = itVolumes->next()->NbNodes();
1481 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1482 myVolumesMap[ nbNodes ] = 0;
1483 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1485 save << clause << ".5) Volumes in detail: " << endl;
1486 map <int,int>::iterator itV;
1487 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1488 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
1493 save << "===========================================================================" << endl;
1497 //=======================================================================
1498 //function : GetElementType
1499 //purpose : Returns type of mesh element with certain id
1500 //=======================================================================
1502 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1504 return _myMeshDS->GetElementType( id, iselem );
1507 //=============================================================================
1509 * \brief Convert group on geometry into standalone group
1511 //=============================================================================
1513 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
1515 SMESH_Group* aGroup = 0;
1516 map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
1517 if ( itg == _mapGroup.end() )
1520 SMESH_Group* anOldGrp = (*itg).second;
1521 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
1522 if ( !anOldGrp || !anOldGrpDS )
1525 // create new standalone group
1526 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
1527 _mapGroup[theGroupID] = aGroup;
1529 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1530 GetMeshDS()->RemoveGroup( anOldGrpDS );
1531 GetMeshDS()->AddGroup( aNewGrpDS );
1533 // add elements (or nodes) into new created group
1534 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
1535 while ( anItr->more() )
1536 aNewGrpDS->Add( (anItr->next())->GetID() );
1544 //=============================================================================
1546 * \brief remove submesh order from Mesh
1548 //=============================================================================
1550 void SMESH_Mesh::ClearMeshOrder()
1552 _mySubMeshOrder.clear();
1555 //=============================================================================
1557 * \brief remove submesh order from Mesh
1559 //=============================================================================
1561 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
1563 _mySubMeshOrder = theOrder;
1566 //=============================================================================
1568 * \brief return submesh order if any
1570 //=============================================================================
1572 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
1574 return _mySubMeshOrder;
1577 //=============================================================================
1579 * \brief fillAncestorsMap
1581 //=============================================================================
1583 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
1585 // fill _mapAncestors
1586 int desType, ancType;
1587 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
1588 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
1589 TopExp::MapShapesAndAncestors ( theShape,
1590 (TopAbs_ShapeEnum) desType,
1591 (TopAbs_ShapeEnum) ancType,
1595 //=============================================================================
1597 * \brief sort submeshes according to stored mesh order
1598 * \param theListToSort in out list to be sorted
1599 * \return FALSE if nothing sorted
1601 //=============================================================================
1603 bool SMESH_Mesh::SortByMeshOrder(list<SMESH_subMesh*>& theListToSort) const
1605 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
1609 list<SMESH_subMesh*> onlyOrderedList;
1610 // collect all ordered submeshes in one list as pointers
1611 // and get their positions within theListToSort
1612 typedef list<SMESH_subMesh*>::iterator TPosInList;
1613 map< int, TPosInList > sortedPos;
1614 TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
1615 TListOfListOfInt::const_iterator listIddIt = _mySubMeshOrder.begin();
1616 for( ; listIddIt != _mySubMeshOrder.end(); listIddIt++) {
1617 const TListOfInt& listOfId = *listIddIt;
1618 TListOfInt::const_iterator idIt = listOfId.begin();
1619 for ( ; idIt != listOfId.end(); idIt++ ) {
1620 if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt )) {
1621 TPosInList smPos = find( smBeg, smEnd, sm );
1622 if ( smPos != smEnd ) {
1623 onlyOrderedList.push_back( sm );
1624 sortedPos[ distance( smBeg, smPos )] = smPos;
1629 if (onlyOrderedList.size() < 2)
1633 list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
1634 list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
1636 // iterates on ordered submeshes and insert them in detected positions
1637 map< int, TPosInList >::iterator i_pos = sortedPos.begin();
1638 for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
1639 *(i_pos->second) = *onlyBIt;
1644 //=============================================================================
1646 * \brief sort submeshes according to stored mesh order
1647 * \param theListToSort in out list to be sorted
1648 * \return FALSE if nothing sorted
1650 //=============================================================================
1652 list<SMESH_subMesh*> SMESH_Mesh::getAncestorsSubMeshes
1653 (const TopoDS_Shape& theSubShape) const
1655 list<SMESH_subMesh*> listOfSubMesh;
1656 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
1657 for (; it.More(); it.Next() )
1658 if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
1659 listOfSubMesh.push_back(sm);
1661 // sort submeshes according to stored mesh order
1662 SortByMeshOrder( listOfSubMesh );
1664 return listOfSubMesh;