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