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)
23 // Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
26 #include "BLSURFPlugin_Hypothesis.hxx"
27 #include <utilities.h>
30 //=============================================================================
31 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
33 : SMESH_Hypothesis(hypId, studyId, gen),
34 _topology(GetDefaultTopology()),
35 _physicalMesh(GetDefaultPhysicalMesh()),
36 _phySize(GetDefaultPhySize()),
37 _phyMax(GetDefaultMaxSize()),
38 _phyMin(GetDefaultMinSize()),
39 _hgeoMax(GetDefaultMaxSize()),
40 _hgeoMin(GetDefaultMinSize()),
41 _geometricMesh(GetDefaultGeometricMesh()),
42 _angleMeshS(GetDefaultAngleMeshS()),
43 _angleMeshC(GetDefaultAngleMeshC()),
44 _gradation(GetDefaultGradation()),
45 _quadAllowed(GetDefaultQuadAllowed()),
46 _decimesh(GetDefaultDecimesh()),
47 _verb( GetDefaultVerbosity() )
49 _name = "BLSURF_Parameters";
52 // to desable writing boundaries
53 //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
56 const char* intOptionNames[] = {
85 const char* doubleOptionNames[] = {
103 const char* charOptionNames[] = {
112 while ( intOptionNames[i][0] )
113 _option2value[ intOptionNames[i++] ].clear();
116 while ( doubleOptionNames[i][0] ) {
117 _doubleOptions.insert( doubleOptionNames[i] );
118 _option2value[ doubleOptionNames[i++] ].clear();
121 while ( charOptionNames[i][0] ) {
122 _charOptions.insert( charOptionNames[i] );
123 _option2value[ charOptionNames[i++] ].clear();
129 //=============================================================================
130 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
132 if (theTopology != _topology) {
133 _topology = theTopology;
134 NotifySubMeshesHypothesisModification();
138 //=============================================================================
139 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
141 if (thePhysicalMesh != _physicalMesh) {
142 _physicalMesh = thePhysicalMesh;
143 switch( _physicalMesh ) {
146 _phySize = GetDefaultPhySize();
149 NotifySubMeshesHypothesisModification();
153 //=============================================================================
154 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
156 if (theVal != _phySize) {
158 NotifySubMeshesHypothesisModification();
162 //=============================================================================
163 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
165 if (theMinSize != _phyMin) {
166 _phyMin = theMinSize;
167 NotifySubMeshesHypothesisModification();
171 //=============================================================================
172 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
174 if (theMaxSize != _phyMax) {
175 _phyMax = theMaxSize;
176 NotifySubMeshesHypothesisModification();
181 //=============================================================================
182 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
184 if (theMinSize != _hgeoMin) {
185 _hgeoMin = theMinSize;
186 NotifySubMeshesHypothesisModification();
190 //=============================================================================
191 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
193 if (theMaxSize != _hgeoMax) {
194 _hgeoMax = theMaxSize;
195 NotifySubMeshesHypothesisModification();
199 //=============================================================================
200 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
202 if (theGeometricMesh != _geometricMesh) {
203 _geometricMesh = theGeometricMesh;
204 switch( _geometricMesh ) {
207 _angleMeshS = GetDefaultAngleMeshS();
208 _gradation = GetDefaultGradation();
211 NotifySubMeshesHypothesisModification();
215 //=============================================================================
216 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
218 if (theVal != _angleMeshS) {
219 _angleMeshS = theVal;
220 NotifySubMeshesHypothesisModification();
224 //=============================================================================
225 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
227 if (theVal != _angleMeshC) {
228 _angleMeshC = theVal;
229 NotifySubMeshesHypothesisModification();
233 //=============================================================================
234 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
236 if (theVal != _gradation) {
238 NotifySubMeshesHypothesisModification();
242 //=============================================================================
243 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
245 if (theVal != _quadAllowed) {
246 _quadAllowed = theVal;
247 NotifySubMeshesHypothesisModification();
251 //=============================================================================
252 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
254 if (theVal != _decimesh) {
256 NotifySubMeshesHypothesisModification();
260 //=============================================================================
261 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
263 if (theVal != _verb) {
265 NotifySubMeshesHypothesisModification();
268 //=============================================================================
269 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
270 const std::string& optionValue)
271 throw (std::invalid_argument)
273 TOptionValues::iterator op_val = _option2value.find( optionName );
274 if ( op_val == _option2value.end() ) {
275 std::string msg = "Unknown BLSURF option: '" + optionName + "'";
276 throw std::invalid_argument(msg);
278 if ( op_val->second != optionValue ) {
279 const char* ptr = optionValue.c_str();
280 // strip white spaces
281 while ( ptr[0] == ' ' )
283 int i = strlen( ptr );
284 while ( i != 0 && ptr[i-1] == ' ')
288 std::string typeName;
292 else if ( _charOptions.find( optionName ) != _charOptions.end() ) {
293 // do not check strings
295 else if ( _doubleOptions.find( optionName ) != _doubleOptions.end() ) {
296 // check if value is double
298 strtod(ptr, &endPtr);
299 typeOk = ( ptr != endPtr );
303 // check if value is int
305 strtol(ptr, &endPtr,10);
306 typeOk = ( ptr != endPtr );
307 typeName = "integer";
310 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue +
311 "' but must be " + typeName;
312 throw std::invalid_argument(msg);
314 op_val->second = optionValue;
315 NotifySubMeshesHypothesisModification();
319 //=============================================================================
320 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName)
321 throw (std::invalid_argument)
323 TOptionValues::iterator op_val = _option2value.find( optionName );
324 if ( op_val == _option2value.end() ) {
325 std::string msg = "Unknown BLSURF option: <";
326 msg += optionName + ">";
327 throw std::invalid_argument(msg);
329 return op_val->second;
332 //=============================================================================
333 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
335 TOptionValues::iterator op_val = _option2value.find( optionName );
336 if ( op_val != _option2value.end() )
337 op_val->second.clear();
341 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry,const std::string& sizeMap)
343 if (_sizeMap[entry].compare(sizeMap) != 0) {
344 _sizeMap[entry]=sizeMap;
345 NotifySubMeshesHypothesisModification();
349 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry)
351 TSizeMap::iterator it = _sizeMap.find( entry );
352 if ( it != _sizeMap.end() )
355 return "No_Such_Entry";
358 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry,const std::string& attractor)
360 if (_attractors[entry].compare(attractor) != 0) {
361 _attractors[entry]=attractor;
362 NotifySubMeshesHypothesisModification();
366 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry)
368 TSizeMap::iterator it = _attractors.find( entry );
369 if ( it != _attractors.end() )
372 return "No_Such_Entry";
376 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
378 TSizeMap::iterator it = _sizeMap.find( entry );
379 if ( it != _sizeMap.end() ) {
381 NotifySubMeshesHypothesisModification();
384 TSizeMap::iterator itAt = _attractors.find( entry );
385 if ( itAt != _attractors.end() ) {
386 _attractors.erase(itAt);
387 NotifySubMeshesHypothesisModification();
390 std::cout<<"No_Such_Entry"<<std::endl;
395 void BLSURFPlugin_Hypothesis::ClearSizeMaps()
403 //=============================================================================
404 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
406 save << " " << (int)_topology
407 << " " << (int)_physicalMesh
408 << " " << (int)_geometricMesh
410 << " " << _angleMeshS
412 << " " << (int)_quadAllowed
413 << " " << (int)_decimesh;
414 save << " " << _phyMin
416 << " " << _angleMeshC
421 TOptionValues::iterator op_val = _option2value.begin();
422 if (op_val != _option2value.end()) {
423 save << " " << "__OPTIONS_BEGIN__";
424 for ( ; op_val != _option2value.end(); ++op_val ) {
425 if ( !op_val->second.empty() )
426 save << " " << op_val->first
427 << " " << op_val->second << "%#"; // "%#" is a mark of value end
429 save << " " << "__OPTIONS_END__";
432 TSizeMap::iterator it_sm = _sizeMap.begin();
433 if (it_sm != _sizeMap.end()) {
434 save << " " << "__SIZEMAP_BEGIN__";
435 for ( ; it_sm != _sizeMap.end(); ++it_sm ) {
436 save << " " << it_sm->first
437 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
439 save << " " << "__SIZEMAP_END__";
442 TSizeMap::iterator it_at = _attractors.begin();
443 if (it_at != _attractors.end()) {
444 save << " " << "__ATTRACTORS_BEGIN__";
445 for ( ; it_at != _attractors.end(); ++it_at ) {
446 save << " " << it_at->first
447 << " " << it_at->second << "%#"; // "%#" is a mark of value end
449 save << " " << "__ATTRACTORS_END__";
456 //=============================================================================
457 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
465 _topology = (Topology) i;
467 load.clear(std::ios::badbit | load.rdstate());
471 _physicalMesh = (PhysicalMesh) i;
473 load.clear(std::ios::badbit | load.rdstate());
477 _geometricMesh = (GeometricMesh) i;
479 load.clear(std::ios::badbit | load.rdstate());
481 isOK = (load >> val);
485 load.clear(std::ios::badbit | load.rdstate());
487 isOK = (load >> val);
491 load.clear(std::ios::badbit | load.rdstate());
493 isOK = (load >> val);
497 load.clear(std::ios::badbit | load.rdstate());
501 _quadAllowed = (bool) i;
503 load.clear(std::ios::badbit | load.rdstate());
507 _decimesh = (bool) i;
509 load.clear(std::ios::badbit | load.rdstate());
511 isOK = (load >> val);
515 load.clear(std::ios::badbit | load.rdstate());
517 isOK = (load >> val);
521 load.clear(std::ios::badbit | load.rdstate());
523 isOK = (load >> val);
527 load.clear(std::ios::badbit | load.rdstate());
529 isOK = (load >> val);
533 load.clear(std::ios::badbit | load.rdstate());
535 isOK = (load >> val);
539 load.clear(std::ios::badbit | load.rdstate());
545 load.clear(std::ios::badbit | load.rdstate());
547 std::string option_or_sm;
548 bool hasOptions = false;
549 bool hasSizeMap = false;
550 bool hasAttractor = false;
552 isOK = (load >> option_or_sm);
554 if (option_or_sm == "__OPTIONS_BEGIN__")
556 else if (option_or_sm == "__SIZEMAP_BEGIN__")
558 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
561 std::string optName, optValue;
562 while (isOK && hasOptions) {
563 isOK = (load >> optName);
565 if (optName == "__OPTIONS_END__")
567 isOK = (load >> optValue);
570 std::string & value = _option2value[ optName ];
572 int len = value.size();
573 // continue reading until "%#" encountered
574 while ( value[len-1] != '#' || value[len-2] != '%' )
576 isOK = (load >> optValue);
586 value[ len-2 ] = '\0'; //cut off "%#"
591 isOK = (load >> option_or_sm);
593 if (option_or_sm == "__SIZEMAP_BEGIN__")
595 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
599 std::string smEntry, smValue;
600 while (isOK && hasSizeMap) {
601 isOK = (load >> smEntry);
603 if (smEntry == "__SIZEMAP_END__")
605 isOK = (load >> smValue);
608 std::string & value2 = _sizeMap[ smEntry ];
610 int len2= value2.size();
611 // continue reading until "%#" encountered
612 while ( value2[len2-1] != '#' || value2[len2-2] != '%' )
614 isOK = (load >> smValue);
618 len2 = value2.size();
624 value2[ len2-2 ] = '\0'; //cut off "%#"
629 isOK = (load >> option_or_sm);
630 if (isOK && option_or_sm == "__ATTRACTORS_BEGIN__")
634 std::string atEntry, atValue;
635 while (isOK && hasAttractor) {
636 isOK = (load >> atEntry);
638 if (atEntry == "__ATTRACTORS_END__")
640 isOK = (load >> atValue);
643 std::string & value3 = _attractors[ atEntry ];
645 int len3= value3.size();
646 // continue reading until "%#" encountered
647 while ( value3[len3-1] != '#' || value3[len3-2] != '%' )
649 isOK = (load >> atValue);
653 len3 = value3.size();
659 value3[ len3-2 ] = '\0'; //cut off "%#"
666 //=============================================================================
667 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp)
669 return hyp.SaveTo( save );
672 //=============================================================================
673 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp)
675 return hyp.LoadFrom( load );
678 //================================================================================
680 * \brief Does nothing
682 //================================================================================
684 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
685 const TopoDS_Shape& theShape)
690 //=============================================================================
692 * \brief Initialize my parameter values by default parameters.
693 * \retval bool - true if parameter values have been successfully defined
695 //=============================================================================
697 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
698 const SMESH_Mesh* theMesh)
700 return bool( _phySize = dflts._elemLength );
703 //=============================================================================
704 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
709 //=============================================================================
710 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
712 return PhysicalUserDefined;
715 //=============================================================================
716 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
721 //======================================================================
722 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
724 return undefinedDouble(); // 1e+4;
727 //======================================================================
728 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
730 return undefinedDouble(); //1e-4;
733 //======================================================================
734 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
739 //=============================================================================
740 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
745 //=============================================================================
746 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
751 //=============================================================================
752 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
757 //=============================================================================
758 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()