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()),
50 _sizeMaps(GetDefaultHexoticSizeMaps())
52 MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
53 _name = "Hexotic_Parameters";
57 //=============================================================================
61 //=============================================================================
63 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
64 if (theVal != _hexesMinLevel) {
65 _hexesMinLevel = theVal;
66 NotifySubMeshesHypothesisModification();
70 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
71 if (theVal != _hexesMaxLevel) {
72 _hexesMaxLevel = theVal;
73 NotifySubMeshesHypothesisModification();
77 void HexoticPlugin_Hypothesis::SetMinSize(double theVal) {
78 if (theVal != _minSize) {
80 NotifySubMeshesHypothesisModification();
84 void HexoticPlugin_Hypothesis::SetMaxSize(double theVal) {
85 if (theVal != _maxSize) {
87 NotifySubMeshesHypothesisModification();
91 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
92 if (theVal != _hexoticIgnoreRidges) {
93 _hexoticIgnoreRidges = theVal;
94 NotifySubMeshesHypothesisModification();
98 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
99 if (theVal != _hexoticInvalidElements) {
100 _hexoticInvalidElements = theVal;
101 NotifySubMeshesHypothesisModification();
105 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(double theVal) {
106 if (theVal != _hexoticSharpAngleThreshold) {
107 _hexoticSharpAngleThreshold = theVal;
108 NotifySubMeshesHypothesisModification();
112 void HexoticPlugin_Hypothesis::SetHexoticNbProc(int theVal) {
113 if (theVal != _hexoticNbProc) {
114 _hexoticNbProc = theVal;
115 NotifySubMeshesHypothesisModification();
119 void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& path)
121 if ( _hexoticWorkingDirectory != path ) {
122 _hexoticWorkingDirectory = path;
123 NotifySubMeshesHypothesisModification();
127 void HexoticPlugin_Hypothesis::SetHexoticSdMode(int theVal) {
128 if (theVal != _hexoticSdMode) {
129 _hexoticSdMode = theVal;
130 NotifySubMeshesHypothesisModification();
134 void HexoticPlugin_Hypothesis::SetHexoticVerbosity(int theVal) {
135 if (theVal != _hexoticVerbosity) {
136 _hexoticVerbosity = theVal;
137 NotifySubMeshesHypothesisModification();
141 void HexoticPlugin_Hypothesis::SetHexoticMaxMemory(int theVal) {
142 if (theVal != _hexoticMaxMemory) {
143 _hexoticMaxMemory = theVal;
144 NotifySubMeshesHypothesisModification();
148 bool HexoticPlugin_Hypothesis::AddSizeMap(std::string theEntry, double theSize) {
149 THexoticSizeMaps::iterator it;
150 it=_sizeMaps.find(theEntry);
155 if( it == _sizeMaps.end() ) // If no size map is defined on the given object
157 _sizeMaps[theEntry] = theSize;
158 MESSAGE("NEW size map, entry :"<<theEntry<<", size : "<<theSize);
159 NotifySubMeshesHypothesisModification();
162 else if( it->second != theSize ) // If a size map exists with a different size value
164 it->second = theSize;
165 MESSAGE("MODIFIED size map, entry :"<<theEntry<<"with size : "<<theSize);
166 NotifySubMeshesHypothesisModification();
171 MESSAGE("NO size map added")
172 return false; // No size map added
176 bool HexoticPlugin_Hypothesis::UnsetSizeMap(std::string theEntry) {
177 THexoticSizeMaps::iterator it;
178 it=_sizeMaps.find(theEntry);
179 if( it != _sizeMaps.end() )
188 //=============================================================================
192 //=============================================================================
193 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
195 //explicit outputs for future code compatibility of saved .hdf
196 //save without any whitespaces!
198 save<<"hexesMinLevel="<<_hexesMinLevel<<";";
199 save<<"hexesMaxLevel="<<_hexesMaxLevel<<";";
200 save<<"hexoticIgnoreRidges="<<(int)_hexoticIgnoreRidges<<";";
201 save<<"hexoticInvalidElements="<<(int)_hexoticInvalidElements<<";";
202 save<<"hexoticSharpAngleThreshold="<<_hexoticSharpAngleThreshold<<";";
203 save<<"hexoticNbProc="<<_hexoticNbProc<<";";
204 save<<"hexoticWorkingDirectory="<<_hexoticWorkingDirectory<<";";
205 save<<"minSize="<<_minSize<<";";
206 save<<"maxSize="<<_maxSize<<";";
207 save<<"hexoticSdMode="<<_hexoticSdMode<<";";
208 save<<"hexoticVerbosity="<<_hexoticVerbosity<<";";
209 save<<"hexoticMaxMemory="<<_hexoticMaxMemory<<";";
210 THexoticSizeMaps::iterator it = _sizeMaps.begin();
211 if ( it != _sizeMaps.end() )
214 for ( ; it!=_sizeMaps.end() ; it++ )
216 save<< it->first << "/" << it->second << "#" ;
223 //=============================================================================
227 //=============================================================================
228 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
230 //explicit inputs for future code compatibility of saved .hdf
232 std::string str1,str2,str3,str4;
234 //save without any whitespaces!
235 isOK = (load >> str1);
237 //defaults values assumed
238 load.clear(std::ios::badbit | load.rdstate());
242 int len = str1.length();
244 int found = str1.find(';',pos);
245 str2 = str1.substr(pos,found-pos);
246 int eqpos = str2.find('=',0);
247 str3 = str2.substr(0,eqpos);
248 str4 = str2.substr(eqpos+1);
251 if (str3=="hexesMinLevel") _hexesMinLevel = atoi(str4.c_str());
252 if (str3=="hexesMaxLevel") _hexesMaxLevel = atoi(str4.c_str());
253 if (str3=="hexoticQuadrangles") {}
254 if (str3=="hexoticIgnoreRidges") _hexoticIgnoreRidges = (bool) atoi(str4.c_str());
255 if (str3=="hexoticInvalidElements") _hexoticInvalidElements = (bool) atoi(str4.c_str());
256 if (str3=="hexoticSharpAngleThreshold") _hexoticSharpAngleThreshold = atof(str4.c_str());
257 if (str3=="hexoticNbProc") _hexoticNbProc = atoi(str4.c_str());
258 if (str3=="hexoticWorkingDirectory") _hexoticWorkingDirectory = str4;
259 if (str3=="minSize") _minSize = atof(str4.c_str());
260 if (str3=="maxSize") _maxSize = atof(str4.c_str());
261 if (str3=="hexoticSdMode") _hexoticSdMode = atoi(str4.c_str());
262 if (str3=="hexoticVerbosity") _hexoticVerbosity = atoi(str4.c_str());
263 if (str3=="hexoticMaxMemory") _hexoticMaxMemory = atoi(str4.c_str());
264 if (str3=="sizeMaps")
266 std::string sm_substr, sm_substr1, sm_substr2;
268 int sm_len = str4.length();
269 while ( sm_pos < sm_len )
271 int sm_found = str4.find('#',sm_pos);
272 sm_substr = str4.substr(sm_pos,sm_found-sm_pos);
273 int sm_slashpos = sm_substr.find('/',0);
274 sm_substr1 = sm_substr.substr(0,sm_slashpos);
275 sm_substr2 = sm_substr.substr(sm_slashpos+1);
276 _sizeMaps[sm_substr1] = atof(sm_substr2.c_str());
277 sm_pos = sm_found + 1;
284 //=============================================================================
288 //=============================================================================
289 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
291 return hyp.SaveTo( save );
294 //=============================================================================
298 //=============================================================================
299 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
301 return hyp.LoadFrom( load );
305 //================================================================================
307 * \brief Does nothing
308 * \param theMesh - the built mesh
309 * \param theShape - the geometry of interest
310 * \retval bool - always false
312 //================================================================================
313 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
314 const TopoDS_Shape& theShape)
318 //================================================================================
320 * \brief Initialize my parameter values by default parameters.
321 * \retval bool - true if parameter values have been successfully defined
323 //================================================================================
325 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
326 const SMESH_Mesh* /*theMesh*/)
331 //=============================================================================
332 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
337 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
342 double HexoticPlugin_Hypothesis::GetDefaultMinSize()
347 double HexoticPlugin_Hypothesis::GetDefaultMaxSize()
352 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
357 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
362 double HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
367 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
372 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
376 char *Tmp_dir = getenv("SALOME_TMP_DIR");
378 if(Tmp_dir == NULL) {
379 Tmp_dir = getenv("TEMP");
381 Tmp_dir = getenv("TMP");
384 if( Tmp_dir != NULL ) {
385 aTmpDir = std::string(Tmp_dir);
387 if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\';
389 if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/';
402 int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()
407 int HexoticPlugin_Hypothesis::GetDefaultHexoticVerbosity()
412 int HexoticPlugin_Hypothesis::GetDefaultHexoticMaxMemory()
417 HexoticPlugin_Hypothesis::THexoticSizeMaps HexoticPlugin_Hypothesis::GetDefaultHexoticSizeMaps()
419 return THexoticSizeMaps();