1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : BLSURFPlugin_Hypothesis.cxx
21 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
22 // & Aurelien ALLEAUME (DISTENE)
25 #include "BLSURFPlugin_Hypothesis.hxx"
26 #include <utilities.h>
29 //=============================================================================
30 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
32 : SMESH_Hypothesis(hypId, studyId, gen),
33 _topology(GetDefaultTopology()),
34 _physicalMesh(GetDefaultPhysicalMesh()),
35 _phySize(GetDefaultPhySize()),
36 _phyMax(GetDefaultMaxSize()),
37 _phyMin(GetDefaultMinSize()),
38 _hgeoMax(GetDefaultMaxSize()),
39 _hgeoMin(GetDefaultMinSize()),
40 _geometricMesh(GetDefaultGeometricMesh()),
41 _angleMeshS(GetDefaultAngleMeshS()),
42 _angleMeshC(GetDefaultAngleMeshC()),
43 _gradation(GetDefaultGradation()),
44 _quadAllowed(GetDefaultQuadAllowed()),
45 _decimesh(GetDefaultDecimesh()),
46 _verb( GetDefaultVerbosity() )
48 _name = "BLSURF_Parameters";
51 // to desable writing boundaries
52 //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
55 const char* intOptionNames[] = {
84 const char* doubleOptionNames[] = {
102 const char* charOptionNames[] = {
111 while ( intOptionNames[i][0] )
112 _option2value[ intOptionNames[i++] ].clear();
115 while ( doubleOptionNames[i][0] ) {
116 _doubleOptions.insert( doubleOptionNames[i] );
117 _option2value[ doubleOptionNames[i++] ].clear();
120 while ( charOptionNames[i][0] ) {
121 _charOptions.insert( charOptionNames[i] );
122 _option2value[ charOptionNames[i++] ].clear();
126 //=============================================================================
127 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
129 if (theTopology != _topology) {
130 _topology = theTopology;
131 NotifySubMeshesHypothesisModification();
135 //=============================================================================
136 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
138 if (thePhysicalMesh != _physicalMesh) {
139 _physicalMesh = thePhysicalMesh;
140 switch( _physicalMesh ) {
143 _phySize = GetDefaultPhySize();
146 NotifySubMeshesHypothesisModification();
150 //=============================================================================
151 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
153 if (theVal != _phySize) {
155 NotifySubMeshesHypothesisModification();
159 //=============================================================================
160 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
162 if (theMinSize != _phyMin) {
163 _phyMin = theMinSize;
164 NotifySubMeshesHypothesisModification();
168 //=============================================================================
169 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
171 if (theMaxSize != _phyMax) {
172 _phyMax = theMaxSize;
173 NotifySubMeshesHypothesisModification();
178 //=============================================================================
179 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
181 if (theMinSize != _hgeoMin) {
182 _hgeoMin = theMinSize;
183 NotifySubMeshesHypothesisModification();
187 //=============================================================================
188 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
190 if (theMaxSize != _hgeoMax) {
191 _hgeoMax = theMaxSize;
192 NotifySubMeshesHypothesisModification();
196 //=============================================================================
197 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
199 if (theGeometricMesh != _geometricMesh) {
200 _geometricMesh = theGeometricMesh;
201 switch( _geometricMesh ) {
204 _angleMeshS = GetDefaultAngleMeshS();
205 _gradation = GetDefaultGradation();
208 NotifySubMeshesHypothesisModification();
212 //=============================================================================
213 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
215 if (theVal != _angleMeshS) {
216 _angleMeshS = theVal;
217 NotifySubMeshesHypothesisModification();
221 //=============================================================================
222 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
224 if (theVal != _angleMeshC) {
225 _angleMeshC = theVal;
226 NotifySubMeshesHypothesisModification();
230 //=============================================================================
231 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
233 if (theVal != _gradation) {
235 NotifySubMeshesHypothesisModification();
239 //=============================================================================
240 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
242 if (theVal != _quadAllowed) {
243 _quadAllowed = theVal;
244 NotifySubMeshesHypothesisModification();
248 //=============================================================================
249 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
251 if (theVal != _decimesh) {
253 NotifySubMeshesHypothesisModification();
257 //=============================================================================
258 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
260 if (theVal != _verb) {
262 NotifySubMeshesHypothesisModification();
265 //=============================================================================
266 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
267 const std::string& optionValue)
268 throw (std::invalid_argument)
270 TOptionValues::iterator op_val = _option2value.find( optionName );
271 if ( op_val == _option2value.end() ) {
272 std::string msg = "Unknown BLSURF option: '" + optionName + "'";
273 throw std::invalid_argument(msg);
275 if ( op_val->second != optionValue ) {
276 const char* ptr = optionValue.c_str();
277 // strip white spaces
278 while ( ptr[0] == ' ' )
280 int i = strlen( ptr );
281 while ( i != 0 && ptr[i-1] == ' ')
285 std::string typeName;
289 else if ( _charOptions.find( optionName ) != _charOptions.end() ) {
290 // do not check strings
292 else if ( _doubleOptions.find( optionName ) != _doubleOptions.end() ) {
293 // check if value is double
295 strtod(ptr, &endPtr);
296 typeOk = ( ptr != endPtr );
300 // check if value is int
302 strtol(ptr, &endPtr,10);
303 typeOk = ( ptr != endPtr );
304 typeName = "integer";
307 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue +
308 "' but must be " + typeName;
309 throw std::invalid_argument(msg);
311 op_val->second = optionValue;
312 NotifySubMeshesHypothesisModification();
316 //=============================================================================
317 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName)
318 throw (std::invalid_argument)
320 TOptionValues::iterator op_val = _option2value.find( optionName );
321 if ( op_val == _option2value.end() ) {
322 std::string msg = "Unknown BLSURF option: <";
323 msg += optionName + ">";
324 throw std::invalid_argument(msg);
326 return op_val->second;
329 //=============================================================================
330 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
332 TOptionValues::iterator op_val = _option2value.find( optionName );
333 if ( op_val != _option2value.end() )
334 op_val->second.clear();
337 //=============================================================================
338 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
340 save << " " << (int)_topology
341 << " " << (int)_physicalMesh
342 << " " << (int)_geometricMesh
344 << " " << _angleMeshS
346 << " " << (int)_quadAllowed
347 << " " << (int)_decimesh;
348 save << " " << _phyMin
350 << " " << _angleMeshC
355 TOptionValues::iterator op_val = _option2value.begin();
356 for ( ; op_val != _option2value.end(); ++op_val ) {
357 if ( !op_val->second.empty() )
358 save << " " << op_val->first
359 << " " << op_val->second << "%#"; // "%#" is a mark of value end
365 //=============================================================================
366 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
374 _topology = (Topology) i;
376 load.clear(std::ios::badbit | load.rdstate());
380 _physicalMesh = (PhysicalMesh) i;
382 load.clear(std::ios::badbit | load.rdstate());
386 _geometricMesh = (GeometricMesh) i;
388 load.clear(std::ios::badbit | load.rdstate());
390 isOK = (load >> val);
394 load.clear(std::ios::badbit | load.rdstate());
396 isOK = (load >> val);
400 load.clear(std::ios::badbit | load.rdstate());
402 isOK = (load >> val);
406 load.clear(std::ios::badbit | load.rdstate());
410 _quadAllowed = (bool) i;
412 load.clear(std::ios::badbit | load.rdstate());
416 _decimesh = (bool) i;
418 load.clear(std::ios::badbit | load.rdstate());
420 isOK = (load >> val);
424 load.clear(std::ios::badbit | load.rdstate());
426 isOK = (load >> val);
430 load.clear(std::ios::badbit | load.rdstate());
432 isOK = (load >> val);
436 load.clear(std::ios::badbit | load.rdstate());
438 isOK = (load >> val);
442 load.clear(std::ios::badbit | load.rdstate());
444 isOK = (load >> val);
448 load.clear(std::ios::badbit | load.rdstate());
454 load.clear(std::ios::badbit | load.rdstate());
456 std::string optName, optValue;
458 isOK = (load >> optName);
460 isOK = (load >> optValue);
462 std::string & value = _option2value[ optName ];
464 int len = value.size();
465 // continue reading until "%#" encountered
466 while ( value[len-1] != '#' || value[len-2] != '%' )
468 isOK = (load >> optValue);
478 value[ len-2 ] = '\0'; //cut off "%#"
485 //=============================================================================
486 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp)
488 return hyp.SaveTo( save );
491 //=============================================================================
492 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp)
494 return hyp.LoadFrom( load );
497 //================================================================================
499 * \brief Does nothing
501 //================================================================================
503 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
504 const TopoDS_Shape& theShape)
509 //=============================================================================
511 * \brief Initialize my parameter values by default parameters.
512 * \retval bool - true if parameter values have been successfully defined
514 //=============================================================================
516 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
517 const SMESH_Mesh* theMesh)
519 return bool( _phySize = dflts._elemLength );
522 //=============================================================================
523 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
528 //=============================================================================
529 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
531 return PhysicalUserDefined;
534 //=============================================================================
535 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
540 //======================================================================
541 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
543 return undefinedDouble(); // 1e+4;
546 //======================================================================
547 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
549 return undefinedDouble(); //1e-4;
552 //======================================================================
553 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
558 //=============================================================================
559 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
564 //=============================================================================
565 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
570 //=============================================================================
571 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
576 //=============================================================================
577 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()