]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
0021179: EDF 1654 SMESH GEOM: better look'n'feel
authorvsr <vsr@opencascade.com>
Wed, 15 Feb 2012 12:53:15 +0000 (12:53 +0000)
committervsr <vsr@opencascade.com>
Wed, 15 Feb 2012 12:53:15 +0000 (12:53 +0000)
Introduce gradient background in the 3D viewer

27 files changed:
src/LightApp/LightApp_Application.cxx
src/LightApp/resources/LightApp_msg_en.ts
src/LightApp/resources/LightApp_msg_fr.ts
src/OCCViewer/OCCViewer_ViewFrame.cxx
src/OCCViewer/OCCViewer_ViewFrame.h
src/OCCViewer/OCCViewer_ViewModel.cxx
src/OCCViewer/OCCViewer_ViewModel.h
src/OCCViewer/OCCViewer_ViewPort.cxx
src/OCCViewer/OCCViewer_ViewPort.h
src/OCCViewer/OCCViewer_ViewPort3d.cxx
src/OCCViewer/OCCViewer_ViewPort3d.h
src/OCCViewer/OCCViewer_ViewWindow.cxx
src/OCCViewer/OCCViewer_ViewWindow.h
src/OCCViewer/resources/OCCViewer_msg_en.ts
src/OCCViewer/resources/OCCViewer_msg_fr.ts
src/SVTK/SVTK_ViewModel.cxx
src/SVTK/SVTK_ViewModel.h
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h
src/SVTK/resources/SVTK_msg_en.ts
src/SVTK/resources/SVTK_msg_fr.ts
src/VTKViewer/VTKViewer_ViewModel.cxx
src/VTKViewer/VTKViewer_ViewModel.h
src/VTKViewer/VTKViewer_ViewWindow.cxx
src/VTKViewer/VTKViewer_ViewWindow.h
src/VTKViewer/resources/VTKViewer_msg_en.ts
src/VTKViewer/resources/VTKViewer_msg_fr.ts

