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