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 using namespace NETGENPlugin;
60 // copied from StdMeshersGUI_StdHypothesisCreator.cxx
61 const double VALUE_MAX = 1.0e+15, // COORD_MAX
62 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
63 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
64 VALUE_SMALL = 1.0e-15,
65 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
66 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
68 NETGENPluginGUI_SimpleCreator::NETGENPluginGUI_SimpleCreator(const QString& theHypType)
69 : SMESHGUI_GenericHypothesisCreator( theHypType ),
75 myLenFromEdgesCheckBox(0),
77 myLenFromFacesCheckBox(0),
82 NETGENPluginGUI_SimpleCreator::~NETGENPluginGUI_SimpleCreator()
86 bool NETGENPluginGUI_SimpleCreator::checkParams(QString& msg) const
89 result = myNbSeg->isValid(msg,true) && result;
90 result = myLength->isValid(msg,true) && result;
91 result = myArea->isValid(msg,true) && result;
93 result = myVolume->isValid(msg,true) && result;
98 QFrame* NETGENPluginGUI_SimpleCreator::buildFrame()
100 QFrame* fr = new QFrame();
102 QVBoxLayout* lay = new QVBoxLayout( fr );
104 lay->setSpacing( 0 );
106 QGroupBox* argGroup = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
107 lay->addWidget( argGroup );
109 QGridLayout* argLay = new QGridLayout( argGroup );
110 argLay->setSpacing( SPACING );
111 argLay->setMargin( MARGIN );
112 argLay->setColumnStretch( 0, 0 );
113 argLay->setColumnStretch( 1, 1 );
118 myName = new QLineEdit( argGroup );
119 argLay->addWidget( new QLabel( tr( "SMESH_NAME" ), argGroup ), argRow, 0 );
120 argLay->addWidget( myName, argRow, 1 );
130 dimGroup = new QGroupBox( tr( "NG_1D" ), argGroup );
131 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
134 dimLay = new QGridLayout( dimGroup );
135 dimLay->setSpacing( SPACING );
136 dimLay->setMargin( MARGIN );
137 dimLay->setColumnStretch( 0, 0 );
138 dimLay->setColumnStretch( 1, 1 );
141 // * number of segments
142 myNbSegRadioBut = new QRadioButton( tr( "SMESH_NB_SEGMENTS_HYPOTHESIS" ), dimGroup );
143 myNbSeg = new SalomeApp_IntSpinBox( dimGroup );
144 myNbSeg->setMinimum( 1 );
145 myNbSeg->setMaximum( 9999 );
146 myNbSeg->setValue( 1 );
147 dimLay->addWidget( myNbSegRadioBut, dimRow, 0 );
148 dimLay->addWidget( myNbSeg, dimRow, 1 );
152 myLengthRadioBut = new QRadioButton( tr( "SMESH_LOCAL_LENGTH_HYPOTHESIS" ), dimGroup );
153 myLength = new SMESHGUI_SpinBox( dimGroup );
154 myLength->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 0.1, 6 );
155 myLength->setValue( 1. );
156 dimLay->addWidget( myLengthRadioBut, dimRow, 0 );
157 dimLay->addWidget( myLength, dimRow, 1 );
162 dimGroup = new QGroupBox( tr( "NG_2D" ), argGroup );
163 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
166 dimLay = new QGridLayout( dimGroup );
167 dimLay->setSpacing( SPACING );
168 dimLay->setMargin( MARGIN );
169 dimLay->setColumnStretch( 0, 0 );
170 dimLay->setColumnStretch( 1, 1 );
173 // * Length from edges
174 myLenFromEdgesCheckBox = new QCheckBox( tr( "NG_LENGTH_FROM_EDGES" ), dimGroup );
175 dimLay->addWidget( myLenFromEdgesCheckBox, dimRow, 0, 1, 2 );
179 dimLay->addWidget( new QLabel( tr( "SMESH_MAX_ELEMENT_AREA_HYPOTHESIS" ), dimGroup), dimRow, 0);
180 myArea = new SMESHGUI_SpinBox( dimGroup );
181 myArea->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 0.1, 6 );
182 myArea->setValue( 1. );
183 dimLay->addWidget( myArea, dimRow, 1 );
187 if ( hypType()=="NETGEN_SimpleParameters_3D" )
189 dimGroup = new QGroupBox( tr( "NG_3D" ), argGroup );
190 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
193 dimLay = new QGridLayout( dimGroup );
194 dimLay->setSpacing( SPACING );
195 dimLay->setMargin( MARGIN );
196 dimLay->setColumnStretch( 0, 0 );
197 dimLay->setColumnStretch( 1, 1 );
200 // * Length from faces
201 myLenFromFacesCheckBox = new QCheckBox( tr( "NG_LENGTH_FROM_FACES" ), dimGroup );
202 dimLay->addWidget( myLenFromFacesCheckBox, dimRow, 0, 1, 2 );
206 dimLay->addWidget(new QLabel( tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"), dimGroup), dimRow, 0);
207 myVolume = new SMESHGUI_SpinBox( dimGroup );
208 myVolume->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 0.1, 6 );
209 myVolume->setValue( 1. );
210 dimLay->addWidget( myVolume, dimRow, 1 );
214 connect( myNbSegRadioBut, SIGNAL( clicked(bool) ), this, SLOT( onValueChanged() ));
215 connect( myLengthRadioBut, SIGNAL( clicked(bool) ), this, SLOT( onValueChanged() ));
216 connect( myLenFromEdgesCheckBox, SIGNAL( stateChanged(int)), this, SLOT( onValueChanged() ));
217 if ( myLenFromFacesCheckBox )
218 connect( myLenFromFacesCheckBox, SIGNAL( stateChanged(int)), this, SLOT( onValueChanged() ));
223 void NETGENPluginGUI_SimpleCreator::retrieveParams() const
226 myName->setText( hypName() );
228 // set default real values
230 NETGENPlugin_SimpleHypothesis_2D_var h =
231 NETGENPlugin_SimpleHypothesis_2D::_narrow( initParamsHypothesis( hasInitParamsHypothesis() ));
233 if ( double len = h->GetLocalLength() )
234 myLength->setValue( len );
235 if ( double area = h->GetMaxElementArea() )
236 myArea->setValue( area );
238 NETGENPlugin_SimpleHypothesis_3D_var h3d =
239 NETGENPlugin_SimpleHypothesis_3D::_narrow( initParamsHypothesis( hasInitParamsHypothesis()) );
240 if ( double volume = (double) h3d->GetMaxElementVolume() )
241 myVolume->setValue( volume );
244 h = NETGENPlugin_SimpleHypothesis_2D::_narrow( hypothesis() );
246 // set values of hypothesis
248 SMESH::ListOfParameters_var aParameters = h->GetLastParameters();
251 int nbSeg = (int) h->GetNumberOfSegments();
252 myNbSegRadioBut->setChecked( nbSeg );
253 myLengthRadioBut->setChecked( !nbSeg );
256 myLength->setEnabled( false );
257 myNbSeg->setEnabled( true );
258 aPrm = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
260 myNbSeg->setValue( nbSeg );
262 myNbSeg->setText(aPrm);
265 myNbSeg->setEnabled( false );
266 myLength->setEnabled( true );
267 aPrm = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
269 myLength->setValue( h->GetLocalLength() );
271 myLength->setText(aPrm);
275 if ( double area = h->GetMaxElementArea() ) {
276 myLenFromEdgesCheckBox->setChecked( false );
277 myArea->setEnabled( true );
278 aPrm = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
280 myArea->setValue( area );
282 myArea->setText( aPrm );
285 myLenFromEdgesCheckBox->setChecked( true );
286 myArea->setEnabled( false );
291 NETGENPlugin_SimpleHypothesis_3D_var h = NETGENPlugin_SimpleHypothesis_3D::_narrow( hypothesis() );
292 if ( double volume = (double) h->GetMaxElementVolume() ) {
293 myLenFromFacesCheckBox->setChecked( false );
294 myVolume->setEnabled( true );
295 aPrm = (aParameters->length() > 2) ? QString(aParameters[2].in()) : QString("");
297 myVolume->setValue( volume );
299 myVolume->setText( aPrm );
302 myLenFromFacesCheckBox->setChecked( true );
303 myVolume->setEnabled( false );
308 QString NETGENPluginGUI_SimpleCreator::storeParams() const
313 NETGENPlugin_SimpleHypothesis_2D_var h =
314 NETGENPlugin_SimpleHypothesis_2D::_narrow( hypothesis() );
317 SMESH::SetName( SMESH::FindSObject( h ), myName->text().toLatin1().data() );
322 QStringList aVariablesList;
323 if ( myNbSeg->isEnabled() ) {
324 h->SetNumberOfSegments( myNbSeg->value() );
325 valStr += "nbSeg=" + myNbSeg->text();
326 aVariablesList.append(myNbSeg->text());
329 h->SetLocalLength( myLength->value() );
330 valStr += "len=" + myLength->text();
331 aVariablesList.append(myLength->text());
334 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
337 if ( myArea->isEnabled() ) {
338 h->SetMaxElementArea( myArea->value() );
339 valStr += "; area=" + myArea->text();
340 aVariablesList.append(myArea->text());
343 h->LengthFromEdges();
344 valStr += "; lenFromEdges";
345 aVariablesList.append(QString());
348 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
352 NETGENPlugin_SimpleHypothesis_3D_var h =
353 NETGENPlugin_SimpleHypothesis_3D::_narrow( hypothesis() );
354 if ( myVolume->isEnabled() ) {
355 h->SetMaxElementVolume( myVolume->value() );
356 valStr += "; vol=" + myVolume->text();
357 aVariablesList.append( myVolume->text());
360 h->LengthFromFaces();
361 valStr += "; lenFromFaces";
362 aVariablesList.append(QString());
364 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
367 catch(const SALOME::SALOME_Exception& ex)
369 SalomeApp_Tools::QtCatchCorbaException(ex);
375 void NETGENPluginGUI_SimpleCreator::onValueChanged()
377 QObject* changed = sender();
379 if ( myNbSegRadioBut == changed )
381 myLengthRadioBut->setChecked( !myNbSegRadioBut->isChecked() );
383 else if ( myLengthRadioBut == changed )
385 myNbSegRadioBut->setChecked( !myLengthRadioBut->isChecked() );
387 else if ( myLenFromEdgesCheckBox == changed )
389 myArea->setEnabled( !myLenFromEdgesCheckBox->isChecked() );
391 else if ( myLenFromFacesCheckBox == changed )
393 myVolume->setEnabled( !myLenFromFacesCheckBox->isChecked() );
395 myLength->setEnabled( myLengthRadioBut->isChecked() );
396 myNbSeg->setEnabled( myNbSegRadioBut->isChecked() );
399 QString NETGENPluginGUI_SimpleCreator::caption() const
401 return tr( (hypType() + "_TITLE").toLatin1().data() );
404 QPixmap NETGENPluginGUI_SimpleCreator::icon() const
406 QString hypIconName = tr( ("ICON_DLG_" + hypType()).toLatin1().data() );
407 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
410 QString NETGENPluginGUI_SimpleCreator::type() const
412 return tr( (hypType() + "_HYPOTHESIS").toLatin1().data() );
415 QString NETGENPluginGUI_SimpleCreator::helpPage() const
417 return "netgen_2d_3d_hypo_page.html";