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>
28 //=============================================================================
29 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
31 : SMESH_Hypothesis(hypId, studyId, gen),
32 _topology(GetDefaultTopology()),
33 _physicalMesh(GetDefaultPhysicalMesh()),
34 _phySize(GetDefaultPhySize()),
35 _phyMax(GetDefaultMaxSize()),
36 _phyMin(GetDefaultMinSize()),
37 _hgeoMax(GetDefaultMaxSize()),
38 _hgeoMin(GetDefaultMinSize()),
39 _geometricMesh(GetDefaultGeometricMesh()),
40 _angleMeshS(GetDefaultAngleMeshS()),
41 _angleMeshC(GetDefaultAngleMeshC()),
42 _gradation(GetDefaultGradation()),
43 _quadAllowed(GetDefaultQuadAllowed()),
44 _decimesh(GetDefaultDecimesh()),
45 _verb( GetDefaultVerbosity() )
47 _name = "BLSURF_Parameters";
50 // to desable writing boundaries
51 //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
54 const char* intOptionNames[] = {
83 const char* doubleOptionNames[] = {
101 const char* charOptionNames[] = {
110 while ( intOptionNames[i][0] )
111 _option2value[ intOptionNames[i++] ].clear();
114 while ( doubleOptionNames[i][0] ) {
115 _doubleOptions.insert( doubleOptionNames[i] );
116 _option2value[ doubleOptionNames[i++] ].clear();
119 while ( charOptionNames[i][0] ) {
120 _charOptions.insert( charOptionNames[i] );
121 _option2value[ charOptionNames[i++] ].clear();
125 //=============================================================================
126 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
128 if (theTopology != _topology) {
129 _topology = theTopology;
130 NotifySubMeshesHypothesisModification();
134 //=============================================================================
135 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
137 if (thePhysicalMesh != _physicalMesh) {
138 _physicalMesh = thePhysicalMesh;
139 switch( _physicalMesh ) {
142 _phySize = GetDefaultPhySize();
145 NotifySubMeshesHypothesisModification();
149 //=============================================================================
150 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
152 if (theVal != _phySize) {
154 NotifySubMeshesHypothesisModification();
158 //=============================================================================
159 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
161 if (theMinSize != _phyMin) {
162 _phyMin = theMinSize;
163 NotifySubMeshesHypothesisModification();
167 //=============================================================================
168 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
170 if (theMaxSize != _phyMax) {
171 _phyMax = theMaxSize;
172 NotifySubMeshesHypothesisModification();
177 //=============================================================================
178 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
180 if (theMinSize != _hgeoMin) {
181 _hgeoMin = theMinSize;
182 NotifySubMeshesHypothesisModification();
186 //=============================================================================
187 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
189 if (theMaxSize != _hgeoMax) {
190 _hgeoMax = theMaxSize;
191 NotifySubMeshesHypothesisModification();
195 //=============================================================================
196 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
198 if (theGeometricMesh != _geometricMesh) {
199 _geometricMesh = theGeometricMesh;
200 switch( _geometricMesh ) {
203 _angleMeshS = GetDefaultAngleMeshS();
204 _gradation = GetDefaultGradation();
207 NotifySubMeshesHypothesisModification();
211 //=============================================================================
212 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
214 if (theVal != _angleMeshS) {
215 _angleMeshS = theVal;
216 NotifySubMeshesHypothesisModification();
220 //=============================================================================
221 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
223 if (theVal != _angleMeshC) {
224 _angleMeshC = theVal;
225 NotifySubMeshesHypothesisModification();
229 //=============================================================================
230 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
232 if (theVal != _gradation) {
234 NotifySubMeshesHypothesisModification();
238 //=============================================================================
239 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
241 if (theVal != _quadAllowed) {
242 _quadAllowed = theVal;
243 NotifySubMeshesHypothesisModification();
247 //=============================================================================
248 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
250 if (theVal != _decimesh) {
252 NotifySubMeshesHypothesisModification();
256 //=============================================================================
257 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
259 if (theVal != _verb) {
261 NotifySubMeshesHypothesisModification();
264 //=============================================================================
265 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
266 const std::string& optionValue)
267 throw (std::invalid_argument)
269 TOptionValues::iterator op_val = _option2value.find( optionName );
270 if ( op_val == _option2value.end() ) {
271 std::string msg = "Unknown BLSURF option: '" + optionName + "'";
272 throw std::invalid_argument(msg);
274 if ( op_val->second != optionValue ) {
275 const char* ptr = optionValue.c_str();
276 // strip white spaces
277 while ( ptr[0] == ' ' )
279 int i = strlen( ptr );
280 while ( i != 0 && ptr[i-1] == ' ')
284 std::string typeName;
288 else if ( _charOptions.find( optionName ) != _charOptions.end() ) {
289 // do not check strings
291 else if ( _doubleOptions.find( optionName ) != _doubleOptions.end() ) {
292 // check if value is double
294 strtod(ptr, &endPtr);
295 typeOk = ( ptr != endPtr );
299 // check if value is int
301 strtol(ptr, &endPtr,10);
302 typeOk = ( ptr != endPtr );
303 typeName = "integer";
306 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue +
307 "' but must be " + typeName;
308 throw std::invalid_argument(msg);
310 op_val->second = optionValue;
311 NotifySubMeshesHypothesisModification();
315 //=============================================================================
316 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName)
317 throw (std::invalid_argument)
319 TOptionValues::iterator op_val = _option2value.find( optionName );
320 if ( op_val == _option2value.end() ) {
321 std::string msg = "Unknown BLSURF option: <";
322 msg += optionName + ">";
323 throw std::invalid_argument(msg);
325 return op_val->second;
328 //=============================================================================
329 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
331 TOptionValues::iterator op_val = _option2value.find( optionName );
332 if ( op_val != _option2value.end() )
333 op_val->second.clear();
336 //=============================================================================
337 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
339 save << " " << (int)_topology
340 << " " << (int)_physicalMesh
341 << " " << (int)_geometricMesh
343 << " " << _angleMeshS
345 << " " << (int)_quadAllowed
346 << " " << (int)_decimesh;
347 save << " " << _phyMin
349 << " " << _angleMeshC
354 TOptionValues::iterator op_val = _option2value.begin();
355 for ( ; op_val != _option2value.end(); ++op_val ) {
356 if ( !op_val->second.empty() )
357 save << " " << op_val->first
358 << " " << op_val->second << "%#"; // "%#" is a mark of value end
364 //=============================================================================
365 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
373 _topology = (Topology) i;
375 load.clear(std::ios::badbit | load.rdstate());
379 _physicalMesh = (PhysicalMesh) i;
381 load.clear(std::ios::badbit | load.rdstate());
385 _geometricMesh = (GeometricMesh) i;
387 load.clear(std::ios::badbit | load.rdstate());
389 isOK = (load >> val);
393 load.clear(std::ios::badbit | load.rdstate());
395 isOK = (load >> val);
399 load.clear(std::ios::badbit | load.rdstate());
401 isOK = (load >> val);
405 load.clear(std::ios::badbit | load.rdstate());
409 _quadAllowed = (bool) i;
411 load.clear(std::ios::badbit | load.rdstate());
415 _decimesh = (bool) i;
417 load.clear(std::ios::badbit | load.rdstate());
419 isOK = (load >> val);
423 load.clear(std::ios::badbit | load.rdstate());
425 isOK = (load >> val);
429 load.clear(std::ios::badbit | load.rdstate());
431 isOK = (load >> val);
435 load.clear(std::ios::badbit | load.rdstate());
437 isOK = (load >> val);
441 load.clear(std::ios::badbit | load.rdstate());
443 isOK = (load >> val);
447 load.clear(std::ios::badbit | load.rdstate());
453 load.clear(std::ios::badbit | load.rdstate());
455 std::string optName, optValue;
457 isOK = (load >> optName);
459 isOK = (load >> optValue);
461 std::string & value = _option2value[ optName ];
463 int len = value.size();
464 // continue reading until "%#" encountered
465 while ( value[len-1] != '#' || value[len-2] != '%' )
467 isOK = (load >> optValue);
477 value[ len-2 ] = '\0'; //cut off "%#"
484 //=============================================================================
485 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp)
487 return hyp.SaveTo( save );
490 //=============================================================================
491 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp)
493 return hyp.LoadFrom( load );
496 //================================================================================
498 * \brief Does nothing
500 //================================================================================
502 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
503 const TopoDS_Shape& theShape)
508 //=============================================================================
510 * \brief Initialize my parameter values by default parameters.
511 * \retval bool - true if parameter values have been successfully defined
513 //=============================================================================
515 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
516 const SMESH_Mesh* theMesh)
518 return bool( _phySize = dflts._elemLength );
521 //=============================================================================
522 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
527 //=============================================================================
528 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
530 return PhysicalUserDefined;
533 //=============================================================================
534 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
539 //======================================================================
540 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
542 return undefinedDouble(); // 1e+4;
545 //======================================================================
546 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
548 return undefinedDouble(); //1e-4;
551 //======================================================================
552 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
557 //=============================================================================
558 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
563 //=============================================================================
564 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
569 //=============================================================================
570 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
575 //=============================================================================
576 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()