1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : VisuGUI_BuildProgressDlg.cxx
25 // Author : Oleg UVAROV
28 #include "VisuGUI_BuildProgressDlg.h"
31 #include "VisuGUI_Tools.h"
33 #include "SUIT_FileDlg.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_MessageBox.h"
36 #include "SUIT_ResourceMgr.h"
38 #include "LightApp_Application.h"
40 #include <vtkTimerLog.h>
42 #include <qcheckbox.h>
43 #include <qgroupbox.h>
46 #include <qlcdnumber.h>
47 #include <qlineedit.h>
48 #include <qpushbutton.h>
54 VisuGUI_BuildProgressDlg::VisuGUI_BuildProgressDlg( QWidget* theParent ):
56 "VisuGUI_BuildProgressBar",
58 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
59 myIsRaiseColor( false )
61 setCaption( tr( "DLG_BUILD_PROGRESS_TITLE" ) );
63 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
65 QVBoxLayout* aTopLayout = new QVBoxLayout( this );
66 aTopLayout->setSpacing( 6 );
67 aTopLayout->setMargin( 6 );
68 aTopLayout->setAutoAdd( true );
71 mySettingsBox = new QGroupBox( tr( "IMPORT_SETTINGS" ), this );
72 mySettingsBox->setColumnLayout( 0, Qt::Vertical );
73 mySettingsBox->layout()->setSpacing( 0 );
74 mySettingsBox->layout()->setMargin( 0 );
76 QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox->layout() );
77 aSettingsLayout->setSpacing( 6 );
78 aSettingsLayout->setMargin( 11 );
80 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox );
81 myFileNameLineEdit = new QLineEdit( mySettingsBox );
82 myFileNameLineEdit->setMinimumWidth( 250 );
83 myFileNameLineEdit->setReadOnly( true );
85 QPushButton* aFileNameButton = new QPushButton( mySettingsBox );
86 aFileNameButton->setAutoDefault( false );
87 aFileNameButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
88 connect( aFileNameButton, SIGNAL( clicked() ), this, SLOT( onBrowseFile() ) );
90 myBuildAllCheckBox = new QCheckBox( tr( "BUILD_ALL" ), mySettingsBox );
91 myBuildAllCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "full_med_loading", false ) );
92 connect( myBuildAllCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
94 myBuildAtOnceCheckBox = new QCheckBox( tr( "BUILD_AT_ONCE" ), mySettingsBox );
95 myBuildAtOnceCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_at_once", false ) );
96 connect( myBuildAtOnceCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
98 myCloseCheckBox = new QCheckBox( tr( "CLOSE_AT_FINISH" ), mySettingsBox );
99 myCloseCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "close_at_finish", true ) );
101 aSettingsLayout->addWidget( aFileNameLabel, 0, 0 );
102 aSettingsLayout->addMultiCellWidget( myFileNameLineEdit, 1, 1, 0, 1 );
103 //aSettingsLayout->addWidget( aFileNameButton, 1, 2 );
104 aSettingsLayout->addWidget( myBuildAllCheckBox, 2, 0 );
105 aSettingsLayout->addWidget( myBuildAtOnceCheckBox, 3, 0 );
106 aSettingsLayout->addWidget( myCloseCheckBox, 4, 0 );
109 myProgressBox = new QGroupBox( tr( "IMPORT_PROGRESS" ), this );
110 myProgressBox->setColumnLayout( 0, Qt::Vertical );
111 myProgressBox->layout()->setSpacing( 0 );
112 myProgressBox->layout()->setMargin( 0 );
114 QGridLayout* aProgressLayout = new QGridLayout( myProgressBox->layout() );
115 aProgressLayout->setSpacing( 6 );
116 aProgressLayout->setMargin( 11 );
118 QLabel* aBuildEntitiesLabel = new QLabel( tr( "BUILD_ENTITIES" ), myProgressBox );
119 myBuildEntitiesButton = new QPushButton( myProgressBox );
120 myBuildEntitiesButton->setEnabled( false );
121 myBuildEntitiesButton->setFixedSize( 30, 30 );
122 myBuildEntitiesButton->setPaletteBackgroundColor( Qt::red );
124 myBuildFieldsCheckBox = new QCheckBox( tr( "BUILD_FIELDS" ), myProgressBox );
125 myBuildFieldsCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_fields", true ) );
126 myBuildFieldsButton = new QPushButton( myProgressBox );
127 myBuildFieldsButton->setEnabled( false );
128 myBuildFieldsButton->setFixedSize( 30, 30 );
129 myBuildFieldsButton->setPaletteBackgroundColor( Qt::red );
130 connect( myBuildFieldsCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
132 myBuildMinMaxCheckBox = new QCheckBox( tr( "BUILD_MINMAX" ), myProgressBox );
133 myBuildMinMaxCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_min_max", true ) );
134 myBuildMinMaxButton = new QPushButton( myProgressBox );
135 myBuildMinMaxButton->setEnabled( false );
136 myBuildMinMaxButton->setFixedSize( 30, 30 );
137 myBuildMinMaxButton->setPaletteBackgroundColor( Qt::red );
138 connect( myBuildMinMaxCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
140 myBuildGroupsCheckBox = new QCheckBox( tr( "BUILD_GROUPS" ), myProgressBox );
141 myBuildGroupsCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_groups", true ) );
142 myBuildGroupsButton = new QPushButton( myProgressBox );
143 myBuildGroupsButton->setEnabled( false );
144 myBuildGroupsButton->setFixedSize( 30, 30 );
145 myBuildGroupsButton->setPaletteBackgroundColor( Qt::red );
146 connect( myBuildGroupsCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
148 aProgressLayout->addWidget( aBuildEntitiesLabel, 0, 0 );
149 aProgressLayout->addWidget( myBuildEntitiesButton, 0, 1 );
150 aProgressLayout->addWidget( myBuildFieldsCheckBox, 1, 0 );
151 aProgressLayout->addWidget( myBuildFieldsButton, 1, 1 );
152 aProgressLayout->addWidget( myBuildMinMaxCheckBox, 2, 0 );
153 aProgressLayout->addWidget( myBuildMinMaxButton, 2, 1 );
154 aProgressLayout->addWidget( myBuildGroupsCheckBox, 3, 0 );
155 aProgressLayout->addWidget( myBuildGroupsButton, 3, 1 );
158 myTimeBox = new QGroupBox( tr( "IMPORT_TIME" ), this );
159 myTimeBox->setColumnLayout( 0, Qt::Vertical );
160 myTimeBox->layout()->setSpacing( 0 );
161 myTimeBox->layout()->setMargin( 0 );
163 QGridLayout* aTimeLayout = new QGridLayout( myTimeBox->layout() );
164 aTimeLayout->setSpacing( 6 );
165 aTimeLayout->setMargin( 11 );
167 QLabel* aTimeLabel = new QLabel( tr( "TIME" ), myTimeBox );
169 myTimeLCDNumber = new QLCDNumber( myTimeBox );
170 myTimeLCDNumber->setSegmentStyle( QLCDNumber::Filled );
171 myTimeLCDNumber->setPaletteBackgroundColor( Qt::black );
172 myTimeLCDNumber->setPaletteForegroundColor( Qt::white );
173 myTimeLCDNumber->setNumDigits( 8 );
174 myTimeLCDNumber->display( myTime.toString( "hh:mm:ss.zzz" ) );
176 aTimeLayout->addWidget( aTimeLabel, 0, 0 );
177 aTimeLayout->addWidget( myTimeLCDNumber, 0, 1 );
180 QGroupBox* CommonGroup = new QGroupBox( this );
181 CommonGroup->setColumnLayout(0, Qt::Vertical );
182 CommonGroup->layout()->setSpacing( 0 );
183 CommonGroup->layout()->setMargin( 0 );
184 QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup->layout() );
185 CommonGroupLayout->setAlignment( Qt::AlignTop );
186 CommonGroupLayout->setSpacing( 6 );
187 CommonGroupLayout->setMargin( 11 );
189 myStartButton = new QPushButton( tr( "START" ), CommonGroup );
190 myStartButton->setAutoDefault( true );
191 myStartButton->setDefault( true );
192 CommonGroupLayout->addWidget( myStartButton, 0, 0 );
193 CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
195 QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup );
196 aCloseButton->setAutoDefault( true );
197 CommonGroupLayout->addWidget( aCloseButton, 0, 2 );
199 QPushButton* aHelpButton = new QPushButton( tr( "HELP" ), CommonGroup );
200 aHelpButton->setAutoDefault( true );
201 CommonGroupLayout->addWidget( aHelpButton, 0, 3 );
203 connect( myStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) );
204 connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) );
205 connect( aHelpButton, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
207 myTimer = new QTimer( this );
208 connect( myTimer, SIGNAL( timeout() ), this, SLOT( onTimer() ) );
211 VisuGUI_BuildProgressDlg::~VisuGUI_BuildProgressDlg()
215 void VisuGUI_BuildProgressDlg::show()
217 if( !myFileName.isNull() || onBrowseFile() )
221 void VisuGUI_BuildProgressDlg::onStart()
223 if( myFileName.isNull() )
226 myResult = myGenerator->CreateResult( myFileName );
228 if (CORBA::is_nil(myResult.in())) {
229 SUIT_MessageBox::warn1(this,
231 tr("ERR_ERROR_IN_THE_FILE"),
235 myResult->SetBuildFields( myBuildFieldsCheckBox->isChecked(), myBuildMinMaxCheckBox->isChecked() );
236 myResult->SetBuildGroups( myBuildGroupsCheckBox->isChecked() );
239 myFileNameLineEdit->setReadOnly( true );
240 myStartButton->setEnabled( false );
242 bool aBuildAtOnce = myBuildAtOnceCheckBox->isChecked();
245 QApplication::setOverrideCursor( Qt::waitCursor );
246 myCurrentTime = vtkTimerLog::GetCurrentTime();
249 myTime.setHMS( 0, 0, 0 );
250 myTimer->start( 100 );
252 bool aBuildAll = myBuildAllCheckBox->isChecked();
253 myResult->Build( aBuildAll, aBuildAtOnce );
257 void VisuGUI_BuildProgressDlg::onClose()
262 void VisuGUI_BuildProgressDlg::onHelp()
264 QString aHelpFileName = "/files/importing_med_objects.htm"; // ?
265 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
267 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
268 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
271 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
272 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
273 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
274 QObject::tr("BUT_OK"));
278 bool VisuGUI_BuildProgressDlg::onBrowseFile()
280 QString aRootDir = QString( getenv( "VISU_ROOT_DIR") );
283 aFilter.append( tr( "FLT_MED_FILES" ) );
284 aFilter.append( tr( "FLT_ALL_FILES" ) );
286 QFileInfo aFileInfo = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_FROM_FILE" ), true );
287 QString aFileName = aFileInfo.filePath();
289 if( aFileName.isNull() )
292 myFileName = aFileName;
293 myFileNameLineEdit->setText( aFileName.section( '/', -1 ) );
298 void VisuGUI_BuildProgressDlg::onTimer()
301 bool aBuildAtOnce = myBuildAtOnceCheckBox->isChecked();
305 myTime = myTime.addMSecs( 100 );
306 if( myTime.minute() > 9 && myTimeLCDNumber->numDigits() < 9 )
307 myTimeLCDNumber->setNumDigits( 9 );
308 myTimeLCDNumber->display( myTime.toString( "m:ss.zzz" ) );
310 bool isEntitiesDone = myResult->IsEntitiesDone();
311 bool isFieldsDone = myResult->IsFieldsDone();
312 bool isMinMaxDone = myResult->IsMinMaxDone();
313 bool isGroupsDone = myResult->IsGroupsDone();
315 updateButton( myBuildEntitiesButton, isEntitiesDone );
316 updateButton( myBuildFieldsButton, isFieldsDone );
317 updateButton( myBuildMinMaxButton, isMinMaxDone );
318 updateButton( myBuildGroupsButton, isGroupsDone );
321 if( myResult->IsDone() )
327 QApplication::restoreOverrideCursor();
330 int mSecs = ( int )( 1000 * ( vtkTimerLog::GetCurrentTime() - myCurrentTime ) );
331 aTime = aTime.addMSecs( mSecs );
332 if( aTime.minute() > 9 )
333 myTimeLCDNumber->setNumDigits( 9 );
334 myTimeLCDNumber->display( aTime.toString( "m:ss.zzz" ) );
337 if( myCloseCheckBox->isChecked() )
340 SUIT_MessageBox::warn1( this, tr( "INF_VISU" ), tr( "IMPORT_DONE" ), tr( "BUT_OK" ) );
348 void VisuGUI_BuildProgressDlg::updateButton( QPushButton* theButton, bool theIsDone )
350 QColor aCurrentColor = theButton->paletteBackgroundColor();
351 if( aCurrentColor == Qt::gray || aCurrentColor == Qt::green )
354 QColor aNewColor = Qt::green;
359 aCurrentColor.getRgb( &r, &g, &b );
361 myIsRaiseColor = true;
363 myIsRaiseColor = false;
365 int gNew = g + ( myIsRaiseColor ? 1 : -1 ) * 51;
367 aNewColor.setRgb( 255, gNew, 0 );
370 theButton->setPaletteBackgroundColor( aNewColor );
373 void VisuGUI_BuildProgressDlg::done( int r )
375 QApplication::restoreOverrideCursor();
380 void VisuGUI_BuildProgressDlg::onBuildCheckBoxClicked()
382 QCheckBox* aCheckBox = ( QCheckBox* )sender();
386 bool anIsChecked = aCheckBox->isChecked();
388 QColor aColor = anIsChecked ? Qt::red : Qt::gray;
390 if( aCheckBox == myBuildAllCheckBox )
392 if( anIsChecked && !myBuildAtOnceCheckBox->isChecked() )
393 myBuildAtOnceCheckBox->animateClick();
395 else if( aCheckBox == myBuildAtOnceCheckBox )
397 if( !anIsChecked && myBuildAllCheckBox->isChecked() )
398 myBuildAllCheckBox->animateClick();
400 else if( aCheckBox == myBuildFieldsCheckBox )
402 myBuildFieldsButton->setPaletteBackgroundColor( aColor );
403 if( !anIsChecked && myBuildMinMaxCheckBox->isChecked() )
404 myBuildMinMaxCheckBox->animateClick();
406 else if( aCheckBox == myBuildMinMaxCheckBox )
408 myBuildMinMaxButton->setPaletteBackgroundColor( aColor );
409 if( anIsChecked && !myBuildFieldsCheckBox->isChecked() )
410 myBuildFieldsCheckBox->animateClick();
412 else if( aCheckBox == myBuildGroupsCheckBox )
413 myBuildGroupsButton->setPaletteBackgroundColor( aColor );
417 void VisuGUI_BuildProgressDlg::setFileName( const QString& theFileName )
419 if ( !theFileName.isNull() )
421 myFileName = theFileName;
422 myFileNameLineEdit->setText( myFileName.section( '/', -1 ) );