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>
37 #include <SalomeApp_Tools.h>
39 #include <QtxDblSpinBox.h>
40 #include <QtxComboBox.h>
43 #include <qgroupbox.h>
46 #include <qlineedit.h>
47 #include <qcheckbox.h>
60 NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType )
61 : SMESHGUI_GenericHypothesisCreator( theHypType ),
66 NETGENPluginGUI_HypothesisCreator::~NETGENPluginGUI_HypothesisCreator()
70 bool NETGENPluginGUI_HypothesisCreator::checkParams() const
72 NetgenHypothesisData data_old, data_new;
73 readParamsFromHypo( data_old );
74 readParamsFromWidgets( data_new );
75 bool res = storeParamsToHypo( data_new );
76 storeParamsToHypo( data_old );
80 QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame()
82 QFrame* fr = new QFrame( 0, "myframe" );
83 QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 );
85 QGroupBox* GroupC1 = new QGroupBox( 2, Qt::Horizontal, fr, "GroupC1" );
86 lay->addWidget( GroupC1 );
88 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
89 GroupC1->layout()->setSpacing( 6 );
90 GroupC1->layout()->setMargin( 11 );
95 new QLabel( tr( "SMESH_NAME" ), GroupC1 );
96 myName = new QLineEdit( GroupC1 );
99 new QLabel( tr( "NETGEN_MAX_SIZE" ), GroupC1 );
100 myMaxSize = new QtxDblSpinBox( GroupC1 );
101 myMaxSize->setPrecision( 7 );
102 myMaxSize->setMinValue( 1e-07 );
103 myMaxSize->setMaxValue( 1e+06 );
104 myMaxSize->setLineStep( 10 );
106 mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 );
107 GroupC1->addSpace(0);
109 new QLabel( tr( "NETGEN_FINENESS" ), GroupC1 );
110 myFineness = new QtxComboBox( GroupC1 );
112 types.append( QObject::tr( "NETGEN_VERYCOARSE" ) );
113 types.append( QObject::tr( "NETGEN_COARSE" ) );
114 types.append( QObject::tr( "NETGEN_MODERATE" ) );
115 types.append( QObject::tr( "NETGEN_FINE" ) );
116 types.append( QObject::tr( "NETGEN_VERYFINE" ) );
117 types.append( QObject::tr( "NETGEN_CUSTOM" ) );
118 myFineness->insertStringList( types );
120 new QLabel( tr( "NETGEN_GROWTH_RATE" ), GroupC1 );
121 myGrowthRate = new QtxDblSpinBox( GroupC1 );
122 myGrowthRate->setMinValue( 0.1 );
123 myGrowthRate->setMaxValue( 10 );
124 myGrowthRate->setLineStep( 0.1 );
126 const double VALUE_MAX = 1.0e+6;
128 new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 );
129 myNbSegPerEdge = new QtxDblSpinBox( GroupC1 );
130 myNbSegPerEdge->setMinValue( 0.2 );
131 myNbSegPerEdge->setMaxValue( VALUE_MAX ); // (PAL14890) max value in native netgen gui is 5
133 new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 );
134 myNbSegPerRadius = new QtxDblSpinBox( GroupC1 );
135 myNbSegPerRadius->setMinValue( 0.2 );
136 myNbSegPerRadius->setMaxValue( VALUE_MAX ); // (PAL14890) max value in native netgen gui is 5
138 if ( hypType()=="NETGEN_Parameters_2D" )
140 myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 );
141 GroupC1->addSpace(0);
145 myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 );
146 GroupC1->addSpace(0);
148 connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) );
153 void NETGENPluginGUI_HypothesisCreator::retrieveParams() const
155 NetgenHypothesisData data;
156 readParamsFromHypo( data );
159 myName->setText( data.myName );
160 myMaxSize->setValue( data.myMaxSize );
161 mySecondOrder->setChecked( data.mySecondOrder );
162 myOptimize->setChecked( data.myOptimize );
163 myFineness->setCurrentItem( data.myFineness );
164 myGrowthRate->setValue( data.myGrowthRate );
165 myNbSegPerEdge->setValue( data.myNbSegPerEdge );
166 myNbSegPerRadius->setValue( data.myNbSegPerRadius );
168 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
171 bool isCustom = (myFineness->currentItem() == UserDefined);
172 myGrowthRate->setEnabled(isCustom);
173 myNbSegPerEdge->setEnabled(isCustom);
174 myNbSegPerRadius->setEnabled(isCustom);
177 QString NETGENPluginGUI_HypothesisCreator::storeParams() const
179 NetgenHypothesisData data;
180 readParamsFromWidgets( data );
181 storeParamsToHypo( data );
183 QString valStr = tr("NETGEN_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
184 if ( data.mySecondOrder )
185 valStr += tr("NETGEN_SECOND_ORDER") + "; ";
186 if ( data.myOptimize )
187 valStr += tr("NETGEN_OPTIMIZE") + "; ";
188 valStr += myFineness->currentText() + "(" + QString::number( data.myGrowthRate ) + ", " +
189 QString::number( data.myNbSegPerEdge ) + ", " +
190 QString::number( data.myNbSegPerRadius ) + ")";
192 if ( myIs2D && data.myAllowQuadrangles )
193 valStr += "; " + tr("NETGEN_ALLOW_QUADRANGLES");
198 bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData& h_data ) const
200 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
201 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
203 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
204 h_data.myName = isCreation() && data ? data->Label : "";
206 h_data.myMaxSize = h->GetMaxSize();
207 h_data.mySecondOrder = h->GetSecondOrder();
208 h_data.myOptimize = h->GetOptimize();
210 h_data.myFineness = (int) h->GetFineness();
211 h_data.myGrowthRate = h->GetGrowthRate();
212 h_data.myNbSegPerEdge = h->GetNbSegPerEdge();
213 h_data.myNbSegPerRadius = h->GetNbSegPerRadius();
217 NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
218 NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( initParamsHypothesis() );
220 if ( !h_2d->_is_nil() )
221 h_data.myAllowQuadrangles = h_2d->GetQuadAllowed();
227 bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesisData& h_data ) const
229 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
230 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( hypothesis() );
236 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.latin1() );
238 h->SetMaxSize( h_data.myMaxSize );
239 h->SetSecondOrder( h_data.mySecondOrder );
240 h->SetOptimize( h_data.myOptimize );
241 int fineness = h_data.myFineness;
242 h->SetFineness( fineness );
244 if( fineness==UserDefined )
246 h->SetGrowthRate( h_data.myGrowthRate );
247 h->SetNbSegPerEdge( h_data.myNbSegPerEdge );
248 h->SetNbSegPerRadius( h_data.myNbSegPerRadius );
253 NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
254 NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h );
256 if ( !h_2d->_is_nil() )
257 h_2d->SetQuadAllowed( h_data.myAllowQuadrangles );
260 catch(const SALOME::SALOME_Exception& ex)
262 SalomeApp_Tools::QtCatchCorbaException(ex);
268 bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisData& h_data ) const
270 h_data.myName = myName ? myName->text() : "";
271 h_data.myMaxSize = myMaxSize->value();
272 h_data.mySecondOrder = mySecondOrder->isChecked();
273 h_data.myOptimize = myOptimize->isChecked();
274 h_data.myFineness = myFineness->currentItem();
275 h_data.myGrowthRate = myGrowthRate->value();
276 h_data.myNbSegPerEdge = myNbSegPerEdge->value();
277 h_data.myNbSegPerRadius = myNbSegPerRadius->value();
280 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
285 void NETGENPluginGUI_HypothesisCreator::onFinenessChanged()
287 bool isCustom = (myFineness->currentItem() == UserDefined);
289 myGrowthRate->setEnabled(isCustom);
290 myNbSegPerEdge->setEnabled(isCustom);
291 myNbSegPerRadius->setEnabled(isCustom);
295 double aGrowthRate, aNbSegPerEdge, aNbSegPerRadius;
297 switch ( myFineness->currentItem() )
307 aNbSegPerRadius = 1.5;
327 myGrowthRate->setValue( aGrowthRate );
328 myNbSegPerEdge->setValue( aNbSegPerEdge );
329 myNbSegPerRadius->setValue( aNbSegPerRadius );
333 QString NETGENPluginGUI_HypothesisCreator::caption() const
335 return tr( QString( "NETGEN_%1_TITLE" ).arg(myIs2D?QString("2D"):QString("3D")) );
338 QPixmap NETGENPluginGUI_HypothesisCreator::icon() const
340 QString hypIconName = tr( QString("ICON_DLG_NETGEN_PARAMETERS%1").arg(myIs2D?QString("_2D"):QString("")) );
341 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
344 QString NETGENPluginGUI_HypothesisCreator::type() const
346 return tr( QString( "NETGEN_%1_HYPOTHESIS" ).arg(myIs2D?QString("2D"):QString("3D")) );