1 // Copyright (C) 2007-2023 CEA, EDF
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 : GHS3DPRLPlugin_Hypothesis.cxx
22 // Author : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
25 #include "GHS3DPRLPlugin_Hypothesis.hxx"
26 #include <Basics_DirUtils.hxx>
27 #include <SMESH_File.hxx>
28 #include <utilities.h>
33 #define getpid _getpid
36 //=============================================================================
40 //=============================================================================
41 GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis (int hypId, SMESH_Gen * gen)
42 : SMESH_Hypothesis(hypId, gen),
43 _MEDName( GetDefaultMEDName() ),
44 _NbPart( GetDefaultNbPart() ),
45 _KeepFiles( GetDefaultKeepFiles() ),
46 _Background( GetDefaultBackground() ),
47 _Multithread( GetDefaultMultithread() ),
48 //_ToMergeSubdomains( GetDefaultToMergeSubdomains() ),
49 _Gradation( GetDefaultGradation() ),
50 _MinSize( GetDefaultMinSize() ),
51 _MaxSize( GetDefaultMaxSize() )
53 MESSAGE("GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis");
58 //=======================================================================
59 //function : DefaultWorkingDirectory
60 //=======================================================================
62 std::string GHS3DPRLPlugin_Hypothesis::DefaultWorkingDirectory()
64 TCollection_AsciiString aTmpDir;
66 char *Tmp_dir = getenv("SALOME_TMP_DIR");
72 aTmpDir = TCollection_AsciiString("C:\\");
74 aTmpDir = TCollection_AsciiString("/tmp/");
77 return aTmpDir.ToCString();
80 //================================================================================
82 * \brief Return a unique file name
84 //================================================================================
86 std::string GHS3DPRLPlugin_Hypothesis::GetFileName(const GHS3DPRLPlugin_Hypothesis* hyp)
88 std::string aTmpDir = DefaultWorkingDirectory();
89 if ( !SMESH_File( aTmpDir ).exists() )
90 aTmpDir = Kernel_Utils::GetTmpDirByPath( aTmpDir );
92 const char lastChar = *aTmpDir.rbegin();
94 if(lastChar != '\\') aTmpDir+='\\';
96 if(lastChar != '/') aTmpDir+='/';
99 TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
100 aGenericName += "MGTETRAHPC_";
101 aGenericName += getpid();
103 aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
105 return aGenericName.ToCString();
108 //=============================================================================
112 //=============================================================================
113 static std::string cutOrReplaceBlancs(std::string theIn)
115 // cut all blancs at the beginning and at the end of the string,
116 // replace each blancs sequence of maximum length inside the string by one '_' symbol,
117 // as blancs consider: 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR) and 32 (Space)
118 int len = theIn.length();
120 const char* str1 = theIn.c_str();
121 char* str2 = new char [len + 1];
124 for (int i = 0, j = 0; i < len; i++)
126 unsigned short ucs = (unsigned short)(str1[i]);
127 if ((9 <= ucs && ucs <= 13) || ucs == 32)
142 str2[lastgood] = '\0';
143 std::string anOut = str2;
147 void GHS3DPRLPlugin_Hypothesis::SetMEDName(std::string theVal) {
148 //without whitespaces! ..from python?
149 std::string tmp1 = cutOrReplaceBlancs(theVal);
150 std::string tmp2 = _MEDName;
152 _MEDName = tmp1.c_str();
153 NotifySubMeshesHypothesisModification();
157 void GHS3DPRLPlugin_Hypothesis::SetNbPart(int theVal) {
158 if (theVal != _NbPart) {
160 NotifySubMeshesHypothesisModification();
164 void GHS3DPRLPlugin_Hypothesis::SetKeepFiles(bool theVal) {
165 if (theVal != _KeepFiles) {
167 NotifySubMeshesHypothesisModification();
171 void GHS3DPRLPlugin_Hypothesis::SetBackground(bool theVal) {
172 if (theVal != _Background) {
173 _Background = theVal;
174 NotifySubMeshesHypothesisModification();
178 void GHS3DPRLPlugin_Hypothesis::SetMultithread(bool theVal) {
179 if (theVal != _Multithread) {
180 _Multithread = theVal;
181 NotifySubMeshesHypothesisModification();
185 //void GHS3DPRLPlugin_Hypothesis::SetToMergeSubdomains(bool theVal) {
186 // if (theVal != _ToMergeSubdomains) {
187 // _ToMergeSubdomains = theVal;
188 // NotifySubMeshesHypothesisModification();
192 void GHS3DPRLPlugin_Hypothesis::SetGradation(float theVal) {
193 if (theVal != _Gradation) {
195 NotifySubMeshesHypothesisModification();
199 void GHS3DPRLPlugin_Hypothesis::SetMinSize(float theVal) {
200 if (theVal != _MinSize) {
202 NotifySubMeshesHypothesisModification();
206 void GHS3DPRLPlugin_Hypothesis::SetMaxSize(float theVal) {
207 if (theVal != _MaxSize) {
209 NotifySubMeshesHypothesisModification();
213 void GHS3DPRLPlugin_Hypothesis::SetAdvancedOption(const char* theOptAndVals )
215 if ( _AdvOptions != theOptAndVals )
217 _AdvOptions = theOptAndVals;
218 NotifySubMeshesHypothesisModification();
224 //=============================================================================
228 //=============================================================================
229 std::ostream& GHS3DPRLPlugin_Hypothesis::SaveTo(std::ostream& save)
231 //explicit outputs for future code compatibility of saved .hdf
232 //save without any whitespaces!
233 save<<"MEDName="<<_MEDName<<";";
234 save<<"NbPart="<<_NbPart<<";";
235 //save<<"ToMeshHoles="<<(int) _ToMeshHoles<<";";
236 //save<<"ToMergeSubdomains="<<(int) _ToMergeSubdomains<<";";
237 save<<"Gradation="<<(float) _Gradation<<";";
238 save<<"MinSize="<<(float) _MinSize<<";";
239 save<<"MaxSize="<<(float) _MaxSize<<";";
240 save<<"KeepFiles="<<(int) _KeepFiles<<";";
241 save<<"Background="<<(int) _Background<<";";
242 save<<"Multithread="<<(int) _Multithread<<";";
243 save<<" " << _AdvOptions.size() << " " << _AdvOptions;
247 //=============================================================================
251 //=============================================================================
252 std::istream& GHS3DPRLPlugin_Hypothesis::LoadFrom(std::istream& load)
254 //explicit inputs for future code compatibility of saved .hdf
256 std::string str1,str2,str3,str4;
258 //save without any whitespaces!
259 isOK = static_cast<bool>(load >> str1);
261 //defaults values assumed
262 load.clear(std::ios::badbit | load.rdstate());
266 int len = str1.length();
268 int found = str1.find(';',pos);
269 str2 = str1.substr(pos,found-pos);
270 int eqpos = str2.find('=',0);
271 str3 = str2.substr(0,eqpos);
272 str4 = str2.substr(eqpos+1);
275 if (str3=="MEDName") _MEDName = str4.c_str();
276 if (str3=="NbPart") _NbPart = atoi(str4.c_str());
277 if (str3=="KeepFiles") _KeepFiles = (bool) atoi(str4.c_str());
278 if (str3=="Gradation") _Gradation = atof(str4.c_str());
279 if (str3=="MinSize") _MinSize = atof(str4.c_str());
280 if (str3=="MaxSize") _MaxSize = atof(str4.c_str());
281 if (str3=="Background") _Background = (bool) atoi(str4.c_str());
282 if (str3=="Multithread") _Multithread = (bool) atoi(str4.c_str());
286 isOK = static_cast<bool>(load >> len >> std::ws);
287 if ( isOK && len > 0 )
289 _AdvOptions.resize( len );
290 load.get( &_AdvOptions[0], len + 1);
295 //=============================================================================
299 //=============================================================================
300 std::ostream& operator <<(std::ostream& save, GHS3DPRLPlugin_Hypothesis& hyp)
302 return hyp.SaveTo( save );
305 //=============================================================================
309 //=============================================================================
310 std::istream& operator >>(std::istream& load, GHS3DPRLPlugin_Hypothesis& hyp)
312 return hyp.LoadFrom( load );
316 //================================================================================
318 * \brief Does nothing
319 * \param theMesh - the built mesh
320 * \param theShape - the geometry of interest
321 * \retval bool - always false
323 //================================================================================
324 bool GHS3DPRLPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
325 const TopoDS_Shape& /*theShape*/)
329 //================================================================================
331 * \brief Initialize my parameter values by default parameters.
332 * \retval bool - true if parameter values have been successfully defined
334 //================================================================================
336 bool GHS3DPRLPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
337 const SMESH_Mesh* /*theMesh*/)
342 //=============================================================================
343 std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
348 //=============================================================================
349 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
354 //=============================================================================
355 bool GHS3DPRLPlugin_Hypothesis::GetDefaultKeepFiles()
360 //=============================================================================
361 bool GHS3DPRLPlugin_Hypothesis::GetDefaultBackground()
366 //=============================================================================
367 bool GHS3DPRLPlugin_Hypothesis::GetDefaultMultithread()
372 //=============================================================================
373 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMeshHoles()
378 //=============================================================================
379 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMergeSubdomains()
384 //=============================================================================
385 float GHS3DPRLPlugin_Hypothesis::GetDefaultGradation()
389 //=============================================================================
390 float GHS3DPRLPlugin_Hypothesis::GetDefaultMinSize()
394 //=============================================================================
395 float GHS3DPRLPlugin_Hypothesis::GetDefaultMaxSize()