Salome HOME
rnc: added missing translations
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ScalarBarDlg.cxx
index 43640501edc55d560f353831905bbacb412253f6..083fffa77759341621555fe759dd9ba5247a2e74 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  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
+// Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 // SMESH SMESHGUI : GUI for SMESH component
@@ -33,6 +33,7 @@
 #include "SMESHGUI_Utils.h"
 
 #include <SMESH_Actor.h>
+#include <SMESH_ActorUtils.h>
 #include <SMESH_ScalarBarActor.h>
 #include <SMESH_ControlsDef.hxx>
 
@@ -410,15 +411,16 @@ SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI*
 
   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
   if( coloringType == SMESH_MONOCOLOR_TYPE ) {
+    myDMonoColor->setChecked(true);
+    onDistributionChanged(myDistribColorGrp->id(myDMonoColor));    
+  } else {
     myDMultiColor->setChecked(true);
     onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
-  } else {
-    myDMonoColor->setChecked(true);
-    onDistributionChanged(myDistribColorGrp->id(myDMonoColor));
+
   }
   
   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
-                                            QColor(255, 255, 255));
+                                             QColor(255, 255, 255));
   myMonoColorBtn->setColor(distributionColor);
   
   
@@ -435,6 +437,7 @@ SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI*
   connect( myXSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
   connect( myYSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
   connect( aOrientationGrp,     SIGNAL( buttonClicked( int ) ),   this, SLOT( onOrientationChanged() ) );
+  connect( myDistributionGrp,   SIGNAL( toggled(bool) ), this, SLOT(onDistributionActivated(bool)) );
   connect( myDistribColorGrp,   SIGNAL( buttonClicked( int ) ),   this, SLOT( onDistributionChanged( int ) ) );
   connect( mySelectionMgr,      SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
   connect( mySMESHGUI,          SIGNAL( SignalCloseAllDialogs() ),   this, SLOT( onCancel() ) );
@@ -509,18 +512,6 @@ bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
   myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
 
   myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
-  if( myColorsSpin->value() != myScalarBarActor->GetMaximumNumberOfColors() ) {
-    myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
-    SMESH::Controls::FunctorPtr fn = myActor->GetFunctor();       
-    SMESH::Controls::NumericalFunctor* aNumericalFunctor = dynamic_cast<SMESH::Controls::NumericalFunctor*>(fn.get());
-    if( aNumericalFunctor ) {
-      int nbIntervals = myColorsSpin->value();
-      std::vector<int> nbEvents;
-      std::vector<double> funValues;
-      aNumericalFunctor->GetHistogram(nbIntervals, nbEvents, funValues);
-      myScalarBarActor->SetDistribution(nbEvents);
-    }
-  }
 
   if ( myHorizRadioBtn->isChecked() )
     myScalarBarActor->SetOrientationToHorizontal();
@@ -532,17 +523,24 @@ bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
   myScalarBarActor->SetHeight( myHeightSpin->value() );
 
   // Distribution
+  bool distributionTypeChanged = false, colorChanged=false;
   myScalarBarActor->SetDistributionVisibility((int)myDistributionGrp->isChecked());
   if( myDistributionGrp->isChecked() ) {
     int ColoringType = myDMultiColor->isChecked() ? SMESH_MULTICOLOR_TYPE : SMESH_MONOCOLOR_TYPE;
-    myScalarBarActor->SetDistributionColoringType(ColoringType);
+    distributionTypeChanged = (ColoringType != myScalarBarActor->GetDistributionColoringType());
+    if(distributionTypeChanged)      
+      myScalarBarActor->SetDistributionColoringType(ColoringType);
+    
     if( !myDMultiColor->isChecked() ) {
       QColor aTColor = myMonoColorBtn->color();
-      double rgb[3];
+      double rgb[3], oldRgb[3];;
       rgb [0] = aTColor.red()/255.;
       rgb [1] = aTColor.green()/255.;
       rgb [2] = aTColor.blue()/255.;
-      myScalarBarActor->SetDistributionColor(rgb);
+      myScalarBarActor->GetDistributionColor(oldRgb);
+      colorChanged = (rgb[0] != oldRgb[0] || rgb[1] != oldRgb[1] || rgb[2] != oldRgb[2]);
+      if(colorChanged)
+        myScalarBarActor->SetDistributionColor(rgb);
     }
   }
 
@@ -550,9 +548,33 @@ bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
   double aMax = myMaxEdit->text().toDouble();
   vtkLookupTable* myLookupTable =
     static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
+  double oldMinMax[2] = { myLookupTable->GetRange()[0], myLookupTable->GetRange()[1] };
+  bool rangeChanges = ( fabs( oldMinMax[0] - aMin ) + fabs( oldMinMax[1] - aMax ) >
+                        0.001 * ( aMax-aMin + oldMinMax[1]-oldMinMax[0] ));
+  
+  bool nbColorsChanged = (myColorsSpin->value() != myScalarBarActor->GetMaximumNumberOfColors());
+  if(nbColorsChanged)
+    myScalarBarActor->SetMaximumNumberOfColors(myColorsSpin->value());
+  
+
   myLookupTable->SetRange( aMin, aMax );
   myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
   myLookupTable->Build();
+
+  if( nbColorsChanged || rangeChanges)
+    myActor->UpdateDistribution();
+  
+#ifndef DISABLE_PLOT2DVIEWER
+  if( myActor->GetPlot2Histogram() && 
+      (nbColorsChanged || 
+       rangeChanges ||
+       distributionTypeChanged || 
+       colorChanged ))
+    SMESH::ProcessIn2DViewers(myActor);
+#endif
+    
+    
+
   SMESH::RepaintCurrentView();
   return true;
 }
@@ -655,17 +677,20 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
         myIniH = myScalarBarActor->GetHeight();
         setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
 
-       myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
-       int coloringType = myScalarBarActor->GetDistributionColoringType();
-       myScalarBarActor->GetDistributionColor( aTColor );
-       myMonoColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
-       if ( coloringType == SMESH_MONOCOLOR_TYPE ) {
-         myDMonoColor->setChecked(true);
-         onDistributionChanged(myDistribColorGrp->id(myDMonoColor));    
-       } else {
-         myDMultiColor->setChecked(true);
-         onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
-       }
+        int coloringType = myScalarBarActor->GetDistributionColoringType();
+        myScalarBarActor->GetDistributionColor( aTColor );
+        myMonoColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
+        if ( coloringType == SMESH_MONOCOLOR_TYPE ) {
+          myDMonoColor->setChecked(true);
+          onDistributionChanged(myDistribColorGrp->id(myDMonoColor));    
+        } else {
+          myDMultiColor->setChecked(true);
+          onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
+        }
+        myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
+        onDistributionActivated(myScalarBarActor->GetDistributionVisibility());
+        
+        
         myRangeGrp->setEnabled( true );
         myFontGrp->setEnabled( true );
         myLabColorGrp->setEnabled( true );
@@ -673,6 +698,7 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
         myOriginDimGrp->setEnabled( true );
         myOkBtn->setEnabled( true );
         myApplyBtn->setEnabled( true );
+        myDistributionGrp->setEnabled( true );
         return;
       }
     }
