]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
PAL10870 - to improve export of Plot2d to PostScript
authorasl <asl@opencascade.com>
Thu, 15 Dec 2005 09:55:40 +0000 (09:55 +0000)
committerasl <asl@opencascade.com>
Thu, 15 Dec 2005 09:55:40 +0000 (09:55 +0000)
src/OCCViewer/OCCViewer_ViewWindow.cxx
src/Plot2d/Plot2d_ViewFrame.cxx
src/Plot2d/Plot2d_ViewFrame.h
src/Plot2d/Plot2d_ViewWindow.cxx
src/Plot2d/Plot2d_ViewWindow.h
src/SUIT/SUIT_ViewWindow.cxx
src/SUIT/SUIT_ViewWindow.h
src/SVTK/SVTK_ViewWindow.cxx
src/VTKViewer/VTKViewer_ViewWindow.cxx

index ed907ed61996b8ee84641359be71fff7f3ed82d7..846a6bcf3ae7c67a8398c0fe075c837b6dd34490 100755 (executable)
@@ -40,6 +40,7 @@
 #include <qpainter.h>
 #include <qapplication.h>
 #include <qdatetime.h>
+#include <qimage.h>
 
 const char* imageZoomCursor[] = { 
 "32 32 3 1",
index 4ef5df821af25b81bbba36c751372a0548d5e9cd..295aff062f9d40c70cf9fac81550d3f961a6da86 100755 (executable)
 #include <qptrlist.h>
 #include <qlayout.h>
 #include <qmap.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
 
 #include <qwt_math.h>
 #include <qwt_plot_canvas.h>
 #include <iostream>
 #include <stdlib.h>
+#include <qprinter.h>
 
 #include <qwt_legend.h>
 
@@ -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
+}
index 3629ed1ca89f2ad000e5c476b2bdde4e029e0695..a52d6d8f237ecc3a37baa639b2b315666d48b55c 100755 (executable)
@@ -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();
index 95b49ab033cfc65acfc3eb32861604b58b8bcdba..447ec7dad192cae4d4bbdad14152c60718ca6d35 100755 (executable)
@@ -34,6 +34,7 @@
 #include <qlayout.h>
 #include <qapplication.h>
 #include <qpopupmenu.h>
+#include <qimage.h>
 
 //////////////////////////////////////////////////////////////////////
 // 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" );
+}
index 16012d4b7b42c01366c65a9937fc2ad7e71ab09d..571d692bf599445df6813cd2ad43dbfbef7be8a3 100755 (executable)
@@ -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);
index 800bfa73a349be9902e56493c1a485d62daaee29..bd4c32e69b7c278483c1b5d2caea1588637e1dfd 100755 (executable)
 #include "SUIT_ViewManager.h"
 #include "SUIT_Tools.h"
 #include "SUIT_MessageBox.h"
-#include "qhbox.h"
-#include "qpopupmenu.h"
-#include "qapplication.h"
+#include <qhbox.h>
+#include <qpopupmenu.h>
+#include <qapplication.h>
+#include <qimage.h>
 
 /*!\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 ) {
index ff6defde24506adfa5fd4308c278dfbe40a151cb..1ac79a504d8472736c7a33d68088b6ff34d23db4 100755 (executable)
 #include "SUIT.h"
 
 #include <qmainwindow.h>
-#include <qimage.h>
 
 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;
index 98f9ce28ddf2d304ac893fbbf2440a27700f8ac5..cbe8d968c528088a43d9f5ed0331bf7732dc8425 100755 (executable)
@@ -19,6 +19,7 @@
 #include "SALOME_Actor.h"
 
 #include <qapplication.h>
+#include <qimage.h>
 
 #include <vtkTextProperty.h>
 #include <vtkActorCollection.h>
index 6c04f3237d3bbb1f2bf9652356b84046b3140cc0..d4500095a314523e6bee492b6484f8b5280d5e92 100755 (executable)
@@ -33,6 +33,7 @@
 #include "SUIT_ResourceMgr.h"
 
 #include <qapplication.h>
+#include <qimage.h>
 
 #include <vtkRenderer.h>
 #include <vtkCamera.h>