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