Salome HOME
Empty list of objects to delete (bug 19263) fix
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_TransparencyDlg.cxx
index e1da9d6ac4c8f5cd8007088099090f8f7e215100..bb893b24d8490dc6f2c1738128c8d1466cd0992d 100644 (file)
@@ -1,68 +1,63 @@
-//  GEOM GEOMGUI : GUI for Geometry component
+// GEOM GEOMGUI : GUI for Geometry component
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// Copyright (C) 2003  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 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 
-//  Lesser General Public License for more details. 
+// 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 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// File   : GEOMToolsGUI_TransparencyDlg.cxx
+// Author : Lucien PIGNOLONI
 //
-//
-//  File   : GEOMBase_TransparencyDlg.cxx
-//  Author : Lucien PIGNOLONI
-//  Module : GEOM
 
-using namespace std;
 #include "GEOMToolsGUI_TransparencyDlg.h"
-#include "GEOMBase.h"
-#include "GEOM_AISShape.hxx"
+#include <GEOMBase.h>
+#include <GEOM_AISShape.hxx>
+#include <GeometryGUI.h>
 
 #include <SALOME_ListIO.hxx>
 #include <SALOME_ListIteratorOfListIO.hxx>
 
-#include <VTKViewer_ViewModel.h>
-#include <OCCViewer_ViewModel.h>
-#include <OCCViewer_ViewWindow.h>
-
+#include <SVTK_ViewModel.h>
 #include <SVTK_ViewWindow.h>
-#include <SVTK_RenderWindowInteractor.h>
+#include <SVTK_View.h>
+
+#include <OCCViewer_ViewModel.h>
 
 #include <SUIT_ViewManager.h>
-#include <SUIT_Application.h>
 #include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
 #include <SUIT_OverrideCursor.h>
 
 #include <SalomeApp_Application.h>
-#include <SalomeApp_SelectionMgr.h>
-
-#include <qframe.h>
-#include <qlabel.h>
-#include <qpushbutton.h>
-#include <qslider.h>
-#include <qlayout.h>
-#include <qvariant.h>
-#include <qtooltip.h>
-#include <qwhatsthis.h>
-#include <qapplication.h>
-#include <qgroupbox.h>
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+
+#include <QLabel>
+#include <QPushButton>
+#include <QSlider>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QKeyEvent>
 
 #include <AIS_InteractiveContext.hxx>
 
+using namespace std;
 
 //=================================================================================
 // class    : GEOMBase_TransparencyDlg()
@@ -73,58 +68,72 @@ using namespace std;
 //
 //=================================================================================
 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
