Salome HOME
Updated copyright comment
[modules/gui.git] / src / VTKViewer / VTKViewer_ViewWindow.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 6c04f32..f088c2e
@@ -1,21 +1,25 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "VTKViewer_ViewWindow.h"
 #include "VTKViewer_ViewModel.h"
 #include "VTKViewer_RenderWindow.h"
 #include "VTKViewer_Trihedron.h"
 #include "VTKViewer_Transform.h"
 #include "VTKViewer_Utilities.h"
+#include "VTKViewer_Texture.h"
+#include "VTKViewer_OpenGLRenderer.h"
 
-#include "SUIT_Session.h"
-#include "SUIT_ToolButton.h"
-#include "SUIT_MessageBox.h"
+#include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Tools.h>
+#include <SUIT_ResourceMgr.h>
 
-#include "SUIT_Tools.h"
-#include "SUIT_ResourceMgr.h"
+#include <QFileInfo>
+#include <QImage>
 
-#include <qapplication.h>
-
-#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>
 
 /*! Construction*/
 VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop, 
                                             VTKViewer_Viewer* theModel,
-                                           VTKViewer_InteractorStyle* iStyle,
-                                           VTKViewer_RenderWindowInteractor* rw )
+                                            VTKViewer_InteractorStyle* iStyle,
+                                            VTKViewer_RenderWindowInteractor* rw )
 : SUIT_ViewWindow( theDesktop )
 {
   myModel = theModel;
 
   myTrihedron = VTKViewer_Trihedron::New();
   myTransform = VTKViewer_Transform::New();
-  myRenderer  = vtkRenderer::New() ;
+  myRenderer  = VTKViewer_OpenGLRenderer::New() ;
 
   myTrihedron->AddToRender( myRenderer );
 
   myRenderWindow = new VTKViewer_RenderWindow( this, "RenderWindow" );
   setCentralWidget(myRenderWindow);
-  myRenderWindow->setFocusPolicy( StrongFocus );
+  myRenderWindow->setFocusPolicy( Qt::StrongFocus );
   myRenderWindow->setFocus();
 
   myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
@@ -63,16 +77,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() );
@@ -87,9 +91,9 @@ VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop,
 
   setCentralWidget( myRenderWindow );
 
-  myToolBar = new QToolBar(this);
-  myToolBar->setCloseMode(QDockWindow::Undocked);
-  myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
+  myToolBar = new QtxToolBar( true, tr("LBL_TOOLBAR_LABEL"), this );
+  myToolBar->setObjectName( "VTKViewerViewOperations" );
+  myToolBar->setFloatable( false );
 
   createActions();
   createToolBar();
@@ -116,6 +120,9 @@ VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop,
            this,           SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
 
 
+  // set default background
+  setBackground( Qtx::BackgroundData( Qt::black ) );
+  // reset view
   onResetView();
 }
 
@@ -130,7 +137,7 @@ VTKViewer_ViewWindow::~VTKViewer_ViewWindow()
   myRWInteractor->Delete();
   
   //m_RW->Delete() ;
-  myRenderer->RemoveAllProps();
+  myRenderer->RemoveAllViewProps();
   //m_Renderer->Delete() ;
   myTrihedron->Delete();
 }
