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, SMESH_Gen* gen)
36 : SMESH_Hypothesis(hypId, gen),
37 _hexesMinLevel( GetDefaultHexesMinLevel() ),
38 _hexesMaxLevel( GetDefaultHexesMaxLevel() ),
39 _minSize( GetDefaultMinSize() ),
40 _maxSize( GetDefaultMaxSize() ),
41 _hexoticIgnoreRidges( GetDefaultHexoticIgnoreRidges() ),
42 _hexoticInvalidElements( GetDefaultHexoticInvalidElements() ),
43 _hexoticSharpAngleThreshold( GetDefaultHexoticSharpAngleThreshold() ),
44 _hexoticNbProc( GetDefaultHexoticNbProc() ),
45 _hexoticSdMode(GetDefaultHexoticSdMode()),
46 _hexoticVerbosity(GetDefaultHexoticVerbosity()),
47 _hexoticMaxMemory(GetDefaultHexoticMaxMemory()),
48 _textOptions(GetDefaultTextOptions()),
49 _sizeMaps(GetDefaultHexoticSizeMaps()),
50 _hexoticWorkingDirectory( GetDefaultHexoticWorkingDirectory() ),
51 _nbLayers(GetDefaultNbLayers()),
52 _firstLayerSize(GetDefaultFirstLayerSize()),
53 _direction(GetDefaultDirection()),
54 _growth(GetDefaultGrowth()),
55 _facesWithLayers(GetDefaultFacesWithLayers()),
56 _imprintedFaces(GetDefaultImprintedFaces())
58 MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
63 //=============================================================================
67 //=============================================================================
69 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
70 if (theVal != _hexesMinLevel) {
71 _hexesMinLevel = theVal;
72 NotifySubMeshesHypothesisModification();
76 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
77 if (theVal != _hexesMaxLevel) {
78 _hexesMaxLevel = theVal;
79 NotifySubMeshesHypothesisModification();
83 void HexoticPlugin_Hypothesis::SetMinSize(double theVal) {
84 if (theVal != _minSize) {
86 NotifySubMeshesHypothesisModification();
90 void HexoticPlugin_Hypothesis::SetMaxSize(double theVal) {
91 if (theVal != _maxSize) {
93 NotifySubMeshesHypothesisModification();
97 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
98 if (theVal != _hexoticIgnoreRidges) {
99 _hexoticIgnoreRidges = theVal;
100 NotifySubMeshesHypothesisModification();
104 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
105 if (theVal != _hexoticInvalidElements) {
106 _hexoticInvalidElements = theVal;
107 NotifySubMeshesHypothesisModification();
111 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(double theVal) {
112 if (theVal != _hexoticSharpAngleThreshold) {
113 _hexoticSharpAngleThreshold = theVal;
114 NotifySubMeshesHypothesisModification();
118 void HexoticPlugin_Hypothesis::SetHexoticNbProc(int theVal) {
119 if (theVal != _hexoticNbProc) {
120 _hexoticNbProc = theVal;
121 NotifySubMeshesHypothesisModification();
125 void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& path)
127 if ( _hexoticWorkingDirectory != path ) {
128 _hexoticWorkingDirectory = path;
132 if( path[ path.size()-1 ] != '\\')
133 _hexoticWorkingDirectory += '\\';
135 if( path[ path.size()-1 ] != '/')
136 _hexoticWorkingDirectory += '/';
139 NotifySubMeshesHypothesisModification();
143 void HexoticPlugin_Hypothesis::SetHexoticSdMode(int theVal) {
144 if (theVal != _hexoticSdMode) {
145 _hexoticSdMode = theVal;
146 NotifySubMeshesHypothesisModification();
150 void HexoticPlugin_Hypothesis::SetHexoticVerbosity(int theVal) {
151 if (theVal != _hexoticVerbosity) {
152 _hexoticVerbosity = theVal;
153 NotifySubMeshesHypothesisModification();
157 void HexoticPlugin_Hypothesis::SetHexoticMaxMemory(int theVal) {
158 if (theVal != _hexoticMaxMemory) {
159 _hexoticMaxMemory = theVal;
160 NotifySubMeshesHypothesisModification();
164 void HexoticPlugin_Hypothesis::SetAdvancedOption(const std::string& theOptions)
166 if (_textOptions != theOptions ) {
167 _textOptions = theOptions;
168 NotifySubMeshesHypothesisModification();
171 void HexoticPlugin_Hypothesis::SetTextOptions(const std::string& theOptions)
173 if (_textOptions != theOptions ) {
174 _textOptions = theOptions;
175 NotifySubMeshesHypothesisModification();
179 bool HexoticPlugin_Hypothesis::AddSizeMap(std::string theEntry, double theSize) {
180 THexoticSizeMaps::iterator it;
181 it=_sizeMaps.find(theEntry);
186 if( it == _sizeMaps.end() ) // If no size map is defined on the given object
188 _sizeMaps[theEntry] = theSize;
189 MESSAGE("NEW size map, entry :"<<theEntry<<", size : "<<theSize);
190 NotifySubMeshesHypothesisModification();
193 else if( it->second != theSize ) // If a size map exists with a different size value
195 it->second = theSize;
196 MESSAGE("MODIFIED size map, entry :"<<theEntry<<"with size : "<<theSize);
197 NotifySubMeshesHypothesisModification();
202 MESSAGE("NO size map added")
203 return false; // No size map added
207 bool HexoticPlugin_Hypothesis::UnsetSizeMap(std::string theEntry) {
208 THexoticSizeMaps::iterator it;
209 it=_sizeMaps.find(theEntry);
210 if( it != _sizeMaps.end() )
219 void HexoticPlugin_Hypothesis::SetNbLayers(int theVal) {
220 if (theVal != _nbLayers) {
222 NotifySubMeshesHypothesisModification();
226 void HexoticPlugin_Hypothesis::SetFirstLayerSize(double theVal) {
227 if (theVal != _firstLayerSize) {
228 _firstLayerSize = theVal;
229 NotifySubMeshesHypothesisModification();
233 void HexoticPlugin_Hypothesis::SetDirection(bool theVal) {
234 if (theVal != _direction) {
236 NotifySubMeshesHypothesisModification();
240 void HexoticPlugin_Hypothesis::SetGrowth(double theVal) {
241 if (theVal != _growth) {
243 NotifySubMeshesHypothesisModification();
247 bool HexoticPlugin_Hypothesis::SetFacesWithLayers(const std::vector<int>& theVal) {
248 if ( _facesWithLayers != theVal ) {
249 _facesWithLayers = theVal;
250 NotifySubMeshesHypothesisModification();
256 bool HexoticPlugin_Hypothesis::SetImprintedFaces(const std::vector<int>& theVal) {
257 if ( _imprintedFaces != theVal ) {
258 _imprintedFaces = theVal;
259 NotifySubMeshesHypothesisModification();
265 //=============================================================================
269 //=============================================================================
270 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
272 //explicit outputs for future code compatibility of saved .hdf
273 //save without any whitespaces!
275 save<<"hexesMinLevel="<<_hexesMinLevel<<";";
276 save<<"hexesMaxLevel="<<_hexesMaxLevel<<";";
277 save<<"hexoticIgnoreRidges="<<(int)_hexoticIgnoreRidges<<";";
278 save<<"hexoticInvalidElements="<<(int)_hexoticInvalidElements<<";";
279 save<<"hexoticSharpAngleThreshold="<<_hexoticSharpAngleThreshold<<";";
280 save<<"hexoticNbProc="<<_hexoticNbProc<<";";
281 save<<"hexoticWorkingDirectory="<<_hexoticWorkingDirectory<<";";
282 save<<"minSize="<<_minSize<<";";
283 save<<"maxSize="<<_maxSize<<";";
284 save<<"hexoticSdMode="<<_hexoticSdMode<<";";
285 save<<"hexoticVerbosity="<<_hexoticVerbosity<<";";
286 save<<"hexoticMaxMemory="<<_hexoticMaxMemory<<";";
287 std::string textOptions = _textOptions; // save _textOptions
288 replace(textOptions.begin(), textOptions.end(), ' ', '*');
289 save<<"textOptions="<<textOptions<<";";
290 THexoticSizeMaps::iterator it = _sizeMaps.begin();
291 if ( it != _sizeMaps.end() )
294 for ( ; it!=_sizeMaps.end() ; it++ )
296 save<< it->first << "/" << it->second << "#" ;
300 save<<"nbLayers="<<_nbLayers<<";";
301 save<<"firstLayerSize="<<_firstLayerSize<<";";
302 save<<"direction="<<_direction<<";";
303 save<<"growth="<<_growth<<";";
304 if ( !_facesWithLayers.empty() )
306 save<<"facesWithLayers=";
307 for ( size_t i = 0; i < _facesWithLayers.size(); i++ )
309 save<< _facesWithLayers.at(i) << "#" ;
313 if ( !_imprintedFaces.empty() )
315 save<<"imprintedFaces=";
316 for ( size_t i = 0; i < _imprintedFaces.size(); i++ )
318 save<< _imprintedFaces.at(i) << "#" ;
325 //=============================================================================
329 //=============================================================================
330 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
332 //explicit inputs for future code compatibility of saved .hdf
334 std::string str1,str2,str3,str4;
336 //save without any whitespaces!
337 isOK = static_cast<bool>(load >> str1);
339 //defaults values assumed
340 load.clear(std::ios::badbit | load.rdstate());
344 int len = str1.length();
346 int found = str1.find(';',pos);
347 str2 = str1.substr(pos,found-pos);
348 int eqpos = str2.find('=',0);
349 str3 = str2.substr(0,eqpos);
350 str4 = str2.substr(eqpos+1);
353 if (str3=="hexesMinLevel") _hexesMinLevel = atoi(str4.c_str());
354 if (str3=="hexesMaxLevel") _hexesMaxLevel = atoi(str4.c_str());
355 if (str3=="hexoticQuadrangles") {}
356 if (str3=="hexoticIgnoreRidges") _hexoticIgnoreRidges = (bool) atoi(str4.c_str());
357 if (str3=="hexoticInvalidElements") _hexoticInvalidElements = (bool) atoi(str4.c_str());
358 if (str3=="hexoticSharpAngleThreshold") _hexoticSharpAngleThreshold = atof(str4.c_str());
359 if (str3=="hexoticNbProc") _hexoticNbProc = atoi(str4.c_str());
360 if (str3=="hexoticWorkingDirectory") _hexoticWorkingDirectory = str4;
361 if (str3=="minSize") _minSize = atof(str4.c_str());
362 if (str3=="maxSize") _maxSize = atof(str4.c_str());
363 if (str3=="hexoticSdMode") _hexoticSdMode = atoi(str4.c_str());
364 if (str3=="hexoticVerbosity") _hexoticVerbosity = atoi(str4.c_str());
365 if (str3=="hexoticMaxMemory") _hexoticMaxMemory = atoi(str4.c_str());
366 if (str3=="textOptions")
368 replace(str4.begin(), str4.end(), '*', ' ');
371 if (str3=="sizeMaps")
373 std::string sm_substr, sm_substr1, sm_substr2;
375 int sm_len = str4.length();
376 while ( sm_pos < sm_len )
378 int sm_found = str4.find('#',sm_pos);
379 sm_substr = str4.substr(sm_pos,sm_found-sm_pos);
380 int sm_slashpos = sm_substr.find('/',0);
381 sm_substr1 = sm_substr.substr(0,sm_slashpos);
382 sm_substr2 = sm_substr.substr(sm_slashpos+1);
383 _sizeMaps[sm_substr1] = atof(sm_substr2.c_str());
384 sm_pos = sm_found + 1;
387 if (str3 == "nbLayers") _nbLayers = atoi(str4.c_str());
388 if (str3 == "firstLayerSize") _firstLayerSize = atof(str4.c_str());
389 if (str3 == "direction") _direction = atoi(str4.c_str());
390 if (str3 == "growth") _growth = atof(str4.c_str());
391 if (str3 == "facesWithLayers")
395 while ( pos < str4.length() )
397 int found = str4.find('#',pos);
398 id = str4.substr(pos, found-pos);
399 _facesWithLayers.push_back(atoi(id.c_str()));
403 if (str3 == "imprintedFaces")
407 while ( pos < str4.length() )
409 int found = str4.find('#',pos);
410 id = str4.substr(pos, found-pos);
411 _imprintedFaces.push_back(atoi(id.c_str()));
419 //=============================================================================
423 //=============================================================================
424 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
426 return hyp.SaveTo( save );
429 //=============================================================================
433 //=============================================================================
434 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
436 return hyp.LoadFrom( load );
440 //================================================================================
442 * \brief Does nothing
443 * \param theMesh - the built mesh
444 * \param theShape - the geometry of interest
445 * \retval bool - always false
447 //================================================================================
448 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
449 const TopoDS_Shape& theShape)
453 //================================================================================
455 * \brief Initialize my parameter values by default parameters.
456 * \retval bool - true if parameter values have been successfully defined
458 //================================================================================
460 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
461 const SMESH_Mesh* /*theMesh*/)
466 //=============================================================================
467 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
472 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
477 double HexoticPlugin_Hypothesis::GetDefaultMinSize()
482 double HexoticPlugin_Hypothesis::GetDefaultMaxSize()
487 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
492 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
497 double HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
502 int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc()
507 std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory()
511 char *Tmp_dir = getenv("SALOME_TMP_DIR");
513 if(Tmp_dir == NULL) {
514 Tmp_dir = getenv("TEMP");
516 Tmp_dir = getenv("TMP");
519 if( Tmp_dir != NULL ) {
520 aTmpDir = std::string(Tmp_dir);
522 if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\';
524 if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/';
537 int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()
542 int HexoticPlugin_Hypothesis::GetDefaultHexoticVerbosity()
547 int HexoticPlugin_Hypothesis::GetDefaultHexoticMaxMemory()
552 std::string HexoticPlugin_Hypothesis::GetDefaultTextOptions()
557 HexoticPlugin_Hypothesis::THexoticSizeMaps HexoticPlugin_Hypothesis::GetDefaultHexoticSizeMaps()
559 return THexoticSizeMaps();
562 int HexoticPlugin_Hypothesis::GetDefaultNbLayers()
567 double HexoticPlugin_Hypothesis::GetDefaultFirstLayerSize()
572 bool HexoticPlugin_Hypothesis::GetDefaultDirection()
577 double HexoticPlugin_Hypothesis::GetDefaultGrowth()
582 std::vector<int> HexoticPlugin_Hypothesis::GetDefaultFacesWithLayers()
584 return std::vector<int>();
587 std::vector<int> HexoticPlugin_Hypothesis::GetDefaultImprintedFaces()
589 return std::vector<int>();