1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Mesh.cxx
25 // Author : Paul RASCLE, EDF
29 #include "SMESH_Mesh.hxx"
30 #include "SMESH_subMesh.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Hypothesis.hxx"
33 #include "SMESH_Group.hxx"
34 #include "SMESH_HypoFilter.hxx"
35 #include "SMESHDS_Group.hxx"
36 #include "SMESHDS_Script.hxx"
37 #include "SMESHDS_GroupOnGeom.hxx"
38 #include "SMDS_MeshVolume.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 #include <BRepTools_WireExplorer.hxx>
52 #include <BRepPrimAPI_MakeBox.hxx>
53 #include <BRep_Builder.hxx>
56 #include <TCollection_AsciiString.hxx>
58 #include <TopTools_ListOfShape.hxx>
59 #include <TopTools_Array1OfShape.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <TopTools_MapOfShape.hxx>
65 #include "Utils_ExceptHandlers.hxx"
67 // maximum stored group name length in MED file
68 #define MAX_MED_GROUP_NAME_LENGTH 80
71 static int MYDEBUG = 0;
73 static int MYDEBUG = 0;
76 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
78 typedef SMESH_HypoFilter THypType;
80 //=============================================================================
84 //=============================================================================
86 SMESH_Mesh::SMESH_Mesh(int theLocalId,
89 bool theIsEmbeddedMode,
90 SMESHDS_Document* theDocument):
93 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
95 _studyId = theStudyId;
97 _myDocument = theDocument;
98 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
99 _myMeshDS = theDocument->GetMesh(_idDoc);
100 _isShapeToMesh = false;
101 _myMeshDS->ShapeToMesh( PseudoShape() );
104 //=============================================================================
108 //=============================================================================
110 SMESH_Mesh::~SMESH_Mesh()
112 INFOS("SMESH_Mesh::~SMESH_Mesh");
115 map < int, SMESH_Group * >::iterator itg;
116 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
117 SMESH_Group *aGroup = (*itg).second;
122 //=============================================================================
124 * \brief Set geometry to be meshed
126 //=============================================================================
128 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
130 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
132 if ( !aShape.IsNull() && _isShapeToMesh )
133 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
135 // clear current data
136 if ( !_myMeshDS->ShapeToMesh().IsNull() )
138 // removal of a shape to mesh, delete objects referring to sub-shapes:
140 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
141 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
144 // - groups on geometry
145 map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
146 while ( i_gr != _mapGroup.end() ) {
147 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
148 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
150 _mapGroup.erase( i_gr++ );
155 _mapAncestors.Clear();
156 _mapPropagationChains.Clear();
159 TopoDS_Shape aNullShape;
160 _myMeshDS->ShapeToMesh( aNullShape );
163 // set a new geometry
164 if ( !aShape.IsNull() )
166 _myMeshDS->ShapeToMesh(aShape);
167 _isShapeToMesh = true;
169 // fill _mapAncestors
170 int desType, ancType;
171 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
172 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
173 TopExp::MapShapesAndAncestors ( aShape,
174 (TopAbs_ShapeEnum) desType,
175 (TopAbs_ShapeEnum) ancType,
180 //=======================================================================
182 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
184 //=======================================================================
186 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
188 return _myMeshDS->ShapeToMesh();
191 //=======================================================================
193 * \brief Return a solid which is returned by GetShapeToMesh() if
194 * a real geometry to be meshed was not set
196 //=======================================================================
198 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
200 static TopoDS_Solid aSolid;
201 if ( aSolid.IsNull() )
203 aSolid = BRepPrimAPI_MakeBox(1,1,1);
208 //=======================================================================
209 //function : UNVToMesh
211 //=======================================================================
213 int SMESH_Mesh::UNVToMesh(const char* theFileName)
215 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
217 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
218 _isShapeToMesh = true;
219 DriverUNV_R_SMDS_Mesh myReader;
220 myReader.SetMesh(_myMeshDS);
221 myReader.SetFile(theFileName);
222 myReader.SetMeshId(-1);
225 MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
226 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
227 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
228 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
230 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
232 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
233 //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
234 aGroup->InitSubGroupsIterator();
235 while (aGroup->MoreSubGroups()) {
236 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
237 std::string aName = aGroupNames[aSubGroup];
240 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
242 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
243 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
245 aGroupDS->SetStoreName(aName.c_str());
246 aSubGroup->InitIterator();
247 const SMDS_MeshElement* aElement = 0;
248 while (aSubGroup->More()) {
249 aElement = aSubGroup->Next();
251 aGroupDS->SMDSGroup().Add(aElement);
255 aGroupDS->SetType(aElement->GetType());
263 //=======================================================================
264 //function : MEDToMesh
266 //=======================================================================
268 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
270 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
272 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
273 _isShapeToMesh = true;
274 DriverMED_R_SMESHDS_Mesh myReader;
275 myReader.SetMesh(_myMeshDS);
276 myReader.SetMeshId(-1);
277 myReader.SetFile(theFileName);
278 myReader.SetMeshName(theMeshName);
279 Driver_Mesh::Status status = myReader.Perform();
281 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
282 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
283 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
284 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
287 // Reading groups (sub-meshes are out of scope of MED import functionality)
288 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
289 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
291 list<TNameAndType>::iterator name_type = aGroupNames.begin();
292 for ( ; name_type != aGroupNames.end(); name_type++ ) {
293 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
295 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
296 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
298 aGroupDS->SetStoreName( name_type->first.c_str() );
299 myReader.GetGroup( aGroupDS );
306 //=======================================================================
307 //function : STLToMesh
309 //=======================================================================
311 int SMESH_Mesh::STLToMesh(const char* theFileName)
313 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
315 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
316 _isShapeToMesh = true;
317 DriverSTL_R_SMDS_Mesh myReader;
318 myReader.SetMesh(_myMeshDS);
319 myReader.SetFile(theFileName);
320 myReader.SetMeshId(-1);
323 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
324 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
325 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
326 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
331 //=============================================================================
335 //=============================================================================
337 SMESH_Hypothesis::Hypothesis_Status
338 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
339 int anHypId ) throw(SALOME_Exception)
341 Unexpect aCatch(SalomeException);
342 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
344 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
345 if ( !subMesh || !subMesh->GetId())
346 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
348 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
349 if ( subMeshDS && subMeshDS->IsComplexSubmesh() ) // group of sub-shapes and maybe of not sub-
351 MESSAGE("AddHypothesis() to complex submesh");
352 // return the worst but not fatal state of all group memebers
353 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
354 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
355 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
356 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
358 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
359 continue; // not sub-shape
360 ret = AddHypothesis( itS.Value(), anHypId );
361 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
362 aWorstNotFatal = ret;
363 if ( ret < aBestRet )
366 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
368 return aWorstNotFatal;
371 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
372 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
374 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
379 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
382 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
383 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
385 bool isGlobalHyp = IsMainShape( aSubShape );
387 // NotConformAllowed can be only global
390 string hypName = anHyp->GetName();
391 if ( hypName == "NotConformAllowed" )
393 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
394 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
400 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
401 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
403 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
406 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
407 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
409 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
411 SMESH_Hypothesis::Hypothesis_Status ret2 =
412 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
416 // check concurent hypotheses on ansestors
417 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
419 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
420 while ( smIt->more() ) {
421 SMESH_subMesh* sm = smIt->next();
422 if ( sm->IsApplicableHypotesis( anHyp )) {
423 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
433 if(MYDEBUG) subMesh->DumpAlgoState(true);
438 //=============================================================================
442 //=============================================================================
444 SMESH_Hypothesis::Hypothesis_Status
445 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
446 int anHypId)throw(SALOME_Exception)
448 Unexpect aCatch(SalomeException);
449 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
451 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
452 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
453 if ( subMeshDS && subMeshDS->IsComplexSubmesh() )
455 // return the worst but not fatal state of all group memebers
456 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
457 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
458 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
459 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
461 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
462 continue; // not sub-shape
463 ret = RemoveHypothesis( itS.Value(), anHypId );
464 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
465 aWorstNotFatal = ret;
466 if ( ret < aBestRet )
469 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
471 return aWorstNotFatal;
474 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
475 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
476 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
478 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
479 int hypType = anHyp->GetType();
480 if(MYDEBUG) SCRUTE(hypType);
484 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
485 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
487 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
489 // there may appear concurrent hyps that were covered by the removed hyp
490 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
491 subMesh->IsApplicableHypotesis( anHyp ) &&
492 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
493 ret = SMESH_Hypothesis::HYP_CONCURENT;
496 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
497 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
499 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
501 SMESH_Hypothesis::Hypothesis_Status ret2 =
502 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
503 if (ret2 > ret) // more severe
506 // check concurent hypotheses on ansestors
507 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
509 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
510 while ( smIt->more() ) {
511 SMESH_subMesh* sm = smIt->next();
512 if ( sm->IsApplicableHypotesis( anHyp )) {
513 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
523 if(MYDEBUG) subMesh->DumpAlgoState(true);
524 if(MYDEBUG) SCRUTE(ret);
528 //=============================================================================
532 //=============================================================================
534 const list<const SMESHDS_Hypothesis*>&
535 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
536 throw(SALOME_Exception)
538 Unexpect aCatch(SalomeException);
539 return _myMeshDS->GetHypothesis(aSubShape);
542 //=======================================================================
544 * \brief Return the hypothesis assigned to the shape
545 * \param aSubShape - the shape to check
546 * \param aFilter - the hypothesis filter
547 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
548 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
550 //=======================================================================
552 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
553 const SMESH_HypoFilter& aFilter,
554 const bool andAncestors) const
557 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
558 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
559 for ( ; hyp != hypList.end(); hyp++ ) {
560 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
561 if ( aFilter.IsOk( h, aSubShape))
567 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
568 for (; it.More(); it.Next() )
570 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
571 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
572 for ( ; hyp != hypList.end(); hyp++ ) {
573 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
574 if (aFilter.IsOk( h, it.Value() ))
582 //================================================================================
584 * \brief Return hypothesis assigned to the shape
585 * \param aSubShape - the shape to check
586 * \param aFilter - the hypothesis filter
587 * \param aHypList - the list of the found hypotheses
588 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
589 * \retval int - number of unique hypos in aHypList
591 //================================================================================
593 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
594 const SMESH_HypoFilter& aFilter,
595 list <const SMESHDS_Hypothesis * >& aHypList,
596 const bool andAncestors) const
598 set<string> hypTypes; // to exclude same type hypos from the result list
601 // only one main hypothesis is allowed
602 bool mainHypFound = false;
605 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
606 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
607 if ( hypTypes.insert( (*hyp)->GetName() ).second )
609 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
613 // get hypos from aSubShape
615 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
616 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
617 if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
618 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
619 hypTypes.insert( (*hyp)->GetName() ).second )
621 aHypList.push_back( *hyp );
623 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
628 // get hypos from ancestors of aSubShape
631 TopTools_MapOfShape map;
632 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
633 for (; it.More(); it.Next() )
635 if ( !map.Add( it.Value() ))
637 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
638 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
639 if (aFilter.IsOk( cSMESH_Hyp( *hyp ), it.Value() ) &&
640 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
641 hypTypes.insert( (*hyp)->GetName() ).second )
643 aHypList.push_back( *hyp );
645 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
653 //=============================================================================
657 //=============================================================================
659 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
661 Unexpect aCatch(SalomeException);
662 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
663 return _myMeshDS->GetScript()->GetCommands();
666 //=============================================================================
670 //=============================================================================
671 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
673 Unexpect aCatch(SalomeException);
674 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
675 _myMeshDS->GetScript()->Clear();
678 //=============================================================================
680 * Get or Create the SMESH_subMesh object implementation
682 //=============================================================================
684 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
685 throw(SALOME_Exception)
687 Unexpect aCatch(SalomeException);
688 SMESH_subMesh *aSubMesh;
689 int index = _myMeshDS->ShapeToIndex(aSubShape);
691 // for submeshes on GEOM Group
692 if ( !index && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
693 TopoDS_Iterator it( aSubShape );
695 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
698 // return NULL; // neither sub-shape nor a group
700 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
701 if ( i_sm != _mapSubMesh.end())
703 aSubMesh = i_sm->second;
707 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
708 _mapSubMesh[index] = aSubMesh;
713 //=============================================================================
715 * Get the SMESH_subMesh object implementation. Dont create it, return null
716 * if it does not exist.
718 //=============================================================================
720 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
721 throw(SALOME_Exception)
723 Unexpect aCatch(SalomeException);
724 SMESH_subMesh *aSubMesh = NULL;
726 int index = _myMeshDS->ShapeToIndex(aSubShape);
728 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
729 if ( i_sm != _mapSubMesh.end())
730 aSubMesh = i_sm->second;
735 //=============================================================================
737 * Get the SMESH_subMesh object implementation. Dont create it, return null
738 * if it does not exist.
740 //=============================================================================
742 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID)
743 throw(SALOME_Exception)
745 Unexpect aCatch(SalomeException);
747 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(aShapeID);
748 if (i_sm == _mapSubMesh.end())
753 //=======================================================================
754 //function : IsUsedHypothesis
755 //purpose : Return True if anHyp is used to mesh aSubShape
756 //=======================================================================
758 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
759 const SMESH_subMesh* aSubMesh)
761 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
763 // check if anHyp can be used to mesh aSubMesh
764 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
767 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
769 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
772 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
773 return ( anHyp == algo );
775 // algorithm parameter
778 // look trough hypotheses used by algo
779 SMESH_HypoFilter hypoKind;
780 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
781 list <const SMESHDS_Hypothesis * > usedHyps;
782 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
783 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
787 // look through all assigned hypotheses
788 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
789 return false; //GetHypothesis( aSubShape, filter, true );
792 //=============================================================================
796 //=============================================================================
798 const list < SMESH_subMesh * >&
799 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
800 throw(SALOME_Exception)
802 Unexpect aCatch(SalomeException);
803 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
804 map < int, SMESH_subMesh * >::iterator itsm;
805 _subMeshesUsingHypothesisList.clear();
806 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
808 SMESH_subMesh *aSubMesh = (*itsm).second;
809 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
810 _subMeshesUsingHypothesisList.push_back(aSubMesh);
812 return _subMeshesUsingHypothesisList;
815 //=======================================================================
816 //function : NotifySubMeshesHypothesisModification
817 //purpose : Say all submeshes using theChangedHyp that it has been modified
818 //=======================================================================
820 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
822 Unexpect aCatch(SalomeException);
824 const SMESH_Algo *foundAlgo = 0;
825 SMESH_HypoFilter algoKind, compatibleHypoKind;
826 list <const SMESHDS_Hypothesis * > usedHyps;
829 map < int, SMESH_subMesh * >::iterator itsm;
830 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
832 SMESH_subMesh *aSubMesh = (*itsm).second;
833 if ( aSubMesh->IsApplicableHypotesis( hyp ))
835 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
837 if ( !foundAlgo ) // init filter for algo search
838 algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape ));
840 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
841 ( GetHypothesis( aSubShape, algoKind, true ));
845 bool sameAlgo = ( algo == foundAlgo );
846 if ( !sameAlgo && foundAlgo )
847 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
849 if ( !sameAlgo ) { // init filter for used hypos search
850 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
851 continue; // algo does not use any hypothesis
855 // check if hyp is used by algo
857 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
858 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
860 aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
861 const_cast< SMESH_Hypothesis*>( hyp ));
863 if ( algo->GetDim() == 1 && IsPropagationHypothesis( aSubShape ))
864 CleanMeshOnPropagationChain( aSubShape );
871 //=============================================================================
873 * To store mesh contents on disk in different formats.
875 //=============================================================================
877 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
879 set<string> aGroupNames;
880 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
881 SMESH_Group* aGroup = it->second;
882 string aGroupName = aGroup->GetName();
883 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
884 if (!aGroupNames.insert(aGroupName).second)
891 void SMESH_Mesh::ExportMED(const char *file,
892 const char* theMeshName,
895 throw(SALOME_Exception)
897 Unexpect aCatch(SalomeException);
899 DriverMED_W_SMESHDS_Mesh myWriter;
900 myWriter.SetFile ( file, MED::EVersion(theVersion) );
901 myWriter.SetMesh ( _myMeshDS );
903 myWriter.SetMeshId ( _idDoc );
905 myWriter.SetMeshId ( -1 );
906 myWriter.SetMeshName( theMeshName );
909 if ( theAutoGroups ) {
910 myWriter.AddGroupOfNodes();
911 myWriter.AddGroupOfEdges();
912 myWriter.AddGroupOfFaces();
913 myWriter.AddGroupOfVolumes();
916 // Pass groups to writer. Provide unique group names.
917 set<string> aGroupNames;
919 int maxNbIter = 10000; // to guarantee cycle finish
920 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
921 SMESH_Group* aGroup = it->second;
922 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
924 string aGroupName0 = aGroup->GetName();
925 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
926 string aGroupName = aGroupName0;
927 for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) {
928 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
929 aGroupName = aString;
930 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
932 aGroupDS->SetStoreName( aGroupName.c_str() );
933 myWriter.AddGroup( aGroupDS );
941 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
943 Unexpect aCatch(SalomeException);
944 DriverDAT_W_SMDS_Mesh myWriter;
945 myWriter.SetFile(string(file));
946 myWriter.SetMesh(_myMeshDS);
947 myWriter.SetMeshId(_idDoc);
951 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
953 Unexpect aCatch(SalomeException);
954 DriverUNV_W_SMDS_Mesh myWriter;
955 myWriter.SetFile(string(file));
956 myWriter.SetMesh(_myMeshDS);
957 myWriter.SetMeshId(_idDoc);
958 // myWriter.SetGroups(_mapGroup);
960 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
961 SMESH_Group* aGroup = it->second;
962 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
964 string aGroupName = aGroup->GetName();
965 aGroupDS->SetStoreName( aGroupName.c_str() );
966 myWriter.AddGroup( aGroupDS );
972 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
974 Unexpect aCatch(SalomeException);
975 DriverSTL_W_SMDS_Mesh myWriter;
976 myWriter.SetFile(string(file));
977 myWriter.SetIsAscii( isascii );
978 myWriter.SetMesh(_myMeshDS);
979 myWriter.SetMeshId(_idDoc);
983 //=============================================================================
987 //=============================================================================
988 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
990 Unexpect aCatch(SalomeException);
991 return _myMeshDS->NbNodes();
994 //=============================================================================
998 //=============================================================================
999 int SMESH_Mesh::NbEdges(ElementOrder order) throw(SALOME_Exception)
1001 Unexpect aCatch(SalomeException);
1002 if (order == ORDER_ANY)
1003 return _myMeshDS->NbEdges();
1006 SMDS_EdgeIteratorPtr it = _myMeshDS->edgesIterator();
1007 while (it->more()) {
1008 const SMDS_MeshEdge* cur = it->next();
1009 if ( order == ORDER_LINEAR && !cur->IsQuadratic() ||
1010 order == ORDER_QUADRATIC && cur->IsQuadratic() )
1016 //=============================================================================
1020 //=============================================================================
1021 int SMESH_Mesh::NbFaces(ElementOrder order) throw(SALOME_Exception)
1023 Unexpect aCatch(SalomeException);
1024 if (order == ORDER_ANY)
1025 return _myMeshDS->NbFaces();
1028 SMDS_FaceIteratorPtr it = _myMeshDS->facesIterator();
1029 while (it->more()) {
1030 const SMDS_MeshFace* cur = it->next();
1031 if ( order == ORDER_LINEAR && !cur->IsQuadratic() ||
1032 order == ORDER_QUADRATIC && cur->IsQuadratic() )
1038 ///////////////////////////////////////////////////////////////////////////////
1039 /// Return the number of 3 nodes faces in the mesh. This method run in O(n)
1040 ///////////////////////////////////////////////////////////////////////////////
1041 int SMESH_Mesh::NbTriangles(ElementOrder order) throw(SALOME_Exception)
1043 Unexpect aCatch(SalomeException);
1046 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1047 while (itFaces->more()) {
1048 const SMDS_MeshFace* curFace = itFaces->next();
1049 int nbnod = curFace->NbNodes();
1050 if ( !curFace->IsPoly() &&
1051 ( order == ORDER_ANY && (nbnod==3 || nbnod==6) ||
1052 order == ORDER_LINEAR && nbnod==3 ||
1053 order == ORDER_QUADRATIC && nbnod==6 ) )
1059 ///////////////////////////////////////////////////////////////////////////////
1060 /// Return the number of 4 nodes faces in the mesh. This method run in O(n)
1061 ///////////////////////////////////////////////////////////////////////////////
1062 int SMESH_Mesh::NbQuadrangles(ElementOrder order) throw(SALOME_Exception)
1064 Unexpect aCatch(SalomeException);
1067 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1068 while (itFaces->more()) {
1069 const SMDS_MeshFace* curFace = itFaces->next();
1070 int nbnod = curFace->NbNodes();
1071 if ( !curFace->IsPoly() &&
1072 ( order == ORDER_ANY && (nbnod==4 || nbnod==8) ||
1073 order == ORDER_LINEAR && nbnod==4 ||
1074 order == ORDER_QUADRATIC && nbnod==8 ) )
1080 ///////////////////////////////////////////////////////////////////////////////
1081 /// Return the number of polygonal faces in the mesh. This method run in O(n)
1082 ///////////////////////////////////////////////////////////////////////////////
1083 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1085 Unexpect aCatch(SalomeException);
1087 SMDS_FaceIteratorPtr itFaces = _myMeshDS->facesIterator();
1088 while (itFaces->more())
1089 if (itFaces->next()->IsPoly()) Nb++;
1093 //=============================================================================
1097 //=============================================================================
1098 int SMESH_Mesh::NbVolumes(ElementOrder order) throw(SALOME_Exception)
1100 Unexpect aCatch(SalomeException);
1101 if (order == ORDER_ANY)
1102 return _myMeshDS->NbVolumes();
1105 SMDS_VolumeIteratorPtr it = _myMeshDS->volumesIterator();
1106 while (it->more()) {
1107 const SMDS_MeshVolume* cur = it->next();
1108 if ( order == ORDER_LINEAR && !cur->IsQuadratic() ||
1109 order == ORDER_QUADRATIC && cur->IsQuadratic() )
1115 int SMESH_Mesh::NbTetras(ElementOrder order) throw(SALOME_Exception)
1117 Unexpect aCatch(SalomeException);
1119 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1120 while (itVolumes->more()) {
1121 const SMDS_MeshVolume* curVolume = itVolumes->next();
1122 int nbnod = curVolume->NbNodes();
1123 if ( !curVolume->IsPoly() &&
1124 ( order == ORDER_ANY && (nbnod==4 || nbnod==10) ||
1125 order == ORDER_LINEAR && nbnod==4 ||
1126 order == ORDER_QUADRATIC && nbnod==10 ) )
1132 int SMESH_Mesh::NbHexas(ElementOrder order) throw(SALOME_Exception)
1134 Unexpect aCatch(SalomeException);
1136 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1137 while (itVolumes->more()) {
1138 const SMDS_MeshVolume* curVolume = itVolumes->next();
1139 int nbnod = curVolume->NbNodes();
1140 if ( !curVolume->IsPoly() &&
1141 ( order == ORDER_ANY && (nbnod==8 || nbnod==20) ||
1142 order == ORDER_LINEAR && nbnod==8 ||
1143 order == ORDER_QUADRATIC && nbnod==20 ) )
1149 int SMESH_Mesh::NbPyramids(ElementOrder order) throw(SALOME_Exception)
1151 Unexpect aCatch(SalomeException);
1153 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1154 while (itVolumes->more()) {
1155 const SMDS_MeshVolume* curVolume = itVolumes->next();
1156 int nbnod = curVolume->NbNodes();
1157 if ( !curVolume->IsPoly() &&
1158 ( order == ORDER_ANY && (nbnod==5 || nbnod==13) ||
1159 order == ORDER_LINEAR && nbnod==5 ||
1160 order == ORDER_QUADRATIC && nbnod==13 ) )
1166 int SMESH_Mesh::NbPrisms(ElementOrder order) throw(SALOME_Exception)
1168 Unexpect aCatch(SalomeException);
1170 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1171 while (itVolumes->more()) {
1172 const SMDS_MeshVolume* curVolume = itVolumes->next();
1173 int nbnod = curVolume->NbNodes();
1174 if ( !curVolume->IsPoly() &&
1175 ( order == ORDER_ANY && (nbnod==6 || nbnod==15) ||
1176 order == ORDER_LINEAR && nbnod==6 ||
1177 order == ORDER_QUADRATIC && nbnod==15 ) )
1183 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1185 Unexpect aCatch(SalomeException);
1187 SMDS_VolumeIteratorPtr itVolumes = _myMeshDS->volumesIterator();
1188 while (itVolumes->more())
1189 if (itVolumes->next()->IsPoly()) Nb++;
1193 //=============================================================================
1197 //=============================================================================
1198 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1200 Unexpect aCatch(SalomeException);
1201 return _myMeshDS->NbSubMesh();
1204 //=======================================================================
1205 //function : IsNotConformAllowed
1206 //purpose : check if a hypothesis alowing notconform mesh is present
1207 //=======================================================================
1209 bool SMESH_Mesh::IsNotConformAllowed() const
1211 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1213 SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1214 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1217 //=======================================================================
1218 //function : IsMainShape
1220 //=======================================================================
1222 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1224 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1227 //=============================================================================
1231 //=============================================================================
1233 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1234 const char* theName,
1236 const TopoDS_Shape& theShape)
1238 if (_mapGroup.find(_groupId) != _mapGroup.end())
1241 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1242 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1243 _mapGroup[_groupId++] = aGroup;
1247 //=============================================================================
1251 //=============================================================================
1253 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1255 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1257 return _mapGroup[theGroupID];
1261 //=============================================================================
1265 //=============================================================================
1267 list<int> SMESH_Mesh::GetGroupIds()
1270 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1271 anIds.push_back( it->first );
1277 //=============================================================================
1281 //=============================================================================
1283 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1285 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1287 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1288 delete _mapGroup[theGroupID];
1289 _mapGroup.erase (theGroupID);
1292 //=============================================================================
1294 * IsLocal1DHypothesis
1295 * Returns a local 1D hypothesis used for theEdge
1297 //=============================================================================
1298 const SMESH_Hypothesis* SMESH_Mesh::IsLocal1DHypothesis (const TopoDS_Shape& theEdge)
1300 SMESH_HypoFilter hypo ( SMESH_HypoFilter::HasDim( 1 ));
1301 hypo.AndNot( hypo.IsAlgo() ).AndNot( hypo.IsAssignedTo( GetMeshDS()->ShapeToMesh() ));
1303 return GetHypothesis( theEdge, hypo, true );
1306 //=============================================================================
1308 * IsPropagationHypothesis
1310 //=============================================================================
1311 bool SMESH_Mesh::IsPropagationHypothesis (const TopoDS_Shape& theEdge)
1313 return _mapPropagationChains.Contains(theEdge);
1316 //=============================================================================
1318 * IsPropagatedHypothesis
1320 //=============================================================================
1321 bool SMESH_Mesh::IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
1322 TopoDS_Shape& theMainEdge)
1324 int nbChains = _mapPropagationChains.Extent();
1325 for (int i = 1; i <= nbChains; i++) {
1326 //const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
1327 const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
1328 if (aChain.Contains(theEdge)) {
1329 theMainEdge = _mapPropagationChains.FindKey(i);
1336 //=============================================================================
1340 //=============================================================================
1342 bool SMESH_Mesh::IsReversedInChain (const TopoDS_Shape& theEdge,
1343 const TopoDS_Shape& theMainEdge)
1345 if ( !theMainEdge.IsNull() && !theEdge.IsNull() &&
1346 _mapPropagationChains.Contains( theMainEdge ))
1348 const SMESH_IndexedMapOfShape& aChain =
1349 _mapPropagationChains.FindFromKey( theMainEdge );
1350 int index = aChain.FindIndex( theEdge );
1352 return aChain(index).Orientation() == TopAbs_REVERSED;
1357 //=============================================================================
1359 * CleanMeshOnPropagationChain
1361 //=============================================================================
1362 void SMESH_Mesh::CleanMeshOnPropagationChain (const TopoDS_Shape& theMainEdge)
1364 const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromKey(theMainEdge);
1365 int i, nbEdges = aChain.Extent();
1366 for (i = 1; i <= nbEdges; i++) {
1367 TopoDS_Shape anEdge = aChain.FindKey(i);
1368 SMESH_subMesh *subMesh = GetSubMesh(anEdge);
1369 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
1370 if (subMeshDS && subMeshDS->NbElements() > 0) {
1371 subMesh->ComputeStateEngine(SMESH_subMesh::CLEAN);
1376 //=============================================================================
1378 * RebuildPropagationChains
1379 * Rebuild all existing propagation chains.
1380 * Have to be used, if 1D hypothesis have been assigned/removed to/from any edge
1382 //=============================================================================
1383 bool SMESH_Mesh::RebuildPropagationChains()
1387 // Clean all chains, because they can be not up-to-date
1388 int i, nbChains = _mapPropagationChains.Extent();
1389 for (i = 1; i <= nbChains; i++) {
1390 TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1391 CleanMeshOnPropagationChain(aMainEdge);
1392 _mapPropagationChains.ChangeFromIndex(i).Clear();
1396 for (i = 1; i <= nbChains; i++) {
1397 TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1398 if (!BuildPropagationChain(aMainEdge))
1400 CleanMeshOnPropagationChain(aMainEdge);
1406 //=============================================================================
1408 * RemovePropagationChain
1409 * Have to be used, if Propagation hypothesis is removed from <theMainEdge>
1411 //=============================================================================
1412 bool SMESH_Mesh::RemovePropagationChain (const TopoDS_Shape& theMainEdge)
1414 if (!_mapPropagationChains.Contains(theMainEdge))
1417 // Clean mesh elements and nodes, built on the chain
1418 CleanMeshOnPropagationChain(theMainEdge);
1421 _mapPropagationChains.ChangeFromKey(theMainEdge).Clear();
1423 // Remove the chain from the map
1424 int i = _mapPropagationChains.FindIndex(theMainEdge);
1425 if ( i == _mapPropagationChains.Extent() )
1426 _mapPropagationChains.RemoveLast();
1428 TopoDS_Vertex anEmptyShape;
1430 BB.MakeVertex(anEmptyShape, gp_Pnt(0,0,0), 0.1);
1431 SMESH_IndexedMapOfShape anEmptyMap;
1432 _mapPropagationChains.Substitute(i, anEmptyShape, anEmptyMap);
1438 //=============================================================================
1440 * BuildPropagationChain
1442 //=============================================================================
1443 bool SMESH_Mesh::BuildPropagationChain (const TopoDS_Shape& theMainEdge)
1445 if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
1447 // Add new chain, if there is no
1448 if (!_mapPropagationChains.Contains(theMainEdge)) {
1449 SMESH_IndexedMapOfShape aNewChain;
1450 _mapPropagationChains.Add(theMainEdge, aNewChain);
1453 // Check presence of 1D hypothesis to be propagated
1454 const SMESH_Hypothesis* aMainHyp = IsLocal1DHypothesis(theMainEdge);
1456 MESSAGE("Warning: There is no 1D hypothesis to propagate. Please, assign.");
1460 // Edges, on which the 1D hypothesis will be propagated from <theMainEdge>
1461 SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.ChangeFromKey(theMainEdge);
1462 if (aChain.Extent() > 0) {
1463 CleanMeshOnPropagationChain(theMainEdge);
1467 // At first put <theMainEdge> in the chain
1468 aChain.Add(theMainEdge);
1470 // List of edges, added to chain on the previous cycle pass
1471 TopTools_ListOfShape listPrevEdges;
1472 listPrevEdges.Append(theMainEdge.Oriented( TopAbs_FORWARD ));
1474 // 5____4____3____4____5____6
1477 // 4____3____2____3____4____5
1478 // | | | | | | Number in the each knot of
1479 // | | | | | | grid indicates cycle pass,
1480 // 3____2____1____2____3____4 on which corresponding edge
1481 // | | | | | | (perpendicular to the plane
1482 // | | | | | | of view) will be found.
1483 // 2____1____0____1____2____3
1486 // 3____2____1____2____3____4
1488 // Collect all edges pass by pass
1489 while (listPrevEdges.Extent() > 0) {
1490 // List of edges, added to chain on this cycle pass
1491 TopTools_ListOfShape listCurEdges;
1493 // Find the next portion of edges
1494 TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
1495 for (; itE.More(); itE.Next()) {
1496 TopoDS_Shape anE = itE.Value();
1498 // Iterate on faces, having edge <anE>
1499 TopTools_ListIteratorOfListOfShape itA (GetAncestors(anE));
1500 for (; itA.More(); itA.Next()) {
1501 TopoDS_Shape aW = itA.Value();
1503 // There are objects of different type among the ancestors of edge
1504 if (aW.ShapeType() == TopAbs_WIRE) {
1505 TopoDS_Shape anOppE;
1507 BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
1508 Standard_Integer nb = 1, found = 0;
1509 TopTools_Array1OfShape anEdges (1,4);
1510 for (; aWE.More(); aWE.Next(), nb++) {
1515 anEdges(nb) = aWE.Current();
1516 if (!_mapAncestors.Contains(anEdges(nb))) {
1517 MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!");
1520 if (anEdges(nb).IsSame(anE)) found = nb;
1523 if (nb == 5 && found > 0) {
1524 // Quadrangle face found, get an opposite edge
1525 Standard_Integer opp = found + 2;
1526 if (opp > 4) opp -= 4;
1527 anOppE = anEdges(opp);
1529 // add anOppE to aChain if ...
1530 if (!aChain.Contains(anOppE)) { // ... anOppE is not in aChain
1531 if (!IsLocal1DHypothesis(anOppE)) { // ... no other 1d hyp on anOppE
1532 TopoDS_Shape aMainEdgeForOppEdge; // ... no other hyp is propagated to anOppE
1533 if (!IsPropagatedHypothesis(anOppE, aMainEdgeForOppEdge))
1535 // Add found edge to the chain oriented so that to
1536 // have it co-directed with a forward MainEdge
1537 TopAbs_Orientation ori = anE.Orientation();
1538 if ( anEdges(opp).Orientation() == anEdges(found).Orientation() )
1539 ori = TopAbs::Reverse( ori );
1540 anOppE.Orientation( ori );
1542 listCurEdges.Append(anOppE);
1546 MESSAGE("Error: Collision between propagated hypotheses");
1547 CleanMeshOnPropagationChain(theMainEdge);
1549 return ( aMainHyp == IsLocal1DHypothesis(aMainEdgeForOppEdge) );
1553 } // if (nb == 5 && found > 0)
1554 } // if (aF.ShapeType() == TopAbs_WIRE)
1555 } // for (; itF.More(); itF.Next())
1556 } // for (; itE.More(); itE.Next())
1558 listPrevEdges = listCurEdges;
1559 } // while (listPrevEdges.Extent() > 0)
1561 CleanMeshOnPropagationChain(theMainEdge);
1565 //=======================================================================
1566 //function : GetAncestors
1567 //purpose : return list of ancestors of theSubShape in the order
1568 // that lower dimention shapes come first.
1569 //=======================================================================
1571 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1573 if ( _mapAncestors.Contains( theS ) )
1574 return _mapAncestors.FindFromKey( theS );
1576 static TopTools_ListOfShape emptyList;
1580 //=======================================================================
1582 //purpose : dumps contents of mesh to stream [ debug purposes ]
1583 //=======================================================================
1584 ostream& SMESH_Mesh::Dump(ostream& save)
1587 save << "========================== Dump contents of mesh ==========================" << endl << endl;
1588 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
1589 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
1590 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
1591 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
1592 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
1593 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
1594 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
1596 string orderStr = isQuadratic ? "quadratic" : "linear";
1597 ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
1599 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
1600 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
1601 if ( NbFaces(order) > 0 ) {
1602 int nb3 = NbTriangles(order);
1603 int nb4 = NbQuadrangles(order);
1604 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
1605 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
1606 if ( nb3 + nb4 != NbFaces(order) ) {
1607 map<int,int> myFaceMap;
1608 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1609 while( itFaces->more( ) ) {
1610 int nbNodes = itFaces->next()->NbNodes();
1611 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1612 myFaceMap[ nbNodes ] = 0;
1613 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1615 save << clause << ".3) Faces in detail: " << endl;
1616 map <int,int>::iterator itF;
1617 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1618 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
1621 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
1622 if ( NbVolumes(order) > 0 ) {
1623 int nb8 = NbHexas(order);
1624 int nb4 = NbTetras(order);
1625 int nb5 = NbPyramids(order);
1626 int nb6 = NbPrisms(order);
1627 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
1628 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
1629 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
1630 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
1631 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
1632 map<int,int> myVolumesMap;
1633 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1634 while( itVolumes->more( ) ) {
1635 int nbNodes = itVolumes->next()->NbNodes();
1636 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1637 myVolumesMap[ nbNodes ] = 0;
1638 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1640 save << clause << ".5) Volumes in detail: " << endl;
1641 map <int,int>::iterator itV;
1642 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1643 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
1648 save << "===========================================================================" << endl;
1652 //=======================================================================
1653 //function : GetElementType
1654 //purpose : Returns type of mesh element with certain id
1655 //=======================================================================
1656 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1658 return _myMeshDS->GetElementType( id, iselem );