]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
0021312: EDF 1900 GEOM: Background picture in OCC viewer. A patch by Renaud Nedelec.
authorjfa <jfa@opencascade.com>
Wed, 6 Jul 2011 10:47:50 +0000 (10:47 +0000)
committerjfa <jfa@opencascade.com>
Wed, 6 Jul 2011 10:47:50 +0000 (10:47 +0000)
src/OCCViewer/OCCViewer_ViewFrame.cxx
src/OCCViewer/OCCViewer_ViewFrame.h
src/OCCViewer/OCCViewer_ViewModel.cxx
src/OCCViewer/OCCViewer_ViewModel.h
src/OCCViewer/OCCViewer_ViewPort3d.cxx
src/OCCViewer/OCCViewer_ViewPort3d.h
src/OCCViewer/OCCViewer_ViewWindow.cxx
src/OCCViewer/OCCViewer_ViewWindow.h
src/OCCViewer/resources/OCCViewer_msg_en.ts
src/OCCViewer/resources/OCCViewer_msg_fr.ts

index 34e8255c2cde68926582391640ba4df4c3a6df94..3e7919e65ea27036abfbe7b0758447fdd6e953b0 100644 (file)
@@ -213,6 +213,17 @@ void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor)
   }
 }
 
+void OCCViewer_ViewFrame::setBackgroundImage( const QString& theFilename,const Aspect_FillMethod& theFillMethod)
+{
+  if (myPopupRequestedView)
+    myPopupRequestedView->setBackgroundImage(theFilename,theFillMethod); 
+  else {
+    foreach (OCCViewer_ViewWindow* aView, myViews) {
+      if (aView->isVisible())
+        aView->setBackgroundImage(theFilename,theFillMethod); 
+    }
+  }
+}
 
 void OCCViewer_ViewFrame::onViewFitAll()
 {
@@ -240,6 +251,18 @@ QColor OCCViewer_ViewFrame::backgroundColor() const
   return getView(MAIN_VIEW)->backgroundColor(); 
 }
 
