]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx
Salome HOME
d7c494fe82affda5bc5019f76a29ac3301dded6d
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 "BLSURFPlugin_Attractor.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include <utilities.h>
31 #include <cstring>
32 #include <iostream>
33 #include <sstream>
34
35 // cascade include
36 #include "ShapeAnalysis.hxx"
37
38 // CORBA includes
39 #include CORBA_CLIENT_HEADER(SALOMEDS)
40 #include CORBA_CLIENT_HEADER(GEOM_Gen)
41
42 namespace
43 {
44   struct GET_DEFAULT // struct used to get default value from GetOptionValue()
45   {
46     bool isDefault;
47     operator bool* () { return &isDefault; }
48   };
49 }
50
51 //=============================================================================
52 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) :
53   SMESH_Hypothesis(hypId, studyId, gen), 
54   _physicalMesh(GetDefaultPhysicalMesh()),
55   _geometricMesh(GetDefaultGeometricMesh()),
56   _phySize(GetDefaultPhySize()),
57   _phySizeRel(GetDefaultPhySizeRel()),
58   _minSize(GetDefaultMinSize()),
59   _maxSize(GetDefaultMaxSize()),
60   _minSizeRel(GetDefaultMinSizeRel()),
61   _maxSizeRel(GetDefaultMaxSizeRel()),
62   _useGradation(GetDefaultUseGradation()),
63   _gradation(GetDefaultGradation()),
64   _useVolumeGradation(GetDefaultUseVolumeGradation()),
65   _volumeGradation(GetDefaultVolumeGradation()),
66   _quadAllowed(GetDefaultQuadAllowed()),
67   _angleMesh(GetDefaultAngleMesh()),
68   _chordalError(GetDefaultChordalError()), 
69   _anisotropic(GetDefaultAnisotropic()),
70   _anisotropicRatio(GetDefaultAnisotropicRatio()),
71   _removeTinyEdges(GetDefaultRemoveTinyEdges()),
72   _tinyEdgeLength(GetDefaultTinyEdgeLength()),
73   _optimiseTinyEdges(GetDefaultOptimiseTinyEdges()),
74   _tinyEdgeOptimisationLength(GetDefaultTinyEdgeOptimisationLength()),
75   _correctSurfaceIntersec(GetDefaultCorrectSurfaceIntersection()),
76   _corrSurfaceIntersCost(GetDefaultCorrectSurfaceIntersectionMaxCost()),
77   _badElementRemoval(GetDefaultBadElementRemoval()),
78   _badElementAspectRatio(GetDefaultBadElementAspectRatio()),
79   _optimizeMesh(GetDefaultOptimizeMesh()),
80   _quadraticMesh(GetDefaultQuadraticMesh()),
81   _verb(GetDefaultVerbosity()),
82   _topology(GetDefaultTopology()),
83   _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
84   _preCADRemoveTinyUVEdges(GetDefaultPreCADRemoveTinyUVEdges()),
85   _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
86   _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
87   _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
88   _sizeMap(GetDefaultSizeMap()),
89   _attractors(GetDefaultSizeMap()),
90   _classAttractors(GetDefaultAttractorMap()),
91   _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
92   _enfVertexList(GetDefaultEnfVertexList()),
93   _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
94   _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
95   _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
96   _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
97   _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
98   _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
99   _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
100   _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
101   _GMFFileName(GetDefaultGMFFile())
102 {
103   _name = GetHypType();
104   _param_algo_dim = 2;
105   
106 //   _GMFFileMode = false; // GMF ascii mode
107
108   // Advanced options with their defaults according to MG User Manual
109
110   const char* boolOptionNames[] = {         "enforce_cad_edge_sizes",                   // default = 0
111                                             // "correct_surface_intersections",            // default = 1
112                                             // "create_tag_on_collision",                  // default = 1
113                                             "jacobian_rectification_respect_geometry",  // default = 1
114                                             "rectify_jacobian",                         // default = 1
115                                             "respect_geometry",                         // default = 1
116                                             // "optimise_tiny_edges",                      // default = 0
117                                             // "remove_duplicate_cad_faces",               // default = 1
118                                             "tiny_edge_avoid_surface_intersections",    // default = 1
119                                             // "tiny_edge_respect_geometry",               // default = 0
120                                             "" // mark of end
121       };
122
123   const char* intOptionNames[] = {          "max_number_of_points_per_patch",           // default = 100000
124                                             "" // mark of end
125       };
126   const char* doubleOptionNames[] = {       // "surface_intersections_processing_max_cost",// default = 15
127                                             // "periodic_tolerance",                       // default = diag/100
128                                             // "volume_gradation",
129                                             // "tiny_edge_optimisation_length",            // default = diag * 1e-6
130                                             "" // mark of end
131       };
132   const char* charOptionNames[] = {         // "required_entities",                        // default = "respect"
133                                             // "tags",                                     // default = "respect"
134                                             "" // mark of end
135       };
136
137   // PreCAD advanced options
138   const char* preCADboolOptionNames[] = {   "closed_geometry",                          // default = 0
139                                             "discard_input_topology",                   // default = 0
140                                             "merge_edges",                              // default =  = 1
141                                             "remove_duplicate_cad_faces",               // default = 1
142                                             // "create_tag_on_collision",                  // default = 1
143                                             "debug",                                    // default = 0 
144                                             // "remove_tiny_edges",                        // default = 0
145                                             "" // mark of end
146       };
147   const char* preCADintOptionNames[] = {    // "manifold_geometry",                        // default = 0
148                                             "" // mark of end
149       };
150   const char* preCADdoubleOptionNames[] = { "periodic_tolerance",                       // default = diag * 1e-5
151                                             "sewing_tolerance",                         // default = diag * 5e-4
152                                             // "tiny_edge_length",                         // default = diag * 1e-5
153                                             "" // mark of end
154       };
155   const char* preCADcharOptionNames[] = {   "required_entities",                        // default = "respect"
156                                             "tags",                                     // default = "respect"
157                                             "" // mark of end
158       };
159   
160   int i = 0;
161   while (boolOptionNames[i][0])
162   {
163     _boolOptions.insert( boolOptionNames[i] );
164     _option2value[boolOptionNames[i++]].clear();
165   }
166   i = 0;
167   while (preCADboolOptionNames[i][0])
168   {
169     _boolOptions.insert( preCADboolOptionNames[i] );
170     _preCADoption2value[preCADboolOptionNames[i++]].clear();
171   }
172   i = 0;
173   while (intOptionNames[i][0])
174     _option2value[intOptionNames[i++]].clear();
175   
176   i = 0;
177   while (preCADintOptionNames[i][0])
178     _preCADoption2value[preCADintOptionNames[i++]].clear();
179
180   i = 0;
181   while (doubleOptionNames[i][0]) {
182     _doubleOptions.insert(doubleOptionNames[i]);
183     _option2value[doubleOptionNames[i++]].clear();
184   }
185   i = 0;
186   while (preCADdoubleOptionNames[i][0]) {
187     _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
188     _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
189   }
190   i = 0;
191   while (charOptionNames[i][0]) {
192     _charOptions.insert(charOptionNames[i]);
193     _option2value[charOptionNames[i++]].clear();
194   }
195   i = 0;
196   while (preCADcharOptionNames[i][0]) {
197     _preCADcharOptions.insert(preCADcharOptionNames[i]);
198     _preCADoption2value[preCADcharOptionNames[i++]].clear();
199   }
200
201   // default values to be used while MG meshing
202
203   _defaultOptionValues["enforce_cad_edge_sizes"                 ] = "no";
204   _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
205   _defaultOptionValues["max_number_of_points_per_patch"         ] = "0";
206   _defaultOptionValues["rectify_jacobian"                       ] = "yes";
207   _defaultOptionValues["respect_geometry"                       ] = "yes";
208   _defaultOptionValues["tiny_edge_avoid_surface_intersections"  ] = "yes";
209   _defaultOptionValues["closed_geometry"                        ] = "no";
210   _defaultOptionValues["debug"                                  ] = "no";
211   _defaultOptionValues["discard_input_topology"                 ] = "no";
212   _defaultOptionValues["merge_edges"                            ] = "no";
213   _defaultOptionValues["periodic_tolerance"                     ] = "1e-5*D";
214   _defaultOptionValues["remove_duplicate_cad_faces"             ] = "no";
215   _defaultOptionValues["required_entities"                      ] = "respect";
216   _defaultOptionValues["sewing_tolerance"                       ] = "5e-4*D";
217   _defaultOptionValues["tags"                                   ] = "respect";
218
219 #ifdef _DEBUG_
220   // check validity of option names of _defaultOptionValues
221   TOptionValues::iterator n2v = _defaultOptionValues.begin();
222   for ( ; n2v != _defaultOptionValues.end(); ++n2v )
223     ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
224   ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
225 #endif
226       
227   _sizeMap.clear();
228   _attractors.clear();
229   _faceEntryEnfVertexListMap.clear();
230   _enfVertexList.clear();
231   _faceEntryCoordsListMap.clear();
232   _coordsEnfVertexMap.clear();
233   _faceEntryEnfVertexEntryListMap.clear();
234   _enfVertexEntryEnfVertexMap.clear();
235   _groupNameNodeIDMap.clear();
236
237   /* TODO GROUPS
238    _groupNameEnfVertexListMap.clear();
239    _enfVertexGroupNameMap.clear();
240    */
241 }
242
243 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
244 {
245   MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
246   GEOM::GEOM_Object_var aGeomObj;
247   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
248   SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
249   
250   TopoDS_Shape S = TopoDS_Shape();
251   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
252   if (!aSObj->_is_nil() ) {
253     CORBA::Object_var obj = aSObj->GetObject();
254     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
255     aSObj->UnRegister();
256   }
257   if ( !aGeomObj->_is_nil() )
258     S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
259   return S;
260 }
261
262 //=============================================================================
263 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
264   if (thePhysicalMesh != _physicalMesh) {
265     _physicalMesh = thePhysicalMesh;
266     NotifySubMeshesHypothesisModification();
267   }
268 }
269
270 //=============================================================================
271 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
272   if (theGeometricMesh != _geometricMesh) {
273     _geometricMesh = theGeometricMesh;
274 //     switch (_geometricMesh) {
275 //       case DefaultGeom:
276 //       default:
277 //         _angleMesh = GetDefaultAngleMesh();
278 //         _gradation = GetDefaultGradation();
279 //         break;
280 //     }
281     NotifySubMeshesHypothesisModification();
282   }
283 }
284
285 //=============================================================================
286 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
287   if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
288     _phySizeRel = isRelative;
289     if (theVal == 0) {
290       _phySize = GetMaxSize();
291       MESSAGE("Warning: nul physical size is not allowed");
292     }
293     else
294       _phySize = theVal;
295     NotifySubMeshesHypothesisModification();
296   }
297 }
298
299 //=============================================================================
300 void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
301   if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
302     _minSizeRel = isRelative;
303     _minSize = theMinSize;
304     NotifySubMeshesHypothesisModification();
305   }
306 }
307
308 //=============================================================================
309 void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
310   if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
311     _maxSizeRel = isRelative;
312     _maxSize = theMaxSize;
313     NotifySubMeshesHypothesisModification();
314   }
315 }
316
317 //=============================================================================
318 void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal) {
319   if (theVal != _useGradation) {
320     _useGradation = theVal;
321     NotifySubMeshesHypothesisModification();
322   }
323 }
324
325 //=============================================================================
326 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
327   _useGradation = ( theVal > 0 );
328   if (theVal != _gradation) {
329     _gradation = theVal;
330     NotifySubMeshesHypothesisModification();
331   }
332 }
333
334 //=============================================================================
335 void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal) {
336   if (theVal != _useVolumeGradation) {
337     _useVolumeGradation = theVal;
338     NotifySubMeshesHypothesisModification();
339   }
340 }
341
342 //=============================================================================
343 void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
344   _useVolumeGradation = ( theVal > 0 );
345   if (theVal != _volumeGradation) {
346     _volumeGradation = theVal;
347     NotifySubMeshesHypothesisModification();
348   }
349 }
350
351 //=============================================================================
352 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
353   if (theVal != _quadAllowed) {
354     _quadAllowed = theVal;
355     NotifySubMeshesHypothesisModification();
356   }
357 }
358
359 //=============================================================================
360 void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
361   if (theVal != _angleMesh) {
362     _angleMesh = theVal;
363     NotifySubMeshesHypothesisModification();
364   }
365 }
366
367 //=============================================================================
368 void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
369   if (theDistance != _chordalError) {
370     _chordalError = theDistance;
371     NotifySubMeshesHypothesisModification();
372   }
373 }
374
375 //=============================================================================
376 void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
377   if (theVal != _anisotropic) {
378     _anisotropic = theVal;
379     NotifySubMeshesHypothesisModification();
380   }
381 }
382
383 //=============================================================================
384 void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
385   if (theVal != _anisotropicRatio) {
386     _anisotropicRatio = theVal;
387     NotifySubMeshesHypothesisModification();
388   }
389 }
390
391 //=============================================================================
392 void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
393   if (theVal != _removeTinyEdges) {
394     _removeTinyEdges = theVal;
395     NotifySubMeshesHypothesisModification();
396   }
397 }
398
399 //=============================================================================
400 void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
401   if (theVal != _tinyEdgeLength) {
402     _tinyEdgeLength = theVal;
403     NotifySubMeshesHypothesisModification();
404   }
405 }
406
407 //=============================================================================
408 void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal) {
409   if (theVal != _optimiseTinyEdges) {
410     _optimiseTinyEdges = theVal;
411     NotifySubMeshesHypothesisModification();
412   }
413 }
414
415 //=============================================================================
416 void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal) {
417   if (theVal != _tinyEdgeOptimisationLength) {
418     _tinyEdgeOptimisationLength = theVal;
419     NotifySubMeshesHypothesisModification();
420   }
421 }
422
423 //=============================================================================
424 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal) {
425   if (theVal != _correctSurfaceIntersec) {
426     _correctSurfaceIntersec = theVal;
427     NotifySubMeshesHypothesisModification();
428   }
429 }
430
431 //=============================================================================
432 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal) {
433   if (theVal != _corrSurfaceIntersCost) {
434     _corrSurfaceIntersCost = theVal;
435     NotifySubMeshesHypothesisModification();
436   }
437 }
438
439 //=============================================================================
440 void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
441   if (theVal != _badElementRemoval) {
442     _badElementRemoval = theVal;
443     NotifySubMeshesHypothesisModification();
444   }
445 }
446
447 //=============================================================================
448 void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
449   if (theVal != _badElementAspectRatio) {
450     _badElementAspectRatio = theVal;
451     NotifySubMeshesHypothesisModification();
452   }
453 }
454
455 //=============================================================================
456 void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
457   if (theVal != _optimizeMesh) {
458     _optimizeMesh = theVal;
459     NotifySubMeshesHypothesisModification();
460   }
461 }
462
463 //=============================================================================
464 void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
465   if (theVal != _quadraticMesh) {
466     _quadraticMesh = theVal;
467     NotifySubMeshesHypothesisModification();
468   }
469 }
470
471 //=============================================================================
472 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
473   if (theTopology != _topology) {
474     _topology = theTopology;
475     NotifySubMeshesHypothesisModification();
476   }
477 }
478
479 //=============================================================================
480 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
481   if (theVal != _verb) {
482     _verb = theVal;
483     NotifySubMeshesHypothesisModification();
484   }
485 }
486
487 //=============================================================================
488 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
489 {
490   if ( GetEnforceCadEdgesSize() != toEnforce )
491   {
492     SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
493     NotifySubMeshesHypothesisModification();
494   }
495 }
496 //=============================================================================
497 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
498 {
499   return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
500 }
501 //=============================================================================
502
503 void BLSURFPlugin_Hypothesis::SetJacobianRectificationRespectGeometry( bool allowRectification )
504 {
505   if ( GetJacobianRectificationRespectGeometry() != allowRectification )
506   {
507     SetOptionValue("jacobian_rectification_respect_geometry", allowRectification ? "yes" : "no" );
508     NotifySubMeshesHypothesisModification();
509   }
510 }
511 //=============================================================================
512 bool BLSURFPlugin_Hypothesis::GetJacobianRectificationRespectGeometry()
513 {
514   return ToBool( GetOptionValue("jacobian_rectification_respect_geometry", GET_DEFAULT()));
515 }
516 //=============================================================================
517
518 void BLSURFPlugin_Hypothesis::SetJacobianRectification( bool allowRectification )
519 {
520   if ( GetJacobianRectification() != allowRectification )
521   {
522     SetOptionValue( "rectify_jacobian", allowRectification ? "yes" : "no" );
523     NotifySubMeshesHypothesisModification();
524   }
525 }
526 //=============================================================================
527 bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
528 {
529   return ToBool( GetOptionValue("rectify_jacobian", GET_DEFAULT()));
530 }
531 //=============================================================================
532
533 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
534   throw (std::invalid_argument)
535 {
536   if ( nb < 0 )
537     throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
538
539   if ( GetMaxNumberOfPointsPerPatch() != nb )
540   {
541     SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
542     NotifySubMeshesHypothesisModification();
543   }
544 }
545 //=============================================================================
546 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
547 {
548   return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
549 }
550 //=============================================================================
551
552 void BLSURFPlugin_Hypothesis::SetRespectGeometry( bool toRespect )
553 {
554   if ( GetRespectGeometry() != toRespect )
555   {
556     SetOptionValue("respect_geometry", toRespect ? "yes" : "no" );
557     NotifySubMeshesHypothesisModification();
558   }
559 }
560 //=============================================================================
561 bool BLSURFPlugin_Hypothesis::GetRespectGeometry()
562 {
563   return ToBool( GetOptionValue( "respect_geometry", GET_DEFAULT()));
564 }
565 //=============================================================================
566
567 void BLSURFPlugin_Hypothesis::SetTinyEdgesAvoidSurfaceIntersections( bool toAvoidIntersection )
568 {
569   if ( GetTinyEdgesAvoidSurfaceIntersections() != toAvoidIntersection )
570   {
571     SetOptionValue("tiny_edge_avoid_surface_intersections", toAvoidIntersection ? "yes" : "no" );
572     NotifySubMeshesHypothesisModification();
573   }
574 }
575 //=============================================================================
576 bool BLSURFPlugin_Hypothesis::GetTinyEdgesAvoidSurfaceIntersections()
577 {
578   return ToBool( GetOptionValue("tiny_edge_avoid_surface_intersections", GET_DEFAULT()));
579 }
580 //=============================================================================
581
582 void BLSURFPlugin_Hypothesis::SetClosedGeometry( bool isClosed )
583 {
584   if ( GetClosedGeometry() != isClosed )
585   {
586     SetPreCADOptionValue("closed_geometry", isClosed ? "yes" : "no" );
587     NotifySubMeshesHypothesisModification();
588   }
589 }
590 //=============================================================================
591 bool BLSURFPlugin_Hypothesis::GetClosedGeometry()
592 {
593   return ToBool( GetPreCADOptionValue( "closed_geometry", GET_DEFAULT()));
594 }
595 //=============================================================================
596
597 void BLSURFPlugin_Hypothesis::SetDebug( bool isDebug )
598 {
599   if ( GetDebug() != isDebug )
600   {
601     SetPreCADOptionValue("debug", isDebug ? "yes" : "no" );
602     NotifySubMeshesHypothesisModification();
603   }
604 }
605 //=============================================================================
606 bool BLSURFPlugin_Hypothesis::GetDebug()
607 {
608   return ToBool( GetPreCADOptionValue("debug", GET_DEFAULT()));
609 }
610 //=============================================================================
611
612 void BLSURFPlugin_Hypothesis::SetPeriodicTolerance( CORBA::Double tol )
613   throw (std::invalid_argument)
614 {
615   if ( tol <= 0 )
616     throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
617   if ( GetPeriodicTolerance() != tol )
618   {
619     SetPreCADOptionValue("periodic_tolerance", SMESH_Comment( tol ) );
620     NotifySubMeshesHypothesisModification();
621   }
622 }
623 //=============================================================================
624 double BLSURFPlugin_Hypothesis::GetPeriodicTolerance()
625 {
626   return ToDbl( GetPreCADOptionValue( "periodic_tolerance", GET_DEFAULT()));
627 }
628 //=============================================================================
629
630 void BLSURFPlugin_Hypothesis::SetRequiredEntities( const std::string& howToTreat )
631   throw (std::invalid_argument)
632 {
633   if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear"  )
634     throw std::invalid_argument
635       ( SMESH_Comment("required_entities must be in ['respect','ignore','clear'] "));
636
637   if ( GetRequiredEntities() != howToTreat )
638   {
639     SetPreCADOptionValue("required_entities", howToTreat );
640     NotifySubMeshesHypothesisModification();
641   }
642 }
643 //=============================================================================
644 std::string BLSURFPlugin_Hypothesis::GetRequiredEntities()
645 {
646   return GetPreCADOptionValue("required_entities", GET_DEFAULT());
647 }
648 //=============================================================================
649
650 void BLSURFPlugin_Hypothesis::SetSewingTolerance( CORBA::Double tol )
651   throw (std::invalid_argument)
652 {
653   if ( tol <= 0 )
654     throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
655   if ( GetSewingTolerance() != tol )
656   {
657     SetPreCADOptionValue("sewing_tolerance", SMESH_Comment( tol ) );
658     NotifySubMeshesHypothesisModification();
659   }
660 }
661 //=============================================================================
662 CORBA::Double BLSURFPlugin_Hypothesis::GetSewingTolerance()
663 {
664   return ToDbl( GetPreCADOptionValue("sewing_tolerance", GET_DEFAULT()));
665 }
666 //=============================================================================
667
668 void BLSURFPlugin_Hypothesis::SetTags( const std::string& howToTreat )
669   throw (std::invalid_argument)
670 {
671   if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear"  )
672     throw std::invalid_argument
673       ( SMESH_Comment("'tags' must be in ['respect','ignore','clear'] "));
674
675   if ( GetTags() != howToTreat )
676   {
677     SetPreCADOptionValue("tags", howToTreat );
678     NotifySubMeshesHypothesisModification();
679   }
680 }
681 //=============================================================================
682 std::string BLSURFPlugin_Hypothesis::GetTags()
683 {
684   return GetPreCADOptionValue("tags", GET_DEFAULT());
685 }
686 //=============================================================================
687 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
688 {
689   if (theVal != _preCADMergeEdges) {
690 //     SetTopology(PreCAD);
691     _preCADMergeEdges = theVal;
692     SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
693     NotifySubMeshesHypothesisModification();
694   }
695 }
696
697 //=============================================================================
698 void BLSURFPlugin_Hypothesis::SetPreCADRemoveTinyUVEdges(bool theVal)
699 {
700   if (theVal != _preCADRemoveTinyUVEdges) {
701 //     SetTopology(PreCAD);
702     _preCADRemoveTinyUVEdges = theVal;
703     NotifySubMeshesHypothesisModification();
704   }
705 }
706
707 //=============================================================================
708 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
709 {
710   if (theVal != _preCADRemoveDuplicateCADFaces) {
711     //     SetTopology(PreCAD);
712     _preCADRemoveDuplicateCADFaces = theVal;
713     SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
714     NotifySubMeshesHypothesisModification();
715   }
716 }
717
718 //=============================================================================
719 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
720 {
721   if (theVal != _preCADProcess3DTopology) {
722     //     SetTopology(PreCAD);
723     _preCADProcess3DTopology = theVal;
724     AddPreCADOption("process_3d_topology", theVal ? "yes" : "no" );
725     NotifySubMeshesHypothesisModification();
726   }
727 }
728
729 //=============================================================================
730 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
731 {
732   if (theVal != _preCADDiscardInput) {
733     //     SetTopology(PreCAD);
734     _preCADDiscardInput = theVal;
735     SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
736     NotifySubMeshesHypothesisModification();
737   }
738 }
739
740 //=============================================================================
741 // Return true if any PreCAD option is activated
742 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
743 {
744   if ( !hyp )
745   {
746     return false;
747   }
748   bool orDefault, isOk;
749   return ( ToBool( hyp->GetPreCADOptionValue("closed_geometry"           , &orDefault )) ||
750            ToBool( hyp->GetPreCADOptionValue("discard_input_topology"    , &orDefault )) ||
751            ToBool( hyp->GetPreCADOptionValue("merge_edges"               , &orDefault )) ||
752            ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
753            ToBool( hyp->GetPreCADOption     ("process_3d_topology")      , &isOk       ) ||
754            ToBool( hyp->GetPreCADOption     ("manifold_geometry")        , &isOk       ) ||
755            hyp->GetPreCADOptionValue("sewing_tolerance") != "5e-4*D"                     ||
756            hyp->GetPreCADProcess3DTopology() );
757 }
758
759 //=============================================================================
760 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
761 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
762 {
763   _GMFFileName = theFileName;
764   //   _GMFFileMode = isBinary;
765   NotifySubMeshesHypothesisModification();
766 }
767
768 //=============================================================================
769 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
770   throw (std::invalid_argument) {
771
772   TOptionValues::iterator op_val = _option2value.find(optionName);
773   if (op_val == _option2value.end())
774   {
775     op_val = _preCADoption2value.find(optionName);
776     if (op_val == _preCADoption2value.end())
777     {
778       std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
779       throw std::invalid_argument(msg);
780     }
781   }
782   if (op_val->second != optionValue)
783   {
784     const char* ptr = optionValue.c_str();
785     // strip white spaces
786     while (ptr[0] == ' ')
787       ptr++;
788     int i = strlen(ptr);
789     while (i != 0 && ptr[i - 1] == ' ')
790       i--;
791     // check value type
792     bool typeOk = true;
793     std::string typeName;
794     if (i == 0) {
795       // empty string
796     } else if (_charOptions.count(optionName)) {
797       // do not check strings
798     } else if (_doubleOptions.count(optionName)) {
799       // check if value is double
800       ToDbl(ptr, &typeOk);
801       typeName = "real";
802     } else if (_boolOptions.count(optionName)) {
803       // check if value is bool
804       ToBool(ptr, &typeOk);
805       typeName = "bool";
806     } else {
807       // check if value is int
808       ToInt(ptr, &typeOk);
809       typeName = "integer";
810     }
811     if (!typeOk) {
812       std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
813       throw std::invalid_argument(msg);
814     }
815     std::string value( ptr, i );
816     if ( _defaultOptionValues[ optionName ] == value )
817       value.clear();
818
819     op_val->second = value;
820
821     NotifySubMeshesHypothesisModification();
822   }
823 }
824
825 //=============================================================================
826 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
827   throw (std::invalid_argument) {
828
829   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
830   if (op_val == _preCADoption2value.end()) {
831     op_val = _option2value.find(optionName);
832     if (op_val == _option2value.end()) {
833       std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
834       throw std::invalid_argument(msg);
835     }
836   }
837   if (op_val->second != optionValue)
838   {
839     const char* ptr = optionValue.c_str();
840     // strip white spaces
841     while (ptr[0] == ' ')
842       ptr++;
843     int i = strlen(ptr);
844     while (i != 0 && ptr[i - 1] == ' ')
845       i--;
846     // check value type
847     bool typeOk = true;
848     std::string typeName;
849     if (i == 0) {
850       // empty string
851     } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
852       // do not check strings
853     } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
854       // check if value is double
855       char * endPtr;
856       strtod(ptr, &endPtr);
857       typeOk = (ptr != endPtr);
858       typeName = "real";
859     } else if (_boolOptions.count(optionName)) {
860       // check if value is bool
861       ToBool(ptr, &typeOk);
862       typeName = "bool";
863     } else {
864       // check if value is int
865       char * endPtr;
866       strtol(ptr, &endPtr, 10);
867       typeOk = (ptr != endPtr);
868       typeName = "integer";
869     }
870     if (!typeOk) {
871       std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
872       throw std::invalid_argument(msg);
873     }
874     std::string value( ptr, i );
875     if ( _defaultOptionValues[ optionName ] == value )
876       value.clear();
877
878     op_val->second = value;
879
880     NotifySubMeshesHypothesisModification();
881   }
882 }
883
884 //=============================================================================
885 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
886                                                     bool*              isDefault) const
887   throw (std::invalid_argument)
888 {
889   TOptionValues::const_iterator op_val = _option2value.find(optionName);
890   if (op_val == _option2value.end())
891   {
892     op_val = _preCADoption2value.find(optionName);
893     if (op_val == _preCADoption2value.end())
894     {
895       op_val = _customOption2value.find(optionName);
896       if (op_val == _customOption2value.end())
897       {
898         std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
899         throw std::invalid_argument(msg);
900       }
901     }
902   }
903   std::string val = op_val->second;
904   if ( isDefault ) *isDefault = ( val.empty() );
905
906   if ( val.empty() && isDefault )
907   {
908     op_val = _defaultOptionValues.find( optionName );
909     if (op_val != _defaultOptionValues.end())
910       val = op_val->second;
911   }
912   return val;
913 }
914
915 //=============================================================================
916 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
917                                                           bool*              isDefault) const
918   throw (std::invalid_argument)
919 {
920   TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
921   if (op_val == _preCADoption2value.end())
922   {
923     op_val = _option2value.find(optionName);
924     if (op_val == _option2value.end())
925     {
926       op_val = _customOption2value.find(optionName);
927       if (op_val == _customOption2value.end())
928       {
929         std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
930         throw std::invalid_argument(msg);
931       }
932     }
933   }
934   std::string val = op_val->second;
935   if ( isDefault ) *isDefault = ( val.empty() );
936
937   if ( val.empty() && isDefault )
938   {
939     op_val = _defaultOptionValues.find( optionName );
940     if (op_val != _option2value.end())
941       val = op_val->second;
942   }
943   return val;
944 }
945
946 //=============================================================================
947 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
948 {
949   TOptionValues::iterator op_val = _customOption2value.find(optionName);
950   if (op_val != _customOption2value.end())
951    _customOption2value.erase(op_val);
952   else {
953     op_val = _option2value.find(optionName);
954     if (op_val != _option2value.end())
955       op_val->second.clear();
956     else {
957       op_val = _preCADoption2value.find(optionName);
958       if (op_val != _preCADoption2value.end())
959         op_val->second.clear();
960     }
961   }
962 }
963
964 //=============================================================================
965 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
966 {
967   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
968   if (op_val != _preCADoption2value.end())
969     op_val->second.clear();
970 }
971
972 //=============================================================================
973 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
974 {
975   bool modif = true;
976   TOptionValues::iterator op_val = _option2value.find(optionName);
977   if (op_val != _option2value.end())
978   {
979     if (op_val->second != optionValue)
980       op_val->second = optionValue;
981     else
982       modif = false;
983   }
984   else
985   {
986     op_val = _preCADoption2value.find(optionName);
987     if (op_val != _preCADoption2value.end())
988     {
989       if (op_val->second != optionValue)
990         op_val->second = optionValue;
991       else
992         modif = false;
993     }
994     else if ( optionValue.empty() )
995     {
996       _customOption2value.erase( optionName );
997     }
998     else
999     {
1000       op_val = _customOption2value.find(optionName);
1001       if (op_val == _customOption2value.end())
1002         _customOption2value[optionName] = optionValue;
1003       else if (op_val->second != optionValue)
1004         op_val->second = optionValue;
1005       else
1006         modif = false;
1007     }
1008   }
1009   if ( modif )
1010     NotifySubMeshesHypothesisModification();
1011 }
1012
1013 //=============================================================================
1014 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1015 {
1016   AddOption( optionName, optionValue );
1017 }
1018
1019 //=============================================================================
1020 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1021 {
1022   TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1023   if (op_val != _customOption2value.end())
1024     return op_val->second;
1025   else
1026     return "";
1027 }
1028
1029 //=============================================================================
1030 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1031 {
1032   TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1033   if (op_val != _customOption2value.end())
1034     return op_val->second;
1035   else
1036     return "";
1037 }
1038
1039 //=============================================================================
1040 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1041 {
1042   TOptionValues vals;
1043   TOptionValues::const_iterator op_val = _option2value.begin();
1044   for ( ; op_val != _option2value.end(); ++op_val )
1045     vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1046
1047   return vals;
1048 }
1049
1050 //=============================================================================
1051 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1052 {
1053   TOptionValues vals;
1054   TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1055   for ( ; op_val != _preCADoption2value.end(); ++op_val )
1056     vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1057
1058   return vals;
1059 }
1060
1061 //=======================================================================
1062 //function : SetSizeMapEntry
1063 //=======================================================================
1064 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1065   if (_sizeMap[entry].compare(sizeMap) != 0) {
1066     SetPhysicalMesh(PhysicalLocalSize);
1067     _sizeMap[entry] = sizeMap;
1068     NotifySubMeshesHypothesisModification();
1069   }
1070 }
1071
1072 //=======================================================================
1073 //function : GetSizeMapEntry
1074 //=======================================================================
1075 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1076   TSizeMap::iterator it = _sizeMap.find(entry);
1077   if (it != _sizeMap.end())
1078     return it->second;
1079   else
1080     return "No_Such_Entry";
1081 }
1082
1083 /*!
1084  * \brief Return the size maps
1085  */
1086 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1087   return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1088 }
1089
1090 //=======================================================================
1091 //function : SetAttractorEntry
1092 //=======================================================================
1093 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1094   if (_attractors[entry].compare(attractor) != 0) {
1095     SetPhysicalMesh(PhysicalLocalSize);
1096     _attractors[entry] = attractor;
1097     NotifySubMeshesHypothesisModification();
1098   }
1099 }
1100
1101 //=======================================================================
1102 //function : GetAttractorEntry
1103 //=======================================================================
1104 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1105   TSizeMap::iterator it = _attractors.find(entry);
1106   if (it != _attractors.end())
1107     return it->second;
1108   else
1109     return "No_Such_Entry";
1110 }
1111
1112 /*!
1113  * \brief Return the attractors
1114  */
1115 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1116   return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1117 }
1118
1119 //=======================================================================
1120 //function : SetClassAttractorEntry
1121 //=======================================================================
1122 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1123 {
1124   SetPhysicalMesh(PhysicalLocalSize);
1125
1126   // The new attractor can't be defined on the same face as another sizemap
1127   TSizeMap::iterator it  = _sizeMap.find( entry );
1128   if ( it != _sizeMap.end() ) {
1129     _sizeMap.erase(it);
1130     NotifySubMeshesHypothesisModification();
1131   }
1132   else {
1133     TSizeMap::iterator itAt  = _attractors.find( entry );
1134     if ( itAt != _attractors.end() ) {
1135       _attractors.erase(itAt);
1136       NotifySubMeshesHypothesisModification();
1137     }
1138   }
1139   
1140   const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1141   const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1142   TAttractorMap::iterator attIt = _classAttractors.find(entry);
1143   for ( ; attIt != _classAttractors.end(); ++attIt )
1144     if ( attIt->first == entry && 
1145          attIt->second->GetAttractorEntry() == attEntry )
1146       break;
1147   bool attExists = (attIt != _classAttractors.end());
1148
1149   BLSURFPlugin_Attractor* myAttractor;
1150   if ( !attExists ) {
1151     myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1152     _classAttractors.insert( make_pair( entry, myAttractor ));
1153   }
1154   else {
1155     myAttractor = attIt->second;
1156   }
1157   // if (!myAttractor->IsMapBuilt())
1158   //   myAttractor->BuildMap();
1159   myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1160
1161   NotifySubMeshesHypothesisModification();
1162 }
1163
1164 //=======================================================================
1165 //function : SetConstantSizeOnAdjacentFaces
1166 //=======================================================================
1167 // TODO uncomment and test (include the needed .hxx)
1168 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist  ) {
1169 //   TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1170 //   TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1171 //   TopTools_IndexedMapOfShapListOdShape::iterator it;
1172 //   for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1173 //       SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1174 //   }
1175
1176
1177
1178
1179
1180
1181 //=======================================================================
1182 //function : GetClassAttractorEntry
1183 //=======================================================================
1184 // BLSURFPlugin_Attractor&  BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1185 // {
1186 //  TAttractorMap::iterator it  = _classAttractors.find( entry );
1187 //  if ( it != _classAttractors.end() )
1188 //    return it->second;
1189 //  else
1190 //    return "No_Such_Entry";
1191 // }
1192 // 
1193   /*!
1194    * \brief Return the map of attractor instances
1195    */
1196 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1197 {
1198     return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1199 }
1200
1201 //=======================================================================
1202 //function : ClearEntry
1203 //=======================================================================
1204 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1205                                          const char * attEntry/*=0*/)
1206 {
1207  TSizeMap::iterator it  = _sizeMap.find( entry );
1208  
1209  if ( it != _sizeMap.end() ) {
1210    _sizeMap.erase(it);
1211    NotifySubMeshesHypothesisModification();
1212  }
1213  else {
1214    TSizeMap::iterator itAt  = _attractors.find( entry );
1215    if ( itAt != _attractors.end() ) {
1216      _attractors.erase(itAt);
1217      NotifySubMeshesHypothesisModification();
1218    }
1219    else {
1220      TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1221      if ( it_clAt != _classAttractors.end() ) {
1222        do {
1223          if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1224            _classAttractors.erase( it_clAt++ );
1225          else
1226            ++it_clAt;
1227        }
1228        while ( it_clAt != _classAttractors.end() );
1229        MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
1230        NotifySubMeshesHypothesisModification();
1231      }
1232      else
1233        std::cout<<"No_Such_Entry"<<std::endl;
1234    }
1235  }
1236 }
1237
1238 //=======================================================================
1239 //function : ClearSizeMaps
1240 //=======================================================================
1241 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1242   _sizeMap.clear();
1243   _attractors.clear();
1244   _classAttractors.clear();
1245 }
1246
1247 // Enable internal enforced vertices on specific face if requested by user
1248
1249 ////=======================================================================
1250 ////function : SetInternalEnforcedVertex
1251 ////=======================================================================
1252 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1253 //                                                        bool toEnforceInternalVertices,
1254 //                                                        TEnfGroupName theGroupName) {
1255
1256 //  MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
1257 //      << toEnforceInternalVertices << ", " << theGroupName << ")");
1258   
1259 //  TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1260 //  if (it != _faceEntryInternalVerticesList.end()) {
1261 //    if (!toEnforceInternalVertices) {
1262 //      _faceEntryInternalVerticesList.erase(it);
1263 //    }
1264 //  }
1265 //  else {
1266 //    if (toEnforceInternalVertices) {
1267 //      _faceEntryInternalVerticesList.insert(theFaceEntry);
1268 //    }
1269 //  }
1270   
1271 //  // TODO
1272 //  // Take care of groups
1273 //}
1274
1275
1276 //=======================================================================
1277 //function : SetEnforcedVertex
1278 //=======================================================================
1279 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
1280                                                 TEnfGroupName theGroupName, double x, double y, double z) {
1281
1282   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
1283       << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
1284
1285   SetPhysicalMesh(PhysicalLocalSize);
1286
1287   //  TEnfVertexList::iterator it;
1288   bool toNotify = false;
1289   bool toCreate = true;
1290
1291   TEnfVertex *oldEnVertex;
1292   TEnfVertex *newEnfVertex = new TEnfVertex();
1293   newEnfVertex->name = theVertexName;
1294   newEnfVertex->geomEntry = theVertexEntry;
1295   newEnfVertex->coords.clear();
1296   if (theVertexEntry == "") {
1297     newEnfVertex->coords.push_back(x);
1298     newEnfVertex->coords.push_back(y);
1299     newEnfVertex->coords.push_back(z);
1300   }
1301   newEnfVertex->grpName = theGroupName;
1302   newEnfVertex->faceEntries.clear();
1303   newEnfVertex->faceEntries.insert(theFaceEntry);
1304   
1305   
1306   // update _enfVertexList
1307   TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1308   if (it != _enfVertexList.end()) {
1309     toCreate = false;
1310     oldEnVertex = (*it);
1311     MESSAGE("Enforced Vertex was found => Update");
1312     if (oldEnVertex->name != theVertexName) {
1313       MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
1314       oldEnVertex->name = theVertexName;
1315       toNotify = true;
1316     }
1317     if (oldEnVertex->grpName != theGroupName) {
1318       MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
1319       oldEnVertex->grpName = theGroupName;
1320       toNotify = true;
1321     }
1322     TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1323     if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1324       MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
1325       oldEnVertex->faceEntries.insert(theFaceEntry);
1326       _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1327       toNotify = true;
1328     }
1329     if (toNotify) {
1330       // update map coords / enf vertex if needed
1331       if (oldEnVertex->coords.size()) {
1332         _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1333         _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1334       }
1335
1336       // update map geom entry / enf vertex if needed
1337       if (oldEnVertex->geomEntry != "") {
1338         _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1339         _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1340       }
1341     }
1342   }
1343
1344 //   //////// CREATE ////////////
1345   if (toCreate) {
1346     toNotify = true;
1347     MESSAGE("Creating new enforced vertex");
1348     _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1349     _enfVertexList.insert(newEnfVertex);
1350     if (theVertexEntry == "") {
1351       _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1352       _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1353     }
1354     else {
1355       _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1356       _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1357     }
1358   }
1359
1360   if (toNotify)
1361     NotifySubMeshesHypothesisModification();
1362
1363   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
1364   return toNotify;
1365 }
1366
1367
1368 //=======================================================================
1369 //function : GetEnforcedVertices
1370 //=======================================================================
1371
1372 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1373     throw (std::invalid_argument) {
1374
1375   if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1376     return _faceEntryEnfVertexListMap[theFaceEntry];
1377   else
1378     return GetDefaultEnfVertexList();
1379
1380   std::ostringstream msg;
1381   msg << "No enforced vertex for face entry " << theFaceEntry;
1382   throw std::invalid_argument(msg.str());
1383 }
1384
1385 //=======================================================================
1386 //function : GetEnfVertexCoordsList
1387 //=======================================================================
1388
1389 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1390     const TEntry& theFaceEntry) throw (std::invalid_argument) {
1391
1392   if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1393     return _faceEntryCoordsListMap[theFaceEntry];
1394
1395   std::ostringstream msg;
1396   msg << "No enforced vertex coords for face entry " << theFaceEntry;
1397   throw std::invalid_argument(msg.str());
1398 }
1399
1400 //=======================================================================
1401 //function : GetEnfVertexEntryList
1402 //=======================================================================
1403
1404 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1405     throw (std::invalid_argument) {
1406
1407   if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1408     return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1409
1410   std::ostringstream msg;
1411   msg << "No enforced vertex entry for face entry " << theFaceEntry;
1412   throw std::invalid_argument(msg.str());
1413 }
1414
1415 //=======================================================================
1416 //function : GetEnfVertex(TEnfVertexCoords coords)
1417 //=======================================================================
1418
1419 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1420     throw (std::invalid_argument) {
1421
1422   if (_coordsEnfVertexMap.count(coords) > 0)
1423     return _coordsEnfVertexMap[coords];
1424
1425   std::ostringstream msg;
1426   msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1427   throw std::invalid_argument(msg.str());
1428 }
1429
1430 //=======================================================================
1431 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1432 //=======================================================================
1433
1434 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1435     throw (std::invalid_argument) {
1436
1437   if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1438     return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1439
1440   std::ostringstream msg;
1441   msg << "No enforced vertex with entry " << theEnfVertexEntry;
1442   throw std::invalid_argument(msg.str());
1443 }
1444
1445 //Enable internal enforced vertices on specific face if requested by user
1446 ////=======================================================================
1447 ////function : GetInternalEnforcedVertex
1448 ////=======================================================================
1449
1450 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1451 //{
1452 //  if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1453 //    return true;
1454 //  return false;
1455 //}
1456
1457 //=======================================================================
1458 //function : ClearEnforcedVertex
1459 //=======================================================================
1460
1461 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1462     const TEntry& theVertexEntry) throw (std::invalid_argument) {
1463
1464   bool toNotify = false;
1465   std::ostringstream msg;
1466   TEnfVertex *oldEnfVertex;
1467   TEnfVertexCoords coords;
1468   coords.clear();
1469   coords.push_back(x);
1470   coords.push_back(y);
1471   coords.push_back(z);
1472
1473   // check that enf vertex with given enf vertex entry exists
1474   TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1475   if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1476     // Success
1477     MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
1478     oldEnfVertex = it_enfVertexEntry->second;
1479
1480     _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1481
1482     TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1483     enfVertexEntryList.erase(theVertexEntry);
1484     if (enfVertexEntryList.size() == 0)
1485       _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1486     //    TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1487     //    TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1488     //    it_entry_entry->second.erase(it_entryList);
1489     //    if (it_entry_entry->second.size() == 0)
1490     //      _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1491   } else {
1492     // Fail
1493     MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1494     msg << "No enforced vertex with geom entry " << theVertexEntry;
1495     // check that enf vertex with given coords exists
1496     TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1497     if (it_coords_enf != _coordsEnfVertexMap.end()) {
1498       // Success
1499       MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
1500       oldEnfVertex = it_coords_enf->second;
1501
1502       _coordsEnfVertexMap.erase(it_coords_enf);
1503
1504       TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1505       enfVertexCoordsList.erase(coords);
1506       if (enfVertexCoordsList.size() == 0)
1507         _faceEntryCoordsListMap.erase(theFaceEntry);
1508       //      TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1509       //      TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1510       //      it_entry_coords->second.erase(it_coordsList);
1511       //      if (it_entry_coords->second.size() == 0)
1512       //        _faceEntryCoordsListMap.erase(it_entry_coords);
1513     } else {
1514       // Fail
1515       MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1516       msg << std::endl;
1517       msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1518       throw std::invalid_argument(msg.str());
1519     }
1520   }
1521
1522   MESSAGE("Remove enf vertex from _enfVertexList");
1523
1524   // update _enfVertexList
1525   TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1526   if (it != _enfVertexList.end()) {
1527     (*it)->faceEntries.erase(theFaceEntry);
1528     if ((*it)->faceEntries.size() == 0){
1529       _enfVertexList.erase(it);
1530       toNotify = true;
1531     }
1532     MESSAGE("Done");
1533   }
1534
1535   // update _faceEntryEnfVertexListMap
1536   TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1537   currentEnfVertexList.erase(oldEnfVertex);
1538
1539   if (currentEnfVertexList.size() == 0) {
1540     MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
1541     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1542     MESSAGE("Done");
1543   }
1544
1545   if (toNotify)
1546     NotifySubMeshesHypothesisModification();
1547
1548   return toNotify;
1549 }
1550
1551 //=======================================================================
1552 //function : ClearEnforcedVertices
1553 //=======================================================================
1554
1555 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1556
1557   bool toNotify = false;
1558   TEnfVertex *oldEnfVertex;
1559
1560   TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1561   if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1562     toNotify = true;
1563     TEnfVertexCoordsList coordsList = it_entry_coords->second;
1564     TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1565     for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1566       TEnfVertexCoords coords = (*it_coordsList);
1567       oldEnfVertex = _coordsEnfVertexMap[coords];
1568       _coordsEnfVertexMap.erase(coords);
1569       // update _enfVertexList
1570       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1571       if (it != _enfVertexList.end()) {
1572         (*it)->faceEntries.erase(theFaceEntry);
1573         if ((*it)->faceEntries.size() == 0){
1574           _enfVertexList.erase(it);
1575           toNotify = true;
1576         }
1577         MESSAGE("Done");
1578       }
1579     }
1580     _faceEntryCoordsListMap.erase(it_entry_coords);
1581     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1582   }
1583
1584   TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1585   if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1586     toNotify = true;
1587     TEntryList enfVertexEntryList = it_entry_entry->second;
1588     TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1589     for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1590       TEntry enfVertexEntry = (*it_enfVertexEntryList);
1591       oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1592       _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1593       // update _enfVertexList
1594       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1595       if (it != _enfVertexList.end()) {
1596         (*it)->faceEntries.erase(theFaceEntry);
1597         if ((*it)->faceEntries.size() == 0){
1598           _enfVertexList.erase(it);
1599           toNotify = true;
1600         }
1601         MESSAGE("Done");
1602       }
1603     }
1604     _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1605     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1606   }
1607
1608   if (toNotify)
1609     NotifySubMeshesHypothesisModification();
1610
1611   return toNotify;
1612   //  std::ostringstream msg;
1613   //  msg << "No enforced vertex for " << theFaceEntry;
1614   //  throw std::invalid_argument(msg.str());
1615 }
1616
1617 //=======================================================================
1618 //function : ClearAllEnforcedVertices
1619 //=======================================================================
1620 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1621   _faceEntryEnfVertexListMap.clear();
1622   _enfVertexList.clear();
1623   _faceEntryCoordsListMap.clear();
1624   _coordsEnfVertexMap.clear();
1625   _faceEntryEnfVertexEntryListMap.clear();
1626   _enfVertexEntryEnfVertexMap.clear();
1627 //  Enable internal enforced vertices on specific face if requested by user
1628 //  _faceEntryInternalVerticesList.clear();
1629   NotifySubMeshesHypothesisModification();
1630 }
1631
1632 //================================================================================
1633 /*!
1634  * \brief Return the enforced vertices
1635  */
1636 //================================================================================
1637
1638
1639 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1640     const BLSURFPlugin_Hypothesis* hyp) {
1641   return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1642 }
1643
1644 //Enable internal enforced vertices on specific face if requested by user
1645 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1646 //    const BLSURFPlugin_Hypothesis* hyp) {
1647 //  return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1648 //}
1649
1650 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1651 {
1652   return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1653 }
1654
1655 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1656 {
1657   return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1658 }
1659
1660 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1661     const BLSURFPlugin_Hypothesis* hyp) {
1662   return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1663 }
1664
1665 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1666     const BLSURFPlugin_Hypothesis* hyp) {
1667   return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1668 }
1669
1670 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1671     const BLSURFPlugin_Hypothesis* hyp) {
1672   return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1673 }
1674
1675 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1676     const BLSURFPlugin_Hypothesis* hyp) {
1677   return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1678 }
1679
1680 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1681     const BLSURFPlugin_Hypothesis* hyp) {
1682   return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1683 }
1684
1685 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1686 {
1687   TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1688   if (it != _groupNameNodeIDMap.end()) {
1689     return it->second;
1690   }
1691   std::ostringstream msg;
1692   msg << "No group " << theGroupName;
1693   throw std::invalid_argument(msg.str());
1694 }
1695
1696 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1697 {
1698   _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1699 }
1700
1701 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1702 {
1703   TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1704   if (it != _groupNameNodeIDMap.end()) {
1705     std::set<int>::iterator IDit = it->second.find(theNodeID);
1706     if (IDit != it->second.end())
1707       it->second.erase(IDit);
1708     std::ostringstream msg;
1709     msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1710     throw std::invalid_argument(msg.str());
1711   }
1712   std::ostringstream msg;
1713   msg << "No group " << theGroupName;
1714   throw std::invalid_argument(msg.str());
1715 }
1716
1717
1718 //=============================================================================
1719 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1720   if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1721     _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1722     if (toEnforceInternalVertices)
1723       SetPhysicalMesh(PhysicalLocalSize);
1724     NotifySubMeshesHypothesisModification();
1725   }
1726 }
1727
1728
1729 //=============================================================================
1730 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1731   if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1732     _enforcedInternalVerticesAllFacesGroup = theGroupName;
1733     NotifySubMeshesHypothesisModification();
1734   }
1735 }
1736
1737 //=============================================================================
1738 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1739     const BLSURFPlugin_Hypothesis* hyp) {
1740   return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1741 }
1742
1743 //=============================================================================
1744 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1745     const BLSURFPlugin_Hypothesis* hyp) {
1746   return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1747 }
1748
1749 //=============================================================================
1750 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1751     const BLSURFPlugin_Hypothesis* hyp) {
1752   return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1753 }
1754
1755 //=============================================================================
1756 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1757     const BLSURFPlugin_Hypothesis* hyp){
1758   return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1759 }
1760
1761 //=============================================================================
1762 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1763     const BLSURFPlugin_Hypothesis* hyp){
1764   return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1765 }
1766
1767 //=======================================================================
1768 //function : ClearAllEnforcedVertices
1769 //=======================================================================
1770 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1771   _preCadFacesPeriodicityVector.clear();
1772   _preCadEdgesPeriodicityVector.clear();
1773   NotifySubMeshesHypothesisModification();
1774 }
1775
1776 //=======================================================================
1777 //function : AddPreCadFacesPeriodicity
1778 //=======================================================================
1779 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1780     std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1781
1782   TPreCadPeriodicity preCadFacesPeriodicity;
1783   preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1784   preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1785   preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1786   preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1787
1788   _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1789
1790   NotifySubMeshesHypothesisModification();
1791 }
1792
1793 //=======================================================================
1794 //function : AddPreCadEdgesPeriodicity
1795 //=======================================================================
1796 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1797     std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1798
1799   TPreCadPeriodicity preCadEdgesPeriodicity;
1800   preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1801   preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1802   preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1803   preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1804
1805   _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1806
1807   NotifySubMeshesHypothesisModification();
1808 }
1809
1810 //=============================================================================
1811 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1812    // We must keep at least the same number of arguments when increasing the SALOME version
1813    // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1814    // parameter can be written several times to keep the old global number of parameters.
1815
1816    // Treat old options which are now in the advanced options
1817    TOptionValues::iterator op_val;
1818    int _decimesh = -1;
1819    int _preCADRemoveNanoEdges = -1;
1820    double _preCADEpsNano = -1.0;
1821    op_val = _option2value.find("respect_geometry");
1822    if (op_val != _option2value.end()) {
1823      std::string value = op_val->second;
1824      if (!value.empty())
1825        _decimesh = value.compare("1") == 0 ? 1 : 0;
1826    }
1827    op_val = _preCADoption2value.find("remove_tiny_edges");
1828    if (op_val != _preCADoption2value.end()) {
1829      std::string value = op_val->second;
1830      if (!value.empty())
1831        _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1832    }
1833    op_val = _preCADoption2value.find("tiny_edge_length");
1834    if (op_val != _preCADoption2value.end()) {
1835      std::string value = op_val->second;
1836      if (!value.empty())
1837        _preCADEpsNano = strtod(value.c_str(), NULL);
1838    }
1839    
1840   save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1841       << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1842   save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1843   save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1844   save << " " << (int) _enforcedInternalVerticesAllFaces;
1845   save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1846   save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1847   save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1848   save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces << " " << (int) _preCADRemoveTinyUVEdges;
1849   save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1850   save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1851   save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1852
1853   op_val = _option2value.begin();
1854   if (op_val != _option2value.end()) {
1855     save << " " << "__OPTIONS_BEGIN__";
1856     for (; op_val != _option2value.end(); ++op_val) {
1857       if (!op_val->second.empty())
1858         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1859     }
1860     save << " " << "__OPTIONS_END__";
1861   }
1862   
1863   op_val = _customOption2value.begin();
1864   if (op_val != _customOption2value.end()) {
1865     save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1866     for (; op_val != _customOption2value.end(); ++op_val) {
1867       if (!op_val->second.empty())
1868         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1869     }
1870     save << " " << "__CUSTOM_OPTIONS_END__";
1871   }
1872
1873   op_val = _preCADoption2value.begin();
1874   if (op_val != _preCADoption2value.end()) {
1875     save << " " << "__PRECAD_OPTIONS_BEGIN__";
1876     for (; op_val != _preCADoption2value.end(); ++op_val) {
1877       if (!op_val->second.empty())
1878         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1879     }
1880     save << " " << "__PRECAD_OPTIONS_END__";
1881   }
1882
1883   TSizeMap::iterator it_sm = _sizeMap.begin();
1884   if (it_sm != _sizeMap.end()) {
1885     save << " " << "__SIZEMAP_BEGIN__";
1886     for (; it_sm != _sizeMap.end(); ++it_sm) {
1887       save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1888     }
1889     save << " " << "__SIZEMAP_END__";
1890   }
1891
1892   TSizeMap::iterator it_at = _attractors.begin();
1893   if (it_at != _attractors.end()) {
1894     save << " " << "__ATTRACTORS_BEGIN__";
1895     for (; it_at != _attractors.end(); ++it_at) {
1896       save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1897     }
1898     save << " " << "__ATTRACTORS_END__";
1899   }
1900   
1901   TAttractorMap::iterator it_At = _classAttractors.begin();
1902   if (it_At != _classAttractors.end()) {
1903     std::ostringstream test;
1904     save << " " << "__NEW_ATTRACTORS_BEGIN__";
1905     test << " " << "__NEW_ATTRACTORS_BEGIN__";
1906     for (; it_At != _classAttractors.end(); ++it_At) {
1907       std::vector<double> attParams;
1908       attParams   = it_At->second->GetParameters();
1909 //       double step = it_At->second->GetStep();
1910       save << " " << it_At->first;
1911       save << " " << it_At->second->GetAttractorEntry();
1912       save << " " << attParams[0]  << " " <<  attParams[1] << " " <<  attParams[2] << " " <<  attParams[3];
1913 //       save << " " << step;
1914       test << " " << it_At->first;
1915       test << " " << it_At->second->GetAttractorEntry();
1916       test << " " << attParams[0]  << " " <<  attParams[1] << " " <<  attParams[2] << " " <<  attParams[3];
1917 //       test << " " << step;
1918     }
1919     save << " " << "__NEW_ATTRACTORS_END__";
1920     test << " " << "__NEW_ATTRACTORS_END__";
1921     MESSAGE(" Attractor hypothesis saved as "<<test.str())
1922   }
1923
1924   TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1925   if (it_enf != _enfVertexList.end()) {
1926     save << " " << "__ENFORCED_VERTICES_BEGIN__";
1927     for (; it_enf != _enfVertexList.end(); ++it_enf) {
1928       TEnfVertex *enfVertex = (*it_enf);
1929       save << " " << "__BEGIN_VERTEX__";
1930       if (!enfVertex->name.empty()) {
1931         save << " " << "__BEGIN_NAME__";
1932         save << " " << enfVertex->name;
1933         save << " " << "__END_NAME__";
1934       }
1935       if (!enfVertex->geomEntry.empty()) {
1936         save << " " << "__BEGIN_ENTRY__";
1937         save << " " << enfVertex->geomEntry;
1938         save << " " << "__END_ENTRY__";
1939       }
1940       if (!enfVertex->grpName.empty()) {
1941         save << " " << "__BEGIN_GROUP__";
1942         save << " " << enfVertex->grpName;
1943         save << " " << "__END_GROUP__";
1944       }
1945       if (enfVertex->coords.size()) {
1946         save << " " << "__BEGIN_COORDS__";
1947         for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1948           save << " " << enfVertex->coords[i];
1949         save << " " << "__END_COORDS__";
1950       }
1951       TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1952       bool hasFaces = false;
1953       if (faceEntriesIt != enfVertex->faceEntries.end()) {
1954         hasFaces = true;
1955         save << " " << "__BEGIN_FACELIST__";
1956       }
1957       for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1958         save << " " << (*faceEntriesIt);
1959       if (hasFaces)
1960         save << " " << "__END_FACELIST__";
1961       save << " " << "__END_VERTEX__";
1962     }
1963     save << " " << "__ENFORCED_VERTICES_END__";
1964   }
1965
1966   //PERIODICITY
1967
1968   SavePreCADPeriodicity(save, "FACES");
1969   SavePreCADPeriodicity(save, "EDGES");
1970
1971   SaveFacesPeriodicity(save);
1972   SaveEdgesPeriodicity(save);
1973   SaveVerticesPeriodicity(save);
1974
1975   return save;
1976 }
1977
1978 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1979
1980   TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1981   if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1982     MESSAGE("__FACES_PERIODICITY_BEGIN__");
1983     save << " " << "__FACES_PERIODICITY_BEGIN__";
1984     for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1985       TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1986       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1987       save << " " << "__BEGIN_ENTRY1__";
1988       save << " " << periodicity_i.first;
1989       save << " " << "__END_ENTRY1__";
1990       save << " " << "__BEGIN_ENTRY2__";
1991       save << " " << periodicity_i.second;
1992       save << " " << "__END_ENTRY2__";
1993       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1994     }
1995     save << " " << "__FACES_PERIODICITY_END__";
1996     MESSAGE("__FACES_PERIODICITY_END__");
1997   }
1998 }
1999
2000 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
2001
2002   TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
2003   if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
2004     save << " " << "__EDGES_PERIODICITY_BEGIN__";
2005     MESSAGE("__EDGES_PERIODICITY_BEGIN__");
2006     for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
2007       TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
2008       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2009       if (! periodicity_i.theFace1Entry.empty()){
2010         save << " " << "__BEGIN_FACE1__";
2011         save << " " << periodicity_i.theFace1Entry;
2012         save << " " << "__END_FACE1__";
2013       }
2014       save << " " << "__BEGIN_EDGE1__";
2015       save << " " << periodicity_i.theEdge1Entry;
2016       save << " " << "__END_EDGE1__";
2017       if (! periodicity_i.theFace2Entry.empty()){
2018         save << " " << "__BEGIN_FACE2__";
2019         save << " " << periodicity_i.theFace2Entry;
2020         save << " " << "__END_FACE2__";
2021       }
2022       save << " " << "__BEGIN_EDGE2__";
2023       save << " " << periodicity_i.theEdge2Entry;
2024       save << " " << "__END_EDGE2__";
2025       save << " " << "__BEGIN_EDGE_ORIENTATION__";
2026       save << " " << periodicity_i.edge_orientation;
2027       save << " " << "__END_EDGE_ORIENTATION__";
2028       save << " " << "__END_PERIODICITY_DESCRIPTION__";
2029     }
2030     save << " " << "__EDGES_PERIODICITY_END__";
2031     MESSAGE("__EDGES_PERIODICITY_END__");
2032   }
2033 }
2034
2035 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2036
2037   TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2038   if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2039     MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
2040     save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2041     for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2042       TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2043       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2044       save << " " << "__BEGIN_EDGE1__";
2045       save << " " << periodicity_i.theEdge1Entry;
2046       save << " " << "__END_EDGE1__";
2047       save << " " << "__BEGIN_VERTEX1__";
2048       save << " " << periodicity_i.theVertex1Entry;
2049       save << " " << "__END_VERTEX1__";
2050       save << " " << "__BEGIN_EDGE2__";
2051       save << " " << periodicity_i.theEdge2Entry;
2052       save << " " << "__END_EDGE2__";
2053       save << " " << "__BEGIN_VERTEX2__";
2054       save << " " << periodicity_i.theVertex2Entry;
2055       save << " " << "__END_VERTEX2__";
2056       save << " " << "__END_PERIODICITY_DESCRIPTION__";
2057     }
2058     save << " " << "__VERTICES_PERIODICITY_END__";
2059     MESSAGE("__VERTICES_PERIODICITY_END__");
2060   }
2061 }
2062
2063 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2064   TPreCadPeriodicityVector precad_periodicity;
2065   if ( shapeType  &&  strcmp( shapeType, "FACES" ) == 0 )
2066     precad_periodicity = _preCadFacesPeriodicityVector;
2067   else
2068     precad_periodicity = _preCadEdgesPeriodicityVector;
2069   TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2070   if (it_precad_periodicity != precad_periodicity.end()) {
2071     save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2072     for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2073       TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2074       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2075       if (!periodicity_i.shape1Entry.empty()) {
2076         save << " " << "__BEGIN_ENTRY1__";
2077         save << " " << periodicity_i.shape1Entry;
2078         save << " " << "__END_ENTRY1__";
2079       }
2080       if (!periodicity_i.shape2Entry.empty()) {
2081         save << " " << "__BEGIN_ENTRY2__";
2082         save << " " << periodicity_i.shape2Entry;
2083         save << " " << "__END_ENTRY2__";
2084       }
2085
2086       std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2087       bool hasSourceVertices = false;
2088       if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2089         hasSourceVertices = true;
2090         save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2091       }
2092       for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2093         save << " " << (*sourceVerticesEntriesIt);
2094       if (hasSourceVertices)
2095         save << " " << "__END_SOURCE_VERTICES_LIST__";
2096
2097       std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2098       bool hasTargetVertices = false;
2099       if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2100         hasTargetVertices = true;
2101         save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2102       }
2103       for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2104         save << " " << (*targetVerticesEntriesIt);
2105       if (hasTargetVertices)
2106         save << " " << "__END_TARGET_VERTICES_LIST__";
2107
2108       save << " " << "__END_PERIODICITY_DESCRIPTION__";
2109     }
2110     save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2111   }
2112
2113 }
2114
2115 //=============================================================================
2116 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
2117   bool isOK = true;
2118   int i;
2119   double val;
2120   std::string option_or_sm;
2121
2122   isOK = static_cast<bool>(load >> i);
2123   if (isOK)
2124     _topology = (Topology) i;
2125   else
2126     load.clear(std::ios::badbit | load.rdstate());
2127
2128   isOK = static_cast<bool>(load >> i);
2129   if (isOK)
2130     _physicalMesh = (PhysicalMesh) i;
2131   else
2132     load.clear(std::ios::badbit | load.rdstate());
2133
2134   isOK = static_cast<bool>(load >> i);
2135   if (isOK)
2136     _geometricMesh = (GeometricMesh) i;
2137   else
2138     load.clear(std::ios::badbit | load.rdstate());
2139
2140   isOK = static_cast<bool>(load >> val);
2141   if (isOK)
2142     _phySize = val;
2143   else
2144     load.clear(std::ios::badbit | load.rdstate());
2145
2146   isOK = static_cast<bool>(load >> val);
2147   if (isOK)
2148     _angleMesh = val;
2149   else
2150     load.clear(std::ios::badbit | load.rdstate());
2151
2152   isOK = static_cast<bool>(load >> val);
2153   if (isOK)
2154     _gradation = val;
2155   else
2156     load.clear(std::ios::badbit | load.rdstate());
2157
2158   isOK = static_cast<bool>(load >> i);
2159   if (isOK)
2160     _quadAllowed = (bool) i;
2161   else
2162     load.clear(std::ios::badbit | load.rdstate());
2163
2164   isOK = static_cast<bool>(load >> i);
2165   if (isOK) {
2166     if ( i != -1) { // if value is -1, then this is no longer a standard option
2167       std::string & value = _option2value["respect_geometry"];
2168       bool _decimesh = (bool) i;
2169       value = _decimesh ? "1" : "0";
2170     }
2171   }
2172   else
2173     load.clear(std::ios::badbit | load.rdstate());
2174
2175   isOK = static_cast<bool>(load >> val);
2176   if (isOK)
2177     _minSize = val;
2178   else
2179     load.clear(std::ios::badbit | load.rdstate());
2180
2181   isOK = static_cast<bool>(load >> val);
2182   if (isOK)
2183     _maxSize = val;
2184   else
2185     load.clear(std::ios::badbit | load.rdstate());
2186
2187   isOK = static_cast<bool>(load >> val);
2188   if (isOK)
2189     // former parameter: get min value
2190     _angleMesh = std::min(val,_angleMesh);
2191   else
2192     load.clear(std::ios::badbit | load.rdstate());
2193
2194   isOK = static_cast<bool>(load >> val);
2195   if (isOK)
2196     // former parameter: get min value
2197     _minSize = std::min(val,_minSize);
2198   else
2199     load.clear(std::ios::badbit | load.rdstate());
2200
2201   isOK = static_cast<bool>(load >> val);
2202   if (isOK)
2203     // former parameter: get max value
2204     _maxSize = std::max(val,_maxSize);
2205   else
2206     load.clear(std::ios::badbit | load.rdstate());
2207
2208   isOK = static_cast<bool>(load >> i);
2209   if (isOK)
2210     _verb = i;
2211   else
2212     load.clear(std::ios::badbit | load.rdstate());
2213
2214   isOK = static_cast<bool>(load >> i);
2215   if (isOK)
2216     _preCADMergeEdges = (bool) i;
2217   else
2218     load.clear(std::ios::badbit | load.rdstate());
2219
2220   isOK = static_cast<bool>(load >> i);
2221   if (isOK) {
2222     if ( i != -1) { // if value is -1, then this is no longer a standard option
2223       std::string & value = _preCADoption2value["remove_tiny_edges"];
2224       bool _preCADRemoveNanoEdges = (bool) i;
2225       value = _preCADRemoveNanoEdges ? "1" : "0";
2226     }
2227   }
2228   else
2229     load.clear(std::ios::badbit | load.rdstate());
2230
2231   isOK = static_cast<bool>(load >> i);
2232   if (isOK)
2233     _preCADDiscardInput = (bool) i;
2234   else
2235     load.clear(std::ios::badbit | load.rdstate());
2236
2237   isOK = static_cast<bool>(load >> val);
2238   if (isOK) { // _preCADEpsNano
2239     if ( (i + 1.0) < 1e-6 ) { // if value is -1, then this is no longer a standard option: get optional value "tiny_edge_length" instead
2240       std::string & value = _preCADoption2value["tiny_edge_length"];
2241       std::ostringstream oss;
2242       oss << i;
2243       value = oss.str();
2244     }
2245   }
2246   else
2247     load.clear(std::ios::badbit | load.rdstate());
2248
2249   isOK = static_cast<bool>(load >> i);
2250   if (isOK)
2251     _enforcedInternalVerticesAllFaces = (bool) i;
2252   else
2253     load.clear(std::ios::badbit | load.rdstate());
2254
2255   // New options with MeshGems-CADSurf
2256
2257   bool hasCADSurfOptions = false;
2258   bool hasOptions = false;
2259   bool hasCustomOptions = false;
2260   bool hasPreCADOptions = false;
2261   bool hasSizeMap = false;
2262   bool hasAttractor = false;
2263   bool hasNewAttractor = false;
2264   bool hasEnforcedVertex = false;
2265   bool hasPreCADFacesPeriodicity = false;
2266   bool hasPreCADEdgesPeriodicity = false;
2267   bool hasFacesPeriodicity = false;
2268   bool hasEdgesPeriodicity = false;
2269   bool hasVerticesPeriodicity = false;
2270
2271   isOK = static_cast<bool>(load >> option_or_sm);
2272   if (isOK)
2273     if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2274       i = atoi(option_or_sm.c_str());
2275       hasCADSurfOptions = true;
2276       _phySizeRel = (bool) i;
2277     }
2278     if (option_or_sm == "__OPTIONS_BEGIN__")
2279       hasOptions = true;
2280     else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2281       hasCustomOptions = true;
2282     else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2283       hasPreCADOptions = true;
2284     else if (option_or_sm == "__SIZEMAP_BEGIN__")
2285       hasSizeMap = true;
2286     else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2287       hasAttractor = true;
2288     else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2289       hasNewAttractor = true;
2290     else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2291       hasEnforcedVertex = true;
2292     else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2293       hasPreCADFacesPeriodicity = true;
2294     else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2295       hasPreCADEdgesPeriodicity = true;
2296     else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2297       hasFacesPeriodicity = true;
2298     else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2299       hasEdgesPeriodicity = true;
2300     else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2301       hasVerticesPeriodicity = true;
2302
2303   if (isOK && hasCADSurfOptions) {
2304     isOK = static_cast<bool>(load >> i);
2305     if (isOK)
2306       _minSizeRel = (bool) i;
2307     else
2308       load.clear(std::ios::badbit | load.rdstate());
2309
2310     isOK = static_cast<bool>(load >> i);
2311     if (isOK)
2312       _maxSizeRel = (bool) i;
2313     else
2314       load.clear(std::ios::badbit | load.rdstate());
2315
2316     isOK = static_cast<bool>(load >> val);
2317     if (isOK)
2318       _chordalError = val;
2319     else
2320       load.clear(std::ios::badbit | load.rdstate());
2321
2322     isOK = static_cast<bool>(load >> i);
2323     if (isOK)
2324       _anisotropic = (bool) i;
2325     else
2326       load.clear(std::ios::badbit | load.rdstate());
2327
2328     isOK = static_cast<bool>(load >> val);
2329     if (isOK)
2330       _anisotropicRatio = val;
2331     else
2332       load.clear(std::ios::badbit | load.rdstate());
2333
2334     isOK = static_cast<bool>(load >> i);
2335     if (isOK)
2336       _removeTinyEdges = (bool) i;
2337     else
2338       load.clear(std::ios::badbit | load.rdstate());
2339
2340     isOK = static_cast<bool>(load >> val);
2341     if (isOK)
2342       _tinyEdgeLength = val;
2343     else
2344       load.clear(std::ios::badbit | load.rdstate());
2345
2346     isOK = static_cast<bool>(load >> i);
2347     if (isOK)
2348       _badElementRemoval = (bool) i;
2349     else
2350       load.clear(std::ios::badbit | load.rdstate());
2351
2352     isOK = static_cast<bool>(load >> val);
2353     if (isOK)
2354       _badElementAspectRatio = val;
2355     else
2356       load.clear(std::ios::badbit | load.rdstate());
2357
2358     isOK = static_cast<bool>(load >> i);
2359     if (isOK)
2360       _optimizeMesh = (bool) i;
2361     else
2362       load.clear(std::ios::badbit | load.rdstate());
2363
2364     isOK = static_cast<bool>(load >> i);
2365     if (isOK)
2366       _quadraticMesh = (bool) i;
2367     else
2368       load.clear(std::ios::badbit | load.rdstate());
2369
2370     isOK = static_cast<bool>(load >> i);
2371     if (isOK)
2372       _preCADProcess3DTopology = (bool) i;
2373     else
2374       load.clear(std::ios::badbit | load.rdstate());
2375
2376     if (( load >> std::ws).peek() != '_' )
2377     {
2378       isOK = static_cast<bool>(load >> i);
2379       if (isOK)
2380         _preCADRemoveDuplicateCADFaces = (bool) i;
2381       else
2382         load.clear(std::ios::badbit | load.rdstate());
2383
2384       isOK = static_cast<bool>(load >> i);
2385       if (isOK)
2386         _preCADRemoveTinyUVEdges = (bool) i;
2387       else
2388         load.clear(std::ios::badbit | load.rdstate());
2389
2390       isOK = static_cast<bool>(load >> i);
2391       if (isOK)
2392         _optimiseTinyEdges = (bool) i;
2393       else
2394         load.clear(std::ios::badbit | load.rdstate());
2395
2396       isOK = static_cast<bool>(load >> val);
2397       if (isOK)
2398         _tinyEdgeOptimisationLength = val;
2399       else
2400         load.clear(std::ios::badbit | load.rdstate());
2401
2402       isOK = static_cast<bool>(load >> i);
2403       if (isOK)
2404         _correctSurfaceIntersec = (bool) i;
2405       else
2406         load.clear(std::ios::badbit | load.rdstate());
2407
2408       isOK = static_cast<bool>(load >> val);
2409       if (isOK)
2410         _corrSurfaceIntersCost = val;
2411       else
2412         load.clear(std::ios::badbit | load.rdstate());
2413
2414       isOK = static_cast<bool>(load >> i);
2415       if (isOK)
2416         _useGradation = (bool) i;
2417       else
2418         load.clear(std::ios::badbit | load.rdstate());
2419
2420       isOK = static_cast<bool>(load >> i);
2421       if (isOK)
2422         _useVolumeGradation = (bool) i;
2423       else
2424         load.clear(std::ios::badbit | load.rdstate());
2425
2426       isOK = static_cast<bool>(load >> val);
2427       if (isOK)
2428         _volumeGradation = val;
2429       else
2430         load.clear(std::ios::badbit | load.rdstate());
2431     }
2432   }
2433
2434
2435   if (hasCADSurfOptions) {
2436     isOK = static_cast<bool>(load >> option_or_sm);
2437     if (isOK) {
2438       if (option_or_sm == "__OPTIONS_BEGIN__")
2439         hasOptions = true;
2440       else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2441         hasCustomOptions = true;
2442       else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2443         hasPreCADOptions = true;
2444       else if (option_or_sm == "__SIZEMAP_BEGIN__")
2445         hasSizeMap = true;
2446       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2447         hasAttractor = true;
2448       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2449         hasNewAttractor = true;
2450       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2451         hasEnforcedVertex = true;
2452       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2453         hasPreCADFacesPeriodicity = true;
2454       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2455         hasPreCADEdgesPeriodicity = true;
2456       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2457         hasFacesPeriodicity = true;
2458       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2459         hasEdgesPeriodicity = true;
2460       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2461         hasVerticesPeriodicity = true;
2462     }
2463   }
2464   
2465   std::string optName, optValue;
2466   while (isOK && hasOptions) {
2467     isOK = static_cast<bool>(load >> optName);
2468     if (isOK) {
2469       if (optName == "__OPTIONS_END__")
2470         break;
2471       isOK = static_cast<bool>(load >> optValue);
2472     }
2473     if (isOK) {
2474       std::string & value = _option2value[optName];
2475       value = optValue;
2476       int len = value.size();
2477       // continue reading until "%#" encountered
2478       while (value[len - 1] != '#' || value[len - 2] != '%') {
2479         isOK = static_cast<bool>(load >> optValue);
2480         if (isOK) {
2481           value += " ";
2482           value += optValue;
2483           len = value.size();
2484         } else {
2485           break;
2486         }
2487       }
2488       value.resize(len - 2); //cut off "%#"
2489     }
2490   }
2491
2492   if (hasOptions) {
2493     isOK = static_cast<bool>(load >> option_or_sm);
2494     if (isOK) {
2495       if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2496         hasCustomOptions = true;
2497       else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2498         hasPreCADOptions = true;
2499       else if (option_or_sm == "__SIZEMAP_BEGIN__")
2500         hasSizeMap = true;
2501       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2502         hasAttractor = true;
2503       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2504         hasNewAttractor = true;
2505       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2506         hasEnforcedVertex = true;
2507       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2508         hasPreCADFacesPeriodicity = true;
2509       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2510         hasPreCADEdgesPeriodicity = true;
2511       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2512         hasFacesPeriodicity = true;
2513       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2514         hasEdgesPeriodicity = true;
2515       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2516         hasVerticesPeriodicity = true;
2517     }
2518   }
2519
2520   while (isOK && hasCustomOptions) {
2521     isOK = static_cast<bool>(load >> optName);
2522     if (isOK) {
2523       if (optName == "__CUSTOM_OPTIONS_END__")
2524         break;
2525       isOK = static_cast<bool>(load >> optValue);
2526     }
2527     if (isOK) {
2528       std::string& value = optValue;
2529       int len = value.size();
2530       // continue reading until "%#" encountered
2531       while (value[len - 1] != '#' || value[len - 2] != '%') {
2532         isOK = static_cast<bool>(load >> optValue);
2533         if (isOK) {
2534           value += " ";
2535           value += optValue;
2536           len = value.size();
2537         } else {
2538           break;
2539         }
2540       }
2541       value.resize(len - 2); //cut off "%#"
2542       _customOption2value[optName] = value;
2543     }
2544   }
2545
2546   if (hasCustomOptions) {
2547     isOK = static_cast<bool>(load >> option_or_sm);
2548     if (isOK) {
2549       if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2550         hasPreCADOptions = true;
2551       else if (option_or_sm == "__SIZEMAP_BEGIN__")
2552         hasSizeMap = true;
2553       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2554         hasAttractor = true;
2555       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2556         hasNewAttractor = true;
2557       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2558         hasEnforcedVertex = true;
2559       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2560         hasPreCADFacesPeriodicity = true;
2561       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2562         hasPreCADEdgesPeriodicity = true;
2563       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2564         hasFacesPeriodicity = true;
2565       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2566         hasEdgesPeriodicity = true;
2567       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2568         hasVerticesPeriodicity = true;
2569     }
2570   }
2571
2572   while (isOK && hasPreCADOptions) {
2573     isOK = static_cast<bool>(load >> optName);
2574     if (isOK) {
2575       if (optName == "__PRECAD_OPTIONS_END__")
2576         break;
2577       isOK = static_cast<bool>(load >> optValue);
2578     }
2579     if (isOK) {
2580       std::string & value = _preCADoption2value[optName];
2581       value = optValue;
2582       int len = value.size();
2583       // continue reading until "%#" encountered
2584       while (value[len - 1] != '#' || value[len - 2] != '%') {
2585         isOK = static_cast<bool>(load >> optValue);
2586         if (isOK) {
2587           value += " ";
2588           value += optValue;
2589           len = value.size();
2590         } else {
2591           break;
2592         }
2593       }
2594       value.resize(len - 2); //cut off "%#"
2595     }
2596   }
2597
2598   if (hasPreCADOptions) {
2599     isOK = static_cast<bool>(load >> option_or_sm);
2600     if (isOK) {
2601       if (option_or_sm == "__SIZEMAP_BEGIN__")
2602         hasSizeMap = true;
2603       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2604         hasAttractor = true;
2605       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2606         hasNewAttractor = true;
2607       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2608         hasEnforcedVertex = true;
2609       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2610         hasPreCADFacesPeriodicity = true;
2611       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2612         hasPreCADEdgesPeriodicity = true;
2613       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2614         hasFacesPeriodicity = true;
2615       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2616         hasEdgesPeriodicity = true;
2617       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2618         hasVerticesPeriodicity = true;
2619     }
2620   }
2621  
2622   std::string smEntry, smValue;
2623   while (isOK && hasSizeMap) {
2624     isOK = static_cast<bool>(load >> smEntry);
2625     if (isOK) {
2626       if (smEntry == "__SIZEMAP_END__")
2627         break;
2628       isOK = static_cast<bool>(load >> smValue);
2629     }
2630     if (isOK) {
2631       std::string & value2 = _sizeMap[smEntry];
2632       value2 = smValue;
2633       int len2 = value2.size();
2634       // continue reading until "%#" encountered
2635       while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2636         isOK = static_cast<bool>(load >> smValue);
2637         if (isOK) {
2638           value2 += " ";
2639           value2 += smValue;
2640           len2 = value2.size();
2641         } else {
2642           break;
2643         }
2644       }
2645       value2.resize(len2 - 2); //cut off "%#"
2646     }
2647   }
2648
2649   if (hasSizeMap) {
2650     isOK = static_cast<bool>(load >> option_or_sm);
2651     if (isOK)
2652       if (option_or_sm == "__ATTRACTORS_BEGIN__")
2653         hasAttractor = true;
2654       if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2655         hasNewAttractor = true;
2656       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2657         hasEnforcedVertex = true;
2658       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2659         hasPreCADFacesPeriodicity = true;
2660       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2661         hasPreCADEdgesPeriodicity = true;
2662       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2663         hasFacesPeriodicity = true;
2664       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2665         hasEdgesPeriodicity = true;
2666       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2667         hasVerticesPeriodicity = true;
2668   }
2669
2670   std::string atEntry, atValue;
2671   while (isOK && hasAttractor) {
2672     isOK = static_cast<bool>(load >> atEntry);
2673     if (isOK) {
2674       if (atEntry == "__ATTRACTORS_END__")
2675         break;
2676       isOK = static_cast<bool>(load >> atValue);
2677     }
2678     if (isOK) {
2679       std::string & value3 = _attractors[atEntry];
2680       value3 = atValue;
2681       int len3 = value3.size();
2682       // continue reading until "%#" encountered
2683       while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2684         isOK = static_cast<bool>(load >> atValue);
2685         if (isOK) {
2686           value3 += " ";
2687           value3 += atValue;
2688           len3 = value3.size();
2689         } else {
2690           break;
2691         }
2692       }
2693       value3.resize(len3 - 2); //cut off "%#"
2694     }
2695   }
2696
2697   if (hasAttractor) {
2698     isOK = static_cast<bool>(load >> option_or_sm);
2699     if (isOK) {
2700       if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2701         hasNewAttractor = true;
2702       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2703         hasEnforcedVertex = true;
2704       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2705         hasPreCADFacesPeriodicity = true;
2706       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2707         hasPreCADEdgesPeriodicity = true;
2708       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2709         hasFacesPeriodicity = true;
2710       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2711         hasEdgesPeriodicity = true;
2712       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2713         hasVerticesPeriodicity = true;
2714     }
2715   }
2716
2717   std::string newAtFaceEntry, atTestString;
2718   std::string newAtShapeEntry;
2719   double attParams[4];
2720   //double step;
2721   while (isOK && hasNewAttractor) {
2722     //std::cout<<"Load new attractor"<<std::endl;
2723     isOK = static_cast<bool>(load >> newAtFaceEntry);
2724     if (isOK) {
2725       if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2726         break;
2727       isOK = static_cast<bool>(load >> newAtShapeEntry);
2728       if (!isOK)
2729     break;
2730       isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2731     }
2732     if (isOK) {
2733       MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
2734       const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2735       const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2736       BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2737       attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2738       //attractor->BuildMap();                     
2739       _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2740     }
2741   }
2742   
2743   
2744   if (hasNewAttractor) {
2745     isOK = static_cast<bool>(load >> option_or_sm);
2746     if (isOK) {
2747       if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2748         hasEnforcedVertex = true;
2749       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2750         hasPreCADFacesPeriodicity = true;
2751       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2752         hasPreCADEdgesPeriodicity = true;
2753       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2754         hasFacesPeriodicity = true;
2755       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2756         hasEdgesPeriodicity = true;
2757       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2758         hasVerticesPeriodicity = true;
2759     }
2760   }
2761
2762
2763 // 
2764 // Here is a example of the saved stream:
2765 // __ENFORCED_VERTICES_BEGIN__ 
2766 // __BEGIN_VERTEX__  => no name, no entry
2767 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2768 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__ 
2769 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__ 
2770 // __END_VERTEX__ 
2771 // __BEGIN_VERTEX__ => no coords
2772 // __BEGIN_NAME__ mes points __END_NAME__ 
2773 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2774 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2775 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2776 // __END_VERTEX__ 
2777 // __ENFORCED_VERTICES_END__
2778 // 
2779
2780   std::string enfSeparator;
2781   std::string enfName;
2782   std::string enfGeomEntry;
2783   std::string enfGroup;
2784   TEntryList enfFaceEntryList;
2785   double enfCoords[3];
2786   bool hasCoords = false;
2787   
2788   _faceEntryEnfVertexListMap.clear();
2789   _enfVertexList.clear();
2790   _faceEntryCoordsListMap.clear();
2791   _coordsEnfVertexMap.clear();
2792   _faceEntryEnfVertexEntryListMap.clear();
2793   _enfVertexEntryEnfVertexMap.clear();
2794   
2795   
2796   while (isOK && hasEnforcedVertex) {
2797     isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2798     TEnfVertex *enfVertex = new TEnfVertex();
2799 //     MESSAGE("enfSeparator: " <<enfSeparator);
2800     if (enfSeparator == "__ENFORCED_VERTICES_END__")
2801       break; // __ENFORCED_VERTICES_END__
2802     if (enfSeparator != "__BEGIN_VERTEX__")
2803       throw std::exception();
2804     
2805     while (isOK) {
2806       isOK = static_cast<bool>(load >> enfSeparator);
2807       MESSAGE("enfSeparator: " <<enfSeparator);
2808       if (enfSeparator == "__END_VERTEX__") {
2809         
2810         enfVertex->name = enfName;
2811         enfVertex->geomEntry = enfGeomEntry;
2812         enfVertex->grpName = enfGroup;
2813         enfVertex->coords.clear();
2814         if (hasCoords)
2815           enfVertex->coords.assign(enfCoords,enfCoords+3);
2816         enfVertex->faceEntries = enfFaceEntryList;
2817         
2818         _enfVertexList.insert(enfVertex);
2819         
2820         if (enfVertex->coords.size()) {
2821           _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2822           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2823             _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2824             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2825           }
2826         }
2827         if (!enfVertex->geomEntry.empty()) {
2828           _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2829           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2830             _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2831             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2832           }
2833         }
2834         
2835         enfName.clear();
2836         enfGeomEntry.clear();
2837         enfGroup.clear();
2838         enfFaceEntryList.clear();
2839         hasCoords = false;
2840         break; // __END_VERTEX__
2841       }
2842         
2843       if (enfSeparator == "__BEGIN_NAME__") {  // __BEGIN_NAME__
2844         while (isOK && (enfSeparator != "__END_NAME__")) {
2845           isOK = static_cast<bool>(load >> enfSeparator);
2846           if (enfSeparator != "__END_NAME__") {
2847             if (!enfName.empty())
2848               enfName += " ";
2849             enfName += enfSeparator;
2850           }
2851         }
2852         MESSAGE("enfName: " <<enfName);
2853       }
2854         
2855       if (enfSeparator == "__BEGIN_ENTRY__") {  // __BEGIN_ENTRY__
2856         isOK = static_cast<bool>(load >> enfGeomEntry);
2857         isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2858         if (enfSeparator != "__END_ENTRY__")
2859           throw std::exception();
2860         MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2861       }
2862         
2863       if (enfSeparator == "__BEGIN_GROUP__") {  // __BEGIN_GROUP__
2864         while (isOK && (enfSeparator != "__END_GROUP__")) {
2865           isOK = static_cast<bool>(load >> enfSeparator);
2866           if (enfSeparator != "__END_GROUP__") {
2867             if (!enfGroup.empty())
2868               enfGroup += " ";
2869             enfGroup += enfSeparator;
2870           }
2871         }
2872         MESSAGE("enfGroup: " <<enfGroup);
2873       }
2874         
2875       if (enfSeparator == "__BEGIN_COORDS__") {  // __BEGIN_COORDS__
2876         hasCoords = true;
2877         isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2878         isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2879         if (enfSeparator != "__END_COORDS__")
2880           throw std::exception();
2881         MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2882       } 
2883         
2884       if (enfSeparator == "__BEGIN_FACELIST__") {  // __BEGIN_FACELIST__
2885         while (isOK && (enfSeparator != "__END_FACELIST__")) {
2886           isOK = static_cast<bool>(load >> enfSeparator);
2887           if (enfSeparator != "__END_FACELIST__") {
2888             enfFaceEntryList.insert(enfSeparator);
2889             MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2890           }
2891         }
2892       } 
2893     }
2894   }
2895
2896   // PERIODICITY
2897
2898   if (hasPreCADFacesPeriodicity){
2899     LoadPreCADPeriodicity(load, "FACES");
2900
2901     isOK = static_cast<bool>(load >> option_or_sm);
2902     if (isOK) {
2903       if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2904         hasPreCADEdgesPeriodicity = true;
2905       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2906         hasFacesPeriodicity = true;
2907       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2908         hasEdgesPeriodicity = true;
2909       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2910         hasVerticesPeriodicity = true;
2911     }
2912   }
2913
2914   if (hasPreCADEdgesPeriodicity){
2915     LoadPreCADPeriodicity(load, "EDGES");
2916
2917     isOK = static_cast<bool>(load >> option_or_sm);
2918     if (isOK) {
2919       if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2920         hasFacesPeriodicity = true;
2921       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2922         hasEdgesPeriodicity = true;
2923       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2924         hasVerticesPeriodicity = true;
2925     }
2926   }
2927
2928   if (hasFacesPeriodicity){
2929       LoadFacesPeriodicity(load);
2930
2931     isOK = static_cast<bool>(load >> option_or_sm);
2932     if (isOK) {
2933       if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2934         hasEdgesPeriodicity = true;
2935       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2936         hasVerticesPeriodicity = true;
2937     }
2938   }
2939
2940   if (hasEdgesPeriodicity){
2941       LoadEdgesPeriodicity(load);
2942
2943     isOK = static_cast<bool>(load >> option_or_sm);
2944     if (isOK)
2945       if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2946         hasVerticesPeriodicity = true;
2947   }
2948
2949   if (hasVerticesPeriodicity)
2950       LoadVerticesPeriodicity(load);
2951
2952   return load;
2953 }
2954
2955 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2956
2957   bool isOK = true;
2958
2959   std::string periodicitySeparator;
2960   TEntry shape1Entry;
2961   TEntry shape2Entry;
2962
2963   _facesPeriodicityVector.clear();
2964
2965   while (isOK) {
2966     isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2967     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2968     TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2969     if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2970       break; // __FACES_PERIODICITY_END__
2971     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2972       MESSAGE("//" << periodicitySeparator << "//");
2973       throw std::exception();
2974     }
2975
2976     while (isOK) {
2977       isOK = static_cast<bool>(load >> periodicitySeparator);
2978       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2979       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2980
2981         periodicity_i->first = shape1Entry;
2982         periodicity_i->second = shape2Entry;
2983
2984         _facesPeriodicityVector.push_back(*periodicity_i);
2985
2986         break; // __END_PERIODICITY_DESCRIPTION__
2987       }
2988
2989       if (periodicitySeparator == "__BEGIN_ENTRY1__") {  // __BEGIN_ENTRY1__
2990         isOK = static_cast<bool>(load >> shape1Entry);
2991         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
2992         if (periodicitySeparator != "__END_ENTRY1__")
2993           throw std::exception();
2994         MESSAGE("shape1Entry: " <<shape1Entry);
2995       }
2996
2997       if (periodicitySeparator == "__BEGIN_ENTRY2__") {  // __BEGIN_ENTRY2__
2998         isOK = static_cast<bool>(load >> shape2Entry);
2999         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3000         if (periodicitySeparator != "__END_ENTRY2__")
3001           throw std::exception();
3002         MESSAGE("shape2Entry: " <<shape2Entry);
3003       }
3004     }
3005   }
3006 }
3007
3008
3009 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
3010
3011   bool isOK = true;
3012
3013   std::string periodicitySeparator;
3014   TEntry theFace1Entry;
3015   TEntry theEdge1Entry;
3016   TEntry theFace2Entry;
3017   TEntry theEdge2Entry;
3018   int edge_orientation = 0;
3019
3020   _edgesPeriodicityVector.clear();
3021
3022   while (isOK) {
3023     isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3024     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3025     TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3026     if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3027       break; // __EDGES_PERIODICITY_END__
3028     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3029       MESSAGE("//" << periodicitySeparator << "//");
3030       throw std::exception();
3031     }
3032
3033     while (isOK) {
3034       isOK = static_cast<bool>(load >> periodicitySeparator);
3035       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3036       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3037
3038         periodicity_i->theFace1Entry = theFace1Entry;
3039         periodicity_i->theEdge1Entry = theEdge1Entry;
3040         periodicity_i->theFace2Entry = theFace2Entry;
3041         periodicity_i->theEdge2Entry = theEdge2Entry;
3042         periodicity_i->edge_orientation = edge_orientation;
3043
3044         _edgesPeriodicityVector.push_back(*periodicity_i);
3045
3046         break; // __END_PERIODICITY_DESCRIPTION__
3047       }
3048
3049       if (periodicitySeparator == "__BEGIN_FACE1__") {  // __BEGIN_FACE1__
3050         isOK = static_cast<bool>(load >> theFace1Entry);
3051         MESSAGE("//" << theFace1Entry << "//");
3052         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3053         if (periodicitySeparator != "__END_FACE1__"){
3054           MESSAGE("//" << periodicitySeparator << "//");
3055           throw std::exception();
3056         }
3057         MESSAGE("theFace1Entry: " <<theFace1Entry);
3058       }
3059
3060       if (periodicitySeparator == "__BEGIN_EDGE1__") {  // __BEGIN_EDGE1__
3061         isOK = static_cast<bool>(load >> theEdge1Entry);
3062         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3063         if (periodicitySeparator != "__END_EDGE1__")
3064           throw std::exception();
3065         MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3066       }
3067
3068       if (periodicitySeparator == "__BEGIN_FACE2__") {  // __BEGIN_FACE2__
3069         isOK = static_cast<bool>(load >> theFace2Entry);
3070         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3071         if (periodicitySeparator != "__END_FACE2__")
3072           throw std::exception();
3073         MESSAGE("theFace2Entry: " <<theFace2Entry);
3074       }
3075
3076       if (periodicitySeparator == "__BEGIN_EDGE2__") {  // __BEGIN_EDGE2__
3077         isOK = static_cast<bool>(load >> theEdge2Entry);
3078         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3079         if (periodicitySeparator != "__END_EDGE2__")
3080           throw std::exception();
3081         MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3082       }
3083
3084       if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") {  // __BEGIN_EDGE_ORIENTATION__
3085         isOK = static_cast<bool>(load >> edge_orientation);
3086         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3087         if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3088           throw std::exception();
3089         MESSAGE("edge_orientation: " <<edge_orientation);
3090       }
3091     }
3092   }
3093 }
3094
3095 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
3096
3097   bool isOK = true;
3098
3099   std::string periodicitySeparator;
3100   TEntry theEdge1Entry;
3101   TEntry theVertex1Entry;
3102   TEntry theEdge2Entry;
3103   TEntry theVertex2Entry;
3104
3105   _verticesPeriodicityVector.clear();
3106
3107   while (isOK) {
3108     isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3109     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3110     TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3111     if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3112       break; // __VERTICES_PERIODICITY_END__
3113     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3114       MESSAGE("//" << periodicitySeparator << "//");
3115       throw std::exception();
3116     }
3117
3118     while (isOK) {
3119       isOK = static_cast<bool>(load >> periodicitySeparator);
3120       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3121       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3122
3123         periodicity_i->theEdge1Entry = theEdge1Entry;
3124         periodicity_i->theVertex1Entry = theVertex1Entry;
3125         periodicity_i->theEdge2Entry = theEdge2Entry;
3126         periodicity_i->theVertex2Entry = theVertex2Entry;
3127
3128         _verticesPeriodicityVector.push_back(*periodicity_i);
3129
3130         break; // __END_PERIODICITY_DESCRIPTION__
3131       }
3132
3133       if (periodicitySeparator == "__BEGIN_EDGE1__") {  // __BEGIN_EDGE1__
3134         isOK = static_cast<bool>(load >> theEdge1Entry);
3135         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3136         if (periodicitySeparator != "__END_EDGE1__")
3137           throw std::exception();
3138         MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3139       }
3140
3141       if (periodicitySeparator == "__BEGIN_VERTEX1__") {  // __BEGIN_VERTEX1__
3142         isOK = static_cast<bool>(load >> theVertex1Entry);
3143         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3144         if (periodicitySeparator != "__END_VERTEX1__")
3145           throw std::exception();
3146         MESSAGE("theVertex1Entry: " <<theVertex1Entry);
3147       }
3148
3149       if (periodicitySeparator == "__BEGIN_EDGE2__") {  // __BEGIN_EDGE2__
3150         isOK = static_cast<bool>(load >> theEdge2Entry);
3151         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3152         if (periodicitySeparator != "__END_EDGE2__")
3153           throw std::exception();
3154         MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3155       }
3156
3157       if (periodicitySeparator == "__BEGIN_VERTEX2__") {  // __BEGIN_VERTEX2__
3158         isOK = static_cast<bool>(load >> theVertex2Entry);
3159         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3160         if (periodicitySeparator != "__END_VERTEX2__")
3161           throw std::exception();
3162         MESSAGE("theVertex2Entry: " <<theVertex2Entry);
3163       }
3164     }
3165   }
3166 }
3167
3168 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3169
3170   bool isOK = true;
3171
3172   std::string periodicitySeparator;
3173   TEntry shape1Entry;
3174   TEntry shape2Entry;
3175   std::vector<std::string> theSourceVerticesEntries;
3176   std::vector<std::string> theTargetVerticesEntries;
3177
3178   bool hasSourceVertices = false;
3179   bool hasTargetVertices = false;
3180
3181   if ( shapeType  &&  strcmp( shapeType, "FACES") == 0 )
3182     _preCadFacesPeriodicityVector.clear();
3183   else
3184     _preCadEdgesPeriodicityVector.clear();
3185
3186
3187   while (isOK) {
3188     isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3189     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3190     TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3191 //     MESSAGE("periodicitySeparator: " <<periodicitySeparator);
3192     std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3193     if (periodicitySeparator == endSeparator)
3194       break; // __PRECAD_FACES_PERIODICITY_END__
3195     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3196       MESSAGE("//" << endSeparator << "//");
3197       MESSAGE("//" << periodicitySeparator << "//");
3198       throw std::exception();
3199     }
3200
3201     while (isOK) {
3202       isOK = static_cast<bool>(load >> periodicitySeparator);
3203       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3204       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3205
3206         periodicity_i->shape1Entry = shape1Entry;
3207         periodicity_i->shape2Entry = shape2Entry;
3208
3209         MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
3210         MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
3211
3212         if (hasSourceVertices)
3213           periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3214         if (hasTargetVertices)
3215           periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3216
3217         if ( shapeType  &&  strcmp( shapeType, "FACES" ))
3218           _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3219         else
3220           _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3221
3222         theSourceVerticesEntries.clear();
3223         theTargetVerticesEntries.clear();
3224         hasSourceVertices = false;
3225         hasTargetVertices = false;
3226         break; // __END_PERIODICITY_DESCRIPTION__
3227       }
3228
3229       if (periodicitySeparator == "__BEGIN_ENTRY1__") {  // __BEGIN_ENTRY1__
3230         isOK = static_cast<bool>(load >> shape1Entry);
3231         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3232         if (periodicitySeparator != "__END_ENTRY1__")
3233           throw std::exception();
3234         MESSAGE("shape1Entry: " <<shape1Entry);
3235       }
3236
3237       if (periodicitySeparator == "__BEGIN_ENTRY2__") {  // __BEGIN_ENTRY2__
3238         isOK = static_cast<bool>(load >> shape2Entry);
3239         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3240         if (periodicitySeparator != "__END_ENTRY2__")
3241           throw std::exception();
3242         MESSAGE("shape2Entry: " <<shape2Entry);
3243       }
3244
3245       if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") {  // __BEGIN_SOURCE_VERTICES_LIST__
3246         hasSourceVertices = true;
3247         while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3248           isOK = static_cast<bool>(load >> periodicitySeparator);
3249           if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3250             theSourceVerticesEntries.push_back(periodicitySeparator);
3251             MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
3252           }
3253         }
3254       }
3255
3256       if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") {  // __BEGIN_TARGET_VERTICES_LIST__
3257         hasTargetVertices = true;
3258         while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3259           isOK = static_cast<bool>(load >> periodicitySeparator);
3260           if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3261             theTargetVerticesEntries.push_back(periodicitySeparator);
3262             MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
3263           }
3264         }
3265       }
3266     }
3267   }
3268 }
3269
3270 //=============================================================================
3271 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3272   return hyp.SaveTo(save);
3273 }
3274
3275 //=============================================================================
3276 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3277   return hyp.LoadFrom(load);
3278 }
3279
3280 //================================================================================
3281 /*!
3282  * \brief Does nothing
3283  */
3284 //================================================================================
3285
3286 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3287   return false;
3288 }
3289
3290 //================================================================================
3291 /*!
3292  * \brief Returns default global constant physical size given a default value of element length ratio
3293  */
3294 //================================================================================
3295
3296 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3297   if (bbSegmentation != 0 && diagonal != 0)
3298     return diagonal / bbSegmentation ;
3299   return 10;
3300 }
3301
3302 //================================================================================
3303 /*!
3304  * \brief Returns default min size given a default value of element length ratio
3305  */
3306 //================================================================================
3307
3308 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3309   if (diagonal != 0)
3310     return diagonal / 1000.0 ;
3311   return undefinedDouble();
3312 }
3313
3314 //================================================================================
3315 /*!
3316  * \brief Returns default max size given a default value of element length ratio
3317  */
3318 //================================================================================
3319
3320 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3321   if (diagonal != 0)
3322     return diagonal / 5.0 ;
3323   return undefinedDouble();
3324 }
3325
3326 //================================================================================
3327 /*!
3328  * \brief Returns default chordal error given a default value of element length ratio
3329  */
3330 //================================================================================
3331
3332 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3333   if (diagonal != 0)
3334     return diagonal;
3335   return undefinedDouble();
3336 }
3337
3338 //================================================================================
3339 /*!
3340  * \brief Returns default tiny edge length given a default value of element length ratio
3341  */
3342 //================================================================================
3343
3344 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3345   if (diagonal != 0)
3346     return diagonal * 1e-6 ;
3347   return undefinedDouble();
3348 }
3349
3350 //================================================================================
3351 /*!
3352  * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3353  */
3354 //================================================================================
3355
3356 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3357   if (diagonal != 0)
3358     return diagonal * 1e-6 ;
3359   return undefinedDouble();
3360 }
3361
3362 //=============================================================================
3363 /*!
3364  * \brief Initialize my parameter values by default parameters.
3365  *  \retval bool - true if parameter values have been successfully defined
3366  */
3367 //=============================================================================
3368
3369 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3370   double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3371   _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3372   _minSize = GetDefaultMinSize(diagonal);
3373   _maxSize = GetDefaultMaxSize(diagonal);
3374   _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3375   _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3376   _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3377
3378   return true;
3379 }
3380
3381 //================================================================================
3382 /*!
3383  * \brief Converts a string to a bool
3384  */
3385 //================================================================================
3386
3387 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3388   throw (std::invalid_argument)
3389 {
3390   std::string s = str;
3391   if ( isOk ) *isOk = true;
3392
3393   for ( size_t i = 0; i <= s.size(); ++i )
3394     s[i] = tolower( s[i] );
3395
3396   if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3397     return true;
3398
3399   if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3400     return false;
3401
3402   if ( isOk )
3403     *isOk = false;
3404   else {
3405     std::string msg = "Not a Boolean value:'" + str + "'";
3406     throw std::invalid_argument(msg);
3407   }
3408   return false;
3409 }
3410
3411 //================================================================================
3412 /*!
3413  * \brief Converts a string to a real value
3414  */
3415 //================================================================================
3416
3417 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3418   throw (std::invalid_argument)
3419 {
3420   if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3421
3422   char * endPtr;
3423   double val = strtod(&str[0], &endPtr);
3424   bool ok = (&str[0] != endPtr);
3425
3426   if ( isOk ) *isOk = ok;
3427
3428   if ( !ok )
3429   {
3430     std::string msg = "Not a real value:'" + str + "'";
3431     throw std::invalid_argument(msg);
3432   }
3433   return val;
3434 }
3435
3436 //================================================================================
3437 /*!
3438  * \brief Converts a string to a integer value
3439  */
3440 //================================================================================
3441
3442 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3443   throw (std::invalid_argument)
3444 {
3445   if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3446
3447   char * endPtr;
3448   int val = (int)strtol( &str[0], &endPtr, 10);
3449   bool ok = (&str[0] != endPtr);
3450
3451   if ( isOk ) *isOk = ok;
3452
3453   if ( !ok )
3454   {
3455     std::string msg = "Not an integer value:'" + str + "'";
3456     throw std::invalid_argument(msg);
3457   }
3458   return val;
3459 }
3460