Salome HOME
Update copyrights
[plugins/ghs3dprlplugin.git] / src / GHS3DPRLPlugin / GHS3DPRLPlugin_Hypothesis.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File   : GHS3DPRLPlugin_Hypothesis.cxx
22 // Author : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
23 // ---
24 //
25 #include "GHS3DPRLPlugin_Hypothesis.hxx"
26 #include <utilities.h>
27
28 //=============================================================================
29 /*!
30  *
31  */
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() )
44 {
45   MESSAGE("GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis");
46   _name = GetHypType();
47   _param_algo_dim = 3;
48 }
49
50 //=============================================================================
51 /*!
52  *
53  */
54 //=============================================================================
55 static std::string cutOrReplaceBlancs(std::string theIn)
56 {
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();
61   int lastgood = 0;
62   const char* str1 = theIn.c_str();
63   char* str2 = new char [len + 1];
64   bool del = true;
65
66   for (int i = 0, j = 0; i < len; i++)
67   {
68     unsigned short ucs = (unsigned short)(str1[i]);
69     if ((9 <= ucs && ucs <= 13) || ucs == 32)
70     {
71       if (!del)
72       {
73         str2[j++] = '_';
74         del = true;
75       }
76     }
77     else
78     {
79       str2[j++] = str1[i];
80       lastgood = j;
81       del = false;
82     }
83   }
84   str2[lastgood] = '\0';
85   std::string anOut = str2;
86   return anOut;
87 }
88
89 void GHS3DPRLPlugin_Hypothesis::SetMEDName(std::string theVal) {
90   //without whitespaces! ..from python?
91   std::string tmp1 = cutOrReplaceBlancs(theVal);
92   std::string tmp2 = _MEDName;
93   if (tmp1 != tmp2) {
94     _MEDName = tmp1.c_str();
95     NotifySubMeshesHypothesisModification();
96   }
97 }
98
99 void GHS3DPRLPlugin_Hypothesis::SetNbPart(int theVal) {
100   if (theVal != _NbPart) {
101     _NbPart = theVal;
102     NotifySubMeshesHypothesisModification();
103   }
104 }
105
106 void GHS3DPRLPlugin_Hypothesis::SetKeepFiles(bool theVal) {
107   if (theVal != _KeepFiles) {
108     _KeepFiles = theVal;
109     NotifySubMeshesHypothesisModification();
110   }
111 }
112
113 void GHS3DPRLPlugin_Hypothesis::SetBackground(bool theVal) {
114   if (theVal != _Background) {
115     _Background = theVal;
116     NotifySubMeshesHypothesisModification();
117   }
118 }
119
120 void GHS3DPRLPlugin_Hypothesis::SetMultithread(bool theVal) {
121   if (theVal != _Multithread) {
122     _Multithread = theVal;
123     NotifySubMeshesHypothesisModification();
124   }
125 }
126
127 //void GHS3DPRLPlugin_Hypothesis::SetToMergeSubdomains(bool theVal) {
128 //  if (theVal != _ToMergeSubdomains) {
129 //    _ToMergeSubdomains = theVal;
130 //    NotifySubMeshesHypothesisModification();
131 //  }
132 //}
133
134 void GHS3DPRLPlugin_Hypothesis::SetGradation(float theVal) {
135   if (theVal != _Gradation) {
136     _Gradation = theVal;
137     NotifySubMeshesHypothesisModification();
138   }
139 }
140
141 void GHS3DPRLPlugin_Hypothesis::SetMinSize(float theVal) {
142   if (theVal != _MinSize) {
143     _MinSize = theVal;
144     NotifySubMeshesHypothesisModification();
145   }
146 }
147
148 void GHS3DPRLPlugin_Hypothesis::SetMaxSize(float theVal) {
149   if (theVal != _MaxSize) {
150     _MaxSize = theVal;
151     NotifySubMeshesHypothesisModification();
152   }
153 }
154
155 void GHS3DPRLPlugin_Hypothesis::SetAdvancedOption(const char* theOptAndVals )
156 {
157   if ( _AdvOptions != theOptAndVals )
158   {
159     _AdvOptions = theOptAndVals;
160     NotifySubMeshesHypothesisModification();
161   }
162 }
163
164
165
166 //=============================================================================
167 /*!
168  *
169  */
170 //=============================================================================
171 std::ostream& GHS3DPRLPlugin_Hypothesis::SaveTo(std::ostream& save)
172 {
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;
186   return save;
187 }
188
189 //=============================================================================
190 /*!
191  *
192  */
193 //=============================================================================
194 std::istream& GHS3DPRLPlugin_Hypothesis::LoadFrom(std::istream& load)
195 {
196    //explicit inputs for future code compatibility of saved .hdf
197    bool isOK = true;
198    std::string str1,str2,str3,str4;
199
200    //save without any whitespaces!
201    isOK = static_cast<bool>(load >> str1);
202    if (!(isOK)) {
203      //defaults values assumed
204      load.clear(std::ios::badbit | load.rdstate());
205      return load;
206    }
207    int pos = 0;
208    int len = str1.length();
209    while (pos < len) {
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);
215      pos = found + 1;
216
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());
225    }
226
227    len = 0;
228    isOK = static_cast<bool>(load >> len >> std::ws);
229    if ( isOK && len > 0 )
230    {
231      _AdvOptions.resize( len );
232      load.get( &_AdvOptions[0], len + 1);
233    }
234    return load;
235 }
236
237 //=============================================================================
238 /*!
239  *
240  */
241 //=============================================================================
242 std::ostream& operator <<(std::ostream& save, GHS3DPRLPlugin_Hypothesis& hyp)
243 {
244   return hyp.SaveTo( save );
245 }
246
247 //=============================================================================
248 /*!
249  *
250  */
251 //=============================================================================
252 std::istream& operator >>(std::istream& load, GHS3DPRLPlugin_Hypothesis& hyp)
253 {
254   return hyp.LoadFrom( load );
255 }
256
257
258 //================================================================================
259 /*!
260  * \brief Does nothing
261  * \param theMesh - the built mesh
262  * \param theShape - the geometry of interest
263  * \retval bool - always false
264  */
265 //================================================================================
266 bool GHS3DPRLPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
267                                                     const TopoDS_Shape& theShape)
268 {
269   return false;
270 }
271 //================================================================================
272 /*!
273  * \brief Initialize my parameter values by default parameters.
274  *  \retval bool - true if parameter values have been successfully defined
275  */
276 //================================================================================
277
278 bool GHS3DPRLPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
279                                                         const SMESH_Mesh* /*theMesh*/)
280 {
281   return false;
282 }
283
284 //=============================================================================
285 std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
286 {
287   return "DOMAIN\0";
288 }
289
290 //=============================================================================
291 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
292 {
293   return 16;
294 }
295
296 //=============================================================================
297 bool GHS3DPRLPlugin_Hypothesis::GetDefaultKeepFiles()
298 {
299   return false;
300 }
301
302 //=============================================================================
303 bool GHS3DPRLPlugin_Hypothesis::GetDefaultBackground()
304 {
305   return false;
306 }
307
308 //=============================================================================
309 bool GHS3DPRLPlugin_Hypothesis::GetDefaultMultithread()
310 {
311   return false;
312 }
313
314 //=============================================================================
315 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMeshHoles()
316 //{
317 //  return false;
318 //}
319
320 //=============================================================================
321 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMergeSubdomains()
322 //{
323 //  return false;
324 //}
325
326 //=============================================================================
327 float GHS3DPRLPlugin_Hypothesis::GetDefaultGradation()
328 {
329   return 1.05;
330 }
331 //=============================================================================
332 float GHS3DPRLPlugin_Hypothesis::GetDefaultMinSize()
333 {
334   return 0.;
335 }
336 //=============================================================================
337 float GHS3DPRLPlugin_Hypothesis::GetDefaultMaxSize()
338 {
339   return 0.;
340 }
341