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