-  :QDialog( parent, "GEOMBase_TransparencyDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+  :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
 {
+  setObjectName( "GEOMBase_TransparencyDlg" );
+  setModal( true );
+  
   resize(152, 107); 
-  setCaption(tr("GEOM_TRANSPARENCY_TITLE"));
+  setWindowTitle(tr("GEOM_TRANSPARENCY_TITLE"));
   setSizeGripEnabled(TRUE);
   QGridLayout* lay = new QGridLayout(this); 
   lay->setSpacing(6);
   lay->setMargin(11);
-
+  
   /*************************************************************************/
-  QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
-  GroupButtons->setColumnLayout(0, Qt::Vertical );
-  GroupButtons->layout()->setSpacing( 0 );
-  GroupButtons->layout()->setMargin( 0 );
-  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
+  QGroupBox* GroupButtons = new QGroupBox( this );
+  GroupButtons->setObjectName( "GroupButtons" );
+  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
   GroupButtonsLayout->setAlignment( Qt::AlignTop );
   GroupButtonsLayout->setSpacing( 6 );
   GroupButtonsLayout->setMargin( 11 );
   
-  QPushButton* buttonOk = new QPushButton( GroupButtons, "buttonOk" );
+  QPushButton* buttonOk = new QPushButton( GroupButtons );
+  buttonOk->setObjectName( "buttonOk" );
   buttonOk->setText( tr( "GEOM_BUT_OK" ) );
   buttonOk->setAutoDefault( TRUE );
   buttonOk->setDefault( TRUE );
-  GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
-  GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
-  GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
-
+  
+  QPushButton* buttonHelp = new QPushButton( GroupButtons );
+  buttonHelp->setObjectName( "buttonHelp" );
+  buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
+  buttonHelp->setAutoDefault( TRUE );
+  buttonHelp->setDefault( TRUE );
+  
+  GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
+  GroupButtonsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
+  GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
+  
   /*************************************************************************/
-  QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
-  GroupC1->setColumnLayout(0, Qt::Vertical );
-  GroupC1->layout()->setSpacing( 0 );
-  GroupC1->layout()->setMargin( 0 );
-  QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
+  QGroupBox* GroupC1 = new QGroupBox( this );
+  GroupC1->setObjectName( "GroupC1" );
+  QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
   GroupC1Layout->setAlignment( Qt::AlignTop );
   GroupC1Layout->setSpacing( 6 );
   GroupC1Layout->setMargin( 11 );
   
-  QLabel* TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
+  QLabel* TextLabelOpaque = new QLabel( GroupC1 );
+  TextLabelOpaque->setObjectName( "TextLabelOpaque" );
   TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE"  ) );
-  TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
+  TextLabelOpaque->setAlignment( Qt::AlignLeft );
   GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
   GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
   
-  QLabel* TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
+  QLabel* TextLabelTransparent = new QLabel( GroupC1 );
+  TextLabelTransparent->setObjectName( "TextLabelTransparent" );
   TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT"  ) );
-  TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
+  TextLabelTransparent->setAlignment( Qt::AlignRight );
   GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
   
-  mySlider = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "mySlider" );
+  mySlider = new QSlider( Qt::Horizontal, GroupC1 );
+  mySlider->setObjectName( "mySlider" );
+  mySlider->setMinimum( 0 );
+  mySlider->setMaximum( 10 );
+  mySlider->setPageStep( 1 );
+  mySlider->setValue( 5 );
   mySlider->setMinimumSize( 300, 0 );
-  mySlider->setTickmarks( QSlider::Left );
-  GroupC1Layout->addMultiCellWidget( mySlider, 1, 1, 0, 2 );
+  mySlider->setTickPosition( QSlider::TicksLeft );
+  GroupC1Layout->addWidget( mySlider, 1, 0, 1, 3 );
   /*************************************************************************/
   
   lay->addWidget(GroupC1, 0,  0);
@@ -137,8 +146,11 @@ GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
   //  mySlider->setValue( 5 ) ;
   ValueHasChanged(mySlider->value());
   
+  myHelpFileName = "transparency_page.html";
+
   // signals and slots connections : after ValueHasChanged()
   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
+  connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
   connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(ValueHasChanged(int)));
 }
 
@@ -174,6 +186,30 @@ void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
   return;
 }
 
+//=================================================================================
+// function : ClickOnHelp()
+// purpose  :
+//=================================================================================
+void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) {
+    GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
+    app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
+  }
+  else {
+               QString platform;
+#ifdef WIN32
+               platform = "winapplication";
+#else
+               platform = "application";
+#endif
+    SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
+                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
+                            QObject::tr("BUT_OK"));
+  }
+}
 
 //=================================================================================
 // function : ValueHasChanged()
@@ -185,7 +221,7 @@ void GEOMToolsGUI_TransparencyDlg::ValueHasChanged( int newValue )
   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
   if ( !app )
     return;
-  SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
   if ( !aSelMgr )
     return;
   SALOME_ListIO selected;
@@ -199,25 +235,25 @@ void GEOMToolsGUI_TransparencyDlg::ValueHasChanged( int newValue )
        
   SUIT_ViewWindow* window = app->desktop()->activeWindow();
   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
-  bool isVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
+  bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
 
   if ( isVTK ) {
     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
     if ( !vtkVW )
       return;
-    SVTK_RenderWindowInteractor* rwi = vtkVW->getRWInteractor();
+    SVTK_View* aView = vtkVW->getView();
     if ( myFirstInit ) {       
       myFirstInit = false;
-      float transp = (rwi->GetTransparency(FirstIOS))*10.0;
+      float transp = (aView->GetTransparency(FirstIOS))*10.0;
       mySlider->setValue(int(transp));
       return;
     }
 
     SUIT_OverrideCursor();
     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
-      rwi->SetTransparency( It.Value(), newValue/10.0 );
+      aView->SetTransparency( It.Value(), newValue/10.0 );
     }
-    rwi->Render();
+    aView->Repaint();
   } // if ( isVTK )
        
   else if ( isOCC ) {
@@ -249,3 +285,20 @@ void GEOMToolsGUI_TransparencyDlg::ValueHasChanged( int newValue )
     ic->UpdateCurrentViewer();
   } // if ( isOCC )
 }
+
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Qt::Key_F1 )
+    {
+      e->accept();
+      ClickOnHelp();
+    }
+}