Salome HOME
Copyrights update 2015.
[plugins/ghs3dprlplugin.git] / src / GHS3DPRLPlugin / GHS3DPRLPlugin_Hypothesis.cxx
1 // Copyright (C) 2007-2015  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     _ToMergeSubdomains( GetDefaultToMergeSubdomains() ),
40     _ToTagSubdomains( GetDefaultToTagSubdomains() ),
41     _ToOutputInterfaces( GetDefaultToOutputInterfaces() ),
42     _ToDiscardSubdomains( GetDefaultToDiscardSubdomains() )
43 {
44   MESSAGE("GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis");
45   _name = GetHypType();
46   _param_algo_dim = 3;
47 }
48
49 //=============================================================================
50 /*!
51  *
52  */
53 //=============================================================================
54 static std::string cutOrReplaceBlancs(std::string theIn)
55 {
56   // cut all blancs at the beginning and at the end of the string,
57   // replace each blancs sequence of maximum length inside the string by one '_' symbol,
58   // as blancs consider: 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR) and 32 (Space)
59   int len = theIn.length();
60   int lastgood = 0;
61   const char* str1 = theIn.c_str();
62   char* str2 = new char [len + 1];
63   bool del = true;
64
65   for (int i = 0, j = 0; i < len; i++)
66   {
67     unsigned short ucs = (unsigned short)(str1[i]);
68     if ((9 <= ucs && ucs <= 13) || ucs == 32)
69     {
70       if (!del)
71       {
72         str2[j++] = '_';
73         del = true;
74       }
75     }
76     else
77     {
78       str2[j++] = str1[i];
79       lastgood = j;
80       del = false;
81     }
82   }
83   str2[lastgood] = '\0';
84   std::string anOut = str2;
85   return anOut;
86 }
87
88 void GHS3DPRLPlugin_Hypothesis::SetMEDName(std::string theVal) {
89   //without whitespaces! ..from python?
90   std::string tmp1 = cutOrReplaceBlancs(theVal);
91   std::string tmp2 = _MEDName;
92   if (tmp1 != tmp2) {
93     _MEDName = tmp1.c_str();
94     NotifySubMeshesHypothesisModification();
95   }
96 }
97
98 void GHS3DPRLPlugin_Hypothesis::SetNbPart(int theVal) {
99   if (theVal != _NbPart) {
100     _NbPart = theVal;
101     NotifySubMeshesHypothesisModification();
102   }
103 }
104
105 void GHS3DPRLPlugin_Hypothesis::SetKeepFiles(bool theVal) {
106   if (theVal != _KeepFiles) {
107     _KeepFiles = theVal;
108     NotifySubMeshesHypothesisModification();
109   }
110 }
111
112 void GHS3DPRLPlugin_Hypothesis::SetBackground(bool theVal) {
113   if (theVal != _Background) {
114     _Background = theVal;
115     NotifySubMeshesHypothesisModification();
116   }
117 }
118
119 /*void GHS3DPRLPlugin_Hypothesis::SetToMeshHoles(bool theVal) {
120   if (theVal != _ToMeshHoles) {
121     _ToMeshHoles = theVal;
122     NotifySubMeshesHypothesisModification();
123   }
124 }*/
125
126 void GHS3DPRLPlugin_Hypothesis::SetToMergeSubdomains(bool theVal) {
127   if (theVal != _ToMergeSubdomains) {
128     _ToMergeSubdomains = theVal;
129     NotifySubMeshesHypothesisModification();
130   }
131 }
132
133 void GHS3DPRLPlugin_Hypothesis::SetToTagSubdomains(bool theVal) {
134   if (theVal != _ToTagSubdomains) {
135     _ToTagSubdomains = theVal;
136     NotifySubMeshesHypothesisModification();
137   }
138 }
139
140 void GHS3DPRLPlugin_Hypothesis::SetToOutputInterfaces(bool theVal) {
141   if (theVal != _ToOutputInterfaces) {
142     _ToOutputInterfaces = theVal;
143     NotifySubMeshesHypothesisModification();
144   }
145 }
146
147 void GHS3DPRLPlugin_Hypothesis::SetToDiscardSubdomains(bool theVal) {
148   if (theVal != _ToDiscardSubdomains) {
149     _ToDiscardSubdomains = theVal;
150     NotifySubMeshesHypothesisModification();
151   }
152 }
153
154
155 //=============================================================================
156 /*!
157  *
158  */
159 //=============================================================================
160 std::ostream& GHS3DPRLPlugin_Hypothesis::SaveTo(std::ostream& save)
161 {
162   /*save << _MEDName ; //without whitespaces!
163   save << " " << _NbPart;
164   save << " " << (int)_KeepFiles;*/
165
166   //explicit outputs for future code compatibility of saved .hdf
167   //save without any whitespaces!
168   save<<"MEDName="<<_MEDName<<";";
169   save<<"NbPart="<<_NbPart<<";";
170   //save<<"ToMeshHoles="<<(int) _ToMeshHoles<<";";
171   save<<"ToMergeSubdomains="<<(int) _ToMergeSubdomains<<";";
172   save<<"ToTagSubdomains="<<(int) _ToTagSubdomains<<";";
173   save<<"ToOutputInterfaces="<<(int) _ToOutputInterfaces<<";";
174   save<<"ToDiscardSubdomains="<<(int) _ToDiscardSubdomains<<";";
175   save<<"KeepFiles="<<(int) _KeepFiles<<";";
176   save<<"Background="<<(int) _Background<<";";
177   return save;
178 }
179
180 //=============================================================================
181 /*!
182  *
183  */
184 //=============================================================================
185 std::istream& GHS3DPRLPlugin_Hypothesis::LoadFrom(std::istream& load)
186 {
187    //explicit inputs for future code compatibility of saved .hdf
188    bool isOK = true;
189    std::string str1,str2,str3,str4;
190
191    //save without any whitespaces!
192    isOK = (load >> str1);
193    if (!(isOK)) {
194      //defaults values assumed
195      load.clear(std::ios::badbit | load.rdstate());
196      return load;
197    }
198    int pos = 0;
199    int len = str1.length();
200    while (pos < len) {
201      int found = str1.find(';',pos);
202      str2 = str1.substr(pos,found-pos);
203      int eqpos = str2.find('=',0);
204      str3 = str2.substr(0,eqpos);
205      str4 = str2.substr(eqpos+1);
206      pos = found + 1;
207
208      if (str3=="MEDName") _MEDName = str4.c_str();
209      if (str3=="NbPart") _NbPart = atoi(str4.c_str());
210      if (str3=="KeepFiles") _KeepFiles = (bool) atoi(str4.c_str());
211      //if (str3=="ToMeshHoles") _ToMeshHoles = (bool) atoi(str4.c_str());
212      if (str3=="ToMergeSubdomains") _ToMergeSubdomains = (bool) atoi(str4.c_str());
213      if (str3=="ToTagSubdomains") _ToTagSubdomains = (bool) atoi(str4.c_str());
214      if (str3=="ToOutputInterfaces") _ToOutputInterfaces = (bool) atoi(str4.c_str());
215      if (str3=="ToDiscardSubdomains") _ToDiscardSubdomains = (bool) atoi(str4.c_str());
216      if (str3=="Background") _Background = (bool) atoi(str4.c_str());
217    }
218    return load;
219 }
220
221 //=============================================================================
222 /*!
223  *
224  */
225 //=============================================================================
226 std::ostream& operator <<(std::ostream& save, GHS3DPRLPlugin_Hypothesis& hyp)
227 {
228   return hyp.SaveTo( save );
229 }
230
231 //=============================================================================
232 /*!
233  *
234  */
235 //=============================================================================
236 std::istream& operator >>(std::istream& load, GHS3DPRLPlugin_Hypothesis& hyp)
237 {
238   return hyp.LoadFrom( load );
239 }
240
241
242 //================================================================================
243 /*!
244  * \brief Does nothing
245  * \param theMesh - the built mesh
246  * \param theShape - the geometry of interest
247  * \retval bool - always false
248  */
249 //================================================================================
250 bool GHS3DPRLPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
251                                                     const TopoDS_Shape& theShape)
252 {
253   return false;
254 }
255 //================================================================================
256 /*!
257  * \brief Initialize my parameter values by default parameters.
258  *  \retval bool - true if parameter values have been successfully defined
259  */
260 //================================================================================
261
262 bool GHS3DPRLPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
263                                                         const SMESH_Mesh* /*theMesh*/)
264 {
265   return false;
266 }
267
268 //=============================================================================
269 std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
270 {
271   return "DOMAIN\0";
272 }
273
274 //=============================================================================
275 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
276 {
277   return 16;
278 }
279
280 //=============================================================================
281 bool GHS3DPRLPlugin_Hypothesis::GetDefaultKeepFiles()
282 {
283   return false;
284 }
285
286 //=============================================================================
287 bool GHS3DPRLPlugin_Hypothesis::GetDefaultBackground()
288 {
289   return false;
290 }
291
292 //=============================================================================
293 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMeshHoles()
294 //{
295 //  return false;
296 //}
297
298 //=============================================================================
299 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMergeSubdomains()
300 {
301   return false;
302 }
303
304 //=============================================================================
305 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToTagSubdomains()
306 {
307   return false;
308 }
309
310 //=============================================================================
311 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToOutputInterfaces()
312 {
313   return false;
314 }
315
316 //=============================================================================
317 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToDiscardSubdomains()
318 {
319   return false;
320 }