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();
128 //=============================================================================
129 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
131 if (theTopology != _topology) {
132 _topology = theTopology;
133 NotifySubMeshesHypothesisModification();
137 //=============================================================================
138 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
140 if (thePhysicalMesh != _physicalMesh) {
141 _physicalMesh = thePhysicalMesh;
142 switch( _physicalMesh ) {
145 _phySize = GetDefaultPhySize();
148 NotifySubMeshesHypothesisModification();
152 //=============================================================================
153 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
155 if (theVal != _phySize) {
157 NotifySubMeshesHypothesisModification();
161 //=============================================================================
162 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
164 if (theMinSize != _phyMin) {
165 _phyMin = theMinSize;
166 NotifySubMeshesHypothesisModification();
170 //=============================================================================
171 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
173 if (theMaxSize != _phyMax) {
174 _phyMax = theMaxSize;
175 NotifySubMeshesHypothesisModification();
180 //=============================================================================
181 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
183 if (theMinSize != _hgeoMin) {
184 _hgeoMin = theMinSize;
185 NotifySubMeshesHypothesisModification();
189 //=============================================================================
190 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
192 if (theMaxSize != _hgeoMax) {
193 _hgeoMax = theMaxSize;
194 NotifySubMeshesHypothesisModification();
198 //=============================================================================
199 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
201 if (theGeometricMesh != _geometricMesh) {
202 _geometricMesh = theGeometricMesh;
203 switch( _geometricMesh ) {
206 _angleMeshS = GetDefaultAngleMeshS();
207 _gradation = GetDefaultGradation();
210 NotifySubMeshesHypothesisModification();
214 //=============================================================================
215 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
217 if (theVal != _angleMeshS) {
218 _angleMeshS = theVal;
219 NotifySubMeshesHypothesisModification();
223 //=============================================================================
224 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
226 if (theVal != _angleMeshC) {
227 _angleMeshC = theVal;
228 NotifySubMeshesHypothesisModification();
232 //=============================================================================
233 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
235 if (theVal != _gradation) {
237 NotifySubMeshesHypothesisModification();
241 //=============================================================================
242 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
244 if (theVal != _quadAllowed) {
245 _quadAllowed = theVal;
246 NotifySubMeshesHypothesisModification();
250 //=============================================================================
251 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
253 if (theVal != _decimesh) {
255 NotifySubMeshesHypothesisModification();
259 //=============================================================================
260 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
262 if (theVal != _verb) {
264 NotifySubMeshesHypothesisModification();
267 //=============================================================================
268 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
269 const std::string& optionValue)
270 throw (std::invalid_argument)
272 TOptionValues::iterator op_val = _option2value.find( optionName );
273 if ( op_val == _option2value.end() ) {
274 std::string msg = "Unknown BLSURF option: '" + optionName + "'";
275 throw std::invalid_argument(msg);
277 if ( op_val->second != optionValue ) {
278 const char* ptr = optionValue.c_str();
279 // strip white spaces
280 while ( ptr[0] == ' ' )
282 int i = strlen( ptr );
283 while ( i != 0 && ptr[i-1] == ' ')
287 std::string typeName;
291 else if ( _charOptions.find( optionName ) != _charOptions.end() ) {
292 // do not check strings
294 else if ( _doubleOptions.find( optionName ) != _doubleOptions.end() ) {
295 // check if value is double
297 strtod(ptr, &endPtr);
298 typeOk = ( ptr != endPtr );
302 // check if value is int
304 strtol(ptr, &endPtr,10);
305 typeOk = ( ptr != endPtr );
306 typeName = "integer";
309 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue +
310 "' but must be " + typeName;
311 throw std::invalid_argument(msg);
313 op_val->second = optionValue;
314 NotifySubMeshesHypothesisModification();
318 //=============================================================================
319 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName)
320 throw (std::invalid_argument)
322 TOptionValues::iterator op_val = _option2value.find( optionName );
323 if ( op_val == _option2value.end() ) {
324 std::string msg = "Unknown BLSURF option: <";
325 msg += optionName + ">";
326 throw std::invalid_argument(msg);
328 return op_val->second;
331 //=============================================================================
332 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
334 TOptionValues::iterator op_val = _option2value.find( optionName );
335 if ( op_val != _option2value.end() )
336 op_val->second.clear();
340 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry,const std::string& sizeMap)
342 if (_sizeMap[entry].compare(sizeMap) != 0) {
343 _sizeMap[entry]=sizeMap;
344 NotifySubMeshesHypothesisModification();
348 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry)
350 TSizeMap::iterator it = _sizeMap.find( entry );
351 if ( it != _sizeMap.end() )
354 return "No_Such_Entry";
357 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
359 TSizeMap::iterator it = _sizeMap.find( entry );
360 if ( it != _sizeMap.end() )
363 std::cout<<"No_Such_Entry"<<std::endl;
367 void BLSURFPlugin_Hypothesis::ClearSizeMaps()
374 //=============================================================================
375 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
377 save << " " << (int)_topology
378 << " " << (int)_physicalMesh
379 << " " << (int)_geometricMesh
381 << " " << _angleMeshS
383 << " " << (int)_quadAllowed
384 << " " << (int)_decimesh;
385 save << " " << _phyMin
387 << " " << _angleMeshC
392 TOptionValues::iterator op_val = _option2value.begin();
393 if (op_val != _option2value.end()) {
394 save << " " << "__OPTIONS_BEGIN__";
395 for ( ; op_val != _option2value.end(); ++op_val ) {
396 if ( !op_val->second.empty() )
397 save << " " << op_val->first
398 << " " << op_val->second << "%#"; // "%#" is a mark of value end
400 save << " " << "__OPTIONS_END__";
403 TSizeMap::iterator it_sm = _sizeMap.begin();
404 if (it_sm != _sizeMap.end()) {
405 save << " " << "__SIZEMAP_BEGIN__";
406 for ( ; it_sm != _sizeMap.end(); ++it_sm ) {
407 save << " " << it_sm->first
408 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
410 save << " " << "__SIZEMAP_END__";
417 //=============================================================================
418 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
426 _topology = (Topology) i;
428 load.clear(std::ios::badbit | load.rdstate());
432 _physicalMesh = (PhysicalMesh) i;
434 load.clear(std::ios::badbit | load.rdstate());
438 _geometricMesh = (GeometricMesh) i;
440 load.clear(std::ios::badbit | load.rdstate());
442 isOK = (load >> val);
446 load.clear(std::ios::badbit | load.rdstate());
448 isOK = (load >> val);
452 load.clear(std::ios::badbit | load.rdstate());
454 isOK = (load >> val);
458 load.clear(std::ios::badbit | load.rdstate());
462 _quadAllowed = (bool) i;
464 load.clear(std::ios::badbit | load.rdstate());
468 _decimesh = (bool) i;
470 load.clear(std::ios::badbit | load.rdstate());
472 isOK = (load >> val);
476 load.clear(std::ios::badbit | load.rdstate());
478 isOK = (load >> val);
482 load.clear(std::ios::badbit | load.rdstate());
484 isOK = (load >> val);
488 load.clear(std::ios::badbit | load.rdstate());
490 isOK = (load >> val);
494 load.clear(std::ios::badbit | load.rdstate());
496 isOK = (load >> val);
500 load.clear(std::ios::badbit | load.rdstate());
506 load.clear(std::ios::badbit | load.rdstate());
508 std::string option_or_sm;
509 bool hasOptions = false;
510 bool hasSizeMap = false;
512 isOK = (load >> option_or_sm);
514 if (option_or_sm == "__OPTIONS_BEGIN__")
516 else if (option_or_sm == "__SIZEMAP_BEGIN__")
519 std::string optName, optValue;
520 while (isOK && hasOptions) {
521 isOK = (load >> optName);
523 if (optName == "__OPTIONS_END__")
525 isOK = (load >> optValue);
528 std::string & value = _option2value[ optName ];
530 int len = value.size();
531 // continue reading until "%#" encountered
532 while ( value[len-1] != '#' || value[len-2] != '%' )
534 isOK = (load >> optValue);
544 value[ len-2 ] = '\0'; //cut off "%#"
549 isOK = (load >> option_or_sm);
550 if (isOK && option_or_sm == "__SIZEMAP_BEGIN__")
554 std::string smEntry, smValue;
555 while (isOK && hasSizeMap) {
556 isOK = (load >> smEntry);
558 if (smEntry == "__SIZEMAP_END__")
560 isOK = (load >> smValue);
563 std::string & value2 = _sizeMap[ smEntry ];
565 int len2= value2.size();
566 // continue reading until "%#" encountered
567 while ( value2[len2-1] != '#' || value2[len2-2] != '%' )
569 isOK = (load >> smValue);
573 len2 = value2.size();
579 value2[ len2-2 ] = '\0'; //cut off "%#"
586 //=============================================================================
587 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp)
589 return hyp.SaveTo( save );
592 //=============================================================================
593 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp)
595 return hyp.LoadFrom( load );
598 //================================================================================
600 * \brief Does nothing
602 //================================================================================
604 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
605 const TopoDS_Shape& theShape)
610 //=============================================================================
612 * \brief Initialize my parameter values by default parameters.
613 * \retval bool - true if parameter values have been successfully defined
615 //=============================================================================
617 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
618 const SMESH_Mesh* theMesh)
620 return bool( _phySize = dflts._elemLength );
623 //=============================================================================
624 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
629 //=============================================================================
630 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
632 return PhysicalUserDefined;
635 //=============================================================================
636 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
641 //======================================================================
642 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
644 return undefinedDouble(); // 1e+4;
647 //======================================================================
648 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
650 return undefinedDouble(); //1e-4;
653 //======================================================================
654 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
659 //=============================================================================
660 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
665 //=============================================================================
666 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
671 //=============================================================================
672 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
677 //=============================================================================
678 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()