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();
147 _gradation = GetDefaultGradation();
150 NotifySubMeshesHypothesisModification();
154 //=============================================================================
155 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
157 if (theVal != _phySize) {
159 NotifySubMeshesHypothesisModification();
163 //=============================================================================
164 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
166 if (theMinSize != _phyMin) {
167 _phyMin = theMinSize;
168 NotifySubMeshesHypothesisModification();
172 //=============================================================================
173 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
175 if (theMaxSize != _phyMax) {
176 _phyMax = theMaxSize;
177 NotifySubMeshesHypothesisModification();
182 //=============================================================================
183 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
185 if (theMinSize != _hgeoMin) {
186 _hgeoMin = theMinSize;
187 NotifySubMeshesHypothesisModification();
191 //=============================================================================
192 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
194 if (theMaxSize != _hgeoMax) {
195 _hgeoMax = theMaxSize;
196 NotifySubMeshesHypothesisModification();
200 //=============================================================================
201 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
203 if (theGeometricMesh != _geometricMesh) {
204 _geometricMesh = theGeometricMesh;
205 switch( _geometricMesh ) {
208 _angleMeshS = GetDefaultAngleMeshS();
209 _gradation = GetDefaultGradation();
212 NotifySubMeshesHypothesisModification();
216 //=============================================================================
217 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
219 if (theVal != _angleMeshS) {
220 _angleMeshS = theVal;
221 NotifySubMeshesHypothesisModification();
225 //=============================================================================
226 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
228 if (theVal != _angleMeshC) {
229 _angleMeshC = theVal;
230 NotifySubMeshesHypothesisModification();
234 //=============================================================================
235 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
237 if (theVal != _gradation) {
239 NotifySubMeshesHypothesisModification();
243 //=============================================================================
244 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
246 if (theVal != _quadAllowed) {
247 _quadAllowed = theVal;
248 NotifySubMeshesHypothesisModification();
252 //=============================================================================
253 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
255 if (theVal != _decimesh) {
257 NotifySubMeshesHypothesisModification();
261 //=============================================================================
262 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
264 if (theVal != _verb) {
266 NotifySubMeshesHypothesisModification();
269 //=============================================================================
270 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
271 const std::string& optionValue)
272 throw (std::invalid_argument)
274 TOptionValues::iterator op_val = _option2value.find( optionName );
275 if ( op_val == _option2value.end() ) {
276 std::string msg = "Unknown BLSURF option: '" + optionName + "'";
277 throw std::invalid_argument(msg);
279 if ( op_val->second != optionValue ) {
280 const char* ptr = optionValue.c_str();
281 // strip white spaces
282 while ( ptr[0] == ' ' )
284 int i = strlen( ptr );
285 while ( i != 0 && ptr[i-1] == ' ')
289 std::string typeName;
293 else if ( _charOptions.find( optionName ) != _charOptions.end() ) {
294 // do not check strings
296 else if ( _doubleOptions.find( optionName ) != _doubleOptions.end() ) {
297 // check if value is double
299 strtod(ptr, &endPtr);
300 typeOk = ( ptr != endPtr );
304 // check if value is int
306 strtol(ptr, &endPtr,10);
307 typeOk = ( ptr != endPtr );
308 typeName = "integer";
311 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue +
312 "' but must be " + typeName;
313 throw std::invalid_argument(msg);
315 op_val->second = optionValue;
316 NotifySubMeshesHypothesisModification();
320 //=============================================================================
321 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName)
322 throw (std::invalid_argument)
324 TOptionValues::iterator op_val = _option2value.find( optionName );
325 if ( op_val == _option2value.end() ) {
326 std::string msg = "Unknown BLSURF option: <";
327 msg += optionName + ">";
328 throw std::invalid_argument(msg);
330 return op_val->second;
333 //=============================================================================
334 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
336 TOptionValues::iterator op_val = _option2value.find( optionName );
337 if ( op_val != _option2value.end() )
338 op_val->second.clear();
342 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry,const std::string& sizeMap)
344 if (_sizeMap[entry].compare(sizeMap) != 0) {
345 _sizeMap[entry]=sizeMap;
346 NotifySubMeshesHypothesisModification();
350 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry)
352 TSizeMap::iterator it = _sizeMap.find( entry );
353 if ( it != _sizeMap.end() )
356 return "No_Such_Entry";
359 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry,const std::string& attractor)
361 if (_attractors[entry].compare(attractor) != 0) {
362 _attractors[entry]=attractor;
363 NotifySubMeshesHypothesisModification();
367 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry)
369 TSizeMap::iterator it = _attractors.find( entry );
370 if ( it != _attractors.end() )
373 return "No_Such_Entry";
377 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
379 TSizeMap::iterator it = _sizeMap.find( entry );
380 if ( it != _sizeMap.end() ) {
382 NotifySubMeshesHypothesisModification();
385 TSizeMap::iterator itAt = _attractors.find( entry );
386 if ( itAt != _attractors.end() ) {
387 _attractors.erase(itAt);
388 NotifySubMeshesHypothesisModification();
391 std::cout<<"No_Such_Entry"<<std::endl;
396 void BLSURFPlugin_Hypothesis::ClearSizeMaps()
404 //=============================================================================
405 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
407 save << " " << (int)_topology
408 << " " << (int)_physicalMesh
409 << " " << (int)_geometricMesh
411 << " " << _angleMeshS
413 << " " << (int)_quadAllowed
414 << " " << (int)_decimesh;
415 save << " " << _phyMin
417 << " " << _angleMeshC
422 TOptionValues::iterator op_val = _option2value.begin();
423 if (op_val != _option2value.end()) {
424 save << " " << "__OPTIONS_BEGIN__";
425 for ( ; op_val != _option2value.end(); ++op_val ) {
426 if ( !op_val->second.empty() )
427 save << " " << op_val->first
428 << " " << op_val->second << "%#"; // "%#" is a mark of value end
430 save << " " << "__OPTIONS_END__";
433 TSizeMap::iterator it_sm = _sizeMap.begin();
434 if (it_sm != _sizeMap.end()) {
435 save << " " << "__SIZEMAP_BEGIN__";
436 for ( ; it_sm != _sizeMap.end(); ++it_sm ) {
437 save << " " << it_sm->first
438 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
440 save << " " << "__SIZEMAP_END__";
443 TSizeMap::iterator it_at = _attractors.begin();
444 if (it_at != _attractors.end()) {
445 save << " " << "__ATTRACTORS_BEGIN__";
446 for ( ; it_at != _attractors.end(); ++it_at ) {
447 save << " " << it_at->first
448 << " " << it_at->second << "%#"; // "%#" is a mark of value end
450 save << " " << "__ATTRACTORS_END__";
457 //=============================================================================
458 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
466 _topology = (Topology) i;
468 load.clear(std::ios::badbit | load.rdstate());
472 _physicalMesh = (PhysicalMesh) i;
474 load.clear(std::ios::badbit | load.rdstate());
478 _geometricMesh = (GeometricMesh) i;
480 load.clear(std::ios::badbit | load.rdstate());
482 isOK = (load >> val);
486 load.clear(std::ios::badbit | load.rdstate());
488 isOK = (load >> val);
492 load.clear(std::ios::badbit | load.rdstate());
494 isOK = (load >> val);
498 load.clear(std::ios::badbit | load.rdstate());
502 _quadAllowed = (bool) i;
504 load.clear(std::ios::badbit | load.rdstate());
508 _decimesh = (bool) i;
510 load.clear(std::ios::badbit | load.rdstate());
512 isOK = (load >> val);
516 load.clear(std::ios::badbit | load.rdstate());
518 isOK = (load >> val);
522 load.clear(std::ios::badbit | load.rdstate());
524 isOK = (load >> val);
528 load.clear(std::ios::badbit | load.rdstate());
530 isOK = (load >> val);
534 load.clear(std::ios::badbit | load.rdstate());
536 isOK = (load >> val);
540 load.clear(std::ios::badbit | load.rdstate());
546 load.clear(std::ios::badbit | load.rdstate());
548 std::string option_or_sm;
549 bool hasOptions = false;
550 bool hasSizeMap = false;
551 bool hasAttractor = false;
553 isOK = (load >> option_or_sm);
555 if (option_or_sm == "__OPTIONS_BEGIN__")
557 else if (option_or_sm == "__SIZEMAP_BEGIN__")
559 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
562 std::string optName, optValue;
563 while (isOK && hasOptions) {
564 isOK = (load >> optName);
566 if (optName == "__OPTIONS_END__")
568 isOK = (load >> optValue);
571 std::string & value = _option2value[ optName ];
573 int len = value.size();
574 // continue reading until "%#" encountered
575 while ( value[len-1] != '#' || value[len-2] != '%' )
577 isOK = (load >> optValue);
587 value[ len-2 ] = '\0'; //cut off "%#"
592 isOK = (load >> option_or_sm);
594 if (option_or_sm == "__SIZEMAP_BEGIN__")
596 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
600 std::string smEntry, smValue;
601 while (isOK && hasSizeMap) {
602 isOK = (load >> smEntry);
604 if (smEntry == "__SIZEMAP_END__")
606 isOK = (load >> smValue);
609 std::string & value2 = _sizeMap[ smEntry ];
611 int len2= value2.size();
612 // continue reading until "%#" encountered
613 while ( value2[len2-1] != '#' || value2[len2-2] != '%' )
615 isOK = (load >> smValue);
619 len2 = value2.size();
625 value2[ len2-2 ] = '\0'; //cut off "%#"
630 isOK = (load >> option_or_sm);
631 if (isOK && option_or_sm == "__ATTRACTORS_BEGIN__")
635 std::string atEntry, atValue;
636 while (isOK && hasAttractor) {
637 isOK = (load >> atEntry);
639 if (atEntry == "__ATTRACTORS_END__")
641 isOK = (load >> atValue);
644 std::string & value3 = _attractors[ atEntry ];
646 int len3= value3.size();
647 // continue reading until "%#" encountered
648 while ( value3[len3-1] != '#' || value3[len3-2] != '%' )
650 isOK = (load >> atValue);
654 len3 = value3.size();
660 value3[ len3-2 ] = '\0'; //cut off "%#"
667 //=============================================================================
668 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp)
670 return hyp.SaveTo( save );
673 //=============================================================================
674 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp)
676 return hyp.LoadFrom( load );
679 //================================================================================
681 * \brief Does nothing
683 //================================================================================
685 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
686 const TopoDS_Shape& theShape)
691 //=============================================================================
693 * \brief Initialize my parameter values by default parameters.
694 * \retval bool - true if parameter values have been successfully defined
696 //=============================================================================
698 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
699 const SMESH_Mesh* theMesh)
701 return bool( _phySize = dflts._elemLength );
704 //=============================================================================
705 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
710 //=============================================================================
711 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
713 return PhysicalUserDefined;
716 //=============================================================================
717 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
722 //======================================================================
723 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
725 return undefinedDouble(); // 1e+4;
728 //======================================================================
729 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
731 return undefinedDouble(); //1e-4;
734 //======================================================================
735 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
740 //=============================================================================
741 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
746 //=============================================================================
747 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
752 //=============================================================================
753 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
758 //=============================================================================
759 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()