]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx
Salome HOME
print output of BLSURF
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
1 //  BLSURFPlugin : C++ implementation
2 //
3 //  Copyright (C) 2006  OPEN CASCADE, CEA/DEN, EDF R&D
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
20 //
21 //
22 // File      : BLSURFPlugin_Hypothesis.cxx
23 // Authors   : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
24 //             & Aurelien ALLEAUME (DISTENE)
25 // Date      : 28/03/2006
26 // Project   : SALOME
27 //=============================================================================
28
29 using namespace std;
30 #include <BLSURFPlugin_Hypothesis.hxx>
31 #include <utilities.h>
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 {
52   _name = "BLSURF_Parameters";
53   _param_algo_dim = 2;
54
55   // to desable writing boundaries
56   //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
57   
58
59   const char* optionNames[] = {
60     "addsurf_ivertex",
61     "background",
62     "CheckAdjacentEdges",
63     "CheckCloseEdges",
64     "CheckWellDefined",
65     "coiter",
66     "communication",
67     "decim",
68     "export_flag",
69     "file_h",
70     "frontal",
71     "gridnu",
72     "gridnv",
73     "hinterpol_flag",
74     "hmean_flag",
75     "intermedfile",
76     "memory",
77     "normals",
78     "optim",
79     "pardom_flag",
80     "pinch",
81     "refs",
82     "rigid",
83     "surforient",
84     "tconf",
85     "topo_collapse",
86     "addsurf_angle",
87     "addsurf_R",
88     "addsurf_H",
89     "addsurf_FG",
90     "addsurf_r",
91     "addsurf_PA",
92     "angle_compcurv",
93     "angle_ridge",
94     "CoefRectangle",
95     "eps_collapse",
96     "eps_ends",
97     "eps_pardom",
98     "LSS",
99     "topo_eps1",
100     "topo_eps2",
101     "export_format",
102     "export_option",
103     "import_option",
104     "prefix",
105     "" // mark of end
106   };
107   int i = 0;
108   while ( optionNames[i][0] )
109     _option2value[ optionNames[i++] ].clear();
110
111 }
112
113 //=============================================================================
114 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
115 {
116   if (theTopology != _topology) {
117     _topology = theTopology;
118     NotifySubMeshesHypothesisModification();
119   }
120 }
121
122 //=============================================================================
123 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
124 {
125   if (thePhysicalMesh != _physicalMesh) {
126     _physicalMesh = thePhysicalMesh;
127     switch( _physicalMesh ) {
128       case DefaultSize:
129       default:
130         _phySize = GetDefaultPhySize();
131         break;
132       }
133     NotifySubMeshesHypothesisModification();
134   }
135 }
136
137 //=============================================================================
138 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
139 {
140   if (theVal != _phySize) {
141     _phySize = theVal;
142     NotifySubMeshesHypothesisModification();
143   }
144 }
145
146 //=============================================================================
147 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
148 {
149   if (theMinSize != _phyMin) {
150     _phyMin = theMinSize;
151     NotifySubMeshesHypothesisModification();
152   }
153 }
154
155 //=============================================================================
156 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
157 {
158   if (theMaxSize != _phyMax) {
159     _phyMax = theMaxSize;
160     NotifySubMeshesHypothesisModification();
161   }
162 }
163
164
165 //=============================================================================
166 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
167 {
168   if (theMinSize != _hgeoMin) {
169     _hgeoMin = theMinSize;
170     NotifySubMeshesHypothesisModification();
171   }
172 }
173
174 //=============================================================================
175 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
176 {
177   if (theMaxSize != _hgeoMax) {
178     _hgeoMax = theMaxSize;
179     NotifySubMeshesHypothesisModification();
180   }
181 }
182
183 //=============================================================================
184 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
185 {
186   if (theGeometricMesh != _geometricMesh) {
187     _geometricMesh = theGeometricMesh;
188     switch( _geometricMesh ) {
189       case DefaultGeom:
190       default:
191         _angleMeshS = GetDefaultAngleMeshS();
192         _gradation  = GetDefaultGradation();
193         break;
194       }
195     NotifySubMeshesHypothesisModification();
196   }
197 }
198
199 //=============================================================================
200 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
201 {
202   if (theVal != _angleMeshS) {
203     _angleMeshS = theVal;
204     NotifySubMeshesHypothesisModification();
205   }
206 }
207
208 //=============================================================================
209 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
210 {
211   if (theVal != _angleMeshC) {
212     _angleMeshC = theVal;
213     NotifySubMeshesHypothesisModification();
214   }
215 }
216
217 //=============================================================================
218 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
219 {
220   if (theVal != _gradation) {
221     _gradation = theVal;
222     NotifySubMeshesHypothesisModification();
223   }
224 }
225
226 //=============================================================================
227 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
228 {
229   if (theVal != _quadAllowed) {
230     _quadAllowed = theVal;
231     NotifySubMeshesHypothesisModification();
232   }
233 }
234
235 //=============================================================================
236 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
237 {
238   if (theVal != _decimesh) {
239     _decimesh = theVal;
240     NotifySubMeshesHypothesisModification();
241   }
242 }
243
244 //=============================================================================
245 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
246 {
247   if (theVal != _verb) {
248     _verb = theVal;
249     NotifySubMeshesHypothesisModification();
250   }
251 }
252 //=============================================================================
253 void BLSURFPlugin_Hypothesis::SetOptionValue(const string& optionName,
254                                              const string& optionValue) throw (SALOME_Exception)
255 {
256   TOptionValues::iterator op_val = _option2value.find( optionName );
257   if ( op_val == _option2value.end() ) {
258     string msg = "Unknown BLSURF option: <";
259     msg += optionName + ">";
260     throw SALOME_Exception(msg.c_str());
261   }
262   if ( op_val->second != optionValue ) {
263     op_val->second = optionValue;
264     NotifySubMeshesHypothesisModification();
265   }
266 }
267
268 //=============================================================================
269 string BLSURFPlugin_Hypothesis::GetOptionValue(const string& optionName)
270   throw (SALOME_Exception)
271 {
272   TOptionValues::iterator op_val = _option2value.find( optionName );
273   if ( op_val == _option2value.end() ) {
274     string msg = "Unknown BLSURF option: <";
275     msg += optionName + ">";
276     throw SALOME_Exception(msg.c_str());
277   }
278   return op_val->second;
279 }
280
281 //=============================================================================
282 void BLSURFPlugin_Hypothesis::ClearOption(const string& optionName)
283 {
284   TOptionValues::iterator op_val = _option2value.find( optionName );
285   if ( op_val != _option2value.end() )
286     op_val->second.clear();
287 }
288
289 //=============================================================================
290 ostream & BLSURFPlugin_Hypothesis::SaveTo(ostream & save)
291 {
292   save << " " << (int)_topology
293        << " " << (int)_physicalMesh
294        << " " << (int)_geometricMesh
295        << " " << _phySize
296        << " " << _angleMeshS   
297        << " " << _gradation     
298        << " " << (int)_quadAllowed 
299        << " " << (int)_decimesh;
300   save << " " << _phyMin
301        << " " << _phyMax
302        << " " << _angleMeshC
303        << " " << _hgeoMin
304        << " " << _hgeoMax
305        << " " << _verb;
306
307   TOptionValues::iterator op_val = _option2value.begin();
308   for ( ; op_val != _option2value.end(); ++op_val ) {
309     if ( !op_val->second.empty() )
310       save << " " << op_val->first
311            << " " << op_val->second << "%#"; // "%#" is a mark of value end
312   }
313
314   return save;
315 }
316
317 //=============================================================================
318 istream & BLSURFPlugin_Hypothesis::LoadFrom(istream & load)
319 {
320   bool isOK = true;
321   int i;
322   double val;
323
324   isOK = (load >> i);
325   if (isOK)
326     _topology = (Topology) i;
327   else
328     load.clear(ios::badbit | load.rdstate());
329
330   isOK = (load >> i);
331   if (isOK)
332     _physicalMesh = (PhysicalMesh) i;
333   else
334     load.clear(ios::badbit | load.rdstate());
335
336   isOK = (load >> i);
337   if (isOK)
338     _geometricMesh = (GeometricMesh) i;
339   else
340     load.clear(ios::badbit | load.rdstate());
341
342   isOK = (load >> val);
343   if (isOK)
344     _phySize = val;
345   else
346     load.clear(ios::badbit | load.rdstate());
347
348   isOK = (load >> val);
349   if (isOK)
350     _angleMeshS = val;
351   else
352     load.clear(ios::badbit | load.rdstate());
353
354   isOK = (load >> val);
355   if (isOK)
356     _gradation = val;
357   else
358     load.clear(ios::badbit | load.rdstate());
359
360   isOK = (load >> i);
361   if (isOK)
362     _quadAllowed = (bool) i;
363   else
364     load.clear(ios::badbit | load.rdstate());
365
366   isOK = (load >> i);
367   if (isOK)
368     _decimesh = (bool) i;
369   else
370     load.clear(ios::badbit | load.rdstate());
371
372   isOK = (load >> val);
373   if (isOK)
374     _phyMin = val;
375   else
376     load.clear(ios::badbit | load.rdstate());
377   
378   isOK = (load >> val);
379   if (isOK)
380     _phyMax = val;
381   else
382     load.clear(ios::badbit | load.rdstate());
383   
384   isOK = (load >> val);
385   if (isOK)
386     _angleMeshC = val;
387   else
388     load.clear(ios::badbit | load.rdstate());
389   
390   isOK = (load >> val);
391   if (isOK)
392     _hgeoMin = val;
393   else
394     load.clear(ios::badbit | load.rdstate());
395   
396   isOK = (load >> val);
397   if (isOK)
398     _hgeoMax = val;
399   else
400     load.clear(ios::badbit | load.rdstate());
401   
402   isOK = (load >> i);
403   if (isOK)
404     _verb = i;
405   else
406     load.clear(ios::badbit | load.rdstate());
407
408   string optName, optValue;
409   while (isOK) {
410     isOK = (load >> optName);
411     if (isOK)
412       isOK = (load >> optValue);
413     if (isOK) {
414       string & value = _option2value[ optName ];
415       value = optValue;
416       int len = value.size();
417       // continue reading until "%#" encountered
418       while ( value[len-1] != '#' || value[len-2] != '%' )
419       {
420         isOK = (load >> optValue);
421         if (isOK) {
422           value += " ";
423           value += optValue;
424           len = value.size();
425         }
426         else {
427           break;
428         }
429       }
430       value[ len-2 ] = '\0'; //cut off "%#"
431     }
432   }
433
434   return load;
435 }
436
437 //=============================================================================
438 ostream & operator <<(ostream & save, BLSURFPlugin_Hypothesis & hyp)
439 {
440   return hyp.SaveTo( save );
441 }
442
443 //=============================================================================
444 istream & operator >>(istream & load, BLSURFPlugin_Hypothesis & hyp)
445 {
446   return hyp.LoadFrom( load );
447 }
448
449 //================================================================================
450 /*!
451  * \brief Does nothing
452  */
453 //================================================================================
454
455 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
456                                                       const TopoDS_Shape& theShape)
457 {
458   return false;
459 }
460
461 //=============================================================================
462 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
463 {
464   return FromCAD;
465 }
466
467 //=============================================================================
468 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
469 {
470   return PhysicalUserDefined;
471 }
472
473 //=============================================================================
474 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
475 {
476   return 10;
477 }
478
479 //======================================================================
480 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
481 {
482   return 1e+4;
483 }
484
485 //======================================================================
486 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
487 {
488   return 1e-4;
489 }
490
491 //======================================================================
492 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
493 {
494   return DefaultGeom;
495 }
496
497 //=============================================================================
498 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
499 {
500   return 8;
501 }
502
503 //=============================================================================
504 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
505 {
506   return 1.1;
507 }
508
509 //=============================================================================
510 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
511 {
512   return false;
513 }
514
515 //=============================================================================
516 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()
517 {
518   return false;
519 }