+QString OCCViewer_ViewFrame::backgroundImageFilename() const 
+{ 
+  if (myPopupRequestedView)
+    return myPopupRequestedView->backgroundImageFilename(); 
+
+  foreach (OCCViewer_ViewWindow* aView, myViews) {
+    if (aView->isVisible())
+      return aView->backgroundImageFilename(); 
+  }
+  return getView(MAIN_VIEW)->backgroundImageFilename(); 
+}
+
 void OCCViewer_ViewFrame::onContextMenuRequested(QContextMenuEvent*)
 {
   myPopupRequestedView = dynamic_cast<OCCViewer_ViewWindow*>(sender());
index b7f43c980f52a5fbecc2cf73b96458ee8af1ba69..4297bcdb3ac3e0323fd7ed6980dbb7efdb325a69 100644 (file)
@@ -77,6 +77,9 @@ public:
   virtual QColor backgroundColor() const;
   virtual void   setBackgroundColor( const QColor& );
 
+  virtual QString backgroundImageFilename() const;
+  virtual void   setBackgroundImage( const QString& theFilename , const Aspect_FillMethod& theFillMethod);
+  
   virtual void   setDropDownButtons( bool );
 
 public slots:
index 4b5783e78cc504e4bc4e123d27045a1f80e29bce..35c81ac3f2f6e6649faecd543d93aa6891ae2407 100755 (executable)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #include "OCCViewer_ViewModel.h"
 #include "OCCViewer_ViewWindow.h"
@@ -36,6 +35,7 @@
 #include <QPainter>
 #include <QApplication>
 #include <QColorDialog>
+#include <QFileDialog>
 #include <QPalette>
 #include <QKeyEvent>
 #include <QMenu>
@@ -410,6 +410,10 @@ void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
 {
   thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
   thePopup->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
+  QMenu * changeImageMenu=thePopup->addMenu( tr( "MEN_CHANGE_IMAGE" ));
+  changeImageMenu->addAction( tr( "CENTERED") , this, SLOT( onChangeBgImageCentered() ) );
+  changeImageMenu->addAction( tr( "TILED") , this, SLOT( onChangeBgImageTiled() ) );
+  changeImageMenu->addAction( tr( "STRETCHED") , this, SLOT( onChangeBgImageStretched() ) );
 
   thePopup->addSeparator();
 
@@ -442,11 +446,53 @@ void OCCViewer_Viewer::onChangeBgColor()
   OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
   if ( !aView )
     return;
+  
   QColor selColor = QColorDialog::getColor( aView->backgroundColor(), aView );
   if ( selColor.isValid() )
     aView->setBackgroundColor(selColor);
 }
 
+/*!
+  SLOT: called if background image is to be changed changed, passes new image to view port in centered mode
+*/
+void OCCViewer_Viewer::onChangeBgImageCentered()
+{
+  OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
+  if ( !aView )
+    return;
+  
+  QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_BG_IMAGE_FILES"));
+  if ( ! selFile.isEmpty() )
+    aView->setBackgroundImage(selFile,Aspect_FM_CENTERED);
+}
+
+/*!
+  SLOT: called if background image is to be changed changed, passes new image to view port in tiled mode
+*/
+void OCCViewer_Viewer::onChangeBgImageTiled()
+{
+  OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
+  if ( !aView )
+    return;
+  
+  QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_BG_IMAGE_FILES"));
+  if ( ! selFile.isEmpty() )
+    aView->setBackgroundImage(selFile,Aspect_FM_TILED);
+}
+
+/*!
+  SLOT: called if background image is to be changed changed, passes new image to view port in stretched mode
+*/
+void OCCViewer_Viewer::onChangeBgImageStretched()
+{
+  OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
+  if ( !aView )
+    return;
+  
+  QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_BG_IMAGE_FILES"));
+  if ( ! selFile.isEmpty() )
+    aView->setBackgroundImage(selFile,Aspect_FM_STRETCH);
+}
 /*!
   Updates OCC 3D viewer
 */
index e298f158b497c549bc2476fbd41932c8c7d1dbf7..4e27361eedca8434a0a65fc53d06b86f6478efc8 100755 (executable)
@@ -141,6 +141,9 @@ protected slots:
 
   void onDumpView();
   void onChangeBgColor();
+  void onChangeBgImageCentered();
+  void onChangeBgImageTiled();
+  void onChangeBgImageStretched();
 
 private:
   Handle(V3d_Viewer)              myV3dViewer;
index fe35effda7890d5badc1ce37c4130cf452a7fbd7..7a594835653c69680f56387687a77d6c392db0ed 100755 (executable)
@@ -29,6 +29,7 @@
 #include <SUIT_ViewManager.h>
 
 #include <QColor>
+#include <QString>
 #include <QRect>
 #include <QPaintEvent>
 #include <QResizeEvent>
@@ -68,7 +69,8 @@ OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_V
     myDegenerated( true ),
     myAnimate( false ),
     myBusy( true ),
-    myIsAdvancedZoomingEnabled( false )
+    myIsAdvancedZoomingEnabled( false ),
+    myBackgroundImageFilename( "" )
 {
   // VSR: 01/07/2010 commented to avoid SIGSEGV at SALOME exit
   //selectVisualId();
@@ -288,6 +290,25 @@ void OCCViewer_ViewPort3d::setBackgroundColor( const QColor& color )
   }
 }
 
