1 // Copyright (C) 2007-2014 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 _ToMergeSubdomains( GetDefaultToMergeSubdomains() ),
40 _ToTagSubdomains( GetDefaultToTagSubdomains() ),
41 _ToOutputInterfaces( GetDefaultToOutputInterfaces() ),
42 _ToDiscardSubdomains( GetDefaultToDiscardSubdomains() )
44 MESSAGE("GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis");
49 //=============================================================================
53 //=============================================================================
54 static std::string cutOrReplaceBlancs(std::string theIn)
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();
61 const char* str1 = theIn.c_str();
62 char* str2 = new char [len + 1];
65 for (int i = 0, j = 0; i < len; i++)
67 unsigned short ucs = (unsigned short)(str1[i]);
68 if ((9 <= ucs && ucs <= 13) || ucs == 32)
83 str2[lastgood] = '\0';
84 std::string anOut = str2;
88 void GHS3DPRLPlugin_Hypothesis::SetMEDName(std::string theVal) {
89 //without whitespaces! ..from python?
90 std::string tmp1 = cutOrReplaceBlancs(theVal);
91 std::string tmp2 = _MEDName;
93 _MEDName = tmp1.c_str();
94 NotifySubMeshesHypothesisModification();
98 void GHS3DPRLPlugin_Hypothesis::SetNbPart(int theVal) {
99 if (theVal != _NbPart) {
101 NotifySubMeshesHypothesisModification();
105 void GHS3DPRLPlugin_Hypothesis::SetKeepFiles(bool theVal) {
106 if (theVal != _KeepFiles) {
108 NotifySubMeshesHypothesisModification();
112 void GHS3DPRLPlugin_Hypothesis::SetBackground(bool theVal) {
113 if (theVal != _Background) {
114 _Background = theVal;
115 NotifySubMeshesHypothesisModification();
119 /*void GHS3DPRLPlugin_Hypothesis::SetToMeshHoles(bool theVal) {
120 if (theVal != _ToMeshHoles) {
121 _ToMeshHoles = theVal;
122 NotifySubMeshesHypothesisModification();
126 void GHS3DPRLPlugin_Hypothesis::SetToMergeSubdomains(bool theVal) {
127 if (theVal != _ToMergeSubdomains) {
128 _ToMergeSubdomains = theVal;
129 NotifySubMeshesHypothesisModification();
133 void GHS3DPRLPlugin_Hypothesis::SetToTagSubdomains(bool theVal) {
134 if (theVal != _ToTagSubdomains) {
135 _ToTagSubdomains = theVal;
136 NotifySubMeshesHypothesisModification();
140 void GHS3DPRLPlugin_Hypothesis::SetToOutputInterfaces(bool theVal) {
141 if (theVal != _ToOutputInterfaces) {
142 _ToOutputInterfaces = theVal;
143 NotifySubMeshesHypothesisModification();
147 void GHS3DPRLPlugin_Hypothesis::SetToDiscardSubdomains(bool theVal) {
148 if (theVal != _ToDiscardSubdomains) {
149 _ToDiscardSubdomains = theVal;
150 NotifySubMeshesHypothesisModification();
155 //=============================================================================
159 //=============================================================================
160 std::ostream& GHS3DPRLPlugin_Hypothesis::SaveTo(std::ostream& save)
162 /*save << _MEDName ; //without whitespaces!
163 save << " " << _NbPart;
164 save << " " << (int)_KeepFiles;*/
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<<";";
180 //=============================================================================
184 //=============================================================================
185 std::istream& GHS3DPRLPlugin_Hypothesis::LoadFrom(std::istream& load)
187 //explicit inputs for future code compatibility of saved .hdf
189 std::string str1,str2,str3,str4;
191 //save without any whitespaces!
192 isOK = (load >> str1);
194 //defaults values assumed
195 load.clear(std::ios::badbit | load.rdstate());
199 int len = str1.length();
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);
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());
221 //=============================================================================
225 //=============================================================================
226 std::ostream& operator <<(std::ostream& save, GHS3DPRLPlugin_Hypothesis& hyp)
228 return hyp.SaveTo( save );
231 //=============================================================================
235 //=============================================================================
236 std::istream& operator >>(std::istream& load, GHS3DPRLPlugin_Hypothesis& hyp)
238 return hyp.LoadFrom( load );
242 //================================================================================
244 * \brief Does nothing
245 * \param theMesh - the built mesh
246 * \param theShape - the geometry of interest
247 * \retval bool - always false
249 //================================================================================
250 bool GHS3DPRLPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
251 const TopoDS_Shape& theShape)
255 //================================================================================
257 * \brief Initialize my parameter values by default parameters.
258 * \retval bool - true if parameter values have been successfully defined
260 //================================================================================
262 bool GHS3DPRLPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
263 const SMESH_Mesh* /*theMesh*/)
268 //=============================================================================
269 std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
274 //=============================================================================
275 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
280 //=============================================================================
281 bool GHS3DPRLPlugin_Hypothesis::GetDefaultKeepFiles()
286 //=============================================================================
287 bool GHS3DPRLPlugin_Hypothesis::GetDefaultBackground()
292 //=============================================================================
293 //bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMeshHoles()
298 //=============================================================================
299 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToMergeSubdomains()
304 //=============================================================================
305 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToTagSubdomains()
310 //=============================================================================
311 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToOutputInterfaces()
316 //=============================================================================
317 bool GHS3DPRLPlugin_Hypothesis::GetDefaultToDiscardSubdomains()