1 // SMESH StdMeshersGUI : GUI for standard meshers
3 // Copyright (C) 2003 CEA
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.salome-platform.org or email : webmaster.salome@opencascade.org
23 // File : StdMeshersGUI_Parameters.cxx
27 #include "StdMeshersGUI_Parameters.h"
29 //#include "SMESHGUI_SpinBox.h" // for the sake of COORD_MAX, COORD_MIN definition
35 #define VALUE_MAX 1.0e+15 // COORD_MAX
36 #define VALUE_MAX_2 (VALUE_MAX*VALUE_MAX)
37 #define VALUE_MAX_3 (VALUE_MAX*VALUE_MAX*VALUE_MAX)
39 #define VALUE_SMALL 1.0e-15
40 #define VALUE_SMALL_2 (VALUE_SMALL*VALUE_SMALL)
41 #define VALUE_SMALL_3 (VALUE_SMALL*VALUE_SMALL*VALUE_SMALL)
43 //=======================================================================
44 //function : HasParameters
46 //=======================================================================
48 bool StdMeshersGUI_Parameters::HasParameters (const QString& hypType)
50 return ((hypType.compare("LocalLength") == 0) ||
51 (hypType.compare("NumberOfSegments") == 0) ||
52 (hypType.compare("MaxElementArea") == 0) ||
53 (hypType.compare("MaxElementVolume") == 0) ||
54 (hypType.compare("StartEndLength") == 0) ||
55 (hypType.compare("Deflection1D") == 0) ||
56 (hypType.compare("Arithmetic1D") == 0));
59 //=======================================================================
60 //function : SetInitValue
62 //=======================================================================
64 void StdMeshersGUI_Parameters::SetInitValue(SMESHGUI_aParameterPtr param,
67 SMESHGUI_intParameter* p = dynamic_cast<SMESHGUI_intParameter*>(param.get());
70 p->InitValue() = initValue;
74 SMESHGUI_enumParameter* q = dynamic_cast<SMESHGUI_enumParameter*>(param.get());
77 q->InitValue() = initValue;
81 SMESHGUI_boolParameter* b = dynamic_cast<SMESHGUI_boolParameter*>(param.get());
84 b->InitValue() = (bool)initValue;
89 //=======================================================================
90 //function : SetInitValue
92 //=======================================================================
94 void StdMeshersGUI_Parameters::SetInitValue(SMESHGUI_aParameterPtr param,
97 SMESHGUI_doubleParameter* p = dynamic_cast<SMESHGUI_doubleParameter*>(param.get());
98 if ( p ) p->InitValue() = initValue;
101 //=======================================================================
102 //function : SetInitValue
104 //=======================================================================
106 void StdMeshersGUI_Parameters::SetInitValue(SMESHGUI_aParameterPtr param,
107 const char* initValue)
109 SMESHGUI_strParameter* p = dynamic_cast<SMESHGUI_strParameter*>(param.get());
110 if ( p ) p->InitValue() = initValue;
113 //=======================================================================
114 //function : SetInitValue
116 //=======================================================================
117 void StdMeshersGUI_Parameters::SetInitValue( SMESHGUI_aParameterPtr param,
118 SMESH::double_array& initValue)
120 SMESHGUI_tableParameter* p = dynamic_cast<SMESHGUI_tableParameter*>(param.get());
123 p->setRowCount( initValue.length()/2 );
124 p->setData( initValue );
128 //=======================================================================
129 //function : GetParameters
131 //=======================================================================
133 // SMESHGUI_doubleParameter( initValue, label, bottom, top, step, decimals )
134 #define DOUBLE_PARAM(v,l,b,t,s,d) SMESHGUI_aParameterPtr(new SMESHGUI_doubleParameter(v,l,b,t,s,d))
135 #define INT_PARAM(v,l,b,t) SMESHGUI_aParameterPtr(new SMESHGUI_intParameter(v,l,b,t))
136 #define ENUM_PARAM(v,i,l) SMESHGUI_aParameterPtr(new SMESHGUI_enumParameter(v,i,l))
137 #define STR_PARAM(i,l) SMESHGUI_aParameterPtr(new SMESHGUI_strParameter(i,l))
138 #define BOOL_PARAM(i,l) SMESHGUI_aParameterPtr(new SMESHGUI_boolParameter(i,l))
140 void StdMeshersGUI_Parameters::GetParameters (const QString& hypType,
141 list<SMESHGUI_aParameterPtr> & paramList )
145 if (hypType.compare("LocalLength") == 0)
147 paramList.push_back( DOUBLE_PARAM (1.0,
148 QObject::tr("SMESH_LOCAL_LENGTH_PARAM"),
149 VALUE_SMALL, VALUE_MAX, 1.0, 6));
151 else if (hypType.compare("NumberOfSegments") == 0)
153 //0-th parameter in list
154 paramList.push_back ( INT_PARAM (3,
155 QObject::tr("SMESH_NB_SEGMENTS_PARAM"),
158 types.append( QObject::tr( "SMESH_DISTR_REGULAR" ) );
159 types.append( QObject::tr( "SMESH_DISTR_SCALE" ) );
160 types.append( QObject::tr( "SMESH_DISTR_TAB" ) );
161 types.append( QObject::tr( "SMESH_DISTR_EXPR" ) );
162 //string description of distribution types
164 SMESHGUI_enumParameter* type = new SMESHGUI_enumParameter( types, 0, QObject::tr( "SMESH_DISTR_TYPE" ) );
165 SMESHGUI_dependParameter::ShownMap& aMap = type->shownMap();
166 aMap[0].append( 0 ); // if DistrType=0 (regular), then number of segments and types are shown (0-th and 1-th)
168 aMap[1].append( 0 ); // if DistrType=1 (scale), then number of segments, types and scale are shown
171 aMap[2].append( 0 ); // if DistrType=2 (table), then number of segments, types, table and exponent are shown
175 aMap[3].append( 0 ); // if DistrType=3 (expression), then number of segments, types, expression and exponent are shown
179 //1-th parameter in list
180 paramList.push_back ( SMESHGUI_aParameterPtr( type ) );
182 //2-th parameter in list
183 paramList.push_back ( DOUBLE_PARAM (1.0,
184 QObject::tr("SMESH_NB_SEGMENTS_SCALE_PARAM"),
185 VALUE_SMALL, VALUE_MAX, 0.1, 6 ));
186 SMESHGUI_tableParameter* tab = new SMESHGUI_tableParameter( 0.0, QObject::tr( "SMESH_TAB_FUNC" ) );
187 tab->setRowCount( 5 );
188 tab->setColCount( 2 );
189 //default size of table: 5x2
191 tab->setColName( 0, "t" );
192 tab->setColName( 1, "f(t)" );
193 tab->setValidator( 0, 0.0, 1.0, 3 );
194 tab->setValidator( 1, 1E-7, 1E+300, 3 );
195 tab->setEditRows( true );
197 //3-th parameter in list
198 paramList.push_back ( SMESHGUI_aParameterPtr( tab ) );
200 //4-th parameter in list
201 paramList.push_back ( STR_PARAM ( "", QObject::tr( "SMESH_EXPR_FUNC" ) ) );
203 //5-th parameter in list
204 paramList.push_back ( BOOL_PARAM ( false, QObject::tr( "SMESH_EXP_MODE" ) ) );
206 else if (hypType.compare("Arithmetic1D") == 0)
208 paramList.push_back( DOUBLE_PARAM ( 1.0,
209 QObject::tr("SMESH_START_LENGTH_PARAM"),
210 VALUE_SMALL, VALUE_MAX, 1, 6));
211 paramList.push_back( DOUBLE_PARAM ( 10.0,
212 QObject::tr("SMESH_END_LENGTH_PARAM"),
213 VALUE_SMALL, VALUE_MAX, 1, 6));
215 else if (hypType.compare("MaxElementArea") == 0)
217 paramList.push_back( DOUBLE_PARAM (1.0,
218 QObject::tr("SMESH_MAX_ELEMENT_AREA_PARAM"),
219 VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6));
221 else if (hypType.compare("MaxElementVolume") == 0)
223 paramList.push_back( DOUBLE_PARAM ( 1.0,
224 QObject::tr("SMESH_MAX_ELEMENT_VOLUME_PARAM"),
225 VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6));
227 else if (hypType.compare("StartEndLength") == 0)
229 paramList.push_back( DOUBLE_PARAM ( 1.0,
230 QObject::tr("SMESH_START_LENGTH_PARAM"),
231 VALUE_SMALL, VALUE_MAX, 1, 6));
232 paramList.push_back( DOUBLE_PARAM ( 10.0,
233 QObject::tr("SMESH_END_LENGTH_PARAM"),
234 VALUE_SMALL, VALUE_MAX, 1, 6));
236 else if (hypType.compare("Deflection1D") == 0)
238 paramList.push_back( DOUBLE_PARAM ( 1.0,
239 QObject::tr("SMESH_DEFLECTION1D_PARAM"),
240 VALUE_SMALL, VALUE_MAX, 1, 6));
244 //=======================================================================
245 //function : GetParameters
247 //=======================================================================
249 void StdMeshersGUI_Parameters::GetParameters (SMESH::SMESH_Hypothesis_ptr theHyp,
250 list<SMESHGUI_aParameterPtr> & paramList )
254 if (theHyp->_is_nil()) return;
256 QString hypType = theHyp->GetName();
257 GetParameters( hypType, paramList ); // get default parameters
258 if ( paramList.empty() )
261 // set current values
262 if (hypType.compare("LocalLength") == 0)
264 StdMeshers::StdMeshers_LocalLength_var LL =
265 StdMeshers::StdMeshers_LocalLength::_narrow(theHyp);
266 SetInitValue( paramList.front(), LL->GetLength() );
268 else if (hypType.compare("NumberOfSegments") == 0)
270 StdMeshers::StdMeshers_NumberOfSegments_var NOS =
271 StdMeshers::StdMeshers_NumberOfSegments::_narrow(theHyp);
273 list<SMESHGUI_aParameterPtr>::iterator anIt = paramList.begin();
274 SetInitValue( *anIt, (int) NOS->GetNumberOfSegments()); anIt++;
275 int DType = (int) NOS->GetDistrType();
276 SetInitValue( *anIt, DType ); anIt++;
279 SetInitValue( *anIt, NOS->GetScaleFactor());
284 SMESH::double_array* tab_func = NOS->GetTableFunction();
285 SetInitValue( *anIt, *tab_func );
292 char* expr_func = NOS->GetExpressionFunction();
293 SetInitValue( *anIt, expr_func );
298 if( DType==2 || DType==3 )
299 SetInitValue( *anIt, (bool)NOS->IsExponentMode());
301 else if (hypType.compare("Arithmetic1D") == 0)
303 StdMeshers::StdMeshers_Arithmetic1D_var hyp =
304 StdMeshers::StdMeshers_Arithmetic1D::_narrow(theHyp);
305 SetInitValue( paramList.front(), hyp->GetLength( true )) ;
306 SetInitValue( paramList.back(), hyp->GetLength( false )) ;
308 else if (hypType.compare("MaxElementArea") == 0)
310 StdMeshers::StdMeshers_MaxElementArea_var MEA =
311 StdMeshers::StdMeshers_MaxElementArea::_narrow(theHyp);
312 SetInitValue( paramList.front(), MEA->GetMaxElementArea() );
314 else if (hypType.compare("MaxElementVolume") == 0)
316 StdMeshers::StdMeshers_MaxElementVolume_var MEV =
317 StdMeshers::StdMeshers_MaxElementVolume::_narrow(theHyp);
318 SetInitValue( paramList.front(), MEV->GetMaxElementVolume() );
320 else if (hypType.compare("StartEndLength") == 0)
322 StdMeshers::StdMeshers_StartEndLength_var hyp =
323 StdMeshers::StdMeshers_StartEndLength::_narrow(theHyp);
324 SetInitValue( paramList.front(), hyp->GetLength( true ));
325 SetInitValue( paramList.back(), hyp->GetLength( false ));
327 else if (hypType.compare("Deflection1D") == 0)
329 StdMeshers::StdMeshers_Deflection1D_var hyp =
330 StdMeshers::StdMeshers_Deflection1D::_narrow(theHyp);
331 SetInitValue( paramList.back(), hyp->GetDeflection()) ;
335 //=======================================================================
336 //function : GetParameters
338 //=======================================================================
339 void StdMeshersGUI_Parameters::GetParameters (SMESH::SMESH_Hypothesis_ptr hyp,
340 list<SMESHGUI_aParameterPtr> & paramList,
344 list<SMESHGUI_aParameterPtr>::iterator paramIt = paramList.begin();
345 for ( ; paramIt != paramList.end(); paramIt++) {
346 if (params.compare("")) params += " ; ";
348 SMESHGUI_aParameter::Type t = (*paramIt)->GetType();
349 if( t==SMESHGUI_aParameter::DOUBLE )
351 double aDoubleValue = 0.;
352 (*paramIt)->GetNewDouble(aDoubleValue);
353 params += QString::number(aDoubleValue);
355 else if( t==SMESHGUI_aParameter::STRING || t==SMESHGUI_aParameter::ENUM )
357 QString aStrValue( "" );
358 (*paramIt)->GetNewText(aStrValue);
359 params += aStrValue.simplifyWhiteSpace();
361 else if( t==SMESHGUI_aParameter::TABLE )
368 (*paramIt)->GetNewInt(aIntValue);
369 params += QString::number(aIntValue);
374 //=======================================================================
375 //function : SetParameters
377 //=======================================================================
379 bool StdMeshersGUI_Parameters::SetParameters(SMESH::SMESH_Hypothesis_ptr theHyp,
380 const list<SMESHGUI_aParameterPtr> & paramList )
382 if (theHyp->_is_nil() || paramList.empty()) return false;
384 bool modified = false;
386 QString hypType = theHyp->GetName();
388 if (hypType.compare("LocalLength") == 0)
390 StdMeshers::StdMeshers_LocalLength_var LL =
391 StdMeshers::StdMeshers_LocalLength::_narrow(theHyp);
392 double length = LL->GetLength();
393 modified = paramList.front()->GetNewDouble( length );
394 LL->SetLength(length);
396 else if (hypType.compare("NumberOfSegments") == 0)
398 StdMeshers::StdMeshers_NumberOfSegments_var NOS =
399 StdMeshers::StdMeshers_NumberOfSegments::_narrow(theHyp);
401 list<SMESHGUI_aParameterPtr>::const_iterator anIt = paramList.begin();
404 SMESH::double_array TabF;
408 modified = (*anIt)->GetNewInt( NbSeg ); anIt++;
409 modified = (*anIt)->GetNewInt( DType ) || modified; anIt++;
410 modified = (*anIt)->GetNewDouble( Scale ) || modified; anIt++;
411 SMESHGUI_aParameterPtr p = *anIt;
412 ((SMESHGUI_tableParameter*)p.get())->data( TabF ); anIt++; modified = true;
413 modified = (*anIt)->GetNewText( exprF ) || modified; anIt++;
414 modified = (*anIt)->GetNewInt( expType ) || modified;
416 NOS->SetNumberOfSegments( NbSeg );
417 NOS->SetDistrType( DType );
419 NOS->SetScaleFactor( Scale );
421 NOS->SetTableFunction( TabF );
423 NOS->SetExpressionFunction( CORBA::string_dup( exprF.latin1() ) );
424 if( DType==2 || DType==3 )
425 NOS->SetExponentMode( (bool)expType );
427 else if (hypType.compare("Arithmetic1D") == 0)
429 if ( paramList.size() != 2 )
431 StdMeshers::StdMeshers_Arithmetic1D_var hyp =
432 StdMeshers::StdMeshers_Arithmetic1D::_narrow(theHyp);
433 double begLength = hyp->GetLength( true ) ;
434 double endLength = hyp->GetLength( false ) ;
435 modified = paramList.front()->GetNewDouble( begLength );
436 modified = paramList.back()->GetNewDouble( endLength ) || modified;
437 hyp->SetLength( begLength, true );
438 hyp->SetLength( endLength, false );
440 else if (hypType.compare("MaxElementArea") == 0)
442 StdMeshers::StdMeshers_MaxElementArea_var MEA =
443 StdMeshers::StdMeshers_MaxElementArea::_narrow(theHyp);
444 double MaxArea = MEA->GetMaxElementArea();
445 modified = paramList.front()->GetNewDouble( MaxArea );
446 MEA->SetMaxElementArea(MaxArea);
448 else if (hypType.compare("MaxElementVolume") == 0)
450 StdMeshers::StdMeshers_MaxElementVolume_var MEV =
451 StdMeshers::StdMeshers_MaxElementVolume::_narrow(theHyp);
452 double MaxVolume = MEV->GetMaxElementVolume() ;
453 modified = paramList.front()->GetNewDouble( MaxVolume );
454 MEV->SetMaxElementVolume(MaxVolume);
456 else if (hypType.compare("StartEndLength") == 0)
458 if ( paramList.size() != 2 )
460 StdMeshers::StdMeshers_StartEndLength_var hyp =
461 StdMeshers::StdMeshers_StartEndLength::_narrow(theHyp);
462 double begLength = hyp->GetLength( true ) ;
463 double endLength = hyp->GetLength( false ) ;
464 modified = paramList.front()->GetNewDouble( begLength );
465 modified = paramList.back()->GetNewDouble( endLength ) || modified;
466 hyp->SetLength( begLength, true );
467 hyp->SetLength( endLength, false );
469 else if (hypType.compare("Deflection1D") == 0)
471 StdMeshers::StdMeshers_Deflection1D_var hyp =
472 StdMeshers::StdMeshers_Deflection1D::_narrow(theHyp);
473 double value = hyp->GetDeflection() ;
474 modified = paramList.front()->GetNewDouble( value );
475 hyp->SetDeflection( value );