@@ -184,134 +191,162 @@ void VTKViewer_ViewWindow::createActions()
   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
                            tr( "MNU_DUMP_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
   myActionsMap[ DumpId ] = aAction;
 
   //! \li FitAll
   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
                            tr( "MNU_FITALL" ), 0, this);
   aAction->setStatusTip(tr("DSC_FITALL"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
   myActionsMap[ FitAllId ] = aAction;
 
   //! \li FitRect
   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
                            tr( "MNU_FITRECT" ), 0, this);
   aAction->setStatusTip(tr("DSC_FITRECT"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
   myActionsMap[ FitRectId ] = aAction;
 
+  //! \li FitSelection
+  aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ),
+                           tr( "MNU_FITSELECTION" ), 0, this);
+  aAction->setStatusTip(tr("DSC_FITSELECTION"));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
+  myActionsMap[ FitSelectionId ] = aAction;
+
   //! \li Zoom
   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
                            tr( "MNU_ZOOM_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
   myActionsMap[ ZoomId ] = aAction;
 
   //! \li Panning
   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
                            tr( "MNU_PAN_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
   myActionsMap[ PanId ] = aAction;
 
   //! \li Global Panning
   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
   myActionsMap[ GlobalPanId ] = aAction;
 
   //! \li Rotation
   aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
                            tr( "MNU_ROTATE_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
   myActionsMap[ RotationId ] = aAction;
 
   //! \li Projections
   aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
                            tr( "MNU_FRONT_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
   myActionsMap[ FrontId ] = aAction;
 
   //! \li Back view
   aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
                            tr( "MNU_BACK_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_BACK_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
   myActionsMap[ BackId ] = aAction;
 
   //! \li Top view
   aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
                            tr( "MNU_TOP_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_TOP_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
   myActionsMap[ TopId ] = aAction;
 
   //! \li Bottom view
   aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
                            tr( "MNU_BOTTOM_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
   myActionsMap[ BottomId ] = aAction;
 
   //! \li Left view
   aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
                            tr( "MNU_LEFT_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
   myActionsMap[ LeftId ] = aAction;
 
   //! \li Right view
   aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
                            tr( "MNU_RIGHT_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
   myActionsMap[ RightId ] = aAction;
 
+  // \li Rotate anticlockwise
+  aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
+                         tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this);
+  aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
+  myActionsMap[ AntiClockWiseId ] = aAction;
+
+  // \li Rotate clockwise
+  aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
+                         tr( "MNU_CLOCKWISE_VIEW" ), 0, this);
+  aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
+  myActionsMap[ ClockWiseId ] = aAction;
+
   //! \li Reset
   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
                            tr( "MNU_RESET_VIEW" ), 0, this);
   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
   myActionsMap[ ResetId ] = aAction;
 
   //! \li Trihedron shown
   aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
                            tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
   aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onTrihedronShow()));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
   myActionsMap[ TrihedronShowId ] = aAction;
 }
 
 /*!Create tool bar.*/
 void VTKViewer_ViewWindow::createToolBar()
 {
-  myActionsMap[DumpId]->addTo(myToolBar);
-  myActionsMap[TrihedronShowId]->addTo(myToolBar);
+  myToolBar->addAction( myActionsMap[DumpId] );
+  myToolBar->addAction( myActionsMap[TrihedronShowId] );
+
+  QtxMultiAction* aScaleAction = new QtxMultiAction( this );
+  aScaleAction->insertAction( myActionsMap[FitAllId] );
+  aScaleAction->insertAction( myActionsMap[FitRectId] );
+  aScaleAction->insertAction( myActionsMap[FitSelectionId] );
+  aScaleAction->insertAction( myActionsMap[ZoomId] );
+  myToolBar->addAction( aScaleAction );
 
-  SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
-  aScaleBtn->AddAction(myActionsMap[FitAllId]);
-  aScaleBtn->AddAction(myActionsMap[FitRectId]);
-  aScaleBtn->AddAction(myActionsMap[ZoomId]);
+  QtxMultiAction* aPanningAction = new QtxMultiAction( this );
+  aPanningAction->insertAction( myActionsMap[PanId] );
+  aPanningAction->insertAction( myActionsMap[GlobalPanId] );
+  myToolBar->addAction( aPanningAction );
 
-  SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
-  aPanningBtn->AddAction(myActionsMap[PanId]);
-  aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
+  myToolBar->addAction( myActionsMap[RotationId] );
 
-  myActionsMap[RotationId]->addTo(myToolBar);
+  QtxMultiAction* aViewsAction = new QtxMultiAction(myToolBar);
+  aViewsAction->insertAction( myActionsMap[FrontId] );
+  aViewsAction->insertAction( myActionsMap[BackId] );
+  aViewsAction->insertAction( myActionsMap[TopId] );
+  aViewsAction->insertAction( myActionsMap[BottomId] );
+  aViewsAction->insertAction( myActionsMap[LeftId] );
+  aViewsAction->insertAction( myActionsMap[RightId] );
+  myToolBar->addAction( aViewsAction );
 
-  SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
-  aViewsBtn->AddAction(myActionsMap[FrontId]);
-  aViewsBtn->AddAction(myActionsMap[BackId]);
-  aViewsBtn->AddAction(myActionsMap[TopId]);
-  aViewsBtn->AddAction(myActionsMap[BottomId]);
-  aViewsBtn->AddAction(myActionsMap[LeftId]);
-  aViewsBtn->AddAction(myActionsMap[RightId]);
+  myToolBar->addAction( myActionsMap[AntiClockWiseId] );
+  myToolBar->addAction( myActionsMap[ClockWiseId] );
 
-  myActionsMap[ResetId]->addTo(myToolBar);
+  myToolBar->addAction( myActionsMap[ResetId] );
 }
 
 /*!On front view event.*/
@@ -374,6 +409,28 @@ void VTKViewer_ViewWindow::onRightView()
   onFitAll();
 }
 
+/*!
+  \brief Rotate view 90 degrees clockwise
+*/
+void VTKViewer_ViewWindow::onClockWiseView()
+{
+  vtkCamera* aCamera = myRenderer->GetActiveCamera(); 
+  aCamera->Roll(-90);
+  aCamera->OrthogonalizeViewUp();
+  Repaint();
+}
+
+/*!
+  \brief Rotate view 90 degrees conterclockwise
+*/
+void VTKViewer_ViewWindow::onAntiClockWiseView()
+{
+  vtkCamera* aCamera = myRenderer->GetActiveCamera(); 
+  aCamera->Roll(90);
+  aCamera->OrthogonalizeViewUp();
+  Repaint();
+}
+
 /*!On reset view slot.*/
 void VTKViewer_ViewWindow::onResetView()
 {
@@ -386,7 +443,7 @@ void VTKViewer_ViewWindow::onResetView()
   ::ResetCamera(myRenderer,true);  
   if(aTriedronIsVisible) myTrihedron->VisibilityOn();
   else myTrihedron->VisibilityOff();
-  static float aCoeff = 3.0;
+  static double aCoeff = 3.0;
   aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
   Repaint();
 }
@@ -398,22 +455,173 @@ void VTKViewer_ViewWindow::onFitAll()
   Repaint();
 }
 
-/*!Set background of the viewport*/
-void VTKViewer_ViewWindow::setBackgroundColor( const QColor& color )
+/*!On fit selection slot.*/
+void VTKViewer_ViewWindow::onFitSelection()
 {
-  if ( myRenderer )
-    myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
+  myRWInteractor->GetInteractorStyle()->ViewFitSelection();
+  Repaint();
 }
 
-/*!Returns background of the viewport*/
+/*!Set background color of the viewport [obsolete]*/
+void VTKViewer_ViewWindow::setBackgroundColor( const QColor& c )
+{
+  Qtx::BackgroundData bg = background();
+  bg.setColor( c );
+  setBackground( bg );
+}
+
+/*!Returns background color of the viewport [obsolete]*/
 QColor VTKViewer_ViewWindow::backgroundColor() const
 {
-  float 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 = false;
+  if ( bgData.isValid() ) {
+    switch ( bgData.mode() ) {
+    case Qtx::ColorBackground:
+      {
+       QColor c = bgData.color();
+       if ( c.isValid() ) {
+         // show solid-colored background
+         getRenderer()->SetTexturedBackground( false );  // cancel texture mode
+         getRenderer()->SetGradientBackground( false );  // cancel gradient mode
+         getRenderer()->SetBackground( c.red()/255.0,
+                                       c.green()/255.0,
+                                       c.blue()/255.0 ); // set background color
+         ok = true;
+       }
+       break;
+      }
+    case Qtx::SimpleGradientBackground:
+      {
+       QColor c1, c2;
+       int type = bgData.gradient( c1, c2 );
+        if ( c1.isValid() )
+        {
+          if ( !c2.isValid() )
+            c2 = c1;
+
+          // show two-color gradient background
+          getRenderer()->SetTexturedBackground( false );    // cancel texture mode
+          getRenderer()->SetGradientBackground( true );     // switch to gradient mode
+
+          VTKViewer_OpenGLRenderer* aRenderer =
+            VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
+          if( aRenderer )
+          {
+            aRenderer->SetGradientType( type );
+            aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
+            aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
+            ok = true;
+          }
+        }
+       break;
+      }
+    case Qtx::CustomGradientBackground:
+      {
+       // NOT IMPLEMENTED YET
+       getRenderer()->SetTexturedBackground( false );  // cancel texture mode
+       getRenderer()->SetGradientBackground( false );  // cancel gradient mode
+       // .........
+       break;
+      }
+    default:
+      break;
+    }
+    if ( bgData.isTextureShown() ) {
+      QString fileName;
+      int textureMode = bgData.texture( fileName );
+      QFileInfo fi( fileName );
+      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().toUtf8().constData() );
+         aReader->Update();
+         
+         VTKViewer_Texture* aTexture = VTKViewer_Texture::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;
+       }
+      }
+    }
   }
