+ if ( bgData.isValid() ) {
+ myBackground = bgData;
+ updateBackground();
+ emit vpChangeBackground( myBackground );
+ }
+}
+
+void OCCViewer_ViewPort3d::updateBackground()
+{
+ if ( activeView().IsNull() ) return;
+ if ( !myBackground.isValid() ) return;
+
+ switch ( myBackground.mode() ) {
+ case Qtx::ColorBackground:
+ {
+ QColor c = myBackground.color();
+ if ( c.isValid() ) {
+ // Unset texture should be done here
+ // ...
+ Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
+ activeView()->SetBgGradientStyle( Aspect_GFM_NONE ); // cancel gradient background
+ activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background
+ // 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 );
+ activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background
+ switch ( type ) {
+ case OCCViewer_Viewer::HorizontalGradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
+ break;
+ case OCCViewer_Viewer::VerticalGradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_VER, Standard_True );
+ break;
+ case OCCViewer_Viewer::Diagonal1Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
+ break;
+ case OCCViewer_Viewer::Diagonal2Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG2, 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;
+ }
+ 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();
+ }