1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_MaxElementVolume.cxx
25 // Moved here from SMESH_MaxElementVolume.cxx
26 // Author : Paul RASCLE, EDF
29 #include "StdMeshers_MaxElementVolume.hxx"
31 #include "SMDS_MeshElement.hxx"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESHDS_SubMesh.hxx"
34 #include "SMESH_ControlsDef.hxx"
35 #include "SMESH_Mesh.hxx"
37 #include "utilities.h"
40 #include <TopExp_Explorer.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
45 //=============================================================================
49 //=============================================================================
51 StdMeshers_MaxElementVolume::StdMeshers_MaxElementVolume(int hypId, int studyId, SMESH_Gen* gen)
52 : SMESH_Hypothesis(hypId, studyId, gen)
55 _name = "MaxElementVolume";
59 //=============================================================================
63 //=============================================================================
65 StdMeshers_MaxElementVolume::~StdMeshers_MaxElementVolume()
67 MESSAGE("StdMeshers_MaxElementVolume::~StdMeshers_MaxElementVolume");
70 //=============================================================================
74 //=============================================================================
76 void StdMeshers_MaxElementVolume::SetMaxVolume(double maxVolume)
77 throw (SALOME_Exception)
79 double oldVolume = _maxVolume;
81 throw SALOME_Exception(LOCALIZED("maxVolume must be positive"));
82 _maxVolume = maxVolume;
83 if (_maxVolume != oldVolume)
84 NotifySubMeshesHypothesisModification();
87 //=============================================================================
91 //=============================================================================
93 double StdMeshers_MaxElementVolume::GetMaxVolume() const
98 //=============================================================================
102 //=============================================================================
104 ostream & StdMeshers_MaxElementVolume::SaveTo(ostream & save)
106 save << this->_maxVolume;
110 //=============================================================================
114 //=============================================================================
116 istream & StdMeshers_MaxElementVolume::LoadFrom(istream & load)
120 isOK = static_cast<bool>(load >> a);
122 this->_maxVolume = a;
124 load.clear(ios::badbit | load.rdstate());
128 //=============================================================================
132 //=============================================================================
134 ostream & operator << (ostream & save, StdMeshers_MaxElementVolume & hyp)
136 return hyp.SaveTo( save );
139 //=============================================================================
143 //=============================================================================
145 istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp)
147 return hyp.LoadFrom( load );
151 //================================================================================
153 * \brief Initialize maximal area by the mesh built on the geometry
154 * \param theMesh - the built mesh
155 * \param theShape - the geometry of interest
156 * \retval bool - true if parameter values have been successfully defined
158 //================================================================================
160 bool StdMeshers_MaxElementVolume::SetParametersByMesh(const SMESH_Mesh* theMesh,
161 const TopoDS_Shape& theShape)
163 if ( !theMesh || theShape.IsNull() )
168 SMESH::Controls::Volume volumeControl;
170 TopTools_IndexedMapOfShape volMap;
171 TopExp::MapShapes( theShape, TopAbs_SOLID, volMap );
172 if ( volMap.IsEmpty() )
173 TopExp::MapShapes( theShape, TopAbs_SHELL, volMap );
174 if ( volMap.IsEmpty() )
177 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
179 for ( int iV = 1; iV <= volMap.Extent(); ++iV )
181 const TopoDS_Shape& S = volMap( iV );
182 SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( S );
183 if ( !subMesh && S.ShapeType() == TopAbs_SOLID ) {
184 TopExp_Explorer shellExp( S, TopAbs_SHELL );
185 if ( shellExp.More() )
186 subMesh = aMeshDS->MeshElements( shellExp.Current() );
190 SMDS_ElemIteratorPtr vIt = subMesh->GetElements();
191 while ( vIt->more() )
193 const SMDS_MeshElement* elem = vIt->next();
194 if ( elem->GetType() == SMDSAbs_Volume ) {
195 _maxVolume = max( _maxVolume, volumeControl.GetValue( elem->GetID() ));
199 return _maxVolume > 0;
201 //================================================================================
203 * \brief Initialize my parameter values by default parameters.
204 * \retval bool - true if parameter values have been successfully defined
206 //================================================================================
208 bool StdMeshers_MaxElementVolume::SetParametersByDefaults(const TDefaults& dflts,
209 const SMESH_Mesh* /*theMesh*/)
211 return ( _maxVolume = dflts._elemLength*dflts._elemLength*dflts._elemLength );