Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISUGUI / VisuGUI_ScalarBarDlg.cxx
index 9cffb00221a8f4fe309f8c3bbb21d7edb1b32356..54c96b88ecbbc46435ecdaf58da03ad7f1d09f24 100644 (file)
 
 #include "VisuGUI.h"
 #include "VisuGUI_Tools.h"
-#include "VisuGUI_FontWg.h"
+#include "VisuGUI_ViewTools.h"
 
 #include "SVTK_ViewWindow.h"
+#include "SVTK_FontWidget.h"
 
 #include "VISUConfig.hh"
 #include "VISU_Convertor.hxx"
@@ -59,8 +60,20 @@ using namespace std;
 VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
   QVBox(parent), myPreviewActor(0)
 {
-  myVerX = 0.01;  myVerY = 0.10;  myVerW = 0.10;  myVerH = 0.80;
-  myHorX = 0.20;  myHorY = 0.01;  myHorW = 0.60;  myHorH = 0.12;
+  SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
+  QString propertyName;
+  propertyName = QString("scalar_bar_vertical_");
+  myVerX = aResourceMgr->doubleValue("VISU", propertyName + "x", myVerX);
+  myVerY = aResourceMgr->doubleValue("VISU", propertyName + "y", myVerY);
+  myVerW = aResourceMgr->doubleValue("VISU", propertyName + "width", myVerW);
+  myVerH = aResourceMgr->doubleValue("VISU", propertyName + "height",myVerH);
+  
+  propertyName = QString("scalar_bar_horizontal_");
+  myHorX = aResourceMgr->doubleValue("VISU", propertyName + "x", myHorX);
+  myHorY = aResourceMgr->doubleValue("VISU", propertyName + "y", myHorY);
+  myHorW = aResourceMgr->doubleValue("VISU", propertyName + "width", myHorW);
+  myHorH = aResourceMgr->doubleValue("VISU", propertyName + "height",myHorH);
+  
   Imin = 0.0; Imax = 0.0; /*Fmin = 0.0; Fmax = 0.0;*/ Rmin = 0.0; Rmax = 0.0;
   myRangeMode = -1;
 
@@ -80,10 +93,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 +259,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 ) ) );
@@ -263,9 +273,9 @@ VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
   changeRange( 0 );
   changeDefaults( 0 );
   myIsStoreTextProp = false;
+  myBusy = false;
 }
 
-
 /**
  * Initializes dialog box values from resources
  */
@@ -278,6 +288,12 @@ void VisuGUI_ScalarBarPane::initFromResources() {
 
   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
 
+  bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0);
+  int aPlace = 1;
+  if (anIsArrangeBar){
+    aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0);
+  }
+
   int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
   myModeCombo->setCurrentItem(aScalarMode);
 
@@ -298,6 +314,11 @@ void VisuGUI_ScalarBarPane::initFromResources() {
   sbW = aResourceMgr->doubleValue("VISU", propertyName + "width", sbW);
   sbH = aResourceMgr->doubleValue("VISU", propertyName + "height",sbH);
   
+  if(orient){
+    sbY1 += sbH*(aPlace-1);
+  } else {
+    sbX1 += sbW*(aPlace-1);
+  }
   sbCol = aResourceMgr->integerValue("VISU" ,"scalar_bar_num_colors", sbCol);
   sbLab = aResourceMgr->integerValue("VISU", "scalar_bar_num_labels", sbLab);
 
@@ -527,7 +548,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(),
@@ -546,7 +566,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);
 
@@ -583,7 +632,7 @@ void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
 void VisuGUI_ScalarBarPane::updatePreview()
 {
   if (myPreviewCheck->isChecked()) {
-    if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
+    if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
       deleteScalarBar();
       createScalarBar();
       vf->Repaint();
@@ -595,11 +644,11 @@ void VisuGUI_ScalarBarPane::updatePreview()
  */
 void VisuGUI_ScalarBarPane::createScalarBar()
 {
-  if (VISU::GetViewWindow() == NULL) return;
+  if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
   if (myPreviewActor != 0) return;
   if (myScalarMap == NULL) return;
 
-  if(!check()) return;
+  if (!check()) return;
 
   if ( myBusy ) return;
 
@@ -686,7 +735,7 @@ void VisuGUI_ScalarBarPane::createScalarBar()
 
   aScalarBarActor->Modified();
 
-  VISU::GetViewWindow()->AddActor(myPreviewActor);
+  VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
 
   myBusy = false;
 }
@@ -697,7 +746,7 @@ void VisuGUI_ScalarBarPane::deleteScalarBar()
   if ( myBusy ) return;
   
   if (myPreviewActor == 0) return;
-  if (SVTK_ViewWindow* vf = VISU::GetViewWindow()){
+  if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()){
     vf->RemoveActor(myPreviewActor);
     myPreviewActor->GetScalarBar()->VisibilityOff();
   }
@@ -849,6 +898,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
 */
@@ -871,6 +936,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
 */
@@ -970,7 +1043,7 @@ void VisuGUI_ScalarBarPane::onTextPref()
 
 void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview)
 {
-  if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
+  if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
     if (thePreview) {
       createScalarBar();
     } else {
@@ -1031,8 +1104,11 @@ VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool Se
 */
 void VisuGUI_ScalarBarDlg::accept()
 {
-  myScalarPane->deletePreview();
-  if (myScalarPane->check()) QDialog::accept();
+  if (myScalarPane->check()) 
+    {
+      myScalarPane->deletePreview(); 
+      QDialog::accept();
+    }
 }
 
 /*!
@@ -1066,7 +1142,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);
 
@@ -1076,7 +1152,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);