From adc11cbe30d981a17183c5ac49300594c5ff3be4 Mon Sep 17 00:00:00 2001 From: isn Date: Tue, 14 Nov 2017 20:05:27 +0300 Subject: [PATCH] dump view to PS format (draft) --- src/GraphicsView/GraphicsView_ViewFrame.cxx | 9 ++++++ src/GraphicsView/GraphicsView_ViewFrame.h | 1 + src/GraphicsView/GraphicsView_ViewPort.cxx | 14 +++++++++ src/GraphicsView/GraphicsView_ViewPort.h | 2 ++ src/SUIT/SUIT_ViewWindow.cxx | 32 ++++++++++++++++----- src/SUIT/SUIT_ViewWindow.h | 3 +- src/SUIT/resources/SUIT_msg_en.ts | 4 +++ 7 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index ea7a4a912..c5f1dfaad 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -211,6 +211,15 @@ QImage GraphicsView_ViewFrame::dumpView() return myViewPort->dumpView(); } +//================================================================ +// Function : dumpViewToPSFormat +// Purpose : +//================================================================ +bool GraphicsView_ViewFrame::dumpViewToPSFormat(const QString& fileName) +{ + return myViewPort->dumpViewToPSFormat(fileName); +} + //================================================================ // Function : getVisualParameters // Purpose : diff --git a/src/GraphicsView/GraphicsView_ViewFrame.h b/src/GraphicsView/GraphicsView_ViewFrame.h index 537c81052..ce7d386d0 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.h +++ b/src/GraphicsView/GraphicsView_ViewFrame.h @@ -55,6 +55,7 @@ public: GraphicsView_ViewPort* getViewPort() const { return myViewPort; } virtual QImage dumpView(); + virtual bool dumpViewToPSFormat(const QString& fileName); virtual QString getVisualParameters(); virtual void setVisualParameters( const QString& theParameters ); diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index dac64f7ce..de9a19d9e 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include @@ -457,6 +459,18 @@ QImage GraphicsView_ViewPort::dumpView( bool theWholeScene, return anImage; } +bool GraphicsView_ViewPort::dumpViewToPSFormat(const QString& fileName) +{ + QPrinter printer(QPrinter::HighResolution); + printer.setOutputFileName(fileName); + QPainter painter; + if (!painter.begin(&printer)) + return false; + myScene->render(&painter); + if (!painter.end()) + return false;; +} + //================================================================ // Function : setSceneGap // Purpose : diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 4b5acfc2e..f6b440bc0 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -93,6 +93,8 @@ public: QImage dumpView( bool theWholeScene = false, QSizeF theSize = QSizeF() ); + bool dumpViewToPSFormat(const QString& fileName); + public: // scene void setSceneGap( double theSceneGap ); diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index 6bc8af07c..e8beaf491 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -93,6 +93,11 @@ QImage SUIT_ViewWindow::dumpView() return QImage(); } +bool SUIT_ViewWindow::dumpViewToPSFormat(const QString& fileName) +{ + return false; +} + /*! Saves image to file according to the format \param image - image @@ -171,9 +176,16 @@ void SUIT_ViewWindow::onDumpView() /*! \return filters for image files */ -QString SUIT_ViewWindow::filter() const +QString SUIT_ViewWindow::filter(bool includePS) const { - return tr( "TLT_IMAGE_FILES" ); + QString aFilter = tr( "TLT_IMAGE_FILES" ); + if (!includePS) + return aFilter; + else + { + aFilter+=";;"+tr( "POSTSCRIPT_FILES" ); + return aFilter; + } } /*! Reaction view window on event \a e. @@ -187,13 +199,19 @@ bool SUIT_ViewWindow::event( QEvent* e ) { // get file name SUIT_Application* app = myManager->study()->application(); - QString fileName = app->getFileName( false, QString(), filter(), tr( "TLT_DUMP_VIEW" ), 0 ); + bool IncludePs = true; //TODO for oscar only + QString fileName = app->getFileName( false, QString(), filter(IncludePs), tr( "TLT_DUMP_VIEW" ), 0 ); if ( !fileName.isEmpty() ) { - QImage im = dumpView(); - QString fmt = SUIT_Tools::extension( fileName ).toUpper(); - Qtx::Localizer loc; - bOk = dumpViewToFormat( im, fileName, fmt ); + QString fmt = SUIT_Tools::extension( fileName ).toUpper(); + if (fmt == "PS" || fmt == "EPS" ) + bOk = dumpViewToPSFormat(fileName); + else + { + QImage im = dumpView(); + Qtx::Localizer loc; + bOk = dumpViewToFormat( im, fileName, fmt ); + } } else bOk = true; // cancelled diff --git a/src/SUIT/SUIT_ViewWindow.h b/src/SUIT/SUIT_ViewWindow.h index fd717f617..3e49587ab 100755 --- a/src/SUIT/SUIT_ViewWindow.h +++ b/src/SUIT/SUIT_ViewWindow.h @@ -53,6 +53,7 @@ public: bool event(QEvent*); virtual QImage dumpView(); + virtual bool dumpViewToPSFormat(const QString& fileName); bool dumpViewToFormat( const QString& fileName, const QString& format ); bool onAccelAction( int ); @@ -93,7 +94,7 @@ signals: protected: void closeEvent( QCloseEvent* ); virtual void contextMenuEvent( QContextMenuEvent* ); - virtual QString filter() const; + virtual QString filter(bool includePS = false) const; virtual bool action( const int ); virtual bool dumpViewToFormat( const QImage&, const QString& fileName, const QString& format ); diff --git a/src/SUIT/resources/SUIT_msg_en.ts b/src/SUIT/resources/SUIT_msg_en.ts index 31bbc382a..6f7991d98 100644 --- a/src/SUIT/resources/SUIT_msg_en.ts +++ b/src/SUIT/resources/SUIT_msg_en.ts @@ -15,6 +15,10 @@ TLT_IMAGE_FILES Images Files (*.bmp *.png *.jpg *.jpeg) + + POSTSCRIPT_FILES + PostScript files (*.ps *.eps) + MEN_DESK_WINDOW_CASCADE &Cascade -- 2.39.2