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