Salome HOME
61ffc49fbfa4d997bd7bf7d830f3af15353c8d00
[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 = GetHypType();
86   _param_algo_dim = 2;
87   
88 //   _GMFFileMode = false; // GMF ascii mode
89
90   const char* boolOptionNames[] = {         "correct_surface_intersections",            // default = 1
91                                             "create_tag_on_collision",                  // default = 1
92                                             "debug",                                    // default = 0
93                                             "enforce_cad_edge_sizes",                   // default = 0
94                                             "frontal",                                  // ok default = 1
95                                             "jacobian_rectification_respect_geometry",  // default = 1
96                                             "proximity",                                // default = 0
97                                             "rectify_jacobian",                         // default = 1
98                                             "respect_geometry",                         // default = 1
99                                             "" // mark of end
100       };
101
102   const char* intOptionNames[] = {          "hinterpol_flag",                           // ok default = 0
103                                             "hmean_flag",                               // ok default = 0
104                                             "max_number_of_points_per_patch",           // default = 100000
105                                             "prox_nb_layer",                            // detects the volumic proximity of surfaces
106                                             "" // mark of end
107       };
108   const char* doubleOptionNames[] = {       "surface_intersections_processing_max_cost",// default = 15
109                                             "periodic_tolerance",                       // default = diag/100
110                                             "prox_ratio",
111                                             "" // 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   TAttractorMap::iterator attIt = _classAttractors.find(entry);
623   for ( ; attIt != _classAttractors.end(); ++attIt )
624     if ( attIt->first == entry && 
625          attIt->second->GetAttractorEntry() == attEntry )
626       break;
627   bool attExists = (attIt != _classAttractors.end());
628
629   BLSURFPlugin_Attractor* myAttractor;
630   if ( !attExists ) {
631     myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
632     _classAttractors.insert( make_pair( entry, myAttractor ));
633   }
634   else {
635     myAttractor = attIt->second;
636   }
637   // if (!myAttractor->IsMapBuilt())
638   //   myAttractor->BuildMap();
639   myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
640
641   NotifySubMeshesHypothesisModification();
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                                          const char * attEntry/*=0*/)
686 {
687  TSizeMap::iterator it  = _sizeMap.find( entry );
688  
689  if ( it != _sizeMap.end() ) {
690    _sizeMap.erase(it);
691    NotifySubMeshesHypothesisModification();
692  }
693  else {
694    TSizeMap::iterator itAt  = _attractors.find( entry );
695    if ( itAt != _attractors.end() ) {
696      _attractors.erase(itAt);
697      NotifySubMeshesHypothesisModification();
698    }
699    else {
700      TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
701      if ( it_clAt != _classAttractors.end() ) {
702        do {
703          if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
704            _classAttractors.erase( it_clAt++ );
705          else
706            ++it_clAt;
707        }
708        while ( it_clAt != _classAttractors.end() );
709        MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
710        NotifySubMeshesHypothesisModification();
711      }
712      else
713        std::cout<<"No_Such_Entry"<<std::endl;
714    }
715  }
716 }
717
718 //=======================================================================
719 //function : ClearSizeMaps
720 //=======================================================================
721 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
722   _sizeMap.clear();
723   _attractors.clear();
724   _classAttractors.clear();
725 }
726
727 // Enable internal enforced vertices on specific face if requested by user
728
729 ////=======================================================================
730 ////function : SetInternalEnforcedVertex
731 ////=======================================================================
732 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
733 //                                                        bool toEnforceInternalVertices,
734 //                                                        TEnfGroupName theGroupName) {
735
736 //  MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
737 //      << toEnforceInternalVertices << ", " << theGroupName << ")");
738   
739 //  TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
740 //  if (it != _faceEntryInternalVerticesList.end()) {
741 //    if (!toEnforceInternalVertices) {
742 //      _faceEntryInternalVerticesList.erase(it);
743 //    }
744 //  }
745 //  else {
746 //    if (toEnforceInternalVertices) {
747 //      _faceEntryInternalVerticesList.insert(theFaceEntry);
748 //    }
749 //  }
750   
751 //  // TODO
752 //  // Take care of groups
753 //}
754
755
756 //=======================================================================
757 //function : SetEnforcedVertex
758 //=======================================================================
759 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
760                                                 TEnfGroupName theGroupName, double x, double y, double z) {
761
762   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
763       << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
764
765   SetPhysicalMesh(PhysicalLocalSize);
766
767   //  TEnfVertexList::iterator it;
768   bool toNotify = false;
769   bool toCreate = true;
770
771   TEnfVertex *oldEnVertex;
772   TEnfVertex *newEnfVertex = new TEnfVertex();
773   newEnfVertex->name = theVertexName;
774   newEnfVertex->geomEntry = theVertexEntry;
775   newEnfVertex->coords.clear();
776   if (theVertexEntry == "") {
777     newEnfVertex->coords.push_back(x);
778     newEnfVertex->coords.push_back(y);
779     newEnfVertex->coords.push_back(z);
780   }
781   newEnfVertex->grpName = theGroupName;
782   newEnfVertex->faceEntries.clear();
783   newEnfVertex->faceEntries.insert(theFaceEntry);
784   
785   
786   // update _enfVertexList
787   TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
788   if (it != _enfVertexList.end()) {
789     toCreate = false;
790     oldEnVertex = (*it);
791     MESSAGE("Enforced Vertex was found => Update");
792     if (oldEnVertex->name != theVertexName) {
793       MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
794       oldEnVertex->name = theVertexName;
795       toNotify = true;
796     }
797     if (oldEnVertex->grpName != theGroupName) {
798       MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
799       oldEnVertex->grpName = theGroupName;
800       toNotify = true;
801     }
802     TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
803     if (it_faceEntries == oldEnVertex->faceEntries.end()) {
804       MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
805       oldEnVertex->faceEntries.insert(theFaceEntry);
806       _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
807       toNotify = true;
808     }
809     if (toNotify) {
810       // update map coords / enf vertex if needed
811       if (oldEnVertex->coords.size()) {
812         _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
813         _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
814       }
815
816       // update map geom entry / enf vertex if needed
817       if (oldEnVertex->geomEntry != "") {
818         _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
819         _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
820       }
821     }
822   }
823
824 //   //////// CREATE ////////////
825   if (toCreate) {
826     toNotify = true;
827     MESSAGE("Creating new enforced vertex");
828     _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
829     _enfVertexList.insert(newEnfVertex);
830     if (theVertexEntry == "") {
831       _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
832       _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
833     }
834     else {
835       _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
836       _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
837     }
838   }
839
840   if (toNotify)
841     NotifySubMeshesHypothesisModification();
842
843   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
844   return toNotify;
845 }
846
847
848 //=======================================================================
849 //function : GetEnforcedVertices
850 //=======================================================================
851
852 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
853     throw (std::invalid_argument) {
854
855   if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
856     return _faceEntryEnfVertexListMap[theFaceEntry];
857   else
858     return GetDefaultEnfVertexList();
859
860   std::ostringstream msg;
861   msg << "No enforced vertex for face entry " << theFaceEntry;
862   throw std::invalid_argument(msg.str());
863 }
864
865 //=======================================================================
866 //function : GetEnfVertexCoordsList
867 //=======================================================================
868
869 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
870     const TEntry& theFaceEntry) throw (std::invalid_argument) {
871
872   if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
873     return _faceEntryCoordsListMap[theFaceEntry];
874
875   std::ostringstream msg;
876   msg << "No enforced vertex coords for face entry " << theFaceEntry;
877   throw std::invalid_argument(msg.str());
878 }
879
880 //=======================================================================
881 //function : GetEnfVertexEntryList
882 //=======================================================================
883
884 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
885     throw (std::invalid_argument) {
886
887   if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
888     return _faceEntryEnfVertexEntryListMap[theFaceEntry];
889
890   std::ostringstream msg;
891   msg << "No enforced vertex entry for face entry " << theFaceEntry;
892   throw std::invalid_argument(msg.str());
893 }
894
895 //=======================================================================
896 //function : GetEnfVertex(TEnfVertexCoords coords)
897 //=======================================================================
898
899 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
900     throw (std::invalid_argument) {
901
902   if (_coordsEnfVertexMap.count(coords) > 0)
903     return _coordsEnfVertexMap[coords];
904
905   std::ostringstream msg;
906   msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
907   throw std::invalid_argument(msg.str());
908 }
909
910 //=======================================================================
911 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
912 //=======================================================================
913
914 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
915     throw (std::invalid_argument) {
916
917   if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
918     return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
919
920   std::ostringstream msg;
921   msg << "No enforced vertex with entry " << theEnfVertexEntry;
922   throw std::invalid_argument(msg.str());
923 }
924
925 //Enable internal enforced vertices on specific face if requested by user
926 ////=======================================================================
927 ////function : GetInternalEnforcedVertex
928 ////=======================================================================
929
930 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
931 //{
932 //  if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
933 //    return true;
934 //  return false;
935 //}
936
937 //=======================================================================
938 //function : ClearEnforcedVertex
939 //=======================================================================
940
941 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
942     const TEntry& theVertexEntry) throw (std::invalid_argument) {
943
944   bool toNotify = false;
945   std::ostringstream msg;
946   TEnfVertex *oldEnfVertex;
947   TEnfVertexCoords coords;
948   coords.clear();
949   coords.push_back(x);
950   coords.push_back(y);
951   coords.push_back(z);
952
953   // check that enf vertex with given enf vertex entry exists
954   TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
955   if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
956     // Success
957     MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
958     oldEnfVertex = it_enfVertexEntry->second;
959
960     _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
961
962     TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
963     enfVertexEntryList.erase(theVertexEntry);
964     if (enfVertexEntryList.size() == 0)
965       _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
966     //    TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
967     //    TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
968     //    it_entry_entry->second.erase(it_entryList);
969     //    if (it_entry_entry->second.size() == 0)
970     //      _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
971   } else {
972     // Fail
973     MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
974     msg << "No enforced vertex with geom entry " << theVertexEntry;
975     // check that enf vertex with given coords exists
976     TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
977     if (it_coords_enf != _coordsEnfVertexMap.end()) {
978       // Success
979       MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
980       oldEnfVertex = it_coords_enf->second;
981
982       _coordsEnfVertexMap.erase(it_coords_enf);
983
984       TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
985       enfVertexCoordsList.erase(coords);
986       if (enfVertexCoordsList.size() == 0)
987         _faceEntryCoordsListMap.erase(theFaceEntry);
988       //      TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
989       //      TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
990       //      it_entry_coords->second.erase(it_coordsList);
991       //      if (it_entry_coords->second.size() == 0)
992       //        _faceEntryCoordsListMap.erase(it_entry_coords);
993     } else {
994       // Fail
995       MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
996       msg << std::endl;
997       msg << "No enforced vertex at " << x << ", " << y << ", " << z;
998       throw std::invalid_argument(msg.str());
999     }
1000   }
1001
1002   MESSAGE("Remove enf vertex from _enfVertexList");
1003
1004   // update _enfVertexList
1005   TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1006   if (it != _enfVertexList.end()) {
1007     (*it)->faceEntries.erase(theFaceEntry);
1008     if ((*it)->faceEntries.size() == 0){
1009       _enfVertexList.erase(it);
1010       toNotify = true;
1011     }
1012     MESSAGE("Done");
1013   }
1014
1015   // update _faceEntryEnfVertexListMap
1016   TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1017   currentEnfVertexList.erase(oldEnfVertex);
1018
1019   if (currentEnfVertexList.size() == 0) {
1020     MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
1021     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1022     MESSAGE("Done");
1023   }
1024
1025   if (toNotify)
1026     NotifySubMeshesHypothesisModification();
1027
1028   return toNotify;
1029 }
1030
1031 //=======================================================================
1032 //function : ClearEnforcedVertices
1033 //=======================================================================
1034
1035 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1036
1037   bool toNotify = false;
1038   TEnfVertex *oldEnfVertex;
1039
1040   TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1041   if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1042     toNotify = true;
1043     TEnfVertexCoordsList coordsList = it_entry_coords->second;
1044     TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1045     for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1046       TEnfVertexCoords coords = (*it_coordsList);
1047       oldEnfVertex = _coordsEnfVertexMap[coords];
1048       _coordsEnfVertexMap.erase(coords);
1049       // update _enfVertexList
1050       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1051       if (it != _enfVertexList.end()) {
1052         (*it)->faceEntries.erase(theFaceEntry);
1053         if ((*it)->faceEntries.size() == 0){
1054           _enfVertexList.erase(it);
1055           toNotify = true;
1056         }
1057         MESSAGE("Done");
1058       }
1059     }
1060     _faceEntryCoordsListMap.erase(it_entry_coords);
1061     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1062   }
1063
1064   TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1065   if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1066     toNotify = true;
1067     TEntryList enfVertexEntryList = it_entry_entry->second;
1068     TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1069     for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1070       TEntry enfVertexEntry = (*it_enfVertexEntryList);
1071       oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1072       _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1073       // update _enfVertexList
1074       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1075       if (it != _enfVertexList.end()) {
1076         (*it)->faceEntries.erase(theFaceEntry);
1077         if ((*it)->faceEntries.size() == 0){
1078           _enfVertexList.erase(it);
1079           toNotify = true;
1080         }
1081         MESSAGE("Done");
1082       }
1083     }
1084     _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1085     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1086   }
1087
1088   if (toNotify)
1089     NotifySubMeshesHypothesisModification();
1090
1091   return toNotify;
1092   //  std::ostringstream msg;
1093   //  msg << "No enforced vertex for " << theFaceEntry;
1094   //  throw std::invalid_argument(msg.str());
1095 }
1096
1097 //=======================================================================
1098 //function : ClearAllEnforcedVertices
1099 //=======================================================================
1100 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1101   _faceEntryEnfVertexListMap.clear();
1102   _enfVertexList.clear();
1103   _faceEntryCoordsListMap.clear();
1104   _coordsEnfVertexMap.clear();
1105   _faceEntryEnfVertexEntryListMap.clear();
1106   _enfVertexEntryEnfVertexMap.clear();
1107 //  Enable internal enforced vertices on specific face if requested by user
1108 //  _faceEntryInternalVerticesList.clear();
1109   NotifySubMeshesHypothesisModification();
1110 }
1111
1112 //================================================================================
1113 /*!
1114  * \brief Return the enforced vertices
1115  */
1116 //================================================================================
1117
1118
1119 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1120     const BLSURFPlugin_Hypothesis* hyp) {
1121   return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1122 }
1123
1124 //Enable internal enforced vertices on specific face if requested by user
1125 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1126 //    const BLSURFPlugin_Hypothesis* hyp) {
1127 //  return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1128 //}
1129
1130 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1131 {
1132   return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1133 }
1134
1135 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1136 {
1137   return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1138 }
1139
1140 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1141     const BLSURFPlugin_Hypothesis* hyp) {
1142   return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1143 }
1144
1145 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1146     const BLSURFPlugin_Hypothesis* hyp) {
1147   return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1148 }
1149
1150 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1151     const BLSURFPlugin_Hypothesis* hyp) {
1152   return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1153 }
1154
1155 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1156     const BLSURFPlugin_Hypothesis* hyp) {
1157   return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1158 }
1159
1160 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1161     const BLSURFPlugin_Hypothesis* hyp) {
1162   return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1163 }
1164
1165 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1166 {
1167   TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1168   if (it != _groupNameNodeIDMap.end()) {
1169     return it->second;
1170   }
1171   std::ostringstream msg;
1172   msg << "No group " << theGroupName;
1173   throw std::invalid_argument(msg.str());
1174 }
1175
1176 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1177 {
1178   _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1179 }
1180
1181 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1182 {
1183   TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1184   if (it != _groupNameNodeIDMap.end()) {
1185     std::set<int>::iterator IDit = it->second.find(theNodeID);
1186     if (IDit != it->second.end())
1187       it->second.erase(IDit);
1188     std::ostringstream msg;
1189     msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1190     throw std::invalid_argument(msg.str());
1191   }
1192   std::ostringstream msg;
1193   msg << "No group " << theGroupName;
1194   throw std::invalid_argument(msg.str());
1195 }
1196
1197
1198 //=============================================================================
1199 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1200   if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1201     _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1202     if (toEnforceInternalVertices)
1203       SetPhysicalMesh(PhysicalLocalSize);
1204     NotifySubMeshesHypothesisModification();
1205   }
1206 }
1207
1208
1209 //=============================================================================
1210 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1211   if (string(theGroupName) != string(_enforcedInternalVerticesAllFacesGroup)) {
1212     _enforcedInternalVerticesAllFacesGroup = theGroupName;
1213     NotifySubMeshesHypothesisModification();
1214   }
1215 }
1216
1217 //=============================================================================
1218 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1219     const BLSURFPlugin_Hypothesis* hyp) {
1220   return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1221 }
1222
1223 //=============================================================================
1224 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1225     const BLSURFPlugin_Hypothesis* hyp) {
1226   return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1227 }
1228
1229 //=============================================================================
1230 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1231     const BLSURFPlugin_Hypothesis* hyp) {
1232   return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1233 }
1234
1235 //=============================================================================
1236 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1237     const BLSURFPlugin_Hypothesis* hyp){
1238   return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1239 }
1240
1241 //=============================================================================
1242 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1243     const BLSURFPlugin_Hypothesis* hyp){
1244   return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1245 }
1246
1247 //=======================================================================
1248 //function : ClearAllEnforcedVertices
1249 //=======================================================================
1250 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1251   _preCadFacesPeriodicityVector.clear();
1252   _preCadEdgesPeriodicityVector.clear();
1253   NotifySubMeshesHypothesisModification();
1254 }
1255
1256 //=======================================================================
1257 //function : AddPreCadFacesPeriodicity
1258 //=======================================================================
1259 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1260     vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries) {
1261
1262   TPreCadPeriodicity preCadFacesPeriodicity;
1263   preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1264   preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1265   preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1266   preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1267
1268   _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1269
1270   NotifySubMeshesHypothesisModification();
1271 }
1272
1273 //=======================================================================
1274 //function : AddPreCadEdgesPeriodicity
1275 //=======================================================================
1276 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1277     vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries) {
1278
1279   TPreCadPeriodicity preCadEdgesPeriodicity;
1280   preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1281   preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1282   preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1283   preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1284
1285   _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1286
1287   NotifySubMeshesHypothesisModification();
1288 }
1289
1290 //=======================================================================
1291 //function : AddFacePeriodicity
1292 //=======================================================================
1293 void BLSURFPlugin_Hypothesis::AddFacePeriodicity(TEntry theFace1Entry, TEntry theFace2Entry) {
1294
1295   std::pair< TEntry, TEntry > pairOfFacesEntries = std::make_pair(theFace1Entry, theFace2Entry);
1296
1297   _facesPeriodicityVector.push_back(pairOfFacesEntries);
1298
1299   // Removed for performance reason since AddFacePeriodicity is called multiple times (one time for each face)
1300   // Does not affect the behaviour since it is only called via python, not via GUI.
1301   //NotifySubMeshesHypothesisModification();
1302 }
1303
1304
1305 //=======================================================================
1306 //function : AddEdgePeriodicity
1307 //=======================================================================
1308 void BLSURFPlugin_Hypothesis::AddEdgePeriodicity(TEntry theFace1Entry, TEntry theEdge1Entry, TEntry theFace2Entry, TEntry theEdge2Entry, int edge_orientation) {
1309
1310   TEdgePeriodicity edgePeriodicity;
1311   edgePeriodicity.theFace1Entry = theFace1Entry;
1312   edgePeriodicity.theEdge1Entry = theEdge1Entry;
1313   edgePeriodicity.theFace2Entry = theFace2Entry;
1314   edgePeriodicity.theEdge2Entry = theEdge2Entry;
1315   edgePeriodicity.edge_orientation = edge_orientation;
1316
1317   _edgesPeriodicityVector.push_back(edgePeriodicity);
1318
1319   // Removed for performance reason since AddEdgePeriodicity is called multiple times (one time for each edge)
1320   // Does not affect the behaviour since it is only called via python, not via GUI.
1321   //NotifySubMeshesHypothesisModification();
1322 }
1323
1324 //=======================================================================
1325 //function : AddVertexPeriodicity
1326 //=======================================================================
1327 void BLSURFPlugin_Hypothesis::AddVertexPeriodicity(TEntry theEdge1Entry, TEntry theVertex1Entry, TEntry theEdge2Entry, TEntry theVertex2Entry) {
1328
1329   TVertexPeriodicity vertexPeriodicity;
1330   vertexPeriodicity.theEdge1Entry = theEdge1Entry;
1331   vertexPeriodicity.theVertex1Entry = theVertex1Entry;
1332   vertexPeriodicity.theEdge2Entry = theEdge2Entry;
1333   vertexPeriodicity.theVertex2Entry = theVertex2Entry;
1334
1335   _verticesPeriodicityVector.push_back(vertexPeriodicity);
1336
1337   // Removed for performance reason since AddVertexPeriodicity is called multiple times (one time for each vertex)
1338   // Does not affect the behaviour since it is only called via python, not via GUI.
1339   //NotifySubMeshesHypothesisModification();
1340 }
1341
1342 //=============================================================================
1343 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1344    // We must keep at least the same number of arguments when increasing the SALOME version
1345    // When BLSURF becomes CADMESH, some parameters were fused into a single one. Thus the same
1346    // parameter can be written several times to keep the old global number of parameters.
1347
1348    // Treat old options which are now in the advanced options
1349    TOptionValues::iterator op_val;
1350    int _decimesh = -1;
1351    int _preCADRemoveNanoEdges = -1;
1352    double _preCADEpsNano = -1.0;
1353    op_val = _option2value.find("respect_geometry");
1354    if (op_val != _option2value.end()) {
1355      std::string value = op_val->second;
1356      if (!value.empty())
1357        _decimesh = value.compare("1") == 0 ? 1 : 0;
1358    }
1359    op_val = _preCADoption2value.find("remove_tiny_edges");
1360    if (op_val != _preCADoption2value.end()) {
1361      std::string value = op_val->second;
1362      if (!value.empty())
1363        _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1364    }
1365    op_val = _preCADoption2value.find("tiny_edge_length");
1366    if (op_val != _preCADoption2value.end()) {
1367      std::string value = op_val->second;
1368      if (!value.empty())
1369        _preCADEpsNano = strtod(value.c_str(), NULL);
1370    }
1371    
1372   save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1373       << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1374   save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1375   save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1376   save << " " << (int) _enforcedInternalVerticesAllFaces;
1377   save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1378   save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1379   save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1380   save << " " << (int) _preCADProcess3DTopology;
1381
1382   op_val = _option2value.begin();
1383   if (op_val != _option2value.end()) {
1384     save << " " << "__OPTIONS_BEGIN__";
1385     for (; op_val != _option2value.end(); ++op_val) {
1386       if (!op_val->second.empty())
1387         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1388     }
1389     save << " " << "__OPTIONS_END__";
1390   }
1391   
1392   op_val = _preCADoption2value.begin();
1393   if (op_val != _preCADoption2value.end()) {
1394     save << " " << "__PRECAD_OPTIONS_BEGIN__";
1395     for (; op_val != _preCADoption2value.end(); ++op_val) {
1396       if (!op_val->second.empty())
1397         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1398     }
1399     save << " " << "__PRECAD_OPTIONS_END__";
1400   }
1401
1402   TSizeMap::iterator it_sm = _sizeMap.begin();
1403   if (it_sm != _sizeMap.end()) {
1404     save << " " << "__SIZEMAP_BEGIN__";
1405     for (; it_sm != _sizeMap.end(); ++it_sm) {
1406       save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1407     }
1408     save << " " << "__SIZEMAP_END__";
1409   }
1410
1411   TSizeMap::iterator it_at = _attractors.begin();
1412   if (it_at != _attractors.end()) {
1413     save << " " << "__ATTRACTORS_BEGIN__";
1414     for (; it_at != _attractors.end(); ++it_at) {
1415       save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1416     }
1417     save << " " << "__ATTRACTORS_END__";
1418   }
1419   
1420   TAttractorMap::iterator it_At = _classAttractors.begin();
1421   if (it_At != _classAttractors.end()) {
1422     std::ostringstream test;
1423     save << " " << "__NEW_ATTRACTORS_BEGIN__";
1424     test << " " << "__NEW_ATTRACTORS_BEGIN__";
1425     for (; it_At != _classAttractors.end(); ++it_At) {
1426       std::vector<double> attParams;
1427       attParams   = it_At->second->GetParameters();
1428 //       double step = it_At->second->GetStep();
1429       save << " " << it_At->first;
1430       save << " " << it_At->second->GetAttractorEntry();
1431       save << " " << attParams[0]  << " " <<  attParams[1] << " " <<  attParams[2] << " " <<  attParams[3];
1432 //       save << " " << step;
1433       test << " " << it_At->first;
1434       test << " " << it_At->second->GetAttractorEntry();
1435       test << " " << attParams[0]  << " " <<  attParams[1] << " " <<  attParams[2] << " " <<  attParams[3];
1436 //       test << " " << step;
1437     }
1438     save << " " << "__NEW_ATTRACTORS_END__";
1439     test << " " << "__NEW_ATTRACTORS_END__";
1440     MESSAGE(" Attractor hypothesis saved as "<<test.str())
1441   }
1442
1443   TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1444   if (it_enf != _enfVertexList.end()) {
1445     save << " " << "__ENFORCED_VERTICES_BEGIN__";
1446     for (; it_enf != _enfVertexList.end(); ++it_enf) {
1447       TEnfVertex *enfVertex = (*it_enf);
1448       save << " " << "__BEGIN_VERTEX__";
1449       if (!enfVertex->name.empty()) {
1450         save << " " << "__BEGIN_NAME__";
1451         save << " " << enfVertex->name;
1452         save << " " << "__END_NAME__";
1453       }
1454       if (!enfVertex->geomEntry.empty()) {
1455         save << " " << "__BEGIN_ENTRY__";
1456         save << " " << enfVertex->geomEntry;
1457         save << " " << "__END_ENTRY__";
1458       }
1459       if (!enfVertex->grpName.empty()) {
1460         save << " " << "__BEGIN_GROUP__";
1461         save << " " << enfVertex->grpName;
1462         save << " " << "__END_GROUP__";
1463       }
1464       if (enfVertex->coords.size()) {
1465         save << " " << "__BEGIN_COORDS__";
1466         for (int i=0;i<enfVertex->coords.size();i++)
1467           save << " " << enfVertex->coords[i];
1468         save << " " << "__END_COORDS__";
1469       }
1470       TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1471       bool hasFaces = false;
1472       if (faceEntriesIt != enfVertex->faceEntries.end()) {
1473         hasFaces = true;
1474         save << " " << "__BEGIN_FACELIST__";
1475       }
1476       for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1477         save << " " << (*faceEntriesIt);
1478       if (hasFaces)
1479         save << " " << "__END_FACELIST__";
1480       save << " " << "__END_VERTEX__";
1481     }
1482     save << " " << "__ENFORCED_VERTICES_END__";
1483   }
1484
1485   //PERIODICITY
1486
1487   SavePreCADPeriodicity(save, "FACES");
1488   SavePreCADPeriodicity(save, "EDGES");
1489
1490   SaveFacesPeriodicity(save);
1491   SaveEdgesPeriodicity(save);
1492   SaveVerticesPeriodicity(save);
1493
1494   return save;
1495 }
1496
1497 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1498
1499   TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1500   if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1501     MESSAGE("__FACES_PERIODICITY_BEGIN__");
1502     save << " " << "__FACES_PERIODICITY_BEGIN__";
1503     for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1504       TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1505       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1506       save << " " << "__BEGIN_ENTRY1__";
1507       save << " " << periodicity_i.first;
1508       save << " " << "__END_ENTRY1__";
1509       save << " " << "__BEGIN_ENTRY2__";
1510       save << " " << periodicity_i.second;
1511       save << " " << "__END_ENTRY2__";
1512       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1513     }
1514     save << " " << "__FACES_PERIODICITY_END__";
1515     MESSAGE("__FACES_PERIODICITY_END__");
1516   }
1517 }
1518
1519 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
1520
1521   TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
1522   if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
1523     save << " " << "__EDGES_PERIODICITY_BEGIN__";
1524     MESSAGE("__EDGES_PERIODICITY_BEGIN__");
1525     for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
1526       TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
1527       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1528       if (! periodicity_i.theFace1Entry.empty()){
1529         save << " " << "__BEGIN_FACE1__";
1530         save << " " << periodicity_i.theFace1Entry;
1531         save << " " << "__END_FACE1__";
1532       }
1533       save << " " << "__BEGIN_EDGE1__";
1534       save << " " << periodicity_i.theEdge1Entry;
1535       save << " " << "__END_EDGE1__";
1536       if (! periodicity_i.theFace2Entry.empty()){
1537         save << " " << "__BEGIN_FACE2__";
1538         save << " " << periodicity_i.theFace2Entry;
1539         save << " " << "__END_FACE2__";
1540       }
1541       save << " " << "__BEGIN_EDGE2__";
1542       save << " " << periodicity_i.theEdge2Entry;
1543       save << " " << "__END_EDGE2__";
1544       save << " " << "__BEGIN_EDGE_ORIENTATION__";
1545       save << " " << periodicity_i.edge_orientation;
1546       save << " " << "__END_EDGE_ORIENTATION__";
1547       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1548     }
1549     save << " " << "__EDGES_PERIODICITY_END__";
1550     MESSAGE("__EDGES_PERIODICITY_END__");
1551   }
1552 }
1553
1554 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
1555
1556   TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
1557   if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
1558     MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
1559     save << " " << "__VERTICES_PERIODICITY_BEGIN__";
1560     for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
1561       TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
1562       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1563       save << " " << "__BEGIN_EDGE1__";
1564       save << " " << periodicity_i.theEdge1Entry;
1565       save << " " << "__END_EDGE1__";
1566       save << " " << "__BEGIN_VERTEX1__";
1567       save << " " << periodicity_i.theVertex1Entry;
1568       save << " " << "__END_VERTEX1__";
1569       save << " " << "__BEGIN_EDGE2__";
1570       save << " " << periodicity_i.theEdge2Entry;
1571       save << " " << "__END_EDGE2__";
1572       save << " " << "__BEGIN_VERTEX2__";
1573       save << " " << periodicity_i.theVertex2Entry;
1574       save << " " << "__END_VERTEX2__";
1575       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1576     }
1577     save << " " << "__VERTICES_PERIODICITY_END__";
1578     MESSAGE("__VERTICES_PERIODICITY_END__");
1579   }
1580 }
1581
1582 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
1583   TPreCadPeriodicityVector precad_periodicity;
1584   if (shapeType == "FACES")
1585     precad_periodicity = _preCadFacesPeriodicityVector;
1586   else
1587     precad_periodicity = _preCadEdgesPeriodicityVector;
1588   TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
1589   if (it_precad_periodicity != precad_periodicity.end()) {
1590     save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
1591     for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
1592       TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
1593       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1594       if (!periodicity_i.shape1Entry.empty()) {
1595         save << " " << "__BEGIN_ENTRY1__";
1596         save << " " << periodicity_i.shape1Entry;
1597         save << " " << "__END_ENTRY1__";
1598       }
1599       if (!periodicity_i.shape2Entry.empty()) {
1600         save << " " << "__BEGIN_ENTRY2__";
1601         save << " " << periodicity_i.shape2Entry;
1602         save << " " << "__END_ENTRY2__";
1603       }
1604
1605       std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
1606       bool hasSourceVertices = false;
1607       if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
1608         hasSourceVertices = true;
1609         save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
1610       }
1611       for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
1612         save << " " << (*sourceVerticesEntriesIt);
1613       if (hasSourceVertices)
1614         save << " " << "__END_SOURCE_VERTICES_LIST__";
1615
1616       std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
1617       bool hasTargetVertices = false;
1618       if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
1619         hasTargetVertices = true;
1620         save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
1621       }
1622       for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
1623         save << " " << (*targetVerticesEntriesIt);
1624       if (hasTargetVertices)
1625         save << " " << "__END_TARGET_VERTICES_LIST__";
1626
1627       save << " " << "__END_PERIODICITY_DESCRIPTION__";
1628     }
1629     save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
1630   }
1631
1632 }
1633
1634 //=============================================================================
1635 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
1636   bool isOK = true;
1637   int i;
1638   double val;
1639   std::string option_or_sm;
1640
1641   isOK = (load >> i);
1642   if (isOK)
1643     _topology = (Topology) i;
1644   else
1645     load.clear(std::ios::badbit | load.rdstate());
1646
1647   isOK = (load >> i);
1648   if (isOK)
1649     _physicalMesh = (PhysicalMesh) i;
1650   else
1651     load.clear(std::ios::badbit | load.rdstate());
1652
1653   isOK = (load >> i);
1654   if (isOK)
1655     _geometricMesh = (GeometricMesh) i;
1656   else
1657     load.clear(std::ios::badbit | load.rdstate());
1658
1659   isOK = (load >> val);
1660   if (isOK)
1661     _phySize = val;
1662   else
1663     load.clear(std::ios::badbit | load.rdstate());
1664
1665   isOK = (load >> val);
1666   if (isOK)
1667     _angleMesh = val;
1668   else
1669     load.clear(std::ios::badbit | load.rdstate());
1670
1671   isOK = (load >> val);
1672   if (isOK)
1673     _gradation = val;
1674   else
1675     load.clear(std::ios::badbit | load.rdstate());
1676
1677   isOK = (load >> i);
1678   if (isOK)
1679     _quadAllowed = (bool) i;
1680   else
1681     load.clear(std::ios::badbit | load.rdstate());
1682
1683   isOK = (load >> i);
1684   if (isOK) {
1685     if ( i != -1) { // if value is -1, then this is no longer a standard option
1686       std::string & value = _option2value["respect_geometry"];
1687       bool _decimesh = (bool) i;
1688       value = _decimesh ? "1" : "0";
1689     }
1690   }
1691   else
1692     load.clear(std::ios::badbit | load.rdstate());
1693
1694   isOK = (load >> val);
1695   if (isOK)
1696     _minSize = val;
1697   else
1698     load.clear(std::ios::badbit | load.rdstate());
1699
1700   isOK = (load >> val);
1701   if (isOK)
1702     _maxSize = val;
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     _angleMesh = min(val,_angleMesh);
1710   else
1711     load.clear(std::ios::badbit | load.rdstate());
1712
1713   isOK = (load >> val);
1714   if (isOK)
1715     // former parameter: get min value
1716     _minSize = min(val,_minSize);
1717   else
1718     load.clear(std::ios::badbit | load.rdstate());
1719
1720   isOK = (load >> val);
1721   if (isOK)
1722     // former parameter: get max value
1723     _maxSize = max(val,_maxSize);
1724   else
1725     load.clear(std::ios::badbit | load.rdstate());
1726
1727   isOK = (load >> i);
1728   if (isOK)
1729     _verb = i;
1730   else
1731     load.clear(std::ios::badbit | load.rdstate());
1732
1733   isOK = (load >> i);
1734   if (isOK)
1735     _preCADMergeEdges = (bool) i;
1736   else
1737     load.clear(std::ios::badbit | load.rdstate());
1738
1739   isOK = (load >> i);
1740   if (isOK) {
1741     if ( i != -1) { // if value is -1, then this is no longer a standard option
1742       std::string & value = _preCADoption2value["remove_tiny_edges"];
1743       bool _preCADRemoveNanoEdges = (bool) i;
1744       value = _preCADRemoveNanoEdges ? "1" : "0";
1745     }
1746   }
1747   else
1748     load.clear(std::ios::badbit | load.rdstate());
1749
1750   isOK = (load >> i);
1751   if (isOK)
1752     _preCADDiscardInput = (bool) i;
1753   else
1754     load.clear(std::ios::badbit | load.rdstate());
1755
1756   isOK = (load >> val);
1757   if (isOK) { // _preCADEpsNano
1758     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
1759       std::string & value = _preCADoption2value["tiny_edge_length"];
1760       std::ostringstream oss;
1761       oss << i;
1762       value = oss.str();
1763     }
1764   }
1765   else
1766     load.clear(std::ios::badbit | load.rdstate());
1767
1768   isOK = (load >> i);
1769   if (isOK)
1770     _enforcedInternalVerticesAllFaces = (bool) i;
1771   else
1772     load.clear(std::ios::badbit | load.rdstate());
1773
1774   // New options with MeshGems-CADSurf
1775
1776   bool hasCADSurfOptions = false;
1777   bool hasOptions = false;
1778   bool hasPreCADOptions = false;
1779   bool hasSizeMap = false;
1780   bool hasAttractor = false;
1781   bool hasNewAttractor = false;
1782   bool hasEnforcedVertex = false;
1783   bool hasPreCADFacesPeriodicity = false;
1784   bool hasPreCADEdgesPeriodicity = false;
1785   bool hasFacesPeriodicity = false;
1786   bool hasEdgesPeriodicity = false;
1787   bool hasVerticesPeriodicity = false;
1788
1789   isOK = (load >> option_or_sm);
1790   if (isOK)
1791     if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
1792       i = atoi(option_or_sm.c_str());
1793       hasCADSurfOptions = true;
1794       _phySizeRel = (bool) i;
1795     }
1796     if (option_or_sm == "__OPTIONS_BEGIN__")
1797       hasOptions = true;
1798     else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1799       hasPreCADOptions = true;
1800     else if (option_or_sm == "__SIZEMAP_BEGIN__")
1801       hasSizeMap = true;
1802     else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1803       hasAttractor = true;
1804     else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1805       hasNewAttractor = true;
1806     else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1807       hasEnforcedVertex = true;
1808     else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
1809       hasPreCADFacesPeriodicity = true;
1810     else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
1811       hasPreCADEdgesPeriodicity = true;
1812     else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
1813       hasFacesPeriodicity = true;
1814     else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
1815       hasEdgesPeriodicity = true;
1816     else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
1817       hasVerticesPeriodicity = true;
1818
1819   if (isOK && hasCADSurfOptions) {
1820     isOK = (load >> i);
1821     if (isOK)
1822       _minSizeRel = (bool) i;
1823     else
1824       load.clear(std::ios::badbit | load.rdstate());
1825
1826     isOK = (load >> i);
1827     if (isOK)
1828       _maxSizeRel = (bool) i;
1829     else
1830       load.clear(std::ios::badbit | load.rdstate());
1831
1832     isOK = (load >> val);
1833     if (isOK)
1834       _chordalError = val;
1835     else
1836       load.clear(std::ios::badbit | load.rdstate());
1837
1838     isOK = (load >> i);
1839     if (isOK)
1840       _anisotropic = (bool) i;
1841     else
1842       load.clear(std::ios::badbit | load.rdstate());
1843
1844     isOK = (load >> val);
1845     if (isOK)
1846       _anisotropicRatio = val;
1847     else
1848       load.clear(std::ios::badbit | load.rdstate());
1849
1850     isOK = (load >> i);
1851     if (isOK)
1852       _removeTinyEdges = (bool) i;
1853     else
1854       load.clear(std::ios::badbit | load.rdstate());
1855
1856     isOK = (load >> val);
1857     if (isOK)
1858       _tinyEdgeLength = val;
1859     else
1860       load.clear(std::ios::badbit | load.rdstate());
1861
1862     isOK = (load >> i);
1863     if (isOK)
1864       _badElementRemoval = (bool) i;
1865     else
1866       load.clear(std::ios::badbit | load.rdstate());
1867
1868     isOK = (load >> val);
1869     if (isOK)
1870       _badElementAspectRatio = val;
1871     else
1872       load.clear(std::ios::badbit | load.rdstate());
1873
1874     isOK = (load >> i);
1875     if (isOK)
1876       _optimizeMesh = (bool) i;
1877     else
1878       load.clear(std::ios::badbit | load.rdstate());
1879
1880     isOK = (load >> i);
1881     if (isOK)
1882       _quadraticMesh = (bool) i;
1883     else
1884       load.clear(std::ios::badbit | load.rdstate());
1885
1886     isOK = (load >> i);
1887     if (isOK)
1888       _preCADProcess3DTopology = (bool) i;
1889     else
1890       load.clear(std::ios::badbit | load.rdstate());
1891
1892   }
1893   
1894
1895   if (hasCADSurfOptions) {
1896     isOK = (load >> option_or_sm);
1897     if (isOK)
1898       if (option_or_sm == "__OPTIONS_BEGIN__")
1899         hasOptions = true;
1900       else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1901         hasPreCADOptions = true;
1902       else if (option_or_sm == "__SIZEMAP_BEGIN__")
1903         hasSizeMap = true;
1904       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1905         hasAttractor = true;
1906       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1907         hasNewAttractor = true;
1908       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1909         hasEnforcedVertex = true;
1910       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
1911         hasPreCADFacesPeriodicity = true;
1912       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
1913         hasPreCADEdgesPeriodicity = true;
1914       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
1915         hasFacesPeriodicity = true;
1916       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
1917         hasEdgesPeriodicity = true;
1918       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
1919         hasVerticesPeriodicity = true;
1920   }
1921   
1922   std::string optName, optValue;
1923   while (isOK && hasOptions) {
1924     isOK = (load >> optName);
1925     if (isOK) {
1926       if (optName == "__OPTIONS_END__")
1927         break;
1928       isOK = (load >> optValue);
1929     }
1930     if (isOK) {
1931       std::string & value = _option2value[optName];
1932       value = optValue;
1933       int len = value.size();
1934       // continue reading until "%#" encountered
1935       while (value[len - 1] != '#' || value[len - 2] != '%') {
1936         isOK = (load >> optValue);
1937         if (isOK) {
1938           value += " ";
1939           value += optValue;
1940           len = value.size();
1941         } else {
1942           break;
1943         }
1944       }
1945       value[len - 2] = '\0'; //cut off "%#"
1946     }
1947   }
1948
1949   if (hasOptions) {
1950     isOK = (load >> option_or_sm);
1951     if (isOK)
1952       if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1953         hasPreCADOptions = true;
1954       else if (option_or_sm == "__SIZEMAP_BEGIN__")
1955         hasSizeMap = true;
1956       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1957         hasAttractor = true;
1958       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1959         hasNewAttractor = true;
1960       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1961         hasEnforcedVertex = true;
1962       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
1963         hasPreCADFacesPeriodicity = true;
1964       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
1965         hasPreCADEdgesPeriodicity = true;
1966       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
1967         hasFacesPeriodicity = true;
1968       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
1969         hasEdgesPeriodicity = true;
1970       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
1971         hasVerticesPeriodicity = true;
1972   }
1973
1974   while (isOK && hasPreCADOptions) {
1975     isOK = (load >> optName);
1976     if (isOK) {
1977       if (optName == "__PRECAD_OPTIONS_END__")
1978         break;
1979       isOK = (load >> optValue);
1980     }
1981     if (isOK) {
1982       std::string & value = _preCADoption2value[optName];
1983       value = optValue;
1984       int len = value.size();
1985       // continue reading until "%#" encountered
1986       while (value[len - 1] != '#' || value[len - 2] != '%') {
1987         isOK = (load >> optValue);
1988         if (isOK) {
1989           value += " ";
1990           value += optValue;
1991           len = value.size();
1992         } else {
1993           break;
1994         }
1995       }
1996       value[len - 2] = '\0'; //cut off "%#"
1997     }
1998   }
1999
2000   if (hasPreCADOptions) {
2001     isOK = (load >> option_or_sm);
2002     if (isOK)
2003       if (option_or_sm == "__SIZEMAP_BEGIN__")
2004         hasSizeMap = true;
2005       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2006         hasAttractor = true;
2007       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2008         hasNewAttractor = true;
2009       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2010         hasEnforcedVertex = true;
2011       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2012         hasPreCADFacesPeriodicity = true;
2013       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2014         hasPreCADEdgesPeriodicity = true;
2015       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2016         hasFacesPeriodicity = true;
2017       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2018         hasEdgesPeriodicity = true;
2019       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2020         hasVerticesPeriodicity = true;
2021   }
2022   
2023   std::string smEntry, smValue;
2024   while (isOK && hasSizeMap) {
2025     isOK = (load >> smEntry);
2026     if (isOK) {
2027       if (smEntry == "__SIZEMAP_END__")
2028         break;
2029       isOK = (load >> smValue);
2030     }
2031     if (isOK) {
2032       std::string & value2 = _sizeMap[smEntry];
2033       value2 = smValue;
2034       int len2 = value2.size();
2035       // continue reading until "%#" encountered
2036       while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2037         isOK = (load >> smValue);
2038         if (isOK) {
2039           value2 += " ";
2040           value2 += smValue;
2041           len2 = value2.size();
2042         } else {
2043           break;
2044         }
2045       }
2046       value2[len2 - 2] = '\0'; //cut off "%#"
2047     }
2048   }
2049
2050   if (hasSizeMap) {
2051     isOK = (load >> option_or_sm);
2052     if (isOK)
2053       if (option_or_sm == "__ATTRACTORS_BEGIN__")
2054         hasAttractor = true;
2055       if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2056         hasNewAttractor = true;
2057       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2058         hasEnforcedVertex = true;
2059       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2060         hasPreCADFacesPeriodicity = true;
2061       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2062         hasPreCADEdgesPeriodicity = true;
2063       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2064         hasFacesPeriodicity = true;
2065       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2066         hasEdgesPeriodicity = true;
2067       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2068         hasVerticesPeriodicity = true;
2069   }
2070
2071   std::string atEntry, atValue;
2072   while (isOK && hasAttractor) {
2073     isOK = (load >> atEntry);
2074     if (isOK) {
2075       if (atEntry == "__ATTRACTORS_END__")
2076         break;
2077       isOK = (load >> atValue);
2078     }
2079     if (isOK) {
2080       std::string & value3 = _attractors[atEntry];
2081       value3 = atValue;
2082       int len3 = value3.size();
2083       // continue reading until "%#" encountered
2084       while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2085         isOK = (load >> atValue);
2086         if (isOK) {
2087           value3 += " ";
2088           value3 += atValue;
2089           len3 = value3.size();
2090         } else {
2091           break;
2092         }
2093       }
2094       value3[len3 - 2] = '\0'; //cut off "%#"
2095     }
2096   }
2097
2098   if (hasAttractor) {
2099     isOK = (load >> option_or_sm);
2100     if (isOK)
2101       if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2102         hasNewAttractor = true;
2103       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2104         hasEnforcedVertex = true;
2105       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2106         hasPreCADFacesPeriodicity = true;
2107       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2108         hasPreCADEdgesPeriodicity = true;
2109       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2110         hasFacesPeriodicity = true;
2111       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2112         hasEdgesPeriodicity = true;
2113       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2114         hasVerticesPeriodicity = true;
2115   }
2116
2117   std::string newAtFaceEntry, atTestString;
2118   std::string newAtShapeEntry;
2119   double attParams[4];
2120   double step;
2121   while (isOK && hasNewAttractor) {
2122     //std::cout<<"Load new attractor"<<std::endl;
2123     isOK = (load >> newAtFaceEntry);
2124     if (isOK) {
2125       if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2126         break;
2127       isOK = (load >> newAtShapeEntry);
2128       if (!isOK)
2129     break;
2130       isOK = (load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2131     }
2132     if (isOK) {
2133       MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
2134       const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2135       const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2136       BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2137       attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2138       //attractor->BuildMap();                     
2139       _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2140     }
2141   }
2142   
2143   
2144   if (hasNewAttractor) {
2145     isOK = (load >> option_or_sm);
2146     if (isOK)
2147       if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2148         hasEnforcedVertex = true;
2149       else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2150         hasPreCADFacesPeriodicity = true;
2151       else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2152         hasPreCADEdgesPeriodicity = true;
2153       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2154         hasFacesPeriodicity = true;
2155       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2156         hasEdgesPeriodicity = true;
2157       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2158         hasVerticesPeriodicity = true;
2159   }
2160
2161
2162 // 
2163 // Here is a example of the saved stream:
2164 // __ENFORCED_VERTICES_BEGIN__ 
2165 // __BEGIN_VERTEX__  => no name, no entry
2166 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2167 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__ 
2168 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__ 
2169 // __END_VERTEX__ 
2170 // __BEGIN_VERTEX__ => no coords
2171 // __BEGIN_NAME__ mes points __END_NAME__ 
2172 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2173 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2174 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2175 // __END_VERTEX__ 
2176 // __ENFORCED_VERTICES_END__
2177 // 
2178
2179   std::string enfSeparator;
2180   std::string enfName;
2181   std::string enfGeomEntry;
2182   std::string enfGroup;
2183   TEntryList enfFaceEntryList;
2184   double enfCoords[3];
2185   bool hasCoords = false;
2186   
2187   _faceEntryEnfVertexListMap.clear();
2188   _enfVertexList.clear();
2189   _faceEntryCoordsListMap.clear();
2190   _coordsEnfVertexMap.clear();
2191   _faceEntryEnfVertexEntryListMap.clear();
2192   _enfVertexEntryEnfVertexMap.clear();
2193   
2194   
2195   while (isOK && hasEnforcedVertex) {
2196     isOK = (load >> enfSeparator); // __BEGIN_VERTEX__
2197     TEnfVertex *enfVertex = new TEnfVertex();
2198 //     MESSAGE("enfSeparator: " <<enfSeparator);
2199     if (enfSeparator == "__ENFORCED_VERTICES_END__")
2200       break; // __ENFORCED_VERTICES_END__
2201     if (enfSeparator != "__BEGIN_VERTEX__")
2202       throw std::exception();
2203     
2204     while (isOK) {
2205       isOK = (load >> enfSeparator);
2206       MESSAGE("enfSeparator: " <<enfSeparator);
2207       if (enfSeparator == "__END_VERTEX__") {
2208         
2209         enfVertex->name = enfName;
2210         enfVertex->geomEntry = enfGeomEntry;
2211         enfVertex->grpName = enfGroup;
2212         enfVertex->coords.clear();
2213         if (hasCoords)
2214           enfVertex->coords.assign(enfCoords,enfCoords+3);
2215         enfVertex->faceEntries = enfFaceEntryList;
2216         
2217         _enfVertexList.insert(enfVertex);
2218         
2219         if (enfVertex->coords.size()) {
2220           _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2221           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2222             _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2223             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2224           }
2225         }
2226         if (!enfVertex->geomEntry.empty()) {
2227           _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2228           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2229             _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2230             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2231           }
2232         }
2233         
2234         enfName.clear();
2235         enfGeomEntry.clear();
2236         enfGroup.clear();
2237         enfFaceEntryList.clear();
2238         hasCoords = false;
2239         break; // __END_VERTEX__
2240       }
2241         
2242       if (enfSeparator == "__BEGIN_NAME__") {  // __BEGIN_NAME__
2243         while (isOK && (enfSeparator != "__END_NAME__")) {
2244           isOK = (load >> enfSeparator);
2245           if (enfSeparator != "__END_NAME__") {
2246             if (!enfName.empty())
2247               enfName += " ";
2248             enfName += enfSeparator;
2249           }
2250         }
2251         MESSAGE("enfName: " <<enfName);
2252       }
2253         
2254       if (enfSeparator == "__BEGIN_ENTRY__") {  // __BEGIN_ENTRY__
2255         isOK = (load >> enfGeomEntry);
2256         isOK = (load >> enfSeparator); // __END_ENTRY__
2257         if (enfSeparator != "__END_ENTRY__")
2258           throw std::exception();
2259         MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2260       }
2261         
2262       if (enfSeparator == "__BEGIN_GROUP__") {  // __BEGIN_GROUP__
2263         while (isOK && (enfSeparator != "__END_GROUP__")) {
2264           isOK = (load >> enfSeparator);
2265           if (enfSeparator != "__END_GROUP__") {
2266             if (!enfGroup.empty())
2267               enfGroup += " ";
2268             enfGroup += enfSeparator;
2269           }
2270         }
2271         MESSAGE("enfGroup: " <<enfGroup);
2272       }
2273         
2274       if (enfSeparator == "__BEGIN_COORDS__") {  // __BEGIN_COORDS__
2275         hasCoords = true;
2276         isOK = (load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2277         isOK = (load >> enfSeparator); // __END_COORDS__
2278         if (enfSeparator != "__END_COORDS__")
2279           throw std::exception();
2280         MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2281       } 
2282         
2283       if (enfSeparator == "__BEGIN_FACELIST__") {  // __BEGIN_FACELIST__
2284         while (isOK && (enfSeparator != "__END_FACELIST__")) {
2285           isOK = (load >> enfSeparator);
2286           if (enfSeparator != "__END_FACELIST__") {
2287             enfFaceEntryList.insert(enfSeparator);
2288             MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2289           }
2290         }
2291       } 
2292     }
2293   }
2294
2295   // PERIODICITY
2296
2297   if (hasPreCADFacesPeriodicity){
2298     LoadPreCADPeriodicity(load, "FACES");
2299
2300     isOK = (load >> option_or_sm);
2301     if (isOK)
2302       if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2303         hasPreCADEdgesPeriodicity = true;
2304       else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2305         hasFacesPeriodicity = true;
2306       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2307         hasEdgesPeriodicity = true;
2308       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2309         hasVerticesPeriodicity = true;
2310   }
2311
2312   if (hasPreCADEdgesPeriodicity){
2313     LoadPreCADPeriodicity(load, "EDGES");
2314
2315     isOK = (load >> option_or_sm);
2316     if (isOK)
2317       if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2318         hasFacesPeriodicity = true;
2319       else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2320         hasEdgesPeriodicity = true;
2321       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2322         hasVerticesPeriodicity = true;
2323   }
2324
2325   if (hasFacesPeriodicity){
2326       LoadFacesPeriodicity(load);
2327
2328     isOK = (load >> option_or_sm);
2329     if (isOK)
2330       if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2331         hasEdgesPeriodicity = true;
2332       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2333         hasVerticesPeriodicity = true;
2334   }
2335
2336   if (hasEdgesPeriodicity){
2337       LoadEdgesPeriodicity(load);
2338
2339     isOK = (load >> option_or_sm);
2340     if (isOK)
2341       if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2342         hasVerticesPeriodicity = true;
2343   }
2344
2345   if (hasVerticesPeriodicity)
2346       LoadVerticesPeriodicity(load);
2347
2348   return load;
2349 }
2350
2351 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2352
2353   bool isOK = true;
2354
2355   std::string periodicitySeparator;
2356   TEntry shape1Entry;
2357   TEntry shape2Entry;
2358
2359   _facesPeriodicityVector.clear();
2360
2361   while (isOK) {
2362     isOK = (load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2363     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2364     TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2365     if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2366       break; // __FACES_PERIODICITY_END__
2367     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2368       MESSAGE("//" << periodicitySeparator << "//");
2369       throw std::exception();
2370     }
2371
2372     while (isOK) {
2373       isOK = (load >> periodicitySeparator);
2374       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2375       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2376
2377         periodicity_i->first = shape1Entry;
2378         periodicity_i->second = shape2Entry;
2379
2380         _facesPeriodicityVector.push_back(*periodicity_i);
2381
2382         break; // __END_PERIODICITY_DESCRIPTION__
2383       }
2384
2385       if (periodicitySeparator == "__BEGIN_ENTRY1__") {  // __BEGIN_ENTRY1__
2386         isOK = (load >> shape1Entry);
2387         isOK = (load >> periodicitySeparator); // __END_ENTRY1__
2388         if (periodicitySeparator != "__END_ENTRY1__")
2389           throw std::exception();
2390         MESSAGE("shape1Entry: " <<shape1Entry);
2391       }
2392
2393       if (periodicitySeparator == "__BEGIN_ENTRY2__") {  // __BEGIN_ENTRY2__
2394         isOK = (load >> shape2Entry);
2395         isOK = (load >> periodicitySeparator); // __END_ENTRY2__
2396         if (periodicitySeparator != "__END_ENTRY2__")
2397           throw std::exception();
2398         MESSAGE("shape2Entry: " <<shape2Entry);
2399       }
2400     }
2401   }
2402 }
2403
2404
2405 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
2406
2407   bool isOK = true;
2408
2409   std::string periodicitySeparator;
2410   TEntry theFace1Entry;
2411   TEntry theEdge1Entry;
2412   TEntry theFace2Entry;
2413   TEntry theEdge2Entry;
2414   int edge_orientation = 0;
2415
2416   _edgesPeriodicityVector.clear();
2417
2418   while (isOK) {
2419     isOK = (load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2420     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2421     TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
2422     if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
2423       break; // __EDGES_PERIODICITY_END__
2424     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2425       MESSAGE("//" << periodicitySeparator << "//");
2426       throw std::exception();
2427     }
2428
2429     while (isOK) {
2430       isOK = (load >> periodicitySeparator);
2431       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2432       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2433
2434         periodicity_i->theFace1Entry = theFace1Entry;
2435         periodicity_i->theEdge1Entry = theEdge1Entry;
2436         periodicity_i->theFace2Entry = theFace2Entry;
2437         periodicity_i->theEdge2Entry = theEdge2Entry;
2438         periodicity_i->edge_orientation = edge_orientation;
2439
2440         _edgesPeriodicityVector.push_back(*periodicity_i);
2441
2442         break; // __END_PERIODICITY_DESCRIPTION__
2443       }
2444
2445       if (periodicitySeparator == "__BEGIN_FACE1__") {  // __BEGIN_FACE1__
2446         isOK = (load >> theFace1Entry);
2447         MESSAGE("//" << theFace1Entry << "//");
2448         isOK = (load >> periodicitySeparator); // __END_FACE1__
2449         if (periodicitySeparator != "__END_FACE1__"){
2450           MESSAGE("//" << periodicitySeparator << "//");
2451           throw std::exception();
2452         }
2453         MESSAGE("theFace1Entry: " <<theFace1Entry);
2454       }
2455
2456       if (periodicitySeparator == "__BEGIN_EDGE1__") {  // __BEGIN_EDGE1__
2457         isOK = (load >> theEdge1Entry);
2458         isOK = (load >> periodicitySeparator); // __END_EDGE1__
2459         if (periodicitySeparator != "__END_EDGE1__")
2460           throw std::exception();
2461         MESSAGE("theEdge1Entry: " <<theEdge1Entry);
2462       }
2463
2464       if (periodicitySeparator == "__BEGIN_FACE2__") {  // __BEGIN_FACE2__
2465         isOK = (load >> theFace2Entry);
2466         isOK = (load >> periodicitySeparator); // __END_FACE2__
2467         if (periodicitySeparator != "__END_FACE2__")
2468           throw std::exception();
2469         MESSAGE("theFace2Entry: " <<theFace2Entry);
2470       }
2471
2472       if (periodicitySeparator == "__BEGIN_EDGE2__") {  // __BEGIN_EDGE2__
2473         isOK = (load >> theEdge2Entry);
2474         isOK = (load >> periodicitySeparator); // __END_EDGE2__
2475         if (periodicitySeparator != "__END_EDGE2__")
2476           throw std::exception();
2477         MESSAGE("theEdge2Entry: " <<theEdge2Entry);
2478       }
2479
2480       if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") {  // __BEGIN_EDGE_ORIENTATION__
2481         isOK = (load >> edge_orientation);
2482         isOK = (load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
2483         if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
2484           throw std::exception();
2485         MESSAGE("edge_orientation: " <<edge_orientation);
2486       }
2487     }
2488   }
2489 }
2490
2491 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
2492
2493   bool isOK = true;
2494
2495   std::string periodicitySeparator;
2496   TEntry theEdge1Entry;
2497   TEntry theVertex1Entry;
2498   TEntry theEdge2Entry;
2499   TEntry theVertex2Entry;
2500
2501   _verticesPeriodicityVector.clear();
2502
2503   while (isOK) {
2504     isOK = (load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2505     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2506     TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
2507     if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
2508       break; // __VERTICES_PERIODICITY_END__
2509     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2510       MESSAGE("//" << periodicitySeparator << "//");
2511       throw std::exception();
2512     }
2513
2514     while (isOK) {
2515       isOK = (load >> periodicitySeparator);
2516       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2517       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2518
2519         periodicity_i->theEdge1Entry = theEdge1Entry;
2520         periodicity_i->theVertex1Entry = theVertex1Entry;
2521         periodicity_i->theEdge2Entry = theEdge2Entry;
2522         periodicity_i->theVertex2Entry = theVertex2Entry;
2523
2524         _verticesPeriodicityVector.push_back(*periodicity_i);
2525
2526         break; // __END_PERIODICITY_DESCRIPTION__
2527       }
2528
2529       if (periodicitySeparator == "__BEGIN_EDGE1__") {  // __BEGIN_EDGE1__
2530         isOK = (load >> theEdge1Entry);
2531         isOK = (load >> periodicitySeparator); // __END_EDGE1__
2532         if (periodicitySeparator != "__END_EDGE1__")
2533           throw std::exception();
2534         MESSAGE("theEdge1Entry: " <<theEdge1Entry);
2535       }
2536
2537       if (periodicitySeparator == "__BEGIN_VERTEX1__") {  // __BEGIN_VERTEX1__
2538         isOK = (load >> theVertex1Entry);
2539         isOK = (load >> periodicitySeparator); // __END_VERTEX1__
2540         if (periodicitySeparator != "__END_VERTEX1__")
2541           throw std::exception();
2542         MESSAGE("theVertex1Entry: " <<theVertex1Entry);
2543       }
2544
2545       if (periodicitySeparator == "__BEGIN_EDGE2__") {  // __BEGIN_EDGE2__
2546         isOK = (load >> theEdge2Entry);
2547         isOK = (load >> periodicitySeparator); // __END_EDGE2__
2548         if (periodicitySeparator != "__END_EDGE2__")
2549           throw std::exception();
2550         MESSAGE("theEdge2Entry: " <<theEdge2Entry);
2551       }
2552
2553       if (periodicitySeparator == "__BEGIN_VERTEX2__") {  // __BEGIN_VERTEX2__
2554         isOK = (load >> theVertex2Entry);
2555         isOK = (load >> periodicitySeparator); // __END_VERTEX2__
2556         if (periodicitySeparator != "__END_VERTEX2__")
2557           throw std::exception();
2558         MESSAGE("theVertex2Entry: " <<theVertex2Entry);
2559       }
2560     }
2561   }
2562 }
2563
2564 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
2565
2566   bool isOK = true;
2567
2568   std::string periodicitySeparator;
2569   TEntry shape1Entry;
2570   TEntry shape2Entry;
2571   std::vector<std::string> theSourceVerticesEntries;
2572   std::vector<std::string> theTargetVerticesEntries;
2573
2574   bool hasSourceVertices = false;
2575   bool hasTargetVertices = false;
2576
2577   if (shapeType == "FACES")
2578     _preCadFacesPeriodicityVector.clear();
2579   else
2580     _preCadEdgesPeriodicityVector.clear();
2581
2582
2583   while (isOK) {
2584     isOK = (load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2585     MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2586     TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
2587 //     MESSAGE("periodicitySeparator: " <<periodicitySeparator);
2588     std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
2589     if (periodicitySeparator == endSeparator)
2590       break; // __PRECAD_FACES_PERIODICITY_END__
2591     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2592       MESSAGE("//" << endSeparator << "//");
2593       MESSAGE("//" << periodicitySeparator << "//");
2594       throw std::exception();
2595     }
2596
2597     while (isOK) {
2598       isOK = (load >> periodicitySeparator);
2599       MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2600       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2601
2602         periodicity_i->shape1Entry = shape1Entry;
2603         periodicity_i->shape2Entry = shape2Entry;
2604
2605         MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
2606         MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
2607
2608         if (hasSourceVertices)
2609           periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
2610         if (hasTargetVertices)
2611           periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
2612
2613         if (shapeType == "FACES")
2614           _preCadFacesPeriodicityVector.push_back(*periodicity_i);
2615         else
2616           _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
2617
2618         theSourceVerticesEntries.clear();
2619         theTargetVerticesEntries.clear();
2620         hasSourceVertices = false;
2621         hasTargetVertices = false;
2622         break; // __END_PERIODICITY_DESCRIPTION__
2623       }
2624
2625       if (periodicitySeparator == "__BEGIN_ENTRY1__") {  // __BEGIN_ENTRY1__
2626         isOK = (load >> shape1Entry);
2627         isOK = (load >> periodicitySeparator); // __END_ENTRY1__
2628         if (periodicitySeparator != "__END_ENTRY1__")
2629           throw std::exception();
2630         MESSAGE("shape1Entry: " <<shape1Entry);
2631       }
2632
2633       if (periodicitySeparator == "__BEGIN_ENTRY2__") {  // __BEGIN_ENTRY2__
2634         isOK = (load >> shape2Entry);
2635         isOK = (load >> periodicitySeparator); // __END_ENTRY2__
2636         if (periodicitySeparator != "__END_ENTRY2__")
2637           throw std::exception();
2638         MESSAGE("shape2Entry: " <<shape2Entry);
2639       }
2640
2641       if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") {  // __BEGIN_SOURCE_VERTICES_LIST__
2642         hasSourceVertices = true;
2643         while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
2644           isOK = (load >> periodicitySeparator);
2645           if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
2646             theSourceVerticesEntries.push_back(periodicitySeparator);
2647             MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
2648           }
2649         }
2650       }
2651
2652       if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") {  // __BEGIN_TARGET_VERTICES_LIST__
2653         hasTargetVertices = true;
2654         while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
2655           isOK = (load >> periodicitySeparator);
2656           if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
2657             theTargetVerticesEntries.push_back(periodicitySeparator);
2658             MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
2659           }
2660         }
2661       }
2662     }
2663   }
2664 }
2665
2666 //=============================================================================
2667 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
2668   return hyp.SaveTo(save);
2669 }
2670
2671 //=============================================================================
2672 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
2673   return hyp.LoadFrom(load);
2674 }
2675
2676 //================================================================================
2677 /*!
2678  * \brief Does nothing
2679  */
2680 //================================================================================
2681
2682 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
2683   return false;
2684 }
2685
2686 //================================================================================
2687 /*!
2688  * \brief Returns default global constant physical size given a default value of element length ratio
2689  */
2690 //================================================================================
2691
2692 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
2693   if (bbSegmentation != 0 && diagonal != 0)
2694     return diagonal / bbSegmentation ;
2695   return 10;
2696 }
2697
2698 //================================================================================
2699 /*!
2700  * \brief Returns default min size given a default value of element length ratio
2701  */
2702 //================================================================================
2703
2704 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
2705   if (diagonal != 0)
2706     return diagonal / 1000.0 ;
2707   return undefinedDouble();
2708 }
2709
2710 //================================================================================
2711 /*!
2712  * \brief Returns default max size given a default value of element length ratio
2713  */
2714 //================================================================================
2715
2716 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
2717   if (diagonal != 0)
2718     return diagonal / 5.0 ;
2719   return undefinedDouble();
2720 }
2721
2722 //================================================================================
2723 /*!
2724  * \brief Returns default chordal error given a default value of element length ratio
2725  */
2726 //================================================================================
2727
2728 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
2729   if (diagonal != 0)
2730     return diagonal;
2731   return undefinedDouble();
2732 }
2733
2734 //================================================================================
2735 /*!
2736  * \brief Returns default tiny edge length given a default value of element length ratio
2737  */
2738 //================================================================================
2739
2740 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
2741   if (diagonal != 0)
2742     return diagonal * 1e-6 ;
2743   return undefinedDouble();
2744 }
2745
2746 //=============================================================================
2747 /*!
2748  * \brief Initialize my parameter values by default parameters.
2749  *  \retval bool - true if parameter values have been successfully defined
2750  */
2751 //=============================================================================
2752
2753 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
2754   double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
2755   _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
2756   _minSize = GetDefaultMinSize(diagonal);
2757   _maxSize = GetDefaultMaxSize(diagonal);
2758   _chordalError = GetDefaultChordalError(diagonal);
2759   _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
2760
2761   return true;
2762 //   return bool(_phySize = dflts._elemLength);
2763 }