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