Salome HOME
Copyrights update 2015.
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
1 // Copyright (C) 2007-2015  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 //=============================================================================
43 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) :
44   SMESH_Hypothesis(hypId, studyId, gen), 
45   _physicalMesh(GetDefaultPhysicalMesh()),
46   _geometricMesh(GetDefaultGeometricMesh()),
47   _phySize(GetDefaultPhySize()),
48   _phySizeRel(GetDefaultPhySizeRel()),
49   _minSize(GetDefaultMinSize()),
50   _minSizeRel(GetDefaultMinSizeRel()),
51   _maxSize(GetDefaultMaxSize()),
52   _maxSizeRel(GetDefaultMaxSizeRel()),
53   _gradation(GetDefaultGradation()),
54   _quadAllowed(GetDefaultQuadAllowed()),
55   _angleMesh(GetDefaultAngleMesh()),
56   _chordalError(GetDefaultChordalError()), 
57   _anisotropic(GetDefaultAnisotropic()),
58   _anisotropicRatio(GetDefaultAnisotropicRatio()),
59   _removeTinyEdges(GetDefaultRemoveTinyEdges()),
60   _tinyEdgeLength(GetDefaultTinyEdgeLength()),
61   _badElementRemoval(GetDefaultBadElementRemoval()),
62   _badElementAspectRatio(GetDefaultBadElementAspectRatio()),
63   _optimizeMesh(GetDefaultOptimizeMesh()),
64   _quadraticMesh(GetDefaultQuadraticMesh()),
65   _verb(GetDefaultVerbosity()),
66   _topology(GetDefaultTopology()),
67   _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
68   _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
69   _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
70   _sizeMap(GetDefaultSizeMap()),
71   _attractors(GetDefaultSizeMap()),
72   _classAttractors(GetDefaultAttractorMap()),
73   _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
74   _enfVertexList(GetDefaultEnfVertexList()),
75   _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
76   _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
77   _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
78   _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
79   _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
80   _GMFFileName(GetDefaultGMFFile()),
81   _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
82   _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
83   _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector())
84 {
85   _name = GetHypType();
86   _param_algo_dim = 2;
87   
88 //   _GMFFileMode = false; // GMF ascii mode
89
90   const char* boolOptionNames[] = {         "correct_surface_intersections",            // default = 1
91                                             "create_tag_on_collision",                  // default = 1
92                                             "debug",                                    // default = 0
93                                             "enforce_cad_edge_sizes",                   // default = 0
94                                             "frontal",                                  // ok default = 1
95                                             "jacobian_rectification_respect_geometry",  // default = 1
96                                             "proximity",                                // default = 0
97                                             "rectify_jacobian",                         // default = 1
98                                             "respect_geometry",                         // default = 1
99                                             "" // mark of end
100       };
101
102   const char* intOptionNames[] = {          "hinterpol_flag",                           // ok default = 0
103                                             "hmean_flag",                               // ok default = 0
104                                             "max_number_of_points_per_patch",           // default = 100000
105                                             "prox_nb_layer",                            // detects the volumic proximity of surfaces
106                                             "" // mark of end
107       };
108   const char* doubleOptionNames[] = {       "surface_intersections_processing_max_cost",// default = 15
109                                             "periodic_tolerance",                       // default = diag/100
110                                             "prox_ratio",
111                                             "volume_gradation"
112                                             "" // mark of end
113       };
114   const char* charOptionNames[] = {         "required_entities",                        // default = "respect"
115                                             "tags",                                     // default = "respect"
116                                             "" // mark of end
117       };
118
119   // PreCAD advanced options
120   const char* preCADboolOptionNames[] = {   "closed_geometry",                          // default = 0
121                                             "create_tag_on_collision",                  // default = 1
122                                             "debug",                                    // default = 0 
123                                             "remove_tiny_edges",                        // default = 0
124                                             "" // mark of end
125       };
126   const char* preCADintOptionNames[] = {    "manifold_geometry",                        // default = 0
127                                             "" // mark of end
128       };
129   const char* preCADdoubleOptionNames[] = { "periodic_tolerance",                       // default = diag * 1e-5
130                                             "sewing_tolerance",                         // default = diag * 5e-4
131                                             "tiny_edge_length",                         // default = diag * 1e-5
132                                             "" // mark of end
133       };
134   const char* preCADcharOptionNames[] = {   "required_entities",                        // default = "respect"
135                                             "tags",                                     // default = "respect"
136                                             "" // mark of end
137       };
138   
139   int i = 0;
140   while (boolOptionNames[i][0])
141     _option2value[boolOptionNames[i++]].clear();
142   
143   i = 0;
144   while (preCADboolOptionNames[i][0])
145     _preCADoption2value[preCADboolOptionNames[i++]].clear();
146   
147   i = 0;
148   while (intOptionNames[i][0])
149     _option2value[intOptionNames[i++]].clear();
150   
151   i = 0;
152   while (preCADintOptionNames[i][0])
153     _preCADoption2value[preCADintOptionNames[i++]].clear();
154
155   i = 0;
156   while (doubleOptionNames[i][0]) {
157     _doubleOptions.insert(doubleOptionNames[i]);
158     _option2value[doubleOptionNames[i++]].clear();
159   }
160   i = 0;
161   while (preCADdoubleOptionNames[i][0]) {
162     _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
163     _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
164   }
165   i = 0;
166   while (charOptionNames[i][0]) {
167     _charOptions.insert(charOptionNames[i]);
168     _option2value[charOptionNames[i++]].clear();
169   }
170   i = 0;
171   while (preCADcharOptionNames[i][0]) {
172     _preCADcharOptions.insert(preCADcharOptionNames[i]);
173     _preCADoption2value[preCADcharOptionNames[i++]].clear();
174   }
175   
176
177       
178   _sizeMap.clear();
179   _attractors.clear();
180   _faceEntryEnfVertexListMap.clear();
181   _enfVertexList.clear();
182   _faceEntryCoordsListMap.clear();
183   _coordsEnfVertexMap.clear();
184   _faceEntryEnfVertexEntryListMap.clear();
185   _enfVertexEntryEnfVertexMap.clear();
186   _groupNameNodeIDMap.clear();
187
188   /* TODO GROUPS
189    _groupNameEnfVertexListMap.clear();
190    _enfVertexGroupNameMap.clear();
191    */
192 }
193
194 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
195 {
196   MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
197   GEOM::GEOM_Object_var aGeomObj;
198   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
199   SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
200   
201   TopoDS_Shape S = TopoDS_Shape();
202   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
203   if (!aSObj->_is_nil() ) {
204     CORBA::Object_var obj = aSObj->GetObject();
205     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
206     aSObj->UnRegister();
207   }
208   if ( !aGeomObj->_is_nil() )
209     S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
210   return S;
211 }
212
213 //=============================================================================
214 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
215   if (thePhysicalMesh != _physicalMesh) {
216     _physicalMesh = thePhysicalMesh;
217     NotifySubMeshesHypothesisModification();
218   }
219 }
220
221 //=============================================================================
222 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
223   if (theGeometricMesh != _geometricMesh) {
224     _geometricMesh = theGeometricMesh;
225 //     switch (_geometricMesh) {
226 //       case DefaultGeom:
227 //       default:
228 //         _angleMesh = GetDefaultAngleMesh();
229 //         _gradation = GetDefaultGradation();
230 //         break;
231 //     }
232     NotifySubMeshesHypothesisModification();
233   }
234 }
235
236 //=============================================================================
237 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
238   if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
239     _phySizeRel = isRelative;
240     if (theVal == 0) {
241       _phySize = GetMaxSize();
242       MESSAGE("Warning: nul physical size is not allowed");
243     }
244     else
245       _phySize = theVal;
246     NotifySubMeshesHypothesisModification();
247   }
248 }
249
250 //=============================================================================
251 void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
252   if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
253     _minSizeRel = isRelative;
254     _minSize = theMinSize;
255     NotifySubMeshesHypothesisModification();
256   }
257 }
258
259 //=============================================================================
260 void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
261   if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
262     _maxSizeRel = isRelative;
263     _maxSize = theMaxSize;
264     NotifySubMeshesHypothesisModification();
265   }
266 }
267
268 //=============================================================================
269 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
270   if (theVal != _gradation) {
271     _gradation = theVal;
272     NotifySubMeshesHypothesisModification();
273   }
274 }
275
276 //=============================================================================
277 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
278   if (theVal != _quadAllowed) {
279     _quadAllowed = theVal;
280     NotifySubMeshesHypothesisModification();
281   }
282 }
283
284 //=============================================================================
285 void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
286   if (theVal != _angleMesh) {
287     _angleMesh = theVal;
288     NotifySubMeshesHypothesisModification();
289   }
290 }
291
292 //=============================================================================
293 void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
294   if (theDistance != _chordalError) {
295     _chordalError = theDistance;
296     NotifySubMeshesHypothesisModification();
297   }
298 }
299
300 //=============================================================================
301 void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
302   if (theVal != _anisotropic) {
303     _anisotropic = theVal;
304     NotifySubMeshesHypothesisModification();
305   }
306 }
307
308 //=============================================================================
309 void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
310   if (theVal != _anisotropicRatio) {
311     _anisotropicRatio = theVal;
312     NotifySubMeshesHypothesisModification();
313   }
314 }
315
316 //=============================================================================
317 void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
318   if (theVal != _removeTinyEdges) {
319     _removeTinyEdges = theVal;
320     NotifySubMeshesHypothesisModification();
321   }
322 }
323
324 //=============================================================================
325 void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
326   if (theVal != _tinyEdgeLength) {
327     _tinyEdgeLength = theVal;
328     NotifySubMeshesHypothesisModification();
329   }
330 }
331
332 //=============================================================================
333 void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
334   if (theVal != _badElementRemoval) {
335     _badElementRemoval = theVal;
336     NotifySubMeshesHypothesisModification();
337   }
338 }
339
340 //=============================================================================
341 void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
342   if (theVal != _badElementAspectRatio) {
343     _badElementAspectRatio = theVal;
344     NotifySubMeshesHypothesisModification();
345   }
346 }
347
348 //=============================================================================
349 void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
350   if (theVal != _optimizeMesh) {
351     _optimizeMesh = theVal;
352     NotifySubMeshesHypothesisModification();
353   }
354 }
355
356 //=============================================================================
357 void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
358   if (theVal != _quadraticMesh) {
359     _quadraticMesh = theVal;
360     NotifySubMeshesHypothesisModification();
361   }
362 }
363
364 //=============================================================================
365 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
366   if (theTopology != _topology) {
367     _topology = theTopology;
368     NotifySubMeshesHypothesisModification();
369   }
370 }
371
372 //=============================================================================
373 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
374   if (theVal != _verb) {
375     _verb = theVal;
376     NotifySubMeshesHypothesisModification();
377   }
378 }
379
380 //=============================================================================
381 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal) {
382   if (theVal != _preCADMergeEdges) {
383 //     SetTopology(PreCAD);
384     _preCADMergeEdges = theVal;
385     NotifySubMeshesHypothesisModification();
386   }
387 }
388
389 //=============================================================================
390 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal) {
391   if (theVal != _preCADProcess3DTopology) {
392 //     SetTopology(PreCAD);
393     _preCADProcess3DTopology = theVal;
394     NotifySubMeshesHypothesisModification();
395   }
396 }
397
398 //=============================================================================
399 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal) {
400   if (theVal != _preCADDiscardInput) {
401 //     SetTopology(PreCAD);
402     _preCADDiscardInput = theVal;
403     NotifySubMeshesHypothesisModification();
404   }
405 }
406
407 //=============================================================================
408 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
409 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
410 {
411   _GMFFileName = theFileName;
412 //   _GMFFileMode = isBinary;
413   NotifySubMeshesHypothesisModification();
414 }
415
416 //=============================================================================
417 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
418     throw (std::invalid_argument) {
419   TOptionValues::iterator op_val = _option2value.find(optionName);
420   if (op_val == _option2value.end()) {
421     std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'";
422     throw std::invalid_argument(msg);
423   }
424   if (op_val->second != optionValue) {
425     const char* ptr = optionValue.c_str();
426     // strip white spaces
427     while (ptr[0] == ' ')
428       ptr++;
429     int i = strlen(ptr);
430     while (i != 0 && ptr[i - 1] == ' ')
431       i--;
432     // check value type
433     bool typeOk = true;
434     std::string typeName;
435     if (i == 0) {
436       // empty string
437     } else if (_charOptions.find(optionName) != _charOptions.end()) {
438       // do not check strings
439     } else if (_doubleOptions.find(optionName) != _doubleOptions.end()) {
440       // check if value is double
441       char * endPtr;
442       strtod(ptr, &endPtr);
443       typeOk = (ptr != endPtr);
444       typeName = "real";
445     } else {
446       // check if value is int
447       char * endPtr;
448       strtol(ptr, &endPtr, 10);
449       typeOk = (ptr != endPtr);
450       typeName = "integer";
451     }
452     if (!typeOk) {
453       std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
454       throw std::invalid_argument(msg);
455     }
456     op_val->second = optionValue;
457     NotifySubMeshesHypothesisModification();
458   }
459 }
460
461 //=============================================================================
462 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
463     throw (std::invalid_argument) {
464   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
465   if (op_val == _preCADoption2value.end()) {
466     std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'";
467     throw std::invalid_argument(msg);
468   }
469   if (op_val->second != optionValue) {
470     const char* ptr = optionValue.c_str();
471     // strip white spaces
472     while (ptr[0] == ' ')
473       ptr++;
474     int i = strlen(ptr);
475     while (i != 0 && ptr[i - 1] == ' ')
476       i--;
477     // check value type
478     bool typeOk = true;
479     std::string typeName;
480     if (i == 0) {
481       // empty string
482     } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
483       // do not check strings
484     } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
485       // check if value is double
486       char * endPtr;
487       strtod(ptr, &endPtr);
488       typeOk = (ptr != endPtr);
489       typeName = "real";
490     } else {
491       // check if value is int
492       char * endPtr;
493       strtol(ptr, &endPtr, 10);
494       typeOk = (ptr != endPtr);
495       typeName = "integer";
496     }
497     if (!typeOk) {
498       std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
499       throw std::invalid_argument(msg);
500     }
501     op_val->second = optionValue;
502     NotifySubMeshesHypothesisModification();
503   }
504 }
505
506 //=============================================================================
507 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName) throw (std::invalid_argument) {
508   TOptionValues::iterator op_val = _option2value.find(optionName);
509   if (op_val == _option2value.end()) {
510     std::string msg = "Unknown MG-CADSurf option: <";
511     msg += optionName + ">";
512     throw std::invalid_argument(msg);
513   }
514   return op_val->second;
515 }
516
517 //=============================================================================
518 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName) throw (std::invalid_argument) {
519   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
520   if (op_val == _preCADoption2value.end()) {
521     std::string msg = "Unknown PRECAD option: <";
522     msg += optionName + ">";
523     throw std::invalid_argument(msg);
524   }
525   return op_val->second;
526 }
527
528 //=============================================================================
529 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName) {
530   TOptionValues::iterator op_val = _option2value.find(optionName);
531   if (op_val != _option2value.end())
532     op_val->second.clear();
533 }
534
535 //=============================================================================
536 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName) {
537   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
538   if (op_val != _preCADoption2value.end())
539     op_val->second.clear();
540 }
541
542 //=======================================================================
543 //function : SetSizeMapEntry
544 //=======================================================================
545 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
546   if (_sizeMap[entry].compare(sizeMap) != 0) {
547     SetPhysicalMesh(PhysicalLocalSize);
548     _sizeMap[entry] = sizeMap;
549     NotifySubMeshesHypothesisModification();
550   }
551 }
552
553 //=======================================================================
554 //function : GetSizeMapEntry
555 //=======================================================================
556 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
557   TSizeMap::iterator it = _sizeMap.find(entry);
558   if (it != _sizeMap.end())
559     return it->second;
560   else
561     return "No_Such_Entry";
562 }
563
564 /*!
565  * \brief Return the size maps
566  */
567 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
568   return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
569 }
570
571 //=======================================================================
572 //function : SetAttractorEntry
573 //=======================================================================
574 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
575   if (_attractors[entry].compare(attractor) != 0) {
576     SetPhysicalMesh(PhysicalLocalSize);
577     _attractors[entry] = attractor;
578     NotifySubMeshesHypothesisModification();
579   }
580 }
581
582 //=======================================================================
583 //function : GetAttractorEntry
584 //=======================================================================
585 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
586   TSizeMap::iterator it = _attractors.find(entry);
587   if (it != _attractors.end())
588     return it->second;
589   else
590     return "No_Such_Entry";
591 }
592
593 /*!
594  * \brief Return the attractors
595  */
596 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
597   return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
598 }
599
600 //=======================================================================
601 //function : SetClassAttractorEntry
602 //=======================================================================
603 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
604 {
605   SetPhysicalMesh(PhysicalLocalSize);
606
607   // The new attractor can't be defined on the same face as another sizemap
608   TSizeMap::iterator it  = _sizeMap.find( entry );
609   if ( it != _sizeMap.end() ) {
610     _sizeMap.erase(it);
611     NotifySubMeshesHypothesisModification();
612   }
613   else {
614     TSizeMap::iterator itAt  = _attractors.find( entry );
615     if ( itAt != _attractors.end() ) {
616       _attractors.erase(itAt);
617       NotifySubMeshesHypothesisModification();
618     }
619   }
620   
621   const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
622   const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
623   TAttractorMap::iterator attIt = _classAttractors.find(entry);
624   for ( ; attIt != _classAttractors.end(); ++attIt )
625     if ( attIt->first == entry && 
626          attIt->second->GetAttractorEntry() == attEntry )
627       break;
628   bool attExists = (attIt != _classAttractors.end());
629
630   BLSURFPlugin_Attractor* myAttractor;
631   if ( !attExists ) {
632     myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
633     _classAttractors.insert( make_pair( entry, myAttractor ));
634   }
635   else {
636     myAttractor = attIt->second;
637   }
638   // if (!myAttractor->IsMapBuilt())
639   //   myAttractor->BuildMap();
640   myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
641
642   NotifySubMeshesHypothesisModification();
643 }
644
645 //=======================================================================
646 //function : SetConstantSizeOnAdjacentFaces
647 //=======================================================================
648 // TODO uncomment and test (include the needed .hxx)
649 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist  ) {
650 //   TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
651 //   TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
652 //   TopTools_IndexedMapOfShapListOdShape::iterator it;
653 //   for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
654 //       SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
655 //   }
656
657
658
659
660
661
662 //=======================================================================
663 //function : GetClassAttractorEntry
664 //=======================================================================
665 // BLSURFPlugin_Attractor&  BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
666 // {
667 //  TAttractorMap::iterator it  = _classAttractors.find( entry );
668 //  if ( it != _classAttractors.end() )
669 //    return it->second;
670 //  else
671 //    return "No_Such_Entry";
672 // }
673 // 
674   /*!
675    * \brief Return the map of attractor instances
676    */
677 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
678 {
679     return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
680 }
681
682 //=======================================================================
683 //function : ClearEntry
684 //=======================================================================
685 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
686                                          const char * attEntry/*=0*/)
687 {
688  TSizeMap::iterator it  = _sizeMap.find( entry );
689  
690  if ( it != _sizeMap.end() ) {
691    _sizeMap.erase(it);
692    NotifySubMeshesHypothesisModification();
693  }
694  else {
695    TSizeMap::iterator itAt  = _attractors.find( entry );
696    if ( itAt != _attractors.end() ) {
697      _attractors.erase(itAt);
698      NotifySubMeshesHypothesisModification();
699    }
700    else {
701      TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
702      if ( it_clAt != _classAttractors.end() ) {
703        do {
704          if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
705            _classAttractors.erase( it_clAt++ );
706          else
707            ++it_clAt;
708        }
709        while ( it_clAt != _classAttractors.end() );
710        MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
711        NotifySubMeshesHypothesisModification();
712      }
713      else
714        std::cout<<"No_Such_Entry"<<std::endl;
715    }
716  }
717 }
718
719 //=======================================================================
720 //function : ClearSizeMaps
721 //=======================================================================
722 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
723   _sizeMap.clear();
724   _attractors.clear();
725   _classAttractors.clear();
726 }
727
728 // Enable internal enforced vertices on specific face if requested by user
729
730 ////=======================================================================
731 ////function : SetInternalEnforcedVertex
732 ////=======================================================================
733 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
734 //                                                        bool toEnforceInternalVertices,
735 //                                                        TEnfGroupName theGroupName) {
736
737 //  MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
738 //      << toEnforceInternalVertices << ", " << theGroupName << ")");
739   
740 //  TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
741 //  if (it != _faceEntryInternalVerticesList.end()) {
742 //    if (!toEnforceInternalVertices) {
743 //      _faceEntryInternalVerticesList.erase(it);
744 //    }
745 //  }
746 //  else {
747 //    if (toEnforceInternalVertices) {
748 //      _faceEntryInternalVerticesList.insert(theFaceEntry);
749 //    }
750 //  }
751   
752 //  // TODO
753 //  // Take care of groups
754 //}
755
756
757 //=======================================================================
758 //function : SetEnforcedVertex
759 //=======================================================================
760 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
761                                                 TEnfGroupName theGroupName, double x, double y, double z) {
762
763   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
764       << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
765
766   SetPhysicalMesh(PhysicalLocalSize);
767
768   //  TEnfVertexList::iterator it;
769   bool toNotify = false;
770   bool toCreate = true;
771
772   TEnfVertex *oldEnVertex;
773   TEnfVertex *newEnfVertex = new TEnfVertex();
774   newEnfVertex->name = theVertexName;
775   newEnfVertex->geomEntry = theVertexEntry;
776   newEnfVertex->coords.clear();
777   if (theVertexEntry == "") {
778     newEnfVertex->coords.push_back(x);
779     newEnfVertex->coords.push_back(y);
780     newEnfVertex->coords.push_back(z);
781   }
782   newEnfVertex->grpName = theGroupName;
783   newEnfVertex->faceEntries.clear();
784   newEnfVertex->faceEntries.insert(theFaceEntry);
785   
786   
787   // update _enfVertexList
788   TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
789   if (it != _enfVertexList.end()) {
790     toCreate = false;
791     oldEnVertex = (*it);
792     MESSAGE("Enforced Vertex was found => Update");
793     if (oldEnVertex->name != theVertexName) {
794       MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
795       oldEnVertex->name = theVertexName;
796       toNotify = true;
797     }
798     if (oldEnVertex->grpName != theGroupName) {
799       MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
800       oldEnVertex->grpName = theGroupName;
801       toNotify = true;
802     }
803     TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
804     if (it_faceEntries == oldEnVertex->faceEntries.end()) {
805       MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
806       oldEnVertex->faceEntries.insert(theFaceEntry);
807       _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
808       toNotify = true;
809     }
810     if (toNotify) {
811       // update map coords / enf vertex if needed
812       if (oldEnVertex->coords.size()) {
813         _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
814         _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
815       }
816
817       // update map geom entry / enf vertex if needed
818       if (oldEnVertex->geomEntry != "") {
819         _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
820         _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
821       }
822     }
823   }
824
825 //   //////// CREATE ////////////
826   if (toCreate) {
827     toNotify = true;
828     MESSAGE("Creating new enforced vertex");
829     _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
830     _enfVertexList.insert(newEnfVertex);
831     if (theVertexEntry == "") {
832       _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
833       _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
834     }
835     else {
836       _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
837       _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
838     }
839   }
840
841   if (toNotify)
842     NotifySubMeshesHypothesisModification();
843
844   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
845   return toNotify;
846 }
847
848
849 //=======================================================================
850 //function : GetEnforcedVertices
851 //=======================================================================
852
853 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
854     throw (std::invalid_argument) {
855
856   if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
857     return _faceEntryEnfVertexListMap[theFaceEntry];
858   else
859     return GetDefaultEnfVertexList();
860
861   std::ostringstream msg;
862   msg << "No enforced vertex for face entry " << theFaceEntry;
863   throw std::invalid_argument(msg.str());
864 }
865
866 //=======================================================================
867 //function : GetEnfVertexCoordsList
868 //=======================================================================
869
870 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
871     const TEntry& theFaceEntry) throw (std::invalid_argument) {
872
873   if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
874     return _faceEntryCoordsListMap[theFaceEntry];
875
876   std::ostringstream msg;
877   msg << "No enforced vertex coords for face entry " << theFaceEntry;
878   throw std::invalid_argument(msg.str());
879 }
880
881 //=======================================================================
882 //function : GetEnfVertexEntryList
883 //=======================================================================
884
885 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
886     throw (std::invalid_argument) {
887
888   if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
889     return _faceEntryEnfVertexEntryListMap[theFaceEntry];
890
891   std::ostringstream msg;
892   msg << "No enforced vertex entry for face entry " << theFaceEntry;
893   throw std::invalid_argument(msg.str());
894 }
895
896 //=======================================================================
897 //function : GetEnfVertex(TEnfVertexCoords coords)
898 //=======================================================================
899
900 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
901     throw (std::invalid_argument) {
902
903   if (_coordsEnfVertexMap.count(coords) > 0)
904     return _coordsEnfVertexMap[coords];
905
906   std::ostringstream msg;
907   msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
908   throw std::invalid_argument(msg.str());
909 }
910
911 //=======================================================================
912 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
913 //=======================================================================
914
915 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
916     throw (std::invalid_argument) {
917
918   if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
919     return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
920
921   std::ostringstream msg;
922   msg << "No enforced vertex with entry " << theEnfVertexEntry;
923   throw std::invalid_argument(msg.str());
924 }
925
926 //Enable internal enforced vertices on specific face if requested by user
927 ////=======================================================================
928 ////function : GetInternalEnforcedVertex
929 ////=======================================================================
930
931 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
932 //{
933 //  if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
934 //    return true;
935 //  return false;
936 //}
937
938 //=======================================================================
939 //function : ClearEnforcedVertex
940 //=======================================================================
941
942 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
943     const TEntry& theVertexEntry) throw (std::invalid_argument) {
944
945   bool toNotify = false;
946   std::ostringstream msg;
947   TEnfVertex *oldEnfVertex;
948   TEnfVertexCoords coords;
949   coords.clear();
950   coords.push_back(x);
951   coords.push_back(y);
952   coords.push_back(z);
953
954   // check that enf vertex with given enf vertex entry exists
955   TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
956   if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
957     // Success
958     MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
959     oldEnfVertex = it_enfVertexEntry->second;
960
961     _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
962
963     TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
964     enfVertexEntryList.erase(theVertexEntry);
965     if (enfVertexEntryList.size() == 0)
966       _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
967     //    TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
968     //    TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
969     //    it_entry_entry->second.erase(it_entryList);
970     //    if (it_entry_entry->second.size() == 0)
971     //      _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
972   } else {
973     // Fail
974     MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
975     msg << "No enforced vertex with geom entry " << theVertexEntry;
976     // check that enf vertex with given coords exists
977     TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
978     if (it_coords_enf != _coordsEnfVertexMap.end()) {
979       // Success
980       MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
981       oldEnfVertex = it_coords_enf->second;
982
983       _coordsEnfVertexMap.erase(it_coords_enf);
984
985       TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
986       enfVertexCoordsList.erase(coords);
987       if (enfVertexCoordsList.size() == 0)
988         _faceEntryCoordsListMap.erase(theFaceEntry);
989       //      TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
990       //      TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
991       //      it_entry_coords->second.erase(it_coordsList);
992       //      if (it_entry_coords->second.size() == 0)
993       //        _faceEntryCoordsListMap.erase(it_entry_coords);
994     } else {
995       // Fail
996       MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
997       msg << std::endl;
998       msg << "No enforced vertex at " << x << ", " << y << ", " << z;
999       throw std::invalid_argument(msg.str());
1000     }
1001   }
1002
1003   MESSAGE("Remove enf vertex from _enfVertexList");
1004
1005   // update _enfVertexList
1006   TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1007   if (it != _enfVertexList.end()) {
1008     (*it)->faceEntries.erase(theFaceEntry);
1009     if ((*it)->faceEntries.size() == 0){
1010       _enfVertexList.erase(it);
1011       toNotify = true;
1012     }
1013     MESSAGE("Done");
1014   }
1015
1016   // update _faceEntryEnfVertexListMap
1017   TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1018   currentEnfVertexList.erase(oldEnfVertex);
1019
1020   if (currentEnfVertexList.size() == 0) {
1021     MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
1022     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1023     MESSAGE("Done");
1024   }
1025
1026   if (toNotify)
1027     NotifySubMeshesHypothesisModification();
1028
1029   return toNotify;
1030 }
1031
1032 //=======================================================================
1033 //function : ClearEnforcedVertices
1034 //=======================================================================
1035
1036 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1037
1038   bool toNotify = false;
1039   TEnfVertex *oldEnfVertex;
1040
1041   TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1042   if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1043     toNotify = true;
1044     TEnfVertexCoordsList coordsList = it_entry_coords->second;
1045     TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1046     for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1047       TEnfVertexCoords coords = (*it_coordsList);
1048       oldEnfVertex = _coordsEnfVertexMap[coords];
1049       _coordsEnfVertexMap.erase(coords);
1050       // update _enfVertexList
1051       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1052       if (it != _enfVertexList.end()) {
1053         (*it)->faceEntries.erase(theFaceEntry);
1054         if ((*it)->faceEntries.size() == 0){
1055           _enfVertexList.erase(it);
1056           toNotify = true;
1057         }
1058         MESSAGE("Done");
1059       }
1060     }
1061     _faceEntryCoordsListMap.erase(it_entry_coords);
1062     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1063   }
1064
1065   TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1066   if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1067     toNotify = true;
1068     TEntryList enfVertexEntryList = it_entry_entry->second;
1069     TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1070     for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1071       TEntry enfVertexEntry = (*it_enfVertexEntryList);
1072       oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1073       _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1074       // update _enfVertexList
1075       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1076       if (it != _enfVertexList.end()) {
1077         (*it)->faceEntries.erase(theFaceEntry);
1078         if ((*it)->faceEntries.size() == 0){
1079           _enfVertexList.erase(it);
1080           toNotify = true;
1081         }
1082         MESSAGE("Done");
1083       }
1084     }
1085     _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1086     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1087   }
1088
1089   if (toNotify)
1090     NotifySubMeshesHypothesisModification();
1091
1092   return toNotify;
1093   //  std::ostringstream msg;
1094   //  msg << "No enforced vertex for " << theFaceEntry;
1095   //  throw std::invalid_argument(msg.str());
1096 }
1097
1098 //=======================================================================
1099 //function : ClearAllEnforcedVertices
1100 //=======================================================================
1101 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1102   _faceEntryEnfVertexListMap.clear();
1103   _enfVertexList.clear();
1104   _faceEntryCoordsListMap.clear();
1105   _coordsEnfVertexMap.clear();
1106   _faceEntryEnfVertexEntryListMap.clear();
1107   _enfVertexEntryEnfVertexMap.clear();
1108 //  Enable internal enforced vertices on specific face if requested by user
1109 //  _faceEntryInternalVerticesList.clear();
1110   NotifySubMeshesHypothesisModification();
1111 }
1112
1113 //================================================================================
1114 /*!
1115  * \brief Return the enforced vertices
1116  */
1117 //================================================================================
1118
1119
1120 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1121     const BLSURFPlugin_Hypothesis* hyp) {
1122   return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1123 }
1124
1125 //Enable internal enforced vertices on specific face if requested by user
1126 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1127 //    const BLSURFPlugin_Hypothesis* hyp) {
1128 //  return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1129 //}
1130
1131 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1132 {
1133   return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1134 }
1135
1136 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1137 {
1138   return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1139 }
1140
1141 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1142     const BLSURFPlugin_Hypothesis* hyp) {
1143   return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1144 }
1145
1146 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1147     const BLSURFPlugin_Hypothesis* hyp) {
1148   return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1149 }
1150
1151 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1152     const BLSURFPlugin_Hypothesis* hyp) {
1153   return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1154 }
1155
1156 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1157     const BLSURFPlugin_Hypothesis* hyp) {
1158   return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1159 }
1160
1161 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1162     const BLSURFPlugin_Hypothesis* hyp) {
1163   return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1164 }
1165
1166 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1167 {
1168   TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1169   if (it != _groupNameNodeIDMap.end()) {
1170     return it->second;
1171   }
1172   std::ostringstream msg;
1173   msg << "No group " << theGroupName;
1174   throw std::invalid_argument(msg.str());
1175 }
1176
1177 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1178 {
1179   _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1180 }
1181
1182 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1183 {
1184   TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1185   if (it != _groupNameNodeIDMap.end()) {
1186     std::set<int>::iterator IDit = it->second.find(theNodeID);
1187     if (IDit != it->second.end())
1188       it->second.erase(IDit);
1189     std::ostringstream msg;
1190     msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1191     throw std::invalid_argument(msg.str());
1192   }
1193   std::ostringstream msg;
1194   msg << "No group " << theGroupName;
1195   throw std::invalid_argument(msg.str());
1196 }
1197
1198
1199 //=============================================================================
1200 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1201   if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1202     _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1203     if (toEnforceInternalVertices)
1204       SetPhysicalMesh(PhysicalLocalSize);
1205     NotifySubMeshesHypothesisModification();
1206   }
1207 }
1208
1209
1210 //=============================================================================
1211 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1212   if (string(theGroupName) != string(_enforcedInternalVerticesAllFacesGroup)) {
1213     _enforcedInternalVerticesAllFacesGroup = theGroupName;
1214     NotifySubMeshesHypothesisModification();
1215   }
1216 }
1217
1218 //=============================================================================
1219 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1220     const BLSURFPlugin_Hypothesis* hyp) {
1221   return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1222 }
1223
1224 //=============================================================================
1225 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1226     const BLSURFPlugin_Hypothesis* hyp) {
1227   return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1228 }
1229
1230 //=============================================================================
1231 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1232     const BLSURFPlugin_Hypothesis* hyp) {
1233   return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1234 }
1235
1236 //=============================================================================
1237 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1238     const BLSURFPlugin_Hypothesis* hyp){
1239   return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1240 }
1241
1242 //=============================================================================
1243 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1244     const BLSURFPlugin_Hypothesis* hyp){
1245   return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1246 }
1247
1248 //=======================================================================
1249 //function : ClearAllEnforcedVertices
1250 //=======================================================================
1251 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1252   _preCadFacesPeriodicityVector.clear();
1253   _preCadEdgesPeriodicityVector.clear();
1254   NotifySubMeshesHypothesisModification();
1255 }
1256
1257 //=======================================================================
1258 //function : AddPreCadFacesPeriodicity
1259 //=======================================================================
1260 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1261     vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries) {
1262
1263   TPreCadPeriodicity preCadFacesPeriodicity;
1264   preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1265   preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1266   preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1267   preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1268
1269   _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1270
1271   NotifySubMeshesHypothesisModification();
1272 }
1273
1274 //=======================================================================
1275 //function : AddPreCadEdgesPeriodicity
1276 //=======================================================================
1277 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1278     vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries) {
1279
1280   TPreCadPeriodicity preCadEdgesPeriodicity;
1281   preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1282   preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1283   preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1284   preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1285
1286   _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1287
1288   NotifySubMeshesHypothesisModification();
1289 }
1290
1291 //=======================================================================
1292 //function : AddFacePeriodicity
1293 //=======================================================================
1294 void BLSURFPlugin_Hypothesis::AddFacePeriodicity(TEntry theFace1Entry, TEntry theFace2Entry) {
1295
1296   std::pair< TEntry, TEntry > pairOfFacesEntries = std::make_pair(theFace1Entry, theFace2Entry);
1297
1298   _facesPeriodicityVector.push_back(pairOfFacesEntries);
1299
1300   // Removed for performance reason since AddFacePeriodicity is called multiple times (one time for each face)
1301   // Does not affect the behaviour since it is only called via python, not via GUI.
1302   //NotifySubMeshesHypothesisModification();
1303 }
1304
1305
1306 //=======================================================================
1307 //function : AddEdgePeriodicity
1308 //=======================================================================
1309 void BLSURFPlugin_Hypothesis::AddEdgePeriodicity(TEntry theFace1Entry, TEntry theEdge1Entry, TEntry theFace2Entry, TEntry theEdge2Entry, int edge_orientation) {
1310
1311   TEdgePeriodicity edgePeriodicity;
1312   edgePeriodicity.theFace1Entry = theFace1Entry;
1313   edgePeriodicity.theEdge1Entry = theEdge1Entry;
1314   edgePeriodicity.theFace2Entry = theFace2Entry;
1315   edgePeriodicity.theEdge2Entry = theEdge2Entry;
1316   edgePeriodicity.edge_orientation = edge_orientation;
1317
1318   _edgesPeriodicityVector.push_back(edgePeriodicity);
1319
1320   // Removed for performance reason since AddEdgePeriodicity is called multiple times (one time for each edge)
1321   // Does not affect the behaviour since it is only called via python, not via GUI.
1322   //NotifySubMeshesHypothesisModification();
1323 }
1324
1325 //=======================================================================
1326 //function : AddVertexPeriodicity
1327 //=======================================================================
1328 void BLSURFPlugin_Hypothesis::AddVertexPeriodicity(TEntry theEdge1Entry, TEntry theVertex1Entry, TEntry theEdge2Entry, TEntry theVertex2Entry) {
1329
1330   TVertexPeriodicity vertexPeriodicity;
1331   vertexPeriodicity.theEdge1Entry = theEdge1Entry;
1332   vertexPeriodicity.theVertex1Entry = theVertex1Entry;
1333   vertexPeriodicity.theEdge2Entry = theEdge2Entry;
1334   vertexPeriodicity.theVertex2Entry = theVertex2Entry;
1335
1336   _verticesPeriodicityVector.push_back(vertexPeriodicity);
1337
1338   // Removed for performance reason since AddVertexPeriodicity is called multiple times (one time for each vertex)
1339   // Does not affect the behaviour since it is only called via python, not via GUI.
1340   //NotifySubMeshesHypothesisModification();
1341 }
1342
1343 //=============================================================================
1344 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1345    // We must keep at least the same number of arguments when increasing the SALOME version
1346    // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1347    // parameter can be written several times to keep the old global number of parameters.
1348
1349    // Treat old options which are now in the advanced options
1350    TOptionValues::iterator op_val;
1351    int _decimesh = -1;
1352    int _preCADRemoveNanoEdges = -1;
1353    double _preCADEpsNano = -1.0;
1354    op_val = _option2value.find("respect_geometry");
1355    if (op_val != _option2value.end()) {
1356      std::string value = op_val->second;
1357      if (!value.empty())
1358        _decimesh = value.compare("1") == 0 ? 1 : 0;
1359    }
1360    op_val = _preCADoption2value.find("remove_tiny_edges");
1361    if (op_val != _preCADoption2value.end()) {
1362      std::string value = op_val->second;
1363      if (!value.empty())
1364        _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1365    }
1366    op_val = _preCADoption2value.find("tiny_edge_length");
1367    if (op_val != _preCADoption2value.end()) {
1368      std::string value = op_val->second;
1369      if (!value.empty())
1370        _preCADEpsNano = strtod(value.c_str(), NULL);
1371    }
1372    
1373   save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1374       << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1375   save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1376   save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1377   save << " " << (int) _enforcedInternalVerticesAllFaces;
1378   save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1379   save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1380   save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1381   save << " " << (int) _preCADProcess3DTopology;
1382
1383   op_val = _option2value.begin();
1384   if (op_val != _option2value.end()) {
1385     save << " " << "__OPTIONS_BEGIN__";
1386     for (; op_val != _option2value.end(); ++op_val) {
1387       if (!op_val->second.empty())
1388         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1389     }
1390     save << " " << "__OPTIONS_END__";
1391   }
1392   
1393   op_val = _preCADoption2value.begin();
1394   if (op_val != _preCADoption2value.end()) {
1395     save << " " << "__PRECAD_OPTIONS_BEGIN__";
1396     for (; op_val != _preCADoption2value.end(); ++op_val) {
1397       if (!op_val->second.empty())
1398         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1399     }
1400     save << " " << "__PRECAD_OPTIONS_END__";
1401   }
1402
1403   TSizeMap::iterator it_sm = _sizeMap.begin();
1404   if (it_sm != _sizeMap.end()) {
1405     save << " " << "__SIZEMAP_BEGIN__";
1406     for (; it_sm != _sizeMap.end(); ++it_sm) {
1407       save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1408     }
1409     save << " " << "__SIZEMAP_END__";
1410   }
1411
1412   TSizeMap::iterator it_at = _attractors.begin();
1413   if (it_at != _attractors.end()) {
1414     save << " " << "__ATTRACTORS_BEGIN__";
1415     for (; it_at != _attractors.end(); ++it_at) {
1416       save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1417     }
1418     save << " " << "__ATTRACTORS_END__";
1419   }
1420   
1421   TAttractorMap::iterator it_At = _classAttractors.begin();
1422   if (it_At != _classAttractors.end()) {
1423     std::ostringstream test;
1424     save << " " << "__NEW_ATTRACTORS_BEGIN__";
1425     test << " " << "__NEW_ATTRACTORS_BEGIN__";
1426     for (; it_At != _classAttractors.end(); ++it_At) {
1427       std::vector<double> attParams;
1428       attParams   = it_At->second->GetParameters();
1429 //       double step = it_At->second->GetStep();
1430       save << " " << it_At->first;
1431       save << " " << it_At->second->GetAttractorEntry();
1432       save << " " << attParams[0]  << " " <<  attParams[1] << " " <<  attParams[2] << " " <<  attParams[3];
1433 //       save << " " << step;
1434       test << " " << it_At->first;
1435       test << " " << it_At->second->GetAttractorEntry();
1436       test << " " << attParams[0]  << " " <<  attParams[1] << " " <<  attParams[2] << " " <<  attParams[3];
1437 //       test << " " << step;
1438     }
1439     save << " " << "__NEW_ATTRACTORS_END__";
1440     test << " " << "__NEW_ATTRACTORS_END__";
1441     MESSAGE(" Attractor hypothesis saved as "<<test.str())
1442   }
1443
1444   TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1445   if (it_enf != _enfVertexList.end()) {
1446     save << " " << "__ENFORCED_VERTICES_BEGIN__";
1447     for (; it_enf != _enfVertexList.end(); ++it_enf) {
1448       TEnfVertex *enfVertex = (*it_enf);
1449       save << " " << "__BEGIN_VERTEX__";
1450       if (!enfVertex->name.empty()) {
1451         save << " " << "__BEGIN_NAME__";
1452         save << " " << enfVertex->name;
1453         save << " " << "__END_NAME__";
1454       }
1455       if (!enfVertex->geomEntry.empty()) {
1456         save << " " << "__BEGIN_ENTRY__";
1457         save << " " << enfVertex->geomEntry;
1458         save << " " << "__END_ENTRY__";
1459       }
1460       if (!enfVertex->grpName.empty()) {
1461         save << " " << "__BEGIN_GROUP__";
1462         save << " " << enfVertex->grpName;
1463         save << " " << "__END_GROUP__";
1464       }
1465       if (enfVertex->coords.size()) {
1466         save << " " << "__BEGIN_COORDS__";
1467         for (int i=0;i<enfVertex->coords.size();i++)
1468           save << " " << enfVertex->coords[i];
1469         save << " " << "__END_COORDS__";
1470       }
1471       TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1472       bool hasFaces = false;
1473       if (faceEntriesIt != enfVertex->faceEntries.end()) {
1474         hasFaces = true;
1475         save << " " << "__BEGIN_FACELIST__";
1476       }
1477       for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1478         save << " " << (*faceEntriesIt);
1479       if (hasFaces)
1480         save << " " << "__END_FACELIST__";
1481       save << " " << "__END_VERTEX__";
1482     }
1483     save << " " << "__ENFORCED_VERTICES_END__";
1484   }
1485
1486   //PERIODICITY
1487
1488   SavePreCADPeriodicity(save, "FACES");
1489   SavePreCADPeriodicity(save, "EDGES");
1490
1491   SaveFacesPeriodicity(save);
1492   SaveEdgesPeriodicity(save);
1493   SaveVerticesPeriodicity(save);
1494
1495   return save;
1496 }
1497
1498 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1499
1500   TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1501   if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1502     MESSAGE("__FACES_PERIODICITY_BEGIN__");
1503     save << " " << "__FACES_PERIODICITY_BEGIN__";
1504     for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1505       TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1506       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1507       save << " " << "__BEGIN_ENTRY1__";
1508       save << " " << periodicity_i.first;
1509       save << " " << "__END_ENTRY1__";
1510       save << " " << "__BEGIN_ENTRY2__";
1511       save << " " << periodicity_i.second;
1512       save << " " << "__END_ENTRY2__";
1513       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1514     }
1515     save << " " << "__FACES_PERIODICITY_END__";
1516     MESSAGE("__FACES_PERIODICITY_END__");
1517   }
1518 }
1519
1520 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
1521
1522   TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
1523   if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
1524     save << " " << "__EDGES_PERIODICITY_BEGIN__";
1525     MESSAGE("__EDGES_PERIODICITY_BEGIN__");
1526     for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
1527       TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
1528       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1529       if (! periodicity_i.theFace1Entry.empty()){
1530         save << " " << "__BEGIN_FACE1__";
1531         save << " " << periodicity_i.theFace1Entry;
1532         save << " " << "__END_FACE1__";
1533       }
1534       save << " " << "__BEGIN_EDGE1__";
1535       save << " " << periodicity_i.theEdge1Entry;
1536       save << " " << "__END_EDGE1__";
1537       if (! periodicity_i.theFace2Entry.empty()){
1538         save << " " << "__BEGIN_FACE2__";
1539         save << " " << periodicity_i.theFace2Entry;
1540         save << " " << "__END_FACE2__";
1541       }
1542       save << " " << "__BEGIN_EDGE2__";
1543       save << " " << periodicity_i.theEdge2Entry;
1544       save << " " << "__END_EDGE2__";
1545       save << " " << "__BEGIN_EDGE_ORIENTATION__";
1546       save << " " << periodicity_i.edge_orientation;
1547       save << " " << "__END_EDGE_ORIENTATION__";
1548       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1549     }
1550     save << " " << "__EDGES_PERIODICITY_END__";
1551     MESSAGE("__EDGES_PERIODICITY_END__");
1552   }
1553 }
1554
1555 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
1556
1557   TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
1558   if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
1559     MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
1560     save << " " << "__VERTICES_PERIODICITY_BEGIN__";
1561     for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
1562       TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
1563       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1564       save << " " << "__BEGIN_EDGE1__";
1565       save << " " << periodicity_i.theEdge1Entry;
1566       save << " " << "__END_EDGE1__";
1567       save << " " << "__BEGIN_VERTEX1__";
1568       save << " " << periodicity_i.theVertex1Entry;
1569       save << " " << "__END_VERTEX1__";
1570       save << " " << "__BEGIN_EDGE2__";
1571       save << " " << periodicity_i.theEdge2Entry;
1572       save << " " << "__END_EDGE2__";
1573       save << " " << "__BEGIN_VERTEX2__";
1574       save << " " << periodicity_i.theVertex2Entry;
1575       save << " " << "__END_VERTEX2__";
1576       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1577     }
1578     save << " " << "__VERTICES_PERIODICITY_END__";
1579     MESSAGE("__VERTICES_PERIODICITY_END__");
1580   }
1581 }
1582
1583 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
1584   TPreCadPeriodicityVector precad_periodicity;
1585   if (shapeType == "FACES")
1586     precad_periodicity = _preCadFacesPeriodicityVector;
1587   else
1588     precad_periodicity = _preCadEdgesPeriodicityVector;
1589   TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
1590   if (it_precad_periodicity != precad_periodicity.end()) {
1591     save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
1592     for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
1593       TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
1594       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1595       if (!periodicity_i.shape1Entry.empty()) {
1596         save << " " << "__BEGIN_ENTRY1__";
1597         save << " " << periodicity_i.shape1Entry;
1598         save << " " << "__END_ENTRY1__";
1599       }
1600       if (!periodicity_i.shape2Entry.empty()) {
1601         save << " " << "__BEGIN_ENTRY2__";
1602         save << " " << periodicity_i.shape2Entry;
1603         save << " " << "__END_ENTRY2__";
1604       }
1605
1606       std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
1607       bool hasSourceVertices = false;
1608       if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
1609         hasSourceVertices = true;
1610         save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
1611       }
1612       for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
1613         save << " " << (*sourceVerticesEntriesIt);
1614       if (hasSourceVertices)
1615         save << " " << "__END_SOURCE_VERTICES_LIST__";
1616
1617       std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
1618       bool hasTargetVertices = false;
1619       if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
1620         hasTargetVertices = true;
1621         save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
1622       }
1623       for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
1624         save << " " << (*targetVerticesEntriesIt);
1625       if (hasTargetVertices)
1626         save << " " << "__END_TARGET_VERTICES_LIST__";
1627
1628       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1629     }
1630     save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
1631   }
1632
1633 }
1634
1635 //=============================================================================
1636 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
1637   bool isOK = true;
1638   int i;
1639   double val;
1640   std::string option_or_sm;
1641
1642   isOK = (load >> i);
1643   if (isOK)
1644     _topology = (Topology) i;
1645   else
1646     load.clear(std::ios::badbit | load.rdstate());
1647
1648   isOK = (load >> i);
1649   if (isOK)
1650     _physicalMesh = (PhysicalMesh) i;
1651   else
1652     load.clear(std::ios::badbit | load.rdstate());
1653
1654   isOK = (load >> i);
1655   if (isOK)
1656     _geometricMesh = (GeometricMesh) i;
1657   else
1658     load.clear(std::ios::badbit | load.rdstate());
1659
1660   isOK = (load >> val);
1661   if (isOK)
1662     _phySize = val;
1663   else
1664     load.clear(std::ios::badbit | load.rdstate());
1665
1666   isOK = (load >> val);
1667   if (isOK)
1668     _angleMesh = val;
1669   else
1670     load.clear(std::ios::badbit | load.rdstate());
1671
1672   isOK = (load >> val);
1673   if (isOK)
1674     _gradation = val;
1675   else
1676     load.clear(std::ios::badbit | load.rdstate());
1677
1678   isOK = (load >> i);
1679   if (isOK)
1680     _quadAllowed = (bool) i;
1681   else
1682     load.clear(std::ios::badbit | load.rdstate());
1683
1684   isOK = (load >> i);
1685   if (isOK) {
1686     if ( i != -1) { // if value is -1, then this is no longer a standard option
1687       std::string & value = _option2value["respect_geometry"];
1688       bool _decimesh = (bool) i;
1689       value = _decimesh ? "1" : "0";
1690     }
1691   }
1692   else
1693     load.clear(std::ios::badbit | load.rdstate());
1694
1695   isOK = (load >> val);
1696   if (isOK)
1697     _minSize = val;
1698   else
1699     load.clear(std::ios::badbit | load.rdstate());
1700
1701   isOK = (load >> val);
1702   if (isOK)
1703     _maxSize = val;
1704   else
1705     load.clear(std::ios::badbit | load.rdstate());
1706
1707   isOK = (load >> val);
1708   if (isOK)
1709     // former parameter: get min value
1710     _angleMesh = min(val,_angleMesh);
1711   else
1712     load.clear(std::ios::badbit | load.rdstate());
1713
1714   isOK = (load >> val);
1715   if (isOK)
1716     // former parameter: get min value
1717     _minSize = min(val,_minSize);
1718   else
1719     load.clear(std::ios::badbit | load.rdstate());
1720
1721   isOK = (load >> val);
1722   if (isOK)
1723     // former parameter: get max value
1724     _maxSize = max(val,_maxSize);
1725   else
1726     load.clear(std::ios::badbit | load.rdstate());
1727
1728   isOK = (load >> i);
1729   if (isOK)
1730     _verb = i;
1731   else
1732     load.clear(std::ios::badbit | load.rdstate());
1733
1734   isOK = (load >> i);
1735   if (isOK)
1736     _preCADMergeEdges = (bool) i;
1737   else
1738     load.clear(std::ios::badbit | load.rdstate());
1739
1740   isOK = (load >> i);
1741   if (isOK) {
1742     if ( i != -1) { // if value is -1, then this is no longer a standard option
1743       std::string & value = _preCADoption2value["remove_tiny_edges"];
1744       bool _preCADRemoveNanoEdges = (bool) i;
1745       value = _preCADRemoveNanoEdges ? "1" : "0";
1746     }
1747   }
1748   else
1749     load.clear(std::ios::badbit | load.rdstate());
1750
1751   isOK = (load >> i);
1752   if (isOK)
1753     _preCADDiscardInput = (bool) i;
1754   else
1755     load.clear(std::ios::badbit | load.rdstate());
1756
1757   isOK = (load >> val);
1758   if (isOK) { // _preCADEpsNano
1759     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
1760       std::string & value = _preCADoption2value["tiny_edge_length"];
1761       std::ostringstream oss;
1762       oss << i;
1763       value = oss.str();
1764     }
1765   }
1766   else
1767     load.clear(std::ios::badbit | load.rdstate());
1768
1769   isOK = (load >> i);
1770   if (isOK)
1771     _enforcedInternalVerticesAllFaces = (bool) i;
1772   else
1773     load.clear(std::ios::badbit | load.rdstate());
1774
1775   // New options with MeshGems-CADSurf
1776
1777   bool hasCADSurfOptions = false;
1778   bool hasOptions = false;
1779   bool hasPreCADOptions = false;
1780   bool hasSizeMap = false;
1781   bool hasAttractor = false;
1782   bool hasNewAttractor = false;
1783   bool hasEnforcedVertex = false;
1784   bool hasPreCADFacesPeriodicity = false;
1785   bool hasPreCADEdgesPeriodicity = false;
1786   bool hasFacesPeriodicity = false;
1787   bool hasEdgesPeriodicity = false;
1788   bool hasVerticesPeriodicity = false;
1789
1790   isOK = (load >> option_or_sm);
1791   if (isOK)
1792     if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
1793       i = atoi(option_or_sm.c_str());
1794       hasCADSurfOptions = true;
1795       _phySizeRel = (bool) i;
1796     }
1797     if (option_or_sm == "__OPTIONS_BEGIN__")
1798       hasOptions = true;
1799     else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1800       hasPreCADOptions = true;
1801     else if (option_or_sm == "__SIZEMAP_BEGIN__")
1802       hasSizeMap = true;
1803     else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1804       hasAttractor = true;
1805     else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1806       hasNewAttractor = true;
1807     else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1808       hasEnforcedVertex = true;
1809     else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
1810       hasPreCADFacesPeriodicity = true;
1811     else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
1812       hasPreCADEdgesPeriodicity = true;
1813     else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
1814       hasFacesPeriodicity = true;
1815     else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
1816       hasEdgesPeriodicity = true;
1817     else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
1818       hasVerticesPeriodicity = true;
1819
1820   if (isOK && hasCADSurfOptions) {
1821     isOK = (load >> i);
1822     if (isOK)
1823       _minSizeRel = (bool) i;
1824     else
1825       load.clear(std::ios::badbit | load.rdstate());
1826
1827     isOK = (load >> i);
1828     if (isOK)
1829       _maxSizeRel = (bool) i;
1830     else
1831       load.clear(std::ios::badbit | load.rdstate());
1832
1833     isOK = (load >> val);
1834     if (isOK)
1835       _chordalError = val;
1836     else
1837       load.clear(std::ios::badbit | load.rdstate());
1838
1839     isOK = (load >> i);
1840     if (isOK)
1841       _anisotropic = (bool) i;
1842     else
1843       load.clear(std::ios::badbit | load.rdstate());
1844
1845     isOK = (load >> val);
1846     if (isOK)
1847       _anisotropicRatio = val;
1848     else
1849       load.clear(std::ios::badbit | load.rdstate());
1850
1851     isOK = (load >> i);
1852     if (isOK)
1853       _removeTinyEdges = (bool) i;
1854     else
1855       load.clear(std::ios::badbit | load.rdstate());
1856
1857     isOK = (load >> val);
1858     if (isOK)
1859       _tinyEdgeLength = val;
1860     else
1861       load.clear(std::ios::badbit | load.rdstate());
1862
1863     isOK = (load >> i);
1864     if (isOK)
1865       _badElementRemoval = (bool) i;
1866     else
1867       load.clear(std::ios::badbit | load.rdstate());
1868
1869     isOK = (load >> val);
1870     if (isOK)
1871       _badElementAspectRatio = val;
1872     else
1873       load.clear(std::ios::badbit | load.rdstate());
1874
1875     isOK = (load >> i);
1876     if (isOK)
1877       _optimizeMesh = (bool) i;
1878     else
1879       load.clear(std::ios::badbit | load.rdstate());
1880
1881     isOK = (load >> i);
1882     if (isOK)
1883       _quadraticMesh = (bool) i;
1884     else
1885       load.clear(std::ios::badbit | load.rdstate());
1886
1887     isOK = (load >> i);
1888     if (isOK)
1889       _preCADProcess3DTopology = (bool) i;
1890     else
1891       load.clear(std::ios::badbit | load.rdstate());
1892
1893   }
1894   
1895
1896   if (hasCADSurfOptions) {
1897     isOK = (load >> option_or_sm);
1898     if (isOK)
1899       if (option_or_sm == "__OPTIONS_BEGIN__")
1900         hasOptions = true;
1901       else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1902         hasPreCADOptions = true;
1903       else if (option_or_sm == "__SIZEMAP_BEGIN__")
1904         hasSizeMap = true;
1905       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1906         hasAttractor = true;
1907       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1908         hasNewAttractor = true;
1909       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1910         hasEnforcedVertex = true;
1911       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
1912         hasPreCADFacesPeriodicity = true;
1913       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
1914         hasPreCADEdgesPeriodicity = true;
1915       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
1916         hasFacesPeriodicity = true;
1917       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
1918         hasEdgesPeriodicity = true;
1919       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
1920         hasVerticesPeriodicity = true;
1921   }
1922   
1923   std::string optName, optValue;
1924   while (isOK && hasOptions) {
1925     isOK = (load >> optName);
1926     if (isOK) {
1927       if (optName == "__OPTIONS_END__")
1928         break;
1929       isOK = (load >> optValue);
1930     }
1931     if (isOK) {
1932       std::string & value = _option2value[optName];
1933       value = optValue;
1934       int len = value.size();
1935       // continue reading until "%#" encountered
1936       while (value[len - 1] != '#' || value[len - 2] != '%') {
1937         isOK = (load >> optValue);
1938         if (isOK) {
1939           value += " ";
1940           value += optValue;
1941           len = value.size();
1942         } else {
1943           break;
1944         }
1945       }
1946       value[len - 2] = '\0'; //cut off "%#"
1947     }
1948   }
1949
1950   if (hasOptions) {
1951     isOK = (load >> option_or_sm);
1952     if (isOK)
1953       if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1954         hasPreCADOptions = true;
1955       else if (option_or_sm == "__SIZEMAP_BEGIN__")
1956         hasSizeMap = true;
1957       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1958         hasAttractor = true;
1959       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1960         hasNewAttractor = true;
1961       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1962         hasEnforcedVertex = true;
1963       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
1964         hasPreCADFacesPeriodicity = true;
1965       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
1966         hasPreCADEdgesPeriodicity = true;
1967       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
1968         hasFacesPeriodicity = true;
1969       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
1970         hasEdgesPeriodicity = true;
1971       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
1972         hasVerticesPeriodicity = true;
1973   }
1974
1975   while (isOK && hasPreCADOptions) {
1976     isOK = (load >> optName);
1977     if (isOK) {
1978       if (optName == "__PRECAD_OPTIONS_END__")
1979         break;
1980       isOK = (load >> optValue);
1981     }
1982     if (isOK) {
1983       std::string & value = _preCADoption2value[optName];
1984       value = optValue;
1985       int len = value.size();
1986       // continue reading until "%#" encountered
1987       while (value[len - 1] != '#' || value[len - 2] != '%') {
1988         isOK = (load >> optValue);
1989         if (isOK) {
1990           value += " ";
1991           value += optValue;
1992           len = value.size();
1993         } else {
1994           break;
1995         }
1996       }
1997       value[len - 2] = '\0'; //cut off "%#"
1998     }
1999   }
2000
2001   if (hasPreCADOptions) {
2002     isOK = (load >> option_or_sm);
2003     if (isOK)
2004       if (option_or_sm == "__SIZEMAP_BEGIN__")
2005         hasSizeMap = true;
2006       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2007         hasAttractor = true;
2008       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2009         hasNewAttractor = true;
2010       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2011         hasEnforcedVertex = true;
2012       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2013         hasPreCADFacesPeriodicity = true;
2014       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2015         hasPreCADEdgesPeriodicity = true;
2016       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2017         hasFacesPeriodicity = true;
2018       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2019         hasEdgesPeriodicity = true;
2020       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2021         hasVerticesPeriodicity = true;
2022   }
2023   
2024   std::string smEntry, smValue;
2025   while (isOK && hasSizeMap) {
2026     isOK = (load >> smEntry);
2027     if (isOK) {
2028       if (smEntry == "__SIZEMAP_END__")
2029         break;
2030       isOK = (load >> smValue);
2031     }
2032     if (isOK) {
2033       std::string & value2 = _sizeMap[smEntry];
2034       value2 = smValue;
2035       int len2 = value2.size();
2036       // continue reading until "%#" encountered
2037       while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2038         isOK = (load >> smValue);
2039         if (isOK) {
2040           value2 += " ";
2041           value2 += smValue;
2042           len2 = value2.size();
2043         } else {
2044           break;
2045         }
2046       }
2047       value2[len2 - 2] = '\0'; //cut off "%#"
2048     }
2049   }
2050
2051   if (hasSizeMap) {
2052     isOK = (load >> option_or_sm);
2053     if (isOK)
2054       if (option_or_sm == "__ATTRACTORS_BEGIN__")
2055         hasAttractor = true;
2056       if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2057         hasNewAttractor = true;
2058       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2059         hasEnforcedVertex = true;
2060       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2061         hasPreCADFacesPeriodicity = true;
2062       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2063         hasPreCADEdgesPeriodicity = true;
2064       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2065         hasFacesPeriodicity = true;
2066       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2067         hasEdgesPeriodicity = true;
2068       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2069         hasVerticesPeriodicity = true;
2070   }
2071
2072   std::string atEntry, atValue;
2073   while (isOK && hasAttractor) {
2074     isOK = (load >> atEntry);
2075     if (isOK) {
2076       if (atEntry == "__ATTRACTORS_END__")
2077         break;
2078       isOK = (load >> atValue);
2079     }
2080     if (isOK) {
2081       std::string & value3 = _attractors[atEntry];
2082       value3 = atValue;
2083       int len3 = value3.size();
2084       // continue reading until "%#" encountered
2085       while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2086         isOK = (load >> atValue);
2087         if (isOK) {
2088           value3 += " ";
2089           value3 += atValue;
2090           len3 = value3.size();
2091         } else {
2092           break;
2093         }
2094       }
2095       value3[len3 - 2] = '\0'; //cut off "%#"
2096     }
2097   }
2098
2099   if (hasAttractor) {
2100     isOK = (load >> option_or_sm);
2101     if (isOK)
2102       if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2103         hasNewAttractor = true;
2104       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2105         hasEnforcedVertex = true;
2106       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2107         hasPreCADFacesPeriodicity = true;
2108       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2109         hasPreCADEdgesPeriodicity = true;
2110       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2111         hasFacesPeriodicity = true;
2112       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2113         hasEdgesPeriodicity = true;
2114       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2115         hasVerticesPeriodicity = true;
2116   }
2117
2118   std::string newAtFaceEntry, atTestString;
2119   std::string newAtShapeEntry;
2120   double attParams[4];
2121   double step;
2122   while (isOK && hasNewAttractor) {
2123     //std::cout<<"Load new attractor"<<std::endl;
2124     isOK = (load >> newAtFaceEntry);
2125     if (isOK) {
2126       if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2127         break;
2128       isOK = (load >> newAtShapeEntry);
2129       if (!isOK)
2130     break;
2131       isOK = (load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2132     }
2133     if (isOK) {
2134       MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
2135       const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2136       const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2137       BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2138       attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2139       //attractor->BuildMap();                     
2140       _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2141     }
2142   }
2143   
2144   
2145   if (hasNewAttractor) {
2146     isOK = (load >> option_or_sm);
2147     if (isOK)
2148       if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2149         hasEnforcedVertex = true;
2150       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2151         hasPreCADFacesPeriodicity = true;
2152       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2153         hasPreCADEdgesPeriodicity = true;
2154       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2155         hasFacesPeriodicity = true;
2156       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2157         hasEdgesPeriodicity = true;
2158       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2159         hasVerticesPeriodicity = true;
2160   }
2161
2162
2163 // 
2164 // Here is a example of the saved stream:
2165 // __ENFORCED_VERTICES_BEGIN__ 
2166 // __BEGIN_VERTEX__  => no name, no entry
2167 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2168 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__ 
2169 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__ 
2170 // __END_VERTEX__ 
2171 // __BEGIN_VERTEX__ => no coords
2172 // __BEGIN_NAME__ mes points __END_NAME__ 
2173 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2174 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2175 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2176 // __END_VERTEX__ 
2177 // __ENFORCED_VERTICES_END__
2178 // 
2179
2180   std::string enfSeparator;
2181   std::string enfName;
2182   std::string enfGeomEntry;
2183   std::string enfGroup;
2184   TEntryList enfFaceEntryList;
2185   double enfCoords[3];
2186   bool hasCoords = false;
2187   
2188   _faceEntryEnfVertexListMap.clear();
2189   _enfVertexList.clear();
2190   _faceEntryCoordsListMap.clear();
2191   _coordsEnfVertexMap.clear();
2192   _faceEntryEnfVertexEntryListMap.clear();
2193   _enfVertexEntryEnfVertexMap.clear();
2194   
2195   
2196   while (isOK && hasEnforcedVertex) {
2197     isOK = (load >> enfSeparator); // __BEGIN_VERTEX__
2198     TEnfVertex *enfVertex = new TEnfVertex();
2199 //     MESSAGE("enfSeparator: " <<enfSeparator);
2200     if (enfSeparator == "__ENFORCED_VERTICES_END__")
2201       break; // __ENFORCED_VERTICES_END__
2202     if (enfSeparator != "__BEGIN_VERTEX__")
2203       throw std::exception();
2204     
2205     while (isOK) {
2206       isOK = (load >> enfSeparator);
2207       MESSAGE("enfSeparator: " <<enfSeparator);
2208       if (enfSeparator == "__END_VERTEX__") {
2209         
2210         enfVertex->name = enfName;
2211         enfVertex->geomEntry = enfGeomEntry;
2212         enfVertex->grpName = enfGroup;
2213         enfVertex->coords.clear();
2214         if (hasCoords)
2215           enfVertex->coords.assign(enfCoords,enfCoords+3);
2216         enfVertex->faceEntries = enfFaceEntryList;
2217         
2218         _enfVertexList.insert(enfVertex);
2219         
2220         if (enfVertex->coords.size()) {
2221           _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2222           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2223             _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2224             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2225           }
2226         }
2227         if (!enfVertex->geomEntry.empty()) {
2228           _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2229           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2230             _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2231             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2232           }
2233         }
2234         
2235         enfName.clear();
2236         enfGeomEntry.clear();
2237         enfGroup.clear();
2238         enfFaceEntryList.clear();
2239         hasCoords = false;
2240         break; // __END_VERTEX__
2241       }
2242         
2243       if (enfSeparator == "__BEGIN_NAME__") {  // __BEGIN_NAME__
2244         while (isOK && (enfSeparator != "__END_NAME__")) {
2245           isOK = (load >> enfSeparator);
2246           if (enfSeparator != "__END_NAME__") {
2247             if (!enfName.empty())
2248               enfName += " ";
2249             enfName += enfSeparator;
2250           }
2251         }
2252         MESSAGE("enfName: " <<enfName);
2253       }
2254         
2255       if (enfSeparator == "__BEGIN_ENTRY__") {  // __BEGIN_ENTRY__
2256         isOK = (load >> enfGeomEntry);
2257         isOK = (load >> enfSeparator); // __END_ENTRY__
2258         if (enfSeparator != "__END_ENTRY__")
2259           throw std::exception();
2260         MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2261       }
2262         
2263       if (enfSeparator == "__BEGIN_GROUP__") {  // __BEGIN_GROUP__
2264         while (isOK && (enfSeparator != "__END_GROUP__")) {
2265           isOK = (load >> enfSeparator);
2266           if (enfSeparator != "__END_GROUP__") {
2267             if (!enfGroup.empty())
2268               enfGroup += " ";
2269             enfGroup += enfSeparator;
2270           }
2271         }
2272         MESSAGE("enfGroup: " <<enfGroup);
2273       }
2274         
2275       if (enfSeparator == "__BEGIN_COORDS__") {  // __BEGIN_COORDS__
2276         hasCoords = true;
2277         isOK = (load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2278         isOK = (load >> enfSeparator); // __END_COORDS__
2279         if (enfSeparator != "__END_COORDS__")
2280           throw std::exception();
2281         MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2282       } 
2283         
2284       if (enfSeparator == "__BEGIN_FACELIST__") {  // __BEGIN_FACELIST__
2285         while (isOK && (enfSeparator != "__END_FACELIST__")) {
2286           isOK = (load >> enfSeparator);
2287           if (enfSeparator != "__END_FACELIST__") {
2288             enfFaceEntryList.insert(enfSeparator);
2289             MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2290           }
2291         }
2292       } 
2293     }
2294   }
2295
2296   // PERIODICITY
2297
2298   if (hasPreCADFacesPeriodicity){
2299     LoadPreCADPeriodicity(load, "FACES");
2300
2301     isOK = (load >> option_or_sm);
2302     if (isOK)
2303       if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2304         hasPreCADEdgesPeriodicity = true;
2305       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2306         hasFacesPeriodicity = true;
2307       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2308         hasEdgesPeriodicity = true;
2309       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2310         hasVerticesPeriodicity = true;
2311   }
2312
2313   if (hasPreCADEdgesPeriodicity){
2314     LoadPreCADPeriodicity(load, "EDGES");
2315
2316     isOK = (load >> option_or_sm);
2317     if (isOK)
2318       if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2319         hasFacesPeriodicity = true;
2320       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2321         hasEdgesPeriodicity = true;
2322       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2323         hasVerticesPeriodicity = true;
2324   }
2325
2326   if (hasFacesPeriodicity){
2327       LoadFacesPeriodicity(load);
2328
2329     isOK = (load >> option_or_sm);
2330     if (isOK)
2331       if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2332         hasEdgesPeriodicity = true;
2333       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2334         hasVerticesPeriodicity = true;
2335   }
2336
2337   if (hasEdgesPeriodicity){
2338       LoadEdgesPeriodicity(load);
2339
2340     isOK = (load >> option_or_sm);
2341     if (isOK)
2342       if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2343         hasVerticesPeriodicity = true;
2344   }
2345
2346   if (hasVerticesPeriodicity)
2347       LoadVerticesPeriodicity(load);
2348
2349   return load;
2350 }
2351
2352 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2353
2354   bool isOK = true;
2355
2356   std::string periodicitySeparator;
2357   TEntry shape1Entry;
2358   TEntry shape2Entry;
2359
2360   _facesPeriodicityVector.clear();
2361
2362   while (isOK) {
2363     isOK = (load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2364     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2365     TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2366     if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2367       break; // __FACES_PERIODICITY_END__
2368     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2369       MESSAGE("//" << periodicitySeparator << "//");
2370       throw std::exception();
2371     }
2372
2373     while (isOK) {
2374       isOK = (load >> periodicitySeparator);
2375       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2376       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2377
2378         periodicity_i->first = shape1Entry;
2379         periodicity_i->second = shape2Entry;
2380
2381         _facesPeriodicityVector.push_back(*periodicity_i);
2382
2383         break; // __END_PERIODICITY_DESCRIPTION__
2384       }
2385
2386       if (periodicitySeparator == "__BEGIN_ENTRY1__") {  // __BEGIN_ENTRY1__
2387         isOK = (load >> shape1Entry);
2388         isOK = (load >> periodicitySeparator); // __END_ENTRY1__
2389         if (periodicitySeparator != "__END_ENTRY1__")
2390           throw std::exception();
2391         MESSAGE("shape1Entry: " <<shape1Entry);
2392       }
2393
2394       if (periodicitySeparator == "__BEGIN_ENTRY2__") {  // __BEGIN_ENTRY2__
2395         isOK = (load >> shape2Entry);
2396         isOK = (load >> periodicitySeparator); // __END_ENTRY2__
2397         if (periodicitySeparator != "__END_ENTRY2__")
2398           throw std::exception();
2399         MESSAGE("shape2Entry: " <<shape2Entry);
2400       }
2401     }
2402   }
2403 }
2404
2405
2406 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
2407
2408   bool isOK = true;
2409
2410   std::string periodicitySeparator;
2411   TEntry theFace1Entry;
2412   TEntry theEdge1Entry;
2413   TEntry theFace2Entry;
2414   TEntry theEdge2Entry;
2415   int edge_orientation = 0;
2416
2417   _edgesPeriodicityVector.clear();
2418
2419   while (isOK) {
2420     isOK = (load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2421     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2422     TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
2423     if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
2424       break; // __EDGES_PERIODICITY_END__
2425     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2426       MESSAGE("//" << periodicitySeparator << "//");
2427       throw std::exception();
2428     }
2429
2430     while (isOK) {
2431       isOK = (load >> periodicitySeparator);
2432       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2433       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2434
2435         periodicity_i->theFace1Entry = theFace1Entry;
2436         periodicity_i->theEdge1Entry = theEdge1Entry;
2437         periodicity_i->theFace2Entry = theFace2Entry;
2438         periodicity_i->theEdge2Entry = theEdge2Entry;
2439         periodicity_i->edge_orientation = edge_orientation;
2440
2441         _edgesPeriodicityVector.push_back(*periodicity_i);
2442
2443         break; // __END_PERIODICITY_DESCRIPTION__
2444       }
2445
2446       if (periodicitySeparator == "__BEGIN_FACE1__") {  // __BEGIN_FACE1__
2447         isOK = (load >> theFace1Entry);
2448         MESSAGE("//" << theFace1Entry << "//");
2449         isOK = (load >> periodicitySeparator); // __END_FACE1__
2450         if (periodicitySeparator != "__END_FACE1__"){
2451           MESSAGE("//" << periodicitySeparator << "//");
2452           throw std::exception();
2453         }
2454         MESSAGE("theFace1Entry: " <<theFace1Entry);
2455       }
2456
2457       if (periodicitySeparator == "__BEGIN_EDGE1__") {  // __BEGIN_EDGE1__
2458         isOK = (load >> theEdge1Entry);
2459         isOK = (load >> periodicitySeparator); // __END_EDGE1__
2460         if (periodicitySeparator != "__END_EDGE1__")
2461           throw std::exception();
2462         MESSAGE("theEdge1Entry: " <<theEdge1Entry);
2463       }
2464
2465       if (periodicitySeparator == "__BEGIN_FACE2__") {  // __BEGIN_FACE2__
2466         isOK = (load >> theFace2Entry);
2467         isOK = (load >> periodicitySeparator); // __END_FACE2__
2468         if (periodicitySeparator != "__END_FACE2__")
2469           throw std::exception();
2470         MESSAGE("theFace2Entry: " <<theFace2Entry);
2471       }
2472
2473       if (periodicitySeparator == "__BEGIN_EDGE2__") {  // __BEGIN_EDGE2__
2474         isOK = (load >> theEdge2Entry);
2475         isOK = (load >> periodicitySeparator); // __END_EDGE2__
2476         if (periodicitySeparator != "__END_EDGE2__")
2477           throw std::exception();
2478         MESSAGE("theEdge2Entry: " <<theEdge2Entry);
2479       }
2480
2481       if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") {  // __BEGIN_EDGE_ORIENTATION__
2482         isOK = (load >> edge_orientation);
2483         isOK = (load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
2484         if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
2485           throw std::exception();
2486         MESSAGE("edge_orientation: " <<edge_orientation);
2487       }
2488     }
2489   }
2490 }
2491
2492 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
2493
2494   bool isOK = true;
2495
2496   std::string periodicitySeparator;
2497   TEntry theEdge1Entry;
2498   TEntry theVertex1Entry;
2499   TEntry theEdge2Entry;
2500   TEntry theVertex2Entry;
2501
2502   _verticesPeriodicityVector.clear();
2503
2504   while (isOK) {
2505     isOK = (load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2506     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2507     TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
2508     if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
2509       break; // __VERTICES_PERIODICITY_END__
2510     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2511       MESSAGE("//" << periodicitySeparator << "//");
2512       throw std::exception();
2513     }
2514
2515     while (isOK) {
2516       isOK = (load >> periodicitySeparator);
2517       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2518       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2519
2520         periodicity_i->theEdge1Entry = theEdge1Entry;
2521         periodicity_i->theVertex1Entry = theVertex1Entry;
2522         periodicity_i->theEdge2Entry = theEdge2Entry;
2523         periodicity_i->theVertex2Entry = theVertex2Entry;
2524
2525         _verticesPeriodicityVector.push_back(*periodicity_i);
2526
2527         break; // __END_PERIODICITY_DESCRIPTION__
2528       }
2529
2530       if (periodicitySeparator == "__BEGIN_EDGE1__") {  // __BEGIN_EDGE1__
2531         isOK = (load >> theEdge1Entry);
2532         isOK = (load >> periodicitySeparator); // __END_EDGE1__
2533         if (periodicitySeparator != "__END_EDGE1__")
2534           throw std::exception();
2535         MESSAGE("theEdge1Entry: " <<theEdge1Entry);
2536       }
2537
2538       if (periodicitySeparator == "__BEGIN_VERTEX1__") {  // __BEGIN_VERTEX1__
2539         isOK = (load >> theVertex1Entry);
2540         isOK = (load >> periodicitySeparator); // __END_VERTEX1__
2541         if (periodicitySeparator != "__END_VERTEX1__")
2542           throw std::exception();
2543         MESSAGE("theVertex1Entry: " <<theVertex1Entry);
2544       }
2545
2546       if (periodicitySeparator == "__BEGIN_EDGE2__") {  // __BEGIN_EDGE2__
2547         isOK = (load >> theEdge2Entry);
2548         isOK = (load >> periodicitySeparator); // __END_EDGE2__
2549         if (periodicitySeparator != "__END_EDGE2__")
2550           throw std::exception();
2551         MESSAGE("theEdge2Entry: " <<theEdge2Entry);
2552       }
2553
2554       if (periodicitySeparator == "__BEGIN_VERTEX2__") {  // __BEGIN_VERTEX2__
2555         isOK = (load >> theVertex2Entry);
2556         isOK = (load >> periodicitySeparator); // __END_VERTEX2__
2557         if (periodicitySeparator != "__END_VERTEX2__")
2558           throw std::exception();
2559         MESSAGE("theVertex2Entry: " <<theVertex2Entry);
2560       }
2561     }
2562   }
2563 }
2564
2565 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
2566
2567   bool isOK = true;
2568
2569   std::string periodicitySeparator;
2570   TEntry shape1Entry;
2571   TEntry shape2Entry;
2572   std::vector<std::string> theSourceVerticesEntries;
2573   std::vector<std::string> theTargetVerticesEntries;
2574
2575   bool hasSourceVertices = false;
2576   bool hasTargetVertices = false;
2577
2578   if (shapeType == "FACES")
2579     _preCadFacesPeriodicityVector.clear();
2580   else
2581     _preCadEdgesPeriodicityVector.clear();
2582
2583
2584   while (isOK) {
2585     isOK = (load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2586     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2587     TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
2588 //     MESSAGE("periodicitySeparator: " <<periodicitySeparator);
2589     std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
2590     if (periodicitySeparator == endSeparator)
2591       break; // __PRECAD_FACES_PERIODICITY_END__
2592     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2593       MESSAGE("//" << endSeparator << "//");
2594       MESSAGE("//" << periodicitySeparator << "//");
2595       throw std::exception();
2596     }
2597
2598     while (isOK) {
2599       isOK = (load >> periodicitySeparator);
2600       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2601       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2602
2603         periodicity_i->shape1Entry = shape1Entry;
2604         periodicity_i->shape2Entry = shape2Entry;
2605
2606         MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
2607         MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
2608
2609         if (hasSourceVertices)
2610           periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
2611         if (hasTargetVertices)
2612           periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
2613
2614         if (shapeType == "FACES")
2615           _preCadFacesPeriodicityVector.push_back(*periodicity_i);
2616         else
2617           _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
2618
2619         theSourceVerticesEntries.clear();
2620         theTargetVerticesEntries.clear();
2621         hasSourceVertices = false;
2622         hasTargetVertices = false;
2623         break; // __END_PERIODICITY_DESCRIPTION__
2624       }
2625
2626       if (periodicitySeparator == "__BEGIN_ENTRY1__") {  // __BEGIN_ENTRY1__
2627         isOK = (load >> shape1Entry);
2628         isOK = (load >> periodicitySeparator); // __END_ENTRY1__
2629         if (periodicitySeparator != "__END_ENTRY1__")
2630           throw std::exception();
2631         MESSAGE("shape1Entry: " <<shape1Entry);
2632       }
2633
2634       if (periodicitySeparator == "__BEGIN_ENTRY2__") {  // __BEGIN_ENTRY2__
2635         isOK = (load >> shape2Entry);
2636         isOK = (load >> periodicitySeparator); // __END_ENTRY2__
2637         if (periodicitySeparator != "__END_ENTRY2__")
2638           throw std::exception();
2639         MESSAGE("shape2Entry: " <<shape2Entry);
2640       }
2641
2642       if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") {  // __BEGIN_SOURCE_VERTICES_LIST__
2643         hasSourceVertices = true;
2644         while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
2645           isOK = (load >> periodicitySeparator);
2646           if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
2647             theSourceVerticesEntries.push_back(periodicitySeparator);
2648             MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
2649           }
2650         }
2651       }
2652
2653       if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") {  // __BEGIN_TARGET_VERTICES_LIST__
2654         hasTargetVertices = true;
2655         while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
2656           isOK = (load >> periodicitySeparator);
2657           if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
2658             theTargetVerticesEntries.push_back(periodicitySeparator);
2659             MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
2660           }
2661         }
2662       }
2663     }
2664   }
2665 }
2666
2667 //=============================================================================
2668 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
2669   return hyp.SaveTo(save);
2670 }
2671
2672 //=============================================================================
2673 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
2674   return hyp.LoadFrom(load);
2675 }
2676
2677 //================================================================================
2678 /*!
2679  * \brief Does nothing
2680  */
2681 //================================================================================
2682
2683 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
2684   return false;
2685 }
2686
2687 //================================================================================
2688 /*!
2689  * \brief Returns default global constant physical size given a default value of element length ratio
2690  */
2691 //================================================================================
2692
2693 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
2694   if (bbSegmentation != 0 && diagonal != 0)
2695     return diagonal / bbSegmentation ;
2696   return 10;
2697 }
2698
2699 //================================================================================
2700 /*!
2701  * \brief Returns default min size given a default value of element length ratio
2702  */
2703 //================================================================================
2704
2705 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
2706   if (diagonal != 0)
2707     return diagonal / 1000.0 ;
2708   return undefinedDouble();
2709 }
2710
2711 //================================================================================
2712 /*!
2713  * \brief Returns default max size given a default value of element length ratio
2714  */
2715 //================================================================================
2716
2717 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
2718   if (diagonal != 0)
2719     return diagonal / 5.0 ;
2720   return undefinedDouble();
2721 }
2722
2723 //================================================================================
2724 /*!
2725  * \brief Returns default chordal error given a default value of element length ratio
2726  */
2727 //================================================================================
2728
2729 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
2730   if (diagonal != 0)
2731     return diagonal;
2732   return undefinedDouble();
2733 }
2734
2735 //================================================================================
2736 /*!
2737  * \brief Returns default tiny edge length given a default value of element length ratio
2738  */
2739 //================================================================================
2740
2741 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
2742   if (diagonal != 0)
2743     return diagonal * 1e-6 ;
2744   return undefinedDouble();
2745 }
2746
2747 //=============================================================================
2748 /*!
2749  * \brief Initialize my parameter values by default parameters.
2750  *  \retval bool - true if parameter values have been successfully defined
2751  */
2752 //=============================================================================
2753
2754 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
2755   double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
2756   _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
2757   _minSize = GetDefaultMinSize(diagonal);
2758   _maxSize = GetDefaultMaxSize(diagonal);
2759   _chordalError = GetDefaultChordalError(diagonal);
2760   _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
2761
2762   return true;
2763 //   return bool(_phySize = dflts._elemLength);
2764 }