1 // NETGENPlugin GUI: GUI for plugged-in mesher NETGENPlugin
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 : NETGENPluginGUI_HypothesisCreator.cxx
24 // Author : Michael Zorin
25 // Module : NETGENPlugin
28 #include "NETGENPluginGUI_HypothesisCreator.h"
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
33 #include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm)
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
38 #include <SalomeApp_Tools.h>
40 #include <QtxDoubleSpinBox.h>
41 #include <QtxComboBox.h>
61 NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType )
62 : SMESHGUI_GenericHypothesisCreator( theHypType ),
67 NETGENPluginGUI_HypothesisCreator::~NETGENPluginGUI_HypothesisCreator()
71 bool NETGENPluginGUI_HypothesisCreator::checkParams() const
73 NetgenHypothesisData data_old, data_new;
74 readParamsFromHypo( data_old );
75 readParamsFromWidgets( data_new );
76 bool res = storeParamsToHypo( data_new );
77 storeParamsToHypo( data_old );
81 QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame()
83 QFrame* fr = new QFrame( 0 );
84 fr->setObjectName( "myframe" );
85 QVBoxLayout* lay = new QVBoxLayout( fr );
89 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
90 lay->addWidget( GroupC1 );
92 QGridLayout* aGroupLayout = new QGridLayout( GroupC1 );
93 aGroupLayout->setSpacing( 6 );
94 aGroupLayout->setMargin( 11 );
100 aGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
101 myName = new QLineEdit( GroupC1 );
102 aGroupLayout->addWidget( myName, row, 1 );
106 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MAX_SIZE" ), GroupC1 ), row, 0 );
107 myMaxSize = new QtxDoubleSpinBox( GroupC1 );
108 myMaxSize->setDecimals( 7 );
109 myMaxSize->setMinimum( 1e-07 );
110 myMaxSize->setMaximum( 1e+06 );
111 myMaxSize->setSingleStep( 10 );
112 aGroupLayout->addWidget( myMaxSize, row, 1 );
115 mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 );
116 aGroupLayout->addWidget( mySecondOrder, row, 0 );
119 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_FINENESS" ), GroupC1 ), row, 0 );
120 myFineness = new QtxComboBox( GroupC1 );
122 types.append( QObject::tr( "NETGEN_VERYCOARSE" ) );
123 types.append( QObject::tr( "NETGEN_COARSE" ) );
124 types.append( QObject::tr( "NETGEN_MODERATE" ) );
125 types.append( QObject::tr( "NETGEN_FINE" ) );
126 types.append( QObject::tr( "NETGEN_VERYFINE" ) );
127 types.append( QObject::tr( "NETGEN_CUSTOM" ) );
128 myFineness->insertItems( myFineness->count(), types );
129 aGroupLayout->addWidget( myFineness, row, 1 );
132 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_GROWTH_RATE" ), GroupC1 ), row, 0 );
133 myGrowthRate = new QtxDoubleSpinBox( GroupC1 );
134 myGrowthRate->setMinimum( 0.1 );
135 myGrowthRate->setMaximum( 10 );
136 myGrowthRate->setSingleStep( 0.1 );
137 aGroupLayout->addWidget( myGrowthRate, row, 1 );
140 const double VALUE_MAX = 1.0e+6;
142 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 ), row, 0 );
143 myNbSegPerEdge = new QtxDoubleSpinBox( GroupC1 );
144 myNbSegPerEdge->setMinimum( 0.2 );
145 myNbSegPerEdge->setMaximum( VALUE_MAX ); // (PAL14890) max value in native netgen gui is 5
146 aGroupLayout->addWidget( myNbSegPerEdge, row, 1 );
149 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 ), row, 0 );
150 myNbSegPerRadius = new QtxDoubleSpinBox( GroupC1 );
151 myNbSegPerRadius->setMinimum( 0.2 );
152 myNbSegPerRadius->setMaximum( VALUE_MAX ); // (PAL14890) max value in native netgen gui is 5
153 aGroupLayout->addWidget( myNbSegPerRadius, row, 1 );
156 if ( hypType()=="NETGEN_Parameters_2D" )
158 myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 );
159 aGroupLayout->addWidget( myAllowQuadrangles, row, 0 );
164 myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 );
165 aGroupLayout->addWidget( myOptimize, row, 0 );
168 connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) );
173 void NETGENPluginGUI_HypothesisCreator::retrieveParams() const
175 NetgenHypothesisData data;
176 readParamsFromHypo( data );
179 myName->setText( data.myName );
180 myMaxSize->setValue( data.myMaxSize );
181 mySecondOrder->setChecked( data.mySecondOrder );
182 myOptimize->setChecked( data.myOptimize );
183 myFineness->setCurrentIndex( data.myFineness );
184 myGrowthRate->setValue( data.myGrowthRate );
185 myNbSegPerEdge->setValue( data.myNbSegPerEdge );
186 myNbSegPerRadius->setValue( data.myNbSegPerRadius );
188 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
191 bool isCustom = (myFineness->currentIndex() == UserDefined);
192 myGrowthRate->setEnabled(isCustom);
193 myNbSegPerEdge->setEnabled(isCustom);
194 myNbSegPerRadius->setEnabled(isCustom);
197 QString NETGENPluginGUI_HypothesisCreator::storeParams() const
199 NetgenHypothesisData data;
200 readParamsFromWidgets( data );
201 storeParamsToHypo( data );
203 QString valStr = tr("NETGEN_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
204 if ( data.mySecondOrder )
205 valStr += tr("NETGEN_SECOND_ORDER") + "; ";
206 if ( data.myOptimize )
207 valStr += tr("NETGEN_OPTIMIZE") + "; ";
208 valStr += myFineness->currentText() + "(" + QString::number( data.myGrowthRate ) + ", " +
209 QString::number( data.myNbSegPerEdge ) + ", " +
210 QString::number( data.myNbSegPerRadius ) + ")";
212 if ( myIs2D && data.myAllowQuadrangles )
213 valStr += "; " + tr("NETGEN_ALLOW_QUADRANGLES");
218 bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData& h_data ) const
220 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
221 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
223 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
224 h_data.myName = isCreation() && data ? data->Label : "";
226 h_data.myMaxSize = h->GetMaxSize();
227 h_data.mySecondOrder = h->GetSecondOrder();
228 h_data.myOptimize = h->GetOptimize();
230 h_data.myFineness = (int) h->GetFineness();
231 h_data.myGrowthRate = h->GetGrowthRate();
232 h_data.myNbSegPerEdge = h->GetNbSegPerEdge();
233 h_data.myNbSegPerRadius = h->GetNbSegPerRadius();
237 NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
238 NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( initParamsHypothesis() );
240 if ( !h_2d->_is_nil() )
241 h_data.myAllowQuadrangles = h_2d->GetQuadAllowed();
247 bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesisData& h_data ) const
249 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
250 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( hypothesis() );
256 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
258 h->SetMaxSize( h_data.myMaxSize );
259 h->SetSecondOrder( h_data.mySecondOrder );
260 h->SetOptimize( h_data.myOptimize );
261 int fineness = h_data.myFineness;
262 h->SetFineness( fineness );
264 if( fineness==UserDefined )
266 h->SetGrowthRate( h_data.myGrowthRate );
267 h->SetNbSegPerEdge( h_data.myNbSegPerEdge );
268 h->SetNbSegPerRadius( h_data.myNbSegPerRadius );
273 NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
274 NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h );
276 if ( !h_2d->_is_nil() )
277 h_2d->SetQuadAllowed( h_data.myAllowQuadrangles );
280 catch(const SALOME::SALOME_Exception& ex)
282 SalomeApp_Tools::QtCatchCorbaException(ex);
288 bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisData& h_data ) const
290 h_data.myName = myName ? myName->text() : "";
291 h_data.myMaxSize = myMaxSize->value();
292 h_data.mySecondOrder = mySecondOrder->isChecked();
293 h_data.myOptimize = myOptimize->isChecked();
294 h_data.myFineness = myFineness->currentIndex();
295 h_data.myGrowthRate = myGrowthRate->value();
296 h_data.myNbSegPerEdge = myNbSegPerEdge->value();
297 h_data.myNbSegPerRadius = myNbSegPerRadius->value();
300 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
305 void NETGENPluginGUI_HypothesisCreator::onFinenessChanged()
307 bool isCustom = (myFineness->currentIndex() == UserDefined);
309 myGrowthRate->setEnabled(isCustom);
310 myNbSegPerEdge->setEnabled(isCustom);
311 myNbSegPerRadius->setEnabled(isCustom);
315 double aGrowthRate, aNbSegPerEdge, aNbSegPerRadius;
317 switch ( myFineness->currentIndex() )
327 aNbSegPerRadius = 1.5;
347 myGrowthRate->setValue( aGrowthRate );
348 myNbSegPerEdge->setValue( aNbSegPerEdge );
349 myNbSegPerRadius->setValue( aNbSegPerRadius );
353 QString NETGENPluginGUI_HypothesisCreator::caption() const
355 return tr( QString( "NETGEN_%1_TITLE" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
358 QPixmap NETGENPluginGUI_HypothesisCreator::icon() const
360 QString hypIconName = tr( QString("ICON_DLG_NETGEN_PARAMETERS%1").arg(myIs2D?QString("_2D"):QString("")).toLatin1().data() );
361 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
364 QString NETGENPluginGUI_HypothesisCreator::type() const
366 return tr( QString( "NETGEN_%1_HYPOTHESIS" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );