1 // Copyright (C) 2007-2020 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 : GHS3DPRLPlugin_Hypothesis.cxx
22 // Author : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
25 #include "GHS3DPRLPlugin_Hypothesis.hxx"
26 #include <utilities.h>
28 //=============================================================================
32 //=============================================================================
33 GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis (int hypId, SMESH_Gen * gen)
34 : SMESH_Hypothesis(hypId, gen),
35 _MEDName( GetDefaultMEDName() ),
36 _NbPart( GetDefaultNbPart() ),
37 _KeepFiles( GetDefaultKeepFiles() ),
38 _Background( GetDefaultBackground() ),
39 _Multithread( GetDefaultMultithread() ),
40 //_ToMergeSubdomains( GetDefaultToMergeSubdomains() ),
41 _Gradation( GetDefaultGradation() ),
42 _MinSize( GetDefaultMinSize() ),
43 _MaxSize( GetDefaultMaxSize() )
45 MESSAGE("GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis");
50 //=============================================================================
54 //=============================================================================
55 static std::string cutOrReplaceBlancs(std::string theIn)
57 // cut all blancs at the beginning and at the end of the string,
58 // replace each blancs sequence of maximum length inside the string by one '_' symbol,
59 // as blancs consider: 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR) and 32 (Space)
60 int len = theIn.length();
62 const char* str1 = theIn.c_str();
63 char* str2 = new char [len + 1];
66 for (int i = 0, j = 0; i < len; i++)
68 unsigned short ucs = (unsigned short)(str1[i]);
69 if ((9 <= ucs && ucs <= 13) || ucs == 32)
84 str2[lastgood] = '\0';
85 std::string anOut = str2;
89 void GHS3DPRLPlugin_Hypothesis::SetMEDName(std::string theVal) {
90 //without whitespaces! ..from python?
91 std::string tmp1 = cutOrReplaceBlancs(theVal);
92 std::string tmp2 = _MEDName;
94 _MEDName = tmp1.c_str();
95 NotifySubMeshesHypothesisModification();
99 void GHS3DPRLPlugin_Hypothesis::SetNbPart(int theVal) {
100 if (theVal != _NbPart) {
102 NotifySubMeshesHypothesisModification();
106 void GHS3DPRLPlugin_Hypothesis::SetKeepFiles(bool theVal) {
107 if (theVal != _KeepFiles) {
109 NotifySubMeshesHypothesisModification();
113 void GHS3DPRLPlugin_Hypothesis::SetBackground(bool theVal) {
114 if (theVal != _Background) {
115 _Background = theVal;
116 NotifySubMeshesHypothesisModification();
120 void GHS3DPRLPlugin_Hypothesis::SetMultithread(bool theVal) {
121 if (theVal != _Multithread) {
122 _Multithread = theVal;
123 NotifySubMeshesHypothesisModification();
127 //void GHS3DPRLPlugin_Hypothesis::SetToMergeSubdomains(bool theVal) {
128 // if (theVal != _ToMergeSubdomains) {
129 // _ToMergeSubdomains = theVal;
130 // NotifySubMeshesHypothesisModification();
134 void GHS3DPRLPlugin_Hypothesis::SetGradation(float theVal) {
135 if (theVal != _Gradation) {
137 NotifySubMeshesHypothesisModification();
141 void GHS3DPRLPlugin_Hypothesis::SetMinSize(float theVal) {
142 if (theVal != _MinSize) {
144 NotifySubMeshesHypothesisModification();
148 void GHS3DPRLPlugin_Hypothesis::SetMaxSize(float theVal) {
149 if (theVal != _MaxSize) {
151 NotifySubMeshesHypothesisModification();
155 void GHS3DPRLPlugin_Hypothesis::SetAdvancedOption(const char* theOptAndVals )
157 if ( _AdvOptions != theOptAndVals )
159 _AdvOptions = theOptAndVals;
160 NotifySubMeshesHypothesisModification();
166 //=============================================================================
170 //=============================================================================
171 std::ostream& GHS3DPRLPlugin_Hypothesis::SaveTo(std::ostream& save)
173 //explicit outputs for future code compatibility of saved .hdf
174 //save without any whitespaces!
175 save<<"MEDName="<<_MEDName<<";";
176 save<<"NbPart="<<_NbPart<<";";
177 //save<<"ToMeshHoles="<<(int) _ToMeshHoles<<";";
178 //save<<"ToMergeSubdomains="<<(int) _ToMergeSubdomains<<";";
179 save<<"Gradation="<<(float) _Gradation<<";";
180 save<<"MinSize="<<(float) _MinSize<<";";
181 save<<"MaxSize="<<(float) _MaxSize<<";";
182 save<<"KeepFiles="<<(int) _KeepFiles<<";";
183 save<<"Background="<<(int) _Background<<";";
184 save<<"Multithread="<<(int) _Multithread<<";";
185 save<<" " << _AdvOptions.size() << " " << _AdvOptions;
189 //=============================================================================
193 //=============================================================================
194 std::istream& GHS3DPRLPlugin_Hypothesis::LoadFrom(std::istream& load)
196 //explicit inputs for future code compatibility of saved .hdf
198 std::string str1,str2,str3,str4;
200 //save without any whitespaces!
201 isOK = static_cast<bool>(load >> str1);
203 //defaults values assumed
204 load.clear(std::ios::badbit | load.rdstate());
208 int len = str1.length();
210 int found = str1.find(';',pos);
211 str2 = str1.substr(pos,found-pos);
212 int eqpos = str2.find('=',0);
213 str3 = str2.substr(0,eqpos);
214 str4 = str2.substr(eqpos+1);
217 if (str3=="MEDName") _MEDName = str4.c_str();
218 if (str3=="NbPart") _NbPart = atoi(str4.c_str());
219 if (str3=="KeepFiles") _KeepFiles = (bool) atoi(str4.c_str());
220 if (str3=="Gradation") _Gradation = atof(str4.c_str());
221 if (str3=="MinSize") _MinSize = atof(str4.c_str());
222 if (str3=="MaxSize") _MaxSize = atof(str4.c_str());
223 if (str3=="Background") _Background = (bool) atoi(str4.c_str());
224 if (str3=="Multithread") _Multithread = (bool) atoi(str4.c_str());
228 isOK = static_cast<bool>(load >> len >> std::ws);
229 if ( isOK && len > 0 )
231 _AdvOptions.resize( len );
232 load.get( &_AdvOptions[0], len + 1);
237 //=============================================================================
241 //=============================================================================
242 std::ostream& operator <<(std::ostream& save, GHS3DPRLPlugin_Hypothesis& hyp)
244 return hyp.SaveTo( save );
247 //=============================================================================
251 //=============================================================================
252 std::istream& operator >>(std::istream& load, GHS3DPRLPlugin_Hypothesis& hyp)
254 return hyp.LoadFrom( load );
258 //================================================================================
260 * \brief Does nothing
261 * \param theMesh - the built mesh
262 * \param theShape - the geometry of interest
263 * \retval bool - always false
265 //================================================================================
266 bool GHS3DPRLPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
267 const TopoDS_Shape& /*theShape*/)
271 //================================================================================
273 * \brief Initialize my parameter values by default parameters.
274 * \retval bool - true if parameter values have been successfully defined
276 //================================================================================
278 bool GHS3DPRLPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
279 const SMESH_Mesh* /*theMesh*/)
284 //=============================================================================
285 std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
290 //=============================================================================
291 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
296 //=============================================================================
297 bool GHS3DPRLPlugin_Hypothesis::GetDefaultKeepFiles()
302 //=============================================================================
303 bool GHS3DPRLPlugin_Hypothesis::GetDefaultBackground()
308 //=============================================================================
309 bool GHS3DPRLPlugin_Hypothesis::GetDefaultMultithread()
314 //=============================================================================
315 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMeshHoles()
320 //=============================================================================
321 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMergeSubdomains()
326 //=============================================================================
327 float GHS3DPRLPlugin_Hypothesis::GetDefaultGradation()
331 //=============================================================================
332 float GHS3DPRLPlugin_Hypothesis::GetDefaultMinSize()
336 //=============================================================================
337 float GHS3DPRLPlugin_Hypothesis::GetDefaultMaxSize()