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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 <BRep_Builder.hxx>
55 #include <TCollection_AsciiString.hxx>
57 #include <TopTools_ListOfShape.hxx>
58 #include <TopTools_Array1OfShape.hxx>
59 #include <TopTools_ListIteratorOfListOfShape.hxx>
60 #include <TopTools_MapOfShape.hxx>
64 #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;
76 //=============================================================================
80 //=============================================================================
82 SMESH_Mesh::SMESH_Mesh(int theLocalId,
85 bool theIsEmbeddedMode,
86 SMESHDS_Document* theDocument):
89 INFOS("SMESH_Mesh::SMESH_Mesh(int localId)");
91 _studyId = theStudyId;
93 _myDocument = theDocument;
94 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
95 _myMeshDS = theDocument->GetMesh(_idDoc);
96 _isShapeToMesh = false;
99 //=============================================================================
103 //=============================================================================
105 SMESH_Mesh::~SMESH_Mesh()
107 INFOS("SMESH_Mesh::~SMESH_Mesh");
110 map < int, SMESH_Group * >::iterator itg;
111 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
112 SMESH_Group *aGroup = (*itg).second;
117 //=============================================================================
121 //=============================================================================
123 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
125 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
127 if ( !_myMeshDS->ShapeToMesh().IsNull() && aShape.IsNull() )
129 // removal of a shape to mesh, delete objects referring to sub-shapes:
131 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
132 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
135 // - groups on geometry
136 map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
137 while ( i_gr != _mapGroup.end() ) {
138 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
139 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
141 _mapGroup.erase( i_gr++ );
146 _mapPropagationChains.Clear();
151 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
153 _isShapeToMesh = true;
154 _myMeshDS->ShapeToMesh(aShape);
156 // fill _mapAncestors
157 _mapAncestors.Clear();
158 int desType, ancType;
159 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
160 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
161 TopExp::MapShapesAndAncestors ( aShape,
162 (TopAbs_ShapeEnum) desType,
163 (TopAbs_ShapeEnum) ancType,
167 //EAP: 1/9/04 TopExp::MapShapes(aShape, _subShapes); USE the same map of _myMeshDS
170 //=======================================================================
171 //function : UNVToMesh
173 //=======================================================================
175 int SMESH_Mesh::UNVToMesh(const char* theFileName)
177 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
179 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
180 _isShapeToMesh = true;
181 DriverUNV_R_SMDS_Mesh myReader;
182 myReader.SetMesh(_myMeshDS);
183 myReader.SetFile(theFileName);
184 myReader.SetMeshId(-1);
187 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
188 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
189 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
190 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
195 //=======================================================================
196 //function : MEDToMesh
198 //=======================================================================
200 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
202 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
204 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
205 _isShapeToMesh = true;
206 DriverMED_R_SMESHDS_Mesh myReader;
207 myReader.SetMesh(_myMeshDS);
208 myReader.SetMeshId(-1);
209 myReader.SetFile(theFileName);
210 myReader.SetMeshName(theMeshName);
211 Driver_Mesh::Status status = myReader.Perform();
213 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
214 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
215 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
216 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
219 // Reading groups (sub-meshes are out of scope of MED import functionality)
220 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
221 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
223 list<TNameAndType>::iterator name_type = aGroupNames.begin();
224 for ( ; name_type != aGroupNames.end(); name_type++ ) {
225 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
227 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
228 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
230 aGroupDS->SetStoreName( name_type->first.c_str() );
231 myReader.GetGroup( aGroupDS );
238 //=======================================================================
239 //function : STLToMesh
241 //=======================================================================
243 int SMESH_Mesh::STLToMesh(const char* theFileName)
245 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
247 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
248 _isShapeToMesh = true;
249 DriverSTL_R_SMDS_Mesh myReader;
250 myReader.SetMesh(_myMeshDS);
251 myReader.SetFile(theFileName);
252 myReader.SetMeshId(-1);
255 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
256 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
257 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
258 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
263 //=============================================================================
267 //=============================================================================
269 SMESH_Hypothesis::Hypothesis_Status
270 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
271 int anHypId ) throw(SALOME_Exception)
273 Unexpect aCatch(SalomeException);
274 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
276 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
277 if ( !subMesh || !subMesh->GetId())
278 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
280 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
281 if ( subMeshDS && subMeshDS->IsComplexSubmesh() ) // group of sub-shapes and maybe of not sub-
283 MESSAGE("AddHypothesis() to complex submesh");
284 // return the worst but not fatal state of all group memebers
285 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
286 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
287 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
288 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
290 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
291 continue; // not sub-shape
292 ret = AddHypothesis( itS.Value(), anHypId );
293 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
294 aWorstNotFatal = ret;
295 if ( ret < aBestRet )
298 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
300 return aWorstNotFatal;
303 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
304 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
306 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
311 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
314 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
315 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
317 bool isGlobalHyp = IsMainShape( aSubShape );
319 // NotConformAllowed can be only global
322 string hypName = anHyp->GetName();
323 if ( hypName == "NotConformAllowed" )
325 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
326 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
333 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
334 event = SMESH_subMesh::ADD_HYP;
336 event = SMESH_subMesh::ADD_ALGO;
337 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
340 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
341 !subMesh->IsApplicableHypotesis( anHyp )) // is added on father
343 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
344 event = SMESH_subMesh::ADD_FATHER_HYP;
346 event = SMESH_subMesh::ADD_FATHER_ALGO;
347 SMESH_Hypothesis::Hypothesis_Status ret2 =
348 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
352 // check concurent hypotheses on ansestors
353 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
355 const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn();
356 map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin();
357 for ( ; smIt != smMap.end(); smIt++ ) {
358 if ( smIt->second->IsApplicableHypotesis( anHyp )) {
359 ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() );
369 if(MYDEBUG) subMesh->DumpAlgoState(true);
374 //=============================================================================
378 //=============================================================================
380 SMESH_Hypothesis::Hypothesis_Status
381 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
382 int anHypId)throw(SALOME_Exception)
384 Unexpect aCatch(SalomeException);
385 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
387 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
388 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
389 if ( subMeshDS && subMeshDS->IsComplexSubmesh() )
391 // return the worst but not fatal state of all group memebers
392 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
393 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
394 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
395 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
397 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
398 continue; // not sub-shape
399 ret = RemoveHypothesis( itS.Value(), anHypId );
400 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
401 aWorstNotFatal = ret;
402 if ( ret < aBestRet )
405 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
407 return aWorstNotFatal;
410 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
411 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
412 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
414 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
415 int hypType = anHyp->GetType();
416 if(MYDEBUG) SCRUTE(hypType);
421 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
422 event = SMESH_subMesh::REMOVE_HYP;
424 event = SMESH_subMesh::REMOVE_ALGO;
425 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
427 // there may appear concurrent hyps that were covered by the removed hyp
428 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
429 subMesh->IsApplicableHypotesis( anHyp ) &&
430 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
431 ret = SMESH_Hypothesis::HYP_CONCURENT;
434 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
435 !subMesh->IsApplicableHypotesis( anHyp )) // is removed from father
437 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
438 event = SMESH_subMesh::REMOVE_FATHER_HYP;
440 event = SMESH_subMesh::REMOVE_FATHER_ALGO;
441 SMESH_Hypothesis::Hypothesis_Status ret2 =
442 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
443 if (ret2 > ret) // more severe
446 // check concurent hypotheses on ansestors
447 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
449 const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn();
450 map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin();
451 for ( ; smIt != smMap.end(); smIt++ ) {
452 if ( smIt->second->IsApplicableHypotesis( anHyp )) {
453 ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() );
463 if(MYDEBUG) subMesh->DumpAlgoState(true);
464 if(MYDEBUG) SCRUTE(ret);
468 //=============================================================================
472 //=============================================================================
474 SMESHDS_Mesh * SMESH_Mesh::GetMeshDS()
479 //=============================================================================
483 //=============================================================================
485 const list<const SMESHDS_Hypothesis*>&
486 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
487 throw(SALOME_Exception)
489 Unexpect aCatch(SalomeException);
490 return _myMeshDS->GetHypothesis(aSubShape);
493 //=======================================================================
494 //function : GetHypothesis
496 //=======================================================================
498 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
499 const SMESH_HypoFilter& aFilter,
500 const bool andAncestors) const
503 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
504 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
505 for ( ; hyp != hypList.end(); hyp++ ) {
506 const SMESH_Hypothesis * h = static_cast<const SMESH_Hypothesis*>( *hyp );
507 if ( aFilter.IsOk( h, aSubShape))
513 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
514 for (; it.More(); it.Next() )
516 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
517 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
518 for ( ; hyp != hypList.end(); hyp++ ) {
519 const SMESH_Hypothesis * h = static_cast<const SMESH_Hypothesis*>( *hyp );
520 if (aFilter.IsOk( h, it.Value() ))
528 //=======================================================================
529 //function : GetHypotheses
531 //=======================================================================
533 //================================================================================
535 * \brief Return hypothesis assigned to the shape
536 * \param aSubShape - the shape to check
537 * \param aFilter - the hypothesis filter
538 * \param aHypList - the list of the found hypotheses
539 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
540 * \retval int - number of unique hypos in aHypList
542 //================================================================================
544 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
545 const SMESH_HypoFilter& aFilter,
546 list <const SMESHDS_Hypothesis * >& aHypList,
547 const bool andAncestors) const
549 set<string> hypTypes; // to exclude same type hypos from the result list
553 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
554 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ )
555 if ( hypTypes.insert( (*hyp)->GetName() ).second )
558 // get hypos from aSubShape
560 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
561 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
562 if ( aFilter.IsOk (static_cast<const SMESH_Hypothesis*>( *hyp ), aSubShape) &&
563 hypTypes.insert( (*hyp)->GetName() ).second )
565 aHypList.push_back( *hyp );
570 // get hypos from ancestors of aSubShape
573 TopTools_MapOfShape map;
574 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
575 for (; it.More(); it.Next() )
577 if ( !map.Add( it.Value() ))
579 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
580 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
581 if (aFilter.IsOk( static_cast<const SMESH_Hypothesis*>( *hyp ), it.Value() ) &&
582 hypTypes.insert( (*hyp)->GetName() ).second ) {
583 aHypList.push_back( *hyp );
591 //=============================================================================
595 //=============================================================================
597 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
599 Unexpect aCatch(SalomeException);
600 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
601 return _myMeshDS->GetScript()->GetCommands();
604 //=============================================================================
608 //=============================================================================
609 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
611 Unexpect aCatch(SalomeException);
612 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
613 _myMeshDS->GetScript()->Clear();
616 //=============================================================================
620 //=============================================================================
622 int SMESH_Mesh::GetId()
624 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetId");
628 //=============================================================================
632 //=============================================================================
634 SMESH_Gen *SMESH_Mesh::GetGen()
639 //=============================================================================
641 * Get or Create the SMESH_subMesh object implementation
643 //=============================================================================
645 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
646 throw(SALOME_Exception)
648 Unexpect aCatch(SalomeException);
649 SMESH_subMesh *aSubMesh;
650 int index = _myMeshDS->ShapeToIndex(aSubShape);
652 // for submeshes on GEOM Group
653 if ( !index && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
654 TopoDS_Iterator it( aSubShape );
656 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
659 // return NULL; // neither sub-shape nor a group
661 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
662 if ( i_sm != _mapSubMesh.end())
664 aSubMesh = i_sm->second;
668 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
669 _mapSubMesh[index] = aSubMesh;
674 //=============================================================================
676 * Get the SMESH_subMesh object implementation. Dont create it, return null
677 * if it does not exist.
679 //=============================================================================
681 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
682 throw(SALOME_Exception)
684 Unexpect aCatch(SalomeException);
685 SMESH_subMesh *aSubMesh = NULL;
687 int index = _myMeshDS->ShapeToIndex(aSubShape);
689 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
690 if ( i_sm != _mapSubMesh.end())
691 aSubMesh = i_sm->second;
696 //=============================================================================
698 * Get the SMESH_subMesh object implementation. Dont create it, return null
699 * if it does not exist.
701 //=============================================================================
703 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID)
704 throw(SALOME_Exception)
706 Unexpect aCatch(SalomeException);
708 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(aShapeID);
709 if (i_sm == _mapSubMesh.end())
714 //=======================================================================
715 //function : IsUsedHypothesis
716 //purpose : Return True if anHyp is used to mesh aSubShape
717 //=======================================================================
719 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
720 const SMESH_subMesh* aSubMesh)
722 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
724 // check if anHyp can be used to mesh aSubMesh
725 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
728 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
730 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
733 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
734 return ( anHyp == algo );
736 // algorithm parameter
739 // look trough hypotheses used by algo
740 SMESH_HypoFilter hypoKind;
741 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
742 list <const SMESHDS_Hypothesis * > usedHyps;
743 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
744 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
748 // look through all assigned hypotheses
749 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
750 return false; //GetHypothesis( aSubShape, filter, true );
753 //=============================================================================
757 //=============================================================================
759 const list < SMESH_subMesh * >&
760 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
761 throw(SALOME_Exception)
763 Unexpect aCatch(SalomeException);
764 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
765 map < int, SMESH_subMesh * >::iterator itsm;
766 _subMeshesUsingHypothesisList.clear();
767 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
769 SMESH_subMesh *aSubMesh = (*itsm).second;
770 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
771 _subMeshesUsingHypothesisList.push_back(aSubMesh);
773 return _subMeshesUsingHypothesisList;
776 //=======================================================================
777 //function : NotifySubMeshesHypothesisModification
778 //purpose : Say all submeshes using theChangedHyp that it has been modified
779 //=======================================================================
781 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp)
783 Unexpect aCatch(SalomeException);
785 const SMESH_Hypothesis* hyp = static_cast<const SMESH_Hypothesis*>(theChangedHyp);
787 const SMESH_Algo *foundAlgo = 0;
788 SMESH_HypoFilter algoKind( SMESH_HypoFilter::IsAlgo() );
789 SMESH_HypoFilter compatibleHypoKind;
790 list <const SMESHDS_Hypothesis * > usedHyps;
793 map < int, SMESH_subMesh * >::iterator itsm;
794 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
796 SMESH_subMesh *aSubMesh = (*itsm).second;
797 if ( aSubMesh->IsApplicableHypotesis( hyp ))
799 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
801 if ( !foundAlgo ) // init filter for algo search
802 algoKind.And( algoKind.IsApplicableTo( aSubShape ));
804 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
805 ( GetHypothesis( aSubShape, algoKind, true ));
809 bool sameAlgo = ( algo == foundAlgo );
810 if ( !sameAlgo && foundAlgo )
811 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
813 if ( !sameAlgo ) { // init filter for used hypos search
814 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
815 continue; // algo does not use any hypothesis
819 // check if hyp is used by algo
821 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
822 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
824 aSubMesh->ComputeStateEngine(SMESH_subMesh::MODIF_HYP);
826 if ( algo->GetDim() == 1 && IsPropagationHypothesis( aSubShape ))
827 CleanMeshOnPropagationChain( aSubShape );
834 //=============================================================================
836 * To store mesh contents on disk in different formats.
838 //=============================================================================
840 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
842 set<string> aGroupNames;
843 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
844 SMESH_Group* aGroup = it->second;
845 string aGroupName = aGroup->GetName();
846 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
847 if (!aGroupNames.insert(aGroupName).second)
854 void SMESH_Mesh::ExportMED(const char *file,
855 const char* theMeshName,
858 throw(SALOME_Exception)
860 Unexpect aCatch(SalomeException);
862 DriverMED_W_SMESHDS_Mesh myWriter;
863 myWriter.SetFile ( file, MED::EVersion(theVersion) );
864 myWriter.SetMesh ( _myMeshDS );
866 myWriter.SetMeshId ( _idDoc );
868 myWriter.SetMeshId ( -1 );
869 myWriter.SetMeshName( theMeshName );
872 if ( theAutoGroups ) {
873 myWriter.AddGroupOfNodes();
874 myWriter.AddGroupOfEdges();
875 myWriter.AddGroupOfFaces();
876 myWriter.AddGroupOfVolumes();
879 // Pass groups to writer. Provide unique group names.
880 set<string> aGroupNames;
882 int maxNbIter = 10000; // to guarantee cycle finish
883 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
884 SMESH_Group* aGroup = it->second;
885 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
887 string aGroupName0 = aGroup->GetName();
888 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
889 string aGroupName = aGroupName0;
890 for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) {
891 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
892 aGroupName = aString;
893 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
895 aGroupDS->SetStoreName( aGroupName.c_str() );
896 myWriter.AddGroup( aGroupDS );
904 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
906 Unexpect aCatch(SalomeException);
907 DriverDAT_W_SMDS_Mesh myWriter;
908 myWriter.SetFile(string(file));
909 myWriter.SetMesh(_myMeshDS);
910 myWriter.SetMeshId(_idDoc);
914 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
916 Unexpect aCatch(SalomeException);
917 DriverUNV_W_SMDS_Mesh myWriter;
918 myWriter.SetFile(string(file));
919 myWriter.SetMesh(_myMeshDS);
920 myWriter.SetMeshId(_idDoc);
924 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
926 Unexpect aCatch(SalomeException);
927 DriverSTL_W_SMDS_Mesh myWriter;
928 myWriter.SetFile(string(file));
929 myWriter.SetIsAscii( isascii );
930 myWriter.SetMesh(_myMeshDS);
931 myWriter.SetMeshId(_idDoc);
935 //=============================================================================
939 //=============================================================================
940 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
942 Unexpect aCatch(SalomeException);
943 return _myMeshDS->NbNodes();
946 //=============================================================================
950 //=============================================================================
951 int SMESH_Mesh::NbEdges() throw(SALOME_Exception)
953 Unexpect aCatch(SalomeException);
954 return _myMeshDS->NbEdges();
957 //=============================================================================
961 //=============================================================================
962 int SMESH_Mesh::NbFaces() throw(SALOME_Exception)
964 Unexpect aCatch(SalomeException);
965 return _myMeshDS->NbFaces();
968 ///////////////////////////////////////////////////////////////////////////////
969 /// Return the number of 3 nodes faces in the mesh. This method run in O(n)
970 ///////////////////////////////////////////////////////////////////////////////
971 int SMESH_Mesh::NbTriangles() throw(SALOME_Exception)
973 Unexpect aCatch(SalomeException);
976 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
977 //while(itFaces->more()) if(itFaces->next()->NbNodes()==3) Nb++;
978 const SMDS_MeshFace * curFace;
979 while (itFaces->more()) {
980 curFace = itFaces->next();
981 if ( !curFace->IsPoly() &&
982 ( curFace->NbNodes()==3 || curFace->NbNodes()==6 ) ) Nb++;
987 ///////////////////////////////////////////////////////////////////////////////
988 /// Return the number of 4 nodes faces in the mesh. This method run in O(n)
989 ///////////////////////////////////////////////////////////////////////////////
990 int SMESH_Mesh::NbQuadrangles() throw(SALOME_Exception)
992 Unexpect aCatch(SalomeException);
995 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
996 //while(itFaces->more()) if(itFaces->next()->NbNodes()==4) Nb++;
997 const SMDS_MeshFace * curFace;
998 while (itFaces->more()) {
999 curFace = itFaces->next();
1000 if ( !curFace->IsPoly() &&
1001 ( curFace->NbNodes() == 4 || curFace->NbNodes()==8 ) ) Nb++;
1006 ///////////////////////////////////////////////////////////////////////////////
1007 /// Return the number of polygonal faces in the mesh. This method run in O(n)
1008 ///////////////////////////////////////////////////////////////////////////////
1009 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1011 Unexpect aCatch(SalomeException);
1013 SMDS_FaceIteratorPtr itFaces = _myMeshDS->facesIterator();
1014 while (itFaces->more())
1015 if (itFaces->next()->IsPoly()) Nb++;
1019 //=============================================================================
1023 //=============================================================================
1024 int SMESH_Mesh::NbVolumes() throw(SALOME_Exception)
1026 Unexpect aCatch(SalomeException);
1027 return _myMeshDS->NbVolumes();
1030 int SMESH_Mesh::NbTetras() throw(SALOME_Exception)
1032 Unexpect aCatch(SalomeException);
1034 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1035 //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==4) Nb++;
1036 const SMDS_MeshVolume * curVolume;
1037 while (itVolumes->more()) {
1038 curVolume = itVolumes->next();
1039 if ( !curVolume->IsPoly() &&
1040 ( curVolume->NbNodes() == 4 || curVolume->NbNodes()==10 ) ) Nb++;
1045 int SMESH_Mesh::NbHexas() throw(SALOME_Exception)
1047 Unexpect aCatch(SalomeException);
1049 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1050 //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==8) Nb++;
1051 const SMDS_MeshVolume * curVolume;
1052 while (itVolumes->more()) {
1053 curVolume = itVolumes->next();
1054 if ( !curVolume->IsPoly() &&
1055 ( curVolume->NbNodes() == 8 || curVolume->NbNodes()==20 ) ) Nb++;
1060 int SMESH_Mesh::NbPyramids() throw(SALOME_Exception)
1062 Unexpect aCatch(SalomeException);
1064 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1065 //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==5) Nb++;
1066 const SMDS_MeshVolume * curVolume;
1067 while (itVolumes->more()) {
1068 curVolume = itVolumes->next();
1069 if ( !curVolume->IsPoly() &&
1070 ( curVolume->NbNodes() == 5 || curVolume->NbNodes()==13 ) ) Nb++;
1075 int SMESH_Mesh::NbPrisms() throw(SALOME_Exception)
1077 Unexpect aCatch(SalomeException);
1079 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1080 //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==6) Nb++;
1081 const SMDS_MeshVolume * curVolume;
1082 while (itVolumes->more()) {
1083 curVolume = itVolumes->next();
1084 if ( !curVolume->IsPoly() &&
1085 ( curVolume->NbNodes() == 6 || curVolume->NbNodes()==15 ) ) Nb++;
1090 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1092 Unexpect aCatch(SalomeException);
1094 SMDS_VolumeIteratorPtr itVolumes = _myMeshDS->volumesIterator();
1095 while (itVolumes->more())
1096 if (itVolumes->next()->IsPoly()) Nb++;
1100 //=============================================================================
1104 //=============================================================================
1105 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1107 Unexpect aCatch(SalomeException);
1108 return _myMeshDS->NbSubMesh();
1111 //=======================================================================
1112 //function : IsNotConformAllowed
1113 //purpose : check if a hypothesis alowing notconform mesh is present
1114 //=======================================================================
1116 bool SMESH_Mesh::IsNotConformAllowed() const
1118 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1120 SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1121 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1124 //=======================================================================
1125 //function : IsMainShape
1127 //=======================================================================
1129 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1131 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1134 //=============================================================================
1138 //=============================================================================
1140 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1141 const char* theName,
1143 const TopoDS_Shape& theShape)
1145 if (_mapGroup.find(_groupId) != _mapGroup.end())
1148 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1149 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1150 _mapGroup[_groupId++] = aGroup;
1154 //=============================================================================
1158 //=============================================================================
1160 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1162 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1164 return _mapGroup[theGroupID];
1168 //=============================================================================
1172 //=============================================================================
1174 list<int> SMESH_Mesh::GetGroupIds()
1177 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1178 anIds.push_back( it->first );
1184 //=============================================================================
1188 //=============================================================================
1190 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1192 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1194 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1195 delete _mapGroup[theGroupID];
1196 _mapGroup.erase (theGroupID);
1199 //=============================================================================
1201 * IsLocal1DHypothesis
1202 * Returns a local 1D hypothesis used for theEdge
1204 //=============================================================================
1205 const SMESH_Hypothesis* SMESH_Mesh::IsLocal1DHypothesis (const TopoDS_Shape& theEdge)
1207 SMESH_HypoFilter hypo ( SMESH_HypoFilter::HasDim( 1 ));
1208 hypo.AndNot( hypo.IsAlgo() ).AndNot( hypo.IsAssignedTo( GetMeshDS()->ShapeToMesh() ));
1210 return GetHypothesis( theEdge, hypo, true );
1213 //=============================================================================
1215 * IsPropagationHypothesis
1217 //=============================================================================
1218 bool SMESH_Mesh::IsPropagationHypothesis (const TopoDS_Shape& theEdge)
1220 return _mapPropagationChains.Contains(theEdge);
1223 //=============================================================================
1225 * IsPropagatedHypothesis
1227 //=============================================================================
1228 bool SMESH_Mesh::IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
1229 TopoDS_Shape& theMainEdge)
1231 int nbChains = _mapPropagationChains.Extent();
1232 for (int i = 1; i <= nbChains; i++) {
1233 //const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
1234 const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
1235 if (aChain.Contains(theEdge)) {
1236 theMainEdge = _mapPropagationChains.FindKey(i);
1243 //=============================================================================
1247 //=============================================================================
1249 bool SMESH_Mesh::IsReversedInChain (const TopoDS_Shape& theEdge,
1250 const TopoDS_Shape& theMainEdge)
1252 if ( !theMainEdge.IsNull() && !theEdge.IsNull() &&
1253 _mapPropagationChains.Contains( theMainEdge ))
1255 const SMESH_IndexedMapOfShape& aChain =
1256 _mapPropagationChains.FindFromKey( theMainEdge );
1257 int index = aChain.FindIndex( theEdge );
1259 return aChain(index).Orientation() == TopAbs_REVERSED;
1264 //=============================================================================
1266 * CleanMeshOnPropagationChain
1268 //=============================================================================
1269 void SMESH_Mesh::CleanMeshOnPropagationChain (const TopoDS_Shape& theMainEdge)
1271 const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromKey(theMainEdge);
1272 int i, nbEdges = aChain.Extent();
1273 for (i = 1; i <= nbEdges; i++) {
1274 TopoDS_Shape anEdge = aChain.FindKey(i);
1275 SMESH_subMesh *subMesh = GetSubMesh(anEdge);
1276 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
1277 if (subMeshDS && subMeshDS->NbElements() > 0) {
1278 subMesh->ComputeStateEngine(SMESH_subMesh::CLEAN);
1283 //=============================================================================
1285 * RebuildPropagationChains
1286 * Rebuild all existing propagation chains.
1287 * Have to be used, if 1D hypothesis have been assigned/removed to/from any edge
1289 //=============================================================================
1290 bool SMESH_Mesh::RebuildPropagationChains()
1294 // Clean all chains, because they can be not up-to-date
1295 int i, nbChains = _mapPropagationChains.Extent();
1296 for (i = 1; i <= nbChains; i++) {
1297 TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1298 CleanMeshOnPropagationChain(aMainEdge);
1299 _mapPropagationChains.ChangeFromIndex(i).Clear();
1303 for (i = 1; i <= nbChains; i++) {
1304 TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1305 if (!BuildPropagationChain(aMainEdge))
1307 CleanMeshOnPropagationChain(aMainEdge);
1313 //=============================================================================
1315 * RemovePropagationChain
1316 * Have to be used, if Propagation hypothesis is removed from <theMainEdge>
1318 //=============================================================================
1319 bool SMESH_Mesh::RemovePropagationChain (const TopoDS_Shape& theMainEdge)
1321 if (!_mapPropagationChains.Contains(theMainEdge))
1324 // Clean mesh elements and nodes, built on the chain
1325 CleanMeshOnPropagationChain(theMainEdge);
1328 _mapPropagationChains.ChangeFromKey(theMainEdge).Clear();
1330 // Remove the chain from the map
1331 int i = _mapPropagationChains.FindIndex(theMainEdge);
1332 if ( i == _mapPropagationChains.Extent() )
1333 _mapPropagationChains.RemoveLast();
1335 TopoDS_Vertex anEmptyShape;
1337 BB.MakeVertex(anEmptyShape, gp_Pnt(0,0,0), 0.1);
1338 SMESH_IndexedMapOfShape anEmptyMap;
1339 _mapPropagationChains.Substitute(i, anEmptyShape, anEmptyMap);
1345 //=============================================================================
1347 * BuildPropagationChain
1349 //=============================================================================
1350 bool SMESH_Mesh::BuildPropagationChain (const TopoDS_Shape& theMainEdge)
1352 if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
1354 // Add new chain, if there is no
1355 if (!_mapPropagationChains.Contains(theMainEdge)) {
1356 SMESH_IndexedMapOfShape aNewChain;
1357 _mapPropagationChains.Add(theMainEdge, aNewChain);
1360 // Check presence of 1D hypothesis to be propagated
1361 const SMESH_Hypothesis* aMainHyp = IsLocal1DHypothesis(theMainEdge);
1363 MESSAGE("Warning: There is no 1D hypothesis to propagate. Please, assign.");
1367 // Edges, on which the 1D hypothesis will be propagated from <theMainEdge>
1368 SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.ChangeFromKey(theMainEdge);
1369 if (aChain.Extent() > 0) {
1370 CleanMeshOnPropagationChain(theMainEdge);
1374 // At first put <theMainEdge> in the chain
1375 aChain.Add(theMainEdge);
1377 // List of edges, added to chain on the previous cycle pass
1378 TopTools_ListOfShape listPrevEdges;
1379 listPrevEdges.Append(theMainEdge.Oriented( TopAbs_FORWARD ));
1381 // 5____4____3____4____5____6
1384 // 4____3____2____3____4____5
1385 // | | | | | | Number in the each knot of
1386 // | | | | | | grid indicates cycle pass,
1387 // 3____2____1____2____3____4 on which corresponding edge
1388 // | | | | | | (perpendicular to the plane
1389 // | | | | | | of view) will be found.
1390 // 2____1____0____1____2____3
1393 // 3____2____1____2____3____4
1395 // Collect all edges pass by pass
1396 while (listPrevEdges.Extent() > 0) {
1397 // List of edges, added to chain on this cycle pass
1398 TopTools_ListOfShape listCurEdges;
1400 // Find the next portion of edges
1401 TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
1402 for (; itE.More(); itE.Next()) {
1403 TopoDS_Shape anE = itE.Value();
1405 // Iterate on faces, having edge <anE>
1406 TopTools_ListIteratorOfListOfShape itA (GetAncestors(anE));
1407 for (; itA.More(); itA.Next()) {
1408 TopoDS_Shape aW = itA.Value();
1410 // There are objects of different type among the ancestors of edge
1411 if (aW.ShapeType() == TopAbs_WIRE) {
1412 TopoDS_Shape anOppE;
1414 BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
1415 Standard_Integer nb = 1, found = 0;
1416 TopTools_Array1OfShape anEdges (1,4);
1417 for (; aWE.More(); aWE.Next(), nb++) {
1422 anEdges(nb) = aWE.Current();
1423 if (!_mapAncestors.Contains(anEdges(nb))) {
1424 MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!");
1427 if (anEdges(nb).IsSame(anE)) found = nb;
1430 if (nb == 5 && found > 0) {
1431 // Quadrangle face found, get an opposite edge
1432 Standard_Integer opp = found + 2;
1433 if (opp > 4) opp -= 4;
1434 anOppE = anEdges(opp);
1436 // add anOppE to aChain if ...
1437 if (!aChain.Contains(anOppE)) { // ... anOppE is not in aChain
1438 if (!IsLocal1DHypothesis(anOppE)) { // ... no other 1d hyp on anOppE
1439 TopoDS_Shape aMainEdgeForOppEdge; // ... no other hyp is propagated to anOppE
1440 if (!IsPropagatedHypothesis(anOppE, aMainEdgeForOppEdge))
1442 // Add found edge to the chain oriented so that to
1443 // have it co-directed with a forward MainEdge
1444 TopAbs_Orientation ori = anE.Orientation();
1445 if ( anEdges(opp).Orientation() == anEdges(found).Orientation() )
1446 ori = TopAbs::Reverse( ori );
1447 anOppE.Orientation( ori );
1449 listCurEdges.Append(anOppE);
1453 MESSAGE("Error: Collision between propagated hypotheses");
1454 CleanMeshOnPropagationChain(theMainEdge);
1456 return ( aMainHyp == IsLocal1DHypothesis(aMainEdgeForOppEdge) );
1460 } // if (nb == 5 && found > 0)
1461 } // if (aF.ShapeType() == TopAbs_WIRE)
1462 } // for (; itF.More(); itF.Next())
1463 } // for (; itE.More(); itE.Next())
1465 listPrevEdges = listCurEdges;
1466 } // while (listPrevEdges.Extent() > 0)
1468 CleanMeshOnPropagationChain(theMainEdge);
1472 //=======================================================================
1473 //function : GetAncestors
1474 //purpose : return list of ancestors of theSubShape in the order
1475 // that lower dimention shapes come first.
1476 //=======================================================================
1478 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1480 if ( _mapAncestors.Contains( theS ) )
1481 return _mapAncestors.FindFromKey( theS );
1483 static TopTools_ListOfShape emptyList;
1487 //=======================================================================
1489 //purpose : dumps contents of mesh to stream [ debug purposes ]
1490 //=======================================================================
1491 ostream& SMESH_Mesh::Dump(ostream& save)
1493 save << "========================== Dump contents of mesh ==========================" << endl;
1494 save << "1) Total number of nodes: " << NbNodes() << endl;
1495 save << "2) Total number of edges: " << NbEdges() << endl;
1496 save << "3) Total number of faces: " << NbFaces() << endl;
1497 if ( NbFaces() > 0 ) {
1498 int nb3 = NbTriangles();
1499 int nb4 = NbQuadrangles();
1500 save << "3.1.) Number of triangles: " << nb3 << endl;
1501 save << "3.2.) Number of quadrangles: " << nb4 << endl;
1502 if ( nb3 + nb4 != NbFaces() ) {
1503 map<int,int> myFaceMap;
1504 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1505 while( itFaces->more( ) ) {
1506 int nbNodes = itFaces->next()->NbNodes();
1507 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1508 myFaceMap[ nbNodes ] = 0;
1509 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1511 save << "3.3.) Faces in detail: " << endl;
1512 map <int,int>::iterator itF;
1513 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1514 save << "--> nb nodes: " << itF->first << " - nb elemens: " << itF->second << endl;
1517 save << "4) Total number of volumes: " << NbVolumes() << endl;
1518 if ( NbVolumes() > 0 ) {
1519 int nb8 = NbHexas();
1520 int nb4 = NbTetras();
1521 int nb5 = NbPyramids();
1522 int nb6 = NbPrisms();
1523 save << "4.1.) Number of hexahedrons: " << nb8 << endl;
1524 save << "4.2.) Number of tetrahedrons: " << nb4 << endl;
1525 save << "4.3.) Number of prisms: " << nb6 << endl;
1526 save << "4.4.) Number of pyramides: " << nb5 << endl;
1527 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes() ) {
1528 map<int,int> myVolumesMap;
1529 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1530 while( itVolumes->more( ) ) {
1531 int nbNodes = itVolumes->next()->NbNodes();
1532 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1533 myVolumesMap[ nbNodes ] = 0;
1534 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1536 save << "4.5.) Volumes in detail: " << endl;
1537 map <int,int>::iterator itV;
1538 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1539 save << "--> nb nodes: " << itV->first << " - nb elemens: " << itV->second << endl;
1542 save << "===========================================================================" << endl;
1546 //=======================================================================
1547 //function : GetElementType
1548 //purpose : Returns type of mesh element with certain id
1549 //=======================================================================
1550 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1552 return _myMeshDS->GetElementType( id, iselem );