index c588752835f3c9976eb81f1328a09971b9d03a1b..398306a2fead46db07742a263602c5a21d9fa1b3 100644 (file)
@@ -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<VTKViewer_Viewer*>( 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<QVariant> anIndicesList;
+  QIntList        idList;
 
   // . Top-level "SALOME" preferences group <<start>>
   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
@@ -2154,19 +2154,43 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
 
   // ... "Background" group <<start>>
   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 <<end>>
 
   // ... -> empty frame (for layout) <<start>>
@@ -2201,7 +2225,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
 
   // ... -> empty frame (for layout) <<start>>
   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 <<start>>
   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" );
index 00ca4253d34e7edcd6a3ba2c51ff1a6aa20c9863..8d573e77129bf03ea4ddb31e9da94eb71b725fbf 100644 (file)
@@ -528,6 +528,10 @@ The changes will be applied on the next application session.</translation>
     </message>
     <message>
         <source>PREF_VIEWER_BACKGROUND</source>
+        <translation>Background</translation>
+    </message>
+    <message>
+        <source>PREF_VIEWER_BACKGROUND_COLOR</source>
         <translation>Background color</translation>
     </message>
     <message>
index 915e617c3107629b84aa5ca5e23a8f24ec4a9071..eff2c633a1ba78c60a902e57a4f32bbf7d360751 100755 (executable)
@@ -528,6 +528,10 @@ Les modifications seront appliquées à la prochaine session.</translation>
     </message>
     <message>
         <source>PREF_VIEWER_BACKGROUND</source>
+        <translation>Arrière-plan</translation>
+    </message>
+    <message>
+        <source>PREF_VIEWER_BACKGROUND_COLOR</source>
         <translation>Couleur de l&apos;arrière-plan</translation>
     </message>
     <message>
index e8a855f5c9e1ee15787ccc0479ff8a5c7d8813bc..3fd668516cd8055109de1b60dde374255ebd957a 100644 (file)
 #include <QLayout>
 #include <QApplication>
 
+class VisEvent : public QEvent
+{
+public:
+  VisEvent( const QMap<int,bool>& visMap ) : QEvent( QEvent::User ), myVisMap( visMap )
+  {}
+  QMap<int,bool> 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<OCCViewer_Viewer*>(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<int,bool> 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<VisEvent*>( e );
+    QMap<int,bool> visMap = ve->myVisMap;
+    for ( int i = 0 ; i < myViews.count(); i++ )
+      myViews[i]->setVisible( visMap.contains( i ) && visMap[i] );
+  }
+}
index f1396d7a6b19d0fbc4f9fb4305a20e640b2df127..52ff9d1abb1413c3e06f8c956bce1c0cefcd279c 100644 (file)
@@ -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();
index 9d94adff635f89ce66cde86bf4333d5ee2c36e38..9196394dcbb9dd7e60b0d47c4c02cc896a9a1058 100755 (executable)
@@ -33,6 +33,7 @@
 #include "SUIT_ResourceMgr.h"
 
 #include "QtxActionToolMgr.h"
+#include "QtxBackgroundTool.h"
 
 #include <QPainter>
 #include <QApplication>
 
 #include <Visual3d_View.hxx>
 
+/*!
+  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<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
   if ( !aView )
     return;
-  
-  QColor selColor = QColorDialog::getColor( aView->backgroundColor(), aView );
-  if ( selColor.isValid() )
-    aView->setBackgroundColor(selColor);
-}
 
-/*!
-  SLOT: called if background image is to be changed changed, passes new image to view port in centered mode
-*/
-void OCCViewer_Viewer::onChangeBgImageCentered()
-{
-  OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
-  if ( !aView )
-    return;
-  
-  QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_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<OCCViewer_ViewWindow*>(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<OCCViewer_ViewWindow*>(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;    
 }
 
 
index 5c5c7bfe2e95e328c2dbfdc01ee870c23f20036f..bda8ce7827a065a3b3b7eb8767970a766354bca8 100755 (executable)
@@ -29,6 +29,7 @@
 
 #include "OCCViewer.h"
 
+#include "Qtx.h"
 #include "SUIT_ViewModel.h"
 
 #include <V3d_View.hxx>
@@ -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<QColor>                 myColors;
+  QVector<Qtx::BackgroundData>    myBackgrounds;
 };
 
 #ifdef WIN32
index ea81421cb7ad5a37a3372dd02c6aa2742afdf194..055c88b1df1782eb01978424f3f6fa2c198a2b6c 100755 (executable)
@@ -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() )
index 69b80490be9de8e8119d9feaf2251344f569e175..092b6fa8491d95104091a1e4c4f5af8cf81112b4 100755 (executable)
@@ -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<QtxAction*>              myPopupActions;
-
+  
 private:
   static int                     nCounter; /* objects counter */
 };
index 1480975416a225b9708bef2f4ea8a34f08f2c5da..e5174ba11362d5f10ceda9dadb3f20dd2099b0ef 100755 (executable)
@@ -31,6 +31,7 @@
 #include <SUIT_ViewModel.h>
 
 #include <QColor>
+#include <QFileInfo>
 #include <QString>
 #include <QRect>
 #include <QPaintEvent>