@@ -685,6 +711,7 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
   myOriginDimGrp->setEnabled( false );
   myOkBtn->setEnabled( false );
   myApplyBtn->setEnabled( false );
+  myDistributionGrp->setEnabled( false );
 }
 
 //=================================================================================================
@@ -745,9 +772,32 @@ void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
  */
 //=================================================================================================
 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged( int id ) {
-  myMonoColorBtn->setEnabled(myDistribColorGrp->id(myDMonoColor) == id);
-  myDistributionColorLbl->setEnabled(myDistribColorGrp->id(myDMonoColor) == id);
+
+  bool isActive = myDistribColorGrp->id(myDMonoColor) == id;
+
+  myMonoColorBtn->setEnabled(isActive);
+  myDistributionColorLbl->setEnabled(isActive);
 }
+//=================================================================================================
+/*!
+ *  SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated
+ *
+ *  Called when distribution group check box is changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated(bool on) {
+  if(on) {
+    if(myDMonoColor->isChecked())
+      onDistributionChanged(myDistribColorGrp->id(myDMonoColor)  );
+    else if(myDMultiColor->isChecked())
+      onDistributionChanged(myDistribColorGrp->id(myDMultiColor) );
+  }
+  else {
+    myMonoColorBtn->setEnabled(false);
+    myDistributionColorLbl->setEnabled(false);
+  }
+}
+
 
 //=================================================================================================
 /*!