Salome HOME
Update comments.
[modules/gui.git] / src / VTKViewer / VTKViewer_ViewWindow.cxx
index 124b95097ada791ff47072bfdebbe528c77e047d..6c3ef1b6e48416a8712470a2c936dbb46844247a 100755 (executable)
 #include <vtkRenderer.h>
 #include <vtkCamera.h>
 
-//****************************************************************
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
+/*! Construction*/
 VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop, 
                                             VTKViewer_Viewer* theModel,
                                            VTKViewer_InteractorStyle* iStyle,
                                            VTKViewer_RenderWindowInteractor* rw )
-: SUIT_ViewWindow(theDesktop)
+: SUIT_ViewWindow( theDesktop )
 {
   myModel = theModel;
 
@@ -104,7 +101,7 @@ VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop,
   onResetView();
 }
 
-//****************************************************************
+/*!Destructor.*/
 VTKViewer_ViewWindow::~VTKViewer_ViewWindow()
 {
   myTransform->Delete();
@@ -120,12 +117,10 @@ VTKViewer_ViewWindow::~VTKViewer_ViewWindow()
   myTrihedron->Delete();
 }
 
-//****************************************************************
 bool VTKViewer_ViewWindow::isTrihedronDisplayed(){
   return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
 }
 
-//****************************************************************
 /*!
     Activates 'zooming' transformation
 */
@@ -134,7 +129,6 @@ void VTKViewer_ViewWindow::activateZoom()
   myRWInteractor->GetInteractorStyle()->startZoom();
 }
 
-//****************************************************************
 /*!
     Activates 'panning' transformation
 */
@@ -143,7 +137,6 @@ void VTKViewer_ViewWindow::activatePanning()
   myRWInteractor->GetInteractorStyle()->startPan();
 }
 
-//****************************************************************
 /*!
     Activates 'rotation' transformation
 */
@@ -152,14 +145,12 @@ void VTKViewer_ViewWindow::activateRotation()
   myRWInteractor->GetInteractorStyle()->startRotate();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::activateGlobalPanning()
 {
   //if(myTrihedron->GetVisibleActorCount(myRenderer))
   myRWInteractor->GetInteractorStyle()->startGlobalPan();
 }
 
-//****************************************************************
 /*!
     Activates 'fit area' transformation
 */
