1 // Copyright (C) 2007-2013 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.
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,
35 : SMESH_Hypothesis(hypId, studyId, gen),
36 _MEDName( GetDefaultMEDName() ),
37 _NbPart( GetDefaultNbPart() ),
38 _KeepFiles( GetDefaultKeepFiles() ),
39 _Background( GetDefaultBackground() ),
40 _ToMeshHoles( GetDefaultToMeshHoles() )
42 MESSAGE("GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis");
43 _name = "GHS3DPRL_Parameters";
47 //=============================================================================
51 //=============================================================================
52 static std::string cutOrReplaceBlancs(std::string theIn)
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();
59 const char* str1 = theIn.c_str();
60 char* str2 = new char [len + 1];
63 for (int i = 0, j = 0; i < len; i++)
65 unsigned short ucs = (unsigned short)(str1[i]);
66 if ((9 <= ucs && ucs <= 13) || ucs == 32)
81 str2[lastgood] = '\0';
82 std::string anOut = str2;
86 void GHS3DPRLPlugin_Hypothesis::SetMEDName(std::string theVal) {
87 //without whitespaces! ..from python?
88 std::string tmp1 = cutOrReplaceBlancs(theVal);
89 std::string tmp2 = _MEDName;
91 _MEDName = tmp1.c_str();
92 NotifySubMeshesHypothesisModification();
96 void GHS3DPRLPlugin_Hypothesis::SetNbPart(int theVal) {
97 if (theVal != _NbPart) {
99 NotifySubMeshesHypothesisModification();
103 void GHS3DPRLPlugin_Hypothesis::SetKeepFiles(bool theVal) {
104 if (theVal != _KeepFiles) {
106 NotifySubMeshesHypothesisModification();
110 void GHS3DPRLPlugin_Hypothesis::SetBackground(bool theVal) {
111 if (theVal != _Background) {
112 _Background = theVal;
113 NotifySubMeshesHypothesisModification();
117 void GHS3DPRLPlugin_Hypothesis::SetToMeshHoles(bool theVal) {
118 if (theVal != _ToMeshHoles) {
119 _ToMeshHoles = theVal;
120 NotifySubMeshesHypothesisModification();
125 //=============================================================================
129 //=============================================================================
130 std::ostream& GHS3DPRLPlugin_Hypothesis::SaveTo(std::ostream& save)
132 /*save << _MEDName ; //without whitespaces!
133 save << " " << _NbPart;
134 save << " " << (int)_KeepFiles;*/
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<<";";
146 //=============================================================================
150 //=============================================================================
151 std::istream& GHS3DPRLPlugin_Hypothesis::LoadFrom(std::istream& load)
153 //explicit inputs for future code compatibility of saved .hdf
155 std::string str1,str2,str3,str4;
157 //save without any whitespaces!
158 isOK = (load >> str1);
160 //defaults values assumed
161 load.clear(std::ios::badbit | load.rdstate());
165 int len = str1.length();
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);
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());
183 //=============================================================================
187 //=============================================================================
188 std::ostream& operator <<(std::ostream& save, GHS3DPRLPlugin_Hypothesis& hyp)
190 return hyp.SaveTo( save );
193 //=============================================================================
197 //=============================================================================
198 std::istream& operator >>(std::istream& load, GHS3DPRLPlugin_Hypothesis& hyp)
200 return hyp.LoadFrom( load );
204 //================================================================================
206 * \brief Does nothing
207 * \param theMesh - the built mesh
208 * \param theShape - the geometry of interest
209 * \retval bool - always false
211 //================================================================================
212 bool GHS3DPRLPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
213 const TopoDS_Shape& theShape)
217 //================================================================================
219 * \brief Initialize my parameter values by default parameters.
220 * \retval bool - true if parameter values have been successfully defined
222 //================================================================================
224 bool GHS3DPRLPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
225 const SMESH_Mesh* /*theMesh*/)
230 //=============================================================================
231 std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
236 //=============================================================================
237 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
242 //=============================================================================
243 bool GHS3DPRLPlugin_Hypothesis::GetDefaultKeepFiles()
248 //=============================================================================
249 bool GHS3DPRLPlugin_Hypothesis::GetDefaultBackground()
254 //=============================================================================
255 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMeshHoles()