Salome HOME
Finished the Save/Load mechanism for enforced vertices
[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 development: 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, SMESH_Gen * gen) :
35   SMESH_Hypothesis(hypId, studyId, gen), _topology(GetDefaultTopology()),
36   _physicalMesh(GetDefaultPhysicalMesh()),
37   _phySize(GetDefaultPhySize()),
38   _phyMax(GetDefaultMaxSize()),
39   _phyMin(GetDefaultMinSize()),
40   _hgeoMax(GetDefaultMaxSize()),
41   _hgeoMin(GetDefaultMinSize()), 
42   _geometricMesh(GetDefaultGeometricMesh()),
43   _angleMeshS(GetDefaultAngleMeshS()),
44   _angleMeshC(GetDefaultAngleMeshC()),
45   _gradation(GetDefaultGradation()),
46   _quadAllowed(GetDefaultQuadAllowed()),
47   _decimesh(GetDefaultDecimesh()),
48   _verb(GetDefaultVerbosity()),
49   _sizeMap(GetDefaultSizeMap()),
50   _attractors(GetDefaultSizeMap()),
51   _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
52   _enfVertexList(GetDefaultEnfVertexList()),
53   _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
54   _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
55   _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
56   _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
57   _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap())
58
59 /* TODO GROUPS
60  _groupNameEnfVertexListMap(GetDefaultGroupNameEnfVertexListMap()),
61  _enfVertexGroupNameMap(GetDefaultEnfVertexGroupNameMap())
62  */
63 {
64   _name = "BLSURF_Parameters";
65   _param_algo_dim = 2;
66
67   // to disable writing boundaries
68   //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
69
70
71   const char* intOptionNames[] = { "addsurf_ivertex", "background", "CheckAdjacentEdges", "CheckCloseEdges",
72       "CheckWellDefined", "coiter", "communication", "decim", "export_flag", "file_h", "frontal", "gridnu", "gridnv",
73       "hinterpol_flag", "hmean_flag", "intermedfile", "memory", "normals", "optim", "pardom_flag", "pinch", "refs",
74       "rigid", "surforient", "tconf", "topo_collapse", "" // mark of end
75       };
76   const char* doubleOptionNames[] = { "addsurf_angle", "addsurf_R", "addsurf_H", "addsurf_FG", "addsurf_r",
77       "addsurf_PA", "angle_compcurv", "angle_ridge", "CoefRectangle", "eps_collapse", "eps_ends", "eps_pardom", "LSS",
78       "topo_eps1", "topo_eps2", "" // mark of end
79       };
80   const char* charOptionNames[] = { "export_format", "export_option", "import_option", "prefix", "" // mark of end
81       };
82
83   int i = 0;
84   while (intOptionNames[i][0])
85     _option2value[intOptionNames[i++]].clear();
86
87   i = 0;
88   while (doubleOptionNames[i][0]) {
89     _doubleOptions.insert(doubleOptionNames[i]);
90     _option2value[doubleOptionNames[i++]].clear();
91   }
92   i = 0;
93   while (charOptionNames[i][0]) {
94     _charOptions.insert(charOptionNames[i]);
95     _option2value[charOptionNames[i++]].clear();
96   }
97
98   _sizeMap.clear();
99   _attractors.clear();
100   _faceEntryEnfVertexListMap.clear();
101   _enfVertexList.clear();
102   _faceEntryCoordsListMap.clear();
103   _coordsEnfVertexMap.clear();
104   _faceEntryEnfVertexEntryListMap.clear();
105   _enfVertexEntryEnfVertexMap.clear();
106   _groupNameNodeIDMap.clear();
107
108   /* TODO GROUPS
109    _groupNameEnfVertexListMap.clear();
110    _enfVertexGroupNameMap.clear();
111    */
112 }
113
114 //=============================================================================
115 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
116   if (theTopology != _topology) {
117     _topology = theTopology;
118     NotifySubMeshesHypothesisModification();
119   }
120 }
121
122 //=============================================================================
123 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
124   if (thePhysicalMesh != _physicalMesh) {
125     _physicalMesh = thePhysicalMesh;
126     switch (_physicalMesh) {
127       case DefaultSize:
128       default:
129         _phySize = GetDefaultPhySize();
130         _gradation = GetDefaultGradation();
131         break;
132     }
133     NotifySubMeshesHypothesisModification();
134   }
135 }
136
137 //=============================================================================
138 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal) {
139   if (theVal != _phySize) {
140     _phySize = theVal;
141     NotifySubMeshesHypothesisModification();
142   }
143 }
144
145 //=============================================================================
146 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize) {
147   if (theMinSize != _phyMin) {
148     _phyMin = theMinSize;
149     NotifySubMeshesHypothesisModification();
150   }
151 }
152
153 //=============================================================================
154 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize) {
155   if (theMaxSize != _phyMax) {
156     _phyMax = theMaxSize;
157     NotifySubMeshesHypothesisModification();
158   }
159 }
160
161 //=============================================================================
162 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize) {
163   if (theMinSize != _hgeoMin) {
164     _hgeoMin = theMinSize;
165     NotifySubMeshesHypothesisModification();
166   }
167 }
168
169 //=============================================================================
170 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize) {
171   if (theMaxSize != _hgeoMax) {
172     _hgeoMax = theMaxSize;
173     NotifySubMeshesHypothesisModification();
174   }
175 }
176
177 //=============================================================================
178 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
179   if (theGeometricMesh != _geometricMesh) {
180     _geometricMesh = theGeometricMesh;
181     switch (_geometricMesh) {
182       case DefaultGeom:
183       default:
184         _angleMeshS = GetDefaultAngleMeshS();
185         _gradation = GetDefaultGradation();
186         break;
187     }
188     NotifySubMeshesHypothesisModification();
189   }
190 }
191
192 //=============================================================================
193 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal) {
194   if (theVal != _angleMeshS) {
195     _angleMeshS = theVal;
196     NotifySubMeshesHypothesisModification();
197   }
198 }
199
200 //=============================================================================
201 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal) {
202   if (theVal != _angleMeshC) {
203     _angleMeshC = theVal;
204     NotifySubMeshesHypothesisModification();
205   }
206 }
207
208 //=============================================================================
209 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
210   if (theVal != _gradation) {
211     _gradation = theVal;
212     NotifySubMeshesHypothesisModification();
213   }
214 }
215
216 //=============================================================================
217 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
218   if (theVal != _quadAllowed) {
219     _quadAllowed = theVal;
220     NotifySubMeshesHypothesisModification();
221   }
222 }
223
224 //=============================================================================
225 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal) {
226   if (theVal != _decimesh) {
227     _decimesh = theVal;
228     NotifySubMeshesHypothesisModification();
229   }
230 }
231
232 //=============================================================================
233 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
234   if (theVal != _verb) {
235     _verb = theVal;
236     NotifySubMeshesHypothesisModification();
237   }
238 }
239 //=============================================================================
240 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
241     throw (std::invalid_argument) {
242   TOptionValues::iterator op_val = _option2value.find(optionName);
243   if (op_val == _option2value.end()) {
244     std::string msg = "Unknown BLSURF option: '" + optionName + "'";
245     throw std::invalid_argument(msg);
246   }
247   if (op_val->second != optionValue) {
248     const char* ptr = optionValue.c_str();
249     // strip white spaces
250     while (ptr[0] == ' ')
251       ptr++;
252     int i = strlen(ptr);
253     while (i != 0 && ptr[i - 1] == ' ')
254       i--;
255     // check value type
256     bool typeOk = true;
257     std::string typeName;
258     if (i == 0) {
259       // empty string
260     } else if (_charOptions.find(optionName) != _charOptions.end()) {
261       // do not check strings
262     } else if (_doubleOptions.find(optionName) != _doubleOptions.end()) {
263       // check if value is double
264       char * endPtr;
265       strtod(ptr, &endPtr);
266       typeOk = (ptr != endPtr);
267       typeName = "real";
268     } else {
269       // check if value is int
270       char * endPtr;
271       strtol(ptr, &endPtr, 10);
272       typeOk = (ptr != endPtr);
273       typeName = "integer";
274     }
275     if (!typeOk) {
276       std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
277       throw std::invalid_argument(msg);
278     }
279     op_val->second = optionValue;
280     NotifySubMeshesHypothesisModification();
281   }
282 }
283
284 //=============================================================================
285 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName) throw (std::invalid_argument) {
286   TOptionValues::iterator op_val = _option2value.find(optionName);
287   if (op_val == _option2value.end()) {
288     std::string msg = "Unknown BLSURF option: <";
289     msg += optionName + ">";
290     throw std::invalid_argument(msg);
291   }
292   return op_val->second;
293 }
294
295 //=============================================================================
296 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName) {
297   TOptionValues::iterator op_val = _option2value.find(optionName);
298   if (op_val != _option2value.end())
299     op_val->second.clear();
300 }
301
302 //=======================================================================
303 //function : SetSizeMapEntry
304 //=======================================================================
305 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
306   if (_sizeMap[entry].compare(sizeMap) != 0) {
307     _sizeMap[entry] = sizeMap;
308     NotifySubMeshesHypothesisModification();
309   }
310 }
311
312 //=======================================================================
313 //function : GetSizeMapEntry
314 //=======================================================================
315 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
316   TSizeMap::iterator it = _sizeMap.find(entry);
317   if (it != _sizeMap.end())
318     return it->second;
319   else
320     return "No_Such_Entry";
321 }
322
323 /*!
324  * \brief Return the size maps
325  */
326 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
327   return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
328 }
329
330 //=======================================================================
331 //function : SetAttractorEntry
332 //=======================================================================
333 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
334   if (_attractors[entry].compare(attractor) != 0) {
335     _attractors[entry] = attractor;
336     NotifySubMeshesHypothesisModification();
337   }
338 }
339
340 //=======================================================================
341 //function : GetAttractorEntry
342 //=======================================================================
343 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
344   TSizeMap::iterator it = _attractors.find(entry);
345   if (it != _attractors.end())
346     return it->second;
347   else
348     return "No_Such_Entry";
349 }
350
351 /*!
352  * \brief Return the attractors
353  */
354 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
355   return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
356 }
357
358 //=======================================================================
359 //function : ClearEntry
360 //=======================================================================
361 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry) {
362   TSizeMap::iterator it = _sizeMap.find(entry);
363   if (it != _sizeMap.end()) {
364     _sizeMap.erase(it);
365     NotifySubMeshesHypothesisModification();
366   } else {
367     TSizeMap::iterator itAt = _attractors.find(entry);
368     if (itAt != _attractors.end()) {
369       _attractors.erase(itAt);
370       NotifySubMeshesHypothesisModification();
371     } else
372       std::cout << "No_Such_Entry" << std::endl;
373   }
374 }
375
376 //=======================================================================
377 //function : ClearSizeMaps
378 //=======================================================================
379 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
380   _sizeMap.clear();
381   _attractors.clear();
382 }
383
384 //=======================================================================
385 //function : SetEnforcedVertex
386 //=======================================================================
387 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
388                                                 TEnfGroupName theGroupName, double x, double y, double z) {
389
390   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
391       << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
392
393   //  TEnfVertexList::iterator it;
394   bool toNotify = false;
395   bool toCreate = true;
396
397   TEnfVertex *oldEnVertex;
398   TEnfVertex *newEnfVertex = new TEnfVertex();
399   newEnfVertex->name = theVertexName;
400   newEnfVertex->geomEntry = theVertexEntry;
401   newEnfVertex->coords.clear();
402   if (theVertexEntry == "") {
403     newEnfVertex->coords.push_back(x);
404     newEnfVertex->coords.push_back(y);
405     newEnfVertex->coords.push_back(z);
406   }
407   newEnfVertex->grpName = theGroupName;
408   newEnfVertex->faceEntries.clear();
409   newEnfVertex->faceEntries.insert(theFaceEntry);
410   
411   
412   // update _enfVertexList
413   TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
414   if (it != _enfVertexList.end()) {
415     toCreate = false;
416     oldEnVertex = (*it);
417     MESSAGE("Enforced Vertex was found => Update");
418     if (oldEnVertex->name != theVertexName) {
419       MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
420       oldEnVertex->name = theVertexName;
421       toNotify = true;
422     }
423     if (oldEnVertex->grpName != theGroupName) {
424       MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
425       oldEnVertex->grpName = theGroupName;
426       toNotify = true;
427     }
428     TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
429     if (it_faceEntries == oldEnVertex->faceEntries.end()) {
430       MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
431       oldEnVertex->faceEntries.insert(theFaceEntry);
432       _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
433       toNotify = true;
434     }
435     if (toNotify) {
436       // update map coords / enf vertex if needed
437       if (oldEnVertex->coords.size()) {
438         _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
439         _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
440       }
441
442       // update map geom entry / enf vertex if needed
443       if (oldEnVertex->geomEntry != "") {
444         _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
445         _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
446       }
447     }
448   }
449
450 //   //////// CREATE ////////////
451   if (toCreate) {
452     toNotify = true;
453     MESSAGE("Creating new enforced vertex");
454     _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
455     _enfVertexList.insert(newEnfVertex);
456     if (theVertexEntry == "") {
457       _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
458       _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
459     }
460     else {
461       _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
462       _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
463     }
464   }
465
466   if (toNotify)
467     NotifySubMeshesHypothesisModification();
468
469   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
470   return toNotify;
471 }
472
473
474 //=======================================================================
475 //function : GetEnforcedVertices
476 //=======================================================================
477
478 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
479     throw (std::invalid_argument) {
480
481   if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
482     return _faceEntryEnfVertexListMap[theFaceEntry];
483   else
484     return GetDefaultEnfVertexList();
485
486   std::ostringstream msg;
487   msg << "No enforced vertex for face entry " << theFaceEntry;
488   throw std::invalid_argument(msg.str());
489 }
490
491 //=======================================================================
492 //function : GetEnfVertexCoordsList
493 //=======================================================================
494
495 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
496     const TEntry& theFaceEntry) throw (std::invalid_argument) {
497
498   if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
499     return _faceEntryCoordsListMap[theFaceEntry];
500
501   std::ostringstream msg;
502   msg << "No enforced vertex coords for face entry " << theFaceEntry;
503   throw std::invalid_argument(msg.str());
504 }
505
506 //=======================================================================
507 //function : GetEnfVertexEntryList
508 //=======================================================================
509
510 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
511     throw (std::invalid_argument) {
512
513   if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
514     return _faceEntryEnfVertexEntryListMap[theFaceEntry];
515
516   std::ostringstream msg;
517   msg << "No enforced vertex entry for face entry " << theFaceEntry;
518   throw std::invalid_argument(msg.str());
519 }
520
521 //=======================================================================
522 //function : GetEnfVertex(TEnfVertexCoords coords)
523 //=======================================================================
524
525 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
526     throw (std::invalid_argument) {
527
528   if (_coordsEnfVertexMap.count(coords) > 0)
529     return _coordsEnfVertexMap[coords];
530
531   std::ostringstream msg;
532   msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
533   throw std::invalid_argument(msg.str());
534 }
535
536 //=======================================================================
537 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
538 //=======================================================================
539
540 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
541     throw (std::invalid_argument) {
542
543   if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
544     return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
545
546   std::ostringstream msg;
547   msg << "No enforced vertex with entry " << theEnfVertexEntry;
548   throw std::invalid_argument(msg.str());
549 }
550
551 //=======================================================================
552 //function : ClearEnforcedVertex
553 //=======================================================================
554
555 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
556     const TEntry& theVertexEntry) throw (std::invalid_argument) {
557
558   bool toNotify = false;
559   std::ostringstream msg;
560   TEnfVertex *oldEnfVertex;
561   TEnfVertexCoords coords;
562   coords.clear();
563   coords.push_back(x);
564   coords.push_back(y);
565   coords.push_back(z);
566
567   // check that enf vertex with given enf vertex entry exists
568   TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
569   if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
570     // Success
571     MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
572     oldEnfVertex = it_enfVertexEntry->second;
573
574     _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
575
576     TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
577     enfVertexEntryList.erase(theVertexEntry);
578     if (enfVertexEntryList.size() == 0)
579       _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
580     //    TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
581     //    TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
582     //    it_entry_entry->second.erase(it_entryList);
583     //    if (it_entry_entry->second.size() == 0)
584     //      _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
585   } else {
586     // Fail
587     MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
588     msg << "No enforced vertex with geom entry " << theVertexEntry;
589     // check that enf vertex with given coords exists
590     TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
591     if (it_coords_enf != _coordsEnfVertexMap.end()) {
592       // Success
593       MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
594       oldEnfVertex = it_coords_enf->second;
595
596       _coordsEnfVertexMap.erase(it_coords_enf);
597
598       TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
599       enfVertexCoordsList.erase(coords);
600       if (enfVertexCoordsList.size() == 0)
601         _faceEntryCoordsListMap.erase(theFaceEntry);
602       //      TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
603       //      TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
604       //      it_entry_coords->second.erase(it_coordsList);
605       //      if (it_entry_coords->second.size() == 0)
606       //        _faceEntryCoordsListMap.erase(it_entry_coords);
607     } else {
608       // Fail
609       MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
610       msg << std::endl;
611       msg << "No enforced vertex at " << x << ", " << y << ", " << z;
612       throw std::invalid_argument(msg.str());
613     }
614   }
615
616   MESSAGE("Remove enf vertex from _enfVertexList");
617
618   // update _enfVertexList
619   TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
620   if (it != _enfVertexList.end()) {
621     (*it)->faceEntries.erase(theFaceEntry);
622     if ((*it)->faceEntries.size() == 0){
623       _enfVertexList.erase(it);
624       toNotify = true;
625     }
626     MESSAGE("Done");
627   }
628
629   // update _faceEntryEnfVertexListMap
630   TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
631   currentEnfVertexList.erase(oldEnfVertex);
632
633   if (currentEnfVertexList.size() == 0) {
634     MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
635     _faceEntryEnfVertexListMap.erase(theFaceEntry);
636     MESSAGE("Done");
637   }
638
639   if (toNotify)
640     NotifySubMeshesHypothesisModification();
641
642   return toNotify;
643 }
644
645 //=======================================================================
646 //function : ClearEnforcedVertices
647 //=======================================================================
648
649 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
650
651   bool toNotify = false;
652   TEnfVertex *oldEnfVertex;
653
654   TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
655   if (it_entry_coords != _faceEntryCoordsListMap.end()) {
656     toNotify = true;
657     TEnfVertexCoordsList coordsList = it_entry_coords->second;
658     TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
659     for (; it_coordsList != coordsList.end(); ++it_coordsList) {
660       TEnfVertexCoords coords = (*it_coordsList);
661       oldEnfVertex = _coordsEnfVertexMap[coords];
662       _coordsEnfVertexMap.erase(coords);
663       // update _enfVertexList
664       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
665       if (it != _enfVertexList.end()) {
666         (*it)->faceEntries.erase(theFaceEntry);
667         if ((*it)->faceEntries.size() == 0){
668           _enfVertexList.erase(it);
669           toNotify = true;
670         }
671         MESSAGE("Done");
672       }
673     }
674     _faceEntryCoordsListMap.erase(it_entry_coords);
675     _faceEntryEnfVertexListMap.erase(theFaceEntry);
676   }
677
678   TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
679   if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
680     toNotify = true;
681     TEntryList enfVertexEntryList = it_entry_entry->second;
682     TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
683     for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
684       TEntry enfVertexEntry = (*it_enfVertexEntryList);
685       oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
686       _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
687       // update _enfVertexList
688       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
689       if (it != _enfVertexList.end()) {
690         (*it)->faceEntries.erase(theFaceEntry);
691         if ((*it)->faceEntries.size() == 0){
692           _enfVertexList.erase(it);
693           toNotify = true;
694         }
695         MESSAGE("Done");
696       }
697     }
698     _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
699     _faceEntryEnfVertexListMap.erase(theFaceEntry);
700   }
701
702   if (toNotify)
703     NotifySubMeshesHypothesisModification();
704
705   return toNotify;
706   //  std::ostringstream msg;
707   //  msg << "No enforced vertex for " << theFaceEntry;
708   //  throw std::invalid_argument(msg.str());
709 }
710
711 //=======================================================================
712 //function : ClearAllEnforcedVertices
713 //=======================================================================
714 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
715   _faceEntryEnfVertexListMap.clear();
716   _enfVertexList.clear();
717   _faceEntryCoordsListMap.clear();
718   _coordsEnfVertexMap.clear();
719   _faceEntryEnfVertexEntryListMap.clear();
720   _enfVertexEntryEnfVertexMap.clear();
721   NotifySubMeshesHypothesisModification();
722 }
723
724 //================================================================================
725 /*!
726  * \brief Return the enforced vertices
727  */
728 //================================================================================
729
730
731 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
732     const BLSURFPlugin_Hypothesis* hyp) {
733   return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
734 }
735
736 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
737     const BLSURFPlugin_Hypothesis* hyp) {
738   return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
739 }
740
741 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
742     const BLSURFPlugin_Hypothesis* hyp) {
743   return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
744 }
745
746 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
747     const BLSURFPlugin_Hypothesis* hyp) {
748   return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
749 }
750
751 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
752     const BLSURFPlugin_Hypothesis* hyp) {
753   return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
754 }
755
756 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
757     const BLSURFPlugin_Hypothesis* hyp) {
758   return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
759 }
760
761 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
762 {
763   TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
764   if (it != _groupNameNodeIDMap.end()) {
765     return it->second;
766   }
767   std::ostringstream msg;
768   msg << "No group " << theGroupName;
769   throw std::invalid_argument(msg.str());
770 }
771
772 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
773 {
774   _groupNameNodeIDMap[theGroupName].insert(theNodeID);
775 }
776
777 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
778 {
779   TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
780   if (it != _groupNameNodeIDMap.end()) {
781     std::set<int>::iterator IDit = it->second.find(theNodeID);
782     if (IDit != it->second.end())
783       it->second.erase(IDit);
784     std::ostringstream msg;
785     msg << "No node IDs " << theNodeID << " for group " << theGroupName;
786     throw std::invalid_argument(msg.str());
787   }
788   std::ostringstream msg;
789   msg << "No group " << theGroupName;
790   throw std::invalid_argument(msg.str());
791 }
792
793 //=============================================================================
794 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
795   save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
796       << _angleMeshS << " " << _gradation << " " << (int) _quadAllowed << " " << (int) _decimesh;
797   save << " " << _phyMin << " " << _phyMax << " " << _angleMeshC << " " << _hgeoMin << " " << _hgeoMax << " " << _verb;
798
799   TOptionValues::iterator op_val = _option2value.begin();
800   if (op_val != _option2value.end()) {
801     save << " " << "__OPTIONS_BEGIN__";
802     for (; op_val != _option2value.end(); ++op_val) {
803       if (!op_val->second.empty())
804         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
805     }
806     save << " " << "__OPTIONS_END__";
807   }
808
809   TSizeMap::iterator it_sm = _sizeMap.begin();
810   if (it_sm != _sizeMap.end()) {
811     save << " " << "__SIZEMAP_BEGIN__";
812     for (; it_sm != _sizeMap.end(); ++it_sm) {
813       save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
814     }
815     save << " " << "__SIZEMAP_END__";
816   }
817
818   TSizeMap::iterator it_at = _attractors.begin();
819   if (it_at != _attractors.end()) {
820     save << " " << "__ATTRACTORS_BEGIN__";
821     for (; it_at != _attractors.end(); ++it_at) {
822       save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
823     }
824     save << " " << "__ATTRACTORS_END__";
825   }
826
827   TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
828   if (it_enf != _enfVertexList.end()) {
829     save << " " << "__ENFORCED_VERTICES_BEGIN__";
830     for (; it_enf != _enfVertexList.end(); ++it_enf) {
831       TEnfVertex *enfVertex = (*it_enf);
832       save << " " << "__BEGIN_VERTEX__";
833       if (!enfVertex->name.empty()) {
834         save << " " << "__BEGIN_NAME__";
835         save << " " << enfVertex->name;
836         save << " " << "__END_NAME__";
837       }
838       if (!enfVertex->geomEntry.empty()) {
839         save << " " << "__BEGIN_ENTRY__";
840         save << " " << enfVertex->geomEntry;
841         save << " " << "__END_ENTRY__";
842       }
843       if (!enfVertex->grpName.empty()) {
844         save << " " << "__BEGIN_GROUP__";
845         save << " " << enfVertex->grpName;
846         save << " " << "__END_GROUP__";
847       }
848       if (enfVertex->coords.size()) {
849         save << " " << "__BEGIN_COORDS__";
850         for (int i=0;i<enfVertex->coords.size();i++)
851           save << " " << enfVertex->coords[i];
852         save << " " << "__END_COORDS__";
853       }
854       TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
855       bool hasFaces = false;
856       if (faceEntriesIt != enfVertex->faceEntries.end()) {
857         hasFaces = true;
858         save << " " << "__BEGIN_FACELIST__";
859       }
860       for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
861         save << " " << (*faceEntriesIt);
862       if (hasFaces)
863         save << " " << "__END_FACELIST__";
864       save << " " << "__END_VERTEX__";
865     }
866     save << " " << "__ENFORCED_VERTICES_END__";
867   }
868
869   return save;
870 }
871
872 //=============================================================================
873 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
874   bool isOK = true;
875   int i;
876   double val;
877
878   isOK = (load >> i);
879   if (isOK)
880     _topology = (Topology) i;
881   else
882     load.clear(std::ios::badbit | load.rdstate());
883
884   isOK = (load >> i);
885   if (isOK)
886     _physicalMesh = (PhysicalMesh) i;
887   else
888     load.clear(std::ios::badbit | load.rdstate());
889
890   isOK = (load >> i);
891   if (isOK)
892     _geometricMesh = (GeometricMesh) i;
893   else
894     load.clear(std::ios::badbit | load.rdstate());
895
896   isOK = (load >> val);
897   if (isOK)
898     _phySize = val;
899   else
900     load.clear(std::ios::badbit | load.rdstate());
901
902   isOK = (load >> val);
903   if (isOK)
904     _angleMeshS = val;
905   else
906     load.clear(std::ios::badbit | load.rdstate());
907
908   isOK = (load >> val);
909   if (isOK)
910     _gradation = val;
911   else
912     load.clear(std::ios::badbit | load.rdstate());
913
914   isOK = (load >> i);
915   if (isOK)
916     _quadAllowed = (bool) i;
917   else
918     load.clear(std::ios::badbit | load.rdstate());
919
920   isOK = (load >> i);
921   if (isOK)
922     _decimesh = (bool) i;
923   else
924     load.clear(std::ios::badbit | load.rdstate());
925
926   isOK = (load >> val);
927   if (isOK)
928     _phyMin = val;
929   else
930     load.clear(std::ios::badbit | load.rdstate());
931
932   isOK = (load >> val);
933   if (isOK)
934     _phyMax = val;
935   else
936     load.clear(std::ios::badbit | load.rdstate());
937
938   isOK = (load >> val);
939   if (isOK)
940     _angleMeshC = val;
941   else
942     load.clear(std::ios::badbit | load.rdstate());
943
944   isOK = (load >> val);
945   if (isOK)
946     _hgeoMin = val;
947   else
948     load.clear(std::ios::badbit | load.rdstate());
949
950   isOK = (load >> val);
951   if (isOK)
952     _hgeoMax = val;
953   else
954     load.clear(std::ios::badbit | load.rdstate());
955
956   isOK = (load >> i);
957   if (isOK)
958     _verb = i;
959   else
960     load.clear(std::ios::badbit | load.rdstate());
961
962   std::string option_or_sm;
963   bool hasOptions = false;
964   bool hasSizeMap = false;
965   bool hasAttractor = false;
966   bool hasEnforcedVertex = false;
967
968   isOK = (load >> option_or_sm);
969   if (isOK)
970     if (option_or_sm == "__OPTIONS_BEGIN__")
971       hasOptions = true;
972     else if (option_or_sm == "__SIZEMAP_BEGIN__")
973       hasSizeMap = true;
974     else if (option_or_sm == "__ATTRACTORS_BEGIN__")
975       hasAttractor = true;
976     else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
977       hasEnforcedVertex = true;
978
979   std::string optName, optValue;
980   while (isOK && hasOptions) {
981     isOK = (load >> optName);
982     if (isOK) {
983       if (optName == "__OPTIONS_END__")
984         break;
985       isOK = (load >> optValue);
986     }
987     if (isOK) {
988       std::string & value = _option2value[optName];
989       value = optValue;
990       int len = value.size();
991       // continue reading until "%#" encountered
992       while (value[len - 1] != '#' || value[len - 2] != '%') {
993         isOK = (load >> optValue);
994         if (isOK) {
995           value += " ";
996           value += optValue;
997           len = value.size();
998         } else {
999           break;
1000         }
1001       }
1002       value[len - 2] = '\0'; //cut off "%#"
1003     }
1004   }
1005
1006   if (hasOptions) {
1007     isOK = (load >> option_or_sm);
1008     if (isOK)
1009       if (option_or_sm == "__SIZEMAP_BEGIN__")
1010         hasSizeMap = true;
1011       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1012         hasAttractor = true;
1013       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1014         hasEnforcedVertex = true;
1015   }
1016
1017   std::string smEntry, smValue;
1018   while (isOK && hasSizeMap) {
1019     isOK = (load >> smEntry);
1020     if (isOK) {
1021       if (smEntry == "__SIZEMAP_END__")
1022         break;
1023       isOK = (load >> smValue);
1024     }
1025     if (isOK) {
1026       std::string & value2 = _sizeMap[smEntry];
1027       value2 = smValue;
1028       int len2 = value2.size();
1029       // continue reading until "%#" encountered
1030       while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
1031         isOK = (load >> smValue);
1032         if (isOK) {
1033           value2 += " ";
1034           value2 += smValue;
1035           len2 = value2.size();
1036         } else {
1037           break;
1038         }
1039       }
1040       value2[len2 - 2] = '\0'; //cut off "%#"
1041     }
1042   }
1043
1044   if (hasSizeMap) {
1045     isOK = (load >> option_or_sm);
1046     if (isOK)
1047       if (option_or_sm == "__ATTRACTORS_BEGIN__")
1048         hasAttractor = true;
1049       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1050         hasEnforcedVertex = true;
1051   }
1052
1053   std::string atEntry, atValue;
1054   while (isOK && hasAttractor) {
1055     isOK = (load >> atEntry);
1056     if (isOK) {
1057       if (atEntry == "__ATTRACTORS_END__")
1058         break;
1059       isOK = (load >> atValue);
1060     }
1061     if (isOK) {
1062       std::string & value3 = _attractors[atEntry];
1063       value3 = atValue;
1064       int len3 = value3.size();
1065       // continue reading until "%#" encountered
1066       while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
1067         isOK = (load >> atValue);
1068         if (isOK) {
1069           value3 += " ";
1070           value3 += atValue;
1071           len3 = value3.size();
1072         } else {
1073           break;
1074         }
1075       }
1076       value3[len3 - 2] = '\0'; //cut off "%#"
1077     }
1078   }
1079
1080   if (hasAttractor) {
1081     isOK = (load >> option_or_sm);
1082     if (isOK)
1083       if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1084         hasEnforcedVertex = true;
1085   }
1086
1087
1088 // 
1089 // Here is a example of the saved stream:
1090 // __ENFORCED_VERTICES_BEGIN__ 
1091 // __BEGIN_VERTEX__  => no name, no entry
1092 // __BEGIN_GROUP__ mon groupe __END_GROUP__
1093 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__ 
1094 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__ 
1095 // __END_VERTEX__ 
1096 // __BEGIN_VERTEX__ => no coords
1097 // __BEGIN_NAME__ mes points __END_NAME__ 
1098 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
1099 // __BEGIN_GROUP__ mon groupe __END_GROUP__
1100 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
1101 // __END_VERTEX__ 
1102 // __ENFORCED_VERTICES_END__
1103 // 
1104
1105   std::string enfSeparator;
1106   std::string enfName;
1107   std::string enfGeomEntry;
1108   std::string enfGroup;
1109   TEntryList enfFaceEntryList;
1110   double enfCoords[3];
1111   bool hasCoords = false;
1112   
1113   _faceEntryEnfVertexListMap.clear();
1114   _enfVertexList.clear();
1115   _faceEntryCoordsListMap.clear();
1116   _coordsEnfVertexMap.clear();
1117   _faceEntryEnfVertexEntryListMap.clear();
1118   _enfVertexEntryEnfVertexMap.clear();
1119   
1120   
1121   while (isOK && hasEnforcedVertex) {
1122     isOK = (load >> enfSeparator); // __BEGIN_VERTEX__
1123     TEnfVertex *enfVertex = new TEnfVertex();
1124 //     MESSAGE("enfSeparator: " <<enfSeparator);
1125     if (enfSeparator == "__ENFORCED_VERTICES_END__")
1126       break; // __ENFORCED_VERTICES_END__
1127     if (enfSeparator != "__BEGIN_VERTEX__")
1128       throw std::exception::exception();
1129     
1130     while (isOK) {
1131       isOK = (load >> enfSeparator);
1132       MESSAGE("enfSeparator: " <<enfSeparator);
1133       if (enfSeparator == "__END_VERTEX__") {
1134         
1135         enfVertex->name = enfName;
1136         enfVertex->geomEntry = enfGeomEntry;
1137         enfVertex->grpName = enfGroup;
1138         enfVertex->coords.clear();
1139         if (hasCoords)
1140           enfVertex->coords.assign(enfCoords,enfCoords+3);
1141         enfVertex->faceEntries = enfFaceEntryList;
1142         
1143         _enfVertexList.insert(enfVertex);
1144         
1145         if (enfVertex->coords.size()) {
1146           _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1147           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
1148             _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
1149             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
1150           }
1151         }
1152         if (!enfVertex->geomEntry.empty()) {
1153           _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1154           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
1155             _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
1156             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
1157           }
1158         }
1159         
1160         enfName.clear();
1161         enfGeomEntry.clear();
1162         enfGroup.clear();
1163         enfFaceEntryList.clear();
1164         hasCoords = false;
1165         break; // __END_VERTEX__
1166       }
1167         
1168       if (enfSeparator == "__BEGIN_NAME__") {  // __BEGIN_NAME__
1169         while (isOK && (enfSeparator != "__END_NAME__")) {
1170           isOK = (load >> enfSeparator);
1171           if (enfSeparator != "__END_NAME__") {
1172             if (!enfName.empty())
1173               enfName += " ";
1174             enfName += enfSeparator;
1175           }
1176         }
1177         MESSAGE("enfName: " <<enfName);
1178       }
1179         
1180       if (enfSeparator == "__BEGIN_ENTRY__") {  // __BEGIN_ENTRY__
1181         isOK = (load >> enfGeomEntry);
1182         isOK = (load >> enfSeparator); // __END_ENTRY__
1183         if (enfSeparator != "__END_ENTRY__")
1184           throw std::exception::exception();
1185         MESSAGE("enfGeomEntry: " <<enfGeomEntry);
1186       }
1187         
1188       if (enfSeparator == "__BEGIN_GROUP__") {  // __BEGIN_GROUP__
1189         while (isOK && (enfSeparator != "__END_GROUP__")) {
1190           isOK = (load >> enfSeparator);
1191           if (enfSeparator != "__END_GROUP__") {
1192             if (!enfGroup.empty())
1193               enfGroup += " ";
1194             enfGroup += enfSeparator;
1195           }
1196         }
1197         MESSAGE("enfGroup: " <<enfGroup);
1198       }
1199         
1200       if (enfSeparator == "__BEGIN_COORDS__") {  // __BEGIN_COORDS__
1201         hasCoords = true;
1202         isOK = (load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
1203         isOK = (load >> enfSeparator); // __END_COORDS__
1204         if (enfSeparator != "__END_COORDS__")
1205           throw std::exception::exception();
1206         MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
1207       } 
1208         
1209       if (enfSeparator == "__BEGIN_FACELIST__") {  // __BEGIN_FACELIST__
1210         while (isOK && (enfSeparator != "__END_FACELIST__")) {
1211           isOK = (load >> enfSeparator);
1212           if (enfSeparator != "__END_FACELIST__") {
1213             enfFaceEntryList.insert(enfSeparator);
1214             MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
1215           }
1216         }
1217       } 
1218     }
1219   }
1220
1221   return load;
1222 }
1223
1224 //=============================================================================
1225 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
1226   return hyp.SaveTo(save);
1227 }
1228
1229 //=============================================================================
1230 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
1231   return hyp.LoadFrom(load);
1232 }
1233
1234 //================================================================================
1235 /*!
1236  * \brief Does nothing
1237  */
1238 //================================================================================
1239
1240 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
1241   return false;
1242 }
1243
1244 //=============================================================================
1245 /*!
1246  * \brief Initialize my parameter values by default parameters.
1247  *  \retval bool - true if parameter values have been successfully defined
1248  */
1249 //=============================================================================
1250
1251 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
1252   return bool(_phySize = dflts._elemLength);
1253 }
1254
1255 //=============================================================================
1256 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology() {
1257   return FromCAD;
1258 }
1259
1260 //=============================================================================
1261 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh() {
1262   return PhysicalUserDefined;
1263 }
1264
1265 //=============================================================================
1266 double BLSURFPlugin_Hypothesis::GetDefaultPhySize() {
1267   return 10;
1268 }
1269
1270 //======================================================================
1271 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize() {
1272   return undefinedDouble(); // 1e+4;
1273 }
1274
1275 //======================================================================
1276 double BLSURFPlugin_Hypothesis::GetDefaultMinSize() {
1277   return undefinedDouble(); //1e-4;
1278 }
1279
1280 //======================================================================
1281 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh() {
1282   return DefaultGeom;
1283 }
1284
1285 //=============================================================================
1286 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS() {
1287   return 8;
1288 }
1289
1290 //=============================================================================
1291 double BLSURFPlugin_Hypothesis::GetDefaultGradation() {
1292   return 1.1;
1293 }
1294
1295 //=============================================================================
1296 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed() {
1297   return false;
1298 }
1299
1300 //=============================================================================
1301 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh() {
1302   return false;
1303 }