+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onOk
+ *
+ * OK button slot
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onOk()
+{
+ if ( onApply() )
+ onCancel();
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onApply
+ *
+ * Apply button slot
+ */
+//=================================================================================================
+bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
+{
+ // Scalar Bar properties
+ if (!myActor)
+ return false;
+ vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
+
+ vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
+ QColor aTColor = myTitleColorBtn->color();
+ aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
+ if ( myTitleFontCombo->currentIndex() == 0 )
+ aTitleTextPrp->SetFontFamilyToArial();
+ else if ( myTitleFontCombo->currentIndex() == 1 )
+ aTitleTextPrp->SetFontFamilyToCourier();
+ else
+ aTitleTextPrp->SetFontFamilyToTimes();
+ aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
+ aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
+ aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
+ myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
+
+ vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
+ QColor aLColor = myLabelsColorBtn->color();
+ aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
+ if ( myLabelsFontCombo->currentIndex() == 0 )
+ aLabelsTextPrp->SetFontFamilyToArial();
+ else if ( myLabelsFontCombo->currentIndex() == 1 )
+ aLabelsTextPrp->SetFontFamilyToCourier();
+ else
+ aLabelsTextPrp->SetFontFamilyToTimes();
+ aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
+ aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
+ aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
+ myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
+
+ myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
+ myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
+
+ if ( myHorizRadioBtn->isChecked() )
+ myScalarBarActor->SetOrientationToHorizontal();
+ else
+ myScalarBarActor->SetOrientationToVertical();
+
+ myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
+ myScalarBarActor->SetWidth( myWidthSpin->value() );
+ myScalarBarActor->SetHeight( myHeightSpin->value() );
+
+ double aMin = myMinEdit->text().toDouble();
+ double aMax = myMaxEdit->text().toDouble();
+ vtkLookupTable* myLookupTable =
+ static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
+ myLookupTable->SetRange( aMin, aMax );
+ myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
+ myLookupTable->Build();
+ SMESH::RepaintCurrentView();
+ return true;
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onCancel
+ *
+ * Cancel button slot
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
+{
+ close();
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onHelp
+ *
+ * Help button slot
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onHelp()
+{
+ LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+ if (app)
+ app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
+ else {
+ QString platform;
+#ifdef WIN32
+ platform = "winapplication";
+#else
+ platform = "application";
+#endif
+ SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
+ tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+ arg(app->resourceMgr()->stringValue("ExternalBrowser",
+ platform)).
+ arg(myHelpFileName));
+ }
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
+ *
+ * Called when selection changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
+{
+ SALOME_ListIO aList;
+ mySelectionMgr->selectedObjects(aList);
+
+ if (aList.Extent() == 1) {
+ Handle(SALOME_InteractiveObject) anIO = aList.First();
+ if( anIO->hasEntry() ) {
+ SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
+ if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
+ myActor = anActor;
+ vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
+
+ if ( myScalarBarActor->GetLookupTable() ) {
+ vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
+ myMinEdit->setText( QString::number( range[0],'g',12 ) );
+ myMaxEdit->setText( QString::number( range[1],'g',12 ) );
+ }
+
+ vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
+ vtkFloatingPointType aTColor[3];
+ aTitleTextPrp->GetColor( aTColor );
+ myTitleColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
+ myTitleFontCombo->setCurrentIndex( aTitleTextPrp->GetFontFamily() );
+ myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
+ myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
+ myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
+
+ vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
+ vtkFloatingPointType aLColor[3];
+ aLabelsTextPrp->GetColor( aLColor );
+ myLabelsColorBtn->setColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
+ myLabelsFontCombo->setCurrentIndex( aLabelsTextPrp->GetFontFamily() );
+ myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
+ myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
+ myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
+
+ myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
+ myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
+
+ if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
+ myVertRadioBtn->setChecked( true );
+ else
+ myHorizRadioBtn->setChecked( true );
+ myIniOrientation = myVertRadioBtn->isChecked();
+
+ myIniX = myScalarBarActor->GetPosition()[0];
+ myIniY = myScalarBarActor->GetPosition()[1];
+ myIniW = myScalarBarActor->GetWidth();
+ myIniH = myScalarBarActor->GetHeight();
+ setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
+
+ myRangeGrp->setEnabled( true );
+ myFontGrp->setEnabled( true );
+ myLabColorGrp->setEnabled( true );
+ myOrientationGrp->setEnabled( true );
+ myOriginDimGrp->setEnabled( true );
+ myOkBtn->setEnabled( true );
+ myApplyBtn->setEnabled( true );
+ return;
+ }
+ }
+ }
+ myActor = 0;
+ myRangeGrp->setEnabled( false );
+ myFontGrp->setEnabled( false );
+ myLabColorGrp->setEnabled( false );
+ myOrientationGrp->setEnabled( false );
+ myOriginDimGrp->setEnabled( false );
+ myOkBtn->setEnabled( false );
+ myApplyBtn->setEnabled( false );
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
+ *
+ * Close event handler
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
+{
+ myDlg = 0;
+ QDialog::closeEvent( e );
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
+ *
+ * Called when X, Y values are changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
+{
+ myWidthSpin->setMaximum( 1.0 - myXSpin->value() );
+ myHeightSpin->setMaximum( 1.0 - myYSpin->value() );
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
+ *
+ * Called when X, Y values are changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
+ const double y,
+ const double w,
+ const double h )
+{
+ blockSignals( true );
+ myXSpin->setValue( x );
+ myYSpin->setValue( y );
+ myWidthSpin->setMaximum( 1.0 );
+ myWidthSpin->setValue( w );
+ myHeightSpin->setMaximum( 1.0 );
+ myHeightSpin->setValue( h );
+ blockSignals( false );
+ onXYChanged();
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
+ *
+ * Called when orientation is changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
+{
+ initScalarBarFromResources();
+
+ int aOrientation = myVertRadioBtn->isChecked();
+ if ( aOrientation == myIniOrientation )
+ setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
+ else
+ setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
+ aOrientation ? DEF_VER_Y : DEF_HOR_Y,
+ aOrientation ? DEF_VER_W : DEF_HOR_W,
+ aOrientation ? DEF_VER_H : DEF_HOR_H );
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
+ *
+ * Rereading vertical and horizontal default positions from resources.
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
+{
+ SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
+ QString name;
+ if (mgr){
+ // initialize from resoources
+
+ // horizontal
+ name = QString("scalar_bar_horizontal_%1");
+ if (mgr->hasValue("SMESH", name.arg( "x" )))
+ DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
+ if (mgr->hasValue("SMESH", name.arg( "y" )))
+ DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
+ if (mgr->hasValue("SMESH", name.arg( "width" )))
+ DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
+ if (mgr->hasValue("SMESH", name.arg( "height" )))
+ DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
+
+ // vertical
+ name = QString("scalar_bar_vertical_%1");
+ if (mgr->hasValue("SMESH", name.arg( "x" )))
+ DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
+ if (mgr->hasValue("SMESH", name.arg( "y" )))
+ DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
+ if (mgr->hasValue("SMESH", name.arg( "width" )))
+ DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
+ if (mgr->hasValue("SMESH", name.arg( "height" )))
+ DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));
+ }
+}