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 _hexoticQuadrangles( GetDefaultHexoticQuadrangles() ),
41 _hexoticIgnoreRidges( GetDefaultHexoticIgnoreRidges() ),
42 _hexoticInvalidElements( GetDefaultHexoticInvalidElements() ),
43 _hexoticSharpAngleThreshold( GetDefaultHexoticSharpAngleThreshold() ),
44 _hexoticNbProc( GetDefaultHexoticNbProc() ),
45 _hexoticWorkingDirectory( GetDefaultHexoticWorkingDirectory() )
47 MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
48 _name = "Hexotic_Parameters";
52 //=============================================================================
56 //=============================================================================
58 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
59 if (theVal != _hexesMinLevel) {
60 _hexesMinLevel = theVal;
61 NotifySubMeshesHypothesisModification();
65 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
66 if (theVal != _hexesMaxLevel) {
67 _hexesMaxLevel = theVal;
68 NotifySubMeshesHypothesisModification();
72 void HexoticPlugin_Hypothesis::SetHexoticQuadrangles(bool theVal) {
73 if (theVal != _hexoticQuadrangles) {
74 _hexoticQuadrangles = theVal;
75 NotifySubMeshesHypothesisModification();
79 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
80 if (theVal != _hexoticIgnoreRidges) {
81 _hexoticIgnoreRidges = theVal;
82 NotifySubMeshesHypothesisModification();
86 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
87 if (theVal != _hexoticInvalidElements) {
88 _hexoticInvalidElements = theVal;
89 NotifySubMeshesHypothesisModification();
93 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(int theVal) {
94 if (theVal != _hexoticSharpAngleThreshold) {
95 _hexoticSharpAngleThreshold = theVal;
96 NotifySubMeshesHypothesisModification();
100 void HexoticPlugin_Hypothesis::SetHexoticNbProc(int theVal) {
101 if (theVal != _hexoticNbProc) {
102 _hexoticNbProc = theVal;
103 NotifySubMeshesHypothesisModification();
107 void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& path)
109 if ( _hexoticWorkingDirectory != path ) {
110 _hexoticWorkingDirectory = path;
111 NotifySubMeshesHypothesisModification();
115 //=============================================================================
119 //=============================================================================
120 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
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;*/
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<<";";
144 //=============================================================================
148 //=============================================================================
149 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
151 //explicit inputs for future code compatibility of saved .hdf
153 std::string str1,str2,str3,str4;
155 //save without any whitespaces!
156 isOK = (load >> str1);
158 //defaults values assumed
159 load.clear(std::ios::badbit | load.rdstate());
163 int len = str1.length();
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);
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;
184 //=============================================================================
188 //=============================================================================
189 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
191 return hyp.SaveTo( save );
194 //=============================================================================
198 //=============================================================================
199 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
201 return hyp.LoadFrom( load );
205 //================================================================================
207 * \brief Does nothing
208 * \param theMesh - the built mesh
209 * \param theShape - the geometry of interest
210 * \retval bool - always false
212 //================================================================================
213 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
214 const TopoDS_Shape& theShape)
218 //================================================================================
220 * \brief Initialize my parameter values by default parameters.
221 * \retval bool - true if parameter values have been successfully defined
223 //================================================================================
225 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
226 const SMESH_Mesh* /*theMesh*/)
231 //=============================================================================
232 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
237 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
242 bool HexoticPlugin_Hypothesis::GetDefaultHexoticQuadrangles()
247 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
252 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
257 int HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
262 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
267 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
269 TCollection_AsciiString aTmpDir;
271 char *Tmp_dir = getenv("SALOME_TMP_DIR");
272 if(Tmp_dir != NULL) {
277 aTmpDir = TCollection_AsciiString("C:\\");
279 aTmpDir = TCollection_AsciiString("/tmp/");
282 return aTmpDir.ToCString();