-  return SUIT_ViewWindow::backgroundColor();
+
+  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.*/
@@ -442,11 +650,11 @@ void VTKViewer_ViewWindow::onAdjustTrihedron(){
   int aVisibleNum = myTrihedron->GetVisibleActorCount(myRenderer);
   if(aVisibleNum){
     // calculating diagonal of visible props of the renderer
-    float bnd[6];
+    double bnd[6];
     myTrihedron->VisibilityOff();
     ::ComputeVisiblePropBounds(myRenderer,bnd);
     myTrihedron->VisibilityOn();
-    float aLength = 0;
+    double aLength = 0;
     static bool CalcByDiag = false;
     if(CalcByDiag){
       aLength = sqrt((bnd[1]-bnd[0])*(bnd[1]-bnd[0])+
@@ -454,17 +662,17 @@ void VTKViewer_ViewWindow::onAdjustTrihedron(){
                      (bnd[5]-bnd[4])*(bnd[5]-bnd[4]));
     }else{
       aLength = bnd[1]-bnd[0];
-      aLength = max((bnd[3]-bnd[2]),aLength);
-      aLength = max((bnd[5]-bnd[4]),aLength);
+      aLength = qMax((bnd[3]-bnd[2]),aLength);
+      aLength = qMax((bnd[5]-bnd[4]),aLength);
     }
    
-    static float aSizeInPercents = 105;
+    static double aSizeInPercents = 105;
     QString aSetting;// = SUIT_CONFIG->getSetting("Viewer:TrihedronSize");
     if(!aSetting.isEmpty()) aSizeInPercents = aSetting.toFloat();
 
-    static float EPS_SIZE = 5.0E-3;
-    float aSize = myTrihedron->GetSize();
-    float aNewSize = aLength*aSizeInPercents/100.0;
+    static double EPS_SIZE = 5.0E-3;
+    double aSize = myTrihedron->GetSize();
+    double aNewSize = aLength*aSizeInPercents/100.0;
     // if the new trihedron size have sufficient difference, then apply the value
     if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE){
       myTrihedron->SetSize(aNewSize);
@@ -556,5 +764,56 @@ void VTKViewer_ViewWindow::onTrihedronShow()
 QImage VTKViewer_ViewWindow::dumpView()
 {
   QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
-  return px.convertToImage();
+  return px.toImage();
+}
+
+/*! The method returns the visual parameters of this view as a formated string
+ */
+QString VTKViewer_ViewWindow::getVisualParameters()
+{
+  double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
+
+  vtkCamera* camera = myRenderer->GetActiveCamera();
+  camera->GetPosition( pos );
+  camera->GetFocalPoint( focalPnt );
+  camera->GetViewUp( viewUp );
+  parScale = camera->GetParallelScale();
+  GetScale( scale );
+
+  QString retStr;
+  retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", 
+                  pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], viewUp[0], viewUp[1], 
+                  viewUp[2], parScale, scale[0], scale[1], scale[2] );
+  return retStr;
+}
+
+/*! The method restors visual parameters of this view from a formated string
+ */
+void VTKViewer_ViewWindow::setVisualParameters( const QString& parameters )
+{
+  QStringList paramsLst = parameters.split( '*' );
+  if ( paramsLst.size() == 13 ) {
+    double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
+    pos[0] = paramsLst[0].toDouble();
+    pos[1] = paramsLst[1].toDouble();
+    pos[2] = paramsLst[2].toDouble();
+    focalPnt[0] = paramsLst[3].toDouble();
+    focalPnt[1] = paramsLst[4].toDouble();
+    focalPnt[2] = paramsLst[5].toDouble();
+    viewUp[0] = paramsLst[6].toDouble();
+    viewUp[1] = paramsLst[7].toDouble();
+    viewUp[2] = paramsLst[8].toDouble();
+    parScale = paramsLst[9].toDouble();
+    scale[0] = paramsLst[10].toDouble();
+    scale[1] = paramsLst[11].toDouble();
+    scale[2] = paramsLst[12].toDouble();
+
+    vtkCamera* camera = myRenderer->GetActiveCamera();
+    camera->SetPosition( pos );
+    camera->SetFocalPoint( focalPnt );
+    camera->SetViewUp( viewUp );
+    camera->SetParallelScale( parScale );
+    myTransform->SetMatrixScale( scale[0], scale[1], scale[2] );
+    myRWInteractor->Render();
+  }
 }