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 <QtxComboBox.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_FileDlg.h>
39 #include <SalomeApp_Tools.h>
42 #include <qgroupbox.h>
45 #include <qlineedit.h>
46 #include <qcheckbox.h>
50 #include <qpushbutton.h>
51 #include <qfiledialog.h>
52 #include <qfileinfo.h>
53 //#include <qapplication.h>
63 #include <sys/sysinfo.h>
66 int maxAvailableMemory()
70 int err = sysinfo( &si );
73 si.totalram * si.mem_unit / 1024 / 1024 +
74 si.totalswap * si.mem_unit / 1024 / 1024 ;
75 return (int) ( 0.7 * totMB );
82 GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType )
83 : SMESHGUI_GenericHypothesisCreator( theHypType )
87 GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator()
91 QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame()
93 QFrame* fr = new QFrame( 0, "myframe" );
94 QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 );
97 QTabBar* tab = new QTabBar( fr, "QTabBar");
98 tab->setShape( QTabBar::RoundedAbove );
99 tab->insertTab( new QTab( tr( "SMESH_ARGUMENTS")), STD_TAB);
100 tab->insertTab( new QTab( tr( "GHS3D_ADV_ARGS")), ADV_TAB);
101 lay->addWidget( tab );
104 myStdGroup = new QGroupBox( 2, Qt::Horizontal, fr, "myStdGroup" );
105 myStdGroup->layout()->setSpacing( 6 );
106 myStdGroup->layout()->setMargin( 11 );
107 lay->addWidget( myStdGroup );
112 new QLabel( tr( "SMESH_NAME" ), myStdGroup );
113 myName = new QLineEdit( myStdGroup );
116 myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup );
117 myStdGroup->addSpace(0);
119 new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup );
120 myOptimizationLevelCombo = new QtxComboBox( myStdGroup );
122 types.append( QObject::tr( "LEVEL_NONE" ) );
123 types.append( QObject::tr( "LEVEL_LIGHT" ) );
124 types.append( QObject::tr( "LEVEL_MEDIUM" ) );
125 types.append( QObject::tr( "LEVEL_STRONG" ) );
126 myOptimizationLevelCombo->insertStringList( types );
128 // advanced parameters
129 myAdvGroup = new QGroupBox( 3, Qt::Horizontal, fr, "myAdvGroup" );
130 lay->addWidget( myAdvGroup );
132 myMaximumMemoryCheck = new QCheckBox( tr("MAX_MEMORY_SIZE"), myAdvGroup );
134 myMaximumMemorySpin = new QSpinBox( myAdvGroup );
135 myMaximumMemorySpin->setMinValue( 20 );
136 myMaximumMemorySpin->setMaxValue( maxAvailableMemory() );
137 myMaximumMemorySpin->setLineStep( 10 );
138 new QLabel( tr("MEGABYTE"), myAdvGroup);
140 myInitialMemoryCheck = new QCheckBox( tr("INIT_MEMORY_SIZE"), myAdvGroup );
142 myInitialMemorySpin = new QSpinBox( myAdvGroup );
143 myInitialMemorySpin->setMinValue( 20 );
144 myInitialMemorySpin->setMaxValue( maxAvailableMemory() );
145 myInitialMemorySpin->setLineStep( 10 );
146 new QLabel( tr("MEGABYTE"), myAdvGroup);
148 new QLabel( tr( "WORKING_DIR" ), myAdvGroup );
149 QPushButton* dirBtn = new QPushButton( tr( "SELECT_DIR"), myAdvGroup, "dirBtn");
150 myWorkingDir = new QLineEdit( myAdvGroup, "myWorkingDir");
151 myWorkingDir->setReadOnly( true );
153 myKeepFiles = new QCheckBox( tr( "KEEP_WORKING_FILES" ), myAdvGroup );
155 connect( tab, SIGNAL( selected(int) ), this, SLOT( onTabSelected(int) ) );
156 connect( myMaximumMemoryCheck, SIGNAL( toggled(bool) ), this, SLOT( onMemCheckToggled(bool) ));
157 connect( myInitialMemoryCheck, SIGNAL( toggled(bool) ), this, SLOT( onMemCheckToggled(bool) ));
158 connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) );
163 void GHS3DPluginGUI_HypothesisCreator::onTabSelected(int tab)
165 if ( tab == STD_TAB ) {
173 // qApp->processEvents();
177 void GHS3DPluginGUI_HypothesisCreator::onMemCheckToggled(bool on)
179 if ( sender() == myMaximumMemoryCheck )
180 myMaximumMemorySpin->setEnabled( on );
182 myInitialMemorySpin->setEnabled( on );
185 void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
187 QString dir = SUIT_FileDlg::getExistingDirectory(dlg(),QString::null, QString::null );
189 myWorkingDir->setText( dir );
193 bool GHS3DPluginGUI_HypothesisCreator::checkParams() const
195 if ( !QFileInfo( myWorkingDir->text() ).isWritable() ) {
196 SUIT_MessageBox::warn1(dlg(),
197 QObject::tr("SMESH_WRN_WARNING"),
198 QObject::tr("GHS3D_PERMISSION_DENIED"),
199 QObject::tr("SMESH_BUT_OK"));
205 void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
207 GHS3DHypothesisData data;
208 readParamsFromHypo( data );
211 myName->setText( data.myName );
213 myToMeshHolesCheck ->setChecked ( data.myToMeshHoles );
214 myOptimizationLevelCombo->setCurrentItem( data.myOptimizationLevel );
215 myMaximumMemoryCheck ->setChecked ( data.myMaximumMemory > 0 );
216 myMaximumMemorySpin ->setValue ( std::max( data.myMaximumMemory, myMaximumMemorySpin->minValue() ));
217 myInitialMemoryCheck ->setChecked ( data.myInitialMemory > 0 );
218 myInitialMemorySpin ->setValue ( std::max( data.myInitialMemory, myInitialMemorySpin->minValue() ));
219 myWorkingDir ->setText ( data.myWorkingDir );
220 myKeepFiles ->setChecked ( data.myKeepFiles );
222 myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() );
223 myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() );
226 QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
228 GHS3DHypothesisData data;
229 readParamsFromWidgets( data );
230 storeParamsToHypo( data );
232 QString valStr = " -c " + QString::number( !data.myToMeshHoles );
233 if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 4 ) {
234 char* level[] = { "none" , "light" , "standard" , "strong" };
236 valStr += level[ data.myOptimizationLevel ];
242 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
244 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
245 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
247 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
248 h_data.myName = isCreation() && data ? hypName() : "";
250 h_data.myToMeshHoles = h->GetToMeshHoles();
251 h_data.myMaximumMemory = h->GetMaximumMemory();
252 h_data.myInitialMemory = h->GetInitialMemory();
253 h_data.myInitialMemory = h->GetInitialMemory();
254 h_data.myOptimizationLevel = h->GetOptimizationLevel();
255 h_data.myKeepFiles = h->GetKeepFiles();
256 h_data.myWorkingDir = h->GetWorkingDirectory();
261 bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
263 GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
264 GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
270 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.latin1() );
272 if ( h->GetToMeshHoles() != h_data.myToMeshHoles ) // avoid duplication of DumpPython commands
273 h->SetToMeshHoles ( h_data.myToMeshHoles );
274 if ( h->GetMaximumMemory() != h_data.myMaximumMemory )
275 h->SetMaximumMemory ( h_data.myMaximumMemory );
276 if ( h->GetInitialMemory() != h_data.myInitialMemory )
277 h->SetInitialMemory ( h_data.myInitialMemory );
278 if ( h->GetInitialMemory() != h_data.myInitialMemory )
279 h->SetInitialMemory ( h_data.myInitialMemory );
280 if ( h->GetOptimizationLevel() != h_data.myOptimizationLevel )
281 h->SetOptimizationLevel( h_data.myOptimizationLevel );
282 if ( h->GetKeepFiles() != h_data.myKeepFiles )
283 h->SetKeepFiles ( h_data.myKeepFiles );
284 if (h->GetWorkingDirectory() != h_data.myWorkingDir )
285 h->SetWorkingDirectory ( h_data.myWorkingDir );
287 catch(const SALOME::SALOME_Exception& ex)
289 SalomeApp_Tools::QtCatchCorbaException(ex);
295 bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
297 h_data.myName = myName ? myName->text() : "";
298 h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
299 h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1;
300 h_data.myInitialMemory = myInitialMemoryCheck->isChecked() ? myInitialMemorySpin->value() : -1;
301 h_data.myOptimizationLevel = myOptimizationLevelCombo->currentItem();
302 h_data.myKeepFiles = myKeepFiles->isChecked();
303 h_data.myWorkingDir = myWorkingDir->text();
308 QString GHS3DPluginGUI_HypothesisCreator::caption() const
310 return tr( "GHS3D_TITLE" );
313 QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const
315 QString hypIconName = tr( QString("ICON_DLG_GHS3D_PARAMETERS" ));
316 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", hypIconName );
319 QString GHS3DPluginGUI_HypothesisCreator::type() const
321 return tr( "GHS3D_HYPOTHESIS" );
324 QString GHS3DPluginGUI_HypothesisCreator::helpPage() const
326 return "ghs3d_hypo_page.html";
329 //=============================================================================
330 /*! GetHypothesisCreator
333 //=============================================================================
337 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType )
339 if( aHypType=="GHS3D_Parameters" )
340 return new GHS3DPluginGUI_HypothesisCreator( aHypType );