Salome HOME
Implementation of the 20937: EDF 1399 GEOM: extend the properties of GEOM object.
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_TransparencyDlg.cxx
index c3f06d704ce8775871699a2afe6b0841d5eb37e3..1bc2c54ddcbc176f4631dac7b2feb918fc5e8701 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // GEOM GEOMGUI : GUI for Geometry component
 // File   : GEOMToolsGUI_TransparencyDlg.cxx
 // Author : Lucien PIGNOLONI
@@ -47,6 +48,7 @@
 #include <SalomeApp_Application.h>
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Study.h>
 
 #include <QLabel>
 #include <QPushButton>
@@ -59,7 +61,6 @@
 
 #include <AIS_InteractiveContext.hxx>
 
-using namespace std;
 
 //=================================================================================
 // class    : GEOMBase_TransparencyDlg()
@@ -120,6 +121,7 @@ GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
   mySlider->setSingleStep( 1 );
   mySlider->setPageStep( 10 );
   //mySlider->setValue( 5 );
+  mySlider->setTracking(false);
 
   mySlider->setTickPosition( QSlider::TicksLeft );
   GroupC1Layout->addWidget( mySlider, 1, 0, 1, 3 );
@@ -155,7 +157,7 @@ GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
   connect(buttonOk,   SIGNAL(clicked()), this, SLOT(ClickOnOk()));
   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
   connect(mySlider,   SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
-  connect(mySlider,   SIGNAL(sliderMoved(int)),  this, SLOT(ValueHasChanged()));
+  connect(mySlider,   SIGNAL(sliderMoved(int)),  this, SLOT(SliderHasMoved(int)));
 }
 
 
@@ -202,16 +204,16 @@ void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
     app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
   }
   else {
-               QString platform;
+                QString platform;
 #ifdef WIN32
-               platform = "winapplication";
+                platform = "winapplication";
 #else
-               platform = "application";
+                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"));
+                             QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                             arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
+                             QObject::tr("BUT_OK"));
   }
 }
 
@@ -224,6 +226,15 @@ void GEOMToolsGUI_TransparencyDlg::ValueHasChanged()
   myValueLab->setText( QString("%1%").arg( mySlider->value() ) );
 }
 
+//=================================================================================
+// function : SliderHasMoved()
+// purpose  : Called when value of slider change
+//=================================================================================
+void GEOMToolsGUI_TransparencyDlg::SliderHasMoved(int value)
+{
+  myValueLab->setText( QString("%1%").arg( value ) );
+}
+
 //=================================================================================
 // function : SetTransparency()
 // purpose  : Called when value of slider change
@@ -239,6 +250,12 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency()
   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
   if ( !aSelMgr )
     return;
+  
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
+  
+  if(!aStudy)
+    return;
+  
   SALOME_ListIO selected;
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() )
@@ -247,17 +264,17 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency()
   Handle(SALOME_InteractiveObject) FirstIOS =  selected.First();
   if ( FirstIOS.IsNull() )
     return;
-       
+        
   SUIT_ViewWindow* window = app->desktop()->activeWindow();
   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
-
+  int aMgrId = window->getViewManager()->getGlobalId();
   if ( isVTK ) {
     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
     if ( !vtkVW )
       return;
     SVTK_View* aView = vtkVW->getView();
-    if ( myFirstInit ) {       
+    if ( myFirstInit ) {        
       myFirstInit = false;
       int transp = int (100 - ((aView->GetTransparency(FirstIOS))*100.0) + 0.5);
       mySlider->setValue(transp);
@@ -268,10 +285,12 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency()
     SUIT_OverrideCursor();
     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
       aView->SetTransparency( It.Value(), newValue );
+      aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), TRANSPARENCY_PROP , newValue );
     }
+    GeometryGUI::Modified();
     aView->Repaint();
   } // if ( isVTK )
-       
+        
   else if ( isOCC ) {
     GEOMBase* gb = new GEOMBase();
     Standard_Boolean found;
@@ -280,7 +299,7 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency()
       myFirstInit = false;
       aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
       if( !found )
-       return;
+        return;
       int transp = int( 100 - ( aisShape->Transparency() * 100.0 ) + 0.5);
       mySlider->setValue(transp);
       ValueHasChanged();
@@ -295,11 +314,13 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency()
     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
       if ( found ) {
-       ic->SetTransparency( aisShape, newValue, false );
-       ic->Redisplay( aisShape, Standard_False, Standard_True );
+        ic->SetTransparency( aisShape, newValue, false );
+        ic->Redisplay( aisShape, Standard_False, Standard_True );
+       aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), TRANSPARENCY_PROP , newValue );
       }
     } // for...
     ic->UpdateCurrentViewer();
+    GeometryGUI::Modified();
   } // if ( isOCC )
 
   ValueHasChanged();