@@ -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();
+  }
 }
 
 /*!
index ea977007bdc1446c85cf7b42022ef52edda9d8a9..6739ff58b8a110bd98a498c0e382c135c3c652a4 100755 (executable)
@@ -24,6 +24,7 @@
 #define OCCVIEWER_VIEWPORT3D_H
 
 #include "OCCViewer_ViewPort.h"
+#include "Qtx.h"
 
 #include <V3d_View.hxx>
 
@@ -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;
 };
index 6c900b90b9b7efb0a6dc62fc228876f329a05458..d514bc1f61477c40e2d6de7e62c769056667a08e 100755 (executable)
@@ -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 );
 }
 
 /*!
index bb91bc1e11016455d840a02112e4b1755c5899ba..79e86bcbb0ad9f3e89682eb0eda2dca3f220d5f2 100755 (executable)
@@ -24,6 +24,7 @@
 #define OCCVIEWER_VIEWWINDOW_H
 
 #include "OCCViewer.h"
+#include "Qtx.h"
 #include "SUIT_ViewWindow.h"
 #include <gp_Pnt.hxx>
 #include <V3d_Plane.hxx>
@@ -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& );
index 1fe32ce8ef26be750195470c8ed44532582206bd..2eb1a39780ffaa2909fee3c8d4eeff447f833b0e 100644 (file)
         <source>STRETCHED</source>
         <translation>in stretched mode</translation>
     </message>
+    <message>
+        <source>GT_HORIZONTALGRADIENT</source>
+        <translation>Horizontal gradient</translation>
+    </message>
+    <message>
+        <source>GT_VERTICALGRADIENT</source>
+        <translation>Vertical gradient</translation>
+    </message>
+    <message>
+        <source>GT_FIRSTDIAGONALGRADIENT</source>
+        <translation>First diagonal gradient</translation>
+    </message>
+    <message>
+        <source>GT_SECONDDIAGONALGRADIENT</source>
+        <translation>Second diagonal gradient</translation>
+    </message>
+    <message>
+        <source>GT_FIRSTCORNERGRADIENT</source>
+        <translation>First corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_SECONDCORNERGRADIENT</source>
+        <translation>Second corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_THIRDCORNERGRADIENT</source>
+        <translation>Third corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_FORTHCORNERGRADIENT</source>
+        <translation>Fourth corner gradient</translation>
+    </message>
 </context>
 <context>
     <name>OCCViewer_AxialScaleDlg</name>
index a5091053e411ba216d241322e6a18ab3184dce36..f234e638a4f33d093dd1313703ec3f7b82803b8e 100755 (executable)
         <source>STRETCHED</source>
         <translation>en mode étiré</translation>
     </message>
+    <message>
+        <source>GT_HORIZONTALGRADIENT</source>
+        <translation type="unfinished">Horizontal gradient</translation>
+    </message>
+    <message>
+        <source>GT_VERTICALGRADIENT</source>
+        <translation type="unfinished">Vertical gradient</translation>
+    </message>
+    <message>
+        <source>GT_FIRSTDIAGONALGRADIENT</source>
+        <translation type="unfinished">First diagonal gradient</translation>
+    </message>
+    <message>
+        <source>GT_SECONDDIAGONALGRADIENT</source>
+        <translation type="unfinished">Second diagonal gradient</translation>
+    </message>
+    <message>
+        <source>GT_FIRSTCORNERGRADIENT</source>
+        <translation type="unfinished">First corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_SECONDCORNERGRADIENT</source>
+        <translation type="unfinished">Second corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_THIRDCORNERGRADIENT</source>
+        <translation type="unfinished">Third corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_FORTHCORNERGRADIENT</source>
+        <translation type="unfinished">Fourth corner gradient</translation>
+    </message>
 </context>
 <context>
     <name>OCCViewer_AxialScaleDlg</name>
index 10ac9944c27ee0856859c7e42de838c1989f3253..513284867cedc40efee76a706a94be1a10fb2c05 100644 (file)
@@ -44,7 +44,8 @@
 
 #include "SALOME_Actor.h"
 
-#include <QtxActionToolMgr.h>
+#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<SUIT_ViewWindow*> 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<TViewWindow*>(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<SVTK_ViewWindow*>(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 );
 }
 
 /*!
index c0313279ef90eb7bdae1abeb5c08401649f8c689..9fa34c32e07b3ca88a3abf221a2808b6c5c83f42 100644 (file)
@@ -26,6 +26,8 @@
 #include "SVTK.h"
 #include "SVTK_ViewModelBase.h"
 
+#include "Qtx.h"
+
 #include <SALOME_Prs.h>
 #include <SALOME_InteractiveObject.hxx>
 #include <SALOME_ListIO.hxx>
@@ -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
index 0a84e834a2feaa9b8b3cb42d98924fe82153abac..f724eb7df73a24a58ccbc93f208430424d46567f 100755 (executable)
 #include "SVTK_CubeAxesDlg.h"
 #include "SVTK_SetRotationPointDlg.h"
 #include "SVTK_ViewParameterDlg.h"
+#include "SVTK_ViewModel.h"
 
 #include "SALOME_Actor.h"
 
 #include <QMenu>
 #include <QToolBar>
 #include <QEvent>
+#include <QFileInfo>
 #include <QXmlStreamWriter>
 #include <QXmlStreamReader>
 #include <QXmlStreamAttributes>
 #include <vtkInteractorStyle.h>
 #include <vtkProperty.h>
 #include <vtkCallbackCommand.h>
+#include <vtkJPEGReader.h>
+#include <vtkBMPReader.h>
+#include <vtkTIFFReader.h>
+#include <vtkPNGReader.h>
+#include <vtkMetaImageReader.h>
+#include <vtkImageMapToColors.h>
+#include <vtkTexture.h>
 
 #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();
index 0e713d57abffc144484457450634db2ec652ab88..fd93854784eebec9408e8485c14f8b61ae513a10 100755 (executable)
@@ -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);
index ad4d257bffe66077bd56220ccf12cccaed476ac8..be884e2760d59e5b73202882039a4b753b558af7 100644 (file)
@@ -595,5 +595,9 @@ Please, refer to the documentation.</translation>
         <source>MEN_CHANGE_BACKGROUD</source>
         <translation>Change background...</translation>
     </message>
+    <message>
+        <source>GT_VERTICALGRADIENT</source>
+        <translation>Vertical gradient</translation>
+    </message>
 </context>
 </TS>
index dad72288594898d7d2c51d697dbf364711c09cb6..3aca7a7702791e1ed883124096888d258a0432e9 100755 (executable)
@@ -595,5 +595,9 @@ Veuillez consulter la documentation.</translation>
         <source>MEN_CHANGE_BACKGROUD</source>
         <translation>Changer l&apos;arrière-plan...</translation>
     </message>
+    <message>
+        <source>GT_VERTICALGRADIENT</source>
+        <translation type="unfinished">Vertical gradient</translation>
+    </message>
 </context>
 </TS>
index db7f32916e3d4c01206fdaea25dec4c9f68d4c53..af301c3aec6fd3e4c670c170f85edb7fde0bad85 100755 (executable)
@@ -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.*/
index a0fae50b3a0cfff37b00d8faf3eb5b7526fc4a4d..27235b90fec2d4feb52ef4875bb03b2bf391ee3e 100755 (executable)
@@ -24,6 +24,7 @@
 #define VTKVIEWER_VIEWMODEL_H
 
 #include "VTKViewer.h"
