Salome HOME
Merge from V6_main (04/10/2012)
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
1 // Copyright (C) 2007-2012  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.
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), _topology(GetDefaultTopology()),
45   _physicalMesh(GetDefaultPhysicalMesh()),
46   _phySize(GetDefaultPhySize()),
47   _phyMax(GetDefaultMaxSize()),
48   _phyMin(GetDefaultMinSize()),
49   _hgeoMax(GetDefaultMaxSize()),
50   _hgeoMin(GetDefaultMinSize()), 
51   _geometricMesh(GetDefaultGeometricMesh()),
52   _angleMeshS(GetDefaultAngleMeshS()),
53   _angleMeshC(GetDefaultAngleMeshC()),
54   _gradation(GetDefaultGradation()),
55   _quadAllowed(GetDefaultQuadAllowed()),
56   _decimesh(GetDefaultDecimesh()),
57   _verb(GetDefaultVerbosity()),
58   _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
59   _preCADRemoveNanoEdges(GetDefaultPreCADRemoveNanoEdges()),
60   _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
61   _preCADEpsNano(GetDefaultPreCADEpsNano()),
62   _sizeMap(GetDefaultSizeMap()),
63   _attractors(GetDefaultSizeMap()),
64   _classAttractors(GetDefaultAttractorMap()),
65   _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
66   _enfVertexList(GetDefaultEnfVertexList()),
67   _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
68   _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
69   _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
70   _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
71   _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
72   _GMFFileName(GetDefaultGMFFile()),
73   _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex())
74 {
75   _name = "BLSURF_Parameters";
76   _param_algo_dim = 2;
77   
78 //   _GMFFileMode = false; // GMF ascii mode
79   
80   // to disable writing boundaries
81   //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
82
83
84   const char* intOptionNames[] = { "addsurf_ivertex", "anisotropic", "background", "CheckAdjacentEdges", "CheckCloseEdges",
85       "CheckWellDefined", "coiter", "communication", "debug", "decim", "export_flag", "file_h", "frontal", "gridnu", "gridnv",
86       "hinterpol_flag", "hmean_flag", "intermedfile", "memory", "normals", "optim", "pardom_flag", "pinch", "refs",
87       "rigid", "surforient", "tconf", "topo_collapse",
88       "proximity", "prox_nb_layer", "prox_ratio", // detects the volumic proximity of surfaces
89       "" // mark of end
90       };
91   const char* doubleOptionNames[] = { "addsurf_angle", "addsurf_R", "addsurf_H", "addsurf_FG", "addsurf_r",
92       "addsurf_PA", "angle_compcurv", "angle_ridge", "anisotropic_ratio", "CoefRectangle", "eps_collapse", "eps_ends", "eps_pardom", "LSS",
93       "topo_eps1", "topo_eps2", "" // mark of end
94       };
95   const char* charOptionNames[] = { "export_format", "export_option", "import_option", "prefix", "" // mark of end
96       };
97
98   // PreCAD advanced options
99   const char* preCADintOptionNames[] = { "closed_geometry", "debug", "manifold_geometry", "create_tag_on_collision","" // mark of end
100       };
101   const char* preCADdoubleOptionNames[] = { "eps_nano_relative", "eps_sewing", "eps_sewing_relative", "periodic_tolerance",
102       "periodic_tolerance_relative", "periodic_split_tolerance", "periodic_split_tolerance_relative", "" // mark of end
103       };
104   
105   int i = 0;
106   while (intOptionNames[i][0])
107     _option2value[intOptionNames[i++]].clear();
108   
109   i = 0;
110   while (preCADintOptionNames[i][0])
111     _preCADoption2value[preCADintOptionNames[i++]].clear();
112
113   i = 0;
114   while (doubleOptionNames[i][0]) {
115     _doubleOptions.insert(doubleOptionNames[i]);
116     _option2value[doubleOptionNames[i++]].clear();
117   }
118   i = 0;
119   while (preCADdoubleOptionNames[i][0]) {
120     _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
121     _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
122   }
123   i = 0;
124   while (charOptionNames[i][0]) {
125     _charOptions.insert(charOptionNames[i]);
126     _option2value[charOptionNames[i++]].clear();
127   }
128   
129
130       
131   _sizeMap.clear();
132   _attractors.clear();
133   _faceEntryEnfVertexListMap.clear();
134   _enfVertexList.clear();
135   _faceEntryCoordsListMap.clear();
136   _coordsEnfVertexMap.clear();
137   _faceEntryEnfVertexEntryListMap.clear();
138   _enfVertexEntryEnfVertexMap.clear();
139   _groupNameNodeIDMap.clear();
140
141   /* TODO GROUPS
142    _groupNameEnfVertexListMap.clear();
143    _enfVertexGroupNameMap.clear();
144    */
145 }
146
147 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
148 {
149   MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
150   GEOM::GEOM_Object_var aGeomObj;
151   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
152   SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
153   
154   TopoDS_Shape S = TopoDS_Shape();
155   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
156   SALOMEDS::GenericAttribute_var anAttr;
157
158   if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
159     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
160     CORBA::String_var aVal = anIOR->Value();
161     CORBA::Object_var obj = myStudy->ConvertIORToObject(aVal);
162     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
163   }
164   if ( !aGeomObj->_is_nil() )
165     S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
166   return S;
167 }
168
169 //=============================================================================
170 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
171   if (theTopology != _topology) {
172     _topology = theTopology;
173     NotifySubMeshesHypothesisModification();
174   }
175 }
176
177 //=============================================================================
178 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
179   if (thePhysicalMesh != _physicalMesh) {
180     _physicalMesh = thePhysicalMesh;
181     NotifySubMeshesHypothesisModification();
182   }
183 }
184
185 //=============================================================================
186 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal) {
187   if (theVal != _phySize) {
188     if (theVal == 0) {
189       _phySize = GetPhyMax();
190       MESSAGE("Warning: nul physical size is not allowed");
191     }
192     else
193       _phySize = theVal;
194     NotifySubMeshesHypothesisModification();
195   }
196 }
197
198 //=============================================================================
199 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize) {
200   if (theMinSize != _phyMin) {
201     _phyMin = theMinSize;
202     NotifySubMeshesHypothesisModification();
203   }
204 }
205
206 //=============================================================================
207 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize) {
208   if (theMaxSize != _phyMax) {
209     _phyMax = theMaxSize;
210     NotifySubMeshesHypothesisModification();
211   }
212 }
213
214 //=============================================================================
215 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize) {
216   if (theMinSize != _hgeoMin) {
217     _hgeoMin = theMinSize;
218     NotifySubMeshesHypothesisModification();
219   }
220 }
221
222 //=============================================================================
223 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize) {
224   if (theMaxSize != _hgeoMax) {
225     _hgeoMax = theMaxSize;
226     NotifySubMeshesHypothesisModification();
227   }
228 }
229
230 //=============================================================================
231 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
232   if (theGeometricMesh != _geometricMesh) {
233     _geometricMesh = theGeometricMesh;
234     switch (_geometricMesh) {
235       case DefaultGeom:
236       default:
237         _angleMeshS = GetDefaultAngleMeshS();
238         _gradation = GetDefaultGradation();
239         break;
240     }
241     NotifySubMeshesHypothesisModification();
242   }
243 }
244
245 //=============================================================================
246 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal) {
247   if (theVal != _angleMeshS) {
248     _angleMeshS = theVal;
249     NotifySubMeshesHypothesisModification();
250   }
251 }
252
253 //=============================================================================
254 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal) {
255   if (theVal != _angleMeshC) {
256     _angleMeshC = theVal;
257     NotifySubMeshesHypothesisModification();
258   }
259 }
260
261 //=============================================================================
262 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
263   if (theVal != _gradation) {
264     _gradation = theVal;
265     NotifySubMeshesHypothesisModification();
266   }
267 }
268
269 //=============================================================================
270 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
271   if (theVal != _quadAllowed) {
272     _quadAllowed = theVal;
273     NotifySubMeshesHypothesisModification();
274   }
275 }
276
277 //=============================================================================
278 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal) {
279   if (theVal != _decimesh) {
280     _decimesh = theVal;
281     NotifySubMeshesHypothesisModification();
282   }
283 }
284
285 //=============================================================================
286 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
287   if (theVal != _verb) {
288     _verb = theVal;
289     NotifySubMeshesHypothesisModification();
290   }
291 }
292
293 //=============================================================================
294 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal) {
295   if (theVal != _preCADMergeEdges) {
296     SetTopology(PreCAD);
297     _preCADMergeEdges = theVal;
298     NotifySubMeshesHypothesisModification();
299   }
300 }
301
302 //=============================================================================
303 void BLSURFPlugin_Hypothesis::SetPreCADRemoveNanoEdges(bool theVal) {
304   if (theVal != _preCADRemoveNanoEdges) {
305     SetTopology(PreCAD);
306     _preCADRemoveNanoEdges = theVal;
307     NotifySubMeshesHypothesisModification();
308   }
309 }
310
311 //=============================================================================
312 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal) {
313   if (theVal != _preCADDiscardInput) {
314     SetTopology(PreCAD);
315     _preCADDiscardInput = theVal;
316     NotifySubMeshesHypothesisModification();
317   }
318 }
319
320 //=============================================================================
321 void BLSURFPlugin_Hypothesis::SetPreCADEpsNano(double theVal) {
322   if (theVal != _preCADEpsNano) {
323     SetTopology(PreCAD);
324     _preCADEpsNano = theVal;
325     NotifySubMeshesHypothesisModification();
326   }
327 }
328
329 //=============================================================================
330 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
331 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
332 {
333   _GMFFileName = theFileName;
334 //   _GMFFileMode = isBinary;
335   NotifySubMeshesHypothesisModification();
336 }
337
338 //=============================================================================
339 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
340     throw (std::invalid_argument) {
341   TOptionValues::iterator op_val = _option2value.find(optionName);
342   if (op_val == _option2value.end()) {
343     std::string msg = "Unknown BLSURF option: '" + optionName + "'";
344     throw std::invalid_argument(msg);
345   }
346   if (op_val->second != optionValue) {
347     const char* ptr = optionValue.c_str();
348     // strip white spaces
349     while (ptr[0] == ' ')
350       ptr++;
351     int i = strlen(ptr);
352     while (i != 0 && ptr[i - 1] == ' ')
353       i--;
354     // check value type
355     bool typeOk = true;
356     std::string typeName;
357     if (i == 0) {
358       // empty string
359     } else if (_charOptions.find(optionName) != _charOptions.end()) {
360       // do not check strings
361     } else if (_doubleOptions.find(optionName) != _doubleOptions.end()) {
362       // check if value is double
363       char * endPtr;
364       strtod(ptr, &endPtr);
365       typeOk = (ptr != endPtr);
366       typeName = "real";
367     } else {
368       // check if value is int
369       char * endPtr;
370       strtol(ptr, &endPtr, 10);
371       typeOk = (ptr != endPtr);
372       typeName = "integer";
373     }
374     if (!typeOk) {
375       std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
376       throw std::invalid_argument(msg);
377     }
378     op_val->second = optionValue;
379     NotifySubMeshesHypothesisModification();
380   }
381 }
382
383 //=============================================================================
384 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
385     throw (std::invalid_argument) {
386   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
387   if (op_val == _preCADoption2value.end()) {
388     std::string msg = "Unknown BLSURF option: '" + optionName + "'";
389     throw std::invalid_argument(msg);
390   }
391   if (op_val->second != optionValue) {
392     const char* ptr = optionValue.c_str();
393     // strip white spaces
394     while (ptr[0] == ' ')
395       ptr++;
396     int i = strlen(ptr);
397     while (i != 0 && ptr[i - 1] == ' ')
398       i--;
399     // check value type
400     bool typeOk = true;
401     std::string typeName;
402     if (i == 0) {
403       // empty string
404     } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
405       // check if value is double
406       char * endPtr;
407       strtod(ptr, &endPtr);
408       typeOk = (ptr != endPtr);
409       typeName = "real";
410     } else {
411       // check if value is int
412       char * endPtr;
413       strtol(ptr, &endPtr, 10);
414       typeOk = (ptr != endPtr);
415       typeName = "integer";
416     }
417     if (!typeOk) {
418       std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
419       throw std::invalid_argument(msg);
420     }
421     op_val->second = optionValue;
422     NotifySubMeshesHypothesisModification();
423   }
424 }
425
426 //=============================================================================
427 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName) throw (std::invalid_argument) {
428   TOptionValues::iterator op_val = _option2value.find(optionName);
429   if (op_val == _option2value.end()) {
430     std::string msg = "Unknown BLSURF option: <";
431     msg += optionName + ">";
432     throw std::invalid_argument(msg);
433   }
434   return op_val->second;
435 }
436
437 //=============================================================================
438 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName) throw (std::invalid_argument) {
439   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
440   if (op_val == _preCADoption2value.end()) {
441     std::string msg = "Unknown PRECAD option: <";
442     msg += optionName + ">";
443     throw std::invalid_argument(msg);
444   }
445   return op_val->second;
446 }
447
448 //=============================================================================
449 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName) {
450   TOptionValues::iterator op_val = _option2value.find(optionName);
451   if (op_val != _option2value.end())
452     op_val->second.clear();
453 }
454
455 //=============================================================================
456 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName) {
457   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
458   if (op_val != _preCADoption2value.end())
459     op_val->second.clear();
460 }
461
462 //=======================================================================
463 //function : SetSizeMapEntry
464 //=======================================================================
465 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
466   if (_sizeMap[entry].compare(sizeMap) != 0) {
467     SetPhysicalMesh(SizeMap);
468     _sizeMap[entry] = sizeMap;
469     NotifySubMeshesHypothesisModification();
470   }
471 }
472
473 //=======================================================================
474 //function : GetSizeMapEntry
475 //=======================================================================
476 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
477   TSizeMap::iterator it = _sizeMap.find(entry);
478   if (it != _sizeMap.end())
479     return it->second;
480   else
481     return "No_Such_Entry";
482 }
483
484 /*!
485  * \brief Return the size maps
486  */
487 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
488   return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
489 }
490
491 //=======================================================================
492 //function : SetAttractorEntry
493 //=======================================================================
494 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
495   if (_attractors[entry].compare(attractor) != 0) {
496     SetPhysicalMesh(SizeMap);
497     _attractors[entry] = attractor;
498     NotifySubMeshesHypothesisModification();
499   }
500 }
501
502 //=======================================================================
503 //function : GetAttractorEntry
504 //=======================================================================
505 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
506   TSizeMap::iterator it = _attractors.find(entry);
507   if (it != _attractors.end())
508     return it->second;
509   else
510     return "No_Such_Entry";
511 }
512
513 /*!
514  * \brief Return the attractors
515  */
516 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
517   return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
518 }
519
520 //=======================================================================
521 //function : SetClassAttractorEntry
522 //=======================================================================
523 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
524 {
525   SetPhysicalMesh(SizeMap);
526
527   // The new attractor can't be defined on the same face as another sizemap
528   TSizeMap::iterator it  = _sizeMap.find( entry );
529   if ( it != _sizeMap.end() ) {
530     _sizeMap.erase(it);
531     NotifySubMeshesHypothesisModification();
532   }
533   else {
534     TSizeMap::iterator itAt  = _attractors.find( entry );
535     if ( itAt != _attractors.end() ) {
536       _attractors.erase(itAt);
537       NotifySubMeshesHypothesisModification();
538     }
539   }
540   
541   const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
542   const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
543   bool attExists = (_classAttractors.find(entry) != _classAttractors.end());
544   double u1,u2,v1,v2, diag;
545   
546   if ( !attExists || (attExists && _classAttractors[entry]->GetAttractorEntry().compare(attEntry) != 0)){ 
547     ShapeAnalysis::GetFaceUVBounds(FaceShape,u1,u2,v1,v2);
548 //     diag = sqrt((u2 - u1) * (u2 - u1) + (v2 - v1) * (v2 - v1));  
549     BLSURFPlugin_Attractor* myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 ); // test 0.002 * diag); 
550     myAttractor->BuildMap();
551     myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
552     _classAttractors[entry] = myAttractor;
553     NotifySubMeshesHypothesisModification();
554   }
555   else {
556     _classAttractors[entry]->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
557     if (!_classAttractors[entry]->IsMapBuilt()){
558       _classAttractors[entry]->BuildMap();
559     }
560     NotifySubMeshesHypothesisModification();
561   }
562     
563 }
564
565 //=======================================================================
566 //function : SetConstantSizeOnAdjacentFaces
567 //=======================================================================
568 // TODO uncomment and test (include the needed .hxx)
569 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist  ) {
570 //   TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
571 //   TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
572 //   TopTools_IndexedMapOfShapListOdShape::iterator it;
573 //   for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
574 //       SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
575 //   }
576
577
578
579
580
581
582 //=======================================================================
583 //function : GetClassAttractorEntry
584 //=======================================================================
585 // BLSURFPlugin_Attractor&  BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
586 // {
587 //  TAttractorMap::iterator it  = _classAttractors.find( entry );
588 //  if ( it != _classAttractors.end() )
589 //    return it->second;
590 //  else
591 //    return "No_Such_Entry";
592 // }
593 // 
594   /*!
595    * \brief Return the map of attractor instances
596    */
597 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
598 {
599     return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
600 }
601
602 //=======================================================================
603 //function : ClearEntry
604 //=======================================================================
605 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
606 {
607  TSizeMap::iterator it  = _sizeMap.find( entry );
608  
609  if ( it != _sizeMap.end() ) {
610    _sizeMap.erase(it);
611    NotifySubMeshesHypothesisModification();
612  }
613  else {
614    TSizeMap::iterator itAt  = _attractors.find( entry );
615    if ( itAt != _attractors.end() ) {
616      _attractors.erase(itAt);
617      NotifySubMeshesHypothesisModification();
618    }
619    else {
620      TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
621      if ( it_clAt != _classAttractors.end() ) {
622        _classAttractors.erase(it_clAt);
623        MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
624        NotifySubMeshesHypothesisModification();
625      }
626      else
627        std::cout<<"No_Such_Entry"<<std::endl;
628    }
629  }
630 }
631
632 //=======================================================================
633 //function : ClearSizeMaps
634 //=======================================================================
635 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
636   _sizeMap.clear();
637   _attractors.clear();
638   _classAttractors.clear();
639 }
640
641 // Enable internal enforced vertices on specific face if requested by user
642
643 ////=======================================================================
644 ////function : SetInternalEnforcedVertex
645 ////=======================================================================
646 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
647 //                                                        bool toEnforceInternalVertices,
648 //                                                        TEnfGroupName theGroupName) {
649
650 //  MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
651 //      << toEnforceInternalVertices << ", " << theGroupName << ")");
652   
653 //  TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
654 //  if (it != _faceEntryInternalVerticesList.end()) {
655 //    if (!toEnforceInternalVertices) {
656 //      _faceEntryInternalVerticesList.erase(it);
657 //    }
658 //  }
659 //  else {
660 //    if (toEnforceInternalVertices) {
661 //      _faceEntryInternalVerticesList.insert(theFaceEntry);
662 //    }
663 //  }
664   
665 //  // TODO
666 //  // Take care of groups
667 //}
668
669
670 //=======================================================================
671 //function : SetEnforcedVertex
672 //=======================================================================
673 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
674                                                 TEnfGroupName theGroupName, double x, double y, double z) {
675
676   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
677       << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
678
679   SetPhysicalMesh(SizeMap);
680
681   //  TEnfVertexList::iterator it;
682   bool toNotify = false;
683   bool toCreate = true;
684
685   TEnfVertex *oldEnVertex;
686   TEnfVertex *newEnfVertex = new TEnfVertex();
687   newEnfVertex->name = theVertexName;
688   newEnfVertex->geomEntry = theVertexEntry;
689   newEnfVertex->coords.clear();
690   if (theVertexEntry == "") {
691     newEnfVertex->coords.push_back(x);
692     newEnfVertex->coords.push_back(y);
693     newEnfVertex->coords.push_back(z);
694   }
695   newEnfVertex->grpName = theGroupName;
696   newEnfVertex->faceEntries.clear();
697   newEnfVertex->faceEntries.insert(theFaceEntry);
698   
699   
700   // update _enfVertexList
701   TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
702   if (it != _enfVertexList.end()) {
703     toCreate = false;
704     oldEnVertex = (*it);
705     MESSAGE("Enforced Vertex was found => Update");
706     if (oldEnVertex->name != theVertexName) {
707       MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
708       oldEnVertex->name = theVertexName;
709       toNotify = true;
710     }
711     if (oldEnVertex->grpName != theGroupName) {
712       MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
713       oldEnVertex->grpName = theGroupName;
714       toNotify = true;
715     }
716     TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
717     if (it_faceEntries == oldEnVertex->faceEntries.end()) {
718       MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
719       oldEnVertex->faceEntries.insert(theFaceEntry);
720       _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
721       toNotify = true;
722     }
723     if (toNotify) {
724       // update map coords / enf vertex if needed
725       if (oldEnVertex->coords.size()) {
726         _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
727         _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
728       }
729
730       // update map geom entry / enf vertex if needed
731       if (oldEnVertex->geomEntry != "") {
732         _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
733         _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
734       }
735     }
736   }
737
738 //   //////// CREATE ////////////
739   if (toCreate) {
740     toNotify = true;
741     MESSAGE("Creating new enforced vertex");
742     _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
743     _enfVertexList.insert(newEnfVertex);
744     if (theVertexEntry == "") {
745       _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
746       _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
747     }
748     else {
749       _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
750       _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
751     }
752   }
753
754   if (toNotify)
755     NotifySubMeshesHypothesisModification();
756
757   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
758   return toNotify;
759 }
760
761
762 //=======================================================================
763 //function : GetEnforcedVertices
764 //=======================================================================
765
766 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
767     throw (std::invalid_argument) {
768
769   if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
770     return _faceEntryEnfVertexListMap[theFaceEntry];
771   else
772     return GetDefaultEnfVertexList();
773
774   std::ostringstream msg;
775   msg << "No enforced vertex for face entry " << theFaceEntry;
776   throw std::invalid_argument(msg.str());
777 }
778
779 //=======================================================================
780 //function : GetEnfVertexCoordsList
781 //=======================================================================
782
783 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
784     const TEntry& theFaceEntry) throw (std::invalid_argument) {
785
786   if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
787     return _faceEntryCoordsListMap[theFaceEntry];
788
789   std::ostringstream msg;
790   msg << "No enforced vertex coords for face entry " << theFaceEntry;
791   throw std::invalid_argument(msg.str());
792 }
793
794 //=======================================================================
795 //function : GetEnfVertexEntryList
796 //=======================================================================
797
798 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
799     throw (std::invalid_argument) {
800
801   if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
802     return _faceEntryEnfVertexEntryListMap[theFaceEntry];
803
804   std::ostringstream msg;
805   msg << "No enforced vertex entry for face entry " << theFaceEntry;
806   throw std::invalid_argument(msg.str());
807 }
808
809 //=======================================================================
810 //function : GetEnfVertex(TEnfVertexCoords coords)
811 //=======================================================================
812
813 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
814     throw (std::invalid_argument) {
815
816   if (_coordsEnfVertexMap.count(coords) > 0)
817     return _coordsEnfVertexMap[coords];
818
819   std::ostringstream msg;
820   msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
821   throw std::invalid_argument(msg.str());
822 }
823
824 //=======================================================================
825 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
826 //=======================================================================
827
828 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
829     throw (std::invalid_argument) {
830
831   if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
832     return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
833
834   std::ostringstream msg;
835   msg << "No enforced vertex with entry " << theEnfVertexEntry;
836   throw std::invalid_argument(msg.str());
837 }
838
839 //Enable internal enforced vertices on specific face if requested by user
840 ////=======================================================================
841 ////function : GetInternalEnforcedVertex
842 ////=======================================================================
843
844 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
845 //{
846 //  if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
847 //    return true;
848 //  return false;
849 //}
850
851 //=======================================================================
852 //function : ClearEnforcedVertex
853 //=======================================================================
854
855 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
856     const TEntry& theVertexEntry) throw (std::invalid_argument) {
857
858   bool toNotify = false;
859   std::ostringstream msg;
860   TEnfVertex *oldEnfVertex;
861   TEnfVertexCoords coords;
862   coords.clear();
863   coords.push_back(x);
864   coords.push_back(y);
865   coords.push_back(z);
866
867   // check that enf vertex with given enf vertex entry exists
868   TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
869   if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
870     // Success
871     MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
872     oldEnfVertex = it_enfVertexEntry->second;
873
874     _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
875
876     TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
877     enfVertexEntryList.erase(theVertexEntry);
878     if (enfVertexEntryList.size() == 0)
879       _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
880     //    TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
881     //    TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
882     //    it_entry_entry->second.erase(it_entryList);
883     //    if (it_entry_entry->second.size() == 0)
884     //      _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
885   } else {
886     // Fail
887     MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
888     msg << "No enforced vertex with geom entry " << theVertexEntry;
889     // check that enf vertex with given coords exists
890     TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
891     if (it_coords_enf != _coordsEnfVertexMap.end()) {
892       // Success
893       MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
894       oldEnfVertex = it_coords_enf->second;
895
896       _coordsEnfVertexMap.erase(it_coords_enf);
897
898       TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
899       enfVertexCoordsList.erase(coords);
900       if (enfVertexCoordsList.size() == 0)
901         _faceEntryCoordsListMap.erase(theFaceEntry);
902       //      TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
903       //      TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
904       //      it_entry_coords->second.erase(it_coordsList);
905       //      if (it_entry_coords->second.size() == 0)
906       //        _faceEntryCoordsListMap.erase(it_entry_coords);
907     } else {
908       // Fail
909       MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
910       msg << std::endl;
911       msg << "No enforced vertex at " << x << ", " << y << ", " << z;
912       throw std::invalid_argument(msg.str());
913     }
914   }
915
916   MESSAGE("Remove enf vertex from _enfVertexList");
917
918   // update _enfVertexList
919   TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
920   if (it != _enfVertexList.end()) {
921     (*it)->faceEntries.erase(theFaceEntry);
922     if ((*it)->faceEntries.size() == 0){
923       _enfVertexList.erase(it);
924       toNotify = true;
925     }
926     MESSAGE("Done");
927   }
928
929   // update _faceEntryEnfVertexListMap
930   TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
931   currentEnfVertexList.erase(oldEnfVertex);
932
933   if (currentEnfVertexList.size() == 0) {
934     MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
935     _faceEntryEnfVertexListMap.erase(theFaceEntry);
936     MESSAGE("Done");
937   }
938
939   if (toNotify)
940     NotifySubMeshesHypothesisModification();
941
942   return toNotify;
943 }
944
945 //=======================================================================
946 //function : ClearEnforcedVertices
947 //=======================================================================
948
949 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
950
951   bool toNotify = false;
952   TEnfVertex *oldEnfVertex;
953
954   TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
955   if (it_entry_coords != _faceEntryCoordsListMap.end()) {
956     toNotify = true;
957     TEnfVertexCoordsList coordsList = it_entry_coords->second;
958     TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
959     for (; it_coordsList != coordsList.end(); ++it_coordsList) {
960       TEnfVertexCoords coords = (*it_coordsList);
961       oldEnfVertex = _coordsEnfVertexMap[coords];
962       _coordsEnfVertexMap.erase(coords);
963       // update _enfVertexList
964       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
965       if (it != _enfVertexList.end()) {
966         (*it)->faceEntries.erase(theFaceEntry);
967         if ((*it)->faceEntries.size() == 0){
968           _enfVertexList.erase(it);
969           toNotify = true;
970         }
971         MESSAGE("Done");
972       }
973     }
974     _faceEntryCoordsListMap.erase(it_entry_coords);
975     _faceEntryEnfVertexListMap.erase(theFaceEntry);
976   }
977
978   TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
979   if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
980     toNotify = true;
981     TEntryList enfVertexEntryList = it_entry_entry->second;
982     TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
983     for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
984       TEntry enfVertexEntry = (*it_enfVertexEntryList);
985       oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
986       _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
987       // update _enfVertexList
988       TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
989       if (it != _enfVertexList.end()) {
990         (*it)->faceEntries.erase(theFaceEntry);
991         if ((*it)->faceEntries.size() == 0){
992           _enfVertexList.erase(it);
993           toNotify = true;
994         }
995         MESSAGE("Done");
996       }
997     }
998     _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
999     _faceEntryEnfVertexListMap.erase(theFaceEntry);
1000   }
1001
1002   if (toNotify)
1003     NotifySubMeshesHypothesisModification();
1004
1005   return toNotify;
1006   //  std::ostringstream msg;
1007   //  msg << "No enforced vertex for " << theFaceEntry;
1008   //  throw std::invalid_argument(msg.str());
1009 }
1010
1011 //=======================================================================
1012 //function : ClearAllEnforcedVertices
1013 //=======================================================================
1014 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1015   _faceEntryEnfVertexListMap.clear();
1016   _enfVertexList.clear();
1017   _faceEntryCoordsListMap.clear();
1018   _coordsEnfVertexMap.clear();
1019   _faceEntryEnfVertexEntryListMap.clear();
1020   _enfVertexEntryEnfVertexMap.clear();
1021 //  Enable internal enforced vertices on specific face if requested by user
1022 //  _faceEntryInternalVerticesList.clear();
1023   NotifySubMeshesHypothesisModification();
1024 }
1025
1026 //================================================================================
1027 /*!
1028  * \brief Return the enforced vertices
1029  */
1030 //================================================================================
1031
1032
1033 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1034     const BLSURFPlugin_Hypothesis* hyp) {
1035   return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1036 }
1037
1038 //Enable internal enforced vertices on specific face if requested by user
1039 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1040 //    const BLSURFPlugin_Hypothesis* hyp) {
1041 //  return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1042 //}
1043
1044 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1045 {
1046   return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1047 }
1048
1049 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1050 {
1051   return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1052 }
1053
1054 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1055     const BLSURFPlugin_Hypothesis* hyp) {
1056   return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1057 }
1058
1059 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1060     const BLSURFPlugin_Hypothesis* hyp) {
1061   return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1062 }
1063
1064 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1065     const BLSURFPlugin_Hypothesis* hyp) {
1066   return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1067 }
1068
1069 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1070     const BLSURFPlugin_Hypothesis* hyp) {
1071   return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1072 }
1073
1074 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1075     const BLSURFPlugin_Hypothesis* hyp) {
1076   return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1077 }
1078
1079 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1080 {
1081   TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1082   if (it != _groupNameNodeIDMap.end()) {
1083     return it->second;
1084   }
1085   std::ostringstream msg;
1086   msg << "No group " << theGroupName;
1087   throw std::invalid_argument(msg.str());
1088 }
1089
1090 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1091 {
1092   _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1093 }
1094
1095 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1096 {
1097   TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1098   if (it != _groupNameNodeIDMap.end()) {
1099     std::set<int>::iterator IDit = it->second.find(theNodeID);
1100     if (IDit != it->second.end())
1101       it->second.erase(IDit);
1102     std::ostringstream msg;
1103     msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1104     throw std::invalid_argument(msg.str());
1105   }
1106   std::ostringstream msg;
1107   msg << "No group " << theGroupName;
1108   throw std::invalid_argument(msg.str());
1109 }
1110
1111
1112 //=============================================================================
1113 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1114   if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1115     _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1116     if (toEnforceInternalVertices)
1117       SetPhysicalMesh(SizeMap);
1118     NotifySubMeshesHypothesisModification();
1119   }
1120 }
1121
1122
1123 //=============================================================================
1124 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1125   if (string(theGroupName) != string(_enforcedInternalVerticesAllFacesGroup)) {
1126     _enforcedInternalVerticesAllFacesGroup = theGroupName;
1127     NotifySubMeshesHypothesisModification();
1128   }
1129 }
1130
1131 //=============================================================================
1132 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1133   save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1134       << _angleMeshS << " " << _gradation << " " << (int) _quadAllowed << " " << (int) _decimesh;
1135   save << " " << _phyMin << " " << _phyMax << " " << _angleMeshC << " " << _hgeoMin << " " << _hgeoMax << " " << _verb;
1136   save << " " << (int) _preCADMergeEdges << " " << (int) _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1137   save << " " << (int) _enforcedInternalVerticesAllFaces;
1138
1139   TOptionValues::iterator op_val = _option2value.begin();
1140   if (op_val != _option2value.end()) {
1141     save << " " << "__OPTIONS_BEGIN__";
1142     for (; op_val != _option2value.end(); ++op_val) {
1143       if (!op_val->second.empty())
1144         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1145     }
1146     save << " " << "__OPTIONS_END__";
1147   }
1148   
1149   op_val = _preCADoption2value.begin();
1150   if (op_val != _preCADoption2value.end()) {
1151     save << " " << "__PRECAD_OPTIONS_BEGIN__";
1152     for (; op_val != _preCADoption2value.end(); ++op_val) {
1153       if (!op_val->second.empty())
1154         save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1155     }
1156     save << " " << "__PRECAD_OPTIONS_END__";
1157   }
1158
1159   TSizeMap::iterator it_sm = _sizeMap.begin();
1160   if (it_sm != _sizeMap.end()) {
1161     save << " " << "__SIZEMAP_BEGIN__";
1162     for (; it_sm != _sizeMap.end(); ++it_sm) {
1163       save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1164     }
1165     save << " " << "__SIZEMAP_END__";
1166   }
1167
1168   TSizeMap::iterator it_at = _attractors.begin();
1169   if (it_at != _attractors.end()) {
1170     save << " " << "__ATTRACTORS_BEGIN__";
1171     for (; it_at != _attractors.end(); ++it_at) {
1172       save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1173     }
1174     save << " " << "__ATTRACTORS_END__";
1175   }
1176   
1177   TAttractorMap::iterator it_At = _classAttractors.begin();
1178   if (it_At != _classAttractors.end()) {
1179     std::ostringstream test;
1180     save << " " << "__NEW_ATTRACTORS_BEGIN__";
1181     test << " " << "__NEW_ATTRACTORS_BEGIN__";
1182     for (; it_At != _classAttractors.end(); ++it_At) {
1183       std::vector<double> attParams;
1184       attParams   = it_At->second->GetParameters();
1185 //       double step = it_At->second->GetStep();
1186       save << " " << it_At->first;
1187       save << " " << it_At->second->GetAttractorEntry();
1188       save << " " << attParams[0]  << " " <<  attParams[1] << " " <<  attParams[2] << " " <<  attParams[3];
1189 //       save << " " << step;
1190       test << " " << it_At->first;
1191       test << " " << it_At->second->GetAttractorEntry();
1192       test << " " << attParams[0]  << " " <<  attParams[1] << " " <<  attParams[2] << " " <<  attParams[3];
1193 //       test << " " << step;
1194     }
1195     save << " " << "__NEW_ATTRACTORS_END__";
1196     test << " " << "__NEW_ATTRACTORS_END__";
1197     MESSAGE(" Attractor hypothesis saved as "<<test.str())
1198   }
1199
1200   TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1201   if (it_enf != _enfVertexList.end()) {
1202     save << " " << "__ENFORCED_VERTICES_BEGIN__";
1203     for (; it_enf != _enfVertexList.end(); ++it_enf) {
1204       TEnfVertex *enfVertex = (*it_enf);
1205       save << " " << "__BEGIN_VERTEX__";
1206       if (!enfVertex->name.empty()) {
1207         save << " " << "__BEGIN_NAME__";
1208         save << " " << enfVertex->name;
1209         save << " " << "__END_NAME__";
1210       }
1211       if (!enfVertex->geomEntry.empty()) {
1212         save << " " << "__BEGIN_ENTRY__";
1213         save << " " << enfVertex->geomEntry;
1214         save << " " << "__END_ENTRY__";
1215       }
1216       if (!enfVertex->grpName.empty()) {
1217         save << " " << "__BEGIN_GROUP__";
1218         save << " " << enfVertex->grpName;
1219         save << " " << "__END_GROUP__";
1220       }
1221       if (enfVertex->coords.size()) {
1222         save << " " << "__BEGIN_COORDS__";
1223         for (int i=0;i<enfVertex->coords.size();i++)
1224           save << " " << enfVertex->coords[i];
1225         save << " " << "__END_COORDS__";
1226       }
1227       TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1228       bool hasFaces = false;
1229       if (faceEntriesIt != enfVertex->faceEntries.end()) {
1230         hasFaces = true;
1231         save << " " << "__BEGIN_FACELIST__";
1232       }
1233       for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1234         save << " " << (*faceEntriesIt);
1235       if (hasFaces)
1236         save << " " << "__END_FACELIST__";
1237       save << " " << "__END_VERTEX__";
1238     }
1239     save << " " << "__ENFORCED_VERTICES_END__";
1240   }
1241
1242   return save;
1243 }
1244
1245 //=============================================================================
1246 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
1247   bool isOK = true;
1248   int i;
1249   double val;
1250
1251   isOK = (load >> i);
1252   if (isOK)
1253     _topology = (Topology) i;
1254   else
1255     load.clear(std::ios::badbit | load.rdstate());
1256
1257   isOK = (load >> i);
1258   if (isOK)
1259     _physicalMesh = (PhysicalMesh) i;
1260   else
1261     load.clear(std::ios::badbit | load.rdstate());
1262
1263   isOK = (load >> i);
1264   if (isOK)
1265     _geometricMesh = (GeometricMesh) i;
1266   else
1267     load.clear(std::ios::badbit | load.rdstate());
1268
1269   isOK = (load >> val);
1270   if (isOK)
1271     _phySize = val;
1272   else
1273     load.clear(std::ios::badbit | load.rdstate());
1274
1275   isOK = (load >> val);
1276   if (isOK)
1277     _angleMeshS = val;
1278   else
1279     load.clear(std::ios::badbit | load.rdstate());
1280
1281   isOK = (load >> val);
1282   if (isOK)
1283     _gradation = val;
1284   else
1285     load.clear(std::ios::badbit | load.rdstate());
1286
1287   isOK = (load >> i);
1288   if (isOK)
1289     _quadAllowed = (bool) i;
1290   else
1291     load.clear(std::ios::badbit | load.rdstate());
1292
1293   isOK = (load >> i);
1294   if (isOK)
1295     _decimesh = (bool) i;
1296   else
1297     load.clear(std::ios::badbit | load.rdstate());
1298
1299   isOK = (load >> val);
1300   if (isOK)
1301     _phyMin = val;
1302   else
1303     load.clear(std::ios::badbit | load.rdstate());
1304
1305   isOK = (load >> val);
1306   if (isOK)
1307     _phyMax = val;
1308   else
1309     load.clear(std::ios::badbit | load.rdstate());
1310
1311   isOK = (load >> val);
1312   if (isOK)
1313     _angleMeshC = val;
1314   else
1315     load.clear(std::ios::badbit | load.rdstate());
1316
1317   isOK = (load >> val);
1318   if (isOK)
1319     _hgeoMin = val;
1320   else
1321     load.clear(std::ios::badbit | load.rdstate());
1322
1323   isOK = (load >> val);
1324   if (isOK)
1325     _hgeoMax = val;
1326   else
1327     load.clear(std::ios::badbit | load.rdstate());
1328
1329   isOK = (load >> i);
1330   if (isOK)
1331     _verb = i;
1332   else
1333     load.clear(std::ios::badbit | load.rdstate());
1334
1335   isOK = (load >> i);
1336   if (isOK)
1337     _preCADMergeEdges = (bool) i;
1338   else
1339     load.clear(std::ios::badbit | load.rdstate());
1340
1341   isOK = (load >> i);
1342   if (isOK)
1343     _preCADRemoveNanoEdges = (bool) i;
1344   else
1345     load.clear(std::ios::badbit | load.rdstate());
1346
1347   isOK = (load >> i);
1348   if (isOK)
1349     _preCADDiscardInput = (bool) i;
1350   else
1351     load.clear(std::ios::badbit | load.rdstate());
1352
1353   isOK = (load >> val);
1354   if (isOK)
1355     _preCADEpsNano = val;
1356   else
1357     load.clear(std::ios::badbit | load.rdstate());
1358
1359   isOK = (load >> i);
1360   if (isOK)
1361     _enforcedInternalVerticesAllFaces = (bool) i;
1362   else
1363     load.clear(std::ios::badbit | load.rdstate());
1364
1365   std::string option_or_sm;
1366   bool hasOptions = false;
1367   bool hasPreCADOptions = false;
1368   bool hasSizeMap = false;
1369   bool hasAttractor = false;
1370   bool hasNewAttractor = false;
1371   bool hasEnforcedVertex = false;
1372
1373   isOK = (load >> option_or_sm);
1374   if (isOK)
1375     if (option_or_sm == "__OPTIONS_BEGIN__")
1376       hasOptions = true;
1377     else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1378       hasPreCADOptions = true;
1379     else if (option_or_sm == "__SIZEMAP_BEGIN__")
1380       hasSizeMap = true;
1381     else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1382       hasAttractor = true;
1383     else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1384       hasNewAttractor = true;
1385     else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1386       hasEnforcedVertex = true;
1387
1388   std::string optName, optValue;
1389   while (isOK && hasOptions) {
1390     isOK = (load >> optName);
1391     if (isOK) {
1392       if (optName == "__OPTIONS_END__")
1393         break;
1394       isOK = (load >> optValue);
1395     }
1396     if (isOK) {
1397       std::string & value = _option2value[optName];
1398       value = optValue;
1399       int len = value.size();
1400       // continue reading until "%#" encountered
1401       while (value[len - 1] != '#' || value[len - 2] != '%') {
1402         isOK = (load >> optValue);
1403         if (isOK) {
1404           value += " ";
1405           value += optValue;
1406           len = value.size();
1407         } else {
1408           break;
1409         }
1410       }
1411       value[len - 2] = '\0'; //cut off "%#"
1412     }
1413   }
1414
1415   if (hasOptions) {
1416     isOK = (load >> option_or_sm);
1417     if (isOK)
1418       if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1419         hasPreCADOptions = true;
1420       else if (option_or_sm == "__SIZEMAP_BEGIN__")
1421         hasSizeMap = true;
1422       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1423         hasAttractor = true;
1424       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1425         hasNewAttractor = true;
1426       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1427         hasEnforcedVertex = true;
1428   }
1429
1430   while (isOK && hasPreCADOptions) {
1431     isOK = (load >> optName);
1432     if (isOK) {
1433       if (optName == "__PRECAD_OPTIONS_END__")
1434         break;
1435       isOK = (load >> optValue);
1436     }
1437     if (isOK) {
1438       std::string & value = _preCADoption2value[optName];
1439       value = optValue;
1440       int len = value.size();
1441       // continue reading until "%#" encountered
1442       while (value[len - 1] != '#' || value[len - 2] != '%') {
1443         isOK = (load >> optValue);
1444         if (isOK) {
1445           value += " ";
1446           value += optValue;
1447           len = value.size();
1448         } else {
1449           break;
1450         }
1451       }
1452       value[len - 2] = '\0'; //cut off "%#"
1453     }
1454   }
1455
1456   if (hasPreCADOptions) {
1457     isOK = (load >> option_or_sm);
1458     if (isOK)
1459       if (option_or_sm == "__SIZEMAP_BEGIN__")
1460         hasSizeMap = true;
1461       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1462         hasAttractor = true;
1463       else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1464         hasNewAttractor = true;
1465       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1466         hasEnforcedVertex = true;
1467   }
1468   
1469   std::string smEntry, smValue;
1470   while (isOK && hasSizeMap) {
1471     isOK = (load >> smEntry);
1472     if (isOK) {
1473       if (smEntry == "__SIZEMAP_END__")
1474         break;
1475       isOK = (load >> smValue);
1476     }
1477     if (isOK) {
1478       std::string & value2 = _sizeMap[smEntry];
1479       value2 = smValue;
1480       int len2 = value2.size();
1481       // continue reading until "%#" encountered
1482       while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
1483         isOK = (load >> smValue);
1484         if (isOK) {
1485           value2 += " ";
1486           value2 += smValue;
1487           len2 = value2.size();
1488         } else {
1489           break;
1490         }
1491       }
1492       value2[len2 - 2] = '\0'; //cut off "%#"
1493     }
1494   }
1495
1496   if (hasSizeMap) {
1497     isOK = (load >> option_or_sm);
1498     if (isOK)
1499       if (option_or_sm == "__ATTRACTORS_BEGIN__")
1500         hasAttractor = true;
1501       if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1502         hasNewAttractor = true;
1503       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1504         hasEnforcedVertex = true;
1505   }
1506
1507   std::string atEntry, atValue;
1508   while (isOK && hasAttractor) {
1509     isOK = (load >> atEntry);
1510     if (isOK) {
1511       if (atEntry == "__ATTRACTORS_END__")
1512         break;
1513       isOK = (load >> atValue);
1514     }
1515     if (isOK) {
1516       std::string & value3 = _attractors[atEntry];
1517       value3 = atValue;
1518       int len3 = value3.size();
1519       // continue reading until "%#" encountered
1520       while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
1521         isOK = (load >> atValue);
1522         if (isOK) {
1523           value3 += " ";
1524           value3 += atValue;
1525           len3 = value3.size();
1526         } else {
1527           break;
1528         }
1529       }
1530       value3[len3 - 2] = '\0'; //cut off "%#"
1531     }
1532   }
1533
1534   if (hasAttractor) {
1535     isOK = (load >> option_or_sm);
1536     if (isOK)
1537       if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1538         hasNewAttractor = true;
1539       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1540         hasEnforcedVertex = true;
1541   }
1542
1543   std::string newAtFaceEntry, atTestString;
1544   std::string newAtShapeEntry;
1545   double attParams[4];
1546   double step;
1547   while (isOK && hasNewAttractor) {
1548     std::cout<<"Load new attractor"<<std::endl;
1549     isOK = (load >> newAtFaceEntry);
1550     if (isOK) {
1551       if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
1552         break;
1553       isOK = (load >> newAtShapeEntry);
1554       if (!isOK)
1555     break;
1556       isOK = (load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
1557     }
1558     if (isOK) {
1559       MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
1560       const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
1561       const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
1562       BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
1563       attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
1564       attractor->BuildMap();                     
1565       _classAttractors[newAtFaceEntry]=attractor;
1566     }
1567   }
1568   
1569   
1570   if (hasNewAttractor) {
1571     isOK = (load >> option_or_sm);
1572     if (isOK)
1573       if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1574         hasEnforcedVertex = true;
1575   }
1576
1577
1578 // 
1579 // Here is a example of the saved stream:
1580 // __ENFORCED_VERTICES_BEGIN__ 
1581 // __BEGIN_VERTEX__  => no name, no entry
1582 // __BEGIN_GROUP__ mon groupe __END_GROUP__
1583 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__ 
1584 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__ 
1585 // __END_VERTEX__ 
1586 // __BEGIN_VERTEX__ => no coords
1587 // __BEGIN_NAME__ mes points __END_NAME__ 
1588 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
1589 // __BEGIN_GROUP__ mon groupe __END_GROUP__
1590 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
1591 // __END_VERTEX__ 
1592 // __ENFORCED_VERTICES_END__
1593 // 
1594
1595   std::string enfSeparator;
1596   std::string enfName;
1597   std::string enfGeomEntry;
1598   std::string enfGroup;
1599   TEntryList enfFaceEntryList;
1600   double enfCoords[3];
1601   bool hasCoords = false;
1602   
1603   _faceEntryEnfVertexListMap.clear();
1604   _enfVertexList.clear();
1605   _faceEntryCoordsListMap.clear();
1606   _coordsEnfVertexMap.clear();
1607   _faceEntryEnfVertexEntryListMap.clear();
1608   _enfVertexEntryEnfVertexMap.clear();
1609   
1610   
1611   while (isOK && hasEnforcedVertex) {
1612     isOK = (load >> enfSeparator); // __BEGIN_VERTEX__
1613     TEnfVertex *enfVertex = new TEnfVertex();
1614 //     MESSAGE("enfSeparator: " <<enfSeparator);
1615     if (enfSeparator == "__ENFORCED_VERTICES_END__")
1616       break; // __ENFORCED_VERTICES_END__
1617     if (enfSeparator != "__BEGIN_VERTEX__")
1618       throw std::exception();
1619     
1620     while (isOK) {
1621       isOK = (load >> enfSeparator);
1622       MESSAGE("enfSeparator: " <<enfSeparator);
1623       if (enfSeparator == "__END_VERTEX__") {
1624         
1625         enfVertex->name = enfName;
1626         enfVertex->geomEntry = enfGeomEntry;
1627         enfVertex->grpName = enfGroup;
1628         enfVertex->coords.clear();
1629         if (hasCoords)
1630           enfVertex->coords.assign(enfCoords,enfCoords+3);
1631         enfVertex->faceEntries = enfFaceEntryList;
1632         
1633         _enfVertexList.insert(enfVertex);
1634         
1635         if (enfVertex->coords.size()) {
1636           _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1637           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
1638             _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
1639             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
1640           }
1641         }
1642         if (!enfVertex->geomEntry.empty()) {
1643           _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1644           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
1645             _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
1646             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
1647           }
1648         }
1649         
1650         enfName.clear();
1651         enfGeomEntry.clear();
1652         enfGroup.clear();
1653         enfFaceEntryList.clear();
1654         hasCoords = false;
1655         break; // __END_VERTEX__
1656       }
1657         
1658       if (enfSeparator == "__BEGIN_NAME__") {  // __BEGIN_NAME__
1659         while (isOK && (enfSeparator != "__END_NAME__")) {
1660           isOK = (load >> enfSeparator);
1661           if (enfSeparator != "__END_NAME__") {
1662             if (!enfName.empty())
1663               enfName += " ";
1664             enfName += enfSeparator;
1665           }
1666         }
1667         MESSAGE("enfName: " <<enfName);
1668       }
1669         
1670       if (enfSeparator == "__BEGIN_ENTRY__") {  // __BEGIN_ENTRY__
1671         isOK = (load >> enfGeomEntry);
1672         isOK = (load >> enfSeparator); // __END_ENTRY__
1673         if (enfSeparator != "__END_ENTRY__")
1674           throw std::exception();
1675         MESSAGE("enfGeomEntry: " <<enfGeomEntry);
1676       }
1677         
1678       if (enfSeparator == "__BEGIN_GROUP__") {  // __BEGIN_GROUP__
1679         while (isOK && (enfSeparator != "__END_GROUP__")) {
1680           isOK = (load >> enfSeparator);
1681           if (enfSeparator != "__END_GROUP__") {
1682             if (!enfGroup.empty())
1683               enfGroup += " ";
1684             enfGroup += enfSeparator;
1685           }
1686         }
1687         MESSAGE("enfGroup: " <<enfGroup);
1688       }
1689         
1690       if (enfSeparator == "__BEGIN_COORDS__") {  // __BEGIN_COORDS__
1691         hasCoords = true;
1692         isOK = (load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
1693         isOK = (load >> enfSeparator); // __END_COORDS__
1694         if (enfSeparator != "__END_COORDS__")
1695           throw std::exception();
1696         MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
1697       } 
1698         
1699       if (enfSeparator == "__BEGIN_FACELIST__") {  // __BEGIN_FACELIST__
1700         while (isOK && (enfSeparator != "__END_FACELIST__")) {
1701           isOK = (load >> enfSeparator);
1702           if (enfSeparator != "__END_FACELIST__") {
1703             enfFaceEntryList.insert(enfSeparator);
1704             MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
1705           }
1706         }
1707       } 
1708     }
1709   }
1710
1711   return load;
1712 }
1713
1714 //=============================================================================
1715 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
1716   return hyp.SaveTo(save);
1717 }
1718
1719 //=============================================================================
1720 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
1721   return hyp.LoadFrom(load);
1722 }
1723
1724 //================================================================================
1725 /*!
1726  * \brief Does nothing
1727  */
1728 //================================================================================
1729
1730 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
1731   return false;
1732 }
1733
1734 //=============================================================================
1735 /*!
1736  * \brief Initialize my parameter values by default parameters.
1737  *  \retval bool - true if parameter values have been successfully defined
1738  */
1739 //=============================================================================
1740
1741 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
1742   return bool(_phySize = dflts._elemLength);
1743 }
1744
1745 //=============================================================================
1746 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology() {
1747   return FromCAD;
1748 }
1749
1750 //=============================================================================
1751 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh() {
1752   return PhysicalUserDefined;
1753 }
1754
1755 //=============================================================================
1756 double BLSURFPlugin_Hypothesis::GetDefaultPhySize() {
1757   return 10;
1758 }
1759
1760 //======================================================================
1761 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize() {
1762   return undefinedDouble(); // 1e+4;
1763 }
1764
1765 //======================================================================
1766 double BLSURFPlugin_Hypothesis::GetDefaultMinSize() {
1767   return undefinedDouble(); //1e-4;
1768 }
1769
1770 //======================================================================
1771 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh() {
1772   return DefaultGeom;
1773 }
1774
1775 //=============================================================================
1776 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS() {
1777   return 8;
1778 }
1779
1780 //=============================================================================
1781 double BLSURFPlugin_Hypothesis::GetDefaultGradation() {
1782   return 1.1;
1783 }
1784
1785 //=============================================================================
1786 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed() {
1787   return false;
1788 }
1789
1790 //=============================================================================
1791 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh() {
1792   return false;
1793 }
1794
1795 //======================================================================
1796 double BLSURFPlugin_Hypothesis::GetDefaultPreCADEpsNano() {
1797   return undefinedDouble(); //1e-4;
1798 }
1799
1800 //======================================================================
1801 std::string BLSURFPlugin_Hypothesis::GetDefaultGMFFile() {
1802   return "";
1803 }
1804
1805 //=============================================================================
1806 bool BLSURFPlugin_Hypothesis::GetDefaultInternalEnforcedVertex() {
1807   return false;
1808 }
1809