Salome HOME
d436fb3f920936281f1d353d6e5903958f2d5239
[plugins/ghs3dprlplugin.git] / src / GHS3DPRLPlugin / GHS3DPRLPlugin_Hypothesis.cxx
1 // Copyright (C) 2007-2016  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, int studyId, SMESH_Gen * gen)
34   : SMESH_Hypothesis(hypId, studyId, 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
156
157
158
159
160 //=============================================================================
161 /*!
162  *
163  */
164 //=============================================================================
165 std::ostream& GHS3DPRLPlugin_Hypothesis::SaveTo(std::ostream& save)
166 {
167   //explicit outputs for future code compatibility of saved .hdf
168   //save without any whitespaces!
169   save<<"MEDName="<<_MEDName<<";";
170   save<<"NbPart="<<_NbPart<<";";
171   //save<<"ToMeshHoles="<<(int) _ToMeshHoles<<";";
172   //save<<"ToMergeSubdomains="<<(int) _ToMergeSubdomains<<";";
173   save<<"Gradation="<<(float) _Gradation<<";";
174   save<<"MinSize="<<(float) _MinSize<<";";
175   save<<"MaxSize="<<(float) _MaxSize<<";";
176   save<<"KeepFiles="<<(int) _KeepFiles<<";";
177   save<<"Background="<<(int) _Background<<";";
178   save<<"Multithread="<<(int) _Multithread<<";";
179   return save;
180 }
181
182 //=============================================================================
183 /*!
184  *
185  */
186 //=============================================================================
187 std::istream& GHS3DPRLPlugin_Hypothesis::LoadFrom(std::istream& load)
188 {
189    //explicit inputs for future code compatibility of saved .hdf
190    bool isOK = true;
191    std::string str1,str2,str3,str4;
192
193    //save without any whitespaces!
194    isOK = static_cast<bool>(load >> str1);
195    if (!(isOK)) {
196      //defaults values assumed
197      load.clear(std::ios::badbit | load.rdstate());
198      return load;
199    }
200    int pos = 0;
201    int len = str1.length();
202    while (pos < len) {
203      int found = str1.find(';',pos);
204      str2 = str1.substr(pos,found-pos);
205      int eqpos = str2.find('=',0);
206      str3 = str2.substr(0,eqpos);
207      str4 = str2.substr(eqpos+1);
208      pos = found + 1;
209
210      if (str3=="MEDName") _MEDName = str4.c_str();
211      if (str3=="NbPart") _NbPart = atoi(str4.c_str());
212      if (str3=="KeepFiles") _KeepFiles = (bool) atoi(str4.c_str());
213      //if (str3=="ToMeshHoles") _ToMeshHoles = (bool) atoi(str4.c_str());
214      if (str3=="Gradation") _Gradation = (float) atof(str4.c_str());
215      if (str3=="MinSize") _MinSize = (float) atof(str4.c_str());
216      if (str3=="MaxSize") _MaxSize = (float) atof(str4.c_str());
217      if (str3=="Background") _Background = (bool) atoi(str4.c_str());
218      if (str3=="Multithread") _Multithread = (bool) atoi(str4.c_str());
219    }
220    return load;
221 }
222
223 //=============================================================================
224 /*!
225  *
226  */
227 //=============================================================================
228 std::ostream& operator <<(std::ostream& save, GHS3DPRLPlugin_Hypothesis& hyp)
229 {
230   return hyp.SaveTo( save );
231 }
232
233 //=============================================================================
234 /*!
235  *
236  */
237 //=============================================================================
238 std::istream& operator >>(std::istream& load, GHS3DPRLPlugin_Hypothesis& hyp)
239 {
240   return hyp.LoadFrom( load );
241 }
242
243
244 //================================================================================
245 /*!
246  * \brief Does nothing
247  * \param theMesh - the built mesh
248  * \param theShape - the geometry of interest
249  * \retval bool - always false
250  */
251 //================================================================================
252 bool GHS3DPRLPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
253                                                     const TopoDS_Shape& theShape)
254 {
255   return false;
256 }
257 //================================================================================
258 /*!
259  * \brief Initialize my parameter values by default parameters.
260  *  \retval bool - true if parameter values have been successfully defined
261  */
262 //================================================================================
263
264 bool GHS3DPRLPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
265                                                         const SMESH_Mesh* /*theMesh*/)
266 {
267   return false;
268 }
269
270 //=============================================================================
271 std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
272 {
273   return "DOMAIN\0";
274 }
275
276 //=============================================================================
277 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
278 {
279   return 16;
280 }
281
282 //=============================================================================
283 bool GHS3DPRLPlugin_Hypothesis::GetDefaultKeepFiles()
284 {
285   return false;
286 }
287
288 //=============================================================================
289 bool GHS3DPRLPlugin_Hypothesis::GetDefaultBackground()
290 {
291   return false;
292 }
293
294 //=============================================================================
295 bool GHS3DPRLPlugin_Hypothesis::GetDefaultMultithread()
296 {
297   return false;
298 }
299
300 //=============================================================================
301 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMeshHoles()
302 //{
303 //  return false;
304 //}
305
306 //=============================================================================
307 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMergeSubdomains()
308 //{
309 //  return false;
310 //}
311
312 //=============================================================================
313 float GHS3DPRLPlugin_Hypothesis::GetDefaultGradation()
314 {
315   return 1.05;
316 }
317 //=============================================================================
318 float GHS3DPRLPlugin_Hypothesis::GetDefaultMinSize()
319 {
320   return 0.;
321 }
322 //=============================================================================
323 float GHS3DPRLPlugin_Hypothesis::GetDefaultMaxSize()
324 {
325   return 0.;
326 }
327