Salome HOME
Value of slider is badly initialized on first open.
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_TransparencyDlg.cxx
index 33940d0a04fcc3a51e63b7cd62f5e47b970f5093..399ba9be9d506acc4cb79283a57076faae0c1e7b 100644 (file)
@@ -48,6 +48,7 @@
 #include <SalomeApp_Application.h>
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Study.h>
 
 #include <QLabel>
 #include <QPushButton>
@@ -120,8 +121,9 @@ GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
   mySlider->setSingleStep( 1 );
   mySlider->setPageStep( 10 );
   //mySlider->setValue( 5 );
+  mySlider->setTracking(false);
 
-  mySlider->setTickPosition( QSlider::TicksLeft );
+  mySlider->setTickPosition( QSlider::TicksAbove );
   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)));
 }
 
 
@@ -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() )
@@ -251,7 +268,7 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency()
   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 )
@@ -268,6 +285,7 @@ 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();
@@ -278,11 +296,13 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency()
     Standard_Boolean found;
     Handle(GEOM_AISShape) aisShape;
     if ( myFirstInit ) {
+      mySlider->setValue(mySlider->maximum());
       myFirstInit = false;
       aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
       if( !found )
         return;
       int transp = int( 100 - ( aisShape->Transparency() * 100.0 ) + 0.5);
+      std::cout << "transp: " << transp << std::endl;
       mySlider->setValue(transp);
       ValueHasChanged();
       return;
@@ -298,6 +318,7 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency()
       if ( found ) {
         ic->SetTransparency( aisShape, newValue, false );
         ic->Redisplay( aisShape, Standard_False, Standard_True );
+       aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), TRANSPARENCY_PROP , newValue );
       }
     } // for...
     ic->UpdateCurrentViewer();