Salome HOME
Merge from V6_main 01/04/2013
[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 {
51   MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
52   _name = "Hexotic_Parameters";
53   _param_algo_dim = 3;
54 }
55
56 //=============================================================================
57 /*!
58  *  
59  */
60 //=============================================================================
61
62 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
63   if (theVal != _hexesMinLevel) {
64     _hexesMinLevel = theVal;
65     NotifySubMeshesHypothesisModification();
66   }
67 }
68
69 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
70   if (theVal != _hexesMaxLevel) {
71     _hexesMaxLevel = theVal;
72     NotifySubMeshesHypothesisModification();
73   }
74 }
75
76 void HexoticPlugin_Hypothesis::SetMinSize(double theVal) {
77   if (theVal != _minSize) {
78           _minSize = theVal;
79     NotifySubMeshesHypothesisModification();
80   }
81 }
82
83 void HexoticPlugin_Hypothesis::SetMaxSize(double theVal) {
84   if (theVal != _maxSize) {
85           _maxSize = theVal;
86     NotifySubMeshesHypothesisModification();
87   }
88 }
89
90 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
91   if (theVal != _hexoticIgnoreRidges) {
92     _hexoticIgnoreRidges = theVal;
93     NotifySubMeshesHypothesisModification();
94   }
95 }
96
97 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
98   if (theVal != _hexoticInvalidElements) {
99     _hexoticInvalidElements = theVal;
100     NotifySubMeshesHypothesisModification();
101   }
102 }
103
104 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(double theVal) {
105   if (theVal != _hexoticSharpAngleThreshold) {
106     _hexoticSharpAngleThreshold = theVal;
107     NotifySubMeshesHypothesisModification();
108   }
109 }
110
111 void HexoticPlugin_Hypothesis::SetHexoticNbProc(int theVal) {
112   if (theVal != _hexoticNbProc) {
113     _hexoticNbProc = theVal;
114     NotifySubMeshesHypothesisModification();
115   }
116 }
117
118 void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& path)
119 {
120   if ( _hexoticWorkingDirectory != path ) {
121     _hexoticWorkingDirectory = path;
122     NotifySubMeshesHypothesisModification();
123   }
124 }
125
126 void HexoticPlugin_Hypothesis::SetHexoticSdMode(int theVal) {
127   if (theVal != _hexoticSdMode) {
128           _hexoticSdMode = theVal;
129     NotifySubMeshesHypothesisModification();
130   }
131 }
132
133 void HexoticPlugin_Hypothesis::SetHexoticVerbosity(int theVal) {
134   if (theVal != _hexoticVerbosity) {
135     _hexoticVerbosity = theVal;
136     NotifySubMeshesHypothesisModification();
137   }
138 }
139
140 void HexoticPlugin_Hypothesis::SetHexoticMaxMemory(int theVal) {
141   if (theVal != _hexoticMaxMemory) {
142     _hexoticMaxMemory = theVal;
143     NotifySubMeshesHypothesisModification();
144   }
145 }
146
147 //=============================================================================
148 /*!
149  *  
150  */
151 //=============================================================================
152 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
153 {
154   //explicit outputs for future code compatibility of saved .hdf
155   //save without any whitespaces!
156   int dummy = -1;
157   save<<"hexesMinLevel="<<_hexesMinLevel<<";"; 
158   save<<"hexesMaxLevel="<<_hexesMaxLevel<<";";
159   save<<"hexoticIgnoreRidges="<<(int)_hexoticIgnoreRidges<<";";
160   save<<"hexoticInvalidElements="<<(int)_hexoticInvalidElements<<";";
161   save<<"hexoticSharpAngleThreshold="<<_hexoticSharpAngleThreshold<<";";
162   save<<"hexoticNbProc="<<_hexoticNbProc<<";";
163   save<<"hexoticWorkingDirectory="<<_hexoticWorkingDirectory<<";";
164   save<<"minSize="<<_minSize<<";";
165   save<<"maxSize="<<_maxSize<<";";
166   save<<"hexoticSdMode="<<_hexoticSdMode<<";";
167   save<<"hexoticVerbosity="<<_hexoticVerbosity<<";";
168   save<<"hexoticMaxMemory="<<_hexoticMaxMemory<<";";
169   return save;
170 }
171
172 //=============================================================================
173 /*!
174  *  
175  */
176 //=============================================================================
177 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
178 {
179    //explicit inputs for future code compatibility of saved .hdf
180    bool isOK = true;
181    std::string str1,str2,str3,str4;
182
183    //save without any whitespaces!
184    isOK = (load >> str1);
185    if (!(isOK)) {
186      //defaults values assumed
187      load.clear(std::ios::badbit | load.rdstate());
188      return load;
189    }
190    int pos = 0;
191    int len = str1.length();
192    while (pos < len) {
193       int found = str1.find(';',pos);
194       str2 = str1.substr(pos,found-pos);
195       int eqpos = str2.find('=',0);
196       str3 = str2.substr(0,eqpos);
197       str4 = str2.substr(eqpos+1);
198       pos = found + 1;
199
200       if (str3=="hexesMinLevel") _hexesMinLevel = atoi(str4.c_str());
201       if (str3=="hexesMaxLevel") _hexesMaxLevel = atoi(str4.c_str());
202       if (str3=="hexoticQuadrangles") {}
203       if (str3=="hexoticIgnoreRidges") _hexoticIgnoreRidges = (bool) atoi(str4.c_str());
204       if (str3=="hexoticInvalidElements") _hexoticInvalidElements = (bool) atoi(str4.c_str());
205       if (str3=="hexoticSharpAngleThreshold") _hexoticSharpAngleThreshold = atof(str4.c_str());
206       if (str3=="hexoticNbProc") _hexoticNbProc = atoi(str4.c_str());
207       if (str3=="hexoticWorkingDirectory") _hexoticWorkingDirectory = str4;
208       if (str3=="minSize") _minSize = atof(str4.c_str());
209       if (str3=="maxSize") _maxSize = atof(str4.c_str());
210       if (str3=="hexoticSdMode") _hexoticSdMode = atoi(str4.c_str());
211       if (str3=="hexoticVerbosity") _hexoticVerbosity = atoi(str4.c_str());
212       if (str3=="hexoticMaxMemory") _hexoticMaxMemory = atoi(str4.c_str());
213    }
214    return load;
215 }
216
217 //=============================================================================
218 /*!
219  *  
220  */
221 //=============================================================================
222 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
223 {
224   return hyp.SaveTo( save );
225 }
226
227 //=============================================================================
228 /*!
229  *  
230  */
231 //=============================================================================
232 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
233 {
234   return hyp.LoadFrom( load );
235 }
236
237
238 //================================================================================
239 /*!
240  * \brief Does nothing
241  * \param theMesh - the built mesh
242  * \param theShape - the geometry of interest
243  * \retval bool - always false
244  */
245 //================================================================================
246 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
247                                                    const TopoDS_Shape& theShape)
248 {
249   return false;
250 }
251 //================================================================================
252 /*!
253  * \brief Initialize my parameter values by default parameters.
254  *  \retval bool - true if parameter values have been successfully defined
255  */
256 //================================================================================
257
258 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
259                                                        const SMESH_Mesh* /*theMesh*/)
260 {
261   return false;
262 }
263
264 //=============================================================================
265 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
266 {
267   return 6;
268 }
269
270 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
271 {
272   return 10;
273 }
274
275 double HexoticPlugin_Hypothesis::GetDefaultMinSize()
276 {
277   return 0.0;
278 }
279
280 double HexoticPlugin_Hypothesis::GetDefaultMaxSize()
281 {
282   return 0.0;
283 }
284
285 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
286 {
287   return false;
288 }
289
290 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
291 {
292   return false;
293 }
294
295 double HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
296 {
297   return 60.0;
298 }
299
300 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
301 {
302   return 4;
303 }
304
305 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
306 {
307   TCollection_AsciiString aTmpDir;
308
309   char *Tmp_dir = getenv("SALOME_TMP_DIR");
310   if(Tmp_dir != NULL) {
311     aTmpDir = Tmp_dir;
312   }
313   else {
314 #ifdef WIN32
315     aTmpDir = TCollection_AsciiString("C:\\");
316 #else
317     aTmpDir = TCollection_AsciiString("/tmp/");
318 #endif
319   }
320   return aTmpDir.ToCString();
321 }
322
323 int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()
324 {
325   return 4;
326 }
327
328 int HexoticPlugin_Hypothesis::GetDefaultHexoticVerbosity()
329 {
330   return 1;
331 }
332
333 int HexoticPlugin_Hypothesis::GetDefaultHexoticMaxMemory()
334 {
335   return 2048;
336 }
337
338