Salome HOME
0021823: [CEA 649] Compute failed without any errors
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ScalarBarDlg.cxx
index b1f9284c6497d6276433710b5d935f51611772ad..7f0a861ae9f1f1e9bfdeba20d8d2d196c889c04d 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  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,11 +411,12 @@ 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",
@@ -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() ) );
@@ -520,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);
     }
   }
 
@@ -553,6 +563,17 @@ bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
 
   if( nbColorsChanged || rangeChanges)
     myActor->UpdateDistribution();
+  
+#ifndef DISABLE_PLOT2DVIEWER
+  if( myActor->GetPlot2Histogram() && 
+      (nbColorsChanged || 
+       rangeChanges ||
+       distributionTypeChanged || 
+       colorChanged ))
+    SMESH::ProcessIn2DViewers(myActor);
+#endif
+    
+    
 
   SMESH::RepaintCurrentView();
   return true;
@@ -656,7 +677,6 @@ 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 ) ) );
@@ -667,6 +687,10 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
           myDMultiColor->setChecked(true);
           onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
         }
+        myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
+        onDistributionActivated(myScalarBarActor->GetDistributionVisibility());
+        
+        
         myRangeGrp->setEnabled( true );
         myFontGrp->setEnabled( true );
         myLabColorGrp->setEnabled( true );
@@ -674,6 +698,7 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
         myOriginDimGrp->setEnabled( true );
         myOkBtn->setEnabled( true );
         myApplyBtn->setEnabled( true );
+        myDistributionGrp->setEnabled( true );
         return;
       }
     }
@@ -686,6 +711,7 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
   myOriginDimGrp->setEnabled( false );
   myOkBtn->setEnabled( false );
   myApplyBtn->setEnabled( false );
+  myDistributionGrp->setEnabled( false );
 }
 
 //=================================================================================================
@@ -746,10 +772,33 @@ 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);
+  }
 }
 
+
 //=================================================================================================
 /*!
  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged