From df0f131041a03626e50419d8f4b1188c87479cb2 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 15 Dec 2005 09:55:40 +0000 Subject: [PATCH] PAL10870 - to improve export of Plot2d to PostScript --- src/OCCViewer/OCCViewer_ViewWindow.cxx | 1 + src/Plot2d/Plot2d_ViewFrame.cxx | 34 +++++++++++ src/Plot2d/Plot2d_ViewFrame.h | 2 + src/Plot2d/Plot2d_ViewWindow.cxx | 15 +++++ src/Plot2d/Plot2d_ViewWindow.h | 4 +- src/SUIT/SUIT_ViewWindow.cxx | 78 +++++++++++++++++++------- src/SUIT/SUIT_ViewWindow.h | 34 +++++------ src/SVTK/SVTK_ViewWindow.cxx | 1 + src/VTKViewer/VTKViewer_ViewWindow.cxx | 1 + 9 files changed, 132 insertions(+), 38 deletions(-) diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index ed907ed61..846a6bcf3 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -40,6 +40,7 @@ #include #include #include +#include const char* imageZoomCursor[] = { "32 32 3 1", diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 4ef5df821..295aff062 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -38,11 +38,14 @@ #include #include #include +#include +#include #include #include #include #include +#include #include @@ -1835,3 +1838,34 @@ void Plot2d_ViewFrame::updateTitles() setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, true ); setTitle( true, aTables.join("; "), MainTitle, true ); } + +bool Plot2d_ViewFrame::print( const QString& file, const QString& format ) const +{ +#ifdef WIN32 + return false; + +#else + bool res = false; + if( myPlot ) + { + QPaintDevice* pd = 0; + if( format=="PS" ) + { + QPrinter* pr = new QPrinter( QPrinter::HighResolution ); + pr->setPageSize( QPrinter::A4 ); + pr->setOutputToFile( true ); + pr->setOutputFileName( file ); + pr->setPrintProgram( "" ); + pd = pr; + } + + if( pd ) + { + myPlot->print( *pd ); + res = true; + delete pd; + } + } + return res; +#endif +} diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 3629ed1ca..a52d6d8f2 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -110,6 +110,8 @@ public: bool isModeVerLinear(); bool isLegendShow() { return myShowLegend; }; + virtual bool print( const QString& file, const QString& format ) const; + protected: int testOperation( const QMouseEvent& ); void readPreferences(); diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx index 95b49ab03..447ec7dad 100755 --- a/src/Plot2d/Plot2d_ViewWindow.cxx +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -34,6 +34,7 @@ #include #include #include +#include ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -457,3 +458,17 @@ QImage Plot2d_ViewWindow::dumpView() QPixmap px = QPixmap::grabWindow( myViewFrame->winId() ); return px.convertToImage(); } + +bool Plot2d_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& format ) +{ + bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false; + if( !res ) + res = SUIT_ViewWindow::dumpViewToFormat( fileName, format ); + + return res; +} + +QString Plot2d_ViewWindow::filter() const +{ + return SUIT_ViewWindow::filter() + ";;" + tr( "POSTSCRIPT_FILES" ); +} diff --git a/src/Plot2d/Plot2d_ViewWindow.h b/src/Plot2d/Plot2d_ViewWindow.h index 16012d4b7..571d692bf 100755 --- a/src/Plot2d/Plot2d_ViewWindow.h +++ b/src/Plot2d/Plot2d_ViewWindow.h @@ -47,7 +47,9 @@ public: void contextMenuPopup( QPopupMenu* thePopup ); protected: - QImage dumpView(); + virtual QImage dumpView(); + virtual QString filter() const; + virtual bool dumpViewToFormat( const QString& fileName, const QString& format ); private: bool eventFilter(QObject* watched, QEvent* e); diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index 800bfa73a..bd4c32e69 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -27,9 +27,10 @@ #include "SUIT_ViewManager.h" #include "SUIT_Tools.h" #include "SUIT_MessageBox.h" -#include "qhbox.h" -#include "qpopupmenu.h" -#include "qapplication.h" +#include +#include +#include +#include /*!\class SUIT_ViewWindow * Class provide view window. @@ -53,6 +54,39 @@ SUIT_ViewWindow::~SUIT_ViewWindow() { } +void SUIT_ViewWindow::setViewManager( SUIT_ViewManager* theManager ) +{ + myManager = theManager; +} + +SUIT_ViewManager* SUIT_ViewWindow::getViewManager() const +{ + return myManager; +} + +QImage SUIT_ViewWindow::dumpView() +{ + return QImage(); +} + +bool SUIT_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& format ) +{ + QImage img = dumpView(); + if( img.isNull() ) + return false; + + QString fmt = format; + if( fmt.isEmpty() ) + fmt = QString( "BMP" ); // default format + else if( fmt == "JPG" ) + fmt = "JPEG"; + + QApplication::setOverrideCursor( Qt::waitCursor ); + bool res = img.save( fileName, fmt.latin1() ); + QApplication::restoreOverrideCursor(); + return res; +} + /*! Close event \a theEvent. */ void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent) @@ -77,29 +111,31 @@ void SUIT_ViewWindow::onDumpView() qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) ); } +QString SUIT_ViewWindow::filter() const +{ + return tr( "TLT_IMAGE_FILES" ); +} + /*! Reaction view window on event \a e. */ bool SUIT_ViewWindow::event( QEvent* e ) { - if ( e->type() == DUMP_EVENT ) { + 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.isEmpty() ) { - 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 ( myManager && myManager->study() && myManager->study()->application() ) + { + // get file name + SUIT_Application* app = myManager->study()->application(); + QString fileName = app->getFileName( false, QString::null, filter(), tr( "TLT_DUMP_VIEW" ), 0 ); + if( !fileName.isEmpty() ) + { + QString fmt = SUIT_Tools::extension( fileName ).upper(); + bOk = dumpViewToFormat( fileName, fmt ); + } + else + { + bOk = true; // cancelled } } if ( !bOk ) { diff --git a/src/SUIT/SUIT_ViewWindow.h b/src/SUIT/SUIT_ViewWindow.h index ff6defde2..1ac79a504 100755 --- a/src/SUIT/SUIT_ViewWindow.h +++ b/src/SUIT/SUIT_ViewWindow.h @@ -30,44 +30,46 @@ #include "SUIT.h" #include -#include class SUIT_Desktop; class SUIT_ViewManager; +class QImage; class SUIT_EXPORT SUIT_ViewWindow: public QMainWindow { Q_OBJECT public: - SUIT_ViewWindow(SUIT_Desktop* theDesktop); + SUIT_ViewWindow( SUIT_Desktop* ); virtual ~SUIT_ViewWindow(); - void setViewManager(SUIT_ViewManager* theManager) { myManager = theManager;} - SUIT_ViewManager* getViewManager() const { return myManager; } + void setViewManager( SUIT_ViewManager* ); + SUIT_ViewManager* getViewManager() const; bool event(QEvent*); - virtual QImage dumpView() { return QImage(); } + virtual QImage dumpView(); + virtual bool dumpViewToFormat( const QString& fileName, const QString& format ); + void onAccelAction( int ); public slots: virtual void onDumpView(); signals: - void closing(SUIT_ViewWindow*); - void mousePressed(SUIT_ViewWindow*, QMouseEvent*); - void mouseReleased(SUIT_ViewWindow*, QMouseEvent*); - void mouseDoubleClicked(SUIT_ViewWindow*, QMouseEvent*); - void mouseMoving(SUIT_ViewWindow*, QMouseEvent*); - void wheeling(SUIT_ViewWindow*, QWheelEvent*); - void keyPressed(SUIT_ViewWindow*, QKeyEvent*); - void keyReleased(SUIT_ViewWindow*, QKeyEvent*); + void closing( SUIT_ViewWindow* ); + void mousePressed( SUIT_ViewWindow*, QMouseEvent* ); + void mouseReleased( SUIT_ViewWindow*, QMouseEvent* ); + void mouseDoubleClicked( SUIT_ViewWindow*, QMouseEvent* ); + void mouseMoving( SUIT_ViewWindow*, QMouseEvent* ); + void wheeling( SUIT_ViewWindow*, QWheelEvent* ); + void keyPressed( SUIT_ViewWindow*, QKeyEvent* ); + void keyReleased( SUIT_ViewWindow*, QKeyEvent* ); void contextMenuRequested( QContextMenuEvent *e ); protected: - void closeEvent(QCloseEvent* theEvent); - virtual void contextMenuEvent( QContextMenuEvent * e ); - + void closeEvent( QCloseEvent* ); + virtual void contextMenuEvent( QContextMenuEvent* ); + virtual QString filter() const; virtual void action( const int ); SUIT_Desktop* myDesktop; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 98f9ce28d..cbe8d968c 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -19,6 +19,7 @@ #include "SALOME_Actor.h" #include +#include #include #include diff --git a/src/VTKViewer/VTKViewer_ViewWindow.cxx b/src/VTKViewer/VTKViewer_ViewWindow.cxx index 6c04f3237..d4500095a 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.cxx +++ b/src/VTKViewer/VTKViewer_ViewWindow.cxx @@ -33,6 +33,7 @@ #include "SUIT_ResourceMgr.h" #include +#include #include #include -- 2.39.2