@@ -168,7 +159,6 @@ void VTKViewer_ViewWindow::activateWindowFit()
   myRWInteractor->GetInteractorStyle()->startFitArea();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::createActions()
 {
   if (!myActionsMap.isEmpty()) return;
@@ -269,12 +259,18 @@ void VTKViewer_ViewWindow::createActions()
   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
   connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
   myActionsMap[ ResetId ] = aAction;
+
+  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()));
+  myActionsMap[ TrihedronShowId ] = aAction;
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::createToolBar()
 {
   myActionsMap[DumpId]->addTo(myToolBar);
+  myActionsMap[TrihedronShowId]->addTo(myToolBar);
 
   SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
   aScaleBtn->AddAction(myActionsMap[FitAllId]);
@@ -298,7 +294,6 @@ void VTKViewer_ViewWindow::createToolBar()
   myActionsMap[ResetId]->addTo(myToolBar);
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onFrontView()
 {
   vtkCamera* camera = myRenderer->GetActiveCamera();
@@ -308,7 +303,6 @@ void VTKViewer_ViewWindow::onFrontView()
   onFitAll();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onBackView()
 {
   vtkCamera* camera = myRenderer->GetActiveCamera();
@@ -318,7 +312,6 @@ void VTKViewer_ViewWindow::onBackView()
   onFitAll();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onTopView()
 {
   vtkCamera* camera = myRenderer->GetActiveCamera();
@@ -328,7 +321,6 @@ void VTKViewer_ViewWindow::onTopView()
   onFitAll();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onBottomView()
 {
   vtkCamera* camera = myRenderer->GetActiveCamera();
@@ -338,7 +330,6 @@ void VTKViewer_ViewWindow::onBottomView()
   onFitAll();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onLeftView()
 {
   vtkCamera* camera = myRenderer->GetActiveCamera(); 
@@ -348,7 +339,6 @@ void VTKViewer_ViewWindow::onLeftView()
   onFitAll();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onRightView()
 {
   vtkCamera* camera = myRenderer->GetActiveCamera();
@@ -358,7 +348,6 @@ void VTKViewer_ViewWindow::onRightView()
   onFitAll();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onResetView()
 {
   int aTriedronIsVisible = isTrihedronDisplayed();
@@ -375,44 +364,12 @@ void VTKViewer_ViewWindow::onResetView()
   Repaint();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onFitAll()
 {
   myRWInteractor->GetInteractorStyle()->ViewFitAll();
   Repaint();
 }
 
-//****************************************************************
-/*
-   Dumps 3d-Viewer contents into image file
-   File format is defined by file's extension; supported formats : PNG, BMP, GIF, JPG
-*/
-void VTKViewer_ViewWindow::onDumpView()
-{
-  QApplication::setOverrideCursor( Qt::waitCursor );
-  QPixmap px = QPixmap::grabWindow(myRenderWindow->winId());
-  QApplication::restoreOverrideCursor();
-  SUIT_Application* app = getViewManager()->study()->application();
-
-  QString aFileName = app->getFileName( false, QString::null, tr("VTK_IMAGE_FILES"), tr("INF_APP_DUMP_VIEW"), 0 );
-  if ( !aFileName.isNull() ) {
-    QApplication::setOverrideCursor( Qt::waitCursor );
-    QString fmt = SUIT_Tools::extension( aFileName ).upper();
-    if (fmt.isEmpty())
-      fmt = QString("BMP"); // default format
-    if (fmt == "JPG")
-      fmt = "JPEG";
-    bool bOk = px.save(aFileName, fmt.latin1());
-    QApplication::restoreOverrideCursor();
-    if (!bOk) {
-      SUIT_MessageBox::error1(this, tr("ERROR"), tr("ERR_DOC_CANT_SAVE_FILE"), tr("BUT_OK"));
-    }
-  }
-}
-
-//****************************************************************
 /*!
     Set background of the viewport
 */
@@ -422,7 +379,6 @@ void VTKViewer_ViewWindow::setBackgroundColor( const QColor& color )
     myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
 }
 
-//****************************************************************
 /*!
     Returns background of the viewport
 */
@@ -436,26 +392,22 @@ QColor VTKViewer_ViewWindow::backgroundColor() const
   return SUIT_ViewWindow::backgroundColor();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::Repaint(bool theUpdateTrihedron)
 {
   if (theUpdateTrihedron) onAdjustTrihedron();
   myRenderWindow->update();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::GetScale( double theScale[3] ) {
   myTransform->GetScale( theScale );
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::SetScale( double theScale[3] ) {
-  myTransform->SetScale( theScale[0], theScale[1], theScale[2] );
+  myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
   myRWInteractor->Render();
   Repaint();
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onAdjustTrihedron(){   
   if( !isTrihedronDisplayed() ) 
     return;
@@ -493,37 +445,31 @@ void VTKViewer_ViewWindow::onAdjustTrihedron(){
   ::ResetCameraClippingRange(myRenderer);
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onKeyPressed(QKeyEvent* event)
 {
   emit keyPressed( this, event );
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onKeyReleased(QKeyEvent* event)
 {
   emit keyReleased( this, event );
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onMousePressed(QMouseEvent* event)
 {
   emit mousePressed(this, event);
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onMouseReleased(QMouseEvent* event)
 {
   emit mouseReleased( this, event );
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onMouseMoving(QMouseEvent* event)
 {
   emit mouseMoving( this, event );
 }
 
-//****************************************************************
 void VTKViewer_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
 {
   emit mouseDoubleClicked( this, event );
@@ -553,3 +499,18 @@ void VTKViewer_ViewWindow::MoveActor( VTKViewer_Actor* theActor)
   RemoveActor(theActor);
   InsertActor(theActor,true);
 }
+
+void VTKViewer_ViewWindow::onTrihedronShow()
+{
+  if (isTrihedronDisplayed())
+    myTrihedron->VisibilityOff();
+  else
+    myTrihedron->VisibilityOn();
+  myRenderWindow->update();
+}
+
+QImage VTKViewer_ViewWindow::dumpView()
+{
+  QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
+  return px.convertToImage();
+}