1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 _hexoticSdMode(GetDefaultHexoticSdMode()),
47 _hexoticVerbosity(GetDefaultHexoticVerbosity()),
48 _hexoticMaxMemory(GetDefaultHexoticMaxMemory()),
49 _textOptions(GetDefaultTextOptions()),
50 _sizeMaps(GetDefaultHexoticSizeMaps()),
51 _hexoticWorkingDirectory( GetDefaultHexoticWorkingDirectory() ),
52 _nbLayers(GetDefaultNbLayers()),
53 _firstLayerSize(GetDefaultFirstLayerSize()),
54 _direction(GetDefaultDirection()),
55 _growth(GetDefaultGrowth()),
56 _facesWithLayers(GetDefaultFacesWithLayers()),
57 _imprintedFaces(GetDefaultImprintedFaces())
59 MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
64 //=============================================================================
68 //=============================================================================
70 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
71 if (theVal != _hexesMinLevel) {
72 _hexesMinLevel = theVal;
73 NotifySubMeshesHypothesisModification();
77 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
78 if (theVal != _hexesMaxLevel) {
79 _hexesMaxLevel = theVal;
80 NotifySubMeshesHypothesisModification();
84 void HexoticPlugin_Hypothesis::SetMinSize(double theVal) {
85 if (theVal != _minSize) {
87 NotifySubMeshesHypothesisModification();
91 void HexoticPlugin_Hypothesis::SetMaxSize(double theVal) {
92 if (theVal != _maxSize) {
94 NotifySubMeshesHypothesisModification();
98 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
99 if (theVal != _hexoticIgnoreRidges) {
100 _hexoticIgnoreRidges = theVal;
101 NotifySubMeshesHypothesisModification();
105 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
106 if (theVal != _hexoticInvalidElements) {
107 _hexoticInvalidElements = theVal;
108 NotifySubMeshesHypothesisModification();
112 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(double theVal) {
113 if (theVal != _hexoticSharpAngleThreshold) {
114 _hexoticSharpAngleThreshold = theVal;
115 NotifySubMeshesHypothesisModification();
119 void HexoticPlugin_Hypothesis::SetHexoticNbProc(int theVal) {
120 if (theVal != _hexoticNbProc) {
121 _hexoticNbProc = theVal;
122 NotifySubMeshesHypothesisModification();
126 void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& path)
128 if ( _hexoticWorkingDirectory != path ) {
129 _hexoticWorkingDirectory = path;
133 if( path[ path.size()-1 ] != '\\')
134 _hexoticWorkingDirectory += '\\';
136 if( path[ path.size()-1 ] != '/')
137 _hexoticWorkingDirectory += '/';
140 NotifySubMeshesHypothesisModification();
144 void HexoticPlugin_Hypothesis::SetHexoticSdMode(int theVal) {
145 if (theVal != _hexoticSdMode) {
146 _hexoticSdMode = theVal;
147 NotifySubMeshesHypothesisModification();
151 void HexoticPlugin_Hypothesis::SetHexoticVerbosity(int theVal) {
152 if (theVal != _hexoticVerbosity) {
153 _hexoticVerbosity = theVal;
154 NotifySubMeshesHypothesisModification();
158 void HexoticPlugin_Hypothesis::SetHexoticMaxMemory(int theVal) {
159 if (theVal != _hexoticMaxMemory) {
160 _hexoticMaxMemory = theVal;
161 NotifySubMeshesHypothesisModification();
165 void HexoticPlugin_Hypothesis::SetTextOptions(const std::string& theOptions)
167 if (_textOptions != theOptions ) {
168 _textOptions = theOptions;
169 NotifySubMeshesHypothesisModification();
173 bool HexoticPlugin_Hypothesis::AddSizeMap(std::string theEntry, double theSize) {
174 THexoticSizeMaps::iterator it;
175 it=_sizeMaps.find(theEntry);
180 if( it == _sizeMaps.end() ) // If no size map is defined on the given object
182 _sizeMaps[theEntry] = theSize;
183 MESSAGE("NEW size map, entry :"<<theEntry<<", size : "<<theSize);
184 NotifySubMeshesHypothesisModification();
187 else if( it->second != theSize ) // If a size map exists with a different size value
189 it->second = theSize;
190 MESSAGE("MODIFIED size map, entry :"<<theEntry<<"with size : "<<theSize);
191 NotifySubMeshesHypothesisModification();
196 MESSAGE("NO size map added")
197 return false; // No size map added
201 bool HexoticPlugin_Hypothesis::UnsetSizeMap(std::string theEntry) {
202 THexoticSizeMaps::iterator it;
203 it=_sizeMaps.find(theEntry);
204 if( it != _sizeMaps.end() )
213 void HexoticPlugin_Hypothesis::SetNbLayers(int theVal) {
214 if (theVal != _nbLayers) {
216 NotifySubMeshesHypothesisModification();
220 void HexoticPlugin_Hypothesis::SetFirstLayerSize(double theVal) {
221 if (theVal != _firstLayerSize) {
222 _firstLayerSize = theVal;
223 NotifySubMeshesHypothesisModification();
227 void HexoticPlugin_Hypothesis::SetDirection(bool theVal) {
228 if (theVal != _direction) {
230 NotifySubMeshesHypothesisModification();
234 void HexoticPlugin_Hypothesis::SetGrowth(double theVal) {
235 if (theVal != _growth) {
237 NotifySubMeshesHypothesisModification();
241 bool HexoticPlugin_Hypothesis::SetFacesWithLayers(const std::vector<int>& theVal) {
242 if ( _facesWithLayers != theVal ) {
243 _facesWithLayers = theVal;
244 NotifySubMeshesHypothesisModification();
250 bool HexoticPlugin_Hypothesis::SetImprintedFaces(const std::vector<int>& theVal) {
251 if ( _imprintedFaces != theVal ) {
252 _imprintedFaces = theVal;
253 NotifySubMeshesHypothesisModification();
259 //=============================================================================
263 //=============================================================================
264 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
266 //explicit outputs for future code compatibility of saved .hdf
267 //save without any whitespaces!
269 save<<"hexesMinLevel="<<_hexesMinLevel<<";";
270 save<<"hexesMaxLevel="<<_hexesMaxLevel<<";";
271 save<<"hexoticIgnoreRidges="<<(int)_hexoticIgnoreRidges<<";";
272 save<<"hexoticInvalidElements="<<(int)_hexoticInvalidElements<<";";
273 save<<"hexoticSharpAngleThreshold="<<_hexoticSharpAngleThreshold<<";";
274 save<<"hexoticNbProc="<<_hexoticNbProc<<";";
275 save<<"hexoticWorkingDirectory="<<_hexoticWorkingDirectory<<";";
276 save<<"minSize="<<_minSize<<";";
277 save<<"maxSize="<<_maxSize<<";";
278 save<<"hexoticSdMode="<<_hexoticSdMode<<";";
279 save<<"hexoticVerbosity="<<_hexoticVerbosity<<";";
280 save<<"hexoticMaxMemory="<<_hexoticMaxMemory<<";";
281 replace(_textOptions.begin(), _textOptions.end(), ' ', '*');
282 save<<"textOptions="<<_textOptions<<";";
283 THexoticSizeMaps::iterator it = _sizeMaps.begin();
284 if ( it != _sizeMaps.end() )
287 for ( ; it!=_sizeMaps.end() ; it++ )
289 save<< it->first << "/" << it->second << "#" ;
293 save<<"nbLayers="<<_nbLayers<<";";
294 save<<"firstLayerSize="<<_firstLayerSize<<";";
295 save<<"direction="<<_direction<<";";
296 save<<"growth="<<_growth<<";";
297 if ( !_facesWithLayers.empty() )
299 save<<"facesWithLayers=";
300 for ( size_t i = 0; i < _facesWithLayers.size(); i++ )
302 save<< _facesWithLayers.at(i) << "#" ;
306 if ( !_imprintedFaces.empty() )
308 save<<"imprintedFaces=";
309 for ( size_t i = 0; i < _imprintedFaces.size(); i++ )
311 save<< _imprintedFaces.at(i) << "#" ;
318 //=============================================================================
322 //=============================================================================
323 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
325 //explicit inputs for future code compatibility of saved .hdf
327 std::string str1,str2,str3,str4;
329 //save without any whitespaces!
330 isOK = static_cast<bool>(load >> str1);
332 //defaults values assumed
333 load.clear(std::ios::badbit | load.rdstate());
337 int len = str1.length();
339 int found = str1.find(';',pos);
340 str2 = str1.substr(pos,found-pos);
341 int eqpos = str2.find('=',0);
342 str3 = str2.substr(0,eqpos);
343 str4 = str2.substr(eqpos+1);
346 if (str3=="hexesMinLevel") _hexesMinLevel = atoi(str4.c_str());
347 if (str3=="hexesMaxLevel") _hexesMaxLevel = atoi(str4.c_str());
348 if (str3=="hexoticQuadrangles") {}
349 if (str3=="hexoticIgnoreRidges") _hexoticIgnoreRidges = (bool) atoi(str4.c_str());
350 if (str3=="hexoticInvalidElements") _hexoticInvalidElements = (bool) atoi(str4.c_str());
351 if (str3=="hexoticSharpAngleThreshold") _hexoticSharpAngleThreshold = atof(str4.c_str());
352 if (str3=="hexoticNbProc") _hexoticNbProc = atoi(str4.c_str());
353 if (str3=="hexoticWorkingDirectory") _hexoticWorkingDirectory = str4;
354 if (str3=="minSize") _minSize = atof(str4.c_str());
355 if (str3=="maxSize") _maxSize = atof(str4.c_str());
356 if (str3=="hexoticSdMode") _hexoticSdMode = atoi(str4.c_str());
357 if (str3=="hexoticVerbosity") _hexoticVerbosity = atoi(str4.c_str());
358 if (str3=="hexoticMaxMemory") _hexoticMaxMemory = atoi(str4.c_str());
359 if (str3=="textOptions")
361 replace(str4.begin(), str4.end(), '*', ' ');
364 if (str3=="sizeMaps")
366 std::string sm_substr, sm_substr1, sm_substr2;
368 int sm_len = str4.length();
369 while ( sm_pos < sm_len )
371 int sm_found = str4.find('#',sm_pos);
372 sm_substr = str4.substr(sm_pos,sm_found-sm_pos);
373 int sm_slashpos = sm_substr.find('/',0);
374 sm_substr1 = sm_substr.substr(0,sm_slashpos);
375 sm_substr2 = sm_substr.substr(sm_slashpos+1);
376 _sizeMaps[sm_substr1] = atof(sm_substr2.c_str());
377 sm_pos = sm_found + 1;
380 if (str3 == "nbLayers") _nbLayers = atoi(str4.c_str());
381 if (str3 == "firstLayerSize") _firstLayerSize = atof(str4.c_str());
382 if (str3 == "direction") _direction = atoi(str4.c_str());
383 if (str3 == "growth") _growth = atof(str4.c_str());
384 if (str3 == "facesWithLayers")
388 while ( pos < str4.length() )
390 int found = str4.find('#',pos);
391 id = str4.substr(pos, found-pos);
392 _facesWithLayers.push_back(atoi(id.c_str()));
396 if (str3 == "imprintedFaces")
400 while ( pos < str4.length() )
402 int found = str4.find('#',pos);
403 id = str4.substr(pos, found-pos);
404 _imprintedFaces.push_back(atoi(id.c_str()));
412 //=============================================================================
416 //=============================================================================
417 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
419 return hyp.SaveTo( save );
422 //=============================================================================
426 //=============================================================================
427 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
429 return hyp.LoadFrom( load );
433 //================================================================================
435 * \brief Does nothing
436 * \param theMesh - the built mesh
437 * \param theShape - the geometry of interest
438 * \retval bool - always false
440 //================================================================================
441 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
442 const TopoDS_Shape& theShape)
446 //================================================================================
448 * \brief Initialize my parameter values by default parameters.
449 * \retval bool - true if parameter values have been successfully defined
451 //================================================================================
453 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
454 const SMESH_Mesh* /*theMesh*/)
459 //=============================================================================
460 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
465 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
470 double HexoticPlugin_Hypothesis::GetDefaultMinSize()
475 double HexoticPlugin_Hypothesis::GetDefaultMaxSize()
480 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
485 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
490 double HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
495 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
500 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
504 char *Tmp_dir = getenv("SALOME_TMP_DIR");
506 if(Tmp_dir == NULL) {
507 Tmp_dir = getenv("TEMP");
509 Tmp_dir = getenv("TMP");
512 if( Tmp_dir != NULL ) {
513 aTmpDir = std::string(Tmp_dir);
515 if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\';
517 if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/';
530 int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()
535 int HexoticPlugin_Hypothesis::GetDefaultHexoticVerbosity()
540 int HexoticPlugin_Hypothesis::GetDefaultHexoticMaxMemory()
545 std::string HexoticPlugin_Hypothesis::GetDefaultTextOptions()
550 HexoticPlugin_Hypothesis::THexoticSizeMaps HexoticPlugin_Hypothesis::GetDefaultHexoticSizeMaps()
552 return THexoticSizeMaps();
555 int HexoticPlugin_Hypothesis::GetDefaultNbLayers()
560 double HexoticPlugin_Hypothesis::GetDefaultFirstLayerSize()
565 bool HexoticPlugin_Hypothesis::GetDefaultDirection()
570 double HexoticPlugin_Hypothesis::GetDefaultGrowth()
575 std::vector<int> HexoticPlugin_Hypothesis::GetDefaultFacesWithLayers()
577 return std::vector<int>();
580 std::vector<int> HexoticPlugin_Hypothesis::GetDefaultImprintedFaces()
582 return std::vector<int>();