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("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
188 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
189 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
190 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
192 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
194 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
195 //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
196 aGroup->InitSubGroupsIterator();
197 while (aGroup->MoreSubGroups()) {
198 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
199 std::string aName = aGroupNames[aSubGroup];
202 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
204 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
205 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
207 aGroupDS->SetStoreName(aName.c_str());
208 aSubGroup->InitIterator();
209 const SMDS_MeshElement* aElement = 0;
210 while (aSubGroup->More()) {
211 aElement = aSubGroup->Next();
213 aGroupDS->SMDSGroup().Add(aElement);
217 aGroupDS->SetType(aElement->GetType());
225 //=======================================================================
226 //function : MEDToMesh
228 //=======================================================================
230 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
232 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
234 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
235 _isShapeToMesh = true;
236 DriverMED_R_SMESHDS_Mesh myReader;
237 myReader.SetMesh(_myMeshDS);
238 myReader.SetMeshId(-1);
239 myReader.SetFile(theFileName);
240 myReader.SetMeshName(theMeshName);
241 Driver_Mesh::Status status = myReader.Perform();
243 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
244 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
245 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
246 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
249 // Reading groups (sub-meshes are out of scope of MED import functionality)
250 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
251 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
253 list<TNameAndType>::iterator name_type = aGroupNames.begin();
254 for ( ; name_type != aGroupNames.end(); name_type++ ) {
255 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
257 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
258 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
260 aGroupDS->SetStoreName( name_type->first.c_str() );
261 myReader.GetGroup( aGroupDS );
268 //=======================================================================
269 //function : STLToMesh
271 //=======================================================================
273 int SMESH_Mesh::STLToMesh(const char* theFileName)
275 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
277 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
278 _isShapeToMesh = true;
279 DriverSTL_R_SMDS_Mesh myReader;
280 myReader.SetMesh(_myMeshDS);
281 myReader.SetFile(theFileName);
282 myReader.SetMeshId(-1);
285 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
286 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
287 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
288 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
293 //=============================================================================
297 //=============================================================================
299 SMESH_Hypothesis::Hypothesis_Status
300 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
301 int anHypId ) throw(SALOME_Exception)
303 Unexpect aCatch(SalomeException);
304 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
306 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
307 if ( !subMesh || !subMesh->GetId())
308 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
310 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
311 if ( subMeshDS && subMeshDS->IsComplexSubmesh() ) // group of sub-shapes and maybe of not sub-
313 MESSAGE("AddHypothesis() to complex submesh");
314 // return the worst but not fatal state of all group memebers
315 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
316 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
317 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
318 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
320 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
321 continue; // not sub-shape
322 ret = AddHypothesis( itS.Value(), anHypId );
323 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
324 aWorstNotFatal = ret;
325 if ( ret < aBestRet )
328 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
330 return aWorstNotFatal;
333 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
334 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
336 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
341 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
344 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
345 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
347 bool isGlobalHyp = IsMainShape( aSubShape );
349 // NotConformAllowed can be only global
352 string hypName = anHyp->GetName();
353 if ( hypName == "NotConformAllowed" )
355 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
356 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
363 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
364 event = SMESH_subMesh::ADD_HYP;
366 event = SMESH_subMesh::ADD_ALGO;
367 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
370 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
371 !subMesh->IsApplicableHypotesis( anHyp )) // is added on father
373 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
374 event = SMESH_subMesh::ADD_FATHER_HYP;
376 event = SMESH_subMesh::ADD_FATHER_ALGO;
377 SMESH_Hypothesis::Hypothesis_Status ret2 =
378 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
382 // check concurent hypotheses on ansestors
383 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
385 const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn();
386 map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin();
387 for ( ; smIt != smMap.end(); smIt++ ) {
388 if ( smIt->second->IsApplicableHypotesis( anHyp )) {
389 ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() );
399 if(MYDEBUG) subMesh->DumpAlgoState(true);
404 //=============================================================================
408 //=============================================================================
410 SMESH_Hypothesis::Hypothesis_Status
411 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
412 int anHypId)throw(SALOME_Exception)
414 Unexpect aCatch(SalomeException);
415 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
417 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
418 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
419 if ( subMeshDS && subMeshDS->IsComplexSubmesh() )
421 // return the worst but not fatal state of all group memebers
422 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
423 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
424 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
425 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
427 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
428 continue; // not sub-shape
429 ret = RemoveHypothesis( itS.Value(), anHypId );
430 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
431 aWorstNotFatal = ret;
432 if ( ret < aBestRet )
435 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
437 return aWorstNotFatal;
440 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
441 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
442 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
444 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
445 int hypType = anHyp->GetType();
446 if(MYDEBUG) SCRUTE(hypType);
451 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
452 event = SMESH_subMesh::REMOVE_HYP;
454 event = SMESH_subMesh::REMOVE_ALGO;
455 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
457 // there may appear concurrent hyps that were covered by the removed hyp
458 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
459 subMesh->IsApplicableHypotesis( anHyp ) &&
460 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
461 ret = SMESH_Hypothesis::HYP_CONCURENT;
464 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
465 !subMesh->IsApplicableHypotesis( anHyp )) // is removed from father
467 if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
468 event = SMESH_subMesh::REMOVE_FATHER_HYP;
470 event = SMESH_subMesh::REMOVE_FATHER_ALGO;
471 SMESH_Hypothesis::Hypothesis_Status ret2 =
472 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
473 if (ret2 > ret) // more severe
476 // check concurent hypotheses on ansestors
477 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
479 const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn();
480 map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin();
481 for ( ; smIt != smMap.end(); smIt++ ) {
482 if ( smIt->second->IsApplicableHypotesis( anHyp )) {
483 ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() );
493 if(MYDEBUG) subMesh->DumpAlgoState(true);
494 if(MYDEBUG) SCRUTE(ret);
498 //=============================================================================
502 //=============================================================================
504 SMESHDS_Mesh * SMESH_Mesh::GetMeshDS()
509 //=============================================================================
513 //=============================================================================
515 const list<const SMESHDS_Hypothesis*>&
516 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
517 throw(SALOME_Exception)
519 Unexpect aCatch(SalomeException);
520 return _myMeshDS->GetHypothesis(aSubShape);
523 //=======================================================================
524 //function : GetHypothesis
526 //=======================================================================
528 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
529 const SMESH_HypoFilter& aFilter,
530 const bool andAncestors) const
533 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
534 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
535 for ( ; hyp != hypList.end(); hyp++ ) {
536 const SMESH_Hypothesis * h = static_cast<const SMESH_Hypothesis*>( *hyp );
537 if ( aFilter.IsOk( h, aSubShape))
543 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
544 for (; it.More(); it.Next() )
546 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
547 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
548 for ( ; hyp != hypList.end(); hyp++ ) {
549 const SMESH_Hypothesis * h = static_cast<const SMESH_Hypothesis*>( *hyp );
550 if (aFilter.IsOk( h, it.Value() ))
558 //=======================================================================
559 //function : GetHypotheses
561 //=======================================================================
563 //================================================================================
565 * \brief Return hypothesis assigned to the shape
566 * \param aSubShape - the shape to check
567 * \param aFilter - the hypothesis filter
568 * \param aHypList - the list of the found hypotheses
569 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
570 * \retval int - number of unique hypos in aHypList
572 //================================================================================
574 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
575 const SMESH_HypoFilter& aFilter,
576 list <const SMESHDS_Hypothesis * >& aHypList,
577 const bool andAncestors) const
579 set<string> hypTypes; // to exclude same type hypos from the result list
583 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
584 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ )
585 if ( hypTypes.insert( (*hyp)->GetName() ).second )
588 // get hypos from aSubShape
590 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
591 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
592 if ( aFilter.IsOk (static_cast<const SMESH_Hypothesis*>( *hyp ), aSubShape) &&
593 hypTypes.insert( (*hyp)->GetName() ).second )
595 aHypList.push_back( *hyp );
600 // get hypos from ancestors of aSubShape
603 TopTools_MapOfShape map;
604 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
605 for (; it.More(); it.Next() )
607 if ( !map.Add( it.Value() ))
609 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
610 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
611 if (aFilter.IsOk( static_cast<const SMESH_Hypothesis*>( *hyp ), it.Value() ) &&
612 hypTypes.insert( (*hyp)->GetName() ).second ) {
613 aHypList.push_back( *hyp );
621 //=============================================================================
625 //=============================================================================
627 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
629 Unexpect aCatch(SalomeException);
630 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
631 return _myMeshDS->GetScript()->GetCommands();
634 //=============================================================================
638 //=============================================================================
639 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
641 Unexpect aCatch(SalomeException);
642 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
643 _myMeshDS->GetScript()->Clear();
646 //=============================================================================
650 //=============================================================================
652 int SMESH_Mesh::GetId()
654 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetId");
658 //=============================================================================
662 //=============================================================================
664 SMESH_Gen *SMESH_Mesh::GetGen()
669 //=============================================================================
671 * Get or Create the SMESH_subMesh object implementation
673 //=============================================================================
675 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
676 throw(SALOME_Exception)
678 Unexpect aCatch(SalomeException);
679 SMESH_subMesh *aSubMesh;
680 int index = _myMeshDS->ShapeToIndex(aSubShape);
682 // for submeshes on GEOM Group
683 if ( !index && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
684 TopoDS_Iterator it( aSubShape );
686 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
689 // return NULL; // neither sub-shape nor a group
691 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
692 if ( i_sm != _mapSubMesh.end())
694 aSubMesh = i_sm->second;
698 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
699 _mapSubMesh[index] = aSubMesh;
704 //=============================================================================
706 * Get the SMESH_subMesh object implementation. Dont create it, return null
707 * if it does not exist.
709 //=============================================================================
711 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
712 throw(SALOME_Exception)
714 Unexpect aCatch(SalomeException);
715 SMESH_subMesh *aSubMesh = NULL;
717 int index = _myMeshDS->ShapeToIndex(aSubShape);
719 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
720 if ( i_sm != _mapSubMesh.end())
721 aSubMesh = i_sm->second;
726 //=============================================================================
728 * Get the SMESH_subMesh object implementation. Dont create it, return null
729 * if it does not exist.
731 //=============================================================================
733 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID)
734 throw(SALOME_Exception)
736 Unexpect aCatch(SalomeException);
738 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(aShapeID);
739 if (i_sm == _mapSubMesh.end())
744 //=======================================================================
745 //function : IsUsedHypothesis
746 //purpose : Return True if anHyp is used to mesh aSubShape
747 //=======================================================================
749 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
750 const SMESH_subMesh* aSubMesh)
752 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
754 // check if anHyp can be used to mesh aSubMesh
755 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
758 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
760 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
763 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
764 return ( anHyp == algo );
766 // algorithm parameter
769 // look trough hypotheses used by algo
770 SMESH_HypoFilter hypoKind;
771 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
772 list <const SMESHDS_Hypothesis * > usedHyps;
773 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
774 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
778 // look through all assigned hypotheses
779 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
780 return false; //GetHypothesis( aSubShape, filter, true );
783 //=============================================================================
787 //=============================================================================
789 const list < SMESH_subMesh * >&
790 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
791 throw(SALOME_Exception)
793 Unexpect aCatch(SalomeException);
794 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
795 map < int, SMESH_subMesh * >::iterator itsm;
796 _subMeshesUsingHypothesisList.clear();
797 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
799 SMESH_subMesh *aSubMesh = (*itsm).second;
800 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
801 _subMeshesUsingHypothesisList.push_back(aSubMesh);
803 return _subMeshesUsingHypothesisList;
806 //=======================================================================
807 //function : NotifySubMeshesHypothesisModification
808 //purpose : Say all submeshes using theChangedHyp that it has been modified
809 //=======================================================================
811 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp)
813 Unexpect aCatch(SalomeException);
815 const SMESH_Hypothesis* hyp = static_cast<const SMESH_Hypothesis*>(theChangedHyp);
817 const SMESH_Algo *foundAlgo = 0;
818 SMESH_HypoFilter algoKind( SMESH_HypoFilter::IsAlgo() );
819 SMESH_HypoFilter compatibleHypoKind;
820 list <const SMESHDS_Hypothesis * > usedHyps;
823 map < int, SMESH_subMesh * >::iterator itsm;
824 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
826 SMESH_subMesh *aSubMesh = (*itsm).second;
827 if ( aSubMesh->IsApplicableHypotesis( hyp ))
829 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
831 if ( !foundAlgo ) // init filter for algo search
832 algoKind.And( algoKind.IsApplicableTo( aSubShape ));
834 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
835 ( GetHypothesis( aSubShape, algoKind, true ));
839 bool sameAlgo = ( algo == foundAlgo );
840 if ( !sameAlgo && foundAlgo )
841 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
843 if ( !sameAlgo ) { // init filter for used hypos search
844 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
845 continue; // algo does not use any hypothesis
849 // check if hyp is used by algo
851 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
852 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
854 aSubMesh->ComputeStateEngine(SMESH_subMesh::MODIF_HYP);
856 if ( algo->GetDim() == 1 && IsPropagationHypothesis( aSubShape ))
857 CleanMeshOnPropagationChain( aSubShape );
864 //=============================================================================
866 * To store mesh contents on disk in different formats.
868 //=============================================================================
870 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
872 set<string> aGroupNames;
873 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
874 SMESH_Group* aGroup = it->second;
875 string aGroupName = aGroup->GetName();
876 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
877 if (!aGroupNames.insert(aGroupName).second)
884 void SMESH_Mesh::ExportMED(const char *file,
885 const char* theMeshName,
888 throw(SALOME_Exception)
890 Unexpect aCatch(SalomeException);
892 DriverMED_W_SMESHDS_Mesh myWriter;
893 myWriter.SetFile ( file, MED::EVersion(theVersion) );
894 myWriter.SetMesh ( _myMeshDS );
896 myWriter.SetMeshId ( _idDoc );
898 myWriter.SetMeshId ( -1 );
899 myWriter.SetMeshName( theMeshName );
902 if ( theAutoGroups ) {
903 myWriter.AddGroupOfNodes();
904 myWriter.AddGroupOfEdges();
905 myWriter.AddGroupOfFaces();
906 myWriter.AddGroupOfVolumes();
909 // Pass groups to writer. Provide unique group names.
910 set<string> aGroupNames;
912 int maxNbIter = 10000; // to guarantee cycle finish
913 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
914 SMESH_Group* aGroup = it->second;
915 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
917 string aGroupName0 = aGroup->GetName();
918 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
919 string aGroupName = aGroupName0;
920 for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) {
921 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
922 aGroupName = aString;
923 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
925 aGroupDS->SetStoreName( aGroupName.c_str() );
926 myWriter.AddGroup( aGroupDS );
934 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
936 Unexpect aCatch(SalomeException);
937 DriverDAT_W_SMDS_Mesh myWriter;
938 myWriter.SetFile(string(file));
939 myWriter.SetMesh(_myMeshDS);
940 myWriter.SetMeshId(_idDoc);
944 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
946 Unexpect aCatch(SalomeException);
947 DriverUNV_W_SMDS_Mesh myWriter;
948 myWriter.SetFile(string(file));
949 myWriter.SetMesh(_myMeshDS);
950 myWriter.SetMeshId(_idDoc);
954 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
956 Unexpect aCatch(SalomeException);
957 DriverSTL_W_SMDS_Mesh myWriter;
958 myWriter.SetFile(string(file));
959 myWriter.SetIsAscii( isascii );
960 myWriter.SetMesh(_myMeshDS);
961 myWriter.SetMeshId(_idDoc);
965 //=============================================================================
969 //=============================================================================
970 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
972 Unexpect aCatch(SalomeException);
973 return _myMeshDS->NbNodes();
976 //=============================================================================
980 //=============================================================================
981 int SMESH_Mesh::NbEdges() throw(SALOME_Exception)
983 Unexpect aCatch(SalomeException);
984 return _myMeshDS->NbEdges();
987 //=============================================================================
991 //=============================================================================
992 int SMESH_Mesh::NbFaces() throw(SALOME_Exception)
994 Unexpect aCatch(SalomeException);
995 return _myMeshDS->NbFaces();
998 ///////////////////////////////////////////////////////////////////////////////
999 /// Return the number of 3 nodes faces in the mesh. This method run in O(n)
1000 ///////////////////////////////////////////////////////////////////////////////
1001 int SMESH_Mesh::NbTriangles() throw(SALOME_Exception)
1003 Unexpect aCatch(SalomeException);
1006 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1007 //while(itFaces->more()) if(itFaces->next()->NbNodes()==3) Nb++;
1008 const SMDS_MeshFace * curFace;
1009 while (itFaces->more()) {
1010 curFace = itFaces->next();
1011 if ( !curFace->IsPoly() &&
1012 ( curFace->NbNodes()==3 || curFace->NbNodes()==6 ) ) Nb++;
1017 ///////////////////////////////////////////////////////////////////////////////
1018 /// Return the number of 4 nodes faces in the mesh. This method run in O(n)
1019 ///////////////////////////////////////////////////////////////////////////////
1020 int SMESH_Mesh::NbQuadrangles() throw(SALOME_Exception)
1022 Unexpect aCatch(SalomeException);
1025 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1026 //while(itFaces->more()) if(itFaces->next()->NbNodes()==4) Nb++;
1027 const SMDS_MeshFace * curFace;
1028 while (itFaces->more()) {
1029 curFace = itFaces->next();
1030 if ( !curFace->IsPoly() &&
1031 ( curFace->NbNodes() == 4 || curFace->NbNodes()==8 ) ) Nb++;
1036 ///////////////////////////////////////////////////////////////////////////////
1037 /// Return the number of polygonal faces in the mesh. This method run in O(n)
1038 ///////////////////////////////////////////////////////////////////////////////
1039 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1041 Unexpect aCatch(SalomeException);
1043 SMDS_FaceIteratorPtr itFaces = _myMeshDS->facesIterator();
1044 while (itFaces->more())
1045 if (itFaces->next()->IsPoly()) Nb++;
1049 //=============================================================================
1053 //=============================================================================
1054 int SMESH_Mesh::NbVolumes() throw(SALOME_Exception)
1056 Unexpect aCatch(SalomeException);
1057 return _myMeshDS->NbVolumes();
1060 int SMESH_Mesh::NbTetras() throw(SALOME_Exception)
1062 Unexpect aCatch(SalomeException);
1064 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1065 //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==4) Nb++;
1066 const SMDS_MeshVolume * curVolume;
1067 while (itVolumes->more()) {
1068 curVolume = itVolumes->next();
1069 if ( !curVolume->IsPoly() &&
1070 ( curVolume->NbNodes() == 4 || curVolume->NbNodes()==10 ) ) Nb++;
1075 int SMESH_Mesh::NbHexas() throw(SALOME_Exception)
1077 Unexpect aCatch(SalomeException);
1079 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1080 //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==8) Nb++;
1081 const SMDS_MeshVolume * curVolume;
1082 while (itVolumes->more()) {
1083 curVolume = itVolumes->next();
1084 if ( !curVolume->IsPoly() &&
1085 ( curVolume->NbNodes() == 8 || curVolume->NbNodes()==20 ) ) Nb++;
1090 int SMESH_Mesh::NbPyramids() throw(SALOME_Exception)
1092 Unexpect aCatch(SalomeException);
1094 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1095 //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==5) Nb++;
1096 const SMDS_MeshVolume * curVolume;
1097 while (itVolumes->more()) {
1098 curVolume = itVolumes->next();
1099 if ( !curVolume->IsPoly() &&
1100 ( curVolume->NbNodes() == 5 || curVolume->NbNodes()==13 ) ) Nb++;
1105 int SMESH_Mesh::NbPrisms() throw(SALOME_Exception)
1107 Unexpect aCatch(SalomeException);
1109 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1110 //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==6) Nb++;
1111 const SMDS_MeshVolume * curVolume;
1112 while (itVolumes->more()) {
1113 curVolume = itVolumes->next();
1114 if ( !curVolume->IsPoly() &&
1115 ( curVolume->NbNodes() == 6 || curVolume->NbNodes()==15 ) ) Nb++;
1120 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1122 Unexpect aCatch(SalomeException);
1124 SMDS_VolumeIteratorPtr itVolumes = _myMeshDS->volumesIterator();
1125 while (itVolumes->more())
1126 if (itVolumes->next()->IsPoly()) Nb++;
1130 //=============================================================================
1134 //=============================================================================
1135 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1137 Unexpect aCatch(SalomeException);
1138 return _myMeshDS->NbSubMesh();
1141 //=======================================================================
1142 //function : IsNotConformAllowed
1143 //purpose : check if a hypothesis alowing notconform mesh is present
1144 //=======================================================================
1146 bool SMESH_Mesh::IsNotConformAllowed() const
1148 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1150 SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1151 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1154 //=======================================================================
1155 //function : IsMainShape
1157 //=======================================================================
1159 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1161 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1164 //=============================================================================
1168 //=============================================================================
1170 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1171 const char* theName,
1173 const TopoDS_Shape& theShape)
1175 if (_mapGroup.find(_groupId) != _mapGroup.end())
1178 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1179 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1180 _mapGroup[_groupId++] = aGroup;
1184 //=============================================================================
1188 //=============================================================================
1190 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1192 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1194 return _mapGroup[theGroupID];
1198 //=============================================================================
1202 //=============================================================================
1204 list<int> SMESH_Mesh::GetGroupIds()
1207 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1208 anIds.push_back( it->first );
1214 //=============================================================================
1218 //=============================================================================
1220 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1222 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1224 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1225 delete _mapGroup[theGroupID];
1226 _mapGroup.erase (theGroupID);
1229 //=============================================================================
1231 * IsLocal1DHypothesis
1232 * Returns a local 1D hypothesis used for theEdge
1234 //=============================================================================
1235 const SMESH_Hypothesis* SMESH_Mesh::IsLocal1DHypothesis (const TopoDS_Shape& theEdge)
1237 SMESH_HypoFilter hypo ( SMESH_HypoFilter::HasDim( 1 ));
1238 hypo.AndNot( hypo.IsAlgo() ).AndNot( hypo.IsAssignedTo( GetMeshDS()->ShapeToMesh() ));
1240 return GetHypothesis( theEdge, hypo, true );
1243 //=============================================================================
1245 * IsPropagationHypothesis
1247 //=============================================================================
1248 bool SMESH_Mesh::IsPropagationHypothesis (const TopoDS_Shape& theEdge)
1250 return _mapPropagationChains.Contains(theEdge);
1253 //=============================================================================
1255 * IsPropagatedHypothesis
1257 //=============================================================================
1258 bool SMESH_Mesh::IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
1259 TopoDS_Shape& theMainEdge)
1261 int nbChains = _mapPropagationChains.Extent();
1262 for (int i = 1; i <= nbChains; i++) {
1263 //const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
1264 const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
1265 if (aChain.Contains(theEdge)) {
1266 theMainEdge = _mapPropagationChains.FindKey(i);
1273 //=============================================================================
1277 //=============================================================================
1279 bool SMESH_Mesh::IsReversedInChain (const TopoDS_Shape& theEdge,
1280 const TopoDS_Shape& theMainEdge)
1282 if ( !theMainEdge.IsNull() && !theEdge.IsNull() &&
1283 _mapPropagationChains.Contains( theMainEdge ))
1285 const SMESH_IndexedMapOfShape& aChain =
1286 _mapPropagationChains.FindFromKey( theMainEdge );
1287 int index = aChain.FindIndex( theEdge );
1289 return aChain(index).Orientation() == TopAbs_REVERSED;
1294 //=============================================================================
1296 * CleanMeshOnPropagationChain
1298 //=============================================================================
1299 void SMESH_Mesh::CleanMeshOnPropagationChain (const TopoDS_Shape& theMainEdge)
1301 const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromKey(theMainEdge);
1302 int i, nbEdges = aChain.Extent();
1303 for (i = 1; i <= nbEdges; i++) {
1304 TopoDS_Shape anEdge = aChain.FindKey(i);
1305 SMESH_subMesh *subMesh = GetSubMesh(anEdge);
1306 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
1307 if (subMeshDS && subMeshDS->NbElements() > 0) {
1308 subMesh->ComputeStateEngine(SMESH_subMesh::CLEAN);
1313 //=============================================================================
1315 * RebuildPropagationChains
1316 * Rebuild all existing propagation chains.
1317 * Have to be used, if 1D hypothesis have been assigned/removed to/from any edge
1319 //=============================================================================
1320 bool SMESH_Mesh::RebuildPropagationChains()
1324 // Clean all chains, because they can be not up-to-date
1325 int i, nbChains = _mapPropagationChains.Extent();
1326 for (i = 1; i <= nbChains; i++) {
1327 TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1328 CleanMeshOnPropagationChain(aMainEdge);
1329 _mapPropagationChains.ChangeFromIndex(i).Clear();
1333 for (i = 1; i <= nbChains; i++) {
1334 TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1335 if (!BuildPropagationChain(aMainEdge))
1337 CleanMeshOnPropagationChain(aMainEdge);
1343 //=============================================================================
1345 * RemovePropagationChain
1346 * Have to be used, if Propagation hypothesis is removed from <theMainEdge>
1348 //=============================================================================
1349 bool SMESH_Mesh::RemovePropagationChain (const TopoDS_Shape& theMainEdge)
1351 if (!_mapPropagationChains.Contains(theMainEdge))
1354 // Clean mesh elements and nodes, built on the chain
1355 CleanMeshOnPropagationChain(theMainEdge);
1358 _mapPropagationChains.ChangeFromKey(theMainEdge).Clear();
1360 // Remove the chain from the map
1361 int i = _mapPropagationChains.FindIndex(theMainEdge);
1362 if ( i == _mapPropagationChains.Extent() )
1363 _mapPropagationChains.RemoveLast();
1365 TopoDS_Vertex anEmptyShape;
1367 BB.MakeVertex(anEmptyShape, gp_Pnt(0,0,0), 0.1);
1368 SMESH_IndexedMapOfShape anEmptyMap;
1369 _mapPropagationChains.Substitute(i, anEmptyShape, anEmptyMap);
1375 //=============================================================================
1377 * BuildPropagationChain
1379 //=============================================================================
1380 bool SMESH_Mesh::BuildPropagationChain (const TopoDS_Shape& theMainEdge)
1382 if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
1384 // Add new chain, if there is no
1385 if (!_mapPropagationChains.Contains(theMainEdge)) {
1386 SMESH_IndexedMapOfShape aNewChain;
1387 _mapPropagationChains.Add(theMainEdge, aNewChain);
1390 // Check presence of 1D hypothesis to be propagated
1391 const SMESH_Hypothesis* aMainHyp = IsLocal1DHypothesis(theMainEdge);
1393 MESSAGE("Warning: There is no 1D hypothesis to propagate. Please, assign.");
1397 // Edges, on which the 1D hypothesis will be propagated from <theMainEdge>
1398 SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.ChangeFromKey(theMainEdge);
1399 if (aChain.Extent() > 0) {
1400 CleanMeshOnPropagationChain(theMainEdge);
1404 // At first put <theMainEdge> in the chain
1405 aChain.Add(theMainEdge);
1407 // List of edges, added to chain on the previous cycle pass
1408 TopTools_ListOfShape listPrevEdges;
1409 listPrevEdges.Append(theMainEdge.Oriented( TopAbs_FORWARD ));
1411 // 5____4____3____4____5____6
1414 // 4____3____2____3____4____5
1415 // | | | | | | Number in the each knot of
1416 // | | | | | | grid indicates cycle pass,
1417 // 3____2____1____2____3____4 on which corresponding edge
1418 // | | | | | | (perpendicular to the plane
1419 // | | | | | | of view) will be found.
1420 // 2____1____0____1____2____3
1423 // 3____2____1____2____3____4
1425 // Collect all edges pass by pass
1426 while (listPrevEdges.Extent() > 0) {
1427 // List of edges, added to chain on this cycle pass
1428 TopTools_ListOfShape listCurEdges;
1430 // Find the next portion of edges
1431 TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
1432 for (; itE.More(); itE.Next()) {
1433 TopoDS_Shape anE = itE.Value();
1435 // Iterate on faces, having edge <anE>
1436 TopTools_ListIteratorOfListOfShape itA (GetAncestors(anE));
1437 for (; itA.More(); itA.Next()) {
1438 TopoDS_Shape aW = itA.Value();
1440 // There are objects of different type among the ancestors of edge
1441 if (aW.ShapeType() == TopAbs_WIRE) {
1442 TopoDS_Shape anOppE;
1444 BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
1445 Standard_Integer nb = 1, found = 0;
1446 TopTools_Array1OfShape anEdges (1,4);
1447 for (; aWE.More(); aWE.Next(), nb++) {
1452 anEdges(nb) = aWE.Current();
1453 if (!_mapAncestors.Contains(anEdges(nb))) {
1454 MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!");
1457 if (anEdges(nb).IsSame(anE)) found = nb;
1460 if (nb == 5 && found > 0) {
1461 // Quadrangle face found, get an opposite edge
1462 Standard_Integer opp = found + 2;
1463 if (opp > 4) opp -= 4;
1464 anOppE = anEdges(opp);
1466 // add anOppE to aChain if ...
1467 if (!aChain.Contains(anOppE)) { // ... anOppE is not in aChain
1468 if (!IsLocal1DHypothesis(anOppE)) { // ... no other 1d hyp on anOppE
1469 TopoDS_Shape aMainEdgeForOppEdge; // ... no other hyp is propagated to anOppE
1470 if (!IsPropagatedHypothesis(anOppE, aMainEdgeForOppEdge))
1472 // Add found edge to the chain oriented so that to
1473 // have it co-directed with a forward MainEdge
1474 TopAbs_Orientation ori = anE.Orientation();
1475 if ( anEdges(opp).Orientation() == anEdges(found).Orientation() )
1476 ori = TopAbs::Reverse( ori );
1477 anOppE.Orientation( ori );
1479 listCurEdges.Append(anOppE);
1483 MESSAGE("Error: Collision between propagated hypotheses");
1484 CleanMeshOnPropagationChain(theMainEdge);
1486 return ( aMainHyp == IsLocal1DHypothesis(aMainEdgeForOppEdge) );
1490 } // if (nb == 5 && found > 0)
1491 } // if (aF.ShapeType() == TopAbs_WIRE)
1492 } // for (; itF.More(); itF.Next())
1493 } // for (; itE.More(); itE.Next())
1495 listPrevEdges = listCurEdges;
1496 } // while (listPrevEdges.Extent() > 0)
1498 CleanMeshOnPropagationChain(theMainEdge);
1502 //=======================================================================
1503 //function : GetAncestors
1504 //purpose : return list of ancestors of theSubShape in the order
1505 // that lower dimention shapes come first.
1506 //=======================================================================
1508 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1510 if ( _mapAncestors.Contains( theS ) )
1511 return _mapAncestors.FindFromKey( theS );
1513 static TopTools_ListOfShape emptyList;
1517 //=======================================================================
1519 //purpose : dumps contents of mesh to stream [ debug purposes ]
1520 //=======================================================================
1521 ostream& SMESH_Mesh::Dump(ostream& save)
1523 save << "========================== Dump contents of mesh ==========================" << endl;
1524 save << "1) Total number of nodes: " << NbNodes() << endl;
1525 save << "2) Total number of edges: " << NbEdges() << endl;
1526 save << "3) Total number of faces: " << NbFaces() << endl;
1527 if ( NbFaces() > 0 ) {
1528 int nb3 = NbTriangles();
1529 int nb4 = NbQuadrangles();
1530 save << "3.1.) Number of triangles: " << nb3 << endl;
1531 save << "3.2.) Number of quadrangles: " << nb4 << endl;
1532 if ( nb3 + nb4 != NbFaces() ) {
1533 map<int,int> myFaceMap;
1534 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1535 while( itFaces->more( ) ) {
1536 int nbNodes = itFaces->next()->NbNodes();
1537 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1538 myFaceMap[ nbNodes ] = 0;
1539 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1541 save << "3.3.) Faces in detail: " << endl;
1542 map <int,int>::iterator itF;
1543 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1544 save << "--> nb nodes: " << itF->first << " - nb elemens: " << itF->second << endl;
1547 save << "4) Total number of volumes: " << NbVolumes() << endl;
1548 if ( NbVolumes() > 0 ) {
1549 int nb8 = NbHexas();
1550 int nb4 = NbTetras();
1551 int nb5 = NbPyramids();
1552 int nb6 = NbPrisms();
1553 save << "4.1.) Number of hexahedrons: " << nb8 << endl;
1554 save << "4.2.) Number of tetrahedrons: " << nb4 << endl;
1555 save << "4.3.) Number of prisms: " << nb6 << endl;
1556 save << "4.4.) Number of pyramides: " << nb5 << endl;
1557 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes() ) {
1558 map<int,int> myVolumesMap;
1559 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1560 while( itVolumes->more( ) ) {
1561 int nbNodes = itVolumes->next()->NbNodes();
1562 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1563 myVolumesMap[ nbNodes ] = 0;
1564 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1566 save << "4.5.) Volumes in detail: " << endl;
1567 map <int,int>::iterator itV;
1568 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1569 save << "--> nb nodes: " << itV->first << " - nb elemens: " << itV->second << endl;
1572 save << "===========================================================================" << endl;
1576 //=======================================================================
1577 //function : GetElementType
1578 //purpose : Returns type of mesh element with certain id
1579 //=======================================================================
1580 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1582 return _myMeshDS->GetElementType( id, iselem );