Salome HOME
Unicode support: correct handling of unicode on GUI level
[modules/gui.git] / src / SVTK / SVTK_ViewWindow.cxx
index 2d98877d6dc7bff2654dae5b3dfc1811f480f881..3a63b154fb6b911ba5061346828a6bb8f95dab44 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -23,6 +23,7 @@
 #include "SVTK_NonIsometricDlg.h"
 #include "SVTK_UpdateRateDlg.h"
 #include "SVTK_CubeAxesDlg.h"
+#include "SVTK_PsOptionsDlg.h"
 #include "SVTK_SetRotationPointDlg.h"
 #include "SVTK_ViewParameterDlg.h"
 #include "SVTK_ViewModel.h"
@@ -76,6 +77,7 @@
 
 #include "VTKViewer_Utilities.h"
 #include "VTKViewer_Trihedron.h"
+#include "VTKViewer_Actor.h"
 
 #include "SVTK_View.h"
 #include "SVTK_Selector.h"
 
 #include <OpenGLUtils_FrameBuffer.h>
 
+#ifdef __APPLE__
+#include <OpenGL/gl.h>
+#else
 #include <GL/gl.h>
+#endif
 
 namespace SVTK
 {
@@ -672,7 +678,7 @@ void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
          aReader = vtkMetaImageReader::New();           
        if ( aReader ) {
          // create texture
-         aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
+         aReader->SetFileName( fi.absoluteFilePath().toUtf8().constData() );
          aReader->Update();      
          VTKViewer_Texture* aTexture = VTKViewer_Texture::New();           
          vtkImageMapToColors* aMap = 0;
@@ -1083,6 +1089,15 @@ void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
     dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
   if ( aPreselectionGroup )
     aPreselectionGroup->setEnabled( theEnable );
+
+  // notify actors
+  vtkActorCollection *actors = getRenderer()->GetActors();
+  for (int i = 0; i < actors->GetNumberOfItems(); ++i )
+    if (VTKViewer_Actor *actor = dynamic_cast<VTKViewer_Actor*>(actors->GetItemAsObject(i)))
+    {
+      cout << "actor " << actor << endl;
+      actor->EnableSelection( theEnable );
+    }
 }
 
 /*!
@@ -1375,33 +1390,43 @@ bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileNa
   if ( format != "PS" && format != "EPS" && format != "PDF" )
     return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
 
-  SUIT_OverrideCursor wc;
+  SVTK_PsOptionsDlg* optionsDlg = new SVTK_PsOptionsDlg(this);
+  if ( optionsDlg->exec() == QDialog::Accepted ) {
+    SUIT_OverrideCursor wc;
 
-  vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
-  anExporter->SetRenderWindow(getRenderWindow());
+    vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
+    anExporter->SetRenderWindow(getRenderWindow());
 
-  if ( format == "PS" ) {
-    anExporter->SetFileFormatToPS();
-    anExporter->CompressOff();
-  }
-
-  if ( format == "EPS" ) {
-    anExporter->SetFileFormatToEPS();
-    anExporter->CompressOff();
-  }
+    // Set options
+    anExporter->SetLineWidthFactor(optionsDlg->getLineFactor());
+    anExporter->SetPointSizeFactor(optionsDlg->getPointFactor());
+    anExporter->SetSort((vtkGL2PSExporter::SortScheme)optionsDlg->getSortType());
+    anExporter->SetWrite3DPropsAsRasterImage((int)optionsDlg->isRasterize3D());
+    anExporter->SetPS3Shading((int)optionsDlg->isPs3Shading());
+    
+    if ( format == "PS" ) {
+      anExporter->SetFileFormatToPS();
+      anExporter->CompressOff();
+    }
+    
+    if ( format == "EPS" ) {
+      anExporter->SetFileFormatToEPS();
+      anExporter->CompressOff();
+    }
 
-  if ( format == "PDF" ) {
-    anExporter->SetFileFormatToPDF();
+    if ( format == "PDF" ) {
+      anExporter->SetFileFormatToPDF();
+    }
+    
+    QString aFilePrefix(fileName);
+    QString anExtension(SUIT_Tools::extension(fileName));
+    aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
+    anExporter->SetFilePrefix(aFilePrefix.toUtf8().data());
+    anExporter->Write();
+    anExporter->Delete();
   }
-
-  QString aFilePrefix(fileName);
-  QString anExtension(SUIT_Tools::extension(fileName));
-  aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
-  anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
-  anExporter->Write();
-  anExporter->Delete();
-
-  return true;
+  delete optionsDlg;
+  return true;  
 }
 
 /*!
@@ -1623,7 +1648,7 @@ void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
   //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
 
   actor->SetTitleVisibility( isVisible );
-  actor->SetTitle( title.toLatin1() );
+  actor->SetTitle( title.toUtf8() );
   vtkTextProperty* txtProp = actor->GetTitleTextProperty();
   if ( txtProp ) {
     txtProp->SetColor( color );
@@ -1708,7 +1733,7 @@ void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
     int shadow = paramsLst[10].toInt();
 
     actor->SetTitleVisibility( isVisible );
-    actor->SetTitle( title.toLatin1() );
+    actor->SetTitle( title.toUtf8() );
     vtkTextProperty* txtProp = actor->GetTitleTextProperty();
     if ( txtProp ) {
       txtProp->SetColor( color );
@@ -2125,7 +2150,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
                            tr( "MNU_DUMP_VIEW" ), 0, this);
   anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
   mgr->registerAction( anAction, DumpId );
 
   // FitAll
@@ -2133,7 +2158,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
                            tr( "MNU_FITALL" ), 0, this);
   anAction->setStatusTip(tr("DSC_FITALL"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
   mgr->registerAction( anAction, FitAllId );
 
   // FitRect
@@ -2141,7 +2166,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
                            tr( "MNU_FITRECT" ), 0, this);
   anAction->setStatusTip(tr("DSC_FITRECT"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
   mgr->registerAction( anAction, FitRectId );
 
   // FitSelection
@@ -2149,7 +2174,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ),
                            tr( "MNU_FITSELECTION" ), 0, this);
   anAction->setStatusTip(tr("DSC_FITSELECTION"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onFitSelection()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
   mgr->registerAction( anAction, FitSelectionId );
 
   // Zoom
@@ -2157,7 +2182,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
                            tr( "MNU_ZOOM_VIEW" ), 0, this);
   anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
   mgr->registerAction( anAction, ZoomId );
 
   // Panning
@@ -2165,7 +2190,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
                            tr( "MNU_PAN_VIEW" ), 0, this);
   anAction->setStatusTip(tr("DSC_PAN_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
   mgr->registerAction( anAction, PanId );
 
   // Global Panning
@@ -2173,7 +2198,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
   anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
   mgr->registerAction( anAction, GlobalPanId );
 
   // Change rotation point
@@ -2190,7 +2215,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
                            tr( "MNU_ROTATE_VIEW" ), 0, this);
   anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
   mgr->registerAction( anAction, RotationId );
 
   // Projections
@@ -2198,7 +2223,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
                            tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
   anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
   this->addAction(anAction);
   mgr->registerAction( anAction, FrontId );
 
@@ -2206,7 +2231,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
                            tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
   anAction->setStatusTip(tr("DSC_BACK_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onBackView()));
   this->addAction(anAction);
   mgr->registerAction( anAction, BackId );
 
@@ -2214,7 +2239,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
                            tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
   anAction->setStatusTip(tr("DSC_TOP_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onTopView()));
   this->addAction(anAction);
   mgr->registerAction( anAction, TopId );
 
@@ -2222,7 +2247,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
                            tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
   anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
   this->addAction(anAction);
   mgr->registerAction( anAction, BottomId );
 
@@ -2230,7 +2255,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
                            tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
   anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
   this->addAction(anAction);
   mgr->registerAction( anAction, LeftId );
 
@@ -2238,7 +2263,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
                            tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
   anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onRightView()));
   this->addAction(anAction);
   mgr->registerAction( anAction, RightId );
 
@@ -2265,7 +2290,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
                            tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
   anAction->setStatusTip(tr("DSC_RESET_VIEW"));
-  connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
+  connect(anAction, SIGNAL(triggered()), this, SLOT(onResetView()));
   this->addAction(anAction);
   mgr->registerAction( anAction, ResetId );
 
@@ -2374,7 +2399,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
   anAction->setCheckable(true);
-  connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
+  connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
   aSignalMapper->setMapping( anAction, Standard_Preselection );
   mgr->registerAction( anAction, StandardPreselectionId );
   
@@ -2383,7 +2408,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
   anAction->setCheckable(true);
-  connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
+  connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
   aSignalMapper->setMapping( anAction, Dynamic_Preselection );
   mgr->registerAction( anAction, DynamicPreselectionId );
 
@@ -2392,7 +2417,7 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
                            tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
   anAction->setCheckable(true);
-  connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
+  connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
   aSignalMapper->setMapping( anAction, Preselection_Disabled );
   mgr->registerAction( anAction, DisablePreselectionId );