]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_RecorderDlg.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VVTK / VVTK_RecorderDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VVTK_RecorderDlg.cxx
24 //  Author : Oleg UVAROV
25 //  Module : VISU
26 //
27 #include "VVTK_RecorderDlg.h"
28 #include "VVTK_Recorder.h"
29
30 #include "SUIT_FileDlg.h"
31 #include "SUIT_MessageBox.h"
32 #include "SUIT_ResourceMgr.h"
33 #include "SUIT_Session.h"
34
35 #include "QtxDoubleSpinBox.h"
36 #include "QtxIntSpinBox.h"
37
38 #include "LightApp_Application.h"
39
40 #include "CAM_Module.h"
41
42 #include <QCheckBox>
43 #include <QComboBox>
44 #include <QGroupBox>
45 #include <QKeyEvent>
46 #include <QLabel>
47 #include <QLayout>
48 #include <QLineEdit>
49 #include <QPushButton>
50
51 /*!
52  * Constructor
53  */
54 VVTK_RecorderDlg::VVTK_RecorderDlg( QWidget* theParent, VVTK_Recorder* theRecorder ):
55   QDialog( theParent ),
56   myRecorder( theRecorder )
57 {
58   setWindowTitle( tr( "DLG_RECORDER_TITLE" ) );
59
60   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
61
62   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
63   aTopLayout->setSpacing( 6 );
64   aTopLayout->setMargin( 6 );
65   //aTopLayout->setAutoAdd( true );
66
67   // Settings
68   QGroupBox* mySettingsBox = new QGroupBox( tr( "SETTINGS" ), this );
69   //mySettingsBox->setColumnLayout( 0, Qt::Vertical );
70   //mySettingsBox->layout()->setSpacing( 0 );
71   //mySettingsBox->layout()->setMargin( 0 );
72
73   QGridLayout* aSettingsLayout = new QGridLayout( mySettingsBox );
74   aSettingsLayout->setSpacing( 6 );
75   aSettingsLayout->setMargin( 11 );
76
77   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), mySettingsBox );
78   myFileNameLineEdit = new QLineEdit( mySettingsBox );
79   myFileNameLineEdit->setMinimumWidth( 250 );
80   myFileNameLineEdit->setReadOnly( true );
81
82   QLabel* aRecordingModeLabel = new QLabel( tr( "RECORDING_MODE" ), mySettingsBox );
83   myRecordingModeComboBox = new QComboBox( mySettingsBox );
84   myRecordingModeComboBox->addItem( tr( "SKIPPED_FRAMES" ) );
85   myRecordingModeComboBox->addItem( tr( "ALL_DISLPAYED_FRAMES" ) );
86   myRecordingModeComboBox->setCurrentIndex( aResourceMgr->integerValue( "VISU", "recorder_mode", 1 ) );
87
88   QLabel* aFPSLabel = new QLabel( tr( "FPS" ), mySettingsBox );
89   myFPSSpinBox = new QtxDoubleSpinBox( 0.1, 100.0, 1.0, mySettingsBox );
90   myFPSSpinBox->setValue( aResourceMgr->doubleValue( "VISU", "recorder_fps", 10.0 ) );
91
92   QLabel* aQualityLabel = new QLabel( tr( "QUALITY" ), mySettingsBox );
93   myQualitySpinBox = new QtxIntSpinBox( 1, 100, 1, mySettingsBox );
94   myQualitySpinBox->setValue( aResourceMgr->integerValue( "VISU", "recorder_quality", 80 ) );
95
96   myProgressiveCheckBox = new QCheckBox( tr( "PROGRESSIVE" ), mySettingsBox );
97   myProgressiveCheckBox->setChecked( aResourceMgr->booleanValue( "VISU", "recorder_progressive", false ) );
98
99   aSettingsLayout->addWidget( aFileNameLabel, 0, 0 );
100   aSettingsLayout->addWidget( myFileNameLineEdit, 1, 0, 1, 2 );
101   //aSettingsLayout->addWidget( aFileNameButton, 1, 2 );
102   aSettingsLayout->addWidget( aRecordingModeLabel, 2, 0 );
103   aSettingsLayout->addWidget( myRecordingModeComboBox, 2, 1 );
104   aSettingsLayout->addWidget( aFPSLabel, 3, 0 );
105   aSettingsLayout->addWidget( myFPSSpinBox, 3, 1 );
106   aSettingsLayout->addWidget( aQualityLabel, 4, 0 );
107   aSettingsLayout->addWidget( myQualitySpinBox, 4, 1 );
108   aSettingsLayout->addWidget( myProgressiveCheckBox, 5, 0 );
109
110   aTopLayout->addWidget( mySettingsBox );
111
112   // Start / Close
113   QGroupBox* CommonGroup = new QGroupBox( this );
114   //CommonGroup->setColumnLayout(0, Qt::Vertical );
115   //CommonGroup->layout()->setSpacing( 0 );
116   //CommonGroup->layout()->setMargin( 0 );
117   QGridLayout* CommonGroupLayout = new QGridLayout( CommonGroup );
118   CommonGroupLayout->setAlignment( Qt::AlignTop );
119   CommonGroupLayout->setSpacing( 6 );
120   CommonGroupLayout->setMargin( 11 );
121
122   QPushButton* aStartButton = new QPushButton( tr( "START" ), CommonGroup );
123   aStartButton->setAutoDefault( true );
124   aStartButton->setDefault( true );
125   CommonGroupLayout->addWidget( aStartButton, 0, 0 );
126   CommonGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
127
128   QPushButton* aCloseButton = new QPushButton( tr( "CLOSE" ), CommonGroup );
129   aCloseButton->setAutoDefault( true );
130   CommonGroupLayout->addWidget( aCloseButton, 0, 2 );
131
132   QPushButton* aHelpButton = new QPushButton( tr( "HELP" ), CommonGroup );
133   aHelpButton->setAutoDefault( true );
134   CommonGroupLayout->addWidget( aHelpButton, 0, 3 );
135
136   aTopLayout->addWidget( CommonGroup );
137
138   connect( aStartButton, SIGNAL( clicked() ), this, SLOT( onStart() ) );
139   connect( aCloseButton, SIGNAL( clicked() ), this, SLOT( onClose() ) );
140   connect( aHelpButton,  SIGNAL( clicked() ), this, SLOT( onHelp() ) );
141 }
142
143 VVTK_RecorderDlg::~VVTK_RecorderDlg()
144 {
145 }
146
147 void VVTK_RecorderDlg::onStart()
148 {
149   if( myFileName.isNull() )
150     return;
151
152   myRecorder->SetName( (const char*)myFileName.toLatin1() );
153
154   myRecorder->SetUseSkippedFrames( myRecordingModeComboBox->currentIndex() == 0 );
155   myRecorder->SetNbFPS( myFPSSpinBox->value() );
156   myRecorder->SetQuality( myQualitySpinBox->value() );
157   myRecorder->SetProgressiveMode( myProgressiveCheckBox->isChecked() );
158
159   accept();
160
161 }
162
163 void VVTK_RecorderDlg::onClose()
164 {
165   reject();
166 }
167
168 void VVTK_RecorderDlg::onHelp()
169 {
170   QString aHelpFileName = "animation_in_gauss_viewer.htm";
171   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
172   if (app)
173     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
174   else {
175                 QString platform;
176 #ifdef WIN32
177                 platform = "winapplication";
178 #else
179                 platform = "application";
180 #endif
181     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
182                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
183                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
184   }
185 }
186
187 bool VVTK_RecorderDlg::onBrowseFile()
188 {
189   QString aRootDir = QString( getenv( "VISU_ROOT_DIR") );
190
191   QStringList aFilter;
192   aFilter.append( tr( "FLT_AVI_FILES" ) );
193   aFilter.append( tr( "FLT_ALL_FILES" ) );
194
195   QString aFileName = SUIT_FileDlg::getFileName( this, getenv( "HOME" ), aFilter,
196                                                  tr( "FILE_NAME" ), false );
197
198   if( aFileName.isNull() )
199     return false;
200
201   myFileName = aFileName;
202   myFileNameLineEdit->setText( aFileName.section( '/', -1 ) );
203
204   return true;
205 }
206
207 int VVTK_RecorderDlg::exec()
208 {
209   if( !onBrowseFile() )
210   {
211     reject();
212     return 0;
213   }
214   return QDialog::exec();
215 }
216
217 void VVTK_RecorderDlg::keyPressEvent( QKeyEvent* e )
218 {
219   QDialog::keyPressEvent( e );
220   if ( e->isAccepted() )
221     return;
222
223   if ( e->key() == Qt::Key_F1 )
224     {
225       e->accept();
226       onHelp();
227     }
228 }