+#include "Qtx.h"
 #include "SUIT_ViewModel.h"
 
 #include <QColor>
@@ -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
index ada19bce43a4d724cbcba1700acb0220632d3609..57c803aa0502f303780558dd257d558f714f5085 100755 (executable)
 #include <SUIT_Tools.h>
 #include <SUIT_ResourceMgr.h>
 
+#include <QFileInfo>
 #include <QImage>
 
 #include <vtkRenderer.h>
 #include <vtkCamera.h>
+#include <vtkJPEGReader.h>
+#include <vtkBMPReader.h>
+#include <vtkTIFFReader.h>
+#include <vtkPNGReader.h>
+#include <vtkMetaImageReader.h>
+#include <vtkImageMapToColors.h>
+#include <vtkTexture.h>
 
 #include <QtxToolBar.h>
 #include <QtxMultiAction.h>
@@ -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.*/
index 6d2a90552ef85930fa19930845530457dd0071db..eea03b277298cff959103783924aecacbf89d10e 100755 (executable)
@@ -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;
 };
index 8e3fa136e58e361ca4446f07bb3b865d7e1e8c44..5c104ae24e04dcb749f38dd5176d8a073177def3 100644 (file)
         <source>MEN_CHANGE_BACKGROUD</source>
         <translation>Change Background...</translation>
     </message>
+    <message>
+        <source>GT_VERTICALGRADIENT</source>
+        <translation>Vertical gradient</translation>
+    </message>
 </context>
 </TS>
index d848beef5b4e96b02b60194adf98fc746c9ca993..c087673cdd1013845443041cada795ecc519beb1 100755 (executable)
         <source>MEN_CHANGE_BACKGROUD</source>
         <translation>Changer l&apos;arrière-plan...</translation>
     </message>
+    <message>
+        <source>GT_VERTICALGRADIENT</source>
+        <translation type="unfinished">Vertical gradient</translation>
+    </message>
 </context>
 </TS>