1 // Copyright (C) 2007-2011 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
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_MaxElementArea.cxx
25 // Moved here from SMESH_MaxElementArea.cxx
26 // Author : Paul RASCLE, EDF
29 #include "StdMeshers_MaxElementArea.hxx"
31 #include "SMESH_ControlsDef.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMESHDS_SubMesh.hxx"
34 #include "SMESH_Mesh.hxx"
37 #include <TopTools_IndexedMapOfShape.hxx>
39 #include "utilities.h"
43 //=============================================================================
47 //=============================================================================
49 StdMeshers_MaxElementArea::StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen* gen)
50 : SMESH_Hypothesis(hypId, studyId, gen)
53 _name = "MaxElementArea";
57 //=============================================================================
61 //=============================================================================
63 StdMeshers_MaxElementArea::~StdMeshers_MaxElementArea()
67 //=============================================================================
71 //=============================================================================
73 void StdMeshers_MaxElementArea::SetMaxArea(double maxArea)
74 throw (SALOME_Exception)
76 double oldArea = _maxArea;
78 throw SALOME_Exception(LOCALIZED("maxArea must be positive"));
80 if (_maxArea != oldArea)
81 NotifySubMeshesHypothesisModification();
84 //=============================================================================
88 //=============================================================================
90 double StdMeshers_MaxElementArea::GetMaxArea() const
95 //=============================================================================
99 //=============================================================================
101 ostream & StdMeshers_MaxElementArea::SaveTo(ostream & save)
103 save << this->_maxArea;
107 //=============================================================================
111 //=============================================================================
113 istream & StdMeshers_MaxElementArea::LoadFrom(istream & load)
121 load.clear(ios::badbit | load.rdstate());
125 //=============================================================================
129 //=============================================================================
131 ostream & operator << (ostream & save, StdMeshers_MaxElementArea & hyp)
133 return hyp.SaveTo( save );
136 //=============================================================================
140 //=============================================================================
142 istream & operator >> (istream & load, StdMeshers_MaxElementArea & hyp)
144 return hyp.LoadFrom( load );
147 //================================================================================
149 * \brief Initialize maximal area by the mesh built on the geometry
150 * \param theMesh - the built mesh
151 * \param theShape - the geometry of interest
152 * \retval bool - true if parameter values have been successfully defined
154 //================================================================================
156 bool StdMeshers_MaxElementArea::SetParametersByMesh(const SMESH_Mesh* theMesh,
157 const TopoDS_Shape& theShape)
159 if ( !theMesh || theShape.IsNull() )
164 SMESH::Controls::Area areaControl;
165 SMESH::Controls::TSequenceOfXYZ nodesCoords;
167 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
169 TopTools_IndexedMapOfShape faceMap;
170 TopExp::MapShapes( theShape, TopAbs_FACE, faceMap );
171 for ( int iF = 1; iF <= faceMap.Extent(); ++iF )
173 SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( faceMap( iF ));
176 SMDS_ElemIteratorPtr fIt = subMesh->GetElements();
177 while ( fIt->more() )
179 const SMDS_MeshElement* elem = fIt->next();
180 if ( elem->GetType() == SMDSAbs_Face ) {
181 areaControl.GetPoints( elem, nodesCoords );
182 _maxArea = max( _maxArea, areaControl.GetValue( nodesCoords ));
188 //================================================================================
190 * \brief Initialize my parameter values by default parameters.
191 * \retval bool - true if parameter values have been successfully defined
193 //================================================================================
195 bool StdMeshers_MaxElementArea::SetParametersByDefaults(const TDefaults& dflts,
196 const SMESH_Mesh* /*theMesh*/)
198 return ( _maxArea = dflts._elemLength*dflts._elemLength );