Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_ScalarBarDlg.cxx
index 5d89779db6efda5c6e68657cc12dc647a7dd869a..ddc63e88388ffe4a59dbeade3d49a339ce14b6d7 100644 (file)
 
 #include "VisuGUI.h"
 #include "VisuGUI_Tools.h"
-#include "VisuGUI_FontWg.h"
+
+#include "SVTK_FontWidget.h"
+
+#include "SVTK_ViewWindow.h"
 
 #include "SVTK_ViewWindow.h"
 
@@ -80,10 +83,6 @@ VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
   myModeLbl = new QLabel("Scalar Mode", RangeGroup);
 
   myModeCombo = new QComboBox(RangeGroup);
-  myModeCombo->insertItem("Modulus");
-  myModeCombo->insertItem("Component 1");
-  myModeCombo->insertItem("Component 2");
-  myModeCombo->insertItem("Component 3");
 
   CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), RangeGroup);
   CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
@@ -250,6 +249,7 @@ VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
 
   // signals and slots connections ===========================================
   connect( RangeGroup,   SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
+  connect( myModeCombo,   SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( int ) ) );
   connect( OrientGroup,  SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
   connect( XSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
   connect( YSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
@@ -538,7 +538,6 @@ void VisuGUI_ScalarBarPane::storeToResources() {
 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
   initFromResources();
   myScalarMap = thePrs;
-  myModeCombo->setCurrentItem(thePrs->GetScalarMode());
   setPosAndSize( thePrs->GetPosX(),
                 thePrs->GetPosY(),
                 thePrs->GetWidth(),
@@ -557,7 +556,36 @@ void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
   setRange( thePrs->GetMin(), thePrs->GetMax(),
            /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
   setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
-  bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
+
+  // Update myModeCombo
+  int aNbComp = thePrs->GetField()->myNbComp;
+  bool isScalarMode = (aNbComp > 1);
+  myModeCombo->clear();
+  myModeCombo->insertItem("<Modulus>");
+  const VISU::PField& aField = thePrs->GetField();
+  const VISU::TNames& aCompNames = aField->myCompNames;
+  const VISU::TNames& aUnitNames = aField->myUnitNames;
+  for(int i = 0; i < aNbComp; i++){
+    QString aComponent = QString(aCompNames[i]).simplifyWhiteSpace();
+    if(aComponent.isNull() || aComponent == "")
+      aComponent = "Component " + QString::number(i+1);
+    else
+      aComponent = "[" + QString::number(i+1) + "] " + aComponent;
+
+    QString anUnit = QString(aUnitNames[i]).simplifyWhiteSpace();
+    if(anUnit.isNull() || anUnit == "")
+      anUnit = "-";
+    
+    aComponent = aComponent + ", " + anUnit;
+
+    myModeCombo->insertItem(aComponent);
+  }
+  //
+  myModeCombo->setCurrentItem(thePrs->GetScalarMode());
+  if (aNbComp==1){
+    myModeCombo->setCurrentItem(1);
+  }
+  //
   myModeLbl->setEnabled(isScalarMode);
   myModeCombo->setEnabled(isScalarMode);
 
@@ -610,7 +638,7 @@ void VisuGUI_ScalarBarPane::createScalarBar()
   if (myPreviewActor != 0) return;
   if (myScalarMap == NULL) return;
 
-  if (!check()) return;
+  if(!check()) return;
 
   if ( myBusy ) return;
 
@@ -706,9 +734,9 @@ void VisuGUI_ScalarBarPane::createScalarBar()
 void VisuGUI_ScalarBarPane::deleteScalarBar()
 {
   if ( myBusy ) return;
-
+  
   if (myPreviewActor == 0) return;
-  if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
+  if (SVTK_ViewWindow* vf = VISU::GetViewWindow()){
     vf->RemoveActor(myPreviewActor);
     myPreviewActor->GetScalarBar()->VisibilityOff();
   }
@@ -724,8 +752,7 @@ void VisuGUI_ScalarBarPane::deletePreview()
 /**
  * Store values to presentation object
  */
-int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs)
-{
+int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
   thePrs->SetScalarMode(myModeCombo->currentItem());
   thePrs->SetPosition(XSpin->value(), YSpin->value());
   thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
@@ -861,6 +888,22 @@ void VisuGUI_ScalarBarPane::XYChanged( double )
   updatePreview();
 }
 
+/*!
+  Called when scalar mode is changed
+*/
+void VisuGUI_ScalarBarPane::changeScalarMode( int theMode )
+{
+  if ( myScalarMap ) {
+    if ( RBFrange->isChecked() ) {
+      float aRange[2];
+      myScalarMap->SetScalarMode(theMode);
+      myScalarMap->GetScalarMapPL()->GetSourceRange(aRange);
+      MinEdit->setText( QString::number( aRange[0] ) );
+      MaxEdit->setText( QString::number( aRange[1] ) );
+    }
+  }
+}
+
 /*!
   Sets default values and range mode
 */
@@ -883,6 +926,14 @@ void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, d
   changeRange( 0 );
 }
 
+/*!
+  Sets default values and range mode
+*/
+void VisuGUI_ScalarBarPane::setDefaultRange(double imin, double imax){
+  Rmin = imin;
+  Rmax = imax;
+}
+
 /*!
   Sets size and position
 */
@@ -1081,7 +1132,7 @@ VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
   //   font
   QHBox* aHBox = new QHBox (aTitleGrp);
   aHBox->setSpacing(5);
-  myTitleFont = new VisuGUI_FontWg (aHBox);
+  myTitleFont = new SVTK_FontWidget (aHBox);
 
   TopLayout->addWidget(aTitleGrp);
 
@@ -1091,7 +1142,7 @@ VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
   //   font
   aHBox = new QHBox (aLabelsGrp);
   aHBox->setSpacing(5);
-  myLabelFont = new VisuGUI_FontWg (aHBox);
+  myLabelFont = new SVTK_FontWidget (aHBox);
 
   TopLayout->addWidget(aLabelsGrp);