From 5a5df777127557c6fd336473de734947549b29c6 Mon Sep 17 00:00:00 2001 From: jfa Date: Wed, 6 Jul 2011 10:47:50 +0000 Subject: [PATCH] 0021312: EDF 1900 GEOM: Background picture in OCC viewer. A patch by Renaud Nedelec. --- src/OCCViewer/OCCViewer_ViewFrame.cxx | 23 ++++++++++ src/OCCViewer/OCCViewer_ViewFrame.h | 3 ++ src/OCCViewer/OCCViewer_ViewModel.cxx | 48 ++++++++++++++++++++- src/OCCViewer/OCCViewer_ViewModel.h | 3 ++ src/OCCViewer/OCCViewer_ViewPort3d.cxx | 23 +++++++++- src/OCCViewer/OCCViewer_ViewPort3d.h | 5 +++ src/OCCViewer/OCCViewer_ViewWindow.cxx | 10 +++++ src/OCCViewer/OCCViewer_ViewWindow.h | 3 ++ src/OCCViewer/resources/OCCViewer_msg_en.ts | 24 +++++++++++ src/OCCViewer/resources/OCCViewer_msg_fr.ts | 20 +++++++++ 10 files changed, 160 insertions(+), 2 deletions(-) diff --git a/src/OCCViewer/OCCViewer_ViewFrame.cxx b/src/OCCViewer/OCCViewer_ViewFrame.cxx index 34e8255c2..3e7919e65 100644 --- a/src/OCCViewer/OCCViewer_ViewFrame.cxx +++ b/src/OCCViewer/OCCViewer_ViewFrame.cxx @@ -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(sender()); diff --git a/src/OCCViewer/OCCViewer_ViewFrame.h b/src/OCCViewer/OCCViewer_ViewFrame.h index b7f43c980..4297bcdb3 100644 --- a/src/OCCViewer/OCCViewer_ViewFrame.h +++ b/src/OCCViewer/OCCViewer_ViewFrame.h @@ -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: diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 4b5783e78..35c81ac3f 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -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 #include #include +#include #include #include #include @@ -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(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(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(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(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 */ diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index e298f158b..4e27361ee 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -141,6 +141,9 @@ protected slots: void onDumpView(); void onChangeBgColor(); + void onChangeBgImageCentered(); + void onChangeBgImageTiled(); + void onChangeBgImageStretched(); private: Handle(V3d_Viewer) myV3dViewer; diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index fe35effda..7a5948356 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.h b/src/OCCViewer/OCCViewer_ViewPort3d.h index 693262d90..7eccb6c43 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.h +++ b/src/OCCViewer/OCCViewer_ViewPort3d.h @@ -28,6 +28,7 @@ #include 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 diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index 3f93fe4e5..c7746c51d 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -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 */ diff --git a/src/OCCViewer/OCCViewer_ViewWindow.h b/src/OCCViewer/OCCViewer_ViewWindow.h index df82bd33b..7d6afb508 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.h +++ b/src/OCCViewer/OCCViewer_ViewWindow.h @@ -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& ); diff --git a/src/OCCViewer/resources/OCCViewer_msg_en.ts b/src/OCCViewer/resources/OCCViewer_msg_en.ts index 662a5d640..6b065ead4 100644 --- a/src/OCCViewer/resources/OCCViewer_msg_en.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_en.ts @@ -271,6 +271,10 @@ OCC_IMAGE_FILES Images Files (*.bmp *.png *.jpg *.jpeg) + + OCC_BG_IMAGE_FILES + Images Files (*.bmp *.gif *.pix *.xwd *.rgb *.rs) + DSC_MAXIMIZE_VIEW Maximize view @@ -347,6 +351,26 @@ MEN_CHANGE_BACKGROUD Change Background... + + MEN_CHANGE_IMAGE + Set/Change Background Image... + + + SELECT_IMAGE + Select image... + + + CENTERED + in centered mode + + + TILED + in tiled mode + + + STRETCHED + in stretched mode + OCCViewer_AxialScaleDlg diff --git a/src/OCCViewer/resources/OCCViewer_msg_fr.ts b/src/OCCViewer/resources/OCCViewer_msg_fr.ts index e8a7173e3..00ce5c0d0 100755 --- a/src/OCCViewer/resources/OCCViewer_msg_fr.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_fr.ts @@ -347,6 +347,26 @@ MEN_CHANGE_BACKGROUD Changer l'arrière-plan + + MEN_CHANGE_IMAGE + Régler/Changer l''image d'arrière-plan... + + + SELECT_IMAGE + Sélectionner l'image + + + CENTERED + en mode centré + + + TILED + en mode pavé + + + STRETCHED + en mode étiré + OCCViewer_AxialScaleDlg -- 2.39.2