1 // SMESH StdMeshersGUI : GUI for plugged-in 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.com
23 // File : StdMeshersGUI_StdHypothesisCreator.cxx
24 // Author : Alexander SOLOVYOV
26 // $Header: /home/server/cvs/SMESH/SMESH_SRC/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx
28 #include "StdMeshersGUI_StdHypothesisCreator.h"
31 #include <SMESHGUI_SpinBox.h>
32 #include <SMESHGUI_HypothesesUtils.h>
33 #include <SMESHGUI_Utils.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
39 #include CORBA_SERVER_HEADER(SMESH_Mesh)
47 const double VALUE_MAX = 1.0e+15, // COORD_MAX
48 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
49 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
50 VALUE_SMALL = 1.0e-15,
51 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
52 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
54 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
55 : SMESHGUI_GenericHypothesisCreator( type )
59 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
63 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
65 return buildStdFrame();
68 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
73 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
75 //here this method must be empty because buildStdParam sets values itself
78 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
80 ListOfStdParams params;
81 bool res = getStdParamFromDlg( params );
84 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().latin1() );
85 params.remove( params.begin() );
88 QString valueStr = stdParamValues( params );
90 if( res && !params.isEmpty() )
92 if( hypType()=="LocalLength" )
94 StdMeshers::StdMeshers_LocalLength_var h =
95 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
97 h->SetLength( params[0].myValue.toDouble() );
99 else if( hypType()=="Arithmetic1D" )
101 StdMeshers::StdMeshers_Arithmetic1D_var h =
102 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
104 h->SetLength( params[0].myValue.toDouble(), true );
105 h->SetLength( params[1].myValue.toDouble(), false );
107 else if( hypType()=="MaxElementArea" )
109 StdMeshers::StdMeshers_MaxElementArea_var h =
110 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
112 h->SetMaxElementArea( params[0].myValue.toDouble() );
114 else if( hypType()=="MaxElementVolume" )
116 StdMeshers::StdMeshers_MaxElementVolume_var h =
117 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
119 h->SetMaxElementVolume( params[0].myValue.toDouble() );
121 else if( hypType()=="StartEndLength" )
123 StdMeshers::StdMeshers_StartEndLength_var h =
124 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
126 h->SetLength( params[0].myValue.toDouble(), true );
127 h->SetLength( params[1].myValue.toDouble(), false );
129 else if( hypType()=="Deflection1D" )
131 StdMeshers::StdMeshers_Deflection1D_var h =
132 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
134 h->SetDeflection( params[0].myValue.toDouble() );
136 else if( hypType()=="AutomaticLength" )
138 StdMeshers::StdMeshers_AutomaticLength_var h =
139 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
141 h->SetFineness( params[0].myValue.toDouble() );
147 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
150 SMESHGUI_GenericHypothesisCreator::StdParam item;
155 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
156 item.myName = tr( "SMESH_NAME" );
157 item.myValue = data ? data->Label : QString();
161 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
163 if( hypType()=="LocalLength" )
165 StdMeshers::StdMeshers_LocalLength_var h =
166 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
168 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
169 item.myValue = h->GetLength();
172 else if( hypType()=="Arithmetic1D" )
174 StdMeshers::StdMeshers_Arithmetic1D_var h =
175 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
177 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
178 item.myValue = h->GetLength( true );
180 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
181 item.myValue = h->GetLength( false );
184 else if( hypType()=="MaxElementArea" )
186 StdMeshers::StdMeshers_MaxElementArea_var h =
187 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
189 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
190 item.myValue = h->GetMaxElementArea();
193 else if( hypType()=="MaxElementVolume" )
195 StdMeshers::StdMeshers_MaxElementVolume_var h =
196 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
198 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
199 item.myValue = h->GetMaxElementVolume();
202 else if( hypType()=="StartEndLength" )
204 StdMeshers::StdMeshers_StartEndLength_var h =
205 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
207 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
208 item.myValue = h->GetLength( true );
210 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
211 item.myValue = h->GetLength( false );
214 else if( hypType()=="Deflection1D" )
216 StdMeshers::StdMeshers_Deflection1D_var h =
217 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
219 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
220 item.myValue = h->GetDeflection();
223 else if( hypType()=="AutomaticLength" )
225 StdMeshers::StdMeshers_AutomaticLength_var h =
226 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
228 item.myName = tr( "SMESH_FINENESS_PARAM" );
229 item.myValue = h->GetFineness();
237 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget( QWidget* w, const int ) const
239 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
240 if( hypType()=="LocalLength" && sb )
242 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
244 else if( hypType()=="Arithmetic1D" && sb )
246 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
248 else if( hypType()=="MaxElementArea" && sb )
250 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
252 else if( hypType()=="MaxElementVolume" && sb )
254 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
256 else if( hypType()=="StartEndLength" && sb )
258 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
260 else if( hypType()=="Deflection1D" && sb )
262 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
264 else if ( sb ) // default validator for possible ancestors
266 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
270 QString StdMeshersGUI_StdHypothesisCreator::caption() const
272 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ) );
275 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
277 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ) );
278 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
281 QString StdMeshersGUI_StdHypothesisCreator::type() const
283 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ) );
286 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
288 static QMap<QString,QString> types;
289 if( types.isEmpty() )
291 types.insert( "LocalLength", "LOCAL_LENGTH" );
292 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
293 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
294 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
295 types.insert( "StartEndLength", "START_END_LENGTH" );
296 types.insert( "Deflection1D", "DEFLECTION1D" );
297 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
298 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
302 if( types.contains( t ) )
308 //================================================================================
310 * \brief Widget: slider with left and right labels
312 //================================================================================
314 class TDoubleSliderWith2Lables: public QHBox
317 TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
318 const double initValue, const double bottom,
319 const double top , const double precision,
320 QWidget * parent=0 , const char * name=0 )
321 :QHBox(parent,name), _bottom(bottom), _precision(precision)
323 if ( !leftLabel.isEmpty() ) (new QLabel( this ))->setText( leftLabel );
324 _slider = new QSlider( Horizontal, this );
325 _slider->setRange( 0, toInt( top ));
326 _slider->setValue( toInt( initValue ));
327 if ( !rightLabel.isEmpty() ) (new QLabel( this ))->setText( rightLabel );
329 double value() const { return _bottom + _slider->value() * _precision; }
330 QSlider * getSlider() const { return _slider; }
331 int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
333 double _bottom, _precision;
337 //=======================================================================
338 //function : getCustomWidget
340 //=======================================================================
342 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
343 QWidget* parent) const
345 if ( hypType()=="AutomaticLength" && param.myValue.type() == QVariant::Double )
346 return new TDoubleSliderWith2Lables( "0 ", " 1", param.myValue.toDouble(),
347 0, 1, 0.01, parent );
352 //=======================================================================
353 //function : getParamFromCustomWidget
355 //=======================================================================
357 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
358 QWidget* widget) const
360 if ( hypType()=="AutomaticLength" ) {
361 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
363 param.myValue = w->value();