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 // File : NETGENPluginGUI_SimpleCreator.cxx
23 // Author : Open CASCADE S.A.S.
26 #include "NETGENPluginGUI_SimpleCreator.h"
28 #include <SMESHGUI_Utils.h>
29 #include <SMESHGUI_HypothesesUtils.h>
30 #include <SMESHGUI_SpinBox.h>
34 #include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm)
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
39 // SALOME GUI includes
40 #include <SalomeApp_Tools.h>
41 #include <SalomeApp_IntSpinBox.h>
48 //#include <QButtonGroup>
49 #include <QRadioButton>
50 #include <QGridLayout>
51 #include <QVBoxLayout>
52 #include <QApplication>
58 // copied from StdMeshersGUI_StdHypothesisCreator.cxx
59 const double VALUE_MAX = 1.0e+15, // COORD_MAX
60 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
61 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
62 VALUE_SMALL = 1.0e-15,
63 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
64 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
66 NETGENPluginGUI_SimpleCreator::NETGENPluginGUI_SimpleCreator(const QString& theHypType)
67 : SMESHGUI_GenericHypothesisCreator( theHypType ),
73 myLenFromEdgesCheckBox(0),
75 myLenFromFacesCheckBox(0),
80 NETGENPluginGUI_SimpleCreator::~NETGENPluginGUI_SimpleCreator()
84 bool NETGENPluginGUI_SimpleCreator::checkParams(QString& msg) const
87 result = myNbSeg->isValid(msg,true) && result;
88 result = myLength->isValid(msg,true) && result;
89 result = myArea->isValid(msg,true) && result;
91 result = myVolume->isValid(msg,true) && result;
96 QFrame* NETGENPluginGUI_SimpleCreator::buildFrame()
98 QFrame* fr = new QFrame();
100 QVBoxLayout* lay = new QVBoxLayout( fr );
102 lay->setSpacing( 0 );
104 QGroupBox* argGroup = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
105 lay->addWidget( argGroup );
107 QGridLayout* argLay = new QGridLayout( argGroup );
108 argLay->setSpacing( SPACING );
109 argLay->setMargin( MARGIN );
110 argLay->setColumnStretch( 0, 0 );
111 argLay->setColumnStretch( 1, 1 );
116 myName = new QLineEdit( argGroup );
117 argLay->addWidget( new QLabel( tr( "SMESH_NAME" ), argGroup ), argRow, 0 );
118 argLay->addWidget( myName, argRow, 1 );
128 dimGroup = new QGroupBox( tr( "NG_1D" ), argGroup );
129 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
132 dimLay = new QGridLayout( dimGroup );
133 dimLay->setSpacing( SPACING );
134 dimLay->setMargin( MARGIN );
135 dimLay->setColumnStretch( 0, 0 );
136 dimLay->setColumnStretch( 1, 1 );
139 // * number of segments
140 myNbSegRadioBut = new QRadioButton( tr( "SMESH_NB_SEGMENTS_HYPOTHESIS" ), dimGroup );
141 myNbSeg = new SalomeApp_IntSpinBox( dimGroup );
142 myNbSeg->setMinimum( 1 );
143 myNbSeg->setMaximum( 9999 );
144 myNbSeg->setValue( 1 );
145 dimLay->addWidget( myNbSegRadioBut, dimRow, 0 );
146 dimLay->addWidget( myNbSeg, dimRow, 1 );
150 myLengthRadioBut = new QRadioButton( tr( "SMESH_LOCAL_LENGTH_HYPOTHESIS" ), dimGroup );
151 myLength = new SMESHGUI_SpinBox( dimGroup );
152 myLength->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 0.1, 6 );
153 myLength->setValue( 1. );
154 dimLay->addWidget( myLengthRadioBut, dimRow, 0 );
155 dimLay->addWidget( myLength, dimRow, 1 );
160 dimGroup = new QGroupBox( tr( "NG_2D" ), argGroup );
161 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
164 dimLay = new QGridLayout( dimGroup );
165 dimLay->setSpacing( SPACING );
166 dimLay->setMargin( MARGIN );
167 dimLay->setColumnStretch( 0, 0 );
168 dimLay->setColumnStretch( 1, 1 );
171 // * Length from edges
172 myLenFromEdgesCheckBox = new QCheckBox( tr( "NG_LENGTH_FROM_EDGES" ), dimGroup );
173 dimLay->addWidget( myLenFromEdgesCheckBox, dimRow, 0, 1, 2 );
177 dimLay->addWidget( new QLabel( tr( "SMESH_MAX_ELEMENT_AREA_HYPOTHESIS" ), dimGroup), dimRow, 0);
178 myArea = new SMESHGUI_SpinBox( dimGroup );
179 myArea->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 0.1, 6 );
180 myArea->setValue( 1. );
181 dimLay->addWidget( myArea, dimRow, 1 );
185 if ( hypType()=="NETGEN_SimpleParameters_3D" )
187 dimGroup = new QGroupBox( tr( "NG_3D" ), argGroup );
188 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
191 dimLay = new QGridLayout( dimGroup );
192 dimLay->setSpacing( SPACING );
193 dimLay->setMargin( MARGIN );
194 dimLay->setColumnStretch( 0, 0 );
195 dimLay->setColumnStretch( 1, 1 );
198 // * Length from faces
199 myLenFromFacesCheckBox = new QCheckBox( tr( "NG_LENGTH_FROM_FACES" ), dimGroup );
200 dimLay->addWidget( myLenFromFacesCheckBox, dimRow, 0, 1, 2 );
204 dimLay->addWidget(new QLabel( tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"), dimGroup), dimRow, 0);
205 myVolume = new SMESHGUI_SpinBox( dimGroup );
206 myVolume->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 0.1, 6 );
207 myVolume->setValue( 1. );
208 dimLay->addWidget( myVolume, dimRow, 1 );
212 connect( myNbSegRadioBut, SIGNAL( clicked(bool) ), this, SLOT( onValueChanged() ));
213 connect( myLengthRadioBut, SIGNAL( clicked(bool) ), this, SLOT( onValueChanged() ));
214 connect( myLenFromEdgesCheckBox, SIGNAL( stateChanged(int)), this, SLOT( onValueChanged() ));
215 if ( myLenFromFacesCheckBox )
216 connect( myLenFromFacesCheckBox, SIGNAL( stateChanged(int)), this, SLOT( onValueChanged() ));
221 void NETGENPluginGUI_SimpleCreator::retrieveParams() const
224 myName->setText( hypName() );
226 NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D_var h =
227 NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D::_narrow( initParamsHypothesis() );
229 SMESH::ListOfParameters_var aParameters = h->GetLastParameters();
232 int nbSeg = (int) h->GetNumberOfSegments();
233 myNbSegRadioBut->setChecked( nbSeg );
234 myLengthRadioBut->setChecked( !nbSeg );
237 myLength->setEnabled( false );
238 myNbSeg->setEnabled( true );
239 aPrm = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
241 myNbSeg->setValue( nbSeg );
243 myNbSeg->setText(aPrm);
246 myNbSeg->setEnabled( false );
247 myLength->setEnabled( true );
248 aPrm = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
250 myLength->setValue( h->GetLocalLength() );
252 myLength->setText(aPrm);
256 if ( double area = h->GetMaxElementArea() ) {
257 myLenFromEdgesCheckBox->setChecked( false );
258 myArea->setEnabled( true );
259 aPrm = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
261 myArea->setValue( area );
263 myArea->setText( aPrm );
266 myLenFromEdgesCheckBox->setChecked( true );
267 myArea->setEnabled( false );
272 NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D_var h =
273 NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D::_narrow( initParamsHypothesis() );
274 if ( double volume = (double) h->GetMaxElementVolume() ) {
275 myLenFromFacesCheckBox->setChecked( false );
276 myVolume->setEnabled( true );
277 aPrm = (aParameters->length() > 2) ? QString(aParameters[2].in()) : QString("");
279 myVolume->setValue( volume );
281 myVolume->setText( aPrm );
284 myLenFromFacesCheckBox->setChecked( true );
285 myVolume->setEnabled( false );
290 QString NETGENPluginGUI_SimpleCreator::storeParams() const
295 NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D_var h =
296 NETGENPlugin::NETGENPlugin_SimpleHypothesis_2D::_narrow( initParamsHypothesis() );
299 SMESH::SetName( SMESH::FindSObject( h ), myName->text().toLatin1().data() );
304 QStringList aVariablesList;
305 if ( myNbSeg->isEnabled() ) {
306 h->SetNumberOfSegments( myNbSeg->value() );
307 valStr += "nbSeg=" + myNbSeg->text();
308 aVariablesList.append(myNbSeg->text());
311 h->SetLocalLength( myLength->value() );
312 valStr += "len=" + myLength->text();
313 aVariablesList.append(myLength->text());
316 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
319 if ( myArea->isEnabled() ) {
320 h->SetMaxElementArea( myArea->value() );
321 valStr += "; area=" + myArea->text();
322 aVariablesList.append(myArea->text());
325 h->LengthFromEdges();
326 valStr += "; lenFromEdges";
327 aVariablesList.append(QString());
330 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
334 NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D_var h =
335 NETGENPlugin::NETGENPlugin_SimpleHypothesis_3D::_narrow( initParamsHypothesis() );
336 if ( myVolume->isEnabled() ) {
337 h->SetMaxElementVolume( myVolume->value() );
338 valStr += "; vol=" + myVolume->text();
339 aVariablesList.append( myVolume->text());
342 h->LengthFromFaces();
343 valStr += "; lenFromFaces";
344 aVariablesList.append(QString());
346 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
349 catch(const SALOME::SALOME_Exception& ex)
351 SalomeApp_Tools::QtCatchCorbaException(ex);
357 void NETGENPluginGUI_SimpleCreator::onValueChanged()
359 QObject* changed = sender();
361 if ( myNbSegRadioBut == changed )
363 myLengthRadioBut->setChecked( !myNbSegRadioBut->isChecked() );
365 else if ( myLengthRadioBut == changed )
367 myNbSegRadioBut->setChecked( !myLengthRadioBut->isChecked() );
369 else if ( myLenFromEdgesCheckBox == changed )
371 myArea->setEnabled( !myLenFromEdgesCheckBox->isChecked() );
373 else if ( myLenFromFacesCheckBox == changed )
375 myVolume->setEnabled( !myLenFromFacesCheckBox->isChecked() );
377 myLength->setEnabled( myLengthRadioBut->isChecked() );
378 myNbSeg->setEnabled( myNbSegRadioBut->isChecked() );
381 QString NETGENPluginGUI_SimpleCreator::caption() const
383 return tr( (hypType() + "_TITLE").toLatin1().data() );
386 QPixmap NETGENPluginGUI_SimpleCreator::icon() const
388 QString hypIconName = tr( ("ICON_DLG_" + hypType()).toLatin1().data() );
389 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
392 QString NETGENPluginGUI_SimpleCreator::type() const
394 return tr( (hypType() + "_HYPOTHESIS").toLatin1().data() );
397 QString NETGENPluginGUI_SimpleCreator::helpPage() const
399 return "netgen_2d_3d_hypo_page.html";