1 // GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : GHS3DPluginGUI_HypothesisCreator.cxx
24 // Author : Michael Zorin
25 // Module : GHS3DPlugin
28 #include "GHS3DPluginGUI_HypothesisCreator.h"
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
33 #include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm)
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_FileDlg.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SalomeApp_Tools.h>
44 #include <QGridLayout>
45 #include <QVBoxLayout>
50 #include <QPushButton>
61 #include <sys/sysinfo.h>
64 int maxAvailableMemory()
68 int err = sysinfo( &si );
71 si.totalram * si.mem_unit / 1024 / 1024 +
72 si.totalswap * si.mem_unit / 1024 / 1024 ;
73 return (int) ( 0.7 * totMB );
80 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType )
81 : SMESHGUI_GenericHypothesisCreator( theHypType )
85 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
89 QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame()
91 QFrame* fr = new QFrame( 0 );
92 QVBoxLayout* lay = new QVBoxLayout( fr );
97 QTabWidget* tab = new QTabWidget( fr );
98 tab->setTabShape( QTabWidget::Rounded );
99 tab->setTabPosition( QTabWidget::North );
100 lay->addWidget( tab );
103 myStdGroup = new QWidget();
104 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
105 aStdLayout->setSpacing( 6 );
106 aStdLayout->setMargin( 11 );
112 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
113 myName = new QLineEdit( myStdGroup );
114 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
117 myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
118 aStdLayout->addWidget( myToMeshHolesCheck, row++, 0, 1, 2 );
120 aStdLayout->addWidget( new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup ), row, 0 );
121 myOptimizationLevelCombo = new QComboBox( myStdGroup );
122 aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 );
125 types << tr( "LEVEL_NONE" ) << tr( "LEVEL_LIGHT" ) << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STRONG" );
126 myOptimizationLevelCombo->addItems( types );
128 aStdLayout->setRowStretch( row, 5 );
130 // advanced parameters
131 myAdvGroup = new QWidget();
132 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
133 anAdvLayout->setSpacing( 6 );
134 anAdvLayout->setMargin( 11 );
136 myMaximumMemoryCheck = new QCheckBox( tr( "MAX_MEMORY_SIZE" ), myAdvGroup );
137 myMaximumMemorySpin = new QSpinBox( myAdvGroup );
138 myMaximumMemorySpin->setMinimum( 1 );
139 myMaximumMemorySpin->setMaximum( maxAvailableMemory() );
140 myMaximumMemorySpin->setSingleStep( 10 );
141 QLabel* aMegabyteLabel = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
143 myInitialMemoryCheck = new QCheckBox( tr( "INIT_MEMORY_SIZE" ), myAdvGroup );
144 myInitialMemorySpin = new QSpinBox( myAdvGroup );
145 myInitialMemorySpin->setMinimum( 1 );
146 myInitialMemorySpin->setMaximum( maxAvailableMemory() );
147 myInitialMemorySpin->setSingleStep( 10 );
148 QLabel* aMegabyteLabel2 = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
150 QLabel* aWorkinDirLabel = new QLabel( tr( "WORKING_DIR" ), myAdvGroup );
151 myWorkingDir = new QLineEdit( myAdvGroup );
152 //myWorkingDir->setReadOnly( true );
153 QPushButton* dirBtn = new QPushButton( tr( "SELECT_DIR" ), myAdvGroup );
154 dirBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
156 myKeepFiles = new QCheckBox( tr( "KEEP_WORKING_FILES" ), myAdvGroup );
158 QLabel* aVerboseLevelLabel = new QLabel( tr( "VERBOSE_LEVEL" ), myAdvGroup );
159 myVerboseLevelSpin = new QSpinBox( myAdvGroup );
160 myVerboseLevelSpin->setMinimum( 0 );
161 myVerboseLevelSpin->setMaximum( 10 );
162 myVerboseLevelSpin->setSingleStep( 1 );
164 myToCreateNewNodesCheck = new QCheckBox( tr( "TO_ADD_NODES" ), myAdvGroup );
166 myBoundaryRecoveryCheck = new QCheckBox( tr( "RECOVERY_VERSION" ), myAdvGroup );
168 QLabel* aTextOptionLabel = new QLabel( tr( "TEXT_OPTION" ), myAdvGroup );
169 myTextOption = new QLineEdit( myAdvGroup );
171 anAdvLayout->addWidget( myMaximumMemoryCheck, 0, 0, 1, 1 );
172 anAdvLayout->addWidget( myMaximumMemorySpin, 0, 1, 1, 1 );
173 anAdvLayout->addWidget( aMegabyteLabel, 0, 2, 1, 1 );
174 anAdvLayout->addWidget( myInitialMemoryCheck, 1, 0, 1, 1 );
175 anAdvLayout->addWidget( myInitialMemorySpin, 1, 1, 1, 1 );
176 anAdvLayout->addWidget( aMegabyteLabel2, 1, 2, 1, 1 );
177 anAdvLayout->addWidget( aWorkinDirLabel, 2, 0, 1, 1 );
178 anAdvLayout->addWidget( myWorkingDir, 2, 1, 1, 2 );
179 anAdvLayout->addWidget( dirBtn, 2, 3, 1, 1 );
180 anAdvLayout->addWidget( myKeepFiles, 3, 0, 1, 4 );
181 anAdvLayout->addWidget( aVerboseLevelLabel, 4, 0, 1, 1 );
182 anAdvLayout->addWidget( myVerboseLevelSpin, 4, 1, 1, 1 );
183 anAdvLayout->addWidget( myToCreateNewNodesCheck, 5, 0, 1, 4 );
184 anAdvLayout->addWidget( myBoundaryRecoveryCheck, 6, 0, 1, 4 );
185 anAdvLayout->addWidget( aTextOptionLabel, 7, 0, 1, 1 );
186 anAdvLayout->addWidget( myTextOption, 7, 1, 1, 2 );
189 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
190 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
191 tab->setCurrentIndex( STD_TAB );
194 connect( myMaximumMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
195 connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
196 connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
197 connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
202 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
204 QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() );
205 if ( !dir.isEmpty() )
206 myWorkingDir->setText( dir );
209 void GHS3DPluginGUI_HypothesisCreator::updateWidgets()
211 myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() );
212 myInitialMemoryCheck->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
213 myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() && !myBoundaryRecoveryCheck->isChecked() );
214 myOptimizationLevelCombo->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
217 bool GHS3DPluginGUI_HypothesisCreator::checkParams() const
219 if ( !QFileInfo( myWorkingDir->text().trimmed() ).isWritable() ) {
220 SUIT_MessageBox::warning( dlg(),
221 tr( "SMESH_WRN_WARNING" ),
222 tr( "GHS3D_PERMISSION_DENIED" ) );
228 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
230 GHS3DHypothesisData data;
231 readParamsFromHypo( data );
234 myName->setText( data.myName );
236 myToMeshHolesCheck ->setChecked ( data.myToMeshHoles );
237 myOptimizationLevelCombo->setCurrentIndex( data.myOptimizationLevel );
238 myMaximumMemoryCheck ->setChecked ( data.myMaximumMemory > 0 );
239 myMaximumMemorySpin ->setValue ( qMax( data.myMaximumMemory,
240 myMaximumMemorySpin->minimum() ));
241 myInitialMemoryCheck ->setChecked ( data.myInitialMemory > 0 );
242 myInitialMemorySpin ->setValue ( qMax( data.myInitialMemory,
243 myInitialMemorySpin->minimum() ));
244 myWorkingDir ->setText ( data.myWorkingDir );
245 myKeepFiles ->setChecked ( data.myKeepFiles );
246 myVerboseLevelSpin ->setValue ( data.myVerboseLevel );
247 myToCreateNewNodesCheck ->setChecked ( data.myToCreateNewNodes );
248 myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery );
249 myTextOption ->setText ( data.myTextOption );
251 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
252 that->updateWidgets();
255 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
257 GHS3DHypothesisData data;
258 readParamsFromWidgets( data );
259 storeParamsToHypo( data );
263 if ( !data.myBoundaryRecovery )
264 valStr = "-c " + QString::number( !data.myToMeshHoles );
266 if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 4 && !data.myBoundaryRecovery) {
267 char* level[] = { "none" , "light" , "standard" , "strong" };
269 valStr += level[ data.myOptimizationLevel ];
271 if ( data.myMaximumMemory > 0 ) {
273 valStr += QString::number( data.myMaximumMemory );
275 if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
277 valStr += QString::number( data.myInitialMemory );
280 valStr += QString::number( data.myVerboseLevel );
282 if ( !data.myToCreateNewNodes )
285 if ( data.myBoundaryRecovery )
289 valStr += data.myTextOption;
294 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
296 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
297 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
299 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
300 h_data.myName = isCreation() && data ? hypName() : "";
302 h_data.myToMeshHoles = h->GetToMeshHoles();
303 h_data.myMaximumMemory = h->GetMaximumMemory();
304 h_data.myInitialMemory = h->GetInitialMemory();
305 h_data.myInitialMemory = h->GetInitialMemory();
306 h_data.myOptimizationLevel = h->GetOptimizationLevel();
307 h_data.myKeepFiles = h->GetKeepFiles();
308 h_data.myWorkingDir = h->GetWorkingDirectory();
309 h_data.myVerboseLevel = h->GetVerboseLevel();
310 h_data.myToCreateNewNodes = h->GetToCreateNewNodes();
311 h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion();
312 h_data.myTextOption = h->GetTextOption();
317 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
319 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
320 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
326 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
328 if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
329 h->SetToMeshHoles ( h_data.myToMeshHoles );
330 if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
331 h->SetMaximumMemory ( h_data.myMaximumMemory );
332 if ( h->GetInitialMemory() != h_data.myInitialMemory )
333 h->SetInitialMemory ( h_data.myInitialMemory );
334 if ( h->GetInitialMemory() != h_data.myInitialMemory )
335 h->SetInitialMemory ( h_data.myInitialMemory );
336 if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
337 h->SetOptimizationLevel( h_data.myOptimizationLevel );
338 if ( h->GetKeepFiles() != h_data.myKeepFiles )
339 h->SetKeepFiles ( h_data.myKeepFiles );
340 if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
341 h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
342 if ( h->GetVerboseLevel() != h_data.myVerboseLevel )
343 h->SetVerboseLevel ( h_data.myVerboseLevel );
344 if ( h->GetToCreateNewNodes() != h_data.myToCreateNewNodes )
345 h->SetToCreateNewNodes( h_data.myToCreateNewNodes );
346 if ( h->GetToUseBoundaryRecoveryVersion() != h_data.myBoundaryRecovery )
347 h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery );
348 if ( h->GetTextOption() != h_data.myTextOption )
349 h->SetTextOption ( h_data.myTextOption.toLatin1().constData() );
351 catch ( const SALOME::SALOME_Exception& ex )
353 SalomeApp_Tools::QtCatchCorbaException( ex );
359 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
361 h_data.myName = myName ? myName->text() : "";
362 h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
363 h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1;
364 h_data.myInitialMemory = myInitialMemoryCheck->isChecked() ? myInitialMemorySpin->value() : -1;
365 h_data.myOptimizationLevel = myOptimizationLevelCombo->currentIndex();
366 h_data.myKeepFiles = myKeepFiles->isChecked();
367 h_data.myWorkingDir = myWorkingDir->text().trimmed();
368 h_data.myVerboseLevel = myVerboseLevelSpin->value();
369 h_data.myToCreateNewNodes = myToCreateNewNodesCheck->isChecked();
370 h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked();
371 h_data.myTextOption = myTextOption->text();
376 QString GHS3DPluginGUI_HypothesisCreator::caption() const
378 return tr( "GHS3D_TITLE" );
381 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
383 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", tr( "ICON_DLG_GHS3D_PARAMETERS" ) );
386 QString GHS3DPluginGUI_HypothesisCreator::type() const
388 return tr( "GHS3D_HYPOTHESIS" );
391 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
393 return "ghs3d_hypo_page.html";
396 //=============================================================================
397 /*! GetHypothesisCreator
400 //=============================================================================
404 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType )
406 if ( aHypType == "GHS3D_Parameters" )
407 return new GHS3DPluginGUI_HypothesisCreator( aHypType );