From: vsr Date: Wed, 15 Feb 2012 12:53:15 +0000 (+0000) Subject: 0021179: EDF 1654 SMESH GEOM: better look'n'feel X-Git-Tag: V6_5_0a1~51 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=229736a662bbf1d31f47ebe84bc21c594cc5c6e9;p=modules%2Fgui.git 0021179: EDF 1654 SMESH GEOM: better look'n'feel Introduce gradient background in the 3D viewer --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index c58875283..398306a2f 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1419,15 +1419,14 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType #else vm = new OCCViewer_Viewer( true ); #endif - vm->setBackgroundColor( OCCViewer_ViewFrame::TOP_LEFT, - resMgr->colorValue( "OCCViewer", "xz_background", vm->backgroundColor() ) ); - vm->setBackgroundColor( OCCViewer_ViewFrame::TOP_RIGHT, - resMgr->colorValue( "OCCViewer", "yz_background", vm->backgroundColor() ) ); - - vm->setBackgroundColor( OCCViewer_ViewFrame::BOTTOM_LEFT, - resMgr->colorValue( "OCCViewer", "xy_background", vm->backgroundColor() ) ); - vm->setBackgroundColor( OCCViewer_ViewFrame::BOTTOM_RIGHT, - resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) ); + vm->setBackground( OCCViewer_ViewFrame::TOP_LEFT, + resMgr->backgroundValue( "OCCViewer", "xz_background", vm->background(OCCViewer_ViewFrame::TOP_LEFT) ) ); + vm->setBackground( OCCViewer_ViewFrame::TOP_RIGHT, + resMgr->backgroundValue( "OCCViewer", "yz_background", vm->background(OCCViewer_ViewFrame::TOP_RIGHT) ) ); + vm->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT, + resMgr->backgroundValue( "OCCViewer", "xy_background", vm->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) ); + vm->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT, + resMgr->backgroundValue( "OCCViewer", "background", vm->background(OCCViewer_ViewFrame::MAIN_VIEW) ) ); vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ), resMgr->booleanValue( "OCCViewer", "relative_size", vm->trihedronRelative() )); @@ -1455,7 +1454,7 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType if( vm ) { vm->setProjectionMode( resMgr->integerValue( "VTKViewer", "projection_mode", vm->projectionMode() ) ); - vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) ); + vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) ); vm->setTrihedronSize( resMgr->doubleValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ), resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) ); vm->setStaticTrihedronVisible( resMgr->booleanValue( "VTKViewer", "show_static_trihedron", vm->isStaticTrihedronVisible() ) ); @@ -1473,7 +1472,7 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() ); VTKViewer_Viewer* vm = dynamic_cast( viewMgr->getViewModel() ); if ( vm ) - vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) ); + vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) ); #endif } #endif @@ -2030,6 +2029,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) QStringList aValuesList; QList anIndicesList; + QIntList idList; // . Top-level "SALOME" preferences group <> int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) ); @@ -2154,19 +2154,43 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) // ... "Background" group <> int bgGroup = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup ); - pref->setItemProperty( "columns", 2, bgGroup ); + // pref->setItemProperty( "columns", 2, bgGroup ); + aValuesList.clear(); + anIndicesList.clear(); + QString formats = OCCViewer_Viewer::backgroundData( aValuesList, idList ); + foreach( int gid, idList ) anIndicesList << gid; // .... -> 3D viewer background - pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup, - LightApp_Preferences::Color, "OCCViewer", "background" ); + int bgId = pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup, + LightApp_Preferences::Background, "OCCViewer", "background" ); + pref->setItemProperty( "gradient_names", aValuesList, bgId ); + pref->setItemProperty( "gradient_ids", anIndicesList, bgId ); + pref->setItemProperty( "texture_enabled", false, bgId ); + pref->setItemProperty( "custom_enabled", false, bgId ); + pref->setItemProperty( "image_formats", formats, bgId ); // .... -> XZ viewer background - pref->addPreference( tr( "PREF_XZVIEWER_BACKGROUND" ), bgGroup, - LightApp_Preferences::Color, "OCCViewer", "xz_background" ); + bgId = pref->addPreference( tr( "PREF_XZVIEWER_BACKGROUND" ), bgGroup, + LightApp_Preferences::Background, "OCCViewer", "xz_background" ); + pref->setItemProperty( "gradient_names", aValuesList, bgId ); + pref->setItemProperty( "gradient_ids", anIndicesList, bgId ); + pref->setItemProperty( "texture_enabled", false, bgId ); + pref->setItemProperty( "custom_enabled", false, bgId ); + pref->setItemProperty( "image_formats", formats, bgId ); // .... -> YZ viewer background - pref->addPreference( tr( "PREF_YZVIEWER_BACKGROUND" ), bgGroup, - LightApp_Preferences::Color, "OCCViewer", "yz_background" ); + bgId = pref->addPreference( tr( "PREF_YZVIEWER_BACKGROUND" ), bgGroup, + LightApp_Preferences::Background, "OCCViewer", "yz_background" ); + pref->setItemProperty( "gradient_names", aValuesList, bgId ); + pref->setItemProperty( "gradient_ids", anIndicesList, bgId ); + pref->setItemProperty( "texture_enabled", false, bgId ); + pref->setItemProperty( "custom_enabled", false, bgId ); + pref->setItemProperty( "image_formats", formats, bgId ); // .... -> XY viewer background - pref->addPreference( tr( "PREF_XYVIEWER_BACKGROUND" ), bgGroup, - LightApp_Preferences::Color, "OCCViewer", "xy_background" ); + bgId = pref->addPreference( tr( "PREF_XYVIEWER_BACKGROUND" ), bgGroup, + LightApp_Preferences::Background, "OCCViewer", "xy_background" ); + pref->setItemProperty( "gradient_names", aValuesList, bgId ); + pref->setItemProperty( "gradient_ids", anIndicesList, bgId ); + pref->setItemProperty( "texture_enabled", false, bgId ); + pref->setItemProperty( "custom_enabled", false, bgId ); + pref->setItemProperty( "image_formats", formats, bgId ); // ... "Background" group <> // ... -> empty frame (for layout) <> @@ -2201,7 +2225,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) // ... -> empty frame (for layout) <> int vtkGen = pref->addPreference( "", vtkGroup, LightApp_Preferences::Frame ); - pref->setItemProperty( "columns", 2, vtkGen ); + //pref->setItemProperty( "columns", 2, vtkGen ); // .... -> projection mode int vtkProjMode = pref->addPreference( tr( "PREF_PROJECTION_MODE" ), vtkGen, LightApp_Preferences::Selector, "VTKViewer", "projection_mode" ); @@ -2212,8 +2236,17 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) pref->setItemProperty( "strings", aValuesList, vtkProjMode ); pref->setItemProperty( "indexes", anIndicesList, vtkProjMode ); // .... -> background - pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen, - LightApp_Preferences::Color, "VTKViewer", "background" ); + aValuesList.clear(); + anIndicesList.clear(); + formats = SVTK_Viewer::backgroundData( aValuesList, idList ); + foreach( int gid, idList ) anIndicesList << gid; + bgId = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen, + LightApp_Preferences::Background, "VTKViewer", "background" ); + pref->setItemProperty( "gradient_names", aValuesList, bgId ); + pref->setItemProperty( "gradient_ids", anIndicesList, bgId ); + pref->setItemProperty( "texture_enabled", false, bgId ); + pref->setItemProperty( "custom_enabled", false, bgId ); + pref->setItemProperty( "image_formats", formats, bgId ); // .... -> navigation mode int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), vtkGen, LightApp_Preferences::Selector, "VTKViewer", "navigation_mode" ); @@ -2266,7 +2299,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) // ... space mouse sub-group <> int vtkSM = pref->addPreference( tr( "PREF_FRAME_SPACEMOUSE" ), vtkGroup, LightApp_Preferences::GroupBox ); - pref->setItemProperty( "columns", 2, vtkSM ); + //pref->setItemProperty( "columns", 2, vtkSM ); // .... -> decrease speed increment int spacemousePref1 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_1" ), vtkSM, LightApp_Preferences::Selector, "VTKViewer", @@ -2384,7 +2417,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) pref->setItemProperty( "strings", aValuesList, verScale ); pref->setItemProperty( "indexes", anIndicesList, verScale ); // ... -> background - pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup, + pref->addPreference( tr( "PREF_VIEWER_BACKGROUND_COLOR" ), plot2dGroup, LightApp_Preferences::Color, "Plot2d", "Background" ); // ... -> font color pref->addPreference( tr( "PREF_FONT_COLOR" ), plot2dGroup, LightApp_Preferences::Color, "Plot2d", "LegendFontColor" ); diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index 00ca4253d..8d573e771 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -528,6 +528,10 @@ The changes will be applied on the next application session. PREF_VIEWER_BACKGROUND + Background + + + PREF_VIEWER_BACKGROUND_COLOR Background color diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index 915e617c3..eff2c633a 100755 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -528,6 +528,10 @@ Les modifications seront appliquées à la prochaine session. PREF_VIEWER_BACKGROUND + Arrière-plan + + + PREF_VIEWER_BACKGROUND_COLOR Couleur de l'arrière-plan diff --git a/src/OCCViewer/OCCViewer_ViewFrame.cxx b/src/OCCViewer/OCCViewer_ViewFrame.cxx index e8a855f5c..3fd668516 100644 --- a/src/OCCViewer/OCCViewer_ViewFrame.cxx +++ b/src/OCCViewer/OCCViewer_ViewFrame.cxx @@ -30,6 +30,14 @@ #include #include +class VisEvent : public QEvent +{ +public: + VisEvent( const QMap& visMap ) : QEvent( QEvent::User ), myVisMap( visMap ) + {} + QMap myVisMap; +}; + OCCViewer_ViewFrame::OCCViewer_ViewFrame(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel) : OCCViewer_ViewWindow( theDesktop, theModel ), myPopupRequestedView(0) { @@ -55,7 +63,7 @@ OCCViewer_ViewFrame::~OCCViewer_ViewFrame() //************************************************************************************** OCCViewer_ViewWindow* OCCViewer_ViewFrame::getView( const int i ) const { - return ( i < myViews.count() ) ? myViews.at( i ) : 0 ; + return ( i >= 0 && i < myViews.count() ) ? myViews.at( i ) : 0 ; } //************************************************************************************** @@ -75,21 +83,21 @@ void OCCViewer_ViewFrame::onMaximizedView( OCCViewer_ViewWindow* theView, bool i if (myViews.count() <= 1) return; - myLayout->setColumnStretch(0 , 0); + myLayout->setColumnStretch(0, 0); myLayout->setColumnStretch(1, 0); int i = 0; - OCCViewer_ViewWindow* aView = 0; + OCCViewer_ViewWindow* view = 0; for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) { - aView = myViews.at(i); - if (aView != theView) - aView->hide(); + view = myViews.at(i); + view->setVisible( view == theView ); + view->setMaximized( view == theView, false ); } } else { OCCViewer_Viewer* aModel = dynamic_cast(myManager->getViewModel()); if (!aModel) return; - myLayout->setColumnStretch(0 , 10); + myLayout->setColumnStretch(0, 10); myLayout->setColumnStretch(1, 10); int i = 0; @@ -106,7 +114,7 @@ void OCCViewer_ViewFrame::onMaximizedView( OCCViewer_ViewWindow* theView, bool i view->setMaximized(false, false); view->setDropDownButtons( dropDownButtons() ); connectViewSignals(view); - view->setBackgroundColor(aModel->backgroundColor(i)); + view->setBackground(aModel->background(i)); } myLayout->addWidget( myViews.at(BOTTOM_LEFT), 1, 0 ); myLayout->addWidget( myViews.at(TOP_LEFT), 0, 0 ); @@ -116,7 +124,8 @@ void OCCViewer_ViewFrame::onMaximizedView( OCCViewer_ViewWindow* theView, bool i for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) { view = myViews.at(i); view->show(); - QApplication::processEvents(); + view->setMaximized( false, false ); + ///////////////QApplication::processEvents(); // VSR: hangs up ? if (view != theView) view->onViewFitAll(); } @@ -193,7 +202,7 @@ void OCCViewer_ViewFrame::connectViewSignals(OCCViewer_ViewWindow* theView) connect( theView, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ), this, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ) ); - // The signal is used to process get/set bacgrounf\d color from popup + // The signal is used to process get/set background color from popup connect( theView, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), this, SLOT( onContextMenuRequested(QContextMenuEvent*) ) ); @@ -201,7 +210,8 @@ void OCCViewer_ViewFrame::connectViewSignals(OCCViewer_ViewWindow* theView) this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) ); } -void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor) +// obsolete +void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor ) { if (myPopupRequestedView) myPopupRequestedView->setBackgroundColor(theColor); @@ -212,15 +222,14 @@ void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor) } } } - -void OCCViewer_ViewFrame::setBackgroundImage( const QString& theFilename,const Aspect_FillMethod& theFillMethod) +void OCCViewer_ViewFrame::setBackground( const Qtx::BackgroundData& theBackground ) { if (myPopupRequestedView) - myPopupRequestedView->setBackgroundImage(theFilename,theFillMethod); + myPopupRequestedView->setBackground(theBackground); else { foreach (OCCViewer_ViewWindow* aView, myViews) { if (aView->isVisible()) - aView->setBackgroundImage(theFilename,theFillMethod); + aView->setBackground(theBackground); } } } @@ -238,7 +247,8 @@ void OCCViewer_ViewFrame::onFitAll() aView->onFitAll(); } } - + +// obsolete QColor OCCViewer_ViewFrame::backgroundColor() const { if (myPopupRequestedView) @@ -251,16 +261,16 @@ QColor OCCViewer_ViewFrame::backgroundColor() const return getView(MAIN_VIEW)->backgroundColor(); } -QString OCCViewer_ViewFrame::backgroundImageFilename() const +Qtx::BackgroundData OCCViewer_ViewFrame::background() const { if (myPopupRequestedView) - return myPopupRequestedView->backgroundImageFilename(); + return myPopupRequestedView->background(); foreach (OCCViewer_ViewWindow* aView, myViews) { if (aView->isVisible()) - return aView->backgroundImageFilename(); + return aView->background(); } - return getView(MAIN_VIEW)->backgroundImageFilename(); + return getView(MAIN_VIEW)->background(); } QImage OCCViewer_ViewFrame::dumpView() @@ -303,3 +313,49 @@ void OCCViewer_ViewFrame::setDropDownButtons( bool on ) } OCCViewer_ViewWindow::setDropDownButtons( on ); } + +QString OCCViewer_ViewFrame::getVisualParameters() +{ + QStringList params; + int maximizedView = 999; + for ( int i = BOTTOM_RIGHT; i <= TOP_RIGHT && i < myViews.count(); i++) { + if ( getView(i)->isVisible() ) + maximizedView = ( maximizedView != -1 ) ? ( maximizedView == 999 ? i : -1 ) : ( maximizedView ); + params << getView(i)->getVisualParameters(); + } + params.prepend( QString::number( maximizedView ) ); + return params.join( "|" ); +} + +void OCCViewer_ViewFrame::setVisualParameters( const QString& parameters ) +{ + QStringList params = parameters.split( "|" ); + if ( params.count() > 1 ) { + int maximizedView = params[0].toInt(); + QMap visMap; + if ( myViews.count() < params.count()-1 ) + onMaximizedView( getView(MAIN_VIEW), false ); // secondary views are not created yet, but should be + for ( int i = 1; i < params.count(); i++ ) { + int idx = i-1; + getView( idx )->setVisualParameters( params[i] ); + //visMap[idx] = maximizedView == -1 || maximizedView == idx; + } + onMaximizedView( getView( maximizedView ), maximizedView != -1 ); // set proper sib-window maximized + //VisEvent ve( visMap ); + //QApplication::sendEvent( this, &ve ); + } + else { + // handle obsolete versions - no parameters for xy, yz, xz views + getView(MAIN_VIEW)->setVisualParameters( parameters ); + } +} + +bool OCCViewer_ViewFrame::event( QEvent* e ) +{ + if ( e->type() == QEvent::User ) { + VisEvent* ve = dynamic_cast( e ); + QMap visMap = ve->myVisMap; + for ( int i = 0 ; i < myViews.count(); i++ ) + myViews[i]->setVisible( visMap.contains( i ) && visMap[i] ); + } +} diff --git a/src/OCCViewer/OCCViewer_ViewFrame.h b/src/OCCViewer/OCCViewer_ViewFrame.h index f1396d7a6..52ff9d1ab 100644 --- a/src/OCCViewer/OCCViewer_ViewFrame.h +++ b/src/OCCViewer/OCCViewer_ViewFrame.h @@ -57,8 +57,8 @@ public: virtual bool isCuttingPlane() { return getView(MAIN_VIEW)->isCuttingPlane(); } - virtual QString getVisualParameters() { return getView(MAIN_VIEW)->getVisualParameters(); } - virtual void setVisualParameters( const QString& parameters ) { getView(MAIN_VIEW)->setVisualParameters(parameters); } + virtual QString getVisualParameters(); + virtual void setVisualParameters( const QString& parameters ); virtual void initSketchers() { getView(MAIN_VIEW)->initSketchers(); } virtual OCCViewer_ViewSketcher* getSketcher( const int i) { return getView(MAIN_VIEW)->getSketcher(i); } @@ -74,14 +74,16 @@ public: virtual bool eventFilter(QObject* watched, QEvent* e) { return SUIT_ViewWindow::eventFilter(watched, e); } - virtual QColor backgroundColor() const; - virtual void setBackgroundColor( const QColor& ); + virtual QColor backgroundColor() const; // obsolete + virtual void setBackgroundColor( const QColor& ); // obsolete + + virtual Qtx::BackgroundData background() const; + virtual void setBackground( const Qtx::BackgroundData& ); - virtual QString backgroundImageFilename() const; - virtual void setBackgroundImage( const QString& theFilename , const Aspect_FillMethod& theFillMethod); - virtual void setDropDownButtons( bool ); + bool event( QEvent* e ); + public slots: virtual void onFrontView() { getView(MAIN_VIEW)->onFrontView(); } virtual void onViewFitAll(); diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 9d94adff6..9196394dc 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -33,6 +33,7 @@ #include "SUIT_ResourceMgr.h" #include "QtxActionToolMgr.h" +#include "QtxBackgroundTool.h" #include #include @@ -60,13 +61,29 @@ #include +/*! + Get data for supported background modes: gradient types, identifiers and supported image formats +*/ +QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList ) +{ + gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") << + tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") << + tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") << + tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT"); + idList << HorizontalGradient << VerticalGradient << + Diagonal1Gradient << Diagonal2Gradient << + Corner1Gradient << Corner2Gradient << + Corner3Gradient << Corner4Gradient; + return QString(); // temporarily, means support of all image formars! +} + /*! Constructor \param DisplayTrihedron - is trihedron displayed */ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron) : SUIT_ViewModel(), - myColors(4, Qt::black), + myBackgrounds(4, Qtx::BackgroundData( Qt::black )), myIsRelative(true), myTrihedronSize(100) { @@ -144,15 +161,24 @@ OCCViewer_Viewer::~OCCViewer_Viewer() } /*! + [obsolete] \return background color of viewer */ QColor OCCViewer_Viewer::backgroundColor() const { - return myColors[0]; + return backgroundColor(0); } /*! - Sets background color + \return background data of viewer +*/ +Qtx::BackgroundData OCCViewer_Viewer::background() const +{ + return background(0); +} + +/*! + Sets background color [obsolete] \param c - new background color */ void OCCViewer_Viewer::setBackgroundColor( const QColor& c ) @@ -160,6 +186,15 @@ void OCCViewer_Viewer::setBackgroundColor( const QColor& c ) setBackgroundColor( 0, c ); } +/*! + Sets background data + \param d - new background data +*/ +void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground ) +{ + setBackground( 0, theBackground ); +} + /*! Start initialization of view window \param view - view window to be initialized @@ -175,7 +210,6 @@ void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view ) OCCViewer_ViewPort3d* vp3d = view->getViewPort(); if ( vp3d ) { - vp3d->setBackgroundColor( myColors[0] ); vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL); } } @@ -187,9 +221,14 @@ void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view ) */ SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop ) { - //OCCViewer_ViewWindow* view = new OCCViewer_ViewWindow(theDesktop, this); + // create view frame OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this); - initView( view->getView(OCCViewer_ViewFrame::MAIN_VIEW) ); + // get main view window (created by view frame) + OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW); + // initialize main view window + initView( vw ); + // set default background for view window + vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here) return view; } @@ -422,11 +461,7 @@ void OCCViewer_Viewer::enableMultiselection(bool isEnable) 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->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBackground() ) ); thePopup->addSeparator(); @@ -454,60 +489,33 @@ void OCCViewer_Viewer::onDumpView() /*! SLOT: called if background color is to be changed changed, passes new color to view port */ -void OCCViewer_Viewer::onChangeBgColor() +void OCCViewer_Viewer::onChangeBackground() { 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_IMAGE_FILES")); - if ( ! selFile.isEmpty() ){ - aView->setBackgroundImage(selFile,Aspect_FM_CENTERED); - } -} + // get supported gradient types + QStringList gradList; + QIntList idList; + QString formats = backgroundData( gradList, idList ); -/*! - 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_IMAGE_FILES")); - if ( ! selFile.isEmpty() ) - aView->setBackgroundImage(selFile,Aspect_FM_TILED); -} + // invoke dialog box + Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box + aView->background(), // initial background + true, // enable solid color mode + false, // disable texture mode + true, // enable gradient mode + false, // disable custom gradient mode + gradList, // gradient names + idList, // gradient identifiers + formats ); // image formats -/*! - 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_IMAGE_FILES")); - if ( ! selFile.isEmpty() ) - aView->setBackgroundImage(selFile,Aspect_FM_STRETCH); -// aView->setBackgroundImage(selFile,Aspect_FM_STRETCH_NODEF); + // set chosen background data to the viewer + if ( bgData.isValid() ) + aView->setBackground( bgData ); } + /*! Updates OCC 3D viewer */ @@ -770,16 +778,32 @@ OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow() { return new OCCViewer_ViewWindow( 0, this); } - -QColor OCCViewer_Viewer::backgroundColor(int theViewId) const + +// obsolete +QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const +{ + return background( theViewId ).color(); +} + +Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const +{ + return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData(); +} + +// obsolete +void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor ) { - return ( theViewId >= 0 && theViewId < myColors.count() ) ? myColors[theViewId] : Qt::black; + if ( theColor.isValid() ) { + Qtx::BackgroundData bg = background( theViewId ); + bg.setColor( theColor ); + setBackground( theViewId, bg ); + } } -void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor) +void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground ) { - if ( theColor.isValid() && theViewId >= 0 && theViewId < myColors.count() ) - myColors[theViewId] = theColor; + if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() ) + myBackgrounds[theViewId] = theBackground; } diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index 5c5c7bfe2..bda8ce782 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -29,6 +29,7 @@ #include "OCCViewer.h" +#include "Qtx.h" #include "SUIT_ViewModel.h" #include @@ -53,7 +54,17 @@ class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel Q_OBJECT public: - static QString Type() { return "OCCViewer"; } + /*! supported gradient types */ + enum { + HorizontalGradient, VerticalGradient, + Diagonal1Gradient, Diagonal2Gradient, + Corner1Gradient, Corner2Gradient, + Corner3Gradient, Corner4Gradient, + LastGradient = Corner4Gradient + }; + + static QString Type() { return "OCCViewer"; } + static QString backgroundData( QStringList&, QIntList& ); OCCViewer_Viewer( bool DisplayTrihedron = true); virtual ~OCCViewer_Viewer(); @@ -74,11 +85,15 @@ public: void performSelectionChanged(); // emit signal selectionChanged - QColor backgroundColor() const; - void setBackgroundColor( const QColor& ); + QColor backgroundColor() const; // obsolete + void setBackgroundColor( const QColor& ); // obsolete + Qtx::BackgroundData background() const; + void setBackground( const Qtx::BackgroundData& ); - QColor backgroundColor(int theViewId) const; - void setBackgroundColor( int theViewId, const QColor& ); + QColor backgroundColor(int theViewId) const; // obsolete + void setBackgroundColor( int theViewId, const QColor& ); // obsolete + Qtx::BackgroundData background(int theViewId) const; + void setBackground( int theViewId, const Qtx::BackgroundData& ); //! returns true if 3d Trihedron in viewer was created bool trihedronActivated() const { return !myTrihedron.IsNull(); } @@ -141,8 +156,6 @@ signals: void selectionChanged(); void deselection(); -protected: - protected slots: virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*); virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); @@ -150,10 +163,7 @@ protected slots: virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*); void onDumpView(); - void onChangeBgColor(); - void onChangeBgImageCentered(); - void onChangeBgImageTiled(); - void onChangeBgImageStretched(); + void onChangeBackground(); protected: Handle(V3d_Viewer) myV3dViewer; @@ -176,7 +186,7 @@ protected: double myTrihedronSize; - QVector myColors; + QVector myBackgrounds; }; #ifdef WIN32 diff --git a/src/OCCViewer/OCCViewer_ViewPort.cxx b/src/OCCViewer/OCCViewer_ViewPort.cxx index ea81421cb..055c88b1d 100755 --- a/src/OCCViewer/OCCViewer_ViewPort.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort.cxx @@ -503,7 +503,7 @@ bool OCCViewer_ViewPort::synchronize( OCCViewer_ViewPort* ) /*! Sets the background color with color selection dialog. [ virtual protected slot ] */ -void OCCViewer_ViewPort::onChangeBgColor() +void OCCViewer_ViewPort::onChangeBackground() { QColor selColor = QColorDialog::getColor ( backgroundColor(), this ); if ( selColor.isValid() ) diff --git a/src/OCCViewer/OCCViewer_ViewPort.h b/src/OCCViewer/OCCViewer_ViewPort.h index 69b80490b..092b6fa84 100755 --- a/src/OCCViewer/OCCViewer_ViewPort.h +++ b/src/OCCViewer/OCCViewer_ViewPort.h @@ -99,7 +99,7 @@ public slots: virtual bool synchronize( OCCViewer_ViewPort* ); protected slots: - virtual void onChangeBgColor(); + virtual void onChangeBackground(); signals: void vpKeyEvent( QKeyEvent* ); @@ -118,7 +118,7 @@ protected: bool myEnableTransform; bool myPaintersRedrawing; /* set to draw externally */ QList myPopupActions; - + private: static int nCounter; /* objects counter */ }; diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index 148097541..e5174ba11 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -67,8 +68,7 @@ OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_V myDegenerated( true ), myAnimate( false ), myBusy( true ), - myIsAdvancedZoomingEnabled( false ), - myBackgroundImageFilename( "" ) + myIsAdvancedZoomingEnabled( false ) { // VSR: 01/07/2010 commented to avoid SIGSEGV at SALOME exit //selectVisualId(); @@ -83,6 +83,7 @@ OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_V } if ( myDegenerated ) activeView()->SetDegenerateModeOn(); + setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background } /*! @@ -273,52 +274,161 @@ void OCCViewer_ViewPort3d::getAxialScale( double& xScale, double& yScale, double } /*! - Returns the background color [ virtual public ] + Returns the background color [ virtual public ] [ obsolete ] */ QColor OCCViewer_ViewPort3d::backgroundColor() const { - if ( !activeView().IsNull() ) { - Standard_Real aRed, aGreen, aBlue; - activeView()->BackgroundColor( Quantity_TOC_RGB, aRed, aGreen, aBlue ); - int red = (int) (aRed * 255); - int green = (int) (aGreen * 255); - int blue = (int) (aBlue * 255); - return QColor( red, green, blue ); - } - return OCCViewer_ViewPort::backgroundColor(); + return background().color(); } /*! - Sets the background color [ virtual public ] + Sets the background color [ virtual public ] [ obsolete ] */ void OCCViewer_ViewPort3d::setBackgroundColor( const QColor& color ) { - if ( !activeView().IsNull() ) { - activeView()->SetBackgroundColor( Quantity_TOC_RGB, color.red()/255., - color.green()/255., color.blue()/255.); - activeView()->Update(); - emit vpChangeBGColor( color ); - } + Qtx::BackgroundData bg = background(); + bg.setColor( color ); + setBackground( bg ); } /*! - Returns the background image fileName[ virtual public ] + Returns the background data */ -QString OCCViewer_ViewPort3d::backgroundImageFilename() const +Qtx::BackgroundData OCCViewer_ViewPort3d::background() const { - return myBackgroundImageFilename; + return myBackground; } /*! - Sets the background image [ virtual public ] + Sets the background data */ -void OCCViewer_ViewPort3d::setBackgroundImage( const QString& fileName,const Aspect_FillMethod& theFillMethod) -{ - myBackgroundImageFilename=fileName; - //TEST -// if ( !activeView().IsNull() ) { -// activeView()->SetBackgroundImage( (Standard_CString)fileName.toLatin1().constData(),theFillMethod,true); -// } +void OCCViewer_ViewPort3d::setBackground( const Qtx::BackgroundData& bgData ) +{ + if ( bgData.isValid() ) { + myBackground = bgData; + updateBackground(); + emit vpChangeBackground( myBackground ); + } +} + +void OCCViewer_ViewPort3d::updateBackground() +{ + if ( activeView().IsNull() ) return; + if ( !myBackground.isValid() ) return; + + // VSR: Important note on below code. + // In OCCT (at least in version 6.5.2), things about the background drawing + // are not straightforward and not clearly understandable: + // - Horizontal gradient is drawn vertically (!), well ok, from top side to bottom one. + // - Vertical gradient is drawn horizontally (!), from right side to left one (!!!). + // - First and second diagonal gradients are confused. + // - Image texture, once set, can not be removed (!). + // - Texture image fill mode Aspect_FM_NONE is not taken into account (and means the same + // as Aspect_FM_CENTERED). + // - The only way to cancel gradient background (and get back to single colored) is to + // set gradient background style to Aspect_GFM_NONE while passing two colors is also needed + // (see V3d_View::SetBgGradientColors() function). + // - Also, it is impossible to draw texture image above the gradiented background (only above + // single-colored). + // Well, all this is strange but we have to live with it. + switch ( myBackground.mode() ) { + case Qtx::ImageBackground: + { + // VSR: Do not use this code until the bug is fixed - currently it is not possible to + // clear the background texture image as soon as it is once set to the viewer. + QString fileName; + int textureMode = myBackground.texture( fileName ); + QFileInfo fi( fileName ); + if ( !fileName.isEmpty() && fi.exists() ) { + // set texture image: file name and fill mode + switch ( textureMode ) { + case Qtx::CenterTexture: + activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_CENTERED ); + break; + case Qtx::TileTexture: + activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_TILED ); + break; + case Qtx::StretchTexture: + activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_STRETCH ); + break; + default: + break; + } + } + break; + } + case Qtx::ColorBackground: + { + QColor c = myBackground.color(); + if ( c.isValid() ) { + // Unset texture should be done here + // ... + // cancel gradient background (in OCC the only way is to set it to NONE type) + Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB ); + activeView()->SetBgGradientColors( qCol, qCol, Aspect_GFM_NONE ); + // then change background color + activeView()->SetBackgroundColor( qCol ); + // update viewer + activeView()->Update(); + } + break; + } + case Qtx::SimpleGradientBackground: + { + QColor c1, c2; + int type = myBackground.gradient( c1, c2 ); + if ( c1.isValid() && type >= OCCViewer_Viewer::HorizontalGradient && type <= OCCViewer_Viewer::LastGradient ) { + // Unset texture should be done here + // ... + // Get colors and set-up gradiented background + if ( !c2.isValid() ) c2 = c1; + Quantity_Color qCol1( c1.red()/255., c1.green()/255., c1.blue()/255., Quantity_TOC_RGB ); + Quantity_Color qCol2( c2.red()/255., c2.green()/255., c2.blue()/255., Quantity_TOC_RGB ); + switch ( type ) { + case OCCViewer_Viewer::HorizontalGradient: + // in OCCT, to draw horizontal gradient it's necessary to use Aspect_GFM_VER type + // and interchange the colors + activeView()->SetBgGradientColors( qCol2, qCol1, Aspect_GFM_VER, Standard_True ); + break; + case OCCViewer_Viewer::VerticalGradient: + // in OCCT, to draw vertical gradient it's necessary to use Aspect_GFM_HOR type + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True ); + break; + case OCCViewer_Viewer::Diagonal1Gradient: + // in OCCT, to draw 1st dialognal gradient it's necessary to use Aspect_GFM_DIAG2 type + // and interchange the colors + activeView()->SetBgGradientColors( qCol2, qCol1, Aspect_GFM_DIAG2, Standard_True ); + break; + case OCCViewer_Viewer::Diagonal2Gradient: + // in OCCT, to draw 2nd dialognal gradient it's necessary to use Aspect_GFM_DIAG1 type + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True ); + break; + case OCCViewer_Viewer::Corner1Gradient: + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True ); + break; + case OCCViewer_Viewer::Corner2Gradient: + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER2, Standard_True ); + break; + case OCCViewer_Viewer::Corner3Gradient: + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER3, Standard_True ); + break; + case OCCViewer_Viewer::Corner4Gradient: + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER4, Standard_True ); + break; + default: + break; + } + } + break; + } + case Qtx::CustomGradientBackground: + { + // NOT IMPLEMENTED YET + break; + } + default: + break; + } } /*! @@ -627,8 +737,10 @@ bool OCCViewer_ViewPort3d::setWindow( const Handle(V3d_View)& view ) void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view, const Handle(Aspect_Window)& window) { - if (!view.IsNull()) + if (!view.IsNull()) { view->SetWindow( window ); + updateBackground(); + } } /*! diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.h b/src/OCCViewer/OCCViewer_ViewPort3d.h index ea977007b..6739ff58b 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.h +++ b/src/OCCViewer/OCCViewer_ViewPort3d.h @@ -24,6 +24,7 @@ #define OCCVIEWER_VIEWPORT3D_H #include "OCCViewer_ViewPort.h" +#include "Qtx.h" #include @@ -54,12 +55,11 @@ public: void setAnimationMode(bool theDegenerated); - virtual void setBackgroundColor( const QColor& color); - virtual QColor backgroundColor() const; + virtual void setBackgroundColor( const QColor& color); // obsolete + virtual QColor backgroundColor() const; // obsolete + void setBackground( const Qtx::BackgroundData& color); + Qtx::BackgroundData background() const; - virtual QString backgroundImageFilename() const; - virtual void setBackgroundImage( const QString& fileName , const Aspect_FillMethod& theFillMethod); - virtual int getBgImgHeight(){return myBgImgHeight; }; virtual int getBgImgWidth() {return myBgImgWidth; }; @@ -94,6 +94,9 @@ public: void setAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; } bool isAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; } +signals: + void vpChangeBackground( const Qtx::BackgroundData& ); + public slots: virtual bool synchronize( OCCViewer_ViewPort* ); @@ -111,7 +114,8 @@ private: bool mapView( const Handle(V3d_View)& ); bool setWindow( const Handle(V3d_View)& ); bool mapped( const Handle(V3d_View)& ) const; - + void updateBackground(); + private: Handle(V3d_View) myOrthoView; Handle(V3d_View) myPerspView; @@ -121,7 +125,7 @@ private: bool myBusy; double myScale; bool myIsAdvancedZoomingEnabled; - QString myBackgroundImageFilename; + Qtx::BackgroundData myBackground; int myBgImgHeight; int myBgImgWidth; }; diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index 6c900b90b..d514bc1f6 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -253,7 +253,6 @@ OCCViewer_ViewWindow::~OCCViewer_ViewWindow() void OCCViewer_ViewWindow::initLayout() { myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC ); - myViewPort->setBackgroundColor(Qt::black); myViewPort->installEventFilter(this); setCentralWidget(myViewPort); myOperation = NOTHING; @@ -2070,6 +2069,8 @@ QString OCCViewer_ViewWindow::getVisualParameters() data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY ); data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ ); #endif + QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" ); + data << QString( "background=%1" ).arg( bg ); return data.join("*"); } @@ -2083,6 +2084,7 @@ void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters ) viewAspect params; QStringList data = parameters.split( '*' ); + Qtx::BackgroundData bgData; if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..." { foreach( QString param, data ) { @@ -2147,6 +2149,10 @@ void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters ) else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt(); else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt(); else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt(); + else if ( paramName == "background" ) { + QString bg = paramValue.replace( "$", "=" ); + bgData = Qtx::stringToBackground( bg ); + } } } else // old format - "1.000e+00*0.000e+00..." @@ -2172,6 +2178,7 @@ void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters ) params.size = data.count() > idx ? data[idx++].toDouble() : 100.0; } performRestoring( params ); + setBackground( bgData ); } /*! @@ -2414,26 +2421,27 @@ void OCCViewer_ViewWindow::set2dMode(Mode2dType theType) { my2dMode = theType; } - + +// obsolete QColor OCCViewer_ViewWindow::backgroundColor() const { return myViewPort ? myViewPort->backgroundColor() : Qt::black; } -void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor) +// obsolete +void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor ) { if ( myViewPort ) myViewPort->setBackgroundColor( theColor ); } -QString OCCViewer_ViewWindow::backgroundImageFilename() const +Qtx::BackgroundData OCCViewer_ViewWindow::background() const { - return myViewPort ? myViewPort->backgroundImageFilename() : ""; + return myViewPort ? myViewPort->background() : Qtx::BackgroundData(); } -void OCCViewer_ViewWindow::setBackgroundImage( const QString& theFileName,const Aspect_FillMethod& theFillMethod) +void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground ) { - if ( myViewPort ) - myViewPort->setBackgroundImage( theFileName ,theFillMethod); + if ( myViewPort ) myViewPort->setBackground( theBackground ); } /*! diff --git a/src/OCCViewer/OCCViewer_ViewWindow.h b/src/OCCViewer/OCCViewer_ViewWindow.h index bb91bc1e1..79e86bcbb 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.h +++ b/src/OCCViewer/OCCViewer_ViewWindow.h @@ -24,6 +24,7 @@ #define OCCVIEWER_VIEWWINDOW_H #include "OCCViewer.h" +#include "Qtx.h" #include "SUIT_ViewWindow.h" #include #include @@ -180,12 +181,12 @@ public: void setMaximized( bool, bool = true ); bool isMaximized() const; - virtual QColor backgroundColor() const; - virtual void setBackgroundColor( const QColor& ); + virtual QColor backgroundColor() const; // obsolete + virtual void setBackgroundColor( const QColor& ); // obsolete + + virtual Qtx::BackgroundData background() const; + virtual void setBackground( const Qtx::BackgroundData& ); - 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 1fe32ce8e..2eb1a3978 100644 --- a/src/OCCViewer/resources/OCCViewer_msg_en.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_en.ts @@ -383,6 +383,38 @@ STRETCHED in stretched mode + + GT_HORIZONTALGRADIENT + Horizontal gradient + + + GT_VERTICALGRADIENT + Vertical gradient + + + GT_FIRSTDIAGONALGRADIENT + First diagonal gradient + + + GT_SECONDDIAGONALGRADIENT + Second diagonal gradient + + + GT_FIRSTCORNERGRADIENT + First corner gradient + + + GT_SECONDCORNERGRADIENT + Second corner gradient + + + GT_THIRDCORNERGRADIENT + Third corner gradient + + + GT_FORTHCORNERGRADIENT + Fourth corner gradient + OCCViewer_AxialScaleDlg diff --git a/src/OCCViewer/resources/OCCViewer_msg_fr.ts b/src/OCCViewer/resources/OCCViewer_msg_fr.ts index a5091053e..f234e638a 100755 --- a/src/OCCViewer/resources/OCCViewer_msg_fr.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_fr.ts @@ -383,6 +383,38 @@ STRETCHED en mode étiré + + GT_HORIZONTALGRADIENT + Horizontal gradient + + + GT_VERTICALGRADIENT + Vertical gradient + + + GT_FIRSTDIAGONALGRADIENT + First diagonal gradient + + + GT_SECONDDIAGONALGRADIENT + Second diagonal gradient + + + GT_FIRSTCORNERGRADIENT + First corner gradient + + + GT_SECONDCORNERGRADIENT + Second corner gradient + + + GT_THIRDCORNERGRADIENT + Third corner gradient + + + GT_FORTHCORNERGRADIENT + Fourth corner gradient + OCCViewer_AxialScaleDlg diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 10ac9944c..513284867 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -44,7 +44,8 @@ #include "SALOME_Actor.h" -#include +#include "QtxActionToolMgr.h" +#include "QtxBackgroundTool.h" // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study. // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from @@ -85,6 +86,7 @@ SVTK_Viewer::SVTK_Viewer() mySpaceBtn[0] = 1; mySpaceBtn[1] = 2; mySpaceBtn[2] = 9; + myDefaultBackground = Qtx::BackgroundData( Qt::black ); } /*! @@ -94,33 +96,51 @@ SVTK_Viewer::~SVTK_Viewer() { } -/*! - \return background color -*/ +/*! Get data for supported background modes: gradient types, identifiers and supported image formats */ +QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList ) +{ + gradList << tr( "GT_VERTICALGRADIENT" ); + idList << VerticalGradient; + return QString(); // temporarily, means support of all image formats! +} + +//! Get background color of the viewer [obsolete] QColor SVTK_Viewer::backgroundColor() const { - return myBgColor; + return background().color(); +} + +//! Set background color to the viewer [obsolete] +void SVTK_Viewer::setBackgroundColor( const QColor& c ) +{ + Qtx::BackgroundData bg = background(); + bg.setColor( c ); + setBackground( bg ); } /*! - Changes background color - \param theColor - new background color + \return background data */ -void SVTK_Viewer::setBackgroundColor( const QColor& theColor ) +Qtx::BackgroundData SVTK_Viewer::background() const { - if ( !theColor.isValid() ) - return; + return myDefaultBackground; +} +/*! + Changes background + \param theBackground - new background data +*/ +void SVTK_Viewer::setBackground( const Qtx::BackgroundData& theBackground ) +{ + myDefaultBackground = theBackground.isValid() ? theBackground : Qtx::BackgroundData( Qt::black ); QVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){ if(TViewWindow* aView = dynamic_cast(aViewWindow)){ - aView->setBackgroundColor(theColor); + aView->setBackground(myDefaultBackground); } } - } - - myBgColor = theColor; + } } /*!Create new instance of view window on desktop \a theDesktop. @@ -131,7 +151,7 @@ SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop ) TViewWindow* aViewWindow = new TViewWindow(theDesktop); aViewWindow->Initialize(this); - aViewWindow->setBackgroundColor( backgroundColor() ); + aViewWindow->setBackground( background() ); aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() ); aViewWindow->SetStaticTrihedronVisible( isStaticTrihedronVisible() ); aViewWindow->SetProjectionMode( projectionMode() ); @@ -412,7 +432,7 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager) void SVTK_Viewer::contextMenuPopup( QMenu* thePopup ) { thePopup->addAction( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); - thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) ); + thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBackground() ) ); thePopup->addSeparator(); @@ -476,12 +496,31 @@ void SVTK_Viewer::onDumpView() /*! SLOT: called if background color is to be changed changed, passes new color to view port */ -void SVTK_Viewer::onChangeBgColor() +void SVTK_Viewer::onChangeBackground() { - if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){ - QColor aColor = QColorDialog::getColor( backgroundColor(), aView); - setBackgroundColor(aColor); - } + SVTK_ViewWindow* aView = dynamic_cast(myViewManager->getActiveView()); + if ( !aView ) + return; + + // get supported gradient types + QStringList gradList; + QIntList idList; + QString formats = backgroundData( gradList, idList ); + + // invoke dialog box + Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box + aView->background(), // initial background + true, // enable solid color mode + false, // disable texture mode + true, // enable gradient mode + false, // disable custom gradient mode + gradList, // gradient names + idList, // gradient identifiers + formats ); // image formats + + // set chosen background data to the viewer + if ( bgData.isValid() ) + aView->setBackground( bgData ); } /*! diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index c0313279e..9fa34c32e 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -26,6 +26,8 @@ #include "SVTK.h" #include "SVTK_ViewModelBase.h" +#include "Qtx.h" + #include #include #include @@ -44,10 +46,17 @@ class SVTK_EXPORT SVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View Q_OBJECT; public: + /*! supported gradient types */ + enum { + VerticalGradient, + LastGradient = VerticalGradient, + }; + typedef SVTK_ViewWindow TViewWindow; //! Define string representation of the viewer type - static QString Type() { return "VTKViewer"; } + static QString Type() { return "VTKViewer"; } + static QString backgroundData( QStringList&, QIntList& ); SVTK_Viewer(); virtual ~SVTK_Viewer(); @@ -64,12 +73,18 @@ public: //! See #SUIT_ViewModel::getType virtual QString getType() const { return Type(); } - //! Get background color of the viewer + //! Get background color of the viewer [obsolete] QColor backgroundColor() const; - //! Set background color to the viewer + //! Set background color to the viewer [obsolete] void setBackgroundColor( const QColor& ); + //! Get background color of the viewer + Qtx::BackgroundData background() const; + + //! Set background color to the viewer + void setBackground( const Qtx::BackgroundData& ); + //! Get size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize) vtkFloatingPointType trihedronSize() const; @@ -166,7 +181,7 @@ protected slots: void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*); void onDumpView(); - void onChangeBgColor(); + void onChangeBackground(); void onActorAdded(VTKViewer_Actor*); void onActorRemoved(VTKViewer_Actor*); @@ -174,20 +189,19 @@ protected slots: private: void updateToolBars(); - - QColor myBgColor; + Qtx::BackgroundData myDefaultBackground; vtkFloatingPointType myTrihedronSize; - bool myTrihedronRelative; - bool myIsStaticTrihedronVisible; - bool mySelectionEnabled; - bool myMultiSelectionEnabled; - int myIncrementSpeed; - int myIncrementMode; - int myProjMode; - int myStyle; - int myZoomingStyle; - bool myDynamicPreSelection; - int mySpaceBtn[3]; + bool myTrihedronRelative; + bool myIsStaticTrihedronVisible; + bool mySelectionEnabled; + bool myMultiSelectionEnabled; + int myIncrementSpeed; + int myIncrementMode; + int myProjMode; + int myStyle; + int myZoomingStyle; + bool myDynamicPreSelection; + int mySpaceBtn[3]; }; #endif diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 0a84e834a..f724eb7df 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -25,12 +25,14 @@ #include "SVTK_CubeAxesDlg.h" #include "SVTK_SetRotationPointDlg.h" #include "SVTK_ViewParameterDlg.h" +#include "SVTK_ViewModel.h" #include "SALOME_Actor.h" #include #include #include +#include #include #include #include @@ -47,6 +49,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include "QtxAction.h" @@ -71,7 +80,6 @@ #include "SVTK_Event.h" #include "SVTK_Renderer.h" #include "SVTK_ViewWindow.h" -#include "SVTK_ViewModelBase.h" #include "SVTK_InteractorStyle.h" #include "SVTK_RenderWindowInteractor.h" #include "SVTK_GenericRenderWindowInteractor.h" @@ -223,6 +231,7 @@ void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) myInteractor->getRenderWindow()->Render(); + setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background onResetView(); } @@ -537,26 +546,174 @@ void SVTK_ViewWindow::EraseAll() } /*! - Sets background color + Sets background color [obsolete] \param color - new background color */ -void SVTK_ViewWindow::setBackgroundColor( const QColor& theColor ) +void SVTK_ViewWindow::setBackgroundColor( const QColor& c ) { - getRenderer()->SetBackground(theColor.red()/255.0, - theColor.green()/255.0, - theColor.blue()/255.0); + Qtx::BackgroundData bg = background(); + bg.setColor( c ); + setBackground( bg ); } /*! - \return background color of viewer + \return background color of viewer [obsolete] */ QColor SVTK_ViewWindow::backgroundColor() const { - vtkFloatingPointType aBackgroundColor[3]; - getRenderer()->GetBackground(aBackgroundColor); - return QColor(int(aBackgroundColor[0]*255), - int(aBackgroundColor[1]*255), - int(aBackgroundColor[2]*255)); + return background().color(); +} + +/*! + Sets background data + \param bgData - new background data +*/ +void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) +{ + bool ok = bgData.isValid(); + + switch ( bgData.mode() ) { + case Qtx::ImageBackground: + { + QString fileName; + int textureMode = bgData.texture( fileName ); + QFileInfo fi( fileName ); + if ( !fileName.isEmpty() && fi.exists() ) { + // read texture from file + QString extension = fi.suffix().toLower(); + vtkImageReader2* aReader = 0; + if ( extension == "jpg" || extension == "jpeg" ) + aReader = vtkJPEGReader::New(); + else if ( extension == "bmp" ) + aReader = vtkBMPReader::New(); + else if ( extension == "tif" || extension == "tiff" ) + aReader = vtkTIFFReader::New(); + else if ( extension == "png" ) + aReader = vtkPNGReader::New(); + else if ( extension == "mhd" || extension == "mha" ) + aReader = vtkMetaImageReader::New(); + if ( aReader ) { + // create texture + aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() ); + aReader->Update(); + + vtkTexture* aTexture = vtkTexture::New(); + vtkImageMapToColors* aMap = 0; + vtkAlgorithmOutput* anOutput; + /* + // special processing for BMP reader + vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader; + if ( aBMPReader ) { + // Special processing for BMP file + aBMPReader->SetAllow8BitBMP(1); + + aMap = vtkImageMapToColors::New(); + aMap->SetInputConnection( aBMPReader->GetOutputPort() ); + aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() ); + aMap->SetOutputFormatToRGB(); + + anOutput = aMap->GetOutputPort(); + } + else { + } + */ + anOutput = aReader->GetOutputPort( 0 ); + aTexture->SetInputConnection( anOutput ); + // set texture mode + // VSR: Currently, VTK only supports Stretch mode, so below code will give + // the same results for all modes + switch ( textureMode ) { + case Qtx::TileTexture: + aTexture->RepeatOn(); + aTexture->EdgeClampOff(); + aTexture->InterpolateOff(); + break; + case Qtx::StretchTexture: + aTexture->RepeatOff(); + aTexture->EdgeClampOff(); + aTexture->InterpolateOn(); + break; + case Qtx::CenterTexture: + default: + aTexture->RepeatOff(); + aTexture->EdgeClampOn(); + aTexture->InterpolateOff(); + break; + } + // show textured background + getRenderer()->SetTexturedBackground( true ); + getRenderer()->SetBackgroundTexture( aTexture ); + + // clean-up resources + if ( aMap ) + aMap->Delete(); + aReader->Delete(); + aTexture->Delete(); + ok = true; + } + } + break; + } + case Qtx::ColorBackground: + { + QColor c = bgData.color(); + if ( c.isValid() ) { + // show solid-colored background + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( false ); // cancel gradient mode + getRenderer()->SetBackground( c.red()/255.0, + c.green()/255.0, + c.blue()/255.0 ); // set background color + ok = true; + } + break; + } + case Qtx::SimpleGradientBackground: + { + QColor c1, c2; + int type = bgData.gradient( c1, c2 ); + // VSR: Currently, only vertical gradient is supported by VTK. + // In future, switch operator might be added here to process different supported gradient types. + if ( c1.isValid() && type == SVTK_Viewer::VerticalGradient ) { + if ( !c2.isValid() ) c2 = c1; + // show two-color gradient background + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( true ); // switch to gradient mode + // VSR: In VTK, gradient is colored from bottom to top: + // - top color is set via SetBackground2() + // - bottom color is set via SetBackground() + // So, we reverse colors, to draw gradient from top to bottom instead. + getRenderer()->SetBackground( c2.red()/255.0, + c2.green()/255.0, + c2.blue()/255.0 ); // set first gradient color + getRenderer()->SetBackground2( c1.red()/255.0, + c1.green()/255.0, + c1.blue()/255.0 ); // set second gradient color + ok = true; + } + break; + } + case Qtx::CustomGradientBackground: + { + // NOT IMPLEMENTED YET + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( false ); // cancel gradient mode + // ......... + break; + } + default: + break; + } + if ( ok ) + myBackground = bgData; +} + +/*! + \return background data of viewer +*/ +Qtx::BackgroundData SVTK_ViewWindow::background() const +{ + return myBackground; } @@ -1455,6 +1612,10 @@ QString SVTK_ViewWindow::getVisualParameters() aWriter.writeAttribute("Size", QString::number(GetTrihedronSize())); aWriter.writeEndElement(); + aWriter.writeStartElement("Background"); + aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) )); + aWriter.writeEndElement(); + aWriter.writeEndElement(); aWriter.writeEndDocument(); @@ -1498,17 +1659,20 @@ void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool bas pos[1] = aAttr.value("Y").toString().toDouble(); pos[2] = aAttr.value("Z").toString().toDouble(); //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]); - } else if (aReader.name() == "FocalPoint") { + } + else if (aReader.name() == "FocalPoint") { focalPnt[0] = aAttr.value("X").toString().toDouble(); focalPnt[1] = aAttr.value("Y").toString().toDouble(); focalPnt[2] = aAttr.value("Z").toString().toDouble(); //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]); - } else if (aReader.name() == "ViewUp") { + } + else if (aReader.name() == "ViewUp") { viewUp[0] = aAttr.value("X").toString().toDouble(); viewUp[1] = aAttr.value("Y").toString().toDouble(); viewUp[2] = aAttr.value("Z").toString().toDouble(); //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]); - } else if (aReader.name() == "ViewScale") { + } + else if (aReader.name() == "ViewScale") { parScale = aAttr.value("Parallel").toString().toDouble(); scale[0] = aAttr.value("X").toString().toDouble(); scale[1] = aAttr.value("Y").toString().toDouble(); @@ -1542,7 +1706,12 @@ void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool bas SetTrihedronSize(aAttr.value("Size").toString().toDouble()); } } - } + else if (aReader.name() == "Background") { + if ( !baseParamsOnly ) { + setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) ); + } + } + } } if (!aReader.hasError()) { vtkCamera* camera = getRenderer()->GetActiveCamera(); diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 0e713d57a..fd9385478 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -29,6 +29,7 @@ #include "SVTK.h" #include "SVTK_Selection.h" +#include "Qtx.h" #include "SUIT_ViewWindow.h" #include "SALOME_InteractiveObject.hxx" @@ -43,7 +44,6 @@ class VTKViewer_Actor; class VTKViewer_Trihedron; class SVTK_ViewModelBase; -//class SVTK_MainWindow; class SVTK_Selector; class SVTK_View; @@ -96,50 +96,55 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow //! Get #SVTK_View SVTK_View* getView(); - //! Get #SVTK_MainWindow - //SVTK_MainWindow* getMainWindow(); - - //! Redirect the request to #SVTK_MainWindow::getRenderWindow + //! Get render window vtkRenderWindow* getRenderWindow(); - //! Redirect the request to #SVTK_MainWindow::getInteractor + //! Get interactor vtkRenderWindowInteractor* getInteractor() const; - //! Redirect the request to #SVTK_MainWindow::getInteractor + //! Get SVTK interactor SVTK_RenderWindowInteractor* GetInteractor() const; + //! Get current interactor style vtkInteractorStyle* GetInteractorStyle() const; - //! Redirect the request to #SVTK_RenderWindowInteractor::PushInteractorStyle + //! Add interactor style to the stack of styles void PushInteractorStyle(vtkInteractorStyle* theStyle); - //! Redirect the request to #SVTK_RenderWindowInteractor::PopInteractorStyle + //! Remove last interactor style from the stack of styles void PopInteractorStyle(); - //! Redirect the request to #SVTK_MainWindow::getRenderer + //! Get renderer vtkRenderer* getRenderer() const; - + + //! Get SVTK renderer SVTK_Renderer* GetRenderer() const; - //! Redirect the request to #SVTK_MainWindow::GetSelector + //! Get selector SVTK_Selector* GetSelector() const; - //! Redirect the request to #SVTK_Selector::SelectionMode + //! Set selection mode Selection_Mode SelectionMode() const; //! Change selection mode virtual void SetSelectionMode(Selection_Mode theMode); - //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor + //! Set background color [obsolete] virtual void setBackgroundColor( const QColor& ); - //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor + //! Get background color [obsolete] QColor backgroundColor() const; - //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed + //! Set background + virtual void setBackground( const Qtx::BackgroundData& ); + + //! Get background + Qtx::BackgroundData background() const; + + //! Return \c true if "display trihedron" flag is set bool isTrihedronDisplayed(); - //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed + //! Return \c true if "show graduated axes" flag is set bool isCubeAxesDisplayed(); /* interactive object management */ @@ -216,24 +221,25 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow //! Redirect the request to #SVTK_Renderer::SetTrihedronSize virtual void SetTrihedronSize( const vtkFloatingPointType, const bool = true ); - //! Redirect the request to #SVTK_MainWindow::SetIncrementalSpeed + //! Set incremental speed virtual void SetIncrementalSpeed( const int, const int = 0 ); - //! Redirect the request to #SVTK_MainWindow::SetProjectionMode + //! Set current projection mode virtual void SetProjectionMode( const int ); - //! Redirect the request to #SVTK_MainWindow::SetInteractionStyle + //! Set interactive style virtual void SetInteractionStyle( const int ); - //! Redirect the request to #SVTK_MainWindow::SetZoomingStyle + //! Set zooming style virtual void SetZoomingStyle( const int ); + //! Set dynamic preselection on/off virtual void SetDynamicPreSelection( bool ); - //! Redirect the request to #SVTK_MainWindow::SetSpacemouseButtons + //! Customize space mouse buttons virtual void SetSpacemouseButtons( const int, const int, const int ); - //! Redirect the request to #SVTK_Renderer::SetSelectionProp + //! Set selection properties virtual void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1, const double& theBlue = 0, @@ -406,7 +412,6 @@ protected: StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId }; SVTK_View* myView; - //SVTK_MainWindow* myMainWindow; SVTK_ViewModelBase* myModel; SVTK_RenderWindowInteractor* myInteractor; @@ -439,6 +444,7 @@ protected: int myRecordingToolBar; vtkPVAxesWidget* myAxesWidget; + Qtx::BackgroundData myBackground; private slots: void onSynchronizeView(bool); diff --git a/src/SVTK/resources/SVTK_msg_en.ts b/src/SVTK/resources/SVTK_msg_en.ts index ad4d257bf..be884e276 100644 --- a/src/SVTK/resources/SVTK_msg_en.ts +++ b/src/SVTK/resources/SVTK_msg_en.ts @@ -595,5 +595,9 @@ Please, refer to the documentation. MEN_CHANGE_BACKGROUD Change background... + + GT_VERTICALGRADIENT + Vertical gradient + diff --git a/src/SVTK/resources/SVTK_msg_fr.ts b/src/SVTK/resources/SVTK_msg_fr.ts index dad722885..3aca7a770 100755 --- a/src/SVTK/resources/SVTK_msg_fr.ts +++ b/src/SVTK/resources/SVTK_msg_fr.ts @@ -595,5 +595,9 @@ Veuillez consulter la documentation. MEN_CHANGE_BACKGROUD Changer l'arrière-plan... + + GT_VERTICALGRADIENT + Vertical gradient + diff --git a/src/VTKViewer/VTKViewer_ViewModel.cxx b/src/VTKViewer/VTKViewer_ViewModel.cxx index db7f32916..af301c3ae 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.cxx +++ b/src/VTKViewer/VTKViewer_ViewModel.cxx @@ -25,6 +25,7 @@ #include "VTKViewer_ViewManager.h" #include "VTKViewer_RenderWindowInteractor.h" +#include "QtxBackgroundTool.h" #include "SUIT_ViewWindow.h" #include "SUIT_Desktop.h" #include "SUIT_Session.h" @@ -48,7 +49,7 @@ static bool _InitializeVtkWarnings = _InitializeVtkWarningsCall(); /*!Constructor.Sets background color to black.*/ VTKViewer_Viewer::VTKViewer_Viewer() : SUIT_ViewModel(), -myBgColor( Qt::black ) + myDefaultBackground( Qtx::BackgroundData( Qt::black ) ) { } @@ -57,24 +58,45 @@ VTKViewer_Viewer::~VTKViewer_Viewer() { } -/*!Gets background color.*/ +/*! Get data for supported background modes: gradient types, identifiers and supported image formats */ +QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList ) +{ + gradList << tr( "GT_VERTICALGRADIENT" ); + idList << VerticalGradient; + return QString(); // temporarily, means support of all image formats! +} + +/*!Gets background color [obsolete]*/ QColor VTKViewer_Viewer::backgroundColor() const { - return myBgColor; + return background().color(); } -/*!Sets background color.*/ +/*!Sets background color [obsolete]*/ void VTKViewer_Viewer::setBackgroundColor( const QColor& c ) { - if ( c.isValid() ) - myBgColor = c; + Qtx::BackgroundData bg = background(); + bg.setColor( c ); + setBackground( bg ); +} + +/*!Gets default background data.*/ +Qtx::BackgroundData VTKViewer_Viewer::background() const +{ + return myDefaultBackground; +} + +/*!Sets default background data.*/ +void VTKViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground ) +{ + myDefaultBackground = theBackground.isValid() ? theBackground : Qtx::BackgroundData( Qt::black ); } /*!Create new instance of VTKViewer_ViewWindow, sets background color and return pointer to it.*/ SUIT_ViewWindow* VTKViewer_Viewer::createView( SUIT_Desktop* theDesktop ) { VTKViewer_ViewWindow* vw = new VTKViewer_ViewWindow( theDesktop, this ); - vw->setBackgroundColor( myBgColor ); + vw->setBackground( myDefaultBackground ); return vw; } @@ -96,7 +118,7 @@ void VTKViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager) void VTKViewer_Viewer::contextMenuPopup(QMenu* thePopup) { thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); - thePopup->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) ); + thePopup->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBackground() ) ); thePopup->addSeparator(); @@ -186,15 +208,31 @@ void VTKViewer_Viewer::onDumpView() } /*!On change back ground color event.*/ -void VTKViewer_Viewer::onChangeBgColor() +void VTKViewer_Viewer::onChangeBackground() { VTKViewer_ViewWindow* aView = (VTKViewer_ViewWindow*)(myViewManager->getActiveView()); if ( !aView ) return; - QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView); - if ( aColor.isValid() ) - aView->setBackgroundColor(aColor); + // get supported gradient types + QStringList gradList; + QIntList idList; + QString formats = backgroundData( gradList, idList ); + + // invoke dialog box + Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box + aView->background(), // initial background + true, // enable solid color mode + false, // disable texture mode + true, // enable gradient mode + false, // disable custom gradient mode + gradList, // gradient names + idList, // gradient identifiers + formats ); // image formats + + // set chosen background data to the viewer + if ( bgData.isValid() ) + aView->setBackground( bgData ); } /*!On show tool bar event.*/ diff --git a/src/VTKViewer/VTKViewer_ViewModel.h b/src/VTKViewer/VTKViewer_ViewModel.h index a0fae50b3..27235b90f 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.h +++ b/src/VTKViewer/VTKViewer_ViewModel.h @@ -24,6 +24,7 @@ #define VTKVIEWER_VIEWMODEL_H #include "VTKViewer.h" +#include "Qtx.h" #include "SUIT_ViewModel.h" #include @@ -38,8 +39,15 @@ class VTKVIEWER_EXPORT VTKViewer_Viewer: public SUIT_ViewModel Q_OBJECT public: + /*! supported gradient types */ + enum { + VerticalGradient, + LastGradient = VerticalGradient, + }; + /*!Initialize type of viewer.*/ - static QString Type() { return "VTKViewer"; } + static QString Type() { return "VTKViewer"; } + static QString backgroundData( QStringList&, QIntList& ); VTKViewer_Viewer(); virtual ~VTKViewer_Viewer(); @@ -52,35 +60,37 @@ public: virtual QString getType() const { return Type(); } public: - void enableSelection(bool isEnabled); + void enableSelection(bool isEnabled); /*!Checks: is selection enabled*/ - bool isSelectionEnabled() const { return mySelectionEnabled; } + bool isSelectionEnabled() const { return mySelectionEnabled; } - void enableMultiselection(bool isEnable); + void enableMultiselection(bool isEnable); /*!Checks: is multi selection enabled*/ - bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; } + bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; } - int getSelectionCount() const; + int getSelectionCount() const; - QColor backgroundColor() const; - void setBackgroundColor( const QColor& ); + QColor backgroundColor() const; // obsolete + void setBackgroundColor( const QColor& ); // obsolete + Qtx::BackgroundData background() const; + void setBackground( const Qtx::BackgroundData& ); signals: - void selectionChanged(); + void selectionChanged(); protected slots: - void onMousePress(SUIT_ViewWindow*, QMouseEvent*); - void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); - void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*); + void onMousePress( SUIT_ViewWindow*, QMouseEvent* ); + void onMouseMove( SUIT_ViewWindow*, QMouseEvent* ); + void onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ); - void onDumpView(); - void onShowToolbar(); - void onChangeBgColor(); + void onDumpView(); + void onShowToolbar(); + void onChangeBackground(); private: - QColor myBgColor; - bool mySelectionEnabled; - bool myMultiSelectionEnabled; + Qtx::BackgroundData myDefaultBackground; + bool mySelectionEnabled; + bool myMultiSelectionEnabled; }; #endif diff --git a/src/VTKViewer/VTKViewer_ViewWindow.cxx b/src/VTKViewer/VTKViewer_ViewWindow.cxx index ada19bce4..57c803aa0 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.cxx +++ b/src/VTKViewer/VTKViewer_ViewWindow.cxx @@ -34,10 +34,18 @@ #include #include +#include #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -68,16 +76,6 @@ VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop, myRenderer->LightFollowCameraOn(); myRenderer->TwoSidedLightingOn(); - // Set BackgroundColor - QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed"); - QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen"); - QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue"); - - if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) - myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. ); - else - myRenderer->SetBackground( 0, 0, 0 ); - // Create an interactor. myRWInteractor = rw ? rw : VTKViewer_RenderWindowInteractor::New(); myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() ); @@ -120,6 +118,9 @@ VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop, this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); + // set default background + setBackground( Qtx::BackgroundData( Qt::black ) ); + // reset view onResetView(); } @@ -444,22 +445,165 @@ void VTKViewer_ViewWindow::onFitAll() Repaint(); } -/*!Set background of the viewport*/ -void VTKViewer_ViewWindow::setBackgroundColor( const QColor& color ) +/*!Set background color of the viewport [obsolete]*/ +void VTKViewer_ViewWindow::setBackgroundColor( const QColor& c ) { - if ( myRenderer ) - myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. ); + Qtx::BackgroundData bg = background(); + bg.setColor( c ); + setBackground( bg ); } -/*!Returns background of the viewport*/ +/*!Returns background color of the viewport [obsolete]*/ QColor VTKViewer_ViewWindow::backgroundColor() const { - vtkFloatingPointType backint[3]; - if ( myRenderer ) { - myRenderer->GetBackground( backint ); - return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)); + return background().color(); +} + +/*!Set background of the viewport*/ +void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) +{ + bool ok = bgData.isValid(); + + switch ( bgData.mode() ) { + case Qtx::ImageBackground: + { + QString fileName; + int textureMode = bgData.texture( fileName ); + QFileInfo fi( fileName ); + if ( !fileName.isEmpty() && fi.exists() ) { + // read texture from file + QString extension = fi.suffix().toLower(); + vtkImageReader2* aReader = 0; + if ( extension == "jpg" || extension == "jpeg" ) + aReader = vtkJPEGReader::New(); + else if ( extension == "bmp" ) + aReader = vtkBMPReader::New(); + else if ( extension == "tif" || extension == "tiff" ) + aReader = vtkTIFFReader::New(); + else if ( extension == "png" ) + aReader = vtkPNGReader::New(); + else if ( extension == "mhd" || extension == "mha" ) + aReader = vtkMetaImageReader::New(); + if ( aReader ) { + // create texture + aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() ); + aReader->Update(); + + vtkTexture* aTexture = vtkTexture::New(); + vtkImageMapToColors* aMap = 0; + vtkAlgorithmOutput* anOutput; + /* + // special processing for BMP reader + vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader; + if ( aBMPReader ) { + // Special processing for BMP file + aBMPReader->SetAllow8BitBMP(1); + + aMap = vtkImageMapToColors::New(); + aMap->SetInputConnection( aBMPReader->GetOutputPort() ); + aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() ); + aMap->SetOutputFormatToRGB(); + + anOutput = aMap->GetOutputPort(); + } + else { + } + */ + anOutput = aReader->GetOutputPort( 0 ); + aTexture->SetInputConnection( anOutput ); + // set texture mode + // VSR: Currently, VTK only supports Stretch mode, so below code will give + // the same results for all modes + switch ( textureMode ) { + case Qtx::TileTexture: + aTexture->RepeatOn(); + aTexture->EdgeClampOff(); + aTexture->InterpolateOff(); + break; + case Qtx::StretchTexture: + aTexture->RepeatOff(); + aTexture->EdgeClampOff(); + aTexture->InterpolateOn(); + break; + case Qtx::CenterTexture: + default: + aTexture->RepeatOff(); + aTexture->EdgeClampOn(); + aTexture->InterpolateOff(); + break; + } + // show textured background + getRenderer()->SetTexturedBackground( true ); // switch to texture mode + getRenderer()->SetBackgroundTexture( aTexture ); // set texture image + + // clean-up resources + if ( aMap ) + aMap->Delete(); + aReader->Delete(); + aTexture->Delete(); + ok = true; + } + } + break; + } + case Qtx::ColorBackground: + { + QColor c = bgData.color(); + if ( c.isValid() ) { + // show solid-colored background + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( false ); // cancel gradient mode + getRenderer()->SetBackground( c.red()/255.0, + c.green()/255.0, + c.blue()/255.0 ); // set background color + ok = true; + } + break; + } + case Qtx::SimpleGradientBackground: + { + QColor c1, c2; + int type = bgData.gradient( c1, c2 ); + // VSR: Currently, only vertical gradient is supported by VTK. + // In future, switch operator might be added here to process different supported gradient types. + if ( c1.isValid() && type == VTKViewer_Viewer::VerticalGradient ) { + if ( !c2.isValid() ) c2 = c1; + // show two-color gradient background + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( true ); // switch to gradient mode + // VSR: In VTK, gradient is colored from bottom to top: + // - top color is set via SetBackground2() + // - bottom color is set via SetBackground() + // So, we reverse colors, to draw gradient from top to bottom instead. + getRenderer()->SetBackground( c2.red()/255.0, + c2.green()/255.0, + c2.blue()/255.0 ); // set first gradient color + getRenderer()->SetBackground2( c1.red()/255.0, + c1.green()/255.0, + c1.blue()/255.0 ); // set second gradient color + ok = true; + } + break; + } + case Qtx::CustomGradientBackground: + { + // NOT IMPLEMENTED YET + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( false ); // cancel gradient mode + // ......... + break; + } + default: + break; } - return palette().color( backgroundRole() ); + if ( ok ) + myBackground = bgData; +} + +/*!Returns background of the viewport*/ +Qtx::BackgroundData VTKViewer_ViewWindow::background() const +{ + return myBackground; } /*!Repaint window. If \a theUpdateTrihedron is true - recalculate trihedron.*/ diff --git a/src/VTKViewer/VTKViewer_ViewWindow.h b/src/VTKViewer/VTKViewer_ViewWindow.h index 6d2a90552..eea03b277 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.h +++ b/src/VTKViewer/VTKViewer_ViewWindow.h @@ -54,10 +54,12 @@ public: virtual ~VTKViewer_ViewWindow(); /*!Gets tool bar.*/ - QToolBar* getToolBar() { return myToolBar; } + QToolBar* getToolBar() { return myToolBar; } - void setBackgroundColor( const QColor& ); - QColor backgroundColor() const; + void setBackgroundColor( const QColor& ); // obsolete + QColor backgroundColor() const; // obsolete + void setBackground( const Qtx::BackgroundData& ); + Qtx::BackgroundData background() const; /*!Gets renderer.*/ vtkRenderer* getRenderer() { return myRenderer; } @@ -133,6 +135,7 @@ private: ActionsMap myActionsMap; double myCurScale; + Qtx::BackgroundData myBackground; friend class VTKViewer_RenderWindowInteractor; }; diff --git a/src/VTKViewer/resources/VTKViewer_msg_en.ts b/src/VTKViewer/resources/VTKViewer_msg_en.ts index 8e3fa136e..5c104ae24 100644 --- a/src/VTKViewer/resources/VTKViewer_msg_en.ts +++ b/src/VTKViewer/resources/VTKViewer_msg_en.ts @@ -219,5 +219,9 @@ MEN_CHANGE_BACKGROUD Change Background... + + GT_VERTICALGRADIENT + Vertical gradient + diff --git a/src/VTKViewer/resources/VTKViewer_msg_fr.ts b/src/VTKViewer/resources/VTKViewer_msg_fr.ts index d848beef5..c087673cd 100755 --- a/src/VTKViewer/resources/VTKViewer_msg_fr.ts +++ b/src/VTKViewer/resources/VTKViewer_msg_fr.ts @@ -219,5 +219,9 @@ MEN_CHANGE_BACKGROUD Changer l'arrière-plan... + + GT_VERTICALGRADIENT + Vertical gradient +