1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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>
31 #include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm)
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
36 // SALOME GUI includes
37 #include <SalomeApp_Tools.h>
38 #include <SalomeApp_IntSpinBox.h>
45 //#include <QButtonGroup>
46 #include <QRadioButton>
47 #include <QGridLayout>
48 #include <QVBoxLayout>
49 #include <QApplication>
55 using namespace NETGENPlugin;
57 // copied from StdMeshersGUI_StdHypothesisCreator.cxx
58 const double VALUE_MAX = 1.0e+15, // COORD_MAX
59 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
60 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
61 VALUE_SMALL = 1.0e-15,
62 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
63 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
65 NETGENPluginGUI_SimpleCreator::NETGENPluginGUI_SimpleCreator(const QString& theHypType)
66 : SMESHGUI_GenericHypothesisCreator( theHypType ),
72 myLenFromEdgesCheckBox(0),
74 myAllowQuadCheckBox(0),
75 myLenFromFacesCheckBox(0),
80 NETGENPluginGUI_SimpleCreator::~NETGENPluginGUI_SimpleCreator()
84 bool NETGENPluginGUI_SimpleCreator::checkParams(QString& msg) const
87 if ( myNbSeg->isEnabled() )
88 result = myNbSeg->isValid(msg,true) && result;
89 if ( myLength->isEnabled() )
90 result = myLength->isValid(msg,true) && result;
91 if ( myArea->isEnabled() )
92 result = myArea->isValid(msg,true) && result;
93 if (myVolume && myVolume->isEnabled() )
94 result = myVolume->isValid(msg,true) && result;
99 QFrame* NETGENPluginGUI_SimpleCreator::buildFrame()
101 QFrame* fr = new QFrame();
103 QVBoxLayout* lay = new QVBoxLayout( fr );
105 lay->setSpacing( 0 );
107 QGroupBox* argGroup = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
108 lay->addWidget( argGroup );
110 QGridLayout* argLay = new QGridLayout( argGroup );
111 argLay->setSpacing( SPACING );
112 argLay->setMargin( MARGIN );
113 argLay->setColumnStretch( 0, 0 );
114 argLay->setColumnStretch( 1, 1 );
119 myName = new QLineEdit( argGroup );
120 argLay->addWidget( new QLabel( tr( "SMESH_NAME" ), argGroup ), argRow, 0 );
121 argLay->addWidget( myName, argRow, 1 );
131 dimGroup = new QGroupBox( tr( "NG_1D" ), argGroup );
132 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
135 dimLay = new QGridLayout( dimGroup );
136 dimLay->setSpacing( SPACING );
137 dimLay->setMargin( MARGIN );
138 dimLay->setColumnStretch( 0, 0 );
139 dimLay->setColumnStretch( 1, 1 );
142 // * number of segments
143 myNbSegRadioBut = new QRadioButton( tr( "SMESH_NB_SEGMENTS_HYPOTHESIS" ), dimGroup );
144 myNbSeg = new SalomeApp_IntSpinBox( dimGroup );
145 myNbSeg->setMinimum( 1 );
146 myNbSeg->setMaximum( 9999 );
147 myNbSeg->setValue( 1 );
148 dimLay->addWidget( myNbSegRadioBut, dimRow, 0 );
149 dimLay->addWidget( myNbSeg, dimRow, 1 );
153 myLengthRadioBut = new QRadioButton( tr( "SMESH_LOCAL_LENGTH_HYPOTHESIS" ), dimGroup );
154 myLength = new SMESHGUI_SpinBox( dimGroup );
155 myLength->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 0.1, "length_precision" );
156 myLength->setValue( 1. );
157 dimLay->addWidget( myLengthRadioBut, dimRow, 0 );
158 dimLay->addWidget( myLength, dimRow, 1 );
163 dimGroup = new QGroupBox( tr( "NG_2D" ), argGroup );
164 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
167 dimLay = new QGridLayout( dimGroup );
168 dimLay->setSpacing( SPACING );
169 dimLay->setMargin( MARGIN );
170 dimLay->setColumnStretch( 0, 0 );
171 dimLay->setColumnStretch( 1, 1 );
174 // * Length from edges
175 myLenFromEdgesCheckBox = new QCheckBox( tr( "NG_LENGTH_FROM_EDGES" ), dimGroup );
176 dimLay->addWidget( myLenFromEdgesCheckBox, dimRow, 0, 1, 2 );
180 dimLay->addWidget( new QLabel( tr( "SMESH_MAX_ELEMENT_AREA_HYPOTHESIS" ), dimGroup), dimRow, 0);
181 myArea = new SMESHGUI_SpinBox( dimGroup );
182 myArea->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 0.1, "area_precision" );
183 myArea->setValue( 1. );
184 dimLay->addWidget( myArea, dimRow, 1 );
187 // * allow quadrangles
188 const bool is3D = ( hypType()=="NETGEN_SimpleParameters_3D" );
191 myAllowQuadCheckBox = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), dimGroup );
192 dimLay->addWidget( myAllowQuadCheckBox, dimRow, 0, 1, 2 );
199 dimGroup = new QGroupBox( tr( "NG_3D" ), argGroup );
200 argLay->addWidget( dimGroup, argRow, 0, 1, 2 );
203 dimLay = new QGridLayout( dimGroup );
204 dimLay->setSpacing( SPACING );
205 dimLay->setMargin( MARGIN );
206 dimLay->setColumnStretch( 0, 0 );
207 dimLay->setColumnStretch( 1, 1 );
210 // * Length from faces
211 myLenFromFacesCheckBox = new QCheckBox( tr( "NG_LENGTH_FROM_FACES" ), dimGroup );
212 dimLay->addWidget( myLenFromFacesCheckBox, dimRow, 0, 1, 2 );
216 dimLay->addWidget(new QLabel( tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"), dimGroup), dimRow, 0);
217 myVolume = new SMESHGUI_SpinBox( dimGroup );
218 myVolume->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 0.1, "volume_precision" );
219 myVolume->setValue( 1. );
220 dimLay->addWidget( myVolume, dimRow, 1 );
224 connect( myNbSegRadioBut, SIGNAL( clicked(bool) ), this, SLOT( onValueChanged() ));
225 connect( myLengthRadioBut, SIGNAL( clicked(bool) ), this, SLOT( onValueChanged() ));
226 connect( myLenFromEdgesCheckBox, SIGNAL( stateChanged(int)), this, SLOT( onValueChanged() ));
227 if ( myLenFromFacesCheckBox )
228 connect( myLenFromFacesCheckBox, SIGNAL( stateChanged(int)), this, SLOT( onValueChanged() ));
233 void NETGENPluginGUI_SimpleCreator::retrieveParams() const
236 myName->setText( hypName() );
238 // Set default values
240 NETGENPlugin_SimpleHypothesis_2D_var h =
241 NETGENPlugin_SimpleHypothesis_2D::_narrow( initParamsHypothesis( hasInitParamsHypothesis() ));
243 int dfltNbSeg = (int) h->GetNumberOfSegments();
244 myNbSeg->setValue( dfltNbSeg );
245 if ( double len = h->GetLocalLength() ) {
246 myLength->setValue( len );
247 myArea->setValue( len * len );
249 myVolume->setValue( len * len * len );
252 h = NETGENPlugin_SimpleHypothesis_2D::_narrow( hypothesis() );
254 // set values of hypothesis
256 //SMESH::ListOfParameters_var aParameters = h->GetLastParameters();
259 int nbSeg = isCreation() ? dfltNbSeg : (int) h->GetNumberOfSegments();
260 myNbSegRadioBut->setChecked( nbSeg );
261 myLengthRadioBut->setChecked( !nbSeg );
264 myLength->setEnabled( false );
265 myNbSeg->setEnabled( true );
266 aPrm = getVariableName("SetNumberOfSegments");
268 myNbSeg->setValue( nbSeg );
270 myNbSeg->setText(aPrm);
273 myNbSeg->setEnabled( false );
274 myLength->setEnabled( true );
275 aPrm = getVariableName("SetLocalLength");
277 myLength->setValue( h->GetLocalLength() );
279 myLength->setText(aPrm);
283 if ( double area = h->GetMaxElementArea() ) {
284 myLenFromEdgesCheckBox->setChecked( false );
285 myArea->setEnabled( true );
286 aPrm = getVariableName("SetMaxElementArea");
288 myArea->setValue( area );
290 myArea->setText( aPrm );
293 myLenFromEdgesCheckBox->setChecked( true );
294 myArea->setEnabled( false );
296 if ( myAllowQuadCheckBox )
297 myAllowQuadCheckBox->setChecked( h->GetAllowQuadrangles() );
301 NETGENPlugin_SimpleHypothesis_3D_var h = NETGENPlugin_SimpleHypothesis_3D::_narrow( hypothesis() );
302 if ( double volume = (double) h->GetMaxElementVolume() ) {
303 myLenFromFacesCheckBox->setChecked( false );
304 myVolume->setEnabled( true );
305 aPrm = getVariableName("SetMaxElementVolume");
307 myVolume->setValue( volume );
309 myVolume->setText( aPrm );
312 myLenFromFacesCheckBox->setChecked( true );
313 myVolume->setEnabled( false );
318 QString NETGENPluginGUI_SimpleCreator::storeParams() const
323 NETGENPlugin_SimpleHypothesis_2D_var h =
324 NETGENPlugin_SimpleHypothesis_2D::_narrow( hypothesis() );
327 SMESH::SetName( SMESH::FindSObject( h ), myName->text().toLatin1().data() );
332 if ( myNbSeg->isEnabled() ) {
333 h->SetVarParameter( myNbSeg->text().toLatin1().constData(), "SetNumberOfSegments");
334 h->SetNumberOfSegments( myNbSeg->value() );
335 valStr += "nbSeg=" + myNbSeg->text();
338 h->SetVarParameter( myLength->text().toLatin1().constData(), "SetLocalLength");
339 h->SetLocalLength( myLength->value() );
340 valStr += "len=" + myLength->text();
344 if ( myArea->isEnabled() ) {
345 h->SetVarParameter( myArea->text().toLatin1().constData(), "SetMaxElementArea");
346 h->SetMaxElementArea( myArea->value() );
347 valStr += "; area=" + myArea->text();
350 h->LengthFromEdges();
351 valStr += "; lenFromEdges";
353 if ( myAllowQuadCheckBox )
354 h->SetAllowQuadrangles( myAllowQuadCheckBox->isChecked() );
358 NETGENPlugin_SimpleHypothesis_3D_var h =
359 NETGENPlugin_SimpleHypothesis_3D::_narrow( hypothesis() );
360 if ( myVolume->isEnabled() ) {
361 h->SetVarParameter( myVolume->text().toLatin1().constData(), "SetMaxElementVolume");
362 h->SetMaxElementVolume( myVolume->value() );
363 valStr += "; vol=" + myVolume->text();
366 h->LengthFromFaces();
367 valStr += "; lenFromFaces";
371 catch(const SALOME::SALOME_Exception& ex)
373 SalomeApp_Tools::QtCatchCorbaException(ex);
379 void NETGENPluginGUI_SimpleCreator::onValueChanged()
381 QObject* changed = sender();
383 if ( myNbSegRadioBut == changed )
385 myLengthRadioBut->setChecked( !myNbSegRadioBut->isChecked() );
387 else if ( myLengthRadioBut == changed )
389 myNbSegRadioBut->setChecked( !myLengthRadioBut->isChecked() );
391 else if ( myLenFromEdgesCheckBox == changed )
393 myArea->setEnabled( !myLenFromEdgesCheckBox->isChecked() );
395 else if ( myLenFromFacesCheckBox == changed )
397 myVolume->setEnabled( !myLenFromFacesCheckBox->isChecked() );
399 myLength->setEnabled( myLengthRadioBut->isChecked() );
400 myNbSeg->setEnabled( myNbSegRadioBut->isChecked() );
403 QString NETGENPluginGUI_SimpleCreator::caption() const
405 return tr( (hypType() + "_TITLE").toLatin1().data() );
408 QPixmap NETGENPluginGUI_SimpleCreator::icon() const
410 QString hypIconName = tr( ("ICON_DLG_" + hypType()).toLatin1().data() );
411 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
414 QString NETGENPluginGUI_SimpleCreator::type() const
416 return tr( (hypType() + "_HYPOTHESIS").toLatin1().data() );
419 QString NETGENPluginGUI_SimpleCreator::helpPage() const
421 return "netgen_2d_3d_hypo_page.html";