1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Mesh.cxx
25 // Author : Paul RASCLE, EDF
29 #include "SMESH_Mesh.hxx"
30 #include "SMESH_subMesh.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Hypothesis.hxx"
33 #include "SMESH_Group.hxx"
34 #include "SMESH_HypoFilter.hxx"
35 #include "SMESHDS_Group.hxx"
36 #include "SMESHDS_Script.hxx"
37 #include "SMESHDS_GroupOnGeom.hxx"
38 #include "SMDS_MeshVolume.hxx"
40 #include "utilities.h"
42 #include "DriverMED_W_SMESHDS_Mesh.h"
43 #include "DriverDAT_W_SMDS_Mesh.h"
44 #include "DriverUNV_W_SMDS_Mesh.h"
45 #include "DriverSTL_W_SMDS_Mesh.h"
47 #include "DriverMED_R_SMESHDS_Mesh.h"
48 #include "DriverUNV_R_SMDS_Mesh.h"
49 #include "DriverSTL_R_SMDS_Mesh.h"
51 #include <BRepTools_WireExplorer.hxx>
52 #include <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;
362 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
363 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
365 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
368 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
369 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
371 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
373 SMESH_Hypothesis::Hypothesis_Status ret2 =
374 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
378 // check concurent hypotheses on ansestors
379 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
381 const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn();
382 map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin();
383 for ( ; smIt != smMap.end(); smIt++ ) {
384 if ( smIt->second->IsApplicableHypotesis( anHyp )) {
385 ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() );
395 if(MYDEBUG) subMesh->DumpAlgoState(true);
400 //=============================================================================
404 //=============================================================================
406 SMESH_Hypothesis::Hypothesis_Status
407 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
408 int anHypId)throw(SALOME_Exception)
410 Unexpect aCatch(SalomeException);
411 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
413 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
414 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
415 if ( subMeshDS && subMeshDS->IsComplexSubmesh() )
417 // return the worst but not fatal state of all group memebers
418 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
419 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
420 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
421 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
423 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
424 continue; // not sub-shape
425 ret = RemoveHypothesis( itS.Value(), anHypId );
426 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
427 aWorstNotFatal = ret;
428 if ( ret < aBestRet )
431 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
433 return aWorstNotFatal;
436 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
437 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
438 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
440 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
441 int hypType = anHyp->GetType();
442 if(MYDEBUG) SCRUTE(hypType);
446 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
447 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
449 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
451 // there may appear concurrent hyps that were covered by the removed hyp
452 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
453 subMesh->IsApplicableHypotesis( anHyp ) &&
454 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
455 ret = SMESH_Hypothesis::HYP_CONCURENT;
458 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
459 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
461 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
463 SMESH_Hypothesis::Hypothesis_Status ret2 =
464 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
465 if (ret2 > ret) // more severe
468 // check concurent hypotheses on ansestors
469 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
471 const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn();
472 map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin();
473 for ( ; smIt != smMap.end(); smIt++ ) {
474 if ( smIt->second->IsApplicableHypotesis( anHyp )) {
475 ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() );
485 if(MYDEBUG) subMesh->DumpAlgoState(true);
486 if(MYDEBUG) SCRUTE(ret);
490 //=============================================================================
494 //=============================================================================
496 SMESHDS_Mesh * SMESH_Mesh::GetMeshDS()
501 //=============================================================================
505 //=============================================================================
507 const list<const SMESHDS_Hypothesis*>&
508 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
509 throw(SALOME_Exception)
511 Unexpect aCatch(SalomeException);
512 return _myMeshDS->GetHypothesis(aSubShape);
515 //=======================================================================
516 //function : GetHypothesis
518 //=======================================================================
520 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
521 const SMESH_HypoFilter& aFilter,
522 const bool andAncestors) const
525 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
526 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
527 for ( ; hyp != hypList.end(); hyp++ ) {
528 const SMESH_Hypothesis * h = static_cast<const SMESH_Hypothesis*>( *hyp );
529 if ( aFilter.IsOk( h, aSubShape))
535 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
536 for (; it.More(); it.Next() )
538 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
539 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
540 for ( ; hyp != hypList.end(); hyp++ ) {
541 const SMESH_Hypothesis * h = static_cast<const SMESH_Hypothesis*>( *hyp );
542 if (aFilter.IsOk( h, it.Value() ))
550 //=======================================================================
551 //function : GetHypotheses
553 //=======================================================================
555 //================================================================================
557 * \brief Return hypothesis assigned to the shape
558 * \param aSubShape - the shape to check
559 * \param aFilter - the hypothesis filter
560 * \param aHypList - the list of the found hypotheses
561 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
562 * \retval int - number of unique hypos in aHypList
564 //================================================================================
566 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
567 const SMESH_HypoFilter& aFilter,
568 list <const SMESHDS_Hypothesis * >& aHypList,
569 const bool andAncestors) const
571 set<string> hypTypes; // to exclude same type hypos from the result list
575 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
576 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ )
577 if ( hypTypes.insert( (*hyp)->GetName() ).second )
580 // get hypos from aSubShape
582 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
583 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
584 if ( aFilter.IsOk (static_cast<const SMESH_Hypothesis*>( *hyp ), aSubShape) &&
585 hypTypes.insert( (*hyp)->GetName() ).second )
587 aHypList.push_back( *hyp );
592 // get hypos from ancestors of aSubShape
595 TopTools_MapOfShape map;
596 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
597 for (; it.More(); it.Next() )
599 if ( !map.Add( it.Value() ))
601 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
602 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
603 if (aFilter.IsOk( static_cast<const SMESH_Hypothesis*>( *hyp ), it.Value() ) &&
604 hypTypes.insert( (*hyp)->GetName() ).second ) {
605 aHypList.push_back( *hyp );
613 //=============================================================================
617 //=============================================================================
619 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
621 Unexpect aCatch(SalomeException);
622 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
623 return _myMeshDS->GetScript()->GetCommands();
626 //=============================================================================
630 //=============================================================================
631 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
633 Unexpect aCatch(SalomeException);
634 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
635 _myMeshDS->GetScript()->Clear();
638 //=============================================================================
642 //=============================================================================
644 int SMESH_Mesh::GetId()
646 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetId");
650 //=============================================================================
654 //=============================================================================
656 SMESH_Gen *SMESH_Mesh::GetGen()
661 //=============================================================================
663 * Get or Create the SMESH_subMesh object implementation
665 //=============================================================================
667 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
668 throw(SALOME_Exception)
670 Unexpect aCatch(SalomeException);
671 SMESH_subMesh *aSubMesh;
672 int index = _myMeshDS->ShapeToIndex(aSubShape);
674 // for submeshes on GEOM Group
675 if ( !index && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
676 TopoDS_Iterator it( aSubShape );
678 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
681 // return NULL; // neither sub-shape nor a group
683 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
684 if ( i_sm != _mapSubMesh.end())
686 aSubMesh = i_sm->second;
690 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
691 _mapSubMesh[index] = aSubMesh;
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 TopoDS_Shape & aSubShape)
704 throw(SALOME_Exception)
706 Unexpect aCatch(SalomeException);
707 SMESH_subMesh *aSubMesh = NULL;
709 int index = _myMeshDS->ShapeToIndex(aSubShape);
711 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
712 if ( i_sm != _mapSubMesh.end())
713 aSubMesh = i_sm->second;
718 //=============================================================================
720 * Get the SMESH_subMesh object implementation. Dont create it, return null
721 * if it does not exist.
723 //=============================================================================
725 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID)
726 throw(SALOME_Exception)
728 Unexpect aCatch(SalomeException);
730 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(aShapeID);
731 if (i_sm == _mapSubMesh.end())
736 //=======================================================================
737 //function : IsUsedHypothesis
738 //purpose : Return True if anHyp is used to mesh aSubShape
739 //=======================================================================
741 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
742 const SMESH_subMesh* aSubMesh)
744 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
746 // check if anHyp can be used to mesh aSubMesh
747 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
750 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
752 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
755 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
756 return ( anHyp == algo );
758 // algorithm parameter
761 // look trough hypotheses used by algo
762 SMESH_HypoFilter hypoKind;
763 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
764 list <const SMESHDS_Hypothesis * > usedHyps;
765 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
766 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
770 // look through all assigned hypotheses
771 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
772 return false; //GetHypothesis( aSubShape, filter, true );
775 //=============================================================================
779 //=============================================================================
781 const list < SMESH_subMesh * >&
782 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
783 throw(SALOME_Exception)
785 Unexpect aCatch(SalomeException);
786 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
787 map < int, SMESH_subMesh * >::iterator itsm;
788 _subMeshesUsingHypothesisList.clear();
789 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
791 SMESH_subMesh *aSubMesh = (*itsm).second;
792 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
793 _subMeshesUsingHypothesisList.push_back(aSubMesh);
795 return _subMeshesUsingHypothesisList;
798 //=======================================================================
799 //function : NotifySubMeshesHypothesisModification
800 //purpose : Say all submeshes using theChangedHyp that it has been modified
801 //=======================================================================
803 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp)
805 Unexpect aCatch(SalomeException);
807 const SMESH_Hypothesis* hyp = static_cast<const SMESH_Hypothesis*>(theChangedHyp);
809 const SMESH_Algo *foundAlgo = 0;
810 SMESH_HypoFilter algoKind( SMESH_HypoFilter::IsAlgo() );
811 SMESH_HypoFilter compatibleHypoKind;
812 list <const SMESHDS_Hypothesis * > usedHyps;
815 map < int, SMESH_subMesh * >::iterator itsm;
816 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
818 SMESH_subMesh *aSubMesh = (*itsm).second;
819 if ( aSubMesh->IsApplicableHypotesis( hyp ))
821 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
823 if ( !foundAlgo ) // init filter for algo search
824 algoKind.And( algoKind.IsApplicableTo( aSubShape ));
826 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
827 ( GetHypothesis( aSubShape, algoKind, true ));
831 bool sameAlgo = ( algo == foundAlgo );
832 if ( !sameAlgo && foundAlgo )
833 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
835 if ( !sameAlgo ) { // init filter for used hypos search
836 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
837 continue; // algo does not use any hypothesis
841 // check if hyp is used by algo
843 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
844 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
846 aSubMesh->ComputeStateEngine(SMESH_subMesh::MODIF_HYP);
848 if ( algo->GetDim() == 1 && IsPropagationHypothesis( aSubShape ))
849 CleanMeshOnPropagationChain( aSubShape );
856 //=============================================================================
858 * To store mesh contents on disk in different formats.
860 //=============================================================================
862 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
864 set<string> aGroupNames;
865 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
866 SMESH_Group* aGroup = it->second;
867 string aGroupName = aGroup->GetName();
868 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
869 if (!aGroupNames.insert(aGroupName).second)
876 void SMESH_Mesh::ExportMED(const char *file,
877 const char* theMeshName,
880 throw(SALOME_Exception)
882 Unexpect aCatch(SalomeException);
884 DriverMED_W_SMESHDS_Mesh myWriter;
885 myWriter.SetFile ( file, MED::EVersion(theVersion) );
886 myWriter.SetMesh ( _myMeshDS );
888 myWriter.SetMeshId ( _idDoc );
890 myWriter.SetMeshId ( -1 );
891 myWriter.SetMeshName( theMeshName );
894 if ( theAutoGroups ) {
895 myWriter.AddGroupOfNodes();
896 myWriter.AddGroupOfEdges();
897 myWriter.AddGroupOfFaces();
898 myWriter.AddGroupOfVolumes();
901 // Pass groups to writer. Provide unique group names.
902 set<string> aGroupNames;
904 int maxNbIter = 10000; // to guarantee cycle finish
905 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
906 SMESH_Group* aGroup = it->second;
907 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
909 string aGroupName0 = aGroup->GetName();
910 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
911 string aGroupName = aGroupName0;
912 for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) {
913 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
914 aGroupName = aString;
915 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
917 aGroupDS->SetStoreName( aGroupName.c_str() );
918 myWriter.AddGroup( aGroupDS );
926 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
928 Unexpect aCatch(SalomeException);
929 DriverDAT_W_SMDS_Mesh myWriter;
930 myWriter.SetFile(string(file));
931 myWriter.SetMesh(_myMeshDS);
932 myWriter.SetMeshId(_idDoc);
936 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
938 Unexpect aCatch(SalomeException);
939 DriverUNV_W_SMDS_Mesh myWriter;
940 myWriter.SetFile(string(file));
941 myWriter.SetMesh(_myMeshDS);
942 myWriter.SetMeshId(_idDoc);
943 // myWriter.SetGroups(_mapGroup);
945 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
946 SMESH_Group* aGroup = it->second;
947 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
949 string aGroupName = aGroup->GetName();
950 aGroupDS->SetStoreName( aGroupName.c_str() );
951 myWriter.AddGroup( aGroupDS );
957 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
959 Unexpect aCatch(SalomeException);
960 DriverSTL_W_SMDS_Mesh myWriter;
961 myWriter.SetFile(string(file));
962 myWriter.SetIsAscii( isascii );
963 myWriter.SetMesh(_myMeshDS);
964 myWriter.SetMeshId(_idDoc);
968 //=============================================================================
972 //=============================================================================
973 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
975 Unexpect aCatch(SalomeException);
976 return _myMeshDS->NbNodes();
979 //=============================================================================
983 //=============================================================================
984 int SMESH_Mesh::NbEdges(ElementOrder order) throw(SALOME_Exception)
986 Unexpect aCatch(SalomeException);
987 if (order == ORDER_ANY)
988 return _myMeshDS->NbEdges();
991 SMDS_EdgeIteratorPtr it = _myMeshDS->edgesIterator();
993 const SMDS_MeshEdge* cur = it->next();
994 if ( order == ORDER_LINEAR && !cur->IsQuadratic() ||
995 order == ORDER_QUADRATIC && cur->IsQuadratic() )
1001 //=============================================================================
1005 //=============================================================================
1006 int SMESH_Mesh::NbFaces(ElementOrder order) throw(SALOME_Exception)
1008 Unexpect aCatch(SalomeException);
1009 if (order == ORDER_ANY)
1010 return _myMeshDS->NbFaces();
1013 SMDS_FaceIteratorPtr it = _myMeshDS->facesIterator();
1014 while (it->more()) {
1015 const SMDS_MeshFace* cur = it->next();
1016 if ( order == ORDER_LINEAR && !cur->IsQuadratic() ||
1017 order == ORDER_QUADRATIC && cur->IsQuadratic() )
1023 ///////////////////////////////////////////////////////////////////////////////
1024 /// Return the number of 3 nodes faces in the mesh. This method run in O(n)
1025 ///////////////////////////////////////////////////////////////////////////////
1026 int SMESH_Mesh::NbTriangles(ElementOrder order) throw(SALOME_Exception)
1028 Unexpect aCatch(SalomeException);
1031 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1032 while (itFaces->more()) {
1033 const SMDS_MeshFace* curFace = itFaces->next();
1034 int nbnod = curFace->NbNodes();
1035 if ( !curFace->IsPoly() &&
1036 ( order == ORDER_ANY && (nbnod==3 || nbnod==6) ||
1037 order == ORDER_LINEAR && nbnod==3 ||
1038 order == ORDER_QUADRATIC && nbnod==6 ) )
1044 ///////////////////////////////////////////////////////////////////////////////
1045 /// Return the number of 4 nodes faces in the mesh. This method run in O(n)
1046 ///////////////////////////////////////////////////////////////////////////////
1047 int SMESH_Mesh::NbQuadrangles(ElementOrder order) throw(SALOME_Exception)
1049 Unexpect aCatch(SalomeException);
1052 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1053 while (itFaces->more()) {
1054 const SMDS_MeshFace* curFace = itFaces->next();
1055 int nbnod = curFace->NbNodes();
1056 if ( !curFace->IsPoly() &&
1057 ( order == ORDER_ANY && (nbnod==4 || nbnod==8) ||
1058 order == ORDER_LINEAR && nbnod==4 ||
1059 order == ORDER_QUADRATIC && nbnod==8 ) )
1065 ///////////////////////////////////////////////////////////////////////////////
1066 /// Return the number of polygonal faces in the mesh. This method run in O(n)
1067 ///////////////////////////////////////////////////////////////////////////////
1068 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1070 Unexpect aCatch(SalomeException);
1072 SMDS_FaceIteratorPtr itFaces = _myMeshDS->facesIterator();
1073 while (itFaces->more())
1074 if (itFaces->next()->IsPoly()) Nb++;
1078 //=============================================================================
1082 //=============================================================================
1083 int SMESH_Mesh::NbVolumes(ElementOrder order) throw(SALOME_Exception)
1085 Unexpect aCatch(SalomeException);
1086 if (order == ORDER_ANY)
1087 return _myMeshDS->NbVolumes();
1090 SMDS_VolumeIteratorPtr it = _myMeshDS->volumesIterator();
1091 while (it->more()) {
1092 const SMDS_MeshVolume* cur = it->next();
1093 if ( order == ORDER_LINEAR && !cur->IsQuadratic() ||
1094 order == ORDER_QUADRATIC && cur->IsQuadratic() )
1100 int SMESH_Mesh::NbTetras(ElementOrder order) throw(SALOME_Exception)
1102 Unexpect aCatch(SalomeException);
1104 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1105 while (itVolumes->more()) {
1106 const SMDS_MeshVolume* curVolume = itVolumes->next();
1107 int nbnod = curVolume->NbNodes();
1108 if ( !curVolume->IsPoly() &&
1109 ( order == ORDER_ANY && (nbnod==4 || nbnod==10) ||
1110 order == ORDER_LINEAR && nbnod==4 ||
1111 order == ORDER_QUADRATIC && nbnod==10 ) )
1117 int SMESH_Mesh::NbHexas(ElementOrder order) throw(SALOME_Exception)
1119 Unexpect aCatch(SalomeException);
1121 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1122 while (itVolumes->more()) {
1123 const SMDS_MeshVolume* curVolume = itVolumes->next();
1124 int nbnod = curVolume->NbNodes();
1125 if ( !curVolume->IsPoly() &&
1126 ( order == ORDER_ANY && (nbnod==8 || nbnod==20) ||
1127 order == ORDER_LINEAR && nbnod==8 ||
1128 order == ORDER_QUADRATIC && nbnod==20 ) )
1134 int SMESH_Mesh::NbPyramids(ElementOrder order) throw(SALOME_Exception)
1136 Unexpect aCatch(SalomeException);
1138 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1139 while (itVolumes->more()) {
1140 const SMDS_MeshVolume* curVolume = itVolumes->next();
1141 int nbnod = curVolume->NbNodes();
1142 if ( !curVolume->IsPoly() &&
1143 ( order == ORDER_ANY && (nbnod==5 || nbnod==13) ||
1144 order == ORDER_LINEAR && nbnod==5 ||
1145 order == ORDER_QUADRATIC && nbnod==13 ) )
1151 int SMESH_Mesh::NbPrisms(ElementOrder order) throw(SALOME_Exception)
1153 Unexpect aCatch(SalomeException);
1155 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1156 while (itVolumes->more()) {
1157 const SMDS_MeshVolume* curVolume = itVolumes->next();
1158 int nbnod = curVolume->NbNodes();
1159 if ( !curVolume->IsPoly() &&
1160 ( order == ORDER_ANY && (nbnod==6 || nbnod==15) ||
1161 order == ORDER_LINEAR && nbnod==6 ||
1162 order == ORDER_QUADRATIC && nbnod==15 ) )
1168 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1170 Unexpect aCatch(SalomeException);
1172 SMDS_VolumeIteratorPtr itVolumes = _myMeshDS->volumesIterator();
1173 while (itVolumes->more())
1174 if (itVolumes->next()->IsPoly()) Nb++;
1178 //=============================================================================
1182 //=============================================================================
1183 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1185 Unexpect aCatch(SalomeException);
1186 return _myMeshDS->NbSubMesh();
1189 //=======================================================================
1190 //function : IsNotConformAllowed
1191 //purpose : check if a hypothesis alowing notconform mesh is present
1192 //=======================================================================
1194 bool SMESH_Mesh::IsNotConformAllowed() const
1196 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1198 SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1199 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1202 //=======================================================================
1203 //function : IsMainShape
1205 //=======================================================================
1207 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1209 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1212 //=============================================================================
1216 //=============================================================================
1218 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1219 const char* theName,
1221 const TopoDS_Shape& theShape)
1223 if (_mapGroup.find(_groupId) != _mapGroup.end())
1226 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1227 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1228 _mapGroup[_groupId++] = aGroup;
1232 //=============================================================================
1236 //=============================================================================
1238 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1240 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1242 return _mapGroup[theGroupID];
1246 //=============================================================================
1250 //=============================================================================
1252 list<int> SMESH_Mesh::GetGroupIds()
1255 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1256 anIds.push_back( it->first );
1262 //=============================================================================
1266 //=============================================================================
1268 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1270 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1272 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1273 delete _mapGroup[theGroupID];
1274 _mapGroup.erase (theGroupID);
1277 //=============================================================================
1279 * IsLocal1DHypothesis
1280 * Returns a local 1D hypothesis used for theEdge
1282 //=============================================================================
1283 const SMESH_Hypothesis* SMESH_Mesh::IsLocal1DHypothesis (const TopoDS_Shape& theEdge)
1285 SMESH_HypoFilter hypo ( SMESH_HypoFilter::HasDim( 1 ));
1286 hypo.AndNot( hypo.IsAlgo() ).AndNot( hypo.IsAssignedTo( GetMeshDS()->ShapeToMesh() ));
1288 return GetHypothesis( theEdge, hypo, true );
1291 //=============================================================================
1293 * IsPropagationHypothesis
1295 //=============================================================================
1296 bool SMESH_Mesh::IsPropagationHypothesis (const TopoDS_Shape& theEdge)
1298 return _mapPropagationChains.Contains(theEdge);
1301 //=============================================================================
1303 * IsPropagatedHypothesis
1305 //=============================================================================
1306 bool SMESH_Mesh::IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
1307 TopoDS_Shape& theMainEdge)
1309 int nbChains = _mapPropagationChains.Extent();
1310 for (int i = 1; i <= nbChains; i++) {
1311 //const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
1312 const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
1313 if (aChain.Contains(theEdge)) {
1314 theMainEdge = _mapPropagationChains.FindKey(i);
1321 //=============================================================================
1325 //=============================================================================
1327 bool SMESH_Mesh::IsReversedInChain (const TopoDS_Shape& theEdge,
1328 const TopoDS_Shape& theMainEdge)
1330 if ( !theMainEdge.IsNull() && !theEdge.IsNull() &&
1331 _mapPropagationChains.Contains( theMainEdge ))
1333 const SMESH_IndexedMapOfShape& aChain =
1334 _mapPropagationChains.FindFromKey( theMainEdge );
1335 int index = aChain.FindIndex( theEdge );
1337 return aChain(index).Orientation() == TopAbs_REVERSED;
1342 //=============================================================================
1344 * CleanMeshOnPropagationChain
1346 //=============================================================================
1347 void SMESH_Mesh::CleanMeshOnPropagationChain (const TopoDS_Shape& theMainEdge)
1349 const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromKey(theMainEdge);
1350 int i, nbEdges = aChain.Extent();
1351 for (i = 1; i <= nbEdges; i++) {
1352 TopoDS_Shape anEdge = aChain.FindKey(i);
1353 SMESH_subMesh *subMesh = GetSubMesh(anEdge);
1354 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
1355 if (subMeshDS && subMeshDS->NbElements() > 0) {
1356 subMesh->ComputeStateEngine(SMESH_subMesh::CLEAN);
1361 //=============================================================================
1363 * RebuildPropagationChains
1364 * Rebuild all existing propagation chains.
1365 * Have to be used, if 1D hypothesis have been assigned/removed to/from any edge
1367 //=============================================================================
1368 bool SMESH_Mesh::RebuildPropagationChains()
1372 // Clean all chains, because they can be not up-to-date
1373 int i, nbChains = _mapPropagationChains.Extent();
1374 for (i = 1; i <= nbChains; i++) {
1375 TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1376 CleanMeshOnPropagationChain(aMainEdge);
1377 _mapPropagationChains.ChangeFromIndex(i).Clear();
1381 for (i = 1; i <= nbChains; i++) {
1382 TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1383 if (!BuildPropagationChain(aMainEdge))
1385 CleanMeshOnPropagationChain(aMainEdge);
1391 //=============================================================================
1393 * RemovePropagationChain
1394 * Have to be used, if Propagation hypothesis is removed from <theMainEdge>
1396 //=============================================================================
1397 bool SMESH_Mesh::RemovePropagationChain (const TopoDS_Shape& theMainEdge)
1399 if (!_mapPropagationChains.Contains(theMainEdge))
1402 // Clean mesh elements and nodes, built on the chain
1403 CleanMeshOnPropagationChain(theMainEdge);
1406 _mapPropagationChains.ChangeFromKey(theMainEdge).Clear();
1408 // Remove the chain from the map
1409 int i = _mapPropagationChains.FindIndex(theMainEdge);
1410 if ( i == _mapPropagationChains.Extent() )
1411 _mapPropagationChains.RemoveLast();
1413 TopoDS_Vertex anEmptyShape;
1415 BB.MakeVertex(anEmptyShape, gp_Pnt(0,0,0), 0.1);
1416 SMESH_IndexedMapOfShape anEmptyMap;
1417 _mapPropagationChains.Substitute(i, anEmptyShape, anEmptyMap);
1423 //=============================================================================
1425 * BuildPropagationChain
1427 //=============================================================================
1428 bool SMESH_Mesh::BuildPropagationChain (const TopoDS_Shape& theMainEdge)
1430 if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
1432 // Add new chain, if there is no
1433 if (!_mapPropagationChains.Contains(theMainEdge)) {
1434 SMESH_IndexedMapOfShape aNewChain;
1435 _mapPropagationChains.Add(theMainEdge, aNewChain);
1438 // Check presence of 1D hypothesis to be propagated
1439 const SMESH_Hypothesis* aMainHyp = IsLocal1DHypothesis(theMainEdge);
1441 MESSAGE("Warning: There is no 1D hypothesis to propagate. Please, assign.");
1445 // Edges, on which the 1D hypothesis will be propagated from <theMainEdge>
1446 SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.ChangeFromKey(theMainEdge);
1447 if (aChain.Extent() > 0) {
1448 CleanMeshOnPropagationChain(theMainEdge);
1452 // At first put <theMainEdge> in the chain
1453 aChain.Add(theMainEdge);
1455 // List of edges, added to chain on the previous cycle pass
1456 TopTools_ListOfShape listPrevEdges;
1457 listPrevEdges.Append(theMainEdge.Oriented( TopAbs_FORWARD ));
1459 // 5____4____3____4____5____6
1462 // 4____3____2____3____4____5
1463 // | | | | | | Number in the each knot of
1464 // | | | | | | grid indicates cycle pass,
1465 // 3____2____1____2____3____4 on which corresponding edge
1466 // | | | | | | (perpendicular to the plane
1467 // | | | | | | of view) will be found.
1468 // 2____1____0____1____2____3
1471 // 3____2____1____2____3____4
1473 // Collect all edges pass by pass
1474 while (listPrevEdges.Extent() > 0) {
1475 // List of edges, added to chain on this cycle pass
1476 TopTools_ListOfShape listCurEdges;
1478 // Find the next portion of edges
1479 TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
1480 for (; itE.More(); itE.Next()) {
1481 TopoDS_Shape anE = itE.Value();
1483 // Iterate on faces, having edge <anE>
1484 TopTools_ListIteratorOfListOfShape itA (GetAncestors(anE));
1485 for (; itA.More(); itA.Next()) {
1486 TopoDS_Shape aW = itA.Value();
1488 // There are objects of different type among the ancestors of edge
1489 if (aW.ShapeType() == TopAbs_WIRE) {
1490 TopoDS_Shape anOppE;
1492 BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
1493 Standard_Integer nb = 1, found = 0;
1494 TopTools_Array1OfShape anEdges (1,4);
1495 for (; aWE.More(); aWE.Next(), nb++) {
1500 anEdges(nb) = aWE.Current();
1501 if (!_mapAncestors.Contains(anEdges(nb))) {
1502 MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!");
1505 if (anEdges(nb).IsSame(anE)) found = nb;
1508 if (nb == 5 && found > 0) {
1509 // Quadrangle face found, get an opposite edge
1510 Standard_Integer opp = found + 2;
1511 if (opp > 4) opp -= 4;
1512 anOppE = anEdges(opp);
1514 // add anOppE to aChain if ...
1515 if (!aChain.Contains(anOppE)) { // ... anOppE is not in aChain
1516 if (!IsLocal1DHypothesis(anOppE)) { // ... no other 1d hyp on anOppE
1517 TopoDS_Shape aMainEdgeForOppEdge; // ... no other hyp is propagated to anOppE
1518 if (!IsPropagatedHypothesis(anOppE, aMainEdgeForOppEdge))
1520 // Add found edge to the chain oriented so that to
1521 // have it co-directed with a forward MainEdge
1522 TopAbs_Orientation ori = anE.Orientation();
1523 if ( anEdges(opp).Orientation() == anEdges(found).Orientation() )
1524 ori = TopAbs::Reverse( ori );
1525 anOppE.Orientation( ori );
1527 listCurEdges.Append(anOppE);
1531 MESSAGE("Error: Collision between propagated hypotheses");
1532 CleanMeshOnPropagationChain(theMainEdge);
1534 return ( aMainHyp == IsLocal1DHypothesis(aMainEdgeForOppEdge) );
1538 } // if (nb == 5 && found > 0)
1539 } // if (aF.ShapeType() == TopAbs_WIRE)
1540 } // for (; itF.More(); itF.Next())
1541 } // for (; itE.More(); itE.Next())
1543 listPrevEdges = listCurEdges;
1544 } // while (listPrevEdges.Extent() > 0)
1546 CleanMeshOnPropagationChain(theMainEdge);
1550 //=======================================================================
1551 //function : GetAncestors
1552 //purpose : return list of ancestors of theSubShape in the order
1553 // that lower dimention shapes come first.
1554 //=======================================================================
1556 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1558 if ( _mapAncestors.Contains( theS ) )
1559 return _mapAncestors.FindFromKey( theS );
1561 static TopTools_ListOfShape emptyList;
1565 //=======================================================================
1567 //purpose : dumps contents of mesh to stream [ debug purposes ]
1568 //=======================================================================
1569 ostream& SMESH_Mesh::Dump(ostream& save)
1572 save << "========================== Dump contents of mesh ==========================" << endl << endl;
1573 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
1574 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
1575 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
1576 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
1577 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
1578 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
1579 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
1581 string orderStr = isQuadratic ? "quadratic" : "linear";
1582 ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
1584 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
1585 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
1586 if ( NbFaces(order) > 0 ) {
1587 int nb3 = NbTriangles(order);
1588 int nb4 = NbQuadrangles(order);
1589 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
1590 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
1591 if ( nb3 + nb4 != NbFaces(order) ) {
1592 map<int,int> myFaceMap;
1593 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1594 while( itFaces->more( ) ) {
1595 int nbNodes = itFaces->next()->NbNodes();
1596 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1597 myFaceMap[ nbNodes ] = 0;
1598 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1600 save << clause << ".3) Faces in detail: " << endl;
1601 map <int,int>::iterator itF;
1602 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1603 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
1606 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
1607 if ( NbVolumes(order) > 0 ) {
1608 int nb8 = NbHexas(order);
1609 int nb4 = NbTetras(order);
1610 int nb5 = NbPyramids(order);
1611 int nb6 = NbPrisms(order);
1612 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
1613 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
1614 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
1615 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
1616 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
1617 map<int,int> myVolumesMap;
1618 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1619 while( itVolumes->more( ) ) {
1620 int nbNodes = itVolumes->next()->NbNodes();
1621 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1622 myVolumesMap[ nbNodes ] = 0;
1623 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1625 save << clause << ".5) Volumes in detail: " << endl;
1626 map <int,int>::iterator itV;
1627 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1628 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
1633 save << "===========================================================================" << endl;
1637 //=======================================================================
1638 //function : GetElementType
1639 //purpose : Returns type of mesh element with certain id
1640 //=======================================================================
1641 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1643 return _myMeshDS->GetElementType( id, iselem );