1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : HexoticPlugin_Hypothesis.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
25 #include "HexoticPlugin_Hypothesis.hxx"
26 #include <utilities.h>
28 #include <TCollection_AsciiString.hxx>
30 //=============================================================================
34 //=============================================================================
35 HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis (int hypId, int studyId,
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())
51 MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
52 _name = "Hexotic_Parameters";
56 //=============================================================================
60 //=============================================================================
62 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
63 if (theVal != _hexesMinLevel) {
64 _hexesMinLevel = theVal;
65 NotifySubMeshesHypothesisModification();
69 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
70 if (theVal != _hexesMaxLevel) {
71 _hexesMaxLevel = theVal;
72 NotifySubMeshesHypothesisModification();
76 void HexoticPlugin_Hypothesis::SetMinSize(double theVal) {
77 if (theVal != _minSize) {
79 NotifySubMeshesHypothesisModification();
83 void HexoticPlugin_Hypothesis::SetMaxSize(double theVal) {
84 if (theVal != _maxSize) {
86 NotifySubMeshesHypothesisModification();
90 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
91 if (theVal != _hexoticIgnoreRidges) {
92 _hexoticIgnoreRidges = theVal;
93 NotifySubMeshesHypothesisModification();
97 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
98 if (theVal != _hexoticInvalidElements) {
99 _hexoticInvalidElements = theVal;
100 NotifySubMeshesHypothesisModification();
104 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(double theVal) {
105 if (theVal != _hexoticSharpAngleThreshold) {
106 _hexoticSharpAngleThreshold = theVal;
107 NotifySubMeshesHypothesisModification();
111 void HexoticPlugin_Hypothesis::SetHexoticNbProc(int theVal) {
112 if (theVal != _hexoticNbProc) {
113 _hexoticNbProc = theVal;
114 NotifySubMeshesHypothesisModification();
118 void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& path)
120 if ( _hexoticWorkingDirectory != path ) {
121 _hexoticWorkingDirectory = path;
122 NotifySubMeshesHypothesisModification();
126 void HexoticPlugin_Hypothesis::SetHexoticSdMode(int theVal) {
127 if (theVal != _hexoticSdMode) {
128 _hexoticSdMode = theVal;
129 NotifySubMeshesHypothesisModification();
133 void HexoticPlugin_Hypothesis::SetHexoticVerbosity(int theVal) {
134 if (theVal != _hexoticVerbosity) {
135 _hexoticVerbosity = theVal;
136 NotifySubMeshesHypothesisModification();
140 void HexoticPlugin_Hypothesis::SetHexoticMaxMemory(int theVal) {
141 if (theVal != _hexoticMaxMemory) {
142 _hexoticMaxMemory = theVal;
143 NotifySubMeshesHypothesisModification();
147 //=============================================================================
151 //=============================================================================
152 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
154 //explicit outputs for future code compatibility of saved .hdf
155 //save without any whitespaces!
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<<";";
172 //=============================================================================
176 //=============================================================================
177 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
179 //explicit inputs for future code compatibility of saved .hdf
181 std::string str1,str2,str3,str4;
183 //save without any whitespaces!
184 isOK = (load >> str1);
186 //defaults values assumed
187 load.clear(std::ios::badbit | load.rdstate());
191 int len = str1.length();
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);
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());
217 //=============================================================================
221 //=============================================================================
222 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
224 return hyp.SaveTo( save );
227 //=============================================================================
231 //=============================================================================
232 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
234 return hyp.LoadFrom( load );
238 //================================================================================
240 * \brief Does nothing
241 * \param theMesh - the built mesh
242 * \param theShape - the geometry of interest
243 * \retval bool - always false
245 //================================================================================
246 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
247 const TopoDS_Shape& theShape)
251 //================================================================================
253 * \brief Initialize my parameter values by default parameters.
254 * \retval bool - true if parameter values have been successfully defined
256 //================================================================================
258 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
259 const SMESH_Mesh* /*theMesh*/)
264 //=============================================================================
265 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
270 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
275 double HexoticPlugin_Hypothesis::GetDefaultMinSize()
280 double HexoticPlugin_Hypothesis::GetDefaultMaxSize()
285 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
290 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
295 double HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
300 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
305 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
309 char *Tmp_dir = getenv("SALOME_TMP_DIR");
311 if(Tmp_dir == NULL) {
312 Tmp_dir = getenv("TEMP");
314 Tmp_dir = getenv("TMP");
317 if( Tmp_dir != NULL ) {
318 aTmpDir = std::string(Tmp_dir);
320 if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\';
322 if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/';
335 int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()
340 int HexoticPlugin_Hypothesis::GetDefaultHexoticVerbosity()
345 int HexoticPlugin_Hypothesis::GetDefaultHexoticMaxMemory()