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 : StdMeshers_MaxElementArea.cxx
25 // Moved here from SMESH_MaxElementArea.cxx
26 // Author : Paul RASCLE, EDF
30 #include "StdMeshers_MaxElementArea.hxx"
32 #include "SMESH_ControlsDef.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMESHDS_SubMesh.hxx"
35 #include "SMESH_Mesh.hxx"
38 #include <TopTools_IndexedMapOfShape.hxx>
40 #include "utilities.h"
44 //=============================================================================
48 //=============================================================================
50 StdMeshers_MaxElementArea::StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen* gen)
51 : SMESH_Hypothesis(hypId, studyId, gen)
54 _name = "MaxElementArea";
58 //=============================================================================
62 //=============================================================================
64 StdMeshers_MaxElementArea::~StdMeshers_MaxElementArea()
68 //=============================================================================
72 //=============================================================================
74 void StdMeshers_MaxElementArea::SetMaxArea(double maxArea)
75 throw (SALOME_Exception)
77 double oldArea = _maxArea;
79 throw SALOME_Exception(LOCALIZED("maxArea must be positive"));
81 if (_maxArea != oldArea)
82 NotifySubMeshesHypothesisModification();
85 //=============================================================================
89 //=============================================================================
91 double StdMeshers_MaxElementArea::GetMaxArea() const
96 //=============================================================================
100 //=============================================================================
102 ostream & StdMeshers_MaxElementArea::SaveTo(ostream & save)
104 save << this->_maxArea;
108 //=============================================================================
112 //=============================================================================
114 istream & StdMeshers_MaxElementArea::LoadFrom(istream & load)
122 load.clear(ios::badbit | load.rdstate());
126 //=============================================================================
130 //=============================================================================
132 ostream & operator << (ostream & save, StdMeshers_MaxElementArea & hyp)
134 return hyp.SaveTo( save );
137 //=============================================================================
141 //=============================================================================
143 istream & operator >> (istream & load, StdMeshers_MaxElementArea & hyp)
145 return hyp.LoadFrom( load );
148 //================================================================================
150 * \brief Initialize maximal area by the mesh built on the geometry
151 * \param theMesh - the built mesh
152 * \param theShape - the geometry of interest
153 * \retval bool - true if parameter values have been successfully defined
155 //================================================================================
157 bool StdMeshers_MaxElementArea::SetParametersByMesh(const SMESH_Mesh* theMesh,
158 const TopoDS_Shape& theShape)
160 if ( !theMesh || theShape.IsNull() )
165 SMESH::Controls::Area areaControl;
166 SMESH::Controls::TSequenceOfXYZ nodesCoords;
168 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
170 TopTools_IndexedMapOfShape faceMap;
171 TopExp::MapShapes( theShape, TopAbs_FACE, faceMap );
172 for ( int iF = 1; iF <= faceMap.Extent(); ++iF )
174 SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( faceMap( iF ));
177 SMDS_ElemIteratorPtr fIt = subMesh->GetElements();
178 while ( fIt->more() )
180 const SMDS_MeshElement* elem = fIt->next();
181 if ( elem->GetType() == SMDSAbs_Face ) {
182 areaControl.GetPoints( elem, nodesCoords );
183 _maxArea = max( _maxArea, areaControl.GetValue( nodesCoords ));