#include "VisuGUI_Tools.h"
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_FileDlg.h"
+
+#include <vtkTimerLog.h>
+
+#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
+#include <qlcdnumber.h>
+#include <qlineedit.h>
#include <qpushbutton.h>
#include <qtimer.h>
/*!
* Constructor
*/
-VisuGUI_BuildProgressDlg::VisuGUI_BuildProgressDlg( QWidget* theParent,
- VISU::Result_var theResult,
- const QString& theFileName ):
- QDialog( theParent ),
- myResult( theResult )
+VisuGUI_BuildProgressDlg::VisuGUI_BuildProgressDlg( QWidget* theParent ):
+ QDialog( theParent, "VisuGUI_BuildProgressBar", false ),
+ myIsRaiseColor( false )
{
- setName( "VisuGUI_BuildProgressBar" );
setCaption( tr( "DLG_BUILD_PROGRESS_TITLE" ) );
- setSizeGripEnabled( true );
SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
QVBoxLayout* aTopLayout = new QVBoxLayout( this );
- //aTopLayout->setSpacing( 6 );
+ aTopLayout->setSpacing( 6 );
aTopLayout->setMargin( 6 );
aTopLayout->setAutoAdd( true );
- QString aCaption = QString( "Importing " ) + theFileName;
- QGroupBox* aBox = new QGroupBox( aCaption, this );
- aBox->setColumnLayout(0, Qt::Vertical );
- aBox->layout()->setSpacing( 0 );
- aBox->layout()->setMargin( 0 );
+ // Settings
+ mySettingsBox = new QGroupBox( tr( "IMPORT_SETTINGS" ), this );
+ mySettingsBox->setColumnLayout( 0, Qt::Vertical );
+ mySettingsBox->layout()->setSpacing( 0 );
+ mySettingsBox->layout()->setMargin( 0 );
+
+ QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox->layout() );
+ aSettingsLayout->setSpacing( 6 );
+ aSettingsLayout->setMargin( 11 );
+
+ QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox );
+ myFileNameLineEdit = new QLineEdit( mySettingsBox );
+ myFileNameLineEdit->setMinimumWidth( 250 );
+
+ QPushButton* aFileNameButton = new QPushButton( mySettingsBox );
+ aFileNameButton->setAutoDefault( false );
+ aFileNameButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
+ connect( aFileNameButton, SIGNAL( clicked() ), this, SLOT( onBrowseFile() ) );
+
+ myBuildAllCheckBox = new QCheckBox( tr( "BUILD_ALL" ), mySettingsBox );
+ myBuildAllCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "full_med_loading", false ) );
+ connect( myBuildAllCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
+
+ myBuildAtOnceCheckBox = new QCheckBox( tr( "BUILD_AT_ONCE" ), mySettingsBox );
+ myBuildAtOnceCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "build_at_once", true ) );
+ connect( myBuildAtOnceCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
+
+ aSettingsLayout->addWidget( aFileNameLabel, 0, 0 );
+ aSettingsLayout->addMultiCellWidget( myFileNameLineEdit, 1, 1, 0, 1 );
+ aSettingsLayout->addWidget( aFileNameButton, 1, 2 );
+ aSettingsLayout->addWidget( myBuildAllCheckBox, 2, 0 );
+ aSettingsLayout->addWidget( myBuildAtOnceCheckBox, 2, 1 );
+
+ // Progress
+ myProgressBox = new QGroupBox( tr( "IMPORT_PROGRESS" ), this );
+ myProgressBox->setColumnLayout( 0, Qt::Vertical );
+ myProgressBox->layout()->setSpacing( 0 );
+ myProgressBox->layout()->setMargin( 0 );
+
+ QGridLayout* aProgressLayout = new QGridLayout( myProgressBox->layout() );
+ aProgressLayout->setSpacing( 6 );
+ aProgressLayout->setMargin( 11 );
- QGridLayout* aGridLayout = new QGridLayout( aBox->layout() );
- aGridLayout->setSpacing( 6 );
- aGridLayout->setMargin( 11 );
+ myBuildEntitiesCheckBox = new QCheckBox( tr( "BUILD_ENTITIES" ), myProgressBox );
+ myBuildEntitiesCheckBox->setChecked( true );
+ myBuildEntitiesCheckBox->setEnabled( false );
+ myBuildEntitiesButton = new QPushButton( myProgressBox );
+ myBuildEntitiesButton->setEnabled( false );
+ myBuildEntitiesButton->setFixedSize( 30, 30 );
+ myBuildEntitiesButton->setPaletteBackgroundColor( Qt::red );
+ connect( myBuildEntitiesCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
- QLabel* BuildFieldsLabel = new QLabel( tr( "BUILD_FIELDS" ), aBox );
- myBuildFieldsButton = new QPushButton( aBox );
+ myBuildFieldsCheckBox = new QCheckBox( tr( "BUILD_FIELDS" ), myProgressBox );
+ myBuildFieldsCheckBox->setChecked( true );
+ myBuildFieldsButton = new QPushButton( myProgressBox );
myBuildFieldsButton->setEnabled( false );
myBuildFieldsButton->setFixedSize( 30, 30 );
myBuildFieldsButton->setPaletteBackgroundColor( Qt::red );
+ connect( myBuildFieldsCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
- QLabel* BuildGroupsLabel = new QLabel( tr( "BUILD_GROUPS" ), aBox );
- myBuildGroupsButton = new QPushButton( aBox );
+ myBuildMinMaxCheckBox = new QCheckBox( tr( "BUILD_MINMAX" ), myProgressBox );
+ myBuildMinMaxCheckBox->setChecked( true );
+ myBuildMinMaxButton = new QPushButton( myProgressBox );
+ myBuildMinMaxButton->setEnabled( false );
+ myBuildMinMaxButton->setFixedSize( 30, 30 );
+ myBuildMinMaxButton->setPaletteBackgroundColor( Qt::red );
+ connect( myBuildMinMaxCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
+
+ myBuildGroupsCheckBox = new QCheckBox( tr( "BUILD_GROUPS" ), myProgressBox );
+ myBuildGroupsCheckBox->setChecked( true );
+ myBuildGroupsButton = new QPushButton( myProgressBox );
myBuildGroupsButton->setEnabled( false );
myBuildGroupsButton->setFixedSize( 30, 30 );
myBuildGroupsButton->setPaletteBackgroundColor( Qt::red );
+ connect( myBuildGroupsCheckBox, SIGNAL( clicked() ), this, SLOT( onBuildCheckBoxClicked() ) );
- QLabel* BuildMinMaxLabel = new QLabel( tr( "BUILD_MINMAX" ), aBox );
- myBuildMinMaxButton = new QPushButton( aBox );
- myBuildMinMaxButton->setEnabled( false );
- myBuildMinMaxButton->setFixedSize( 30, 30 );
- myBuildMinMaxButton->setPaletteBackgroundColor( Qt::red );
+ aProgressLayout->addWidget( myBuildEntitiesCheckBox, 0, 0 );
+ aProgressLayout->addWidget( myBuildEntitiesButton, 0, 1 );
+ aProgressLayout->addWidget( myBuildFieldsCheckBox, 1, 0 );
+ aProgressLayout->addWidget( myBuildFieldsButton, 1, 1 );
+ aProgressLayout->addWidget( myBuildMinMaxCheckBox, 2, 0 );
+ aProgressLayout->addWidget( myBuildMinMaxButton, 2, 1 );
+ aProgressLayout->addWidget( myBuildGroupsCheckBox, 3, 0 );
+ aProgressLayout->addWidget( myBuildGroupsButton, 3, 1 );
+
+ // Time
+ myTimeBox = new QGroupBox( tr( "IMPORT_TIME" ), this );
+ myTimeBox->setColumnLayout( 0, Qt::Vertical );
+ myTimeBox->layout()->setSpacing( 0 );
+ myTimeBox->layout()->setMargin( 0 );
+
+ QGridLayout* aTimeLayout = new QGridLayout( myTimeBox->layout() );
+ aTimeLayout->setSpacing( 6 );
+ aTimeLayout->setMargin( 11 );
- aGridLayout->addWidget( BuildFieldsLabel, 0, 0 );
- aGridLayout->addWidget( myBuildFieldsButton, 0, 1 );
- aGridLayout->addWidget( BuildGroupsLabel, 1, 0 );
- aGridLayout->addWidget( myBuildGroupsButton, 1, 1 );
- aGridLayout->addWidget( BuildMinMaxLabel, 2, 0 );
- aGridLayout->addWidget( myBuildMinMaxButton, 2, 1 );
+ QLabel* aTimeLabel = new QLabel( tr( "TIME" ), myTimeBox );
+
+ myTimeLCDNumber = new QLCDNumber( myTimeBox );
+ myTimeLCDNumber->setSegmentStyle( QLCDNumber::Filled );
+ myTimeLCDNumber->setPaletteBackgroundColor( Qt::black );
+ myTimeLCDNumber->setPaletteForegroundColor( Qt::white );
+ myTimeLCDNumber->setNumDigits( 8 );
+ myTimeLCDNumber->display( myTime.toString( "hh:mm:ss.zzz" ) );
+
+ aTimeLayout->addWidget( aTimeLabel, 0, 0 );
+ aTimeLayout->addWidget( myTimeLCDNumber, 0, 1 );
+
+ // Start / Close
+ QGroupBox* CommonGroup = new QGroupBox( this );
+ CommonGroup->setColumnLayout(0, Qt::Vertical );
+ CommonGroup->layout()->setSpacing( 0 );
+ CommonGroup->layout()->setMargin( 0 );
+ QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup->layout() );
+ CommonGroupLayout->setAlignment( Qt::AlignTop );
+ CommonGroupLayout->setSpacing( 6 );
+ CommonGroupLayout->setMargin( 11 );
+
+ myStartButton = new QPushButton( tr( "START" ), CommonGroup );
+ myStartButton->setAutoDefault( true );
+ myStartButton->setDefault( true );
+ CommonGroupLayout->addWidget( myStartButton, 0, 0 );
+ CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
+
+ QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup );
+ aCloseButton->setAutoDefault( true );
+ CommonGroupLayout->addWidget( aCloseButton, 0, 2 );
+
+ connect( myStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) );
+ connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) );
myTimer = new QTimer( this );
connect( myTimer, SIGNAL( timeout() ), this, SLOT( onTimer() ) );
{
}
-void VisuGUI_BuildProgressDlg::start()
+void VisuGUI_BuildProgressDlg::show()
+{
+ if( onBrowseFile() )
+ QWidget::show();
+}
+
+void VisuGUI_BuildProgressDlg::onStart()
{
+ if( myFileName.isNull() )
+ return;
+
+ bool aBuildAll = myBuildAllCheckBox->isChecked();
+ bool aBuildAtOnce = myBuildAtOnceCheckBox->isChecked();
+
+ myResult = myGenerator->CreateResult( myFileName );
+
+ myResult->SetBuildFields( myBuildFieldsCheckBox->isChecked(), myBuildMinMaxCheckBox->isChecked() );
+ myResult->SetBuildGroups( myBuildGroupsCheckBox->isChecked() );
+
+ myResult->Build( aBuildAll, aBuildAtOnce );
+
+ //if( aBuildAtOnce )
+ // onClose();
+
+ //setModal( false );
+ myFileNameLineEdit->setReadOnly( true );
+ /*
+ myBuildAllCheckBox->setNoChange();
+ myBuildAtOnceCheckBox->setNoChange();
+ myBuildEntitiesCheckBox->setNoChange();
+ myBuildFieldsCheckBox->setNoChange();
+ myBuildMinMaxCheckBox->setNoChange();
+ myBuildGroupsCheckBox->setNoChange();
+ */
+
+ myStartButton->setEnabled( false );
+
+ myCurrentTime = vtkTimerLog::GetCurrentTime();
+
+ myTime.setHMS( 0, 0, 0 );
myTimer->start( 100 );
- show();
+}
+
+void VisuGUI_BuildProgressDlg::onClose()
+{
+ done( 0 );
+}
+
+bool VisuGUI_BuildProgressDlg::onBrowseFile()
+{
+ QString aRootDir = QString( getenv( "VISU_ROOT_DIR") );
+
+ QStringList aFilter;
+ aFilter.append( tr( "FLT_MED_FILES" ) );
+ aFilter.append( tr( "FLT_ALL_FILES" ) );
+
+ QFileInfo aFileInfo = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_FROM_FILE" ), true );
+ QString aFileName = aFileInfo.filePath();
+
+ if( aFileName.isNull() )
+ return false;
+
+ myFileName = aFileName;
+ myFileNameLineEdit->setText( aFileName.section( '/', -1 ) );
+
+ return true;
}
void VisuGUI_BuildProgressDlg::onTimer()
{
try {
+ bool aBuildAtOnce = myBuildAtOnceCheckBox->isChecked();
+
+ if( !aBuildAtOnce )
+ {
+ myTime = myTime.addMSecs( 100 );
+ if( myTime.minute() > 9 && myTimeLCDNumber->numDigits() < 9 )
+ myTimeLCDNumber->setNumDigits( 9 );
+ myTimeLCDNumber->display( myTime.toString( "m:ss.zzz" ) );
+ }
+
+ bool isEntitiesDone = myResult->IsEntitiesDone();
bool isFieldsDone = myResult->IsFieldsDone();
- bool isGroupsDone = myResult->IsGroupsDone();
bool isMinMaxDone = myResult->IsMinMaxDone();
+ bool isGroupsDone = myResult->IsGroupsDone();
+ updateButton( myBuildEntitiesButton, isEntitiesDone );
updateButton( myBuildFieldsButton, isFieldsDone );
- updateButton( myBuildGroupsButton, isGroupsDone );
updateButton( myBuildMinMaxButton, isMinMaxDone );
+ updateButton( myBuildGroupsButton, isGroupsDone );
+
+ if( myResult->IsDone() )
+ {
+ myTimer->stop();
- if( isFieldsDone && isGroupsDone && isMinMaxDone )
- done( 0 );
+ if( aBuildAtOnce )
+ {
+ cout << myCurrentTime << " -> " << vtkTimerLog::GetCurrentTime() << endl;
+ QTime aTime;
+ int mSecs = ( int )( 1000 * ( vtkTimerLog::GetCurrentTime() - myCurrentTime ) );
+ aTime = aTime.addMSecs( mSecs );
+ if( aTime.minute() > 9 )
+ myTimeLCDNumber->setNumDigits( 9 );
+ myTimeLCDNumber->display( aTime.toString( "m:ss.zzz" ) );
+ }
+ }
}
catch( ... ) {
done( 1 );
void VisuGUI_BuildProgressDlg::updateButton( QPushButton* theButton, bool theIsDone )
{
QColor aCurrentColor = theButton->paletteBackgroundColor();
+ if( aCurrentColor == Qt::gray || aCurrentColor == Qt::green )
+ return;
+
QColor aNewColor = Qt::green;
if( !theIsDone )
{
- aNewColor = Qt::red;
- if( aCurrentColor == Qt::red )
- aNewColor = Qt::yellow;
+ int r, g, b;
+ aCurrentColor.getRgb( &r, &g, &b );
+ if( g == 0 )
+ myIsRaiseColor = true;
+ else if( g == 255 )
+ myIsRaiseColor = false;
+
+ int gNew = g + ( myIsRaiseColor ? 1 : -1 ) * 51;
+
+ aNewColor.setRgb( 255, gNew, 0 );
}
theButton->setPaletteBackgroundColor( aNewColor );
myTimer->stop();
QDialog::done( r );
}
+
+void VisuGUI_BuildProgressDlg::onBuildCheckBoxClicked()
+{
+ QCheckBox* aCheckBox = ( QCheckBox* )sender();
+ if( !aCheckBox )
+ return;
+
+ bool anIsChecked = aCheckBox->isChecked();
+
+ QColor aColor = anIsChecked ? Qt::red : Qt::gray;
+
+ if( aCheckBox == myBuildAllCheckBox )
+ {
+ if( anIsChecked && !myBuildAtOnceCheckBox->isChecked() )
+ myBuildAtOnceCheckBox->animateClick();
+ }
+ else if( aCheckBox == myBuildAtOnceCheckBox )
+ {
+ if( !anIsChecked && myBuildAllCheckBox->isChecked() )
+ myBuildAllCheckBox->animateClick();
+ }
+ else if( aCheckBox == myBuildFieldsCheckBox )
+ {
+ myBuildFieldsButton->setPaletteBackgroundColor( aColor );
+ if( !anIsChecked && myBuildMinMaxCheckBox->isChecked() )
+ myBuildMinMaxCheckBox->animateClick();
+ }
+ else if( aCheckBox == myBuildMinMaxCheckBox )
+ {
+ myBuildMinMaxButton->setPaletteBackgroundColor( aColor );
+ if( anIsChecked && !myBuildFieldsCheckBox->isChecked() )
+ myBuildFieldsCheckBox->animateClick();
+ }
+ else if( aCheckBox == myBuildGroupsCheckBox )
+ myBuildGroupsButton->setPaletteBackgroundColor( aColor );
+
+}