From 0191641222d5e776a92bb6a4577e30c8223c396d Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 20 Jun 2005 14:31:43 +0000 Subject: [PATCH] Implement generic "Dump view" method to be used by all views (toolbar & context menu) --- src/GLViewer/GLViewer_ViewFrame.cxx | 31 ++----------- src/GLViewer/GLViewer_ViewFrame.h | 4 +- src/GLViewer/GLViewer_Viewer2d.cxx | 10 ++++ src/GLViewer/GLViewer_Viewer2d.h | 1 + src/GLViewer/resources/GLViewer_msg_en.po | 2 +- src/OCCViewer/OCCViewer_ViewWindow.cxx | 37 +++------------ src/OCCViewer/OCCViewer_ViewWindow.h | 2 +- src/Plot2d/Plot2d_ViewFrame.cxx | 28 ----------- src/Plot2d/Plot2d_ViewFrame.h | 1 - src/Plot2d/Plot2d_ViewModel.cxx | 11 ++++- src/Plot2d/Plot2d_ViewModel.h | 1 + src/Plot2d/Plot2d_ViewWindow.cxx | 21 ++++++--- src/Plot2d/Plot2d_ViewWindow.h | 6 ++- src/Plot2d/resources/Plot2d_msg_en.po | 2 +- src/SUIT/SUIT_ViewWindow.cxx | 51 +++++++++++++++++++++ src/SUIT/SUIT_ViewWindow.h | 8 ++++ src/SUIT/resources/SUIT_msg_en.po | 8 ++++ src/SVTK/SVTK_ViewWindow.cxx | 37 ++++----------- src/SVTK/SVTK_ViewWindow.h | 6 ++- src/VTKViewer/VTKViewer_ViewWindow.cxx | 37 +++------------ src/VTKViewer/VTKViewer_ViewWindow.h | 4 +- src/VTKViewer/resources/VTKViewer_msg_en.po | 2 +- 22 files changed, 150 insertions(+), 160 deletions(-) diff --git a/src/GLViewer/GLViewer_ViewFrame.cxx b/src/GLViewer/GLViewer_ViewFrame.cxx index 14e2305ab..5053889bd 100644 --- a/src/GLViewer/GLViewer_ViewFrame.cxx +++ b/src/GLViewer/GLViewer_ViewFrame.cxx @@ -81,7 +81,7 @@ void GLViewer_ViewFrame::createActions() aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_DUMP" ) ), tr( "MNU_DUMP_VIEW" ), 0, this); aAction->setStatusTip(tr("DSC_DUMP_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewDump())); + connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView())); myActionsMap[ DumpId ] = aAction; // FitAll @@ -246,7 +246,7 @@ void GLViewer_ViewFrame::onUpdate( int ) { } -void GLViewer_ViewFrame::onViewDump() +QImage GLViewer_ViewFrame::dumpView() { GLViewer_Widget* aWidget = ((GLViewer_ViewPort2d*)myVP)->getGLWidget(); int width, height; @@ -383,31 +383,7 @@ void GLViewer_ViewFrame::onViewDump() } delete [] imageBits; - - SUIT_Application* app = getViewManager()->study()->application(); - - QString aFileName = app->getFileName( false, QString::null, QString( "*.bmp;*.png" ), tr( "DUMP_VIEW_SAVE_FILE_DLG_CAPTION" ), 0 ); - - if( aFileName.isEmpty() ) // cancelled - return; - - QString aSaveOp = SUIT_Tools::extension( aFileName ).upper(); - - if ( aSaveOp != "BMP" && aSaveOp != "PNG" ) { - SUIT_MessageBox::error1( this, - tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ), - tr( "DUMP_VIEW_ERROR_UNSUPPORTED_FORMAT" ).arg( aSaveOp ), - tr( "BUT_OK" ) ); - return; - } - - if( !anImage.save( aFileName, aSaveOp ) ) - { - SUIT_MessageBox::error1( this, - tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ), - tr( "DUMP_VIEW_ERROR_DLG_TEXT" ), - tr( "BUT_OK" ) ); - } + return anImage; } void GLViewer_ViewFrame::onViewPan() @@ -509,3 +485,4 @@ void GLViewer_ViewFrame::wheelEvent( QWheelEvent* e ) break; } } + diff --git a/src/GLViewer/GLViewer_ViewFrame.h b/src/GLViewer/GLViewer_ViewFrame.h index 18d172631..9033b7020 100644 --- a/src/GLViewer/GLViewer_ViewFrame.h +++ b/src/GLViewer/GLViewer_ViewFrame.h @@ -56,12 +56,14 @@ protected: GLViewer_Viewer* myViewer; GLViewer_ViewPort* myVP; +protected: + QImage dumpView(); + public: //ViewType getTypeView() const { return VIEW_GL; }; QWidget* getViewWidget() { return ( QWidget* )getViewPort(); }; protected slots: - void onViewDump(); void onViewPan(); void onViewZoom(); void onViewFitAll(); diff --git a/src/GLViewer/GLViewer_Viewer2d.cxx b/src/GLViewer/GLViewer_Viewer2d.cxx index e80af49be..d13de15e7 100644 --- a/src/GLViewer/GLViewer_Viewer2d.cxx +++ b/src/GLViewer/GLViewer_Viewer2d.cxx @@ -57,6 +57,7 @@ void GLViewer_Viewer2d::contextMenuPopup( QPopupMenu* thePopup ) { if( thePopup->count() > 0 ) thePopup->insertSeparator(); + thePopup->insertItem( tr( "MNU_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); thePopup->insertItem( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) ); } } @@ -993,6 +994,14 @@ void GLViewer_Viewer2d::startOperations( QWheelEvent* e ) updateAll(); } +/*! + Processes "Dump view..." context popup menu command +*/ +void GLViewer_Viewer2d::onDumpView() +{ + if ( getActiveView() ) + getActiveView()->onDumpView(); +} /**************************************************************** ** Class: GLViewer_View2dTransformer @@ -1068,3 +1077,4 @@ void GLViewer_View2dTransformer::onTransform( TransformState state ) } GLViewer_ViewTransformer::onTransform( state ); } + diff --git a/src/GLViewer/GLViewer_Viewer2d.h b/src/GLViewer/GLViewer_Viewer2d.h index 982753314..9441c23ab 100644 --- a/src/GLViewer/GLViewer_Viewer2d.h +++ b/src/GLViewer/GLViewer_Viewer2d.h @@ -129,6 +129,7 @@ protected: protected slots: void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* ); + void onDumpView(); private: bool testRotation( QMouseEvent* ); diff --git a/src/GLViewer/resources/GLViewer_msg_en.po b/src/GLViewer/resources/GLViewer_msg_en.po index ca1b5e351..3b9e942be 100644 --- a/src/GLViewer/resources/GLViewer_msg_en.po +++ b/src/GLViewer/resources/GLViewer_msg_en.po @@ -60,7 +60,7 @@ msgid "DSC_DUMP_VIEW" msgstr "Saves the active view in the image file" msgid "MNU_DUMP_VIEW" -msgstr "Dump" +msgstr "Dump view..." msgid "GL_IMAGE_FILES" msgstr "Images Files (*.bmp *.png)" diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index 0cb903a56..0351deacd 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -775,36 +775,6 @@ void OCCViewer_ViewWindow::onFitAll() myViewPort->fitAll(); } -//**************************************************************** -/* - Dumps 3d-Viewer contents into image file - File format is defined by file's extension; supported formats : PNG, BMP, GIF, JPG -*/ -void OCCViewer_ViewWindow::onDumpView() -{ - QApplication::setOverrideCursor( Qt::waitCursor ); - QPixmap px = QPixmap::grabWindow(myViewPort->winId()); - QApplication::restoreOverrideCursor(); - - SUIT_Application* app = getViewManager()->study()->application(); - - QString aFileName = app->getFileName( false, QString::null, tr("OCC_IMAGE_FILES"), tr("INF_APP_DUMP_VIEW"), 0 ); - - if ( !aFileName.isNull() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - QString fmt = SUIT_Tools::extension( aFileName ).upper(); - if (fmt.isEmpty()) - fmt = QString("BMP"); // default format - if (fmt == "JPG") - fmt = "JPEG"; - bool bOk = px.save(aFileName, fmt.latin1()); - QApplication::restoreOverrideCursor(); - if (!bOk) { - SUIT_MessageBox::error1(this, tr("ERROR"), tr("ERR_DOC_CANT_SAVE_FILE"), tr("BUT_OK")); - } - } -} - //**************************************************************** void OCCViewer_ViewWindow::onCloneView() { @@ -886,3 +856,10 @@ void OCCViewer_ViewWindow::onTrihedronShow() { myModel->toggleTrihedron(); } + +//**************************************************************** +QImage OCCViewer_ViewWindow::dumpView() +{ + QPixmap px = QPixmap::grabWindow( myViewPort->winId() ); + return px.convertToImage(); +} diff --git a/src/OCCViewer/OCCViewer_ViewWindow.h b/src/OCCViewer/OCCViewer_ViewWindow.h index efac118cf..986678577 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.h +++ b/src/OCCViewer/OCCViewer_ViewWindow.h @@ -48,7 +48,6 @@ public slots: void onRightView(); void onResetView(); void onFitAll(); - void onDumpView(); void activateZoom(); void activateWindowFit(); void activateRotation(); @@ -72,6 +71,7 @@ protected: typedef QMap ActionsMap; + QImage dumpView(); /* Transformation selected but not started yet */ bool transformRequested() const { return ( myOperation != NOTHING ); } diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index a5f7abd2a..116410def 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -1462,34 +1462,6 @@ void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event) myPlot->replot(); myPnt = event->pos(); } -/*! - View operations : Dump view -*/ -void Plot2d_ViewFrame::onDump() -{ - QApplication::setOverrideCursor( Qt::waitCursor ); - QPixmap px = QPixmap::grabWindow(winId()); - QApplication::restoreOverrideCursor(); - - SUIT_Application* app = ((Plot2d_ViewWindow*)parent())->getViewManager()->study()->application(); - - QString aFileName = app->getFileName( false, QString::null, tr("PLOT2D_IMAGE_FILES"), tr("INF_APP_DUMP_VIEW"), 0 ); - - if ( !aFileName.isNull() ) - { - QApplication::setOverrideCursor( Qt::waitCursor ); - QString fmt = SUIT_Tools::extension( aFileName ).upper(); - if (fmt.isEmpty()) - fmt = QString("BMP"); // default format - if (fmt == "JPG") - fmt = "JPEG"; - bool bOk = px.save(aFileName, fmt.latin1()); - QApplication::restoreOverrideCursor(); - if (!bOk) { - SUIT_MessageBox::error1(this, tr("ERROR"), tr("ERR_DOC_CANT_SAVE_FILE"), tr("BUT_OK")); - } - } -} /*! View operations : Pan view */ diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 1c5f3037d..565f8d04e 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -94,7 +94,6 @@ protected: virtual void wheelEvent( QWheelEvent* ); public slots: - void onDump(); void onViewPan(); void onViewZoom(); void onViewFitAll(); diff --git a/src/Plot2d/Plot2d_ViewModel.cxx b/src/Plot2d/Plot2d_ViewModel.cxx index beadcac51..e5f1bf967 100755 --- a/src/Plot2d/Plot2d_ViewModel.cxx +++ b/src/Plot2d/Plot2d_ViewModel.cxx @@ -36,7 +36,8 @@ void Plot2d_Viewer::contextMenuPopup(QPopupMenu* thePopup) aView->contextMenuPopup(thePopup); if (thePopup->count() > 0) thePopup->insertSeparator(); - thePopup->insertItem("Change background...", this, SLOT(onChangeBgColor())); + thePopup->insertItem( tr( "MNU_DUMP_VIEW" ), this, SLOT(onDumpView())); + thePopup->insertItem( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor())); if ( aView ) { if ( !aView->getToolBar()->isVisible() ) { @@ -110,3 +111,11 @@ void Plot2d_Viewer::onShowToolbar() { if ( aView ) aView->getToolBar()->show(); } + +//********************************************************************* +void Plot2d_Viewer::onDumpView() +{ + Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView()); + if ( aView ) + aView->onDumpView(); +} diff --git a/src/Plot2d/Plot2d_ViewModel.h b/src/Plot2d/Plot2d_ViewModel.h index a53f16b7b..ab40293bd 100755 --- a/src/Plot2d/Plot2d_ViewModel.h +++ b/src/Plot2d/Plot2d_ViewModel.h @@ -35,6 +35,7 @@ public: protected slots: void onChangeBgColor(); + void onDumpView(); void onShowToolbar(); private: diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx index 7f7ed5ef3..6a5d512dc 100755 --- a/src/Plot2d/Plot2d_ViewWindow.cxx +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -10,6 +10,7 @@ #include #include +#include ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -341,12 +342,6 @@ void Plot2d_ViewWindow::onChangeLegendMode() myActionsMap[ LegendId ]->setOn(myViewFrame->isLegendShow()); } -//**************************************************************** -void Plot2d_ViewWindow::onDumpView() -{ - myViewFrame->onDump(); -} - //**************************************************************** void Plot2d_ViewWindow::onFitAll() { @@ -425,3 +420,17 @@ void Plot2d_ViewWindow::onCurves() myViewFrame->setCurveType(2); } } + +//**************************************************************** +void Plot2d_ViewWindow::onDumpView() +{ + qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ), TRUE ) ); + SUIT_ViewWindow::onDumpView(); +} + +//**************************************************************** +QImage Plot2d_ViewWindow::dumpView() +{ + QPixmap px = QPixmap::grabWindow( myViewFrame->winId() ); + return px.convertToImage(); +} diff --git a/src/Plot2d/Plot2d_ViewWindow.h b/src/Plot2d/Plot2d_ViewWindow.h index 9c20a5bd4..6ac6970b6 100755 --- a/src/Plot2d/Plot2d_ViewWindow.h +++ b/src/Plot2d/Plot2d_ViewWindow.h @@ -35,6 +35,9 @@ public: QToolBar* getToolBar() { return myToolBar; }; void contextMenuPopup( QPopupMenu* thePopup ); +protected: + QImage dumpView(); + private: bool eventFilter(QObject* watched, QEvent* e); @@ -47,7 +50,6 @@ public slots: void onChangeCurveMode(); void onChangeLegendMode(); - void onDumpView(); void onFitAll(); void onFitRect(); void onZoom(); @@ -58,6 +60,8 @@ public slots: void onLegend(); void onCurves(); + void onDumpView(); + signals: void cloneView(); diff --git a/src/Plot2d/resources/Plot2d_msg_en.po b/src/Plot2d/resources/Plot2d_msg_en.po index ce99101b5..45d54cf10 100755 --- a/src/Plot2d/resources/Plot2d_msg_en.po +++ b/src/Plot2d/resources/Plot2d_msg_en.po @@ -275,7 +275,7 @@ msgid "DSC_DUMP_VIEW" msgstr "Saves the active view in the image file" msgid "MNU_DUMP_VIEW" -msgstr "Dump" +msgstr "Dump view..." msgid "DSC_FITALL" msgstr "Fit all objects inside the view frame" diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index 4eb47e3ef..f7060156b 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -4,8 +4,18 @@ #include "SUIT_ViewWindow.h" #include "SUIT_Desktop.h" +#include "SUIT_Application.h" +#include "SUIT_Study.h" +#include "SUIT_ViewManager.h" +#include "SUIT_Tools.h" +#include "SUIT_MessageBox.h" #include "qhbox.h" #include "qpopupmenu.h" +#include "qapplication.h" + +// Dump view custom event +const int DUMP_EVENT = QEvent::User + 123; + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -33,3 +43,44 @@ void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e ) if ( e->reason() != QContextMenuEvent::Mouse ) emit contextMenuRequested( e ); } + +//**************************************************************** +void SUIT_ViewWindow::onDumpView() +{ + qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) ); + qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) ); +} + +//**************************************************************** +bool SUIT_ViewWindow::event( QEvent* e ) +{ + if ( e->type() == DUMP_EVENT ) { + bool bOk = false; + if ( myManager && myManager->study() && myManager->study()->application() ) { + // first create an image (this is small trick to avoid dialog box overlapping) + QImage img = dumpView(); + if ( !img.isNull() ) { + // get file name + QString fileName = myManager->study()->application()->getFileName( false, QString::null, tr( "TLT_IMAGE_FILES" ), tr( "TLT_DUMP_VIEW" ), 0 ); + if ( fileName ) { + QString fmt = SUIT_Tools::extension( fileName ).upper(); + if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format + if ( fmt == "JPG" ) fmt = "JPEG"; + QApplication::setOverrideCursor( Qt::waitCursor ); + bOk = img.save( fileName, fmt.latin1() ); + QApplication::restoreOverrideCursor(); + } + else { + bOk = true; // cancelled + } + } + } + if ( !bOk ) { + SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) ); + } + return TRUE; + } + return QMainWindow::event( e ); +} + +//**************************************************************** diff --git a/src/SUIT/SUIT_ViewWindow.h b/src/SUIT/SUIT_ViewWindow.h index 4f8525db9..115f1fc4c 100755 --- a/src/SUIT/SUIT_ViewWindow.h +++ b/src/SUIT/SUIT_ViewWindow.h @@ -12,6 +12,7 @@ #include "SUIT.h" #include +#include class SUIT_Desktop; class SUIT_ViewManager; @@ -26,6 +27,11 @@ public: void setViewManager(SUIT_ViewManager* theManager) { myManager = theManager;} SUIT_ViewManager* getViewManager() const { return myManager; } + bool event(QEvent*); + +public slots: + virtual void onDumpView(); + signals: void closing(SUIT_ViewWindow*); void mousePressed(SUIT_ViewWindow*, QMouseEvent*); @@ -41,6 +47,8 @@ protected: void closeEvent(QCloseEvent* theEvent); virtual void contextMenuEvent( QContextMenuEvent * e ); + virtual QImage dumpView() { return QImage(); } + SUIT_Desktop* myDesktop; SUIT_ViewManager* myManager; }; diff --git a/src/SUIT/resources/SUIT_msg_en.po b/src/SUIT/resources/SUIT_msg_en.po index 32d03cff3..4cedd757a 100755 --- a/src/SUIT/resources/SUIT_msg_en.po +++ b/src/SUIT/resources/SUIT_msg_en.po @@ -75,3 +75,11 @@ msgstr "Directories" msgid "QUE_FILE_EXISTS" msgstr "The file \"%1\" already exists.\nDo you want to overwrite it?" +msgid "TLT_DUMP_VIEW" +msgstr "Dump View to File" + +msgid "TLT_IMAGE_FILES" +msgstr "Images Files (*.bmp *.png *.jpg *.jpeg)"" + +msgid "ERR_CANT_DUMP_VIEW" +msgstr "Can't dump view contents to the file." \ No newline at end of file diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index dace6f30e..cd140f5fa 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -417,34 +417,6 @@ SVTK_ViewWindow Repaint(); } -//---------------------------------------------------------------------------- -void -SVTK_ViewWindow -::onDumpView() -{ - QApplication::setOverrideCursor( Qt::waitCursor ); - QPixmap px = QPixmap::grabWindow(myRenderWindow->winId()); - QApplication::restoreOverrideCursor(); - - SUIT_Application* app = getViewManager()->study()->application(); - - QString aFileName = app->getFileName( false, QString::null, tr("VTK_IMAGE_FILES"), tr("INF_APP_DUMP_VIEW"), 0 ); - - if ( !aFileName.isNull() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - QString fmt = SUIT_Tools::extension( aFileName ).upper(); - if (fmt.isEmpty()) - fmt = QString("BMP"); // default format - if (fmt == "JPG") - fmt = "JPEG"; - bool bOk = px.save(aFileName, fmt.latin1()); - QApplication::restoreOverrideCursor(); - if (!bOk) { - SUIT_MessageBox::error1(this, tr("ERROR"), tr("ERR_DOC_CANT_SAVE_FILE"), tr("BUT_OK")); - } - } -} - //---------------------------------------------------------------- void SVTK_ViewWindow @@ -898,3 +870,12 @@ SVTK_ViewWindow RemoveActor(theActor); InsertActor(theActor,true); } + +//---------------------------------------------------------------------------- +QImage +SVTK_ViewWindow +::dumpView() +{ + QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() ); + return px.convertToImage(); +} diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 3b4f4c383..a2f70efa4 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -85,7 +85,7 @@ public: public slots: void onSelectionChanged(); - signals: +signals: void selectionChanged(); public slots: @@ -98,7 +98,6 @@ public slots: void onResetView(); void onFitAll(); - void onDumpView(); void onViewTrihedron(); void onAdjustTrihedron(); @@ -120,6 +119,9 @@ public slots: void activatePanning(); void activateGlobalPanning(); +protected: + QImage dumpView(); + protected slots: void onKeyPressed(QKeyEvent* event); void onKeyReleased(QKeyEvent* event); diff --git a/src/VTKViewer/VTKViewer_ViewWindow.cxx b/src/VTKViewer/VTKViewer_ViewWindow.cxx index 014608d68..78b400430 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.cxx +++ b/src/VTKViewer/VTKViewer_ViewWindow.cxx @@ -385,36 +385,6 @@ void VTKViewer_ViewWindow::onFitAll() Repaint(); } -//**************************************************************** -/* - Dumps 3d-Viewer contents into image file - File format is defined by file's extension; supported formats : PNG, BMP, GIF, JPG -*/ -void VTKViewer_ViewWindow::onDumpView() -{ - QApplication::setOverrideCursor( Qt::waitCursor ); - QPixmap px = QPixmap::grabWindow(myRenderWindow->winId()); - QApplication::restoreOverrideCursor(); - - SUIT_Application* app = getViewManager()->study()->application(); - - QString aFileName = app->getFileName( false, QString::null, tr("VTK_IMAGE_FILES"), tr("INF_APP_DUMP_VIEW"), 0 ); - - if ( !aFileName.isNull() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); - QString fmt = SUIT_Tools::extension( aFileName ).upper(); - if (fmt.isEmpty()) - fmt = QString("BMP"); // default format - if (fmt == "JPG") - fmt = "JPEG"; - bool bOk = px.save(aFileName, fmt.latin1()); - QApplication::restoreOverrideCursor(); - if (!bOk) { - SUIT_MessageBox::error1(this, tr("ERROR"), tr("ERR_DOC_CANT_SAVE_FILE"), tr("BUT_OK")); - } - } -} - //**************************************************************** /*! Set background of the viewport @@ -566,3 +536,10 @@ void VTKViewer_ViewWindow::onTrihedronShow() myTrihedron->VisibilityOn(); myRenderWindow->update(); } + +//**************************************************************** +QImage VTKViewer_ViewWindow::dumpView() +{ + QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() ); + return px.convertToImage(); +} diff --git a/src/VTKViewer/VTKViewer_ViewWindow.h b/src/VTKViewer/VTKViewer_ViewWindow.h index a998414d7..df62ed447 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.h +++ b/src/VTKViewer/VTKViewer_ViewWindow.h @@ -57,7 +57,6 @@ public slots: void onRightView(); void onResetView(); void onFitAll(); - void onDumpView(); void activateZoom(); void activateWindowFit(); void activateRotation(); @@ -65,6 +64,9 @@ public slots: void activateGlobalPanning(); void onTrihedronShow(); +protected: + QImage dumpView(); + protected slots: void onKeyPressed(QKeyEvent* event); void onKeyReleased(QKeyEvent* event); diff --git a/src/VTKViewer/resources/VTKViewer_msg_en.po b/src/VTKViewer/resources/VTKViewer_msg_en.po index 18fe26af3..603fbb3c0 100755 --- a/src/VTKViewer/resources/VTKViewer_msg_en.po +++ b/src/VTKViewer/resources/VTKViewer_msg_en.po @@ -117,7 +117,7 @@ msgid "DSC_DUMP_VIEW" msgstr "Saves the active view in the image file" msgid "MNU_DUMP_VIEW" -msgstr "Dump" +msgstr "Dump view..." msgid "VTK_IMAGE_FILES" msgstr "Images Files (*.bmp *.png *.jpg *.jpeg)" -- 2.39.2