From 313e7b97ede3f286f4a3633aae510fd271df7515 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 29 Mar 2012 08:01:19 +0000 Subject: [PATCH] Improve background tool to support textured background properly (texture can be drown above the solid color/gradient background) --- src/LightApp/LightApp_Application.cxx | 34 ++- src/OCCViewer/OCCViewer_ViewModel.cxx | 23 +- src/OCCViewer/OCCViewer_ViewModel.h | 2 +- src/OCCViewer/OCCViewer_ViewPort3d.cxx | 130 +++++---- src/OCCViewer/resources/OCCViewer_msg_en.ts | 8 +- src/OCCViewer/resources/OCCViewer_msg_fr.ts | 8 +- src/Qtx/Qtx.cxx | 80 ++++-- src/Qtx/Qtx.h | 16 +- src/Qtx/QtxBackgroundTool.cxx | 288 ++++++++++++++++---- src/Qtx/QtxBackgroundTool.h | 29 +- src/Qtx/QtxPagePrefMgr.cxx | 70 ++++- src/Qtx/QtxPagePrefMgr.h | 8 +- src/SVTK/SVTK_ViewModel.cxx | 26 +- src/SVTK/SVTK_ViewModel.h | 2 +- src/SVTK/SVTK_ViewWindow.cxx | 128 ++++----- src/SVTK/resources/SVTK_msg_en.ts | 4 + src/SVTK/resources/SVTK_msg_fr.ts | 4 + src/VTKViewer/VTKViewer_ViewModel.cxx | 25 +- src/VTKViewer/VTKViewer_ViewModel.h | 2 +- src/VTKViewer/VTKViewer_ViewWindow.cxx | 111 ++++---- src/VTKViewer/resources/VTKViewer_msg_en.ts | 4 + src/VTKViewer/resources/VTKViewer_msg_fr.ts | 4 + 22 files changed, 701 insertions(+), 305 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index b4afefbed..c8ea9a9f5 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -2000,6 +2000,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) QStringList aValuesList; QList anIndicesList; QIntList idList; + QIntList txtList; // . Top-level "SALOME" preferences group <> int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) ); @@ -2127,14 +2128,18 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) // pref->setItemProperty( "columns", 2, bgGroup ); aValuesList.clear(); anIndicesList.clear(); - QString formats = OCCViewer_Viewer::backgroundData( aValuesList, idList ); + txtList.clear(); + QString formats = OCCViewer_Viewer::backgroundData( aValuesList, idList, txtList ); foreach( int gid, idList ) anIndicesList << gid; // .... -> 3D viewer 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( "texture_enabled", !txtList.isEmpty(), bgId ); + pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId ); + pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId ); + pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId ); pref->setItemProperty( "custom_enabled", false, bgId ); pref->setItemProperty( "image_formats", formats, bgId ); // .... -> XZ viewer background @@ -2142,7 +2147,10 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) 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( "texture_enabled", !txtList.isEmpty(), bgId ); + pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId ); + pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId ); + pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId ); pref->setItemProperty( "custom_enabled", false, bgId ); pref->setItemProperty( "image_formats", formats, bgId ); // .... -> YZ viewer background @@ -2150,7 +2158,10 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) 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( "texture_enabled", !txtList.isEmpty(), bgId ); + pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId ); + pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId ); + pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId ); pref->setItemProperty( "custom_enabled", false, bgId ); pref->setItemProperty( "image_formats", formats, bgId ); // .... -> XY viewer background @@ -2158,7 +2169,10 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) 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( "texture_enabled", !txtList.isEmpty(), bgId ); + pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId ); + pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId ); + pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId ); pref->setItemProperty( "custom_enabled", false, bgId ); pref->setItemProperty( "image_formats", formats, bgId ); // ... "Background" group <> @@ -2208,13 +2222,17 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) // .... -> background aValuesList.clear(); anIndicesList.clear(); - formats = SVTK_Viewer::backgroundData( aValuesList, idList ); + txtList.clear(); + formats = SVTK_Viewer::backgroundData( aValuesList, idList, txtList ); 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( "texture_enabled", !txtList.isEmpty(), bgId ); + pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId ); + pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId ); + pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId ); pref->setItemProperty( "custom_enabled", false, bgId ); pref->setItemProperty( "image_formats", formats, bgId ); // .... -> navigation mode @@ -3397,8 +3415,6 @@ void LightApp_Application::createEmptyStudy() /*!Set desktop:*/ void LightApp_Application::setDesktop( SUIT_Desktop* desk ) { - SUIT_Desktop* prev = desktop(); - CAM_Application::setDesktop( desk ); if ( desk ) { diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 8bd978269..8cf6ad1cd 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -63,10 +63,13 @@ #include +// VSR: Uncomment below line to allow texture background support in OCC viewer +// #define OCC_ENABLE_TEXTURED_BACKGROUND + /*! Get data for supported background modes: gradient types, identifiers and supported image formats */ -QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList ) +QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList ) { gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") << tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") << @@ -76,7 +79,12 @@ QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idLis Diagonal1Gradient << Diagonal2Gradient << Corner1Gradient << Corner2Gradient << Corner3Gradient << Corner4Gradient; - return QString(); // temporarily, means support of all image formars! +#if OCC_VERSION_LARGE > 0x06050200 // enabled since OCCT 6.5.3, since in previous version this functionality is buggy +#ifdef OCC_ENABLE_TEXTURED_BACKGROUND + txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture; +#endif +#endif + return tr("BG_IMAGE_FILES"); } /*! @@ -510,16 +518,17 @@ void OCCViewer_Viewer::onChangeBackground() // get supported gradient types QStringList gradList; - QIntList idList; - QString formats = backgroundData( gradList, idList ); + QIntList idList, txtList; + QString formats = backgroundData( gradList, idList, txtList ); // invoke dialog box - Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box - aView->background(), // initial background + Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background + aView, // parent for dialog box + txtList, // allowed texture modes true, // enable solid color mode - false, // disable texture mode true, // enable gradient mode false, // disable custom gradient mode + !txtList.isEmpty(), // enable/disable texture mode gradList, // gradient names idList, // gradient identifiers formats ); // image formats diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index b55e9d77f..455e36796 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -64,7 +64,7 @@ public: }; static QString Type() { return "OCCViewer"; } - static QString backgroundData( QStringList&, QIntList& ); + static QString backgroundData( QStringList&, QIntList&, QIntList& ); OCCViewer_Viewer( bool DisplayTrihedron = true); virtual ~OCCViewer_Viewer(); diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index e5174ba11..5af15af82 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -158,7 +158,7 @@ Handle( V3d_View ) OCCViewer_ViewPort3d::setView( const Handle( V3d_View )& view oldView->View()->Deactivate(); view->SetBackgroundColor( oldView->BackgroundColor() ); } - + if ( myDegenerated ) view->SetDegenerateModeOn(); else @@ -317,7 +317,7 @@ void OCCViewer_ViewPort3d::updateBackground() if ( !myBackground.isValid() ) return; // VSR: Important note on below code. - // In OCCT (at least in version 6.5.2), things about the background drawing + // In OCCT (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 (!!!). @@ -330,42 +330,23 @@ void OCCViewer_ViewPort3d::updateBackground() // (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. + // In OCCT 6.5.3 all above mentioned problems are fixed; so, above comment should be removed as soon + // as SALOME is migrated to OCCT 6.5.3. The same concerns #ifdef statements in the below code 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 ); +#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3 + activeView()->SetBgGradientStyle( Aspect_GFM_NONE ); // cancel gradient background + activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background +#else + // cancel gradient background (in OCC before v6.5.3 the only way to do this is to set it to NONE type passing arbitrary colors as parameters) activeView()->SetBgGradientColors( qCol, qCol, Aspect_GFM_NONE ); +#endif // then change background color activeView()->SetBackgroundColor( qCol ); // update viewer @@ -384,24 +365,41 @@ void OCCViewer_ViewPort3d::updateBackground() 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 ); + activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background switch ( type ) { case OCCViewer_Viewer::HorizontalGradient: - // in OCCT, to draw horizontal gradient it's necessary to use Aspect_GFM_VER type +#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3 + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True ); +#else + // in OCCT before v6.5.3, 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 ); +#endif break; case OCCViewer_Viewer::VerticalGradient: - // in OCCT, to draw vertical gradient it's necessary to use Aspect_GFM_HOR type +#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3 + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_VER, Standard_True ); +#else + // in OCCT before v6.5.3, to draw vertical gradient it's necessary to use Aspect_GFM_HOR type activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True ); +#endif break; case OCCViewer_Viewer::Diagonal1Gradient: - // in OCCT, to draw 1st dialognal gradient it's necessary to use Aspect_GFM_DIAG2 type +#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3 + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True ); +#else + // in OCCT before v6.5.3, 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 ); +#endif break; case OCCViewer_Viewer::Diagonal2Gradient: - // in OCCT, to draw 2nd dialognal gradient it's necessary to use Aspect_GFM_DIAG1 type +#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3 + activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG2, Standard_True ); +#else + // in OCCT before v6.5.3, to draw 2nd dialognal gradient it's necessary to use Aspect_GFM_DIAG1 type activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True ); +#endif break; case OCCViewer_Viewer::Corner1Gradient: activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True ); @@ -429,6 +427,32 @@ void OCCViewer_ViewPort3d::updateBackground() default: break; } +#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3 + // VSR: In OCCT before v6.5.3 below code can't be used because of very ugly bug - it has been impossible to + // clear the background texture image as soon as it was once set to the viewer. + if ( myBackground.isTextureShown() ) { + 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; + } + activeView()->Update(); + } + } +#endif } /*! @@ -518,7 +542,7 @@ void OCCViewer_ViewPort3d::pan( int dx, int dy ) /*! Inits 'rotation' transformation. [ protected ] */ -void OCCViewer_ViewPort3d::startRotation( int x, int y, +void OCCViewer_ViewPort3d::startRotation( int x, int y, int theRotationPointType, const gp_Pnt& theSelectedPoint ) { @@ -526,27 +550,27 @@ void OCCViewer_ViewPort3d::startRotation( int x, int y, myDegenerated = activeView()->DegenerateModeIsOn(); activeView()->SetDegenerateModeOn(); if (myAnimate) activeView()->SetAnimationModeOn(); - + //double gx, gy, gz; //double gx = activeView()->gx; //activeView()->Gravity(gx,gy,gz); - + switch ( theRotationPointType ) { case OCCViewer_ViewWindow::GRAVITY: activeView()->StartRotation( x, y, 0.45 ); break; case OCCViewer_ViewWindow::SELECTED: sx = x; sy = y; - + double X,Y; activeView()->Size(X,Y); - rx = Standard_Real(activeView()->Convert(X)); - ry = Standard_Real(activeView()->Convert(Y)); - - activeView()->Rotate( 0., 0., 0., - theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(), + rx = Standard_Real(activeView()->Convert(X)); + ry = Standard_Real(activeView()->Convert(Y)); + + activeView()->Rotate( 0., 0., 0., + theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(), Standard_True ); - + Quantity_Ratio zRotationThreshold; zRotation = Standard_False; zRotationThreshold = 0.45; @@ -567,7 +591,7 @@ void OCCViewer_ViewPort3d::startRotation( int x, int y, /*! Rotates the viewport. [ protected ] */ -void OCCViewer_ViewPort3d::rotate( int x, int y, +void OCCViewer_ViewPort3d::rotate( int x, int y, int theRotationPointType, const gp_Pnt& theSelectedPoint ) { @@ -579,7 +603,7 @@ void OCCViewer_ViewPort3d::rotate( int x, int y, case OCCViewer_ViewWindow::SELECTED: double dx, dy, dz; if( zRotation ) { - dz = atan2(Standard_Real(x)-rx/2., ry/2.-Standard_Real(y)) - + dz = atan2(Standard_Real(x)-rx/2., ry/2.-Standard_Real(y)) - atan2(sx-rx/2.,ry/2.-sy); dx = dy = 0.; } @@ -588,8 +612,8 @@ void OCCViewer_ViewPort3d::rotate( int x, int y, dy = (sy - Standard_Real(y)) * M_PI/ry; dz = 0.; } - - activeView()->Rotate( dx, dy, dz, + + activeView()->Rotate( dx, dy, dz, theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(), Standard_False ); break; @@ -695,8 +719,8 @@ void OCCViewer_ViewPort3d::rotateXY( double degrees ) activeView()->Convert( x, y, X, Y, Z ); activeView()->Rotate( 0, 0, degrees * M_PI / 180., X, Y, Z ); emit vpTransformed( this ); -} - +} + /*! Set axial scale to the view */ @@ -704,7 +728,7 @@ void OCCViewer_ViewPort3d::setAxialScale( double xScale, double yScale, double z { if ( activeView().IsNull() ) return; - + activeView()->SetAxialScale( xScale, yScale, zScale ); emit vpTransformed( this ); } @@ -734,7 +758,7 @@ bool OCCViewer_ViewPort3d::setWindow( const Handle(V3d_View)& view ) return !myWindow.IsNull(); } -void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view, +void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view, const Handle(Aspect_Window)& window) { if (!view.IsNull()) { @@ -776,7 +800,7 @@ bool OCCViewer_ViewPort3d::synchronize( OCCViewer_ViewPort* view ) { bool ok = false; OCCViewer_ViewPort3d* vp3d = qobject_cast( view ); - if ( vp3d ) { + if ( vp3d ) { bool blocked = blockSignals( false ); Handle(V3d_View) aView3d = getView(); Handle(V3d_View) aRefView3d = vp3d->getView(); @@ -808,5 +832,5 @@ void OCCViewer_ViewPort3d::updateStaticTriedronVisibility() { } aView->Update(); } - } + } } diff --git a/src/OCCViewer/resources/OCCViewer_msg_en.ts b/src/OCCViewer/resources/OCCViewer_msg_en.ts index 2eb1a3978..982a3bd3a 100644 --- a/src/OCCViewer/resources/OCCViewer_msg_en.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_en.ts @@ -271,10 +271,6 @@ OCC_IMAGE_FILES Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps) - - OCC_BG_IMAGE_FILES - Images Files (*.bmp *.gif *.pix *.xwd *.rgb *.rs) - DSC_MAXIMIZE_VIEW Maximize view @@ -415,6 +411,10 @@ GT_FORTHCORNERGRADIENT Fourth corner gradient + + BG_IMAGE_FILES + Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs) + OCCViewer_AxialScaleDlg diff --git a/src/OCCViewer/resources/OCCViewer_msg_fr.ts b/src/OCCViewer/resources/OCCViewer_msg_fr.ts index 03f4ab079..a4624b21e 100755 --- a/src/OCCViewer/resources/OCCViewer_msg_fr.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_fr.ts @@ -271,10 +271,6 @@ OCC_IMAGE_FILES Fichiers images (*.bmp *.png *.jpg *.jpeg *.eps *.ps) - - OCC_BG_IMAGE_FILES - Fichiers images (*.bmp *.gif *.pix *.xwd *.rgb *.rs) - DSC_MAXIMIZE_VIEW Maximiser la vue @@ -415,6 +411,10 @@ GT_FORTHCORNERGRADIENT Gradient du quatrième coin + + BG_IMAGE_FILES + Fichiers images (*.bmp *.gif *.pix *.xwd *.rgb *.rs) + OCCViewer_AxialScaleDlg diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index e71028ee4..dc0849ab1 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -1510,10 +1510,11 @@ bool Qtx::stringToConicalGradient( const QString& str, QConicalGradient& gradien 1. background type (enumerator, see Qtx::BackgroundMode) 2. texture image file name (string) 3. texture mode (enumerator, see Qtx::TextureMode) - 4. first color (for simple gradient data) or solid color (for single-colored mode) - 5. second color (for simple gradient data) - 6. type of simple gradient (some integer identifier) - 7. complex gradient data (for custom gradient mode) + 4. "show texture" flag (boolean) + 5. first color (for simple gradient data) or solid color (for single-colored mode) + 6. second color (for simple gradient data) + 7. type of simple gradient (some integer identifier) + 8. complex gradient data (for custom gradient mode) Each sub-string consists of keyword/value couple, in form of "=". Backward conversion can be done with stringToBackground() method. @@ -1530,6 +1531,7 @@ QString Qtx::backgroundToString( const Qtx::BackgroundData& bgData ) const QString kwBgType = "bt"; const QString kwFileName = "fn"; const QString kwTextureMode = "tm"; + const QString kwShowTexture = "ts"; const QString kwFirstColor = "c1"; const QString kwSecondColor = "c2"; const QString kwGrType = "gt"; @@ -1538,6 +1540,7 @@ QString Qtx::backgroundToString( const Qtx::BackgroundData& bgData ) Qtx::BackgroundMode bgMode = bgData.mode(); QString fileName; Qtx::TextureMode textureMode = bgData.texture( fileName ); + bool showTexture = bgData.isTextureShown(); QColor c1, c2; int gradientType = bgData.gradient( c1, c2 ); const QGradient* gradient = bgData.gradient(); @@ -1561,6 +1564,7 @@ QString Qtx::backgroundToString( const Qtx::BackgroundData& bgData ) data << QString( "%1%2%3" ).arg( kwBgType ).arg( kwSep ).arg( (int)bgMode ); data << QString( "%1%2%3" ).arg( kwFileName ).arg( kwSep ).arg( fileName ); data << QString( "%1%2%3" ).arg( kwTextureMode ).arg( kwSep ).arg( (int)textureMode ); + data << QString( "%1%2%3" ).arg( kwShowTexture ).arg( kwSep ).arg( showTexture ? "true" : "false" ); data << QString( "%1%2%3" ).arg( kwFirstColor ).arg( kwSep ).arg( Qtx::colorToString( c1 ) ); data << QString( "%1%2%3" ).arg( kwSecondColor ).arg( kwSep ).arg( Qtx::colorToString( c2 ) ); data << QString( "%1%2%3" ).arg( kwGrType ).arg( kwSep ).arg( gradientType ); @@ -1574,11 +1578,12 @@ QString Qtx::backgroundToString( const Qtx::BackgroundData& bgData ) The string should consist of several sub-strings separated by ';' symbol. Each sub-string consists of keyword/value couple, in form of "=". - The sub-strings can follow in arbitrary order, some keywords might be missed. + The sub-strings can follow in arbitrary order, some keywords can be missing. The background data is described by the following values: - background type (enumerator, see Qtx::BackgroundMode), keyword "bt" - texture image file name (string), keyword "fn" - texture mode (enumerator, see Qtx::TextureMode), keyword "tm" + - "show texture" flag (boolean), keyword "ts" - first color (for simple gradient data) or solid color (for single-colored mode), keyword "c1" - second color (for simple gradient data), keyword "c2" - name of gradient type (string), keyword "gt" @@ -1608,6 +1613,7 @@ Qtx::BackgroundData Qtx::stringToBackground( const QString& str ) const QString kwBgType = "bt"; const QString kwFileName = "fn"; const QString kwTextureMode = "tm"; + const QString kwShowTexture = "ts"; const QString kwFirstColor = "c1"; const QString kwSecondColor = "c2"; const QString kwGrType = "gt"; @@ -1636,16 +1642,20 @@ Qtx::BackgroundData Qtx::stringToBackground( const QString& str ) QString bgMode = dmap.value( kwBgType, QString() ); QString fileName = dmap.value( kwFileName, QString() ); QString textureMode = dmap.value( kwTextureMode, QString() ); + QString showTexture = dmap.value( kwShowTexture, QString() ); QString color1 = dmap.value( kwFirstColor, QString() ); QString color2 = dmap.value( kwSecondColor, QString() ); QString gradientType = dmap.value( kwGrType, QString() ); QString gradient = dmap.value( kwGrData, QString() ); - // try texture mode - if ( !fileName.isEmpty() || !textureMode.isEmpty() ) { + // texture data + if ( !fileName.isEmpty() || !textureMode.isEmpty() || !showTexture.isEmpty() ) { Qtx::TextureMode m = (Qtx::TextureMode)( stringToInt( textureMode, Qtx::CenterTexture, Qtx::CenterTexture, Qtx::StretchTexture ) ); bgData.setTexture( fileName, m ); + QStringList boolvars; boolvars << "true" << "yes" << "ok" << "1"; + if ( boolvars.contains( showTexture.trimmed().toLower() ) ) + bgData.setTextureShown( true ); } QColor c1, c2; // try color mode @@ -1676,9 +1686,9 @@ Qtx::BackgroundData Qtx::stringToBackground( const QString& str ) bgData.setGradient( cg ); } - // finally set backround mode - Qtx::BackgroundMode m = (Qtx::BackgroundMode)( stringToInt( bgMode, Qtx::ColorBackground, - Qtx::ImageBackground, Qtx::CustomGradientBackground ) ); + // finally set background mode + Qtx::BackgroundMode m = (Qtx::BackgroundMode)( stringToInt( bgMode, Qtx::ColorBackground, + Qtx::NoBackground, Qtx::CustomGradientBackground ) ); bgData.setMode( m ); } @@ -1730,19 +1740,21 @@ Qtx::Localizer::~Localizer() This class is used to store background data. Depending on the mode, the background can be specified by: - - image (by assigning the file name to be used as background texture), see setTexture() + - image (by assigning the file name to be used as background texture), see setTexture(), setTextureShown() - single color (by assigning any color), see setColor() - simple two-color gradient (with the gradient type id and two colors), see setGradient( int, const QColor&, const QColor& ) - complex gradient (by assigning arbitrary gradient data), see setGradient( const QGradient& ) + The class stores all the data passed to it, so switching between different modes can be done just by calling setMode() function. + \note Texture is used with combination of the background mode. + \note Two-color gradient is specified by two colors and integer identifier. The interpretation of this identifier should be done in the calling code. \code Qtx::BackgroundData bg; - bg.setTexture( "/data/images/background.png" ); // bg is switched to Qtx::ImageBackground mode bg.setColor( QColor(100, 100, 100) ); // bg is switched to Qtx::ColorBackground mode bg.setGradient( Qt::Horizontal, Qt::gray, Qt::white ); // bg is switched to Qtx::ColorBackground mode QLinearGradient grad( 0,0,1,1 ); @@ -1752,6 +1764,8 @@ Qtx::Localizer::~Localizer() grad.setSpread( QGradient::PadSpread ); bg.setGradient( grad ); // bg is switched to Qtx::CustomGradientBackground mode bg.setMode( Qtx::ColorBackground ); // bg is switched back to Qtx::ColorBackground mode + bg.setTexture( "/data/images/background.png" ); // specify texture (in the centered mode by default) + bg.setTextureShown( true ); // draw texture on the solid color background \endcode */ @@ -1760,7 +1774,7 @@ Qtx::Localizer::~Localizer() Creates invalid background data. */ Qtx::BackgroundData::BackgroundData() - : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ) + : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ), myTextureShown( false ) { setMode( Qtx::NoBackground ); } @@ -1771,7 +1785,7 @@ Qtx::BackgroundData::BackgroundData() \param c color */ Qtx::BackgroundData::BackgroundData( const QColor& c ) - : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ) + : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ), myTextureShown( false ) { setColor( c ); } @@ -1785,7 +1799,7 @@ Qtx::BackgroundData::BackgroundData( const QColor& c ) \note the interpretation of the gradient identifier should be done in the calling code */ Qtx::BackgroundData::BackgroundData( int type, const QColor& c1, const QColor& c2 ) - : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ) + : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ), myTextureShown( false ) { setGradient( type, c1, c2 ); } @@ -1796,7 +1810,7 @@ Qtx::BackgroundData::BackgroundData( int type, const QColor& c1, const QColor& c \param grad gradient data */ Qtx::BackgroundData::BackgroundData( const QGradient& grad ) - : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ) + : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ), myTextureShown( false ) { setGradient( grad ); } @@ -1819,7 +1833,8 @@ bool Qtx::BackgroundData::operator==( const Qtx::BackgroundData& other ) const ( myFileName == other.myFileName ) && ( myColors == other.myColors ) && ( myGradientType == other.myGradientType ) && - ( myGradient == other.myGradient ); + ( myGradient == other.myGradient ) && + ( myTextureShown == other.myTextureShown ); } /*! @@ -1855,7 +1870,7 @@ void Qtx::BackgroundData::setMode( const Qtx::BackgroundMode m ) /*! \brief Get file name used as a texture image \return path to the texture image file - \sa setTexture(), mode() + \sa setTexture(), setTextureShown() */ Qtx::TextureMode Qtx::BackgroundData::texture( QString& fileName ) const { @@ -1864,16 +1879,39 @@ Qtx::TextureMode Qtx::BackgroundData::texture( QString& fileName ) const } /*! - \brief Set file name to be used as a texture image and switch to the Qtx::ImageBackground mode + \brief Set file name to be used as a texture image. + + \note To show texture image on the background it is necessary to call additionally + setTextureShown() method. + \param fileName path to the texture image file name \param m texture mode (Qtx::CenterTexture by default) - \sa texture(), mode() + \sa texture(), setTextureShown() */ void Qtx::BackgroundData::setTexture( const QString& fileName, const Qtx::TextureMode m ) { myFileName = fileName; myTextureMode = m; - setMode( Qtx::ImageBackground ); +} + +/*! + \brief Check if "show texture" flag is switched on + \return \c true if "show texture" flag is set or \c false otherwise + \sa setTextureShown(), texture() +*/ +bool Qtx::BackgroundData::isTextureShown() const +{ + return myTextureShown; +} + +/*! + \brief Specify if texture should be shown on the background or no. + \param on \c true if texture should be shown or \c false otherwise + \sa isTextureShown(), texture() +*/ +void Qtx::BackgroundData::setTextureShown( bool on ) +{ + myTextureShown = on; } /*! diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index 464335113..1d8137716 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -133,7 +133,6 @@ public: //! Background mode typedef enum { NoBackground, // no (invalid) background data - ImageBackground, // image (texture) ColorBackground, // single color SimpleGradientBackground, // simple two-color gradient CustomGradientBackground // custom (complex) gradient @@ -175,6 +174,8 @@ public: TextureMode texture( QString& ) const; void setTexture( const QString&, TextureMode = Qtx::CenterTexture ); + bool isTextureShown() const; + void setTextureShown( bool ); QColor color() const; void setColor( const QColor& ); @@ -186,12 +187,13 @@ public: void setGradient( const QGradient& ); private: - BackgroundMode myMode; - TextureMode myTextureMode; - QString myFileName; - QColorList myColors; - int myGradientType; - QGradient myGradient; + BackgroundMode myMode; + TextureMode myTextureMode; + QString myFileName; + QColorList myColors; + int myGradientType; + QGradient myGradient; + bool myTextureShown; }; static QString toQString( const char*, const int = -1 ); diff --git a/src/Qtx/QtxBackgroundTool.cxx b/src/Qtx/QtxBackgroundTool.cxx index 3d18609d5..4feebef08 100644 --- a/src/Qtx/QtxBackgroundTool.cxx +++ b/src/Qtx/QtxBackgroundTool.cxx @@ -23,6 +23,7 @@ #include "QtxBackgroundTool.h" #include "QtxColorButton.h" +#include #include #include #include @@ -73,21 +74,27 @@ /*! \brief Constructor. + + Creates a background data widget with horizontal orientation. + \param parent parent widget */ QtxBackgroundTool::QtxBackgroundTool( QWidget* parent ) - : QWidget( parent ), myLastGradient( -1 ) + : QWidget( parent ), myTextureAllowed( true ), myLastGradient( -1 ) { init( Qt::Horizontal ); } /*! \brief Constructor. + + Creates a background data widget with specified orientation. + \param o widget orientation \param parent parent widget */ QtxBackgroundTool::QtxBackgroundTool( Qt::Orientation o, QWidget* parent ) - : QWidget( parent ), myLastGradient( -1 ) + : QWidget( parent ), myTextureAllowed( true ), myLastGradient( -1 ) { init( o ); } @@ -99,24 +106,28 @@ void QtxBackgroundTool::init( Qt::Orientation o ) { // mode combo box myModeCombo = new QComboBox( this ); - // sub-widgets container - myContainer = new QStackedWidget( this ); + // color / gradient sub-widgets container + myCContainer = new QStackedWidget( this ); + // texture sub-widgets container + myTContainer = new QWidget( this ); QWidget* wrap; QHBoxLayout* wrapLayout; // add image controls - wrap = new QWidget( this ); - wrapLayout = new QHBoxLayout( wrap ); + wrapLayout = new QHBoxLayout( myTContainer ); wrapLayout->setMargin( 0 ); wrapLayout->setSpacing( 5 ); - myFileName = new QLineEdit( wrap ); - myBrowseBtn = new QPushButton( tr( "Browse..." ), wrap ); - myTextureMode = new QComboBox( wrap ); + myTextureCheck = new QCheckBox( tr( "Image" ), myTContainer ); + myFileName = new QLineEdit( myTContainer ); + myFileName->setMinimumWidth(100); + myBrowseBtn = new QPushButton( tr( "Browse..." ), myTContainer ); + myTextureMode = new QComboBox( myTContainer ); + wrapLayout->addWidget( myTextureCheck ); wrapLayout->addWidget( myFileName ); wrapLayout->addWidget( myBrowseBtn ); wrapLayout->addWidget( myTextureMode ); - myContainer->addWidget( wrap ); // Image + wrapLayout->setStretchFactor(myFileName, 10); // add color controls wrap = new QWidget( this ); wrapLayout = new QHBoxLayout( wrap ); @@ -126,7 +137,9 @@ void QtxBackgroundTool::init( Qt::Orientation o ) mySecondColor = new QtxColorButton( wrap ); wrapLayout->addWidget( myFirstColor ); wrapLayout->addWidget( mySecondColor ); - myContainer->addWidget( wrap ); // Color + wrapLayout->setStretchFactor(myFirstColor, 5); + wrapLayout->setStretchFactor(mySecondColor, 5); + myCContainer->addWidget( wrap ); // Color // add gradient controls ... NOT IMPLEMENTED YET wrap = new QWidget( this ); wrapLayout = new QHBoxLayout( wrap ); @@ -135,22 +148,23 @@ void QtxBackgroundTool::init( Qt::Orientation o ) QLabel* foo = new QLabel( tr( "Not implemented yet" ), wrap ); foo->setAlignment( Qt::AlignCenter ); wrapLayout->addWidget( foo ); - myContainer->addWidget( wrap ); // Gradient + myCContainer->addWidget( wrap ); // Gradient // initialize widget myFirstColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); mySecondColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); - myTextureMode->addItem( tr( "Center" ), Qtx::CenterTexture ); - myTextureMode->addItem( tr( "Tile" ), Qtx::TileTexture ); - myTextureMode->addItem( tr( "Stretch" ), Qtx::StretchTexture ); connect( myModeCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateState() ) ); + connect( myTextureCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateState() ) ); connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browse() ) ); - setModeAllowed( Qtx::ImageBackground ); setModeAllowed( Qtx::ColorBackground ); setModeAllowed( Qtx::SimpleGradientBackground ); setModeAllowed( Qtx::CustomGradientBackground ); + setTextureModeAllowed( Qtx::CenterTexture ); + setTextureModeAllowed( Qtx::TileTexture ); + setTextureModeAllowed( Qtx::StretchTexture ); + setTextureAllowed(); setImageFormats( QString() ); setOrientation( o ); } @@ -175,9 +189,10 @@ Qtx::BackgroundData QtxBackgroundTool::data() const // get currently selected mode int id = myModeCombo->itemData( idx, TypeRole ).toInt(); // texture data - if ( isModeAllowed( Qtx::ImageBackground ) ) { + if ( isTextureAllowed() && myTextureMode->currentIndex() != -1 ) { bgData.setTexture( myFileName->text().trimmed(), Qtx::TextureMode( myTextureMode->itemData( myTextureMode->currentIndex() ).toInt() ) ); + bgData.setTextureShown( myTextureCheck->isChecked() ); } // single-color data if ( isModeAllowed( Qtx::ColorBackground ) ) { @@ -211,16 +226,26 @@ void QtxBackgroundTool::setData( const Qtx::BackgroundData& bgData ) int gtype = bgData.gradient( c1, c2 ); QString fileName; int tmode = bgData.texture( fileName ); + bool tshown = bgData.isTextureShown(); + // texture data myFileName->setText( fileName ); - myTextureMode->setCurrentIndex( tmode ); + for ( int i = 0; i < myTextureMode->count(); i++ ) { + if ( myTextureMode->itemData( i ).toInt() == tmode ) { + myTextureMode->setCurrentIndex( i ); + break; + } + } + myTextureCheck->setChecked( tshown ); + // color / simple gradient data myFirstColor->setColor( c1 ); mySecondColor->setColor( c2 ); + // gradient data // ... NOT IMPLEMENTED YET - // set current index + // set current mode index int idx = -1; for ( int i = 0; i < myModeCombo->count() && idx == -1; i++ ) { int im = myModeCombo->itemData( i, TypeRole ).toInt(); @@ -230,8 +255,12 @@ void QtxBackgroundTool::setData( const Qtx::BackgroundData& bgData ) if ( it == gtype ) idx = i; } // for other modes we just check mode itself - else if ( im == m ) idx = i; + else if ( im == m ) { + idx = i; + } } + // if background data is invalid, we set-up widget to the first available type + if ( idx == -1 && myModeCombo->count() > 0 ) idx = 0; myModeCombo->setCurrentIndex( idx ); } @@ -253,10 +282,10 @@ void QtxBackgroundTool::gradients( QStringList& gradList, QIntList& idList ) con */ void QtxBackgroundTool::setGradients( const QStringList& gradList, const QIntList& idList ) { - myGradients = gradList; - myGradientsIds = idList; - myLastGradient = -1; - Qtx::BackgroundData d = data(); // store current state + Qtx::BackgroundData d = data(); // get current state + myGradients = gradList; // store new gradient data + myGradientsIds = idList; // ... + myLastGradient = -1; // ... internalUpdate(); // re-initialize setData( d ); // restore current state (if possible) } @@ -275,7 +304,7 @@ bool QtxBackgroundTool::isModeAllowed( Qtx::BackgroundMode mode ) const /*! \brief Enable / disable specific background mode \param mode background mode - \param on enable / disable flag + \param on enable / disable flag (\c true by default) \sa isModeAllowed() */ void QtxBackgroundTool::setModeAllowed( Qtx::BackgroundMode mode, bool on ) @@ -283,10 +312,62 @@ void QtxBackgroundTool::setModeAllowed( Qtx::BackgroundMode mode, bool on ) if ( mode == Qtx::CustomGradientBackground ) return; // NOT IMPLEMENTED YET // - myTypesAllowed[ mode ] = on; - Qtx::BackgroundData d = data(); // store current state - internalUpdate(); // re-initialize - setData( d ); // restore current state (if possible) + if ( isModeAllowed( mode ) != on ) { + Qtx::BackgroundData d = data(); // get current state + myTypesAllowed[ mode ] = on; // store new background mode state + internalUpdate(); // re-initialize + setData( d ); // restore current state (if possible) + } +} + +/*! + \brief Check if specific texture mode is allowed + \param mode texture mode + \return \c true if specified texture mode is enabled or \c false otherwise + \sa setTextureModeAllowed(), setTextureAllowed() +*/ +bool QtxBackgroundTool::isTextureModeAllowed( Qtx::TextureMode mode ) const +{ + return myTextureTypesAllowed.contains( mode ) ? myTextureTypesAllowed[ mode ] : false; +} + +/*! + \brief Enable / disable specific texture mode + \param mode texture mode + \param on enable / disable flag (\c true by default) + \sa isTextureModeAllowed(), setTextureAllowed() +*/ +void QtxBackgroundTool::setTextureModeAllowed( Qtx::TextureMode mode, bool on ) +{ + if ( isTextureModeAllowed( mode ) != on ) { + Qtx::BackgroundData d = data(); // get current state + myTextureTypesAllowed[ mode ] = on; // store new texture mode + internalUpdate(); // re-initialize + setData( d ); // restore current state (if possible) + } +} + +/*! + \brief Check if texture controls are allowed (shown) + \return \c true if texture controls are enabled or \c false otherwise + \sa setTextureAllowed(), setTextureModeAllowed() +*/ +bool QtxBackgroundTool::isTextureAllowed() const +{ + return myTextureAllowed; +} + +/*! + \brief Enable / disable texture controls + \param on enable / disable flag (\c true by default) + \sa isTextureAllowed(), setTextureModeAllowed() +*/ +void QtxBackgroundTool::setTextureAllowed( bool on ) +{ + if ( myTextureAllowed != on ) { + myTextureAllowed = on; + setOrientation( orientation() ); + } } /*! @@ -330,7 +411,10 @@ void QtxBackgroundTool::setOrientation( Qt::Orientation orientation ) l->setMargin( 0 ); l->setSpacing( 5 ); l->addWidget( myModeCombo ); - l->addWidget( myContainer ); + l->addWidget( myCContainer ); + myTContainer->setVisible( isTextureAllowed() ); + if ( isTextureAllowed() ) + l->addWidget( myTContainer ); delete layout(); setLayout( l ); } @@ -342,21 +426,13 @@ void QtxBackgroundTool::setOrientation( Qt::Orientation orientation ) void QtxBackgroundTool::internalUpdate() { myModeCombo->clear(); - if ( isModeAllowed( Qtx::ImageBackground ) ) { - myModeCombo->addItem( tr( "Image" ) ); - int idx = myModeCombo->count()-1; - myModeCombo->setItemData( idx, (int)Qtx::ImageBackground, TypeRole ); - } if ( isModeAllowed( Qtx::ColorBackground ) ) { - if ( myModeCombo->count() > 0 ) - myModeCombo->insertSeparator( myModeCombo->count() ); myModeCombo->addItem( tr( "Single Color" ) ); - int idx = myModeCombo->count()-1; - myModeCombo->setItemData( idx, (int)Qtx::ColorBackground, TypeRole ); + myModeCombo->setItemData( 0, (int)Qtx::ColorBackground, TypeRole ); } if ( isModeAllowed( Qtx::SimpleGradientBackground ) ) { - if ( myGradients.count() > 0 && myModeCombo->count() > 0 ) - myModeCombo->insertSeparator( myModeCombo->count() ); +// if ( myGradients.count() > 0 && myModeCombo->count() > 0 ) +// myModeCombo->insertSeparator( myModeCombo->count() ); for ( int i = 0; i < myGradients.count(); i++ ) { myModeCombo->addItem( myGradients[i] ); int idx = myModeCombo->count()-1; @@ -365,12 +441,21 @@ void QtxBackgroundTool::internalUpdate() } } if ( isModeAllowed( Qtx::CustomGradientBackground ) ) { - if ( myModeCombo->count() > 0 ) - myModeCombo->insertSeparator( myModeCombo->count() ); +// if ( myModeCombo->count() > 0 ) +// myModeCombo->insertSeparator( myModeCombo->count() ); myModeCombo->addItem( tr( "Custom" ) ); int idx = myModeCombo->count()-1; myModeCombo->setItemData( idx, (int)Qtx::CustomGradientBackground, TypeRole ); } + + myTextureMode->clear(); + if ( isTextureModeAllowed( Qtx::CenterTexture ) ) + myTextureMode->addItem( tr( "Center" ), Qtx::CenterTexture ); + if ( isTextureModeAllowed( Qtx::TileTexture ) ) + myTextureMode->addItem( tr( "Tile" ), Qtx::TileTexture ); + if ( isTextureModeAllowed( Qtx::StretchTexture ) ) + myTextureMode->addItem( tr( "Stretch" ), Qtx::StretchTexture ); + updateState(); } @@ -384,22 +469,25 @@ void QtxBackgroundTool::updateState() if ( idx >= 0 ) { id = myModeCombo->itemData( idx, TypeRole ).toInt(); switch( id ) { - case Qtx::ImageBackground: - myContainer->setCurrentIndex( Image ); - break; case Qtx::ColorBackground: + myCContainer->setCurrentIndex( Color ); + break; case Qtx::SimpleGradientBackground: - myContainer->setCurrentIndex( Color ); + myCContainer->setCurrentIndex( Color ); myLastGradient = myModeCombo->itemData( idx, IdRole ).toInt(); break; case Qtx::CustomGradientBackground: - myContainer->setCurrentIndex( Gradient ); + myCContainer->setCurrentIndex( Gradient ); break; } } myModeCombo->setEnabled( idx >= 0 ); - myContainer->setEnabled( idx >= 0 ); + myCContainer->setEnabled( idx >= 0 ); mySecondColor->setEnabled( id == Qtx::SimpleGradientBackground ); + myTContainer->setEnabled( idx >= 0 ); + myFileName->setEnabled( myTextureCheck->isChecked() ); + myBrowseBtn->setEnabled( myTextureCheck->isChecked() ); + myTextureMode->setEnabled( myTextureCheck->isChecked() ); } /*! @@ -462,6 +550,7 @@ QtxBackgroundDialog::QtxBackgroundDialog( const Qtx::BackgroundData& bgData, QWi : QtxDialog( parent, true, true, OK | Cancel ) { init(); + setData( bgData ); } /*! @@ -482,6 +571,8 @@ void QtxBackgroundDialog::init() setDialogFlags( SetFocus ); // move "Cancel" button to the right setButtonPosition( Right, Cancel ); + // set OK button to be default (activated by Enter key) + qobject_cast( button( OK ) )->setDefault( true ); // main layout QVBoxLayout* main = new QVBoxLayout( mainFrame() ); @@ -531,6 +622,27 @@ void QtxBackgroundDialog::setModeAllowed( Qtx::BackgroundMode mode, bool on ) myTool->setModeAllowed( mode, on ); } +/*! + \brief Enable / disable texture controls + \param on enable / disable flag + \sa setTextureModeAllowed() +*/ +void QtxBackgroundDialog::setTextureAllowed( bool on ) +{ + myTool->setTextureAllowed( on ); +} + +/*! + \brief Enable / disable specific texture mode + \param mode texture mode + \param on enable / disable flag (\c true by default) + \sa setTextureAllowed() +*/ +void QtxBackgroundDialog::setTextureModeAllowed( Qtx::TextureMode mode, bool on ) +{ + myTool->setTextureModeAllowed( mode, on ); +} + /*! \brief Set allowed image formats \param formats image formats @@ -543,19 +655,91 @@ void QtxBackgroundDialog::setImageFormats( const QString& formats ) /*! \brief This is a convenience static function that returns an background data selected by the user. If the user presses Cancel, it returns an invalid background data. + + By default: + - all background modes are enabled + - texture controls are shown + - all texture modes are enabled + - simple gradient types list is empty + - all image formats are supported + + To customize the dialog box behavior, initialize it passing the corresponding options to the function. + + \param bgData initial background data + \param parent parent widget + \param enableSolidColor "enable solid colored background mode" flag + \param enableGradient "enable simple gradient background mode" flag + \param enableCustom "enable custom gradient background mode" flag + \param enableTexture "show texture controls" flag + \param gradList list of simple gradients names + \param idList list of simple gradients identifiers + \param formats image formats + \return resulting background data chosen by the user or invalid data if users cancels operation */ -Qtx::BackgroundData QtxBackgroundDialog::getBackground( QWidget* parent, - const Qtx::BackgroundData& bgData, +Qtx::BackgroundData QtxBackgroundDialog::getBackground( const Qtx::BackgroundData& bgData, + QWidget* parent, bool enableSolidColor, + bool enableGradient, + bool enableCustom, bool enableTexture, + const QStringList& gradList, + const QIntList& idList, + const QString& formats ) +{ + QtxBackgroundDialog dlg( parent ); + dlg.setTextureAllowed( enableTexture ); + dlg.setModeAllowed( Qtx::ColorBackground, enableSolidColor ); + dlg.setModeAllowed( Qtx::SimpleGradientBackground, enableGradient ); + dlg.setModeAllowed( Qtx::CustomGradientBackground, enableCustom ); + dlg.setGradients( gradList, idList ); + dlg.setImageFormats( formats ); + dlg.setData( bgData ); + Qtx::BackgroundData res; + int rc = dlg.exec(); + if ( rc ) res = dlg.data(); + return res; +} + +/*! + \brief This is a convenience static function that returns an background data selected by the user. + If the user presses Cancel, it returns an invalid background data. + + By default: + - all background modes are enabled + - texture controls are shown + - all texture modes are disabled + - simple gradient types list is empty + - all image formats are supported + + To customize the dialog box behavior, initialize it passing the corresponding options to the function. + + \param bgData initial background data + \param parent parent widget + \param tmList allowed texture modes + \param enableSolidColor "enable solid colored background mode" flag + \param enableGradient "enable simple gradient background mode" flag + \param enableCustom "enable custom gradient background mode" flag + \param enableTexture "show texture controls" flag + \param gradList list of simple gradients names + \param idList list of simple gradients identifiers + \param formats image formats + \return resulting background data chosen by the user or invalid data if users cancels operation +*/ +Qtx::BackgroundData QtxBackgroundDialog::getBackground( const Qtx::BackgroundData& bgData, + QWidget* parent, + const QIntList& tmList, + bool enableSolidColor, bool enableGradient, bool enableCustom, + bool enableTexture, const QStringList& gradList, const QIntList& idList, const QString& formats ) { QtxBackgroundDialog dlg( parent ); - dlg.setModeAllowed( Qtx::ImageBackground, enableTexture ); + dlg.setTextureAllowed( enableTexture ); + for ( int i = Qtx::CenterTexture; i <= Qtx::StretchTexture; i++ ) + dlg.setTextureModeAllowed( (Qtx::TextureMode)i, tmList.contains( i ) ); dlg.setModeAllowed( Qtx::ColorBackground, enableSolidColor ); dlg.setModeAllowed( Qtx::SimpleGradientBackground, enableGradient ); dlg.setModeAllowed( Qtx::CustomGradientBackground, enableCustom ); diff --git a/src/Qtx/QtxBackgroundTool.h b/src/Qtx/QtxBackgroundTool.h index cf6fc689d..f676f124b 100644 --- a/src/Qtx/QtxBackgroundTool.h +++ b/src/Qtx/QtxBackgroundTool.h @@ -29,6 +29,7 @@ #include #include +class QCheckBox; class QComboBox; class QStackedWidget; class QLineEdit; @@ -37,7 +38,7 @@ class QtxColorButton; class QTX_EXPORT QtxBackgroundTool : public QWidget { - enum { Image, Color, Gradient }; + enum { Color, Gradient }; enum { TypeRole = Qt::UserRole, IdRole }; Q_OBJECT @@ -56,6 +57,12 @@ public: bool isModeAllowed( Qtx::BackgroundMode ) const; void setModeAllowed( Qtx::BackgroundMode, bool = true ); + bool isTextureModeAllowed( Qtx::TextureMode ) const; + void setTextureModeAllowed( Qtx::TextureMode, bool = true ); + + bool isTextureAllowed() const; + void setTextureAllowed( bool = true ); + QString imageFormats() const; void setImageFormats( const QString& ); @@ -72,7 +79,9 @@ private slots: private: QComboBox* myModeCombo; - QStackedWidget* myContainer; + QStackedWidget* myCContainer; + QWidget* myTContainer; + QCheckBox* myTextureCheck; QLineEdit* myFileName; QPushButton* myBrowseBtn; QComboBox* myTextureMode; @@ -80,7 +89,9 @@ private: QtxColorButton* mySecondColor; QStringList myGradients; QIntList myGradientsIds; + bool myTextureAllowed; QMap myTypesAllowed; + QMap myTextureTypesAllowed; QString myImageFormats; int myLastGradient; }; @@ -97,15 +108,25 @@ public: void setData( const Qtx::BackgroundData& ); Qtx::BackgroundData data() const; - static Qtx::BackgroundData getBackground( QWidget* = 0, - const Qtx::BackgroundData& = Qtx::BackgroundData(), + static Qtx::BackgroundData getBackground( const Qtx::BackgroundData& = Qtx::BackgroundData(), + QWidget* = 0, bool = true, bool = true, bool = true, bool = true, const QStringList& = QStringList(), const QIntList& = QIntList(), const QString& = QString() ); + static Qtx::BackgroundData getBackground( const Qtx::BackgroundData&, + QWidget*, + const QIntList&, + bool = true, bool = true, bool = true, bool = true, + const QStringList& = QStringList(), + const QIntList& = QIntList(), + const QString& = QString() ); + void setGradients( const QStringList&, const QIntList& = QIntList() ); void setModeAllowed( Qtx::BackgroundMode, bool = true ); + void setTextureAllowed( bool = true ); + void setTextureModeAllowed( Qtx::TextureMode, bool = true ); void setImageFormats( const QString& ); private: diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 888ca1c50..2bfbc9114 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -4522,11 +4522,15 @@ void QtxPagePrefShortcutTreeItem::store() - simple two-color gradient - complex custom gradient (NOT IMPLEMENTED YET) - Allows background modes can be specified using setModeAllowed() method. + Allowed background modes can be specified using setModeAllowed() method. + Texture modes can be enabled/disabled using setTextureModeAllowed() method. + Also, showing texture controls can be enabled/disabled by means of + setTextureAllowed() method. Verical or horizontal orientation of the widget can be chosen via setOrientation() method (default orientation is horizontal). Simple gradient types can be specified using setGradients() method. + \sa Qtx::BackgroundData, QtxBackgroundTool */ @@ -4593,6 +4597,48 @@ void QtxPagePrefBackgroundItem::setModeAllowed( Qtx::BackgroundMode mode, bool o myBgTool->setModeAllowed( mode, on ); } +/*! + \brief Check if specific texture mode is allowed + \param mode texture mode + \return \c true if specified texture mode is enabled or \c false otherwise + \sa setTextureModeAllowed(), setTextureAllowed() +*/ +bool QtxPagePrefBackgroundItem::isTextureModeAllowed( Qtx::TextureMode mode ) const +{ + return myBgTool->isTextureModeAllowed( mode ); +} + +/*! + \brief Enable / disable specific texture mode + \param mode texture mode + \param on enable / disable flag (\c true by default) + \sa isTextureModeAllowed(), setTextureAllowed() +*/ +void QtxPagePrefBackgroundItem::setTextureModeAllowed( Qtx::TextureMode mode, bool on ) +{ + myBgTool->setTextureModeAllowed( mode, on ); +} + +/*! + \brief Check if texture controls are allowed (shown) + \return \c true if texture controls are enabled or \c false otherwise + \sa setTextureAllowed(), setTextureModeAllowed() +*/ +bool QtxPagePrefBackgroundItem::isTextureAllowed() const +{ + return myBgTool->isTextureAllowed(); +} + +/*! + \brief Enable / disable texture controls + \param on enable / disable flag (\c true by default) + \sa isTextureAllowed(), setTextureModeAllowed() +*/ +void QtxPagePrefBackgroundItem::setTextureAllowed( bool on ) +{ + myBgTool->setTextureAllowed( on ); +} + /*! \brief Get allowed image formats \return image formats @@ -4656,13 +4702,19 @@ void QtxPagePrefBackgroundItem::retrieve() QVariant QtxPagePrefBackgroundItem::optionValue( const QString& name ) const { if ( name == "texture_enabled" ) - return isModeAllowed( Qtx::ImageBackground ); + return isTextureAllowed(); else if ( name == "color_enabled" ) return isModeAllowed( Qtx::ColorBackground ); else if ( name == "gradient_enabled" ) return isModeAllowed( Qtx::SimpleGradientBackground ); else if ( name == "custom_enabled" ) return isModeAllowed( Qtx::CustomGradientBackground ); + else if ( name == "texture_center_enabled" ) + return isTextureModeAllowed( Qtx::CenterTexture ); + else if ( name == "texture_tile_enabled" ) + return isTextureModeAllowed( Qtx::TileTexture ); + else if ( name == "texture_stretch_enabled" ) + return isTextureModeAllowed( Qtx::StretchTexture ); else if ( name == "orientation" ) return orientation(); else if ( name == "image_formats" ) @@ -4696,7 +4748,7 @@ void QtxPagePrefBackgroundItem::setOptionValue( const QString& name, const QVari { if ( name == "texture_enabled" ) { if ( val.canConvert( QVariant::Bool ) ) - setModeAllowed( Qtx::ImageBackground, val.toBool() ); + setTextureAllowed( val.toBool() ); } else if ( name == "color_enabled" ) { if ( val.canConvert( QVariant::Bool ) ) @@ -4710,6 +4762,18 @@ void QtxPagePrefBackgroundItem::setOptionValue( const QString& name, const QVari if ( val.canConvert( QVariant::Bool ) ) setModeAllowed( Qtx::CustomGradientBackground, val.toBool() ); } + else if ( name == "texture_center_enabled" ) { + if ( val.canConvert( QVariant::Bool ) ) + setTextureModeAllowed( Qtx::CenterTexture, val.toBool() ); + } + else if ( name == "texture_tile_enabled" ) { + if ( val.canConvert( QVariant::Bool ) ) + setTextureModeAllowed( Qtx::TileTexture, val.toBool() ); + } + else if ( name == "texture_stretch_enabled" ) { + if ( val.canConvert( QVariant::Bool ) ) + setTextureModeAllowed( Qtx::StretchTexture, val.toBool() ); + } else if ( name == "orientation" ) { if ( val.canConvert( QVariant::Int ) ) setOrientation( (Qt::Orientation)val.toInt() ); diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index b9686bc42..93648a557 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -778,7 +778,13 @@ public: void setGradients( const QStringList&, const QIntList& = QIntList() ); bool isModeAllowed( Qtx::BackgroundMode ) const; - void setModeAllowed( Qtx::BackgroundMode, bool = true ); + void setModeAllowed( Qtx::BackgroundMode, bool ); + + bool isTextureModeAllowed( Qtx::TextureMode ) const; + void setTextureModeAllowed( Qtx::TextureMode, bool ); + + bool isTextureAllowed() const; + void setTextureAllowed( bool ); QString imageFormats() const; void setImageFormats( const QString& ); diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 513284867..ec2e587dc 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -47,6 +47,10 @@ #include "QtxActionToolMgr.h" #include "QtxBackgroundTool.h" +// VSR: Uncomment below line to allow texture background support in VTK viewer +// #define VTK_ENABLE_TEXTURED_BACKGROUND + + // 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 // SALOMEDS::StudyManager - no linkage with SalomeApp. @@ -97,11 +101,14 @@ SVTK_Viewer::~SVTK_Viewer() } /*! Get data for supported background modes: gradient types, identifiers and supported image formats */ -QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList ) +QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList ) { - gradList << tr( "GT_VERTICALGRADIENT" ); - idList << VerticalGradient; - return QString(); // temporarily, means support of all image formats! + gradList << tr( "GT_VERTICALGRADIENT" ); // only vertical type of gradient is supported + idList << VerticalGradient; // only vertical type of gradient is supported +#ifdef VTK_ENABLE_TEXTURED_BACKGROUND + txtList << Qtx::StretchTexture; // only stretch texture mode is supported +#endif + return tr("BG_IMAGE_FILES"); } //! Get background color of the viewer [obsolete] @@ -504,16 +511,17 @@ void SVTK_Viewer::onChangeBackground() // get supported gradient types QStringList gradList; - QIntList idList; - QString formats = backgroundData( gradList, idList ); + QIntList idList, txtList; + QString formats = backgroundData( gradList, idList, txtList ); // invoke dialog box - Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box - aView->background(), // initial background + Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background + aView, // parent for dialog box + txtList, // allowed texture modes true, // enable solid color mode - false, // disable texture mode true, // enable gradient mode false, // disable custom gradient mode + !txtList.isEmpty(), // enable texture mode gradList, // gradient names idList, // gradient identifiers formats ); // image formats diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index 9fa34c32e..05dc8cf77 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -56,7 +56,7 @@ public: //! Define string representation of the viewer type static QString Type() { return "VTKViewer"; } - static QString backgroundData( QStringList&, QIntList& ); + static QString backgroundData( QStringList&, QIntList&, QIntList& ); SVTK_Viewer(); virtual ~SVTK_Viewer(); diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index f724eb7df..05ecc1993 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -570,11 +570,61 @@ QColor SVTK_ViewWindow::backgroundColor() const */ void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) { - bool ok = bgData.isValid(); - - switch ( bgData.mode() ) { - case Qtx::ImageBackground: - { + bool ok = false; + + if ( bgData.isValid() ) { + switch ( bgData.mode() ) { + 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 ( bgData.isTextureShown() ) { QString fileName; int textureMode = bgData.texture( fileName ); QFileInfo fi( fileName ); @@ -596,7 +646,7 @@ void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) // create texture aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() ); aReader->Update(); - + vtkTexture* aTexture = vtkTexture::New(); vtkImageMapToColors* aMap = 0; vtkAlgorithmOutput* anOutput; @@ -604,18 +654,18 @@ void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) // special processing for BMP reader vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader; if ( aBMPReader ) { - // Special processing for BMP file - aBMPReader->SetAllow8BitBMP(1); + // Special processing for BMP file + aBMPReader->SetAllow8BitBMP(1); - aMap = vtkImageMapToColors::New(); - aMap->SetInputConnection( aBMPReader->GetOutputPort() ); - aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() ); - aMap->SetOutputFormatToRGB(); + aMap = vtkImageMapToColors::New(); + aMap->SetInputConnection( aBMPReader->GetOutputPort() ); + aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() ); + aMap->SetOutputFormatToRGB(); - anOutput = aMap->GetOutputPort(); + anOutput = aMap->GetOutputPort(); } else { - } + } */ anOutput = aReader->GetOutputPort( 0 ); aTexture->SetInputConnection( anOutput ); @@ -652,57 +702,7 @@ void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) 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; diff --git a/src/SVTK/resources/SVTK_msg_en.ts b/src/SVTK/resources/SVTK_msg_en.ts index be884e276..ec3a19da1 100644 --- a/src/SVTK/resources/SVTK_msg_en.ts +++ b/src/SVTK/resources/SVTK_msg_en.ts @@ -599,5 +599,9 @@ Please, refer to the documentation. GT_VERTICALGRADIENT Vertical gradient + + BG_IMAGE_FILES + Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha) + diff --git a/src/SVTK/resources/SVTK_msg_fr.ts b/src/SVTK/resources/SVTK_msg_fr.ts index a490016ed..b4f06d86f 100755 --- a/src/SVTK/resources/SVTK_msg_fr.ts +++ b/src/SVTK/resources/SVTK_msg_fr.ts @@ -599,5 +599,9 @@ Veuillez consulter la documentation. GT_VERTICALGRADIENT Gradient vertical + + BG_IMAGE_FILES + Fichiers images (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha) + diff --git a/src/VTKViewer/VTKViewer_ViewModel.cxx b/src/VTKViewer/VTKViewer_ViewModel.cxx index af301c3ae..67eb90e13 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.cxx +++ b/src/VTKViewer/VTKViewer_ViewModel.cxx @@ -35,6 +35,9 @@ #include #include +// VSR: Uncomment below line to allow texture background support in VTK viewer +// #define VTK_ENABLE_TEXTURED_BACKGROUND + bool _InitializeVtkWarningsCall() { char* isOn = getenv( "VTK_WARNINGS_IS_ON" ); @@ -59,11 +62,14 @@ VTKViewer_Viewer::~VTKViewer_Viewer() } /*! Get data for supported background modes: gradient types, identifiers and supported image formats */ -QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList ) +QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList ) { - gradList << tr( "GT_VERTICALGRADIENT" ); - idList << VerticalGradient; - return QString(); // temporarily, means support of all image formats! + gradList << tr( "GT_VERTICALGRADIENT" ); // only vertical type of gradient is supported + idList << VerticalGradient; // only vertical type of gradient is supported +#ifdef VTK_ENABLE_TEXTURED_BACKGROUND + txtList << Qtx::StretchTexture; // only stretch texture mode is supported +#endif + return tr("BG_IMAGE_FILES"); } /*!Gets background color [obsolete]*/ @@ -216,16 +222,17 @@ void VTKViewer_Viewer::onChangeBackground() // get supported gradient types QStringList gradList; - QIntList idList; - QString formats = backgroundData( gradList, idList ); + QIntList idList, txtList; + QString formats = backgroundData( gradList, idList, txtList ); // invoke dialog box - Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box - aView->background(), // initial background + Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background + aView, // parent for dialog box + txtList, // allowed texture modes true, // enable solid color mode - false, // disable texture mode true, // enable gradient mode false, // disable custom gradient mode + !txtList.isEmpty(), // enable texture mode gradList, // gradient names idList, // gradient identifiers formats ); // image formats diff --git a/src/VTKViewer/VTKViewer_ViewModel.h b/src/VTKViewer/VTKViewer_ViewModel.h index 27235b90f..d0dee3dc4 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.h +++ b/src/VTKViewer/VTKViewer_ViewModel.h @@ -47,7 +47,7 @@ public: /*!Initialize type of viewer.*/ static QString Type() { return "VTKViewer"; } - static QString backgroundData( QStringList&, QIntList& ); + static QString backgroundData( QStringList&, QIntList&, QIntList& ); VTKViewer_Viewer(); virtual ~VTKViewer_Viewer(); diff --git a/src/VTKViewer/VTKViewer_ViewWindow.cxx b/src/VTKViewer/VTKViewer_ViewWindow.cxx index 57c803aa0..abaa6cec0 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.cxx +++ b/src/VTKViewer/VTKViewer_ViewWindow.cxx @@ -462,11 +462,61 @@ QColor VTKViewer_ViewWindow::backgroundColor() const /*!Set background of the viewport*/ void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) { - bool ok = bgData.isValid(); - - switch ( bgData.mode() ) { - case Qtx::ImageBackground: - { + bool ok = false; + + if ( bgData.isValid() ) { + switch ( bgData.mode() ) { + 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; + } + if ( bgData.isTextureShown() ) { QString fileName; int textureMode = bgData.texture( fileName ); QFileInfo fi( fileName ); @@ -544,58 +594,9 @@ void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) 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; } + if ( ok ) myBackground = bgData; } diff --git a/src/VTKViewer/resources/VTKViewer_msg_en.ts b/src/VTKViewer/resources/VTKViewer_msg_en.ts index 5c104ae24..a05fe00af 100644 --- a/src/VTKViewer/resources/VTKViewer_msg_en.ts +++ b/src/VTKViewer/resources/VTKViewer_msg_en.ts @@ -223,5 +223,9 @@ GT_VERTICALGRADIENT Vertical gradient + + BG_IMAGE_FILES + Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha) + diff --git a/src/VTKViewer/resources/VTKViewer_msg_fr.ts b/src/VTKViewer/resources/VTKViewer_msg_fr.ts index 2cbf9c0f0..56f65130a 100755 --- a/src/VTKViewer/resources/VTKViewer_msg_fr.ts +++ b/src/VTKViewer/resources/VTKViewer_msg_fr.ts @@ -223,5 +223,9 @@ GT_VERTICALGRADIENT Gradient vertical + + BG_IMAGE_FILES + Fichiers images (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha) + -- 2.39.2