1 // BLSURFPlugin : C++ implementation
3 // Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D
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.
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.
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
19 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 // File : BLSURFPlugin_Hypothesis.cxx
23 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
24 // & Aurelien ALLEAUME (DISTENE)
27 //=============================================================================
30 #include <BLSURFPlugin_Hypothesis.hxx>
31 #include <utilities.h>
33 //=============================================================================
34 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
36 : SMESH_Hypothesis(hypId, studyId, gen),
37 _topology(GetDefaultTopology()),
38 _physicalMesh(GetDefaultPhysicalMesh()),
39 _phySize(GetDefaultPhySize()),
40 _phyMax(GetDefaultMaxSize()),
41 _phyMin(GetDefaultMinSize()),
42 _hgeoMax(GetDefaultMaxSize()),
43 _hgeoMin(GetDefaultMinSize()),
44 _geometricMesh(GetDefaultGeometricMesh()),
45 _angleMeshS(GetDefaultAngleMeshS()),
46 _angleMeshC(GetDefaultAngleMeshC()),
47 _gradation(GetDefaultGradation()),
48 _quadAllowed(GetDefaultQuadAllowed()),
49 _decimesh(GetDefaultDecimesh()),
50 _verb( GetDefaultVerbosity() )
52 _name = "BLSURF_Parameters";
55 // to desable writing boundaries
56 //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
59 const char* optionNames[] = {
108 while ( optionNames[i][0] )
109 _option2value[ optionNames[i++] ].clear();
113 //=============================================================================
114 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
116 if (theTopology != _topology) {
117 _topology = theTopology;
118 NotifySubMeshesHypothesisModification();
122 //=============================================================================
123 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
125 if (thePhysicalMesh != _physicalMesh) {
126 _physicalMesh = thePhysicalMesh;
127 switch( _physicalMesh ) {
130 _phySize = GetDefaultPhySize();
133 NotifySubMeshesHypothesisModification();
137 //=============================================================================
138 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal)
140 if (theVal != _phySize) {
142 NotifySubMeshesHypothesisModification();
146 //=============================================================================
147 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize)
149 if (theMinSize != _phyMin) {
150 _phyMin = theMinSize;
151 NotifySubMeshesHypothesisModification();
155 //=============================================================================
156 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize)
158 if (theMaxSize != _phyMax) {
159 _phyMax = theMaxSize;
160 NotifySubMeshesHypothesisModification();
165 //=============================================================================
166 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize)
168 if (theMinSize != _hgeoMin) {
169 _hgeoMin = theMinSize;
170 NotifySubMeshesHypothesisModification();
174 //=============================================================================
175 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize)
177 if (theMaxSize != _hgeoMax) {
178 _hgeoMax = theMaxSize;
179 NotifySubMeshesHypothesisModification();
183 //=============================================================================
184 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
186 if (theGeometricMesh != _geometricMesh) {
187 _geometricMesh = theGeometricMesh;
188 switch( _geometricMesh ) {
191 _angleMeshS = GetDefaultAngleMeshS();
192 _gradation = GetDefaultGradation();
195 NotifySubMeshesHypothesisModification();
199 //=============================================================================
200 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal)
202 if (theVal != _angleMeshS) {
203 _angleMeshS = theVal;
204 NotifySubMeshesHypothesisModification();
208 //=============================================================================
209 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal)
211 if (theVal != _angleMeshC) {
212 _angleMeshC = theVal;
213 NotifySubMeshesHypothesisModification();
217 //=============================================================================
218 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
220 if (theVal != _gradation) {
222 NotifySubMeshesHypothesisModification();
226 //=============================================================================
227 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal)
229 if (theVal != _quadAllowed) {
230 _quadAllowed = theVal;
231 NotifySubMeshesHypothesisModification();
235 //=============================================================================
236 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal)
238 if (theVal != _decimesh) {
240 NotifySubMeshesHypothesisModification();
244 //=============================================================================
245 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal)
247 if (theVal != _verb) {
249 NotifySubMeshesHypothesisModification();
252 //=============================================================================
253 void BLSURFPlugin_Hypothesis::SetOptionValue(const string& optionName,
254 const string& optionValue) throw (SALOME_Exception)
256 TOptionValues::iterator op_val = _option2value.find( optionName );
257 if ( op_val == _option2value.end() ) {
258 string msg = "Unknown BLSURF option: <";
259 msg += optionName + ">";
260 throw SALOME_Exception(msg.c_str());
262 if ( op_val->second != optionValue ) {
263 op_val->second = optionValue;
264 NotifySubMeshesHypothesisModification();
268 //=============================================================================
269 string BLSURFPlugin_Hypothesis::GetOptionValue(const string& optionName)
270 throw (SALOME_Exception)
272 TOptionValues::iterator op_val = _option2value.find( optionName );
273 if ( op_val == _option2value.end() ) {
274 string msg = "Unknown BLSURF option: <";
275 msg += optionName + ">";
276 throw SALOME_Exception(msg.c_str());
278 return op_val->second;
281 //=============================================================================
282 void BLSURFPlugin_Hypothesis::ClearOption(const string& optionName)
284 TOptionValues::iterator op_val = _option2value.find( optionName );
285 if ( op_val != _option2value.end() )
286 op_val->second.clear();
289 //=============================================================================
290 ostream & BLSURFPlugin_Hypothesis::SaveTo(ostream & save)
292 save << " " << (int)_topology
293 << " " << (int)_physicalMesh
294 << " " << (int)_geometricMesh
296 << " " << _angleMeshS
298 << " " << (int)_quadAllowed
299 << " " << (int)_decimesh;
300 save << " " << _phyMin
302 << " " << _angleMeshC
307 TOptionValues::iterator op_val = _option2value.begin();
308 for ( ; op_val != _option2value.end(); ++op_val ) {
309 if ( !op_val->second.empty() )
310 save << " " << op_val->first
311 << " " << op_val->second << "%#"; // "%#" is a mark of value end
317 //=============================================================================
318 istream & BLSURFPlugin_Hypothesis::LoadFrom(istream & load)
326 _topology = (Topology) i;
328 load.clear(ios::badbit | load.rdstate());
332 _physicalMesh = (PhysicalMesh) i;
334 load.clear(ios::badbit | load.rdstate());
338 _geometricMesh = (GeometricMesh) i;
340 load.clear(ios::badbit | load.rdstate());
342 isOK = (load >> val);
346 load.clear(ios::badbit | load.rdstate());
348 isOK = (load >> val);
352 load.clear(ios::badbit | load.rdstate());
354 isOK = (load >> val);
358 load.clear(ios::badbit | load.rdstate());
362 _quadAllowed = (bool) i;
364 load.clear(ios::badbit | load.rdstate());
368 _decimesh = (bool) i;
370 load.clear(ios::badbit | load.rdstate());
372 isOK = (load >> val);
376 load.clear(ios::badbit | load.rdstate());
378 isOK = (load >> val);
382 load.clear(ios::badbit | load.rdstate());
384 isOK = (load >> val);
388 load.clear(ios::badbit | load.rdstate());
390 isOK = (load >> val);
394 load.clear(ios::badbit | load.rdstate());
396 isOK = (load >> val);
400 load.clear(ios::badbit | load.rdstate());
406 load.clear(ios::badbit | load.rdstate());
408 string optName, optValue;
410 isOK = (load >> optName);
412 isOK = (load >> optValue);
414 string & value = _option2value[ optName ];
416 int len = value.size();
417 // continue reading until "%#" encountered
418 while ( value[len-1] != '#' || value[len-2] != '%' )
420 isOK = (load >> optValue);
430 value[ len-2 ] = '\0'; //cut off "%#"
437 //=============================================================================
438 ostream & operator <<(ostream & save, BLSURFPlugin_Hypothesis & hyp)
440 return hyp.SaveTo( save );
443 //=============================================================================
444 istream & operator >>(istream & load, BLSURFPlugin_Hypothesis & hyp)
446 return hyp.LoadFrom( load );
449 //================================================================================
451 * \brief Does nothing
453 //================================================================================
455 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
456 const TopoDS_Shape& theShape)
461 //=============================================================================
462 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology()
467 //=============================================================================
468 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh()
470 return PhysicalUserDefined;
473 //=============================================================================
474 double BLSURFPlugin_Hypothesis::GetDefaultPhySize()
479 //======================================================================
480 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize()
485 //======================================================================
486 double BLSURFPlugin_Hypothesis::GetDefaultMinSize()
491 //======================================================================
492 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh()
497 //=============================================================================
498 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS()
503 //=============================================================================
504 double BLSURFPlugin_Hypothesis::GetDefaultGradation()
509 //=============================================================================
510 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed()
515 //=============================================================================
516 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh()