1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // NETGENPlugin GUI: GUI for plugged-in mesher NETGENPlugin
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>
34 #include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm)
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
39 #include <SalomeApp_Tools.h>
41 #include <SalomeApp_DoubleSpinBox.h>
62 NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType )
63 : SMESHGUI_GenericHypothesisCreator( theHypType ),
68 NETGENPluginGUI_HypothesisCreator::~NETGENPluginGUI_HypothesisCreator()
72 bool NETGENPluginGUI_HypothesisCreator::checkParams(QString& msg) const
74 NetgenHypothesisData data_old, data_new;
75 readParamsFromHypo( data_old );
76 readParamsFromWidgets( data_new );
77 bool res = storeParamsToHypo( data_new );
78 storeParamsToHypo( data_old );
80 res = myMaxSize->isValid(msg,true) && res;
81 res = myGrowthRate->isValid(msg,true) && res; ;
82 res = myNbSegPerEdge->isValid(msg,true) && res;
83 res = myNbSegPerRadius->isValid(msg,true) && res;
87 QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame()
89 QFrame* fr = new QFrame( 0 );
90 fr->setObjectName( "myframe" );
91 QVBoxLayout* lay = new QVBoxLayout( fr );
95 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
96 lay->addWidget( GroupC1 );
98 QGridLayout* aGroupLayout = new QGridLayout( GroupC1 );
99 aGroupLayout->setSpacing( 6 );
100 aGroupLayout->setMargin( 11 );
106 aGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
107 myName = new QLineEdit( GroupC1 );
108 aGroupLayout->addWidget( myName, row, 1 );
112 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MAX_SIZE" ), GroupC1 ), row, 0 );
113 myMaxSize = new SalomeApp_DoubleSpinBox( GroupC1 );
114 myMaxSize->setDecimals( 7 );
115 myMaxSize->setMinimum( 1e-07 );
116 myMaxSize->setMaximum( 1e+06 );
117 myMaxSize->setSingleStep( 10 );
118 aGroupLayout->addWidget( myMaxSize, row, 1 );
121 mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 );
122 aGroupLayout->addWidget( mySecondOrder, row, 0 );
125 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_FINENESS" ), GroupC1 ), row, 0 );
126 myFineness = new QComboBox( GroupC1 );
128 types << tr( "NETGEN_VERYCOARSE" ) << tr( "NETGEN_COARSE" ) << tr( "NETGEN_MODERATE" ) <<
129 tr( "NETGEN_FINE" ) << tr( "NETGEN_VERYFINE" ) << tr( "NETGEN_CUSTOM" );
130 myFineness->addItems( types );
131 aGroupLayout->addWidget( myFineness, row, 1 );
134 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_GROWTH_RATE" ), GroupC1 ), row, 0 );
135 myGrowthRate = new SalomeApp_DoubleSpinBox( GroupC1 );
136 myGrowthRate->setMinimum( 0.1 );
137 myGrowthRate->setMaximum( 10 );
138 myGrowthRate->setSingleStep( 0.1 );
139 aGroupLayout->addWidget( myGrowthRate, row, 1 );
142 const double VALUE_MAX = 1.0e+6;
144 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 ), row, 0 );
145 myNbSegPerEdge = new SalomeApp_DoubleSpinBox( GroupC1 );
146 myNbSegPerEdge->setMinimum( 0.2 );
147 myNbSegPerEdge->setMaximum( VALUE_MAX ); // (PAL14890) max value in native netgen gui is 5
148 aGroupLayout->addWidget( myNbSegPerEdge, row, 1 );
151 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 ), row, 0 );
152 myNbSegPerRadius = new SalomeApp_DoubleSpinBox( GroupC1 );
153 myNbSegPerRadius->setMinimum( 0.2 );
154 myNbSegPerRadius->setMaximum( VALUE_MAX ); // (PAL14890) max value in native netgen gui is 5
155 aGroupLayout->addWidget( myNbSegPerRadius, row, 1 );
158 if ( hypType()=="NETGEN_Parameters_2D" )
160 myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 );
161 aGroupLayout->addWidget( myAllowQuadrangles, row, 0 );
166 myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 );
167 aGroupLayout->addWidget( myOptimize, row, 0 );
170 connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) );
175 void NETGENPluginGUI_HypothesisCreator::retrieveParams() const
177 NetgenHypothesisData data;
178 readParamsFromHypo( data );
181 myName->setText( data.myName );
182 if(data.myMaxSizeVar.isEmpty())
183 myMaxSize->setValue( data.myMaxSize );
185 myMaxSize->setText( data.myMaxSizeVar );
187 mySecondOrder->setChecked( data.mySecondOrder );
188 myOptimize->setChecked( data.myOptimize );
189 myFineness->setCurrentIndex( data.myFineness );
191 if(data.myGrowthRateVar.isEmpty())
192 myGrowthRate->setValue( data.myGrowthRate );
194 myGrowthRate->setText( data.myGrowthRateVar );
196 if(data.myNbSegPerEdgeVar.isEmpty())
197 myNbSegPerEdge->setValue( data.myNbSegPerEdge );
199 myNbSegPerEdge->setText( data.myNbSegPerEdgeVar );
201 if(data.myNbSegPerRadiusVar.isEmpty())
202 myNbSegPerRadius->setValue( data.myNbSegPerRadius );
204 myNbSegPerRadius->setText( data.myNbSegPerRadiusVar );
207 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
210 bool isCustom = (myFineness->currentIndex() == UserDefined);
211 myGrowthRate->setEnabled(isCustom);
212 myNbSegPerEdge->setEnabled(isCustom);
213 myNbSegPerRadius->setEnabled(isCustom);
216 QString NETGENPluginGUI_HypothesisCreator::storeParams() const
218 NetgenHypothesisData data;
219 readParamsFromWidgets( data );
220 storeParamsToHypo( data );
222 QString valStr = tr("NETGEN_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
223 if ( data.mySecondOrder )
224 valStr += tr("NETGEN_SECOND_ORDER") + "; ";
225 if ( data.myOptimize )
226 valStr += tr("NETGEN_OPTIMIZE") + "; ";
227 valStr += myFineness->currentText() + "(" + QString::number( data.myGrowthRate ) + ", " +
228 QString::number( data.myNbSegPerEdge ) + ", " +
229 QString::number( data.myNbSegPerRadius ) + ")";
231 if ( myIs2D && data.myAllowQuadrangles )
232 valStr += "; " + tr("NETGEN_ALLOW_QUADRANGLES");
237 bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData& h_data ) const
239 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
240 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
242 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
243 h_data.myName = isCreation() && data ? data->Label : "";
245 SMESH::ListOfParameters_var aParameters = h->GetLastParameters();
247 h_data.myMaxSize = h->GetMaxSize();
248 h_data.myMaxSizeVar = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
249 h_data.mySecondOrder = h->GetSecondOrder();
250 h_data.myOptimize = h->GetOptimize();
252 h_data.myFineness = (int) h->GetFineness();
253 h_data.myGrowthRate = h->GetGrowthRate();
254 h_data.myGrowthRateVar = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
255 h_data.myNbSegPerEdge = h->GetNbSegPerEdge();
256 h_data.myNbSegPerEdgeVar = (aParameters->length() > 2) ? QString(aParameters[2].in()) : QString("");
257 h_data.myNbSegPerRadius = h->GetNbSegPerRadius();
258 h_data.myNbSegPerRadiusVar = (aParameters->length() > 3) ? QString(aParameters[3].in()) : QString("");
262 NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
263 NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( initParamsHypothesis() );
265 if ( !h_2d->_is_nil() )
266 h_data.myAllowQuadrangles = h_2d->GetQuadAllowed();
272 bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesisData& h_data ) const
274 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
275 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( hypothesis() );
281 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
282 QStringList aVariablesList;
283 h->SetMaxSize( h_data.myMaxSize );
284 aVariablesList.append(h_data.myMaxSizeVar);
285 h->SetSecondOrder( h_data.mySecondOrder );
286 h->SetOptimize( h_data.myOptimize );
287 int fineness = h_data.myFineness;
288 h->SetFineness( fineness );
290 if( fineness==UserDefined )
292 h->SetGrowthRate( h_data.myGrowthRate );
293 h->SetNbSegPerEdge( h_data.myNbSegPerEdge );
294 h->SetNbSegPerRadius( h_data.myNbSegPerRadius );
296 aVariablesList.append(h_data.myGrowthRateVar);
297 aVariablesList.append(h_data.myNbSegPerEdgeVar);
298 aVariablesList.append(h_data.myNbSegPerRadiusVar);
303 NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
304 NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h );
306 if ( !h_2d->_is_nil() )
307 h_2d->SetQuadAllowed( h_data.myAllowQuadrangles );
310 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
311 if( fineness==UserDefined )
313 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
314 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
315 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
319 catch(const SALOME::SALOME_Exception& ex)
321 SalomeApp_Tools::QtCatchCorbaException(ex);
327 bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisData& h_data ) const
329 h_data.myName = myName ? myName->text() : "";
330 h_data.myMaxSize = myMaxSize->value();
331 h_data.myMaxSizeVar = myMaxSize->text();
332 h_data.mySecondOrder = mySecondOrder->isChecked();
333 h_data.myOptimize = myOptimize->isChecked();
334 h_data.myFineness = myFineness->currentIndex();
335 h_data.myGrowthRate = myGrowthRate->value();
336 h_data.myNbSegPerEdge = myNbSegPerEdge->value();
337 h_data.myNbSegPerRadius = myNbSegPerRadius->value();
339 h_data.myGrowthRateVar = myGrowthRate->text();
340 h_data.myNbSegPerEdgeVar = myNbSegPerEdge->text();
341 h_data.myNbSegPerRadiusVar = myNbSegPerRadius->text();
345 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
350 void NETGENPluginGUI_HypothesisCreator::onFinenessChanged()
352 bool isCustom = (myFineness->currentIndex() == UserDefined);
354 myGrowthRate->setEnabled(isCustom);
355 myNbSegPerEdge->setEnabled(isCustom);
356 myNbSegPerRadius->setEnabled(isCustom);
360 double aGrowthRate, aNbSegPerEdge, aNbSegPerRadius;
362 switch ( myFineness->currentIndex() )
372 aNbSegPerRadius = 1.5;
392 myGrowthRate->setValue( aGrowthRate );
393 myNbSegPerEdge->setValue( aNbSegPerEdge );
394 myNbSegPerRadius->setValue( aNbSegPerRadius );
398 QString NETGENPluginGUI_HypothesisCreator::caption() const
400 return tr( QString( "NETGEN_%1_TITLE" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
403 QPixmap NETGENPluginGUI_HypothesisCreator::icon() const
405 QString hypIconName = tr( QString("ICON_DLG_NETGEN_PARAMETERS%1").arg(myIs2D?QString("_2D"):QString("")).toLatin1().data() );
406 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
409 QString NETGENPluginGUI_HypothesisCreator::type() const
411 return tr( QString( "NETGEN_%1_HYPOTHESIS" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
414 QString NETGENPluginGUI_HypothesisCreator::helpPage() const
416 return "netgen_2d_3d_hypo_page.html";