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;
1033 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1034 SMESH_Group* aGroup = it->second;
1035 string aGroupName = aGroup->GetName();
1036 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1037 if (!aGroupNames.insert(aGroupName).second)
1044 void SMESH_Mesh::ExportMED(const char *file,
1045 const char* theMeshName,
1048 throw(SALOME_Exception)
1050 Unexpect aCatch(SalomeException);
1052 DriverMED_W_SMESHDS_Mesh myWriter;
1053 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1054 myWriter.SetMesh ( _myMeshDS );
1056 myWriter.SetMeshId ( _idDoc );
1058 myWriter.SetMeshId ( -1 );
1059 myWriter.SetMeshName( theMeshName );
1062 if ( theAutoGroups ) {
1063 myWriter.AddGroupOfNodes();
1064 myWriter.AddGroupOfEdges();
1065 myWriter.AddGroupOfFaces();
1066 myWriter.AddGroupOfVolumes();
1069 // Pass groups to writer. Provide unique group names.
1070 set<string> aGroupNames;
1072 int maxNbIter = 10000; // to guarantee cycle finish
1073 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1074 SMESH_Group* aGroup = it->second;
1075 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1077 string aGroupName0 = aGroup->GetName();
1078 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1079 string aGroupName = aGroupName0;
1080 for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) {
1081 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1082 aGroupName = aString;
1083 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1085 aGroupDS->SetStoreName( aGroupName.c_str() );
1086 myWriter.AddGroup( aGroupDS );
1094 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
1096 Unexpect aCatch(SalomeException);
1097 DriverDAT_W_SMDS_Mesh myWriter;
1098 myWriter.SetFile(string(file));
1099 myWriter.SetMesh(_myMeshDS);
1100 myWriter.SetMeshId(_idDoc);
1104 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
1106 Unexpect aCatch(SalomeException);
1107 DriverUNV_W_SMDS_Mesh myWriter;
1108 myWriter.SetFile(string(file));
1109 myWriter.SetMesh(_myMeshDS);
1110 myWriter.SetMeshId(_idDoc);
1111 // myWriter.SetGroups(_mapGroup);
1113 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1114 SMESH_Group* aGroup = it->second;
1115 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1117 string aGroupName = aGroup->GetName();
1118 aGroupDS->SetStoreName( aGroupName.c_str() );
1119 myWriter.AddGroup( aGroupDS );
1125 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
1127 Unexpect aCatch(SalomeException);
1128 DriverSTL_W_SMDS_Mesh myWriter;
1129 myWriter.SetFile(string(file));
1130 myWriter.SetIsAscii( isascii );
1131 myWriter.SetMesh(_myMeshDS);
1132 myWriter.SetMeshId(_idDoc);
1136 //================================================================================
1138 * \brief Return number of nodes in the mesh
1140 //================================================================================
1142 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
1144 Unexpect aCatch(SalomeException);
1145 return _myMeshDS->NbNodes();
1148 //================================================================================
1150 * \brief Return number of edges of given order in the mesh
1152 //================================================================================
1154 int SMESH_Mesh::Nb0DElements() throw(SALOME_Exception)
1156 Unexpect aCatch(SalomeException);
1157 return _myMeshDS->GetMeshInfo().Nb0DElements();
1160 //================================================================================
1162 * \brief Return number of edges of given order in the mesh
1164 //================================================================================
1166 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1168 Unexpect aCatch(SalomeException);
1169 return _myMeshDS->GetMeshInfo().NbEdges(order);
1172 //================================================================================
1174 * \brief Return number of faces of given order in the mesh
1176 //================================================================================
1178 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1180 Unexpect aCatch(SalomeException);
1181 return _myMeshDS->GetMeshInfo().NbFaces(order);
1184 //================================================================================
1186 * \brief Return the number of faces in the mesh
1188 //================================================================================
1190 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1192 Unexpect aCatch(SalomeException);
1193 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1196 //================================================================================
1198 * \brief Return the number nodes faces in the mesh
1200 //================================================================================
1202 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1204 Unexpect aCatch(SalomeException);
1205 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1208 //================================================================================
1210 * \brief Return the number of polygonal faces in the mesh
1212 //================================================================================
1214 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1216 Unexpect aCatch(SalomeException);
1217 return _myMeshDS->GetMeshInfo().NbPolygons();
1220 //================================================================================
1222 * \brief Return number of volumes of given order in the mesh
1224 //================================================================================
1226 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1228 Unexpect aCatch(SalomeException);
1229 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1232 //================================================================================
1234 * \brief Return number of tetrahedrons of given order in the mesh
1236 //================================================================================
1238 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1240 Unexpect aCatch(SalomeException);
1241 return _myMeshDS->GetMeshInfo().NbTetras(order);
1244 //================================================================================
1246 * \brief Return number of hexahedrons of given order in the mesh
1248 //================================================================================
1250 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1252 Unexpect aCatch(SalomeException);
1253 return _myMeshDS->GetMeshInfo().NbHexas(order);
1256 //================================================================================
1258 * \brief Return number of pyramids of given order in the mesh
1260 //================================================================================
1262 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1264 Unexpect aCatch(SalomeException);
1265 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1268 //================================================================================
1270 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1272 //================================================================================
1274 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1276 Unexpect aCatch(SalomeException);
1277 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1280 //================================================================================
1282 * \brief Return number of polyhedrons in the mesh
1284 //================================================================================
1286 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1288 Unexpect aCatch(SalomeException);
1289 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1292 //================================================================================
1294 * \brief Return number of submeshes in the mesh
1296 //================================================================================
1298 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1300 Unexpect aCatch(SalomeException);
1301 return _myMeshDS->NbSubMesh();
1304 //=======================================================================
1305 //function : IsNotConformAllowed
1306 //purpose : check if a hypothesis alowing notconform mesh is present
1307 //=======================================================================
1309 bool SMESH_Mesh::IsNotConformAllowed() const
1311 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1313 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1314 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1317 //=======================================================================
1318 //function : IsMainShape
1320 //=======================================================================
1322 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1324 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1327 //=============================================================================
1331 //=============================================================================
1333 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1334 const char* theName,
1336 const TopoDS_Shape& theShape)
1338 if (_mapGroup.find(_groupId) != _mapGroup.end())
1341 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1342 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1343 _mapGroup[_groupId++] = aGroup;
1347 //================================================================================
1349 * \brief Return iterator on all existing groups
1351 //================================================================================
1353 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
1355 typedef map <int, SMESH_Group *> TMap;
1356 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
1359 //=============================================================================
1361 * \brief Return a group by ID
1363 //=============================================================================
1365 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1367 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1369 return _mapGroup[theGroupID];
1373 //=============================================================================
1375 * \brief Return IDs of all groups
1377 //=============================================================================
1379 list<int> SMESH_Mesh::GetGroupIds() const
1382 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1383 anIds.push_back( it->first );
1389 //=============================================================================
1393 //=============================================================================
1395 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1397 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1399 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1400 delete _mapGroup[theGroupID];
1401 _mapGroup.erase (theGroupID);
1404 //=======================================================================
1405 //function : GetAncestors
1406 //purpose : return list of ancestors of theSubShape in the order
1407 // that lower dimention shapes come first.
1408 //=======================================================================
1410 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1412 if ( _mapAncestors.Contains( theS ) )
1413 return _mapAncestors.FindFromKey( theS );
1415 static TopTools_ListOfShape emptyList;
1419 //=======================================================================
1421 //purpose : dumps contents of mesh to stream [ debug purposes ]
1422 //=======================================================================
1424 ostream& SMESH_Mesh::Dump(ostream& save)
1427 save << "========================== Dump contents of mesh ==========================" << endl << endl;
1428 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
1429 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
1430 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
1431 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
1432 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
1433 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
1434 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
1436 string orderStr = isQuadratic ? "quadratic" : "linear";
1437 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
1439 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
1440 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
1441 if ( NbFaces(order) > 0 ) {
1442 int nb3 = NbTriangles(order);
1443 int nb4 = NbQuadrangles(order);
1444 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
1445 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
1446 if ( nb3 + nb4 != NbFaces(order) ) {
1447 map<int,int> myFaceMap;
1448 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1449 while( itFaces->more( ) ) {
1450 int nbNodes = itFaces->next()->NbNodes();
1451 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1452 myFaceMap[ nbNodes ] = 0;
1453 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1455 save << clause << ".3) Faces in detail: " << endl;
1456 map <int,int>::iterator itF;
1457 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1458 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
1461 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
1462 if ( NbVolumes(order) > 0 ) {
1463 int nb8 = NbHexas(order);
1464 int nb4 = NbTetras(order);
1465 int nb5 = NbPyramids(order);
1466 int nb6 = NbPrisms(order);
1467 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
1468 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
1469 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
1470 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
1471 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
1472 map<int,int> myVolumesMap;
1473 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1474 while( itVolumes->more( ) ) {
1475 int nbNodes = itVolumes->next()->NbNodes();
1476 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1477 myVolumesMap[ nbNodes ] = 0;
1478 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1480 save << clause << ".5) Volumes in detail: " << endl;
1481 map <int,int>::iterator itV;
1482 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1483 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
1488 save << "===========================================================================" << endl;
1492 //=======================================================================
1493 //function : GetElementType
1494 //purpose : Returns type of mesh element with certain id
1495 //=======================================================================
1497 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1499 return _myMeshDS->GetElementType( id, iselem );
1502 //=============================================================================
1504 * \brief Convert group on geometry into standalone group
1506 //=============================================================================
1508 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
1510 SMESH_Group* aGroup = 0;
1511 map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
1512 if ( itg == _mapGroup.end() )
1515 SMESH_Group* anOldGrp = (*itg).second;
1516 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
1517 if ( !anOldGrp || !anOldGrpDS )
1520 // create new standalone group
1521 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
1522 _mapGroup[theGroupID] = aGroup;
1524 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1525 GetMeshDS()->RemoveGroup( anOldGrpDS );
1526 GetMeshDS()->AddGroup( aNewGrpDS );
1528 // add elements (or nodes) into new created group
1529 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
1530 while ( anItr->more() )
1531 aNewGrpDS->Add( (anItr->next())->GetID() );
1539 //=============================================================================
1541 * \brief remove submesh order from Mesh
1543 //=============================================================================
1545 void SMESH_Mesh::ClearMeshOrder()
1547 _mySubMeshOrder.clear();
1550 //=============================================================================
1552 * \brief remove submesh order from Mesh
1554 //=============================================================================
1556 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
1558 _mySubMeshOrder = theOrder;
1561 //=============================================================================
1563 * \brief return submesh order if any
1565 //=============================================================================
1567 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
1569 return _mySubMeshOrder;
1572 //=============================================================================
1574 * \brief fillAncestorsMap
1576 //=============================================================================
1578 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
1580 // fill _mapAncestors
1581 int desType, ancType;
1582 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
1583 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
1584 TopExp::MapShapesAndAncestors ( theShape,
1585 (TopAbs_ShapeEnum) desType,
1586 (TopAbs_ShapeEnum) ancType,
1590 //=============================================================================
1592 * \brief sort submeshes according to stored mesh order
1593 * \param theListToSort in out list to be sorted
1594 * \return FALSE if nothing sorted
1596 //=============================================================================
1598 bool SMESH_Mesh::SortByMeshOrder(list<SMESH_subMesh*>& theListToSort) const
1600 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
1604 list<SMESH_subMesh*> onlyOrderedList;
1605 // collect all ordered submeshes in one list as pointers
1606 // and get their positions within theListToSort
1607 typedef list<SMESH_subMesh*>::iterator TPosInList;
1608 map< int, TPosInList > sortedPos;
1609 TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
1610 TListOfListOfInt::const_iterator listIddIt = _mySubMeshOrder.begin();
1611 for( ; listIddIt != _mySubMeshOrder.end(); listIddIt++) {
1612 const TListOfInt& listOfId = *listIddIt;
1613 TListOfInt::const_iterator idIt = listOfId.begin();
1614 for ( ; idIt != listOfId.end(); idIt++ ) {
1615 if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt )) {
1616 TPosInList smPos = find( smBeg, smEnd, sm );
1617 if ( smPos != smEnd ) {
1618 onlyOrderedList.push_back( sm );
1619 sortedPos[ distance( smBeg, smPos )] = smPos;
1624 if (onlyOrderedList.size() < 2)
1628 list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
1629 list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
1631 // iterates on ordered submeshes and insert them in detected positions
1632 map< int, TPosInList >::iterator i_pos = sortedPos.begin();
1633 for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
1634 *(i_pos->second) = *onlyBIt;
1639 //=============================================================================
1641 * \brief sort submeshes according to stored mesh order
1642 * \param theListToSort in out list to be sorted
1643 * \return FALSE if nothing sorted
1645 //=============================================================================
1647 list<SMESH_subMesh*> SMESH_Mesh::getAncestorsSubMeshes
1648 (const TopoDS_Shape& theSubShape) const
1650 list<SMESH_subMesh*> listOfSubMesh;
1651 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
1652 for (; it.More(); it.Next() )
1653 if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
1654 listOfSubMesh.push_back(sm);
1656 // sort submeshes according to stored mesh order
1657 SortByMeshOrder( listOfSubMesh );
1659 return listOfSubMesh;