1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : NETGENPluginGUI_SimpleCreator.cxx
21 // Author : Open CASCADE S.A.S.
24 #include "NETGENPluginGUI_SimpleCreator.h"
26 #include <SMESHGUI_Utils.h>
27 #include <SMESHGUI_HypothesesUtils.h>
28 #include <SMESHGUI_SpinBox.h>
32 #include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm)
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
37 // SALOME GUI includes
38 #include <SalomeApp_Tools.h>
39 #include <SalomeApp_IntSpinBox.h>
46 //#include <QButtonGroup>
47 #include <QRadioButton>
48 #include <QGridLayout>
49 #include <QVBoxLayout>
50 #include <QApplication>
56 using namespace NETGENPlugin;
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, "length_precision" );
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, "area_precision" );
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, "volume_precision" );
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 // Set default values
228 NETGENPlugin_SimpleHypothesis_2D_var h =
229 NETGENPlugin_SimpleHypothesis_2D::_narrow( initParamsHypothesis( hasInitParamsHypothesis() ));
231 int dfltNbSeg = (int) h->GetNumberOfSegments();
232 myNbSeg->setValue( dfltNbSeg );
233 if ( double len = h->GetLocalLength() ) {
234 myLength->setValue( len );
235 myArea->setValue( len * len );
237 myVolume->setValue( len * len * len );
240 h = NETGENPlugin_SimpleHypothesis_2D::_narrow( hypothesis() );
242 // set values of hypothesis
244 SMESH::ListOfParameters_var aParameters = h->GetLastParameters();
247 int nbSeg = isCreation() ? dfltNbSeg : (int) h->GetNumberOfSegments();
248 myNbSegRadioBut->setChecked( nbSeg );
249 myLengthRadioBut->setChecked( !nbSeg );
252 myLength->setEnabled( false );
253 myNbSeg->setEnabled( true );
254 aPrm = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
256 myNbSeg->setValue( nbSeg );
258 myNbSeg->setText(aPrm);
261 myNbSeg->setEnabled( false );
262 myLength->setEnabled( true );
263 aPrm = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
265 myLength->setValue( h->GetLocalLength() );
267 myLength->setText(aPrm);
271 if ( double area = h->GetMaxElementArea() ) {
272 myLenFromEdgesCheckBox->setChecked( false );
273 myArea->setEnabled( true );
274 aPrm = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
276 myArea->setValue( area );
278 myArea->setText( aPrm );
281 myLenFromEdgesCheckBox->setChecked( true );
282 myArea->setEnabled( false );
287 NETGENPlugin_SimpleHypothesis_3D_var h = NETGENPlugin_SimpleHypothesis_3D::_narrow( hypothesis() );
288 if ( double volume = (double) h->GetMaxElementVolume() ) {
289 myLenFromFacesCheckBox->setChecked( false );
290 myVolume->setEnabled( true );
291 aPrm = (aParameters->length() > 2) ? QString(aParameters[2].in()) : QString("");
293 myVolume->setValue( volume );
295 myVolume->setText( aPrm );
298 myLenFromFacesCheckBox->setChecked( true );
299 myVolume->setEnabled( false );
304 QString NETGENPluginGUI_SimpleCreator::storeParams() const
309 NETGENPlugin_SimpleHypothesis_2D_var h =
310 NETGENPlugin_SimpleHypothesis_2D::_narrow( hypothesis() );
313 SMESH::SetName( SMESH::FindSObject( h ), myName->text().toLatin1().data() );
318 QStringList aVariablesList;
319 if ( myNbSeg->isEnabled() ) {
320 h->SetNumberOfSegments( myNbSeg->value() );
321 valStr += "nbSeg=" + myNbSeg->text();
322 aVariablesList.append(myNbSeg->text());
325 h->SetLocalLength( myLength->value() );
326 valStr += "len=" + myLength->text();
327 aVariablesList.append(myLength->text());
330 h->SetParameters(aVariablesList.join(":").toLatin1().constData());
333 if ( myArea->isEnabled() ) {
334 h->SetMaxElementArea( myArea->value() );
335 valStr += "; area=" + myArea->text();
336 aVariablesList.append(myArea->text());
339 h->LengthFromEdges();
340 valStr += "; lenFromEdges";
341 aVariablesList.append(QString());
344 h->SetParameters(aVariablesList.join(":").toLatin1().constData());
348 NETGENPlugin_SimpleHypothesis_3D_var h =
349 NETGENPlugin_SimpleHypothesis_3D::_narrow( hypothesis() );
350 if ( myVolume->isEnabled() ) {
351 h->SetMaxElementVolume( myVolume->value() );
352 valStr += "; vol=" + myVolume->text();
353 aVariablesList.append( myVolume->text());
356 h->LengthFromFaces();
357 valStr += "; lenFromFaces";
358 aVariablesList.append(QString());
360 h->SetParameters(aVariablesList.join(":").toLatin1().constData());
363 catch(const SALOME::SALOME_Exception& ex)
365 SalomeApp_Tools::QtCatchCorbaException(ex);
371 void NETGENPluginGUI_SimpleCreator::onValueChanged()
373 QObject* changed = sender();
375 if ( myNbSegRadioBut == changed )
377 myLengthRadioBut->setChecked( !myNbSegRadioBut->isChecked() );
379 else if ( myLengthRadioBut == changed )
381 myNbSegRadioBut->setChecked( !myLengthRadioBut->isChecked() );
383 else if ( myLenFromEdgesCheckBox == changed )
385 myArea->setEnabled( !myLenFromEdgesCheckBox->isChecked() );
387 else if ( myLenFromFacesCheckBox == changed )
389 myVolume->setEnabled( !myLenFromFacesCheckBox->isChecked() );
391 myLength->setEnabled( myLengthRadioBut->isChecked() );
392 myNbSeg->setEnabled( myNbSegRadioBut->isChecked() );
395 QString NETGENPluginGUI_SimpleCreator::caption() const
397 return tr( (hypType() + "_TITLE").toLatin1().data() );
400 QPixmap NETGENPluginGUI_SimpleCreator::icon() const
402 QString hypIconName = tr( ("ICON_DLG_" + hypType()).toLatin1().data() );
403 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
406 QString NETGENPluginGUI_SimpleCreator::type() const
408 return tr( (hypType() + "_HYPOTHESIS").toLatin1().data() );
411 QString NETGENPluginGUI_SimpleCreator::helpPage() const
413 return "netgen_2d_3d_hypo_page.html";