1 // Copyright (C) 2007-2016 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::SetAdvancedOption(const std::string& theOptions)
167 if (_textOptions != theOptions ) {
168 _textOptions = theOptions;
169 NotifySubMeshesHypothesisModification();
172 void HexoticPlugin_Hypothesis::SetTextOptions(const std::string& theOptions)
174 if (_textOptions != theOptions ) {
175 _textOptions = theOptions;
176 NotifySubMeshesHypothesisModification();
180 bool HexoticPlugin_Hypothesis::AddSizeMap(std::string theEntry, double theSize) {
181 THexoticSizeMaps::iterator it;
182 it=_sizeMaps.find(theEntry);
187 if( it == _sizeMaps.end() ) // If no size map is defined on the given object
189 _sizeMaps[theEntry] = theSize;
190 MESSAGE("NEW size map, entry :"<<theEntry<<", size : "<<theSize);
191 NotifySubMeshesHypothesisModification();
194 else if( it->second != theSize ) // If a size map exists with a different size value
196 it->second = theSize;
197 MESSAGE("MODIFIED size map, entry :"<<theEntry<<"with size : "<<theSize);
198 NotifySubMeshesHypothesisModification();
203 MESSAGE("NO size map added")
204 return false; // No size map added
208 bool HexoticPlugin_Hypothesis::UnsetSizeMap(std::string theEntry) {
209 THexoticSizeMaps::iterator it;
210 it=_sizeMaps.find(theEntry);
211 if( it != _sizeMaps.end() )
220 void HexoticPlugin_Hypothesis::SetNbLayers(int theVal) {
221 if (theVal != _nbLayers) {
223 NotifySubMeshesHypothesisModification();
227 void HexoticPlugin_Hypothesis::SetFirstLayerSize(double theVal) {
228 if (theVal != _firstLayerSize) {
229 _firstLayerSize = theVal;
230 NotifySubMeshesHypothesisModification();
234 void HexoticPlugin_Hypothesis::SetDirection(bool theVal) {
235 if (theVal != _direction) {
237 NotifySubMeshesHypothesisModification();
241 void HexoticPlugin_Hypothesis::SetGrowth(double theVal) {
242 if (theVal != _growth) {
244 NotifySubMeshesHypothesisModification();
248 bool HexoticPlugin_Hypothesis::SetFacesWithLayers(const std::vector<int>& theVal) {
249 if ( _facesWithLayers != theVal ) {
250 _facesWithLayers = theVal;
251 NotifySubMeshesHypothesisModification();
257 bool HexoticPlugin_Hypothesis::SetImprintedFaces(const std::vector<int>& theVal) {
258 if ( _imprintedFaces != theVal ) {
259 _imprintedFaces = theVal;
260 NotifySubMeshesHypothesisModification();
266 //=============================================================================
270 //=============================================================================
271 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
273 //explicit outputs for future code compatibility of saved .hdf
274 //save without any whitespaces!
276 save<<"hexesMinLevel="<<_hexesMinLevel<<";";
277 save<<"hexesMaxLevel="<<_hexesMaxLevel<<";";
278 save<<"hexoticIgnoreRidges="<<(int)_hexoticIgnoreRidges<<";";
279 save<<"hexoticInvalidElements="<<(int)_hexoticInvalidElements<<";";
280 save<<"hexoticSharpAngleThreshold="<<_hexoticSharpAngleThreshold<<";";
281 save<<"hexoticNbProc="<<_hexoticNbProc<<";";
282 save<<"hexoticWorkingDirectory="<<_hexoticWorkingDirectory<<";";
283 save<<"minSize="<<_minSize<<";";
284 save<<"maxSize="<<_maxSize<<";";
285 save<<"hexoticSdMode="<<_hexoticSdMode<<";";
286 save<<"hexoticVerbosity="<<_hexoticVerbosity<<";";
287 save<<"hexoticMaxMemory="<<_hexoticMaxMemory<<";";
288 std::string textOptions = _textOptions; // save _textOptions
289 replace(textOptions.begin(), textOptions.end(), ' ', '*');
290 save<<"textOptions="<<textOptions<<";";
291 THexoticSizeMaps::iterator it = _sizeMaps.begin();
292 if ( it != _sizeMaps.end() )
295 for ( ; it!=_sizeMaps.end() ; it++ )
297 save<< it->first << "/" << it->second << "#" ;
301 save<<"nbLayers="<<_nbLayers<<";";
302 save<<"firstLayerSize="<<_firstLayerSize<<";";
303 save<<"direction="<<_direction<<";";
304 save<<"growth="<<_growth<<";";
305 if ( !_facesWithLayers.empty() )
307 save<<"facesWithLayers=";
308 for ( size_t i = 0; i < _facesWithLayers.size(); i++ )
310 save<< _facesWithLayers.at(i) << "#" ;
314 if ( !_imprintedFaces.empty() )
316 save<<"imprintedFaces=";
317 for ( size_t i = 0; i < _imprintedFaces.size(); i++ )
319 save<< _imprintedFaces.at(i) << "#" ;
326 //=============================================================================
330 //=============================================================================
331 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
333 //explicit inputs for future code compatibility of saved .hdf
335 std::string str1,str2,str3,str4;
337 //save without any whitespaces!
338 isOK = static_cast<bool>(load >> str1);
340 //defaults values assumed
341 load.clear(std::ios::badbit | load.rdstate());
345 int len = str1.length();
347 int found = str1.find(';',pos);
348 str2 = str1.substr(pos,found-pos);
349 int eqpos = str2.find('=',0);
350 str3 = str2.substr(0,eqpos);
351 str4 = str2.substr(eqpos+1);
354 if (str3=="hexesMinLevel") _hexesMinLevel = atoi(str4.c_str());
355 if (str3=="hexesMaxLevel") _hexesMaxLevel = atoi(str4.c_str());
356 if (str3=="hexoticQuadrangles") {}
357 if (str3=="hexoticIgnoreRidges") _hexoticIgnoreRidges = (bool) atoi(str4.c_str());
358 if (str3=="hexoticInvalidElements") _hexoticInvalidElements = (bool) atoi(str4.c_str());
359 if (str3=="hexoticSharpAngleThreshold") _hexoticSharpAngleThreshold = atof(str4.c_str());
360 if (str3=="hexoticNbProc") _hexoticNbProc = atoi(str4.c_str());
361 if (str3=="hexoticWorkingDirectory") _hexoticWorkingDirectory = str4;
362 if (str3=="minSize") _minSize = atof(str4.c_str());
363 if (str3=="maxSize") _maxSize = atof(str4.c_str());
364 if (str3=="hexoticSdMode") _hexoticSdMode = atoi(str4.c_str());
365 if (str3=="hexoticVerbosity") _hexoticVerbosity = atoi(str4.c_str());
366 if (str3=="hexoticMaxMemory") _hexoticMaxMemory = atoi(str4.c_str());
367 if (str3=="textOptions")
369 replace(str4.begin(), str4.end(), '*', ' ');
372 if (str3=="sizeMaps")
374 std::string sm_substr, sm_substr1, sm_substr2;
376 int sm_len = str4.length();
377 while ( sm_pos < sm_len )
379 int sm_found = str4.find('#',sm_pos);
380 sm_substr = str4.substr(sm_pos,sm_found-sm_pos);
381 int sm_slashpos = sm_substr.find('/',0);
382 sm_substr1 = sm_substr.substr(0,sm_slashpos);
383 sm_substr2 = sm_substr.substr(sm_slashpos+1);
384 _sizeMaps[sm_substr1] = atof(sm_substr2.c_str());
385 sm_pos = sm_found + 1;
388 if (str3 == "nbLayers") _nbLayers = atoi(str4.c_str());
389 if (str3 == "firstLayerSize") _firstLayerSize = atof(str4.c_str());
390 if (str3 == "direction") _direction = atoi(str4.c_str());
391 if (str3 == "growth") _growth = atof(str4.c_str());
392 if (str3 == "facesWithLayers")
396 while ( pos < str4.length() )
398 int found = str4.find('#',pos);
399 id = str4.substr(pos, found-pos);
400 _facesWithLayers.push_back(atoi(id.c_str()));
404 if (str3 == "imprintedFaces")
408 while ( pos < str4.length() )
410 int found = str4.find('#',pos);
411 id = str4.substr(pos, found-pos);
412 _imprintedFaces.push_back(atoi(id.c_str()));
420 //=============================================================================
424 //=============================================================================
425 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
427 return hyp.SaveTo( save );
430 //=============================================================================
434 //=============================================================================
435 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
437 return hyp.LoadFrom( load );
441 //================================================================================
443 * \brief Does nothing
444 * \param theMesh - the built mesh
445 * \param theShape - the geometry of interest
446 * \retval bool - always false
448 //================================================================================
449 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
450 const TopoDS_Shape& theShape)
454 //================================================================================
456 * \brief Initialize my parameter values by default parameters.
457 * \retval bool - true if parameter values have been successfully defined
459 //================================================================================
461 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
462 const SMESH_Mesh* /*theMesh*/)
467 //=============================================================================
468 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
473 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
478 double HexoticPlugin_Hypothesis::GetDefaultMinSize()
483 double HexoticPlugin_Hypothesis::GetDefaultMaxSize()
488 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
493 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
498 double HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
503 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
508 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
512 char *Tmp_dir = getenv("SALOME_TMP_DIR");
514 if(Tmp_dir == NULL) {
515 Tmp_dir = getenv("TEMP");
517 Tmp_dir = getenv("TMP");
520 if( Tmp_dir != NULL ) {
521 aTmpDir = std::string(Tmp_dir);
523 if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\';
525 if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/';
538 int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()
543 int HexoticPlugin_Hypothesis::GetDefaultHexoticVerbosity()
548 int HexoticPlugin_Hypothesis::GetDefaultHexoticMaxMemory()
553 std::string HexoticPlugin_Hypothesis::GetDefaultTextOptions()
558 HexoticPlugin_Hypothesis::THexoticSizeMaps HexoticPlugin_Hypothesis::GetDefaultHexoticSizeMaps()
560 return THexoticSizeMaps();
563 int HexoticPlugin_Hypothesis::GetDefaultNbLayers()
568 double HexoticPlugin_Hypothesis::GetDefaultFirstLayerSize()
573 bool HexoticPlugin_Hypothesis::GetDefaultDirection()
578 double HexoticPlugin_Hypothesis::GetDefaultGrowth()
583 std::vector<int> HexoticPlugin_Hypothesis::GetDefaultFacesWithLayers()
585 return std::vector<int>();
588 std::vector<int> HexoticPlugin_Hypothesis::GetDefaultImprintedFaces()
590 return std::vector<int>();