1 // Copyright (C) 2007-2020 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 : implementation 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 "SMDS_MeshElement.hxx"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESHDS_Mesh.hxx"
34 #include "SMESHDS_SubMesh.hxx"
35 #include "SMESH_ControlsDef.hxx"
36 #include "SMESH_Mesh.hxx"
39 #include <TopTools_IndexedMapOfShape.hxx>
41 #include "utilities.h"
45 //=============================================================================
49 //=============================================================================
51 StdMeshers_MaxElementArea::StdMeshers_MaxElementArea(int hypId, SMESH_Gen* gen)
52 : SMESH_Hypothesis(hypId, gen)
55 _name = "MaxElementArea";
59 //=============================================================================
63 //=============================================================================
65 StdMeshers_MaxElementArea::~StdMeshers_MaxElementArea()
69 //=============================================================================
73 //=============================================================================
75 void StdMeshers_MaxElementArea::SetMaxArea(double maxArea)
76 throw (SALOME_Exception)
78 double oldArea = _maxArea;
80 throw SALOME_Exception(LOCALIZED("maxArea must be positive"));
82 if (_maxArea != oldArea)
83 NotifySubMeshesHypothesisModification();
86 //=============================================================================
90 //=============================================================================
92 double StdMeshers_MaxElementArea::GetMaxArea() const
97 //=============================================================================
101 //=============================================================================
103 ostream & StdMeshers_MaxElementArea::SaveTo(ostream & save)
105 save << this->_maxArea;
109 //=============================================================================
113 //=============================================================================
115 istream & StdMeshers_MaxElementArea::LoadFrom(istream & load)
119 isOK = static_cast<bool>(load >> a);
123 load.clear(ios::badbit | load.rdstate());
127 //=============================================================================
131 //=============================================================================
133 ostream & operator << (ostream & save, StdMeshers_MaxElementArea & hyp)
135 return hyp.SaveTo( save );
138 //=============================================================================
142 //=============================================================================
144 istream & operator >> (istream & load, StdMeshers_MaxElementArea & hyp)
146 return hyp.LoadFrom( load );
149 //================================================================================
151 * \brief Initialize maximal area by the mesh built on the geometry
152 * \param theMesh - the built mesh
153 * \param theShape - the geometry of interest
154 * \retval bool - true if parameter values have been successfully defined
156 //================================================================================
158 bool StdMeshers_MaxElementArea::SetParametersByMesh(const SMESH_Mesh* theMesh,
159 const TopoDS_Shape& theShape)
161 if ( !theMesh || theShape.IsNull() )
166 SMESH::Controls::Area areaControl;
167 SMESH::Controls::TSequenceOfXYZ nodesCoords;
169 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
171 TopTools_IndexedMapOfShape faceMap;
172 TopExp::MapShapes( theShape, TopAbs_FACE, faceMap );
173 for ( int iF = 1; iF <= faceMap.Extent(); ++iF )
175 SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( faceMap( iF ));
178 SMDS_ElemIteratorPtr fIt = subMesh->GetElements();
179 while ( fIt->more() )
181 const SMDS_MeshElement* elem = fIt->next();
182 if ( elem->GetType() == SMDSAbs_Face ) {
183 areaControl.GetPoints( elem, nodesCoords );
184 _maxArea = max( _maxArea, areaControl.GetValue( nodesCoords ));
190 //================================================================================
192 * \brief Initialize my parameter values by default parameters.
193 * \retval bool - true if parameter values have been successfully defined
195 //================================================================================
197 bool StdMeshers_MaxElementArea::SetParametersByDefaults(const TDefaults& dflts,
198 const SMESH_Mesh* /*theMesh*/)
200 return ( _maxArea = dflts._elemLength*dflts._elemLength );