+/*!
+  Returns the background image fileName[ virtual public ]
+*/
+QString OCCViewer_ViewPort3d::backgroundImageFilename() const
+{
+  return myBackgroundImageFilename;
+}
+
+/*!
+  Sets the background image [ virtual public ]
+*/
+void OCCViewer_ViewPort3d::setBackgroundImage( const QString& fileName,const Aspect_FillMethod& theFillMethod)
+{ 
+  myBackgroundImageFilename=fileName;
+  if ( !activeView().IsNull() ) {
+    activeView()->SetBackgroundImage( (Standard_CString)fileName.toLatin1().constData(),theFillMethod,true);
+  }
+}
+
 /*!
   Set animation mode
   \param theDegenerated - degenerated mode
index 693262d9031381f3a1dd4a2e60a76242b72855b7..7eccb6c43cd396ca5ca3bc281c08868fb41dab0a 100755 (executable)
@@ -28,6 +28,7 @@
 #include <V3d_View.hxx>
 
 class QColor;
+class QString;
 class QRect;
 
 class Handle(V3d_Viewer);
@@ -56,6 +57,9 @@ public:
   virtual void          setBackgroundColor( const QColor& color);
   virtual QColor        backgroundColor() const;
 
+  virtual QString       backgroundImageFilename() const;
+  virtual void          setBackgroundImage( const QString& fileName , const Aspect_FillMethod& theFillMethod);
+
 //   void         setActive( V3d_TypeOfView );
   virtual bool syncronize( const OCCViewer_ViewPort3d* );
 
@@ -106,6 +110,7 @@ private:
   bool                  myBusy;
   double                myScale;
   bool                  myIsAdvancedZoomingEnabled;
+  QString               myBackgroundImageFilename;
 };
 
 #ifdef WIN32
index 3f93fe4e5f3ec4dd2ae3aa187f92f83a349524c3..c7746c51dd1bd3266a3694277e4add2823a70645 100755 (executable)
@@ -2384,6 +2384,16 @@ void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor)
   if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
 }
 
+QString OCCViewer_ViewWindow::backgroundImageFilename() const
+{
+  return myViewPort ? myViewPort->backgroundImageFilename() : "";
+}
+   
+void OCCViewer_ViewWindow::setBackgroundImage( const QString& theFileName,const Aspect_FillMethod& theFillMethod)
+{
+  if ( myViewPort ) myViewPort->setBackgroundImage( theFileName ,theFillMethod);
+}
+
 /*!
   Clears view aspects
 */
index df82bd33be06fb22be724f8c3bc68f0735e2fac4..7d6afb508b06e714e136b8b333bcc1f8dcd42bb0 100755 (executable)
@@ -181,6 +181,9 @@ public:
   virtual QColor  backgroundColor() const;
   virtual void    setBackgroundColor( const QColor& );
 
+  virtual QString backgroundImageFilename() const;
+  virtual void    setBackgroundImage( const QString& ,const Aspect_FillMethod& theFillMethod);
+  
   virtual const viewAspectList&   getViewAspects();
   virtual void                    appendViewAspect( const viewAspect& );
   virtual void                    updateViewAspects( const viewAspectList& );
index 662a5d640de81120d9b2975ab5689b1d8af6244b..6b065ead4b9f6b1dd063a34b23bf7dec89aa3a64 100644 (file)
         <source>OCC_IMAGE_FILES</source>
         <translation>Images Files (*.bmp *.png *.jpg *.jpeg)</translation>
     </message>
+    <message>
+        <source>OCC_BG_IMAGE_FILES</source>
+        <translation>Images Files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)</translation>
+    </message>
     <message>
         <source>DSC_MAXIMIZE_VIEW</source>
         <translation>Maximize view</translation>
         <source>MEN_CHANGE_BACKGROUD</source>
         <translation>Change Background...</translation>
     </message>
+    <message>
+        <source>MEN_CHANGE_IMAGE</source>
+        <translation>Set/Change Background Image...</translation>
+    </message>
+    <message>
+        <source>SELECT_IMAGE</source>
+        <translation>Select image...</translation>
+    </message>
+    <message>
+        <source>CENTERED</source>
+        <translation>in centered mode</translation>
+    </message>
+    <message>
+        <source>TILED</source>
+        <translation>in tiled mode</translation>
+    </message>
+    <message>
+        <source>STRETCHED</source>
+        <translation>in stretched mode</translation>
+    </message>
 </context>
 <context>
     <name>OCCViewer_AxialScaleDlg</name>
index e8a7173e3f730c742a7d55f68e3bb2fb1422a22f..00ce5c0d0e428b4c3ca0c682678ab25f05892898 100755 (executable)
         <source>MEN_CHANGE_BACKGROUD</source>
         <translation>Changer l&apos;arrière-plan</translation>
     </message>
+    <message>
+        <source>MEN_CHANGE_IMAGE</source>
+       <translation>Régler/Changer l'&apos;image d&apos;arrière-plan...</translation>
+    </message>
+    <message>
+        <source>SELECT_IMAGE</source>
+        <translation>Sélectionner l&apos;image</translation>
+    </message>
+    <message>
+        <source>CENTERED</source>
+        <translation>en mode centré</translation>
+    </message>
+    <message>
+        <source>TILED</source>
+        <translation>en mode pavé</translation>
+    </message>
+    <message>
+        <source>STRETCHED</source>
+        <translation>en mode étiré</translation>
+    </message>
 </context>
 <context>
     <name>OCCViewer_AxialScaleDlg</name>