1 // Copyright (C) 2004-2008 CEA/DEN, EDF R&D
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
19 // GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin
20 // File : GHS3DPluginGUI_HypothesisCreator.cxx
21 // Author : Michael Zorin
22 // Module : GHS3DPlugin
25 #include "GHS3DPluginGUI_HypothesisCreator.h"
27 #include <SMESHGUI_Utils.h>
28 #include <SMESHGUI_HypothesesUtils.h>
30 #include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm)
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_FileDlg.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Tools.h>
41 #include <QGridLayout>
42 #include <QVBoxLayout>
47 #include <QPushButton>
60 #include <sys/sysinfo.h>
63 int maxAvailableMemory()
66 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
67 MEMORYSTATUSEX statex;
68 statex.dwLength = sizeof (statex);
69 int err = GlobalMemoryStatusEx (&statex);
72 statex.ullTotalPhys / 1024 / 1024 +
73 statex.ullTotalPageFile / 1024 / 1024 +
74 statex.ullTotalVirtual / 1024 / 1024;
75 return (int) ( 0.7 * totMB );
79 int err = sysinfo( &si );
82 si.totalram * si.mem_unit / 1024 / 1024 +
83 si.totalswap * si.mem_unit / 1024 / 1024 ;
84 return (int) ( 0.7 * totMB );
90 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType )
91 : SMESHGUI_GenericHypothesisCreator( theHypType )
95 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
99 QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame()
101 QFrame* fr = new QFrame( 0 );
102 QVBoxLayout* lay = new QVBoxLayout( fr );
104 lay->setSpacing( 0 );
107 QTabWidget* tab = new QTabWidget( fr );
108 tab->setTabShape( QTabWidget::Rounded );
109 tab->setTabPosition( QTabWidget::North );
110 lay->addWidget( tab );
113 myStdGroup = new QWidget();
114 QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
115 aStdLayout->setSpacing( 6 );
116 aStdLayout->setMargin( 11 );
122 aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
123 myName = new QLineEdit( myStdGroup );
124 aStdLayout->addWidget( myName, row++, 1, 1, 1 );
127 myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
128 aStdLayout->addWidget( myToMeshHolesCheck, row++, 0, 1, 2 );
130 aStdLayout->addWidget( new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup ), row, 0 );
131 myOptimizationLevelCombo = new QComboBox( myStdGroup );
132 aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 );
135 types << tr( "LEVEL_NONE" ) << tr( "LEVEL_LIGHT" ) << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STRONG" );
136 myOptimizationLevelCombo->addItems( types );
138 aStdLayout->setRowStretch( row, 5 );
140 // advanced parameters
141 myAdvGroup = new QWidget();
142 QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
143 anAdvLayout->setSpacing( 6 );
144 anAdvLayout->setMargin( 11 );
146 myMaximumMemoryCheck = new QCheckBox( tr( "MAX_MEMORY_SIZE" ), myAdvGroup );
147 myMaximumMemorySpin = new QSpinBox( myAdvGroup );
148 myMaximumMemorySpin->setMinimum( 1 );
149 myMaximumMemorySpin->setMaximum( maxAvailableMemory() );
150 myMaximumMemorySpin->setSingleStep( 10 );
151 QLabel* aMegabyteLabel = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
153 myInitialMemoryCheck = new QCheckBox( tr( "INIT_MEMORY_SIZE" ), myAdvGroup );
154 myInitialMemorySpin = new QSpinBox( myAdvGroup );
155 myInitialMemorySpin->setMinimum( 1 );
156 myInitialMemorySpin->setMaximum( maxAvailableMemory() );
157 myInitialMemorySpin->setSingleStep( 10 );
158 QLabel* aMegabyteLabel2 = new QLabel( tr( "MEGABYTE" ), myAdvGroup );
160 QLabel* aWorkinDirLabel = new QLabel( tr( "WORKING_DIR" ), myAdvGroup );
161 myWorkingDir = new QLineEdit( myAdvGroup );
162 //myWorkingDir->setReadOnly( true );
163 QPushButton* dirBtn = new QPushButton( tr( "SELECT_DIR" ), myAdvGroup );
164 dirBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
166 myKeepFiles = new QCheckBox( tr( "KEEP_WORKING_FILES" ), myAdvGroup );
168 QLabel* aVerboseLevelLabel = new QLabel( tr( "VERBOSE_LEVEL" ), myAdvGroup );
169 myVerboseLevelSpin = new QSpinBox( myAdvGroup );
170 myVerboseLevelSpin->setMinimum( 0 );
171 myVerboseLevelSpin->setMaximum( 10 );
172 myVerboseLevelSpin->setSingleStep( 1 );
174 myToCreateNewNodesCheck = new QCheckBox( tr( "TO_ADD_NODES" ), myAdvGroup );
176 myBoundaryRecoveryCheck = new QCheckBox( tr( "RECOVERY_VERSION" ), myAdvGroup );
178 QLabel* aTextOptionLabel = new QLabel( tr( "TEXT_OPTION" ), myAdvGroup );
179 myTextOption = new QLineEdit( myAdvGroup );
181 anAdvLayout->addWidget( myMaximumMemoryCheck, 0, 0, 1, 1 );
182 anAdvLayout->addWidget( myMaximumMemorySpin, 0, 1, 1, 1 );
183 anAdvLayout->addWidget( aMegabyteLabel, 0, 2, 1, 1 );
184 anAdvLayout->addWidget( myInitialMemoryCheck, 1, 0, 1, 1 );
185 anAdvLayout->addWidget( myInitialMemorySpin, 1, 1, 1, 1 );
186 anAdvLayout->addWidget( aMegabyteLabel2, 1, 2, 1, 1 );
187 anAdvLayout->addWidget( aWorkinDirLabel, 2, 0, 1, 1 );
188 anAdvLayout->addWidget( myWorkingDir, 2, 1, 1, 2 );
189 anAdvLayout->addWidget( dirBtn, 2, 3, 1, 1 );
190 anAdvLayout->addWidget( myKeepFiles, 3, 0, 1, 4 );
191 anAdvLayout->addWidget( aVerboseLevelLabel, 4, 0, 1, 1 );
192 anAdvLayout->addWidget( myVerboseLevelSpin, 4, 1, 1, 1 );
193 anAdvLayout->addWidget( myToCreateNewNodesCheck, 5, 0, 1, 4 );
194 anAdvLayout->addWidget( myBoundaryRecoveryCheck, 6, 0, 1, 4 );
195 anAdvLayout->addWidget( aTextOptionLabel, 7, 0, 1, 1 );
196 anAdvLayout->addWidget( myTextOption, 7, 1, 1, 2 );
199 tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
200 tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
201 tab->setCurrentIndex( STD_TAB );
204 connect( myMaximumMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
205 connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
206 connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
207 connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
212 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
214 QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() );
215 if ( !dir.isEmpty() )
216 myWorkingDir->setText( dir );
219 void GHS3DPluginGUI_HypothesisCreator::updateWidgets()
221 myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() );
222 myInitialMemoryCheck->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
223 myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() && !myBoundaryRecoveryCheck->isChecked() );
224 myOptimizationLevelCombo->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
227 bool GHS3DPluginGUI_HypothesisCreator::checkParams() const
229 if ( !QFileInfo( myWorkingDir->text().trimmed() ).isWritable() ) {
230 SUIT_MessageBox::warning( dlg(),
231 tr( "SMESH_WRN_WARNING" ),
232 tr( "GHS3D_PERMISSION_DENIED" ) );
238 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
240 GHS3DHypothesisData data;
241 readParamsFromHypo( data );
244 myName->setText( data.myName );
246 myToMeshHolesCheck ->setChecked ( data.myToMeshHoles );
247 myOptimizationLevelCombo->setCurrentIndex( data.myOptimizationLevel );
248 myMaximumMemoryCheck ->setChecked ( data.myMaximumMemory > 0 );
249 myMaximumMemorySpin ->setValue ( qMax( data.myMaximumMemory,
250 myMaximumMemorySpin->minimum() ));
251 myInitialMemoryCheck ->setChecked ( data.myInitialMemory > 0 );
252 myInitialMemorySpin ->setValue ( qMax( data.myInitialMemory,
253 myInitialMemorySpin->minimum() ));
254 myWorkingDir ->setText ( data.myWorkingDir );
255 myKeepFiles ->setChecked ( data.myKeepFiles );
256 myVerboseLevelSpin ->setValue ( data.myVerboseLevel );
257 myToCreateNewNodesCheck ->setChecked ( data.myToCreateNewNodes );
258 myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery );
259 myTextOption ->setText ( data.myTextOption );
261 GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this;
262 that->updateWidgets();
265 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
267 GHS3DHypothesisData data;
268 readParamsFromWidgets( data );
269 storeParamsToHypo( data );
273 if ( !data.myBoundaryRecovery )
274 valStr = "-c " + QString::number( !data.myToMeshHoles );
276 if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 4 && !data.myBoundaryRecovery) {
277 char* level[] = { "none" , "light" , "standard" , "strong" };
279 valStr += level[ data.myOptimizationLevel ];
281 if ( data.myMaximumMemory > 0 ) {
283 valStr += QString::number( data.myMaximumMemory );
285 if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
287 valStr += QString::number( data.myInitialMemory );
290 valStr += QString::number( data.myVerboseLevel );
292 if ( !data.myToCreateNewNodes )
295 if ( data.myBoundaryRecovery )
299 valStr += data.myTextOption;
304 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
306 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
307 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
309 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
310 h_data.myName = isCreation() && data ? hypName() : "";
312 h_data.myToMeshHoles = h->GetToMeshHoles();
313 h_data.myMaximumMemory = h->GetMaximumMemory();
314 h_data.myInitialMemory = h->GetInitialMemory();
315 h_data.myInitialMemory = h->GetInitialMemory();
316 h_data.myOptimizationLevel = h->GetOptimizationLevel();
317 h_data.myKeepFiles = h->GetKeepFiles();
318 h_data.myWorkingDir = h->GetWorkingDirectory();
319 h_data.myVerboseLevel = h->GetVerboseLevel();
320 h_data.myToCreateNewNodes = h->GetToCreateNewNodes();
321 h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion();
322 h_data.myTextOption = h->GetTextOption();
327 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
329 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
330 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
336 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
338 if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
339 h->SetToMeshHoles ( h_data.myToMeshHoles );
340 if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
341 h->SetMaximumMemory ( h_data.myMaximumMemory );
342 if ( h->GetInitialMemory() != h_data.myInitialMemory )
343 h->SetInitialMemory ( h_data.myInitialMemory );
344 if ( h->GetInitialMemory() != h_data.myInitialMemory )
345 h->SetInitialMemory ( h_data.myInitialMemory );
346 if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
347 h->SetOptimizationLevel( h_data.myOptimizationLevel );
348 if ( h->GetKeepFiles() != h_data.myKeepFiles )
349 h->SetKeepFiles ( h_data.myKeepFiles );
350 if ( h->GetWorkingDirectory() != h_data.myWorkingDir )
351 h->SetWorkingDirectory ( h_data.myWorkingDir.toLatin1().constData() );
352 if ( h->GetVerboseLevel() != h_data.myVerboseLevel )
353 h->SetVerboseLevel ( h_data.myVerboseLevel );
354 if ( h->GetToCreateNewNodes() != h_data.myToCreateNewNodes )
355 h->SetToCreateNewNodes( h_data.myToCreateNewNodes );
356 if ( h->GetToUseBoundaryRecoveryVersion() != h_data.myBoundaryRecovery )
357 h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery );
358 if ( h->GetTextOption() != h_data.myTextOption )
359 h->SetTextOption ( h_data.myTextOption.toLatin1().constData() );
361 catch ( const SALOME::SALOME_Exception& ex )
363 SalomeApp_Tools::QtCatchCorbaException( ex );
369 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
371 h_data.myName = myName ? myName->text() : "";
372 h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
373 h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1;
374 h_data.myInitialMemory = myInitialMemoryCheck->isChecked() ? myInitialMemorySpin->value() : -1;
375 h_data.myOptimizationLevel = myOptimizationLevelCombo->currentIndex();
376 h_data.myKeepFiles = myKeepFiles->isChecked();
377 h_data.myWorkingDir = myWorkingDir->text().trimmed();
378 h_data.myVerboseLevel = myVerboseLevelSpin->value();
379 h_data.myToCreateNewNodes = myToCreateNewNodesCheck->isChecked();
380 h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked();
381 h_data.myTextOption = myTextOption->text();
386 QString GHS3DPluginGUI_HypothesisCreator::caption() const
388 return tr( "GHS3D_TITLE" );
391 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
393 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", tr( "ICON_DLG_GHS3D_PARAMETERS" ) );
396 QString GHS3DPluginGUI_HypothesisCreator::type() const
398 return tr( "GHS3D_HYPOTHESIS" );
401 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
403 return "ghs3d_hypo_page.html";
406 //=============================================================================
407 /*! GetHypothesisCreator
410 //=============================================================================
413 GHS3DPLUGINGUI_EXPORT
414 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType )
416 if ( aHypType == "GHS3D_Parameters" )
417 return new GHS3DPluginGUI_HypothesisCreator( aHypType );