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 // NETGENPlugin : C++ implementation
23 // File : NETGENPlugin_SimpleHypothesis_2D.cxx
24 // Author : Edward AGAPOV
26 //=============================================================================
28 #include "NETGENPlugin_SimpleHypothesis_2D.hxx"
29 #include "NETGENPlugin_Hypothesis.hxx"
31 #include <SMESH_Mesh.hxx>
32 #include <SMESH_subMesh.hxx>
33 #include <SMESH_ControlsDef.hxx>
35 #include <TopExp_Explorer.hxx>
37 #include <utilities.h>
41 //=============================================================================
45 //=============================================================================
46 NETGENPlugin_SimpleHypothesis_2D::NETGENPlugin_SimpleHypothesis_2D (int hypId,
49 : SMESH_Hypothesis(hypId, studyId, gen),
50 _nbSegments ((int)NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()),
54 _name = "NETGEN_SimpleParameters_2D";
58 //=============================================================================
62 //=============================================================================
63 void NETGENPlugin_SimpleHypothesis_2D::SetNumberOfSegments(int nb) throw (SALOME_Exception)
66 throw SALOME_Exception("Number of segments must be positive");
67 if (nb != _nbSegments)
70 if ( _nbSegments ) _segmentLength = 0.;
71 NotifySubMeshesHypothesisModification();
75 //=============================================================================
79 //=============================================================================
80 void NETGENPlugin_SimpleHypothesis_2D::SetLocalLength(double segmentLength)
81 throw (SALOME_Exception)
83 if ( segmentLength < DBL_MIN )
84 throw SALOME_Exception("segment length must be more than zero");
85 if (segmentLength != _segmentLength)
87 _segmentLength = segmentLength;
88 if ( _segmentLength > DBL_MIN ) _nbSegments = 0;
89 NotifySubMeshesHypothesisModification();
93 //=============================================================================
97 //=============================================================================
98 void NETGENPlugin_SimpleHypothesis_2D::LengthFromEdges()
100 if (_area > DBL_MIN )
103 NotifySubMeshesHypothesisModification();
107 //=============================================================================
111 //=============================================================================
112 void NETGENPlugin_SimpleHypothesis_2D::SetMaxElementArea(double area)
114 if ( area < DBL_MIN )
119 NotifySubMeshesHypothesisModification();
123 //=============================================================================
127 //=============================================================================
128 ostream & NETGENPlugin_SimpleHypothesis_2D::SaveTo(ostream & save)
130 save << _nbSegments << " " << _segmentLength << " " << _area;
135 //=============================================================================
139 //=============================================================================
140 istream & NETGENPlugin_SimpleHypothesis_2D::LoadFrom(istream & load)
145 isOK = (load >> val);
147 _nbSegments = (int) val;
149 load.clear(ios::badbit | load.rdstate());
151 isOK = (load >> val);
153 _segmentLength = val;
155 load.clear(ios::badbit | load.rdstate());
157 isOK = (load >> val);
161 load.clear(ios::badbit | load.rdstate());
166 //================================================================================
168 * \brief Does nothing
169 * \param theMesh - the built mesh
170 * \param theShape - the geometry of interest
171 * \retval bool - always false
173 //================================================================================
174 bool NETGENPlugin_SimpleHypothesis_2D::SetParametersByMesh(const SMESH_Mesh* theMesh,
175 const TopoDS_Shape& theShape)
177 // Find out nb of segments.
178 int nbSeg = 0, nbEdges = 0;
179 TopExp_Explorer exp( theShape, TopAbs_EDGE );
180 for ( ; exp.More(); exp.Next() ) {
181 SMESH_subMesh* sm = theMesh->GetSubMeshContaining( exp.Current() );
182 if ( sm && !sm->IsEmpty() ) {
183 nbSeg += sm->GetSubMeshDS()->NbElements();
188 _nbSegments = nbSeg / nbEdges;
190 // Find out max face area
192 SMESH::Controls::Area areaControl;
193 SMESH::Controls::TSequenceOfXYZ nodesCoords;
194 const int nbFacesToCheck = 100;
195 for ( exp.Init( theShape, TopAbs_FACE ); exp.More(); exp.Next() ) {
196 SMESH_subMesh* sm = theMesh->GetSubMeshContaining( exp.Current() );
197 if ( sm && !sm->IsEmpty() ) {
198 SMDS_ElemIteratorPtr fIt = sm->GetSubMeshDS()->GetElements();
199 int nbCheckedFaces = 0;
200 while ( fIt->more() && nbCheckedFaces++ < nbFacesToCheck ) {
201 const SMDS_MeshElement* elem = fIt->next();
202 areaControl.GetPoints( elem, nodesCoords );
203 _area = max( _area, areaControl.GetValue( nodesCoords ));
210 //================================================================================
212 * \brief Initialize my parameter values by default parameters.
213 * \retval bool - true if parameter values have been successfully defined
215 //================================================================================
217 bool NETGENPlugin_SimpleHypothesis_2D::SetParametersByDefaults(const TDefaults& dflts,
218 const SMESH_Mesh* /*theMesh*/)
220 _nbSegments = dflts._nbSegments;
221 _segmentLength = dflts._elemLength;
222 return _nbSegments && _segmentLength > 0;