1 // Copyright (C) 2007-2016 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, 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() )
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();
160 //=============================================================================
164 //=============================================================================
165 std::ostream& GHS3DPRLPlugin_Hypothesis::SaveTo(std::ostream& save)
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<<";";
182 //=============================================================================
186 //=============================================================================
187 std::istream& GHS3DPRLPlugin_Hypothesis::LoadFrom(std::istream& load)
189 //explicit inputs for future code compatibility of saved .hdf
191 std::string str1,str2,str3,str4;
193 //save without any whitespaces!
194 isOK = static_cast<bool>(load >> str1);
196 //defaults values assumed
197 load.clear(std::ios::badbit | load.rdstate());
201 int len = str1.length();
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);
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());
223 //=============================================================================
227 //=============================================================================
228 std::ostream& operator <<(std::ostream& save, GHS3DPRLPlugin_Hypothesis& hyp)
230 return hyp.SaveTo( save );
233 //=============================================================================
237 //=============================================================================
238 std::istream& operator >>(std::istream& load, GHS3DPRLPlugin_Hypothesis& hyp)
240 return hyp.LoadFrom( load );
244 //================================================================================
246 * \brief Does nothing
247 * \param theMesh - the built mesh
248 * \param theShape - the geometry of interest
249 * \retval bool - always false
251 //================================================================================
252 bool GHS3DPRLPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
253 const TopoDS_Shape& theShape)
257 //================================================================================
259 * \brief Initialize my parameter values by default parameters.
260 * \retval bool - true if parameter values have been successfully defined
262 //================================================================================
264 bool GHS3DPRLPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
265 const SMESH_Mesh* /*theMesh*/)
270 //=============================================================================
271 std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
276 //=============================================================================
277 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
282 //=============================================================================
283 bool GHS3DPRLPlugin_Hypothesis::GetDefaultKeepFiles()
288 //=============================================================================
289 bool GHS3DPRLPlugin_Hypothesis::GetDefaultBackground()
294 //=============================================================================
295 bool GHS3DPRLPlugin_Hypothesis::GetDefaultMultithread()
300 //=============================================================================
301 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMeshHoles()
306 //=============================================================================
307 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMergeSubdomains()
312 //=============================================================================
313 float GHS3DPRLPlugin_Hypothesis::GetDefaultGradation()
317 //=============================================================================
318 float GHS3DPRLPlugin_Hypothesis::GetDefaultMinSize()
322 //=============================================================================
323 float GHS3DPRLPlugin_Hypothesis::GetDefaultMaxSize()