1 // Copyright (C) 2007-2012 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())
50 MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
51 _name = "Hexotic_Parameters";
55 //=============================================================================
59 //=============================================================================
61 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
62 if (theVal != _hexesMinLevel) {
63 _hexesMinLevel = theVal;
64 NotifySubMeshesHypothesisModification();
68 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
69 if (theVal != _hexesMaxLevel) {
70 _hexesMaxLevel = theVal;
71 NotifySubMeshesHypothesisModification();
75 void HexoticPlugin_Hypothesis::SetMinSize(double theVal) {
76 if (theVal != _minSize) {
78 NotifySubMeshesHypothesisModification();
82 void HexoticPlugin_Hypothesis::SetMaxSize(double theVal) {
83 if (theVal != _maxSize) {
85 NotifySubMeshesHypothesisModification();
89 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
90 if (theVal != _hexoticIgnoreRidges) {
91 _hexoticIgnoreRidges = theVal;
92 NotifySubMeshesHypothesisModification();
96 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
97 if (theVal != _hexoticInvalidElements) {
98 _hexoticInvalidElements = theVal;
99 NotifySubMeshesHypothesisModification();
103 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(double theVal) {
104 if (theVal != _hexoticSharpAngleThreshold) {
105 _hexoticSharpAngleThreshold = theVal;
106 NotifySubMeshesHypothesisModification();
110 void HexoticPlugin_Hypothesis::SetHexoticNbProc(int theVal) {
111 if (theVal != _hexoticNbProc) {
112 _hexoticNbProc = theVal;
113 NotifySubMeshesHypothesisModification();
117 void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& path)
119 if ( _hexoticWorkingDirectory != path ) {
120 _hexoticWorkingDirectory = path;
121 NotifySubMeshesHypothesisModification();
125 void HexoticPlugin_Hypothesis::SetHexoticSdMode(int theVal) {
126 if (theVal != _hexoticSdMode) {
127 _hexoticSdMode = theVal;
128 NotifySubMeshesHypothesisModification();
132 void HexoticPlugin_Hypothesis::SetHexoticVerbosity(int theVal) {
133 if (theVal != _hexoticVerbosity) {
134 _hexoticVerbosity = theVal;
135 NotifySubMeshesHypothesisModification();
139 //=============================================================================
143 //=============================================================================
144 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
146 //explicit outputs for future code compatibility of saved .hdf
147 //save without any whitespaces!
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<<";";
163 //=============================================================================
167 //=============================================================================
168 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
170 //explicit inputs for future code compatibility of saved .hdf
172 std::string str1,str2,str3,str4;
174 //save without any whitespaces!
175 isOK = (load >> str1);
177 //defaults values assumed
178 load.clear(std::ios::badbit | load.rdstate());
182 int len = str1.length();
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);
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());
207 //=============================================================================
211 //=============================================================================
212 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
214 return hyp.SaveTo( save );
217 //=============================================================================
221 //=============================================================================
222 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
224 return hyp.LoadFrom( load );
228 //================================================================================
230 * \brief Does nothing
231 * \param theMesh - the built mesh
232 * \param theShape - the geometry of interest
233 * \retval bool - always false
235 //================================================================================
236 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
237 const TopoDS_Shape& theShape)
241 //================================================================================
243 * \brief Initialize my parameter values by default parameters.
244 * \retval bool - true if parameter values have been successfully defined
246 //================================================================================
248 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
249 const SMESH_Mesh* /*theMesh*/)
254 //=============================================================================
255 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
260 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
265 double HexoticPlugin_Hypothesis::GetDefaultMinSize()
270 double HexoticPlugin_Hypothesis::GetDefaultMaxSize()
275 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
280 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
285 double HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
290 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
295 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
297 TCollection_AsciiString aTmpDir;
299 char *Tmp_dir = getenv("SALOME_TMP_DIR");
300 if(Tmp_dir != NULL) {
305 aTmpDir = TCollection_AsciiString("C:\\");
307 aTmpDir = TCollection_AsciiString("/tmp/");
310 return aTmpDir.ToCString();
313 int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()
318 int HexoticPlugin_Hypothesis::GetDefaultHexoticVerbosity()