Salome HOME
- Replace QLineEdit by SMESH_SpinBox
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
1 //  Copyright (C) 2007-2010  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 developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
25 // ---
26 //
27 #include "BLSURFPlugin_Hypothesis.hxx"
28 #include <utilities.h>
29 #include <cstring>
30 #include <iostream>
31 #include <sstream>
32
33 //=============================================================================
34 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
35                                                   SMESH_Gen * gen)
36   : SMESH_Hypothesis(hypId, studyId, gen),
37     _topology(GetDefaultTopology()),
38     _physicalMesh(GetDefaultPhysicalMesh()),
39     _phySize(GetDefaultPhySize()),
40     _phyMax(GetDefaultMaxSize()),
41     _phyMin(GetDefaultMinSize()),
42     _hgeoMax(GetDefaultMaxSize()),
43     _hgeoMin(GetDefaultMinSize()),
44     _geometricMesh(GetDefaultGeometricMesh()),
45     _angleMeshS(GetDefaultAngleMeshS()),
46     _angleMeshC(GetDefaultAngleMeshC()),
47     _gradation(GetDefaultGradation()),
48     _quadAllowed(GetDefaultQuadAllowed()),
49     _decimesh(GetDefaultDecimesh()),
50     _verb( GetDefaultVerbosity() ),
51     _sizeMap(GetDefaultSizeMap()),
52     _attractors(GetDefaultSizeMap()),
53     _enfVertexList(GetDefaultEnfVertexList()),
54     _entryEnfVertexListMap(GetDefaultEntryEnfVertexListMap())
55     /* TODO GROUPS
56     _groupNameEnfVertexListMap(GetDefaultGroupNameEnfVertexListMap()),
57     _enfVertexGroupNameMap(GetDefaultEnfVertexGroupNameMap())
58     */
59 {
60   _name = "BLSURF_Parameters";
61   _param_algo_dim = 2;
62
63   // to desable writing boundaries
64   //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
65
66
67   const char* intOptionNames[] = {
68     "addsurf_ivertex",
69     "background",
70     "CheckAdjacentEdges",
71     "CheckCloseEdges",
72     "CheckWellDefined",
73     "coiter",
74     "communication",
75     "decim",
76     "export_flag",
77     "file_h",
78     "frontal",
79     "gridnu",
80     "gridnv",
81     "hinterpol_flag",
82     "hmean_flag",
83     "intermedfile",
84     "memory",
85     "normals",
86     "optim",
87     "pardom_flag",
88     "pinch",
89     "refs",
90     "rigid",
91     "surforient",
92     "tconf",
93     "topo_collapse",
94     "" // mark of end
95   };
96   const char* doubleOptionNames[] = {
97     "addsurf_angle",
98     "addsurf_R",
99     "addsurf_H",
100     "addsurf_FG",
101     "addsurf_r",
102     "addsurf_PA",
103     "angle_compcurv",
104     "angle_ridge",
105     "CoefRectangle",
106     "eps_collapse",
107     "eps_ends",
108     "eps_pardom",
109     "LSS",
110     "topo_eps1",
111     "topo_eps2",
112     "" // mark of end
113   };
114   const char* charOptionNames[] = {
115     "export_format",
116     "export_option",
117     "import_option",
118     "prefix",
119     "" // mark of end
120   };
121
122   int i = 0;
123   while ( intOptionNames[i][0] )
124     _option2value[ intOptionNames[i++] ].clear();
125
126   i = 0;
127   while ( doubleOptionNames[i][0] ) {
128     _doubleOptions.insert( doubleOptionNames[i] );
129     _option2value[ doubleOptionNames[i++] ].clear();
130   }
131   i = 0;
132   while ( charOptionNames[i][0] ) {
133     _charOptions.insert( charOptionNames[i] );
134     _option2value[ charOptionNames[i++] ].clear();
135   }
136
137   _sizeMap.clear();
138   _attractors.clear();
139   _enfVertexList.clear();
140   _entryEnfVertexListMap.clear();
141   /* TODO GROUPS
142   _groupNameEnfVertexListMap.clear();
143   _enfVertexGroupNameMap.clear();
144   */
145 }
146
147 //=============================================================================
148 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
149 {
150   if (theTopology != _topology) {
151     _topology = theTopology;
152     NotifySubMeshesHypothesisModification();
153   }
154 }
155
156 //=============================================================================
157 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
158 {
159   if (thePhysicalMesh != _physicalMesh) {
160     _physicalMesh = thePhysicalMesh;
161     switch( _physicalMesh ) {
162       case DefaultSize:
163       default:
164         _phySize = GetDefaultPhySize();
165         _gradation  = GetDefaultGradation();
166         break;
167       }
168     NotifySubMeshesHypothesisModification();
169   }
170 }
171
172 //=============================================================================
173 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
174 {
175   if (theVal != _phySize) {
176     _phySize = theVal;
177     NotifySubMeshesHypothesisModification();
178   }
179 }
180
181 //=============================================================================
182 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
183 {
184   if (theMinSize != _phyMin) {
185     _phyMin = theMinSize;
186     NotifySubMeshesHypothesisModification();
187   }
188 }
189
190 //=============================================================================
191 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
192 {
193   if (theMaxSize != _phyMax) {
194     _phyMax = theMaxSize;
195     NotifySubMeshesHypothesisModification();
196   }
197 }
198
199
200 //=============================================================================
201 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
202 {
203   if (theMinSize != _hgeoMin) {
204     _hgeoMin = theMinSize;
205     NotifySubMeshesHypothesisModification();
206   }
207 }
208
209 //=============================================================================
210 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
211 {
212   if (theMaxSize != _hgeoMax) {
213     _hgeoMax = theMaxSize;
214     NotifySubMeshesHypothesisModification();
215   }
216 }
217
218 //=============================================================================
219 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
220 {
221   if (theGeometricMesh != _geometricMesh) {
222     _geometricMesh = theGeometricMesh;
223     switch( _geometricMesh ) {
224       case DefaultGeom:
225       default:
226         _angleMeshS = GetDefaultAngleMeshS();
227         _gradation  = GetDefaultGradation();
228         break;
229       }
230     NotifySubMeshesHypothesisModification();
231   }
232 }
233
234 //=============================================================================
235 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
236 {
237   if (theVal != _angleMeshS) {
238     _angleMeshS = theVal;
239     NotifySubMeshesHypothesisModification();
240   }
241 }
242
243 //=============================================================================
244 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
245 {
246   if (theVal != _angleMeshC) {
247     _angleMeshC = theVal;
248     NotifySubMeshesHypothesisModification();
249   }
250 }
251
252 //=============================================================================
253 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
254 {
255   if (theVal != _gradation) {
256     _gradation = theVal;
257     NotifySubMeshesHypothesisModification();
258   }
259 }
260
261 //=============================================================================
262 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
263 {
264   if (theVal != _quadAllowed) {
265     _quadAllowed = theVal;
266     NotifySubMeshesHypothesisModification();
267   }
268 }
269
270 //=============================================================================
271 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
272 {
273   if (theVal != _decimesh) {
274     _decimesh = theVal;
275     NotifySubMeshesHypothesisModification();
276   }
277 }
278
279 //=============================================================================
280 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
281 {
282   if (theVal != _verb) {
283     _verb = theVal;
284     NotifySubMeshesHypothesisModification();
285   }
286 }
287 //=============================================================================
288 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
289                                              const std::string& optionValue)
290   throw (std::invalid_argument)
291 {
292   TOptionValues::iterator op_val = _option2value.find( optionName );
293   if ( op_val == _option2value.end() ) {
294     std::string msg = "Unknown BLSURF option: '" + optionName + "'";
295     throw std::invalid_argument(msg);
296   }
297   if ( op_val->second != optionValue ) {
298     const char* ptr = optionValue.c_str();
299     // strip white spaces
300     while ( ptr[0] == ' ' )
301       ptr++;
302     int i = strlen( ptr );
303     while ( i != 0 && ptr[i-1] == ' ')
304       i--;
305     // check value type
306     bool typeOk = true;
307     std::string typeName;
308     if ( i == 0 ) {
309       // empty string
310     }
311     else if ( _charOptions.find( optionName ) != _charOptions.end() ) {
312       // do not check strings
313     }
314     else if ( _doubleOptions.find( optionName ) != _doubleOptions.end() ) {
315       // check if value is double
316       char * endPtr;
317       strtod(ptr, &endPtr);
318       typeOk = ( ptr != endPtr );
319       typeName = "real";
320     }
321     else {
322       // check if value is int
323       char * endPtr;
324       strtol(ptr, &endPtr,10);
325       typeOk = ( ptr != endPtr );
326       typeName = "integer";
327     }
328     if ( !typeOk ) {
329       std::string msg = "Advanced option '" + optionName + "' = '" + optionValue +
330         "' but must be " + typeName;
331       throw std::invalid_argument(msg);
332     }
333     op_val->second = optionValue;
334     NotifySubMeshesHypothesisModification();
335   }
336 }
337
338 //=============================================================================
339 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName)
340   throw (std::invalid_argument)
341 {
342   TOptionValues::iterator op_val = _option2value.find( optionName );
343   if ( op_val == _option2value.end() ) {
344     std::string msg = "Unknown BLSURF option: <";
345     msg += optionName + ">";
346     throw std::invalid_argument(msg);
347   }
348   return op_val->second;
349 }
350
351 //=============================================================================
352 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
353 {
354   TOptionValues::iterator op_val = _option2value.find( optionName );
355   if ( op_val != _option2value.end() )
356     op_val->second.clear();
357 }
358
359 //=======================================================================
360 //function : SetSizeMapEntry
361 //=======================================================================
362 void  BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry,const std::string& sizeMap)
363 {
364   if (_sizeMap[entry].compare(sizeMap) != 0) {
365     _sizeMap[entry]=sizeMap;
366     NotifySubMeshesHypothesisModification();
367   }
368 }
369
370 //=======================================================================
371 //function : GetSizeMapEntry
372 //=======================================================================
373 std::string  BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry)
374 {
375  TSizeMap::iterator it  = _sizeMap.find( entry );
376  if ( it != _sizeMap.end() )
377    return it->second;
378  else
379    return "No_Such_Entry";
380 }
381
382   /*!
383    * \brief Return the size maps
384    */
385 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp)
386 {
387     return hyp ? hyp->_GetSizeMapEntries():GetDefaultSizeMap();
388 }
389
390 //=======================================================================
391 //function : SetAttractorEntry
392 //=======================================================================
393 void  BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry,const std::string& attractor)
394 {
395   if (_attractors[entry].compare(attractor) != 0) {
396     _attractors[entry]=attractor;
397     NotifySubMeshesHypothesisModification();
398   }
399 }
400
401 //=======================================================================
402 //function : GetAttractorEntry
403 //=======================================================================
404 std::string  BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry)
405 {
406  TSizeMap::iterator it  = _attractors.find( entry );
407  if ( it != _attractors.end() )
408    return it->second;
409  else
410    return "No_Such_Entry";
411 }
412
413   /*!
414    * \brief Return the attractors
415    */
416 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
417 {
418     return hyp ? hyp->_GetAttractorEntries():GetDefaultSizeMap();
419 }
420
421 //=======================================================================
422 //function : ClearEntry
423 //=======================================================================
424 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
425 {
426  TSizeMap::iterator it  = _sizeMap.find( entry );
427  if ( it != _sizeMap.end() ) {
428    _sizeMap.erase(it);
429    NotifySubMeshesHypothesisModification();
430  }
431  else {
432    TSizeMap::iterator itAt  = _attractors.find( entry );
433    if ( itAt != _attractors.end() ) {
434      _attractors.erase(itAt);
435      NotifySubMeshesHypothesisModification();
436    }
437    else
438      std::cout<<"No_Such_Entry"<<std::endl;
439  }
440 }
441
442 //=======================================================================
443 //function : ClearSizeMaps
444 //=======================================================================
445 void BLSURFPlugin_Hypothesis::ClearSizeMaps()
446 {
447   _sizeMap.clear();
448   _attractors.clear();
449 }
450
451
452
453 //=======================================================================
454 //function : SetEnforcedVertex
455 //=======================================================================
456 /* TODO GROUPS
457 void BLSURFPlugin_Hypothesis::SetEnforcedVertex(const TEnfEntry& entry,
458                                                 double x, double y, double z,
459                                                 const TEnfGroupName& groupName)
460 */
461 void BLSURFPlugin_Hypothesis::SetEnforcedVertex(const TEnfEntry& entry,
462                                                 double x, double y, double z)
463 {
464   /* TODO GROUPS
465   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex START - entry: " << entry << " vertex: " << x << " " << y << " " << z << " group name: " << groupName);
466   */
467   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex START - entry: " << entry << " vertex: " << x << " " << y << " " << z);
468   TEnfVertex enfVertex;
469   enfVertex.push_back(x);
470   enfVertex.push_back(y);
471   enfVertex.push_back(z);
472
473   bool toNotify = false;
474   if (_entryEnfVertexListMap.count(entry)>0)
475     if (_entryEnfVertexListMap[entry].count(enfVertex)==0)
476       toNotify = true;
477   else
478     toNotify = true;
479
480   _enfVertexList.insert(enfVertex);
481 //   _entryEnfVertexListMap[entry].insert(enfVertex);
482   TEnfVertexList& entryEnfVertexList = _entryEnfVertexListMap[entry];
483   entryEnfVertexList.insert(enfVertex);
484
485   /* TODO GROUPS
486   bool toNotify2 = _setEnfVertexWithGroup(x,y,z,groupName);
487
488   if (toNotify || toNotify2)
489     NotifySubMeshesHypothesisModification();
490   */
491   if (toNotify)
492     NotifySubMeshesHypothesisModification();
493   
494   MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
495 }
496
497 /* TODO GROUPS
498 bool BLSURFPlugin_Hypothesis::_setEnfVertexWithGroup(double x, double y, double z, const std::string groupName) throw (std::invalid_argument)
499 {
500   bool isModified = false;
501   std::vector<double> enfVertex;
502   enfVertex.push_back(x);
503   enfVertex.push_back(y);
504   enfVertex.push_back(z);
505   if (_enfVertexList.find(enfVertex) != _enfVertexList.end()) {
506     TEnfGroupName oldGroupName = _enfVertexGroupNameMap[enfVertex];
507     _enfVertexGroupNameMap[enfVertex] = groupName;
508     if ((groupName != "") && (groupName != oldGroupName)) {
509       MESSAGE("Group name is not empty");
510       TEnfVertexList& enfVertexList = _groupNameEnfVertexListMap[groupName];
511       enfVertexList.insert(enfVertex);
512       isModified = true;
513     }
514     else {
515       if (oldGroupName != "") {
516         // groupName = "" => remove group name
517         TGroupNameEnfVertexListMap::iterator it = _groupNameEnfVertexListMap.find(oldGroupName);
518         if (it != _groupNameEnfVertexListMap.end()) {
519           _groupNameEnfVertexListMap[oldGroupName].erase(enfVertex);
520           if (_groupNameEnfVertexListMap[oldGroupName].size() == 0)
521             _groupNameEnfVertexListMap.erase(oldGroupName);
522           isModified = true;
523         }
524       }
525     }
526     return isModified;
527   }
528
529   std::ostringstream msg ;
530   msg << "No enforced vertex at (" << x << "," << y << "," << z << ")" ;
531   throw std::invalid_argument(msg.str());
532 }
533
534 //=======================================================================
535 //function : SetEnforcedVertexGroupName
536 //=======================================================================
537 void BLSURFPlugin_Hypothesis::SetEnforcedVertexGroupName(double x, double y, double z,
538                                                         const TEnfGroupName& groupName)
539   throw (std::invalid_argument)
540 {
541   bool toNotify = _setEnfVertexWithGroup(x,y,z,groupName);
542   if (toNotify)
543       NotifySubMeshesHypothesisModification();
544 //   bool toNotify = false;
545 //   TEnfVertex enfVertex;
546 //   enfVertex.push_back(x);
547 //   enfVertex.push_back(y);
548 //   enfVertex.push_back(z);
549 //   
550 //   if (_enfVertexList.find(enfVertex) != _enfVertexList.end()) {
551 //     TEnfGroupName oldGroupName = _enfVertexGroupNameMap[enfVertex];
552 //     _enfVertexGroupNameMap[enfVertex] = groupName;
553 //     if ((groupName != "") && (groupName != oldGroupName)) {
554 //       MESSAGE("Group name is not empty");
555 //       TEnfVertexList& enfVertexList = _groupNameEnfVertexListMap[groupName];
556 //       enfVertexList.insert(enfVertex);
557 //       toNotify = true;
558 //     }
559 //     else {
560 //       if (oldGroupName != "") {
561 //         // groupName = "" => remove group name
562 //         TGroupNameEnfVertexListMap::iterator it = _groupNameEnfVertexListMap.find(oldGroupName);
563 //         if (it != _groupNameEnfVertexListMap.end()) {
564 //           _groupNameEnfVertexListMap[oldGroupName].erase(enfVertex);
565 //           if (_groupNameEnfVertexListMap[oldGroupName].size() == 0)
566 //             _groupNameEnfVertexListMap.erase(oldGroupName);
567 //           toNotify = true;
568 //         }
569 //       }
570 //     }
571 //     if (toNotify)
572 //       NotifySubMeshesHypothesisModification();
573 //     return;
574 //   }
575
576 // //   std::ostringstream msg ;
577 // //   msg << "No enforced vertex at (" << x << "," << y << "," << z << ")" ;
578 // //   throw std::invalid_argument(msg.str());
579 }
580
581
582 //=======================================================================
583 //function : GetEnforcedVertexGroupName
584 //=======================================================================
585 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetEnforcedVertexGroupName(double x, double y, double z)
586   throw (std::invalid_argument)
587 {
588   TEnfVertex enfVertex;
589   enfVertex.push_back(x);
590   enfVertex.push_back(y);
591   enfVertex.push_back(z);
592
593   if (_enfVertexGroupNameMap.find(enfVertex) != _enfVertexGroupNameMap.end())
594       return _enfVertexGroupNameMap[enfVertex];
595
596   std::ostringstream msg ;
597   msg << "No enforced vertex at (" << x << "," << y << "," << z << ")" ;
598   throw std::invalid_argument(msg.str());
599 }
600 */
601
602 /*
603 //=======================================================================
604 //function : SetEnforcedVertexList
605 //=======================================================================
606
607 void BLSURFPlugin_Hypothesis::SetEnforcedVertexList(const TEnfEntry& entry,
608                                                     const TEnfVertexList vertexList)
609 {
610   TEnfVertexList::const_iterator it;
611   bool toNotify = false;
612   for(it = vertexList.begin();it!=vertexList.end();++it) {
613     if (_entryEnfVertexListMap.count(entry)>0)
614       if (_entryEnfVertexListMap[entry].count(*it)==0)
615         toNotify = true;
616     else
617       toNotify = true;
618     _entryEnfVertexListMap[entry].insert(*it);
619     _enfVertexList.insert(*it);
620   }
621   if (toNotify)
622     NotifySubMeshesHypothesisModification();
623 }
624 */
625
626 //=======================================================================
627 //function : GetEnforcedVertices
628 //=======================================================================
629
630 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnforcedVertices(const TEnfEntry& entry)
631   throw (std::invalid_argument)
632 {
633   if (_entryEnfVertexListMap.count(entry)>0)
634     return _entryEnfVertexListMap[entry];
635   std::ostringstream msg ;
636   msg << "No enforced vertex for entry " << entry ;
637   throw std::invalid_argument(msg.str());
638 }
639
640 //=======================================================================
641 //function : ClearEnforcedVertex
642 //=======================================================================
643
644 void BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEnfEntry& entry, double x, double y, double z)
645   throw (std::invalid_argument)
646 {
647   std::ostringstream msg ;
648   
649   TEnfVertex enfVertex;
650   enfVertex.push_back(x);
651   enfVertex.push_back(y);
652   enfVertex.push_back(z);
653
654   // check that enf vertex with given coords exists
655   if (_enfVertexList.count(enfVertex) == 0) {
656     msg << "No enforced vertex for " << entry;
657     throw std::invalid_argument(msg.str());
658   }
659
660
661   TEntryEnfVertexListMap::iterator it_enf = _entryEnfVertexListMap.find(entry);
662   if (it_enf != _entryEnfVertexListMap.end()) {
663     bool toNotify = false;
664     TEnfVertexList::iterator it = _entryEnfVertexListMap[entry].find(enfVertex);
665     if (it != _entryEnfVertexListMap[entry].end()) {
666       toNotify = true;
667
668       // Update entry2enfList map
669       _entryEnfVertexListMap[entry].erase(it);
670       if (_entryEnfVertexListMap[entry].size() == 0)
671         _entryEnfVertexListMap.erase(it_enf);
672
673       /* TODO GROUPS
674       // Update groupName2enfCoord map
675       TEnfGroupName groupName = _enfVertexGroupNameMap[enfVertex];
676       if (groupName != "") {
677         TGroupNameEnfVertexListMap::iterator it_grp =_groupNameEnfVertexListMap.find(groupName);
678         if (it_grp != _groupNameEnfVertexListMap.end()) {
679           _groupNameEnfVertexListMap[groupName].erase(enfVertex);
680           if (_groupNameEnfVertexListMap[groupName].size() == 0)
681             _groupNameEnfVertexListMap.erase(it_grp);
682         }
683       }
684       
685       // Update _enfVertexGroupNameMap
686       _enfVertexGroupNameMap.erase(enfVertex);
687       */
688       
689       // Update _enfVertexList
690       _enfVertexList.erase(enfVertex);
691
692     }
693     if (toNotify)
694       NotifySubMeshesHypothesisModification();
695     return;
696   }
697
698   msg << "No enforced vertex for " << entry;
699   throw std::invalid_argument(msg.str());
700 }
701 /*
702 //=======================================================================
703 //function : ClearEnforcedVertexList
704 //=======================================================================
705
706 void BLSURFPlugin_Hypothesis::ClearEnforcedVertexList(const std::string& entry, TEnfVertexList vertexList)
707   throw (std::invalid_argument)
708 {
709   TEnfVertex coord;
710   TEnfVertexList::const_iterator it_toRemove;
711   TEnfVertexList::iterator it;
712   bool toNotify = false;
713
714   TEntryEnfVertexListMap::iterator it_enf = _entryEnfVertexListMap.find(entry);
715   if (it_enf != _entryEnfVertexListMap.end()) {
716     for (it_toRemove = vertexList.begin() ; it_toRemove != vertexList.end() ; ++it_toRemove) {
717       coord = *it_toRemove;
718       it = _entryEnfVertexListMap[entry].find(coord);
719       if (it != _entryEnfVertexListMap[entry].end()) {
720         toNotify = true;
721         _entryEnfVertexListMap[entry].erase(it);
722         _enfVertexList.erase(it);
723       }
724     }
725     if (_entryEnfVertexListMap[entry].size() == 0) {
726       toNotify = true;
727       _entryEnfVertexListMap.erase(it_enf);
728     }
729     if (toNotify)
730       NotifySubMeshesHypothesisModification();
731     return;
732   }
733
734   std::ostringstream msg ;
735   msg << "No enforced vertex for " << entry;
736   throw std::invalid_argument(msg.str());
737 }
738 */
739 //=======================================================================
740 //function : ClearEnforcedVertices
741 //=======================================================================
742
743 void BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEnfEntry& entry)
744   throw (std::invalid_argument)
745 {
746   TEntryEnfVertexListMap::iterator it_enf = _entryEnfVertexListMap.find(entry);
747   if (it_enf != _entryEnfVertexListMap.end()) {
748     TEnfVertexList enfList = it_enf->second;
749     TEnfVertexList::iterator it;
750     for(it = enfList.begin();it!=enfList.end();++it) {
751       /* TODO GROUPS
752       TEnfGroupName groupName = _enfVertexGroupNameMap[*it];
753       if (groupName != "") {
754         TGroupNameEnfVertexListMap::iterator it_grp =_groupNameEnfVertexListMap.find(groupName);
755         if (it_grp != _groupNameEnfVertexListMap.end()) {
756           _groupNameEnfVertexListMap[groupName].erase(it);
757           if (_groupNameEnfVertexListMap[groupName].size() == 0)
758             _groupNameEnfVertexListMap.erase(it_grp);
759         }
760       }
761       _enfVertexGroupNameMap.erase(*it);
762       */
763       _enfVertexList.erase(it);
764     }
765     _entryEnfVertexListMap.erase(it_enf);
766     NotifySubMeshesHypothesisModification();
767     return;
768   }
769
770   std::ostringstream msg ;
771   msg << "No enforced vertex for " << entry;
772   throw std::invalid_argument(msg.str());
773 }
774
775 //=======================================================================
776 //function : ClearAllEnforcedVertices
777 //=======================================================================
778 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices()
779 {
780     _enfVertexList.clear();
781     _entryEnfVertexListMap.clear();
782     /* TODO GROUPS
783     _groupNameEnfVertexListMap.clear();
784     _enfVertexGroupNameMap.clear();
785     */
786     NotifySubMeshesHypothesisModification();
787 }
788
789 //================================================================================
790 /*!
791 * \brief Return the enforced vertices
792 */
793 //================================================================================
794
795 BLSURFPlugin_Hypothesis::TEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(const BLSURFPlugin_Hypothesis* hyp)
796 {
797     return hyp ? hyp->_GetAllEnforcedVertices():GetDefaultEntryEnfVertexListMap();
798 }
799
800
801
802 //=============================================================================
803 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
804 {
805   save << " " << (int)_topology
806        << " " << (int)_physicalMesh
807        << " " << (int)_geometricMesh
808        << " " << _phySize
809        << " " << _angleMeshS
810        << " " << _gradation
811        << " " << (int)_quadAllowed
812        << " " << (int)_decimesh;
813   save << " " << _phyMin
814        << " " << _phyMax
815        << " " << _angleMeshC
816        << " " << _hgeoMin
817        << " " << _hgeoMax
818        << " " << _verb;
819
820   TOptionValues::iterator op_val = _option2value.begin();
821   if (op_val != _option2value.end()) {
822     save << " " << "__OPTIONS_BEGIN__";
823     for ( ; op_val != _option2value.end(); ++op_val ) {
824       if ( !op_val->second.empty() )
825         save << " " << op_val->first
826              << " " << op_val->second << "%#"; // "%#" is a mark of value end
827     }
828     save << " " << "__OPTIONS_END__";
829   }
830
831   TSizeMap::iterator it_sm  = _sizeMap.begin();
832   if (it_sm != _sizeMap.end()) {
833     save << " " << "__SIZEMAP_BEGIN__";
834     for ( ; it_sm != _sizeMap.end(); ++it_sm ) {
835         save << " " << it_sm->first
836              << " " << it_sm->second << "%#"; // "%#" is a mark of value end
837     }
838     save << " " << "__SIZEMAP_END__";
839   }
840
841   TSizeMap::iterator it_at  = _attractors.begin();
842   if (it_at != _attractors.end()) {
843     save << " " << "__ATTRACTORS_BEGIN__";
844     for ( ; it_at != _attractors.end(); ++it_at ) {
845         save << " " << it_at->first
846              << " " << it_at->second << "%#"; // "%#" is a mark of value end
847     }
848     save << " " << "__ATTRACTORS_END__";
849   }
850
851   TEntryEnfVertexListMap::const_iterator it_enf = _entryEnfVertexListMap.begin();
852   if (it_enf != _entryEnfVertexListMap.end()) {
853     save << " " << "__ENFORCED_VERTICES_BEGIN__";
854     for ( ; it_enf != _entryEnfVertexListMap.end(); ++it_enf ) {
855       save << " " << it_enf->first;
856       TEnfVertexList evl = it_enf->second;
857       TEnfVertexList::const_iterator it_evl = evl.begin();
858       for ( ; it_evl != evl.end() ; ++it_evl) {
859         save << " " << (*it_evl)[0];
860         save << " " << (*it_evl)[1];
861         save << " " << (*it_evl)[2];
862         /* TODO GROUPS
863         TEnfVertexGroupNameMap::const_iterator it_enfGroup = _enfVertexGroupNameMap.find(*it_evl);
864         if (it_enfGroup != _enfVertexGroupNameMap.end()) {
865           save << " " << "__ENF_GROUP_BEGIN__";
866           save << " " << it_enfGroup->second ;
867           save << " " << "__ENF_GROUP_END__";
868         }
869         */
870         save << " " << "$"; // "$" is a mark of enforced vertex end
871       }
872       save << "#"; // "#" is a mark of enforced shape end
873     }
874     save << " " << "__ENFORCED_VERTICES_END__";
875   }
876
877   return save;
878 }
879
880 //=============================================================================
881 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
882 {
883   bool isOK = true;
884   int i;
885   double val;
886
887   isOK = (load >> i);
888   if (isOK)
889     _topology = (Topology) i;
890   else
891     load.clear(std::ios::badbit | load.rdstate());
892
893   isOK = (load >> i);
894   if (isOK)
895     _physicalMesh = (PhysicalMesh) i;
896   else
897     load.clear(std::ios::badbit | load.rdstate());
898
899   isOK = (load >> i);
900   if (isOK)
901     _geometricMesh = (GeometricMesh) i;
902   else
903     load.clear(std::ios::badbit | load.rdstate());
904
905   isOK = (load >> val);
906   if (isOK)
907     _phySize = val;
908   else
909     load.clear(std::ios::badbit | load.rdstate());
910
911   isOK = (load >> val);
912   if (isOK)
913     _angleMeshS = val;
914   else
915     load.clear(std::ios::badbit | load.rdstate());
916
917   isOK = (load >> val);
918   if (isOK)
919     _gradation = val;
920   else
921     load.clear(std::ios::badbit | load.rdstate());
922
923   isOK = (load >> i);
924   if (isOK)
925     _quadAllowed = (bool) i;
926   else
927     load.clear(std::ios::badbit | load.rdstate());
928
929   isOK = (load >> i);
930   if (isOK)
931     _decimesh = (bool) i;
932   else
933     load.clear(std::ios::badbit | load.rdstate());
934
935   isOK = (load >> val);
936   if (isOK)
937     _phyMin = val;
938   else
939     load.clear(std::ios::badbit | load.rdstate());
940
941   isOK = (load >> val);
942   if (isOK)
943     _phyMax = val;
944   else
945     load.clear(std::ios::badbit | load.rdstate());
946
947   isOK = (load >> val);
948   if (isOK)
949     _angleMeshC = val;
950   else
951     load.clear(std::ios::badbit | load.rdstate());
952
953   isOK = (load >> val);
954   if (isOK)
955     _hgeoMin = val;
956   else
957     load.clear(std::ios::badbit | load.rdstate());
958
959   isOK = (load >> val);
960   if (isOK)
961     _hgeoMax = val;
962   else
963     load.clear(std::ios::badbit | load.rdstate());
964
965   isOK = (load >> i);
966   if (isOK)
967     _verb = i;
968   else
969     load.clear(std::ios::badbit | load.rdstate());
970
971   std::string option_or_sm;
972   bool hasOptions = false;
973   bool hasSizeMap = false;
974   bool hasAttractor = false;
975   bool hasEnforcedVertex = false;
976
977   isOK = (load >> option_or_sm);
978   if (isOK)
979     if (option_or_sm == "__OPTIONS_BEGIN__")
980       hasOptions = true;
981     else if (option_or_sm == "__SIZEMAP_BEGIN__")
982       hasSizeMap = true;
983     else if (option_or_sm == "__ATTRACTORS_BEGIN__")
984       hasAttractor = true;
985     else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
986       hasEnforcedVertex = true;
987
988   std::string optName, optValue;
989   while (isOK && hasOptions) {
990     isOK = (load >> optName);
991     if (isOK) {
992       if (optName == "__OPTIONS_END__")
993         break;
994       isOK = (load >> optValue);
995     }
996     if (isOK) {
997       std::string & value = _option2value[ optName ];
998       value = optValue;
999       int len = value.size();
1000       // continue reading until "%#" encountered
1001       while ( value[len-1] != '#' || value[len-2] != '%' )
1002       {
1003         isOK = (load >> optValue);
1004         if (isOK) {
1005           value += " ";
1006           value += optValue;
1007           len = value.size();
1008         }
1009         else {
1010           break;
1011         }
1012       }
1013       value[ len-2 ] = '\0'; //cut off "%#"
1014     }
1015   }
1016
1017   if (hasOptions) {
1018     isOK = (load >> option_or_sm);
1019     if (isOK)
1020       if (option_or_sm == "__SIZEMAP_BEGIN__")
1021         hasSizeMap = true;
1022       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1023         hasAttractor = true;
1024       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1025         hasEnforcedVertex = true;
1026   }
1027
1028   std::string smEntry, smValue;
1029   while (isOK && hasSizeMap) {
1030     isOK = (load >> smEntry);
1031     if (isOK) {
1032       if (smEntry == "__SIZEMAP_END__")
1033         break;
1034       isOK = (load >> smValue);
1035     }
1036     if (isOK) {
1037       std::string & value2 = _sizeMap[ smEntry ];
1038       value2 = smValue;
1039       int len2= value2.size();
1040       // continue reading until "%#" encountered
1041       while ( value2[len2-1] != '#' || value2[len2-2] != '%' )
1042       {
1043         isOK = (load >> smValue);
1044         if (isOK) {
1045           value2 += " ";
1046           value2 += smValue;
1047           len2 = value2.size();
1048         }
1049         else {
1050           break;
1051         }
1052       }
1053       value2[ len2-2 ] = '\0'; //cut off "%#"
1054     }
1055   }
1056
1057   if (hasSizeMap) {
1058     isOK = (load >> option_or_sm);
1059     if (isOK)
1060       if (option_or_sm == "__ATTRACTORS_BEGIN__")
1061         hasAttractor = true;
1062       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1063         hasEnforcedVertex = true;
1064   }
1065
1066   std::string atEntry, atValue;
1067   while (isOK && hasAttractor) {
1068     isOK = (load >> atEntry);
1069     if (isOK) {
1070       if (atEntry == "__ATTRACTORS_END__")
1071         break;
1072       isOK = (load >> atValue);
1073     }
1074     if (isOK) {
1075       std::string & value3 = _attractors[ atEntry ];
1076       value3 = atValue;
1077       int len3= value3.size();
1078       // continue reading until "%#" encountered
1079       while ( value3[len3-1] != '#' || value3[len3-2] != '%' )
1080       {
1081         isOK = (load >> atValue);
1082         if (isOK) {
1083           value3 += " ";
1084           value3 += atValue;
1085           len3 = value3.size();
1086         }
1087         else {
1088           break;
1089         }
1090       }
1091       value3[ len3-2 ] = '\0'; //cut off "%#"
1092     }
1093   }
1094   
1095   if (hasAttractor) {
1096     isOK = (load >> option_or_sm);
1097     if (isOK)
1098       if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1099         hasEnforcedVertex = true;
1100   }
1101   
1102   std::string enfEntry, enfValue, enfGroup, trace;
1103   std::ostringstream oss;
1104   while (isOK && hasEnforcedVertex) {
1105     isOK = (load >> enfEntry);
1106     if (isOK) {
1107       MESSAGE("enfEntry: " <<enfEntry);
1108       if (enfEntry == "__ENFORCED_VERTICES_END__")
1109         break;
1110
1111       /* TODO GROUPS
1112       bool hasGroup = false;
1113       */
1114       enfValue = "begin";
1115       int len4 = enfValue.size();
1116
1117       TEnfVertexList & evl = _entryEnfVertexListMap[enfEntry];
1118       evl.clear();
1119       TEnfVertex enfVertex;
1120
1121       // continue reading until "#" encountered
1122       while ( enfValue[len4-1] != '#') {
1123         // New vector begin
1124         enfVertex.clear();
1125         while ( enfValue[len4-1] != '$') {
1126           isOK = (load >> enfValue);
1127           if (isOK) {
1128             MESSAGE("enfValue: " <<enfValue);
1129             len4 = enfValue.size();
1130             // End of vertex list
1131             if (enfValue[len4-1] == '#')
1132               break;
1133             /* TODO GROUPS
1134             if (enfValue == "__ENF_GROUP_BEGIN__") {
1135               hasGroup = true;
1136               isOK = (load >> enfGroup);
1137               MESSAGE("enfGroup: " <<enfGroup);
1138               TEnfGroupName& groupName = _enfVertexGroupNameMap[ enfVertex ];
1139               groupName = enfGroup;
1140               while ( isOK) {
1141                 isOK = (load >> enfGroup);
1142                 if (isOK) {
1143                   MESSAGE("enfGroup: " <<enfGroup);
1144                   if (enfGroup == "__ENF_GROUP_END__")
1145                     break;
1146                   groupName += " ";
1147                   groupName += enfGroup;
1148                 }
1149               }
1150             }
1151             else {
1152               // Add to vertex
1153               enfVertex.push_back(atof(enfValue.c_str()));
1154             }
1155             */
1156             if (enfValue[len4-1] != '$') {
1157               // Add to vertex
1158               enfVertex.push_back(atof(enfValue.c_str()));
1159             }
1160           }
1161           else
1162             break;
1163         }
1164         if (enfValue[len4-1] == '$') {
1165           MESSAGE("enfValue is $");
1166           enfValue[len4-1] = '\0'; //cut off "$"
1167           /* TODO GROUPS
1168           if (!hasGroup) {
1169             MESSAGE("no group: remove $");
1170             // Remove '$' and add to vertex
1171 //             enfValue[len4-1] = '\0'; //cut off "$#"
1172             enfVertex.push_back(atof(enfValue.c_str()));
1173           }
1174           */
1175           enfValue[len4-1] = '\0'; //cut off "$#"
1176           enfVertex.push_back(atof(enfValue.c_str()));
1177           MESSAGE("Add vertex to list");
1178           // Add vertex to list of vertex
1179           evl.insert(enfVertex);
1180         }
1181       }
1182       if (enfValue[len4-1] == '#') {
1183         /* TODO GROUPS
1184         if (!hasGroup) {
1185           // Remove '$#' and add to vertex
1186           enfValue[len4-2] = '\0'; //cut off "$#"
1187           enfVertex.push_back(atof(enfValue.c_str()));
1188         }
1189         */
1190         // Remove '$#' and add to vertex
1191         enfValue[len4-2] = '\0'; //cut off "$#"
1192         enfVertex.push_back(atof(enfValue.c_str()));
1193         // Add vertex to list of vertex
1194         evl.insert(enfVertex);
1195       }
1196     }
1197     else
1198       break;
1199   }
1200
1201   return load;
1202 }
1203
1204 //=============================================================================
1205 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp)
1206 {
1207   return hyp.SaveTo( save );
1208 }
1209
1210 //=============================================================================
1211 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp)
1212 {
1213   return hyp.LoadFrom( load );
1214 }
1215
1216 //================================================================================
1217 /*!
1218  * \brief Does nothing
1219  */
1220 //================================================================================
1221
1222 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
1223                                                       const TopoDS_Shape& theShape)
1224 {
1225   return false;
1226 }
1227
1228 //=============================================================================
1229 /*!
1230  * \brief Initialize my parameter values by default parameters.
1231  *  \retval bool - true if parameter values have been successfully defined
1232  */
1233 //=============================================================================
1234
1235 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&   dflts,
1236                                                       const SMESH_Mesh* theMesh)
1237 {
1238   return bool( _phySize = dflts._elemLength );
1239 }
1240
1241 //=============================================================================
1242 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
1243 {
1244   return FromCAD;
1245 }
1246
1247 //=============================================================================
1248 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
1249 {
1250   return PhysicalUserDefined;
1251 }
1252
1253 //=============================================================================
1254 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
1255 {
1256   return 10;
1257 }
1258
1259 //======================================================================
1260 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
1261 {
1262   return undefinedDouble(); // 1e+4;
1263 }
1264
1265 //======================================================================
1266 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
1267 {
1268   return undefinedDouble(); //1e-4;
1269 }
1270
1271 //======================================================================
1272 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
1273 {
1274   return DefaultGeom;
1275 }
1276
1277 //=============================================================================
1278 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
1279 {
1280   return 8;
1281 }
1282
1283 //=============================================================================
1284 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
1285 {
1286   return 1.1;
1287 }
1288
1289 //=============================================================================
1290 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
1291 {
1292   return false;
1293 }
1294
1295 //=============================================================================
1296 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()
1297 {
1298   return false;
1299 }