]> SALOME platform Git repositories - plugins/hexoticplugin.git/blob - src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx
Salome HOME
BUG: HexoticPLUGIN/Size maps: Fixed some dump issues
[plugins/hexoticplugin.git] / src / HexoticPlugin / HexoticPlugin_Hypothesis.cxx
1 // Copyright (C) 2007-2013  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   : HexoticPlugin_Hypothesis.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
23 // ---
24 //
25 #include "HexoticPlugin_Hypothesis.hxx"
26 #include <utilities.h>
27
28 #include <TCollection_AsciiString.hxx>
29
30 //=============================================================================
31 /*!
32  *  
33  */
34 //=============================================================================
35 HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis (int hypId, int studyId,
36                                                     SMESH_Gen* gen)
37   : SMESH_Hypothesis(hypId, studyId, gen),
38     _hexesMinLevel( GetDefaultHexesMinLevel() ),
39     _hexesMaxLevel( GetDefaultHexesMaxLevel() ),
40     _minSize( GetDefaultMinSize() ),
41     _maxSize( GetDefaultMaxSize() ),
42     _hexoticIgnoreRidges( GetDefaultHexoticIgnoreRidges() ),
43     _hexoticInvalidElements( GetDefaultHexoticInvalidElements() ), 
44     _hexoticSharpAngleThreshold( GetDefaultHexoticSharpAngleThreshold() ),
45     _hexoticNbProc( GetDefaultHexoticNbProc() ),
46     _hexoticWorkingDirectory( GetDefaultHexoticWorkingDirectory() ),
47     _hexoticSdMode(GetDefaultHexoticSdMode()),
48     _hexoticVerbosity(GetDefaultHexoticVerbosity()),
49     _hexoticMaxMemory(GetDefaultHexoticMaxMemory()),
50     _sizeMaps(GetDefaultHexoticSizeMaps())
51 {
52   MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
53   _name = "Hexotic_Parameters";
54   _param_algo_dim = 3;
55 }
56
57 //=============================================================================
58 /*!
59  *  
60  */
61 //=============================================================================
62
63 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
64   if (theVal != _hexesMinLevel) {
65     _hexesMinLevel = theVal;
66     NotifySubMeshesHypothesisModification();
67   }
68 }
69
70 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
71   if (theVal != _hexesMaxLevel) {
72     _hexesMaxLevel = theVal;
73     NotifySubMeshesHypothesisModification();
74   }
75 }
76
77 void HexoticPlugin_Hypothesis::SetMinSize(double theVal) {
78   if (theVal != _minSize) {
79           _minSize = theVal;
80     NotifySubMeshesHypothesisModification();
81   }
82 }
83
84 void HexoticPlugin_Hypothesis::SetMaxSize(double theVal) {
85   if (theVal != _maxSize) {
86           _maxSize = theVal;
87     NotifySubMeshesHypothesisModification();
88   }
89 }
90
91 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
92   if (theVal != _hexoticIgnoreRidges) {
93     _hexoticIgnoreRidges = theVal;
94     NotifySubMeshesHypothesisModification();
95   }
96 }
97
98 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
99   if (theVal != _hexoticInvalidElements) {
100     _hexoticInvalidElements = theVal;
101     NotifySubMeshesHypothesisModification();
102   }
103 }
104
105 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(double theVal) {
106   if (theVal != _hexoticSharpAngleThreshold) {
107     _hexoticSharpAngleThreshold = theVal;
108     NotifySubMeshesHypothesisModification();
109   }
110 }
111
112 void HexoticPlugin_Hypothesis::SetHexoticNbProc(int theVal) {
113   if (theVal != _hexoticNbProc) {
114     _hexoticNbProc = theVal;
115     NotifySubMeshesHypothesisModification();
116   }
117 }
118
119 void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& path)
120 {
121   if ( _hexoticWorkingDirectory != path ) {
122     _hexoticWorkingDirectory = path;
123     NotifySubMeshesHypothesisModification();
124   }
125 }
126
127 void HexoticPlugin_Hypothesis::SetHexoticSdMode(int theVal) {
128   if (theVal != _hexoticSdMode) {
129     _hexoticSdMode = theVal;
130     NotifySubMeshesHypothesisModification();
131   }
132 }
133
134 void HexoticPlugin_Hypothesis::SetHexoticVerbosity(int theVal) {
135   if (theVal != _hexoticVerbosity) {
136     _hexoticVerbosity = theVal;
137     NotifySubMeshesHypothesisModification();
138   }
139 }
140
141 void HexoticPlugin_Hypothesis::SetHexoticMaxMemory(int theVal) {
142   if (theVal != _hexoticMaxMemory) {
143     _hexoticMaxMemory = theVal;
144     NotifySubMeshesHypothesisModification();
145   }
146 }
147
148 bool HexoticPlugin_Hypothesis::AddSizeMap(std::string theEntry, double theSize) {
149   THexoticSizeMaps::iterator it;
150   it=_sizeMaps.find(theEntry);
151   if( it == _sizeMaps.end() ) // If no size map is defined on the given object
152   {
153     _sizeMaps[theEntry] = theSize;
154     MESSAGE("NEW size map, entry :"<<theEntry<<", size : "<<theSize);
155     NotifySubMeshesHypothesisModification();
156     return true;
157   }
158   else if( it->second != theSize ) // If a size map exists with a different size value
159   {
160     it->second = theSize;
161     MESSAGE("MODIFIED size map, entry :"<<theEntry<<"with size : "<<theSize);
162     NotifySubMeshesHypothesisModification();
163     return true;
164   }
165   else
166   {
167     MESSAGE("NO size map added")
168     return false; // No size map added
169   }
170 }
171
172 bool HexoticPlugin_Hypothesis::UnsetSizeMap(std::string theEntry) {
173   THexoticSizeMaps::iterator it;
174   it=_sizeMaps.find(theEntry);
175   if( it != _sizeMaps.end() )
176   {
177     _sizeMaps.erase(it);  
178     return true;
179   }
180   else
181     return false;
182 }
183
184 //=============================================================================
185 /*!
186  *  
187  */
188 //=============================================================================
189 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
190 {
191   //explicit outputs for future code compatibility of saved .hdf
192   //save without any whitespaces!
193   int dummy = -1;
194   save<<"hexesMinLevel="<<_hexesMinLevel<<";"; 
195   save<<"hexesMaxLevel="<<_hexesMaxLevel<<";";
196   save<<"hexoticIgnoreRidges="<<(int)_hexoticIgnoreRidges<<";";
197   save<<"hexoticInvalidElements="<<(int)_hexoticInvalidElements<<";";
198   save<<"hexoticSharpAngleThreshold="<<_hexoticSharpAngleThreshold<<";";
199   save<<"hexoticNbProc="<<_hexoticNbProc<<";";
200   save<<"hexoticWorkingDirectory="<<_hexoticWorkingDirectory<<";";
201   save<<"minSize="<<_minSize<<";";
202   save<<"maxSize="<<_maxSize<<";";
203   save<<"hexoticSdMode="<<_hexoticSdMode<<";";
204   save<<"hexoticVerbosity="<<_hexoticVerbosity<<";";
205   save<<"hexoticMaxMemory="<<_hexoticMaxMemory<<";";
206   return save;
207 }
208
209 //=============================================================================
210 /*!
211  *  
212  */
213 //=============================================================================
214 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
215 {
216    //explicit inputs for future code compatibility of saved .hdf
217    bool isOK = true;
218    std::string str1,str2,str3,str4;
219
220    //save without any whitespaces!
221    isOK = (load >> str1);
222    if (!(isOK)) {
223      //defaults values assumed
224      load.clear(std::ios::badbit | load.rdstate());
225      return load;
226    }
227    int pos = 0;
228    int len = str1.length();
229    while (pos < len) {
230       int found = str1.find(';',pos);
231       str2 = str1.substr(pos,found-pos);
232       int eqpos = str2.find('=',0);
233       str3 = str2.substr(0,eqpos);
234       str4 = str2.substr(eqpos+1);
235       pos = found + 1;
236
237       if (str3=="hexesMinLevel") _hexesMinLevel = atoi(str4.c_str());
238       if (str3=="hexesMaxLevel") _hexesMaxLevel = atoi(str4.c_str());
239       if (str3=="hexoticQuadrangles") {}
240       if (str3=="hexoticIgnoreRidges") _hexoticIgnoreRidges = (bool) atoi(str4.c_str());
241       if (str3=="hexoticInvalidElements") _hexoticInvalidElements = (bool) atoi(str4.c_str());
242       if (str3=="hexoticSharpAngleThreshold") _hexoticSharpAngleThreshold = atof(str4.c_str());
243       if (str3=="hexoticNbProc") _hexoticNbProc = atoi(str4.c_str());
244       if (str3=="hexoticWorkingDirectory") _hexoticWorkingDirectory = str4;
245       if (str3=="minSize") _minSize = atof(str4.c_str());
246       if (str3=="maxSize") _maxSize = atof(str4.c_str());
247       if (str3=="hexoticSdMode") _hexoticSdMode = atoi(str4.c_str());
248       if (str3=="hexoticVerbosity") _hexoticVerbosity = atoi(str4.c_str());
249       if (str3=="hexoticMaxMemory") _hexoticMaxMemory = atoi(str4.c_str());
250    }
251    return load;
252 }
253
254 //=============================================================================
255 /*!
256  *  
257  */
258 //=============================================================================
259 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
260 {
261   return hyp.SaveTo( save );
262 }
263
264 //=============================================================================
265 /*!
266  *  
267  */
268 //=============================================================================
269 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
270 {
271   return hyp.LoadFrom( load );
272 }
273
274
275 //================================================================================
276 /*!
277  * \brief Does nothing
278  * \param theMesh - the built mesh
279  * \param theShape - the geometry of interest
280  * \retval bool - always false
281  */
282 //================================================================================
283 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
284                                                    const TopoDS_Shape& theShape)
285 {
286   return false;
287 }
288 //================================================================================
289 /*!
290  * \brief Initialize my parameter values by default parameters.
291  *  \retval bool - true if parameter values have been successfully defined
292  */
293 //================================================================================
294
295 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
296                                                        const SMESH_Mesh* /*theMesh*/)
297 {
298   return false;
299 }
300
301 //=============================================================================
302 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
303 {
304   return 6;
305 }
306
307 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
308 {
309   return 10;
310 }
311
312 double HexoticPlugin_Hypothesis::GetDefaultMinSize()
313 {
314   return 0.0;
315 }
316
317 double HexoticPlugin_Hypothesis::GetDefaultMaxSize()
318 {
319   return 0.0;
320 }
321
322 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
323 {
324   return false;
325 }
326
327 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
328 {
329   return false;
330 }
331
332 double HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
333 {
334   return 60.0;
335 }
336
337 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
338 {
339   return 4;
340 }
341
342 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
343 {
344   std::string aTmpDir;
345
346   char *Tmp_dir = getenv("SALOME_TMP_DIR");
347 #ifdef WIN32
348   if(Tmp_dir == NULL) {
349     Tmp_dir = getenv("TEMP");
350     if( Tmp_dir== NULL )
351       Tmp_dir = getenv("TMP");
352   }
353 #endif
354   if( Tmp_dir != NULL ) {
355     aTmpDir = std::string(Tmp_dir);
356 #ifdef WIN32
357     if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\';
358 #else
359     if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/';
360 #endif
361   }
362   else {
363 #ifdef WIN32
364     aTmpDir = "C:\\";
365 #else
366     aTmpDir = "/tmp/";
367 #endif
368   }
369   return aTmpDir;
370 }
371
372 int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()
373 {
374   return 4;
375 }
376
377 int HexoticPlugin_Hypothesis::GetDefaultHexoticVerbosity()
378 {
379   return 1;
380 }
381
382 int HexoticPlugin_Hypothesis::GetDefaultHexoticMaxMemory()
383 {
384   return 2048;
385 }
386
387 HexoticPlugin_Hypothesis::THexoticSizeMaps HexoticPlugin_Hypothesis::GetDefaultHexoticSizeMaps()
388 {
389   return THexoticSizeMaps();
390 }
391
392