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