Salome HOME
remove ^A symbol from a tail of blsurf message
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
1 //  BLSURFPlugin : C++ implementation
2 //
3 //  Copyright (C) 2006  OPEN CASCADE, CEA/DEN, EDF R&D
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
20 //
21 //
22 // File      : BLSURFPlugin_Hypothesis.cxx
23 // Authors   : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
24 //             & Aurelien ALLEAUME (DISTENE)
25 // Date      : 28/03/2006
26 // Project   : SALOME
27 //=============================================================================
28
29 using namespace std;
30 #include <BLSURFPlugin_Hypothesis.hxx>
31 #include <utilities.h>
32
33 //=============================================================================
34 /*!
35  *  
36  */
37 //=============================================================================
38 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
39                                                   SMESH_Gen * gen)
40   : SMESH_Hypothesis(hypId, studyId, gen),
41     _topology(GetDefaultTopology()),
42     _physicalMesh(GetDefaultPhysicalMesh()),
43     _phySize(GetDefaultPhySize()),
44     _geometricMesh(GetDefaultGeometricMesh()),
45     _angleMeshS(GetDefaultAngleMeshS()),
46     _gradation(GetDefaultGradation()),
47     _quadAllowed(GetDefaultQuadAllowed()),
48     _decimesh(GetDefaultDecimesh())
49 {
50   _name = "BLSURF_Parameters";
51   _param_algo_dim = 2;
52 }
53
54 //=============================================================================
55 /*!
56  *  
57  */
58 //=============================================================================
59 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
60 {
61   if (theTopology != _topology) {
62     _topology = theTopology;
63     NotifySubMeshesHypothesisModification();
64   }
65 }
66
67 //=============================================================================
68 /*!
69  *  
70  */
71 //=============================================================================
72 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
73 {
74   if (thePhysicalMesh != _physicalMesh) {
75     _physicalMesh = thePhysicalMesh;
76     switch( _physicalMesh ) {
77       case DefaultSize:
78       default:
79         _phySize = GetDefaultPhySize();
80         break;
81       }
82     NotifySubMeshesHypothesisModification();
83   }
84 }
85
86 //=============================================================================
87 /*!
88  *  
89  */
90 //=============================================================================
91 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
92 {
93   if (theVal != _phySize) {
94     _phySize = theVal;
95     NotifySubMeshesHypothesisModification();
96   }
97 }
98
99 //=============================================================================
100 /*!
101  *  
102  */
103 //=============================================================================
104 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
105 {
106   if (theGeometricMesh != _geometricMesh) {
107     _geometricMesh = theGeometricMesh;
108     switch( _geometricMesh ) {
109       case DefaultGeom:
110       default:
111         _angleMeshS = GetDefaultAngleMeshS();
112         _gradation  = GetDefaultGradation();
113         break;
114       }
115     NotifySubMeshesHypothesisModification();
116   }
117 }
118
119 //=============================================================================
120 /*!
121  *  
122  */
123 //=============================================================================
124 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
125 {
126   if (theVal != _angleMeshS) {
127     _angleMeshS = theVal;
128     NotifySubMeshesHypothesisModification();
129   }
130 }
131
132 //=============================================================================
133 /*!
134  *  
135  */
136 //=============================================================================
137 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
138 {
139   if (theVal != _gradation) {
140     _gradation = theVal;
141     NotifySubMeshesHypothesisModification();
142   }
143 }
144
145 //=============================================================================
146 /*!
147  *  
148  */
149 //=============================================================================
150 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
151 {
152   if (theVal != _quadAllowed) {
153     _quadAllowed = theVal;
154     NotifySubMeshesHypothesisModification();
155   }
156 }
157
158 //=============================================================================
159 /*!
160  *  
161  */
162 //=============================================================================
163 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
164 {
165   if (theVal != _decimesh) {
166     _decimesh = theVal;
167     NotifySubMeshesHypothesisModification();
168   }
169 }
170
171 //=============================================================================
172 /*!
173  *  
174  */
175 //=============================================================================
176 ostream & BLSURFPlugin_Hypothesis::SaveTo(ostream & save)
177 {
178   save << " " << (int)_topology
179        << " " << (int)_physicalMesh
180        << " " << (int)_geometricMesh
181        << " " << _phySize
182        << " " << _angleMeshS   
183        << " " << _gradation     
184        << " " << (int)_quadAllowed 
185        << " " << (int)_decimesh;
186
187   return save;
188 }
189
190 //=============================================================================
191 /*!
192  *  
193  */
194 //=============================================================================
195 istream & BLSURFPlugin_Hypothesis::LoadFrom(istream & load)
196 {
197   bool isOK = true;
198   int i;
199   double val;
200
201   isOK = (load >> i);
202   if (isOK)
203     _topology = (Topology) i;
204   else
205     load.clear(ios::badbit | load.rdstate());
206
207   isOK = (load >> i);
208   if (isOK)
209     _physicalMesh = (PhysicalMesh) i;
210   else
211     load.clear(ios::badbit | load.rdstate());
212
213   isOK = (load >> i);
214   if (isOK)
215     _geometricMesh = (GeometricMesh) i;
216   else
217     load.clear(ios::badbit | load.rdstate());
218
219   isOK = (load >> val);
220   if (isOK)
221     _phySize = val;
222   else
223     load.clear(ios::badbit | load.rdstate());
224
225   isOK = (load >> val);
226   if (isOK)
227     _angleMeshS = val;
228   else
229     load.clear(ios::badbit | load.rdstate());
230
231   isOK = (load >> val);
232   if (isOK)
233     _gradation = val;
234   else
235     load.clear(ios::badbit | load.rdstate());
236
237   isOK = (load >> i);
238   if (isOK)
239     _quadAllowed = (bool) i;
240   else
241     load.clear(ios::badbit | load.rdstate());
242
243   isOK = (load >> i);
244   if (isOK)
245     _decimesh = (bool) i;
246   else
247     load.clear(ios::badbit | load.rdstate());
248
249   return load;
250 }
251
252 //=============================================================================
253 /*!
254  *  
255  */
256 //=============================================================================
257 ostream & operator <<(ostream & save, BLSURFPlugin_Hypothesis & hyp)
258 {
259   return hyp.SaveTo( save );
260 }
261
262 //=============================================================================
263 /*!
264  *  
265  */
266 //=============================================================================
267 istream & operator >>(istream & load, BLSURFPlugin_Hypothesis & hyp)
268 {
269   return hyp.LoadFrom( load );
270 }
271
272
273 //================================================================================
274 /*!
275  * \brief Does nothing
276  * \param theMesh - the built mesh
277  * \param theShape - the geometry of interest
278  * \retval bool - always false
279  */
280 //================================================================================
281 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
282                                                       const TopoDS_Shape& theShape)
283 {
284   return false;
285 }
286
287 //=============================================================================
288 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
289 {
290   return FromCAD;
291 }
292
293 //=============================================================================
294 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
295 {
296   return PhysicalUserDefined;
297 }
298
299 //=============================================================================
300 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
301 {
302   return 10;
303 }
304
305 //=============================================================================
306 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
307 {
308   return DefaultGeom;
309 }
310
311 //=============================================================================
312 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
313 {
314   return 8;
315 }
316
317 //=============================================================================
318 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
319 {
320   return 1.1;
321 }
322
323 //=============================================================================
324 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
325 {
326   return false;
327 }
328
329 //=============================================================================
330 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()
331 {
332   return false;
333 }