Salome HOME
Remove unnecessary print text
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // ---
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)
24 // ---
25 //
26 #include "BLSURFPlugin_Hypothesis.hxx"
27 #include <utilities.h>
28 #include <cstring>
29 #include <iostream>
30 #include <sstream>
31
32 //=============================================================================
33 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
34                                                   SMESH_Gen * gen)
35   : SMESH_Hypothesis(hypId, studyId, gen),
36     _topology(GetDefaultTopology()),
37     _physicalMesh(GetDefaultPhysicalMesh()),
38     _phySize(GetDefaultPhySize()),
39     _phyMax(GetDefaultMaxSize()),
40     _phyMin(GetDefaultMinSize()),
41     _hgeoMax(GetDefaultMaxSize()),
42     _hgeoMin(GetDefaultMinSize()),
43     _geometricMesh(GetDefaultGeometricMesh()),
44     _angleMeshS(GetDefaultAngleMeshS()),
45     _angleMeshC(GetDefaultAngleMeshC()),
46     _gradation(GetDefaultGradation()),
47     _quadAllowed(GetDefaultQuadAllowed()),
48     _decimesh(GetDefaultDecimesh()),
49     _verb( GetDefaultVerbosity() ),
50     _sizeMap(GetDefaultSizeMap()),
51     _attractors(GetDefaultSizeMap()),
52     _enforcedVertices(GetDefaultEnforcedVertexMap())
53 {
54   _name = "BLSURF_Parameters";
55   _param_algo_dim = 2;
56
57   // to desable writing boundaries
58   //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
59
60
61   const char* intOptionNames[] = {
62     "addsurf_ivertex",
63     "background",
64     "CheckAdjacentEdges",
65     "CheckCloseEdges",
66     "CheckWellDefined",
67     "coiter",
68     "communication",
69     "decim",
70     "export_flag",
71     "file_h",
72     "frontal",
73     "gridnu",
74     "gridnv",
75     "hinterpol_flag",
76     "hmean_flag",
77     "intermedfile",
78     "memory",
79     "normals",
80     "optim",
81     "pardom_flag",
82     "pinch",
83     "refs",
84     "rigid",
85     "surforient",
86     "tconf",
87     "topo_collapse",
88     "" // mark of end
89   };
90   const char* doubleOptionNames[] = {
91     "addsurf_angle",
92     "addsurf_R",
93     "addsurf_H",
94     "addsurf_FG",
95     "addsurf_r",
96     "addsurf_PA",
97     "angle_compcurv",
98     "angle_ridge",
99     "CoefRectangle",
100     "eps_collapse",
101     "eps_ends",
102     "eps_pardom",
103     "LSS",
104     "topo_eps1",
105     "topo_eps2",
106     "" // mark of end
107   };
108   const char* charOptionNames[] = {
109     "export_format",
110     "export_option",
111     "import_option",
112     "prefix",
113     "" // mark of end
114   };
115
116   int i = 0;
117   while ( intOptionNames[i][0] )
118     _option2value[ intOptionNames[i++] ].clear();
119
120   i = 0;
121   while ( doubleOptionNames[i][0] ) {
122     _doubleOptions.insert( doubleOptionNames[i] );
123     _option2value[ doubleOptionNames[i++] ].clear();
124   }
125   i = 0;
126   while ( charOptionNames[i][0] ) {
127     _charOptions.insert( charOptionNames[i] );
128     _option2value[ charOptionNames[i++] ].clear();
129   }
130
131   _sizeMap.clear();
132 }
133
134 //=============================================================================
135 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
136 {
137   if (theTopology != _topology) {
138     _topology = theTopology;
139     NotifySubMeshesHypothesisModification();
140   }
141 }
142
143 //=============================================================================
144 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
145 {
146   if (thePhysicalMesh != _physicalMesh) {
147     _physicalMesh = thePhysicalMesh;
148     switch( _physicalMesh ) {
149       case DefaultSize:
150       default:
151         _phySize = GetDefaultPhySize();
152         _gradation  = GetDefaultGradation();
153         break;
154       }
155     NotifySubMeshesHypothesisModification();
156   }
157 }
158
159 //=============================================================================
160 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
161 {
162   if (theVal != _phySize) {
163     _phySize = theVal;
164     NotifySubMeshesHypothesisModification();
165   }
166 }
167
168 //=============================================================================
169 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
170 {
171   if (theMinSize != _phyMin) {
172     _phyMin = theMinSize;
173     NotifySubMeshesHypothesisModification();
174   }
175 }
176
177 //=============================================================================
178 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
179 {
180   if (theMaxSize != _phyMax) {
181     _phyMax = theMaxSize;
182     NotifySubMeshesHypothesisModification();
183   }
184 }
185
186
187 //=============================================================================
188 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
189 {
190   if (theMinSize != _hgeoMin) {
191     _hgeoMin = theMinSize;
192     NotifySubMeshesHypothesisModification();
193   }
194 }
195
196 //=============================================================================
197 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
198 {
199   if (theMaxSize != _hgeoMax) {
200     _hgeoMax = theMaxSize;
201     NotifySubMeshesHypothesisModification();
202   }
203 }
204
205 //=============================================================================
206 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
207 {
208   if (theGeometricMesh != _geometricMesh) {
209     _geometricMesh = theGeometricMesh;
210     switch( _geometricMesh ) {
211       case DefaultGeom:
212       default:
213         _angleMeshS = GetDefaultAngleMeshS();
214         _gradation  = GetDefaultGradation();
215         break;
216       }
217     NotifySubMeshesHypothesisModification();
218   }
219 }
220
221 //=============================================================================
222 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
223 {
224   if (theVal != _angleMeshS) {
225     _angleMeshS = theVal;
226     NotifySubMeshesHypothesisModification();
227   }
228 }
229
230 //=============================================================================
231 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
232 {
233   if (theVal != _angleMeshC) {
234     _angleMeshC = theVal;
235     NotifySubMeshesHypothesisModification();
236   }
237 }
238
239 //=============================================================================
240 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
241 {
242   if (theVal != _gradation) {
243     _gradation = theVal;
244     NotifySubMeshesHypothesisModification();
245   }
246 }
247
248 //=============================================================================
249 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
250 {
251   if (theVal != _quadAllowed) {
252     _quadAllowed = theVal;
253     NotifySubMeshesHypothesisModification();
254   }
255 }
256
257 //=============================================================================
258 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
259 {
260   if (theVal != _decimesh) {
261     _decimesh = theVal;
262     NotifySubMeshesHypothesisModification();
263   }
264 }
265
266 //=============================================================================
267 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
268 {
269   if (theVal != _verb) {
270     _verb = theVal;
271     NotifySubMeshesHypothesisModification();
272   }
273 }
274 //=============================================================================
275 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
276                                              const std::string& optionValue)
277   throw (std::invalid_argument)
278 {
279   TOptionValues::iterator op_val = _option2value.find( optionName );
280   if ( op_val == _option2value.end() ) {
281     std::string msg = "Unknown BLSURF option: '" + optionName + "'";
282     throw std::invalid_argument(msg);
283   }
284   if ( op_val->second != optionValue ) {
285     const char* ptr = optionValue.c_str();
286     // strip white spaces
287     while ( ptr[0] == ' ' )
288       ptr++;
289     int i = strlen( ptr );
290     while ( i != 0 && ptr[i-1] == ' ')
291       i--;
292     // check value type
293     bool typeOk = true;
294     std::string typeName;
295     if ( i == 0 ) {
296       // empty string
297     }
298     else if ( _charOptions.find( optionName ) != _charOptions.end() ) {
299       // do not check strings
300     }
301     else if ( _doubleOptions.find( optionName ) != _doubleOptions.end() ) {
302       // check if value is double
303       char * endPtr;
304       strtod(ptr, &endPtr);
305       typeOk = ( ptr != endPtr );
306       typeName = "real";
307     }
308     else {
309       // check if value is int
310       char * endPtr;
311       strtol(ptr, &endPtr,10);
312       typeOk = ( ptr != endPtr );
313       typeName = "integer";
314     }
315     if ( !typeOk ) {
316       std::string msg = "Advanced option '" + optionName + "' = '" + optionValue +
317         "' but must be " + typeName;
318       throw std::invalid_argument(msg);
319     }
320     op_val->second = optionValue;
321     NotifySubMeshesHypothesisModification();
322   }
323 }
324
325 //=============================================================================
326 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName)
327   throw (std::invalid_argument)
328 {
329   TOptionValues::iterator op_val = _option2value.find( optionName );
330   if ( op_val == _option2value.end() ) {
331     std::string msg = "Unknown BLSURF option: <";
332     msg += optionName + ">";
333     throw std::invalid_argument(msg);
334   }
335   return op_val->second;
336 }
337
338 //=============================================================================
339 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
340 {
341   TOptionValues::iterator op_val = _option2value.find( optionName );
342   if ( op_val != _option2value.end() )
343     op_val->second.clear();
344 }
345
346 //=======================================================================
347 //function : SetSizeMapEntry
348 //=======================================================================
349 void  BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry,const std::string& sizeMap)
350 {
351   if (_sizeMap[entry].compare(sizeMap) != 0) {
352     _sizeMap[entry]=sizeMap;
353     NotifySubMeshesHypothesisModification();
354   }
355 }
356
357 //=======================================================================
358 //function : GetSizeMapEntry
359 //=======================================================================
360 std::string  BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry)
361 {
362  TSizeMap::iterator it  = _sizeMap.find( entry );
363  if ( it != _sizeMap.end() )
364    return it->second;
365  else
366    return "No_Such_Entry";
367 }
368
369   /*!
370    * \brief Return the size maps
371    */
372 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp)
373 {
374     return hyp ? hyp->_GetSizeMapEntries():GetDefaultSizeMap();
375 }
376
377 //=======================================================================
378 //function : SetAttractorEntry
379 //=======================================================================
380 void  BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry,const std::string& attractor)
381 {
382   if (_attractors[entry].compare(attractor) != 0) {
383     _attractors[entry]=attractor;
384     NotifySubMeshesHypothesisModification();
385   }
386 }
387
388 //=======================================================================
389 //function : GetAttractorEntry
390 //=======================================================================
391 std::string  BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry)
392 {
393  TSizeMap::iterator it  = _attractors.find( entry );
394  if ( it != _attractors.end() )
395    return it->second;
396  else
397    return "No_Such_Entry";
398 }
399
400   /*!
401    * \brief Return the attractors
402    */
403 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
404 {
405     return hyp ? hyp->_GetAttractorEntries():GetDefaultSizeMap();
406 }
407
408
409
410 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
411 {
412  TSizeMap::iterator it  = _sizeMap.find( entry );
413  if ( it != _sizeMap.end() ) {
414    _sizeMap.erase(it);
415    NotifySubMeshesHypothesisModification();
416  }
417  else {
418    TSizeMap::iterator itAt  = _attractors.find( entry );
419    if ( itAt != _attractors.end() ) {
420      _attractors.erase(itAt);
421      NotifySubMeshesHypothesisModification();
422    }
423    else
424      std::cout<<"No_Such_Entry"<<std::endl;
425  }
426 }
427
428
429 void BLSURFPlugin_Hypothesis::ClearSizeMaps()
430 {
431   _sizeMap.clear();
432   _attractors.clear();
433 }
434
435
436
437 //=======================================================================
438 //function : SetEnforcedVertex
439 //=======================================================================
440
441 void BLSURFPlugin_Hypothesis::SetEnforcedVertex(const std::string& entry, double x, double y, double z)
442 {
443   BLSURFPlugin_Hypothesis::TEnforcedVertex coord;
444   coord.push_back(x);
445   coord.push_back(y);
446   coord.push_back(z);
447   bool toNotify = false;
448   if (_enforcedVertices.count(entry)>0)
449     if (_enforcedVertices[entry].count(coord)==0)
450       toNotify = true;
451   else
452     toNotify = true;
453   
454   _enforcedVertices[entry].insert(coord);
455   if (toNotify)
456     NotifySubMeshesHypothesisModification();
457 }
458
459 /*
460 //=======================================================================
461 //function : SetEnforcedVertexList
462 //=======================================================================
463
464 void BLSURFPlugin_Hypothesis::SetEnforcedVertexList(const std::string& entry, const BLSURFPlugin_Hypothesis::TEnforcedVertexList vertexList)
465 {
466   BLSURFPlugin_Hypothesis::TEnforcedVertexList::const_iterator it;
467   bool toNotify = false;
468   for(it = vertexList.begin();it!=vertexList.end();++it) {
469     if (_enforcedVertices.count(entry)>0)
470       if (_enforcedVertices[entry].count(*it)==0)
471         toNotify = true;
472     else
473       toNotify = true;
474     _enforcedVertices[entry].insert(*it);
475   }
476   if (toNotify)
477     NotifySubMeshesHypothesisModification();
478 }
479 */
480
481 //=======================================================================
482 //function : GetEnforcedVertices
483 //=======================================================================
484
485 BLSURFPlugin_Hypothesis::TEnforcedVertexList BLSURFPlugin_Hypothesis::GetEnforcedVertices(const std::string& entry)
486   throw (std::invalid_argument)
487 {
488   if (_enforcedVertices.count(entry)>0)
489     return _enforcedVertices[entry];
490   std::ostringstream msg ;
491   msg << "No enforced vertex for entry " << entry ;
492   throw std::invalid_argument(msg.str());
493 }
494
495 //=======================================================================
496 //function : ClearEnforcedVertex
497 //=======================================================================
498
499 void BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const std::string& entry, double x, double y, double z)
500   throw (std::invalid_argument)
501 {
502   BLSURFPlugin_Hypothesis::TEnforcedVertex coord;
503   coord.push_back(x);
504   coord.push_back(y);
505   coord.push_back(z);
506   BLSURFPlugin_Hypothesis::TEnforcedVertexList::iterator it;
507   bool toNotify = false;
508
509   BLSURFPlugin_Hypothesis::TEnforcedVertexMap::iterator it_enf = _enforcedVertices.find(entry);
510   if (it_enf != _enforcedVertices.end()) {
511     it = _enforcedVertices[entry].find(coord);
512     if (it != _enforcedVertices[entry].end()) {
513       toNotify = true;
514       _enforcedVertices[entry].erase(it);
515       if (_enforcedVertices[entry].size() == 0)
516         _enforcedVertices.erase(it_enf);
517     }
518     if (toNotify)
519       NotifySubMeshesHypothesisModification();
520     return;
521   }
522
523   std::ostringstream msg ;
524   msg << "No enforced vertex for " << entry;
525   throw std::invalid_argument(msg.str());
526 }
527 /*
528 //=======================================================================
529 //function : ClearEnforcedVertexList
530 //=======================================================================
531
532 void BLSURFPlugin_Hypothesis::ClearEnforcedVertexList(const std::string& entry, BLSURFPlugin_Hypothesis::TEnforcedVertexList vertexList)
533   throw (std::invalid_argument)
534 {
535   BLSURFPlugin_Hypothesis::TEnforcedVertex coord;
536   BLSURFPlugin_Hypothesis::TEnforcedVertexList::const_iterator it_toRemove;
537   BLSURFPlugin_Hypothesis::TEnforcedVertexList::iterator it;
538   bool toNotify = false;
539
540   BLSURFPlugin_Hypothesis::TEnforcedVertexMap::iterator it_enf = _enforcedVertices.find(entry);
541   if (it_enf != _enforcedVertices.end()) {
542     for (it_toRemove = vertexList.begin() ; it_toRemove != vertexList.end() ; ++it_toRemove) {
543       coord = *it_toRemove;
544       it = _enforcedVertices[entry].find(coord);
545       if (it != _enforcedVertices[entry].end()) {
546         toNotify = true;
547         _enforcedVertices[entry].erase(it);
548       }
549     }
550     if (_enforcedVertices[entry].size() == 0) {
551       toNotify = true;
552       _enforcedVertices.erase(it_enf);
553     }
554     if (toNotify)
555       NotifySubMeshesHypothesisModification();
556     return;
557   }
558
559   std::ostringstream msg ;
560   msg << "No enforced vertex for " << entry;
561   throw std::invalid_argument(msg.str());
562 }
563 */
564 //=======================================================================
565 //function : ClearEnforcedVertices
566 //=======================================================================
567
568 void BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const std::string& entry)
569   throw (std::invalid_argument)
570 {
571   BLSURFPlugin_Hypothesis::TEnforcedVertexMap::iterator it_enf = _enforcedVertices.find(entry);
572   if (it_enf != _enforcedVertices.end()) {
573     _enforcedVertices.erase(it_enf);
574     NotifySubMeshesHypothesisModification();
575     return;
576   }
577
578   std::ostringstream msg ;
579   msg << "No enforced vertex for " << entry;
580   throw std::invalid_argument(msg.str());
581 }
582
583 //=======================================================================
584 //function : ClearAllEnforcedVertices
585 //=======================================================================
586 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices()
587 {
588     _enforcedVertices.clear();
589     NotifySubMeshesHypothesisModification();
590 }
591
592 //================================================================================
593 /*!
594 * \brief Return the enforced vertices
595 */
596 //================================================================================
597
598 BLSURFPlugin_Hypothesis::TEnforcedVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(const BLSURFPlugin_Hypothesis* hyp)
599 {
600     return hyp ? hyp->_GetAllEnforcedVertices():GetDefaultEnforcedVertexMap();
601 }
602
603
604
605 //=============================================================================
606 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
607 {
608   save << " " << (int)_topology
609        << " " << (int)_physicalMesh
610        << " " << (int)_geometricMesh
611        << " " << _phySize
612        << " " << _angleMeshS
613        << " " << _gradation
614        << " " << (int)_quadAllowed
615        << " " << (int)_decimesh;
616   save << " " << _phyMin
617        << " " << _phyMax
618        << " " << _angleMeshC
619        << " " << _hgeoMin
620        << " " << _hgeoMax
621        << " " << _verb;
622
623   TOptionValues::iterator op_val = _option2value.begin();
624   if (op_val != _option2value.end()) {
625     save << " " << "__OPTIONS_BEGIN__";
626     for ( ; op_val != _option2value.end(); ++op_val ) {
627       if ( !op_val->second.empty() )
628         save << " " << op_val->first
629              << " " << op_val->second << "%#"; // "%#" is a mark of value end
630     }
631     save << " " << "__OPTIONS_END__";
632   }
633
634   TSizeMap::iterator it_sm  = _sizeMap.begin();
635   if (it_sm != _sizeMap.end()) {
636     save << " " << "__SIZEMAP_BEGIN__";
637     for ( ; it_sm != _sizeMap.end(); ++it_sm ) {
638         save << " " << it_sm->first
639              << " " << it_sm->second << "%#"; // "%#" is a mark of value end
640     }
641     save << " " << "__SIZEMAP_END__";
642   }
643
644   TSizeMap::iterator it_at  = _attractors.begin();
645   if (it_at != _attractors.end()) {
646     save << " " << "__ATTRACTORS_BEGIN__";
647     for ( ; it_at != _attractors.end(); ++it_at ) {
648         save << " " << it_at->first
649              << " " << it_at->second << "%#"; // "%#" is a mark of value end
650     }
651     save << " " << "__ATTRACTORS_END__";
652   }
653
654   TEnforcedVertexMap::const_iterator it_enf = _enforcedVertices.begin();
655   if (it_enf != _enforcedVertices.end()) {
656     save << " " << "__ENFORCED_VERTICES_BEGIN__";
657     for ( ; it_enf != _enforcedVertices.end(); ++it_enf ) {
658       save << " " << it_enf->first;
659       TEnforcedVertexList evl = it_enf->second;
660       TEnforcedVertexList::const_iterator it_evl = evl.begin();
661       if (it_evl != evl.end()) {
662         for ( ; it_evl != evl.end() ; ++it_evl) {
663           save << " " << (*it_evl)[0];
664           save << " " << (*it_evl)[1];
665           save << " " << (*it_evl)[2];
666           save << "$"; // "$" is a mark of enforced vertex end
667         }
668       }
669       save << "#"; // "#" is a mark of enforced shape end
670     }
671     save << " " << "__ENFORCED_VERTICES_END__";
672   }
673
674   return save;
675 }
676
677 //=============================================================================
678 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
679 {
680   bool isOK = true;
681   int i;
682   double val;
683
684   isOK = (load >> i);
685   if (isOK)
686     _topology = (Topology) i;
687   else
688     load.clear(std::ios::badbit | load.rdstate());
689
690   isOK = (load >> i);
691   if (isOK)
692     _physicalMesh = (PhysicalMesh) i;
693   else
694     load.clear(std::ios::badbit | load.rdstate());
695
696   isOK = (load >> i);
697   if (isOK)
698     _geometricMesh = (GeometricMesh) i;
699   else
700     load.clear(std::ios::badbit | load.rdstate());
701
702   isOK = (load >> val);
703   if (isOK)
704     _phySize = val;
705   else
706     load.clear(std::ios::badbit | load.rdstate());
707
708   isOK = (load >> val);
709   if (isOK)
710     _angleMeshS = val;
711   else
712     load.clear(std::ios::badbit | load.rdstate());
713
714   isOK = (load >> val);
715   if (isOK)
716     _gradation = val;
717   else
718     load.clear(std::ios::badbit | load.rdstate());
719
720   isOK = (load >> i);
721   if (isOK)
722     _quadAllowed = (bool) i;
723   else
724     load.clear(std::ios::badbit | load.rdstate());
725
726   isOK = (load >> i);
727   if (isOK)
728     _decimesh = (bool) i;
729   else
730     load.clear(std::ios::badbit | load.rdstate());
731
732   isOK = (load >> val);
733   if (isOK)
734     _phyMin = val;
735   else
736     load.clear(std::ios::badbit | load.rdstate());
737
738   isOK = (load >> val);
739   if (isOK)
740     _phyMax = val;
741   else
742     load.clear(std::ios::badbit | load.rdstate());
743
744   isOK = (load >> val);
745   if (isOK)
746     _angleMeshC = val;
747   else
748     load.clear(std::ios::badbit | load.rdstate());
749
750   isOK = (load >> val);
751   if (isOK)
752     _hgeoMin = val;
753   else
754     load.clear(std::ios::badbit | load.rdstate());
755
756   isOK = (load >> val);
757   if (isOK)
758     _hgeoMax = val;
759   else
760     load.clear(std::ios::badbit | load.rdstate());
761
762   isOK = (load >> i);
763   if (isOK)
764     _verb = i;
765   else
766     load.clear(std::ios::badbit | load.rdstate());
767
768   std::string option_or_sm;
769   bool hasOptions = false;
770   bool hasSizeMap = false;
771   bool hasAttractor = false;
772   bool hasEnforcedVertex = false;
773
774   isOK = (load >> option_or_sm);
775   if (isOK)
776     if (option_or_sm == "__OPTIONS_BEGIN__")
777       hasOptions = true;
778     else if (option_or_sm == "__SIZEMAP_BEGIN__")
779       hasSizeMap = true;
780     else if (option_or_sm == "__ATTRACTORS_BEGIN__")
781       hasAttractor = true;
782     else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
783       hasEnforcedVertex = true;
784
785   std::string optName, optValue;
786   while (isOK && hasOptions) {
787     isOK = (load >> optName);
788     if (isOK) {
789       if (optName == "__OPTIONS_END__")
790         break;
791       isOK = (load >> optValue);
792     }
793     if (isOK) {
794       std::string & value = _option2value[ optName ];
795       value = optValue;
796       int len = value.size();
797       // continue reading until "%#" encountered
798       while ( value[len-1] != '#' || value[len-2] != '%' )
799       {
800         isOK = (load >> optValue);
801         if (isOK) {
802           value += " ";
803           value += optValue;
804           len = value.size();
805         }
806         else {
807           break;
808         }
809       }
810       value[ len-2 ] = '\0'; //cut off "%#"
811     }
812   }
813
814   if (hasOptions) {
815     isOK = (load >> option_or_sm);
816     if (isOK)
817       if (option_or_sm == "__SIZEMAP_BEGIN__")
818         hasSizeMap = true;
819       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
820         hasAttractor = true;
821       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
822         hasEnforcedVertex = true;
823   }
824
825   std::string smEntry, smValue;
826   while (isOK && hasSizeMap) {
827     isOK = (load >> smEntry);
828     if (isOK) {
829       if (smEntry == "__SIZEMAP_END__")
830         break;
831       isOK = (load >> smValue);
832     }
833     if (isOK) {
834       std::string & value2 = _sizeMap[ smEntry ];
835       value2 = smValue;
836       int len2= value2.size();
837       // continue reading until "%#" encountered
838       while ( value2[len2-1] != '#' || value2[len2-2] != '%' )
839       {
840         isOK = (load >> smValue);
841         if (isOK) {
842           value2 += " ";
843           value2 += smValue;
844           len2 = value2.size();
845         }
846         else {
847           break;
848         }
849       }
850       value2[ len2-2 ] = '\0'; //cut off "%#"
851     }
852   }
853
854   if (hasSizeMap) {
855     isOK = (load >> option_or_sm);
856     if (isOK)
857       if (option_or_sm == "__ATTRACTORS_BEGIN__")
858         hasAttractor = true;
859       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
860         hasEnforcedVertex = true;
861   }
862
863   std::string atEntry, atValue;
864   while (isOK && hasAttractor) {
865     isOK = (load >> atEntry);
866     if (isOK) {
867       if (atEntry == "__ATTRACTORS_END__")
868         break;
869       isOK = (load >> atValue);
870     }
871     if (isOK) {
872       std::string & value3 = _attractors[ atEntry ];
873       value3 = atValue;
874       int len3= value3.size();
875       // continue reading until "%#" encountered
876       while ( value3[len3-1] != '#' || value3[len3-2] != '%' )
877       {
878         isOK = (load >> atValue);
879         if (isOK) {
880           value3 += " ";
881           value3 += atValue;
882           len3 = value3.size();
883         }
884         else {
885           break;
886         }
887       }
888       value3[ len3-2 ] = '\0'; //cut off "%#"
889     }
890   }
891   
892   if (hasAttractor) {
893     isOK = (load >> option_or_sm);
894     if (isOK)
895       if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
896         hasEnforcedVertex = true;
897   }
898   
899   std::string enfEntry, enfValue, trace;
900   std::ostringstream oss;
901   while (isOK && hasEnforcedVertex) {
902     isOK = (load >> enfEntry);
903     if (isOK) {
904       if (enfEntry == "__ENFORCED_VERTICES_END__")
905         break;
906
907       enfValue = "begin";
908       int len4 = enfValue.size();
909
910       TEnforcedVertexList & evl = _enforcedVertices[enfEntry];
911       evl.clear();
912       TEnforcedVertex enfVertex;
913
914       // continue reading until "#" encountered
915       while ( enfValue[len4-1] != '#') {
916         // New vector begin
917         enfVertex.clear();
918         while ( enfValue[len4-1] != '$') {
919           isOK = (load >> enfValue);
920           if (isOK) {
921             len4 = enfValue.size();
922             // End of vertex list
923             if (enfValue[len4-1] == '#')
924               break;
925             if (enfValue[len4-1] != '$') {
926               // Add to vertex
927               enfVertex.push_back(atof(enfValue.c_str()));
928             }
929           }
930           else
931             break;
932         }
933         if (enfValue[len4-1] == '$') {
934           // Remove '$' and add to vertex
935           enfValue[len4-1] = '\0'; //cut off "$#"
936           enfVertex.push_back(atof(enfValue.c_str()));
937           // Add vertex to list of vertex
938           evl.insert(enfVertex);
939         }
940       }
941       if (enfValue[len4-1] == '#') {
942         // Remove '$#' and add to vertex
943         enfValue[len4-2] = '\0'; //cut off "$#"
944         enfVertex.push_back(atof(enfValue.c_str()));
945         // Add vertex to list of vertex
946         evl.insert(enfVertex);
947       }
948     }
949     else
950       break;
951   }
952
953   return load;
954 }
955
956 //=============================================================================
957 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp)
958 {
959   return hyp.SaveTo( save );
960 }
961
962 //=============================================================================
963 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp)
964 {
965   return hyp.LoadFrom( load );
966 }
967
968 //================================================================================
969 /*!
970  * \brief Does nothing
971  */
972 //================================================================================
973
974 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
975                                                       const TopoDS_Shape& theShape)
976 {
977   return false;
978 }
979
980 //=============================================================================
981 /*!
982  * \brief Initialize my parameter values by default parameters.
983  *  \retval bool - true if parameter values have been successfully defined
984  */
985 //=============================================================================
986
987 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&   dflts,
988                                                       const SMESH_Mesh* theMesh)
989 {
990   return bool( _phySize = dflts._elemLength );
991 }
992
993 //=============================================================================
994 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
995 {
996   return FromCAD;
997 }
998
999 //=============================================================================
1000 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
1001 {
1002   return PhysicalUserDefined;
1003 }
1004
1005 //=============================================================================
1006 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
1007 {
1008   return 10;
1009 }
1010
1011 //======================================================================
1012 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
1013 {
1014   return undefinedDouble(); // 1e+4;
1015 }
1016
1017 //======================================================================
1018 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
1019 {
1020   return undefinedDouble(); //1e-4;
1021 }
1022
1023 //======================================================================
1024 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
1025 {
1026   return DefaultGeom;
1027 }
1028
1029 //=============================================================================
1030 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
1031 {
1032   return 8;
1033 }
1034
1035 //=============================================================================
1036 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
1037 {
1038   return 1.1;
1039 }
1040
1041 //=============================================================================
1042 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
1043 {
1044   return false;
1045 }
1046
1047 //=============================================================================
1048 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()
1049 {
1050   return false;
1051 }