1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : StdMeshers_MaxElementVolume.cxx
24 // Moved here from SMESH_MaxElementVolume.cxx
25 // Author : Paul RASCLE, EDF
29 #include "StdMeshers_MaxElementVolume.hxx"
31 #include "SMDS_MeshElement.hxx"
32 #include "SMESHDS_SubMesh.hxx"
33 #include "SMESH_ControlsDef.hxx"
34 #include "SMESH_Mesh.hxx"
36 #include "utilities.h"
39 #include <TopExp_Explorer.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
44 //=============================================================================
48 //=============================================================================
50 StdMeshers_MaxElementVolume::StdMeshers_MaxElementVolume(int hypId, int studyId, SMESH_Gen* gen)
51 : SMESH_Hypothesis(hypId, studyId, gen)
54 _name = "MaxElementVolume";
58 //=============================================================================
62 //=============================================================================
64 StdMeshers_MaxElementVolume::~StdMeshers_MaxElementVolume()
66 MESSAGE("StdMeshers_MaxElementVolume::~StdMeshers_MaxElementVolume");
69 //=============================================================================
73 //=============================================================================
75 void StdMeshers_MaxElementVolume::SetMaxVolume(double maxVolume)
76 throw (SALOME_Exception)
78 double oldVolume = _maxVolume;
80 throw SALOME_Exception(LOCALIZED("maxVolume must be positive"));
81 _maxVolume = maxVolume;
82 if (_maxVolume != oldVolume)
83 NotifySubMeshesHypothesisModification();
86 //=============================================================================
90 //=============================================================================
92 double StdMeshers_MaxElementVolume::GetMaxVolume() const
97 //=============================================================================
101 //=============================================================================
103 ostream & StdMeshers_MaxElementVolume::SaveTo(ostream & save)
105 save << this->_maxVolume;
109 //=============================================================================
113 //=============================================================================
115 istream & StdMeshers_MaxElementVolume::LoadFrom(istream & load)
121 this->_maxVolume = a;
123 load.clear(ios::badbit | load.rdstate());
127 //=============================================================================
131 //=============================================================================
133 ostream & operator << (ostream & save, StdMeshers_MaxElementVolume & hyp)
135 return hyp.SaveTo( save );
138 //=============================================================================
142 //=============================================================================
144 istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp)
146 return hyp.LoadFrom( load );
150 //================================================================================
152 * \brief Initialize maximal area by the mesh built on the geometry
153 * \param theMesh - the built mesh
154 * \param theShape - the geometry of interest
155 * \retval bool - true if parameter values have been successfully defined
157 //================================================================================
159 bool StdMeshers_MaxElementVolume::SetParametersByMesh(const SMESH_Mesh* theMesh,
160 const TopoDS_Shape& theShape)
162 if ( !theMesh || theShape.IsNull() )
167 SMESH::Controls::Volume volumeControl;
169 TopTools_IndexedMapOfShape volMap;
170 TopExp::MapShapes( theShape, TopAbs_SOLID, volMap );
171 if ( volMap.IsEmpty() )
172 TopExp::MapShapes( theShape, TopAbs_SHELL, volMap );
173 if ( volMap.IsEmpty() )
176 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
178 for ( int iV = 1; iV <= volMap.Extent(); ++iV )
180 const TopoDS_Shape& S = volMap( iV );
181 SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( S );
182 if ( !subMesh && S.ShapeType() == TopAbs_SOLID ) {
183 TopExp_Explorer shellExp( S, TopAbs_SHELL );
184 if ( shellExp.More() )
185 subMesh = aMeshDS->MeshElements( shellExp.Current() );
189 SMDS_ElemIteratorPtr vIt = subMesh->GetElements();
190 while ( vIt->more() )
192 const SMDS_MeshElement* elem = vIt->next();
193 if ( elem->GetType() == SMDSAbs_Volume ) {
194 _maxVolume = max( _maxVolume, volumeControl.GetValue( elem->GetID() ));
198 return _maxVolume > 0;