From: enk Date: Wed, 26 Oct 2005 13:48:54 +0000 (+0000) Subject: Fix for Bug PAL8597: X-Git-Tag: BR-D5-38-2003_D2005-27-10~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=05fcd1667c01e2dd0a0882460a44b137d418320d;p=modules%2Fvisu.git Fix for Bug PAL8597: apply button on "edit window" for 3d objects. ========= Added preview functionality for Scalar Bar --- diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index 41f32151..b1f94480 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -665,6 +665,9 @@ msgstr "X:" msgid "VisuGUI_ScalarBarPane::LBL_Y" msgstr "Y:" +msgid "VisuGUI_ScalarBarPane::LBL_SHOW_PREVIEW" +msgstr "Show preview" + msgid "VisuGUI_ScalarBarPane::DIMENSIONS_GRP" msgstr "Dimensions" diff --git a/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx b/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx index 6a24502f..3769e646 100644 --- a/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx +++ b/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx @@ -32,11 +32,14 @@ #include "VisuGUI_Tools.h" #include "VisuGUI_FontWg.h" +#include "SVTK_ViewWindow.h" + #include "VISUConfig.hh" #include "VISU_Convertor.hxx" #include "VISU_ScalarMapPL.hxx" #include "VISU_ScalarMap_i.hh" +#include "VISU_ScalarMapAct.h" #include "SalomeApp_Application.h" @@ -48,11 +51,13 @@ #include #include +#include + using namespace std; VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref): - QVBox(parent) + 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; @@ -233,13 +238,30 @@ VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref): myTextDlg = new VisuGUI_TextPrefDlg(this); myTextDlg->setTitleVisible(!SetPref); + QGroupBox* CheckGroup = new QGroupBox("", this, "CheckGroup"); + CheckGroup->setColumnLayout(0, Qt::Vertical ); + CheckGroup->layout()->setSpacing( 0 ); + CheckGroup->layout()->setMargin( 0 ); + QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup->layout() ); + + myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this); + myPreviewCheck->setChecked(false); + CheckGroupLayout->addWidget(myPreviewCheck , 0, 0 ); + // signals and slots connections =========================================== connect( RangeGroup, SIGNAL( clicked( int ) ), this, SLOT( changeRange( 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 ) ) ); connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) ); - + connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) ); + connect( ColorSpin, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() )); + connect( LabelSpin, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() )); + connect( WidthSpin, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() )); + connect( HeightSpin, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() )); + connect( MinEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updatePreview() )); + connect( MaxEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updatePreview() )); + connect( CBLog, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() )); changeRange( 0 ); changeDefaults( 0 ); myIsStoreTextProp = false; @@ -506,6 +528,7 @@ void VisuGUI_ScalarBarPane::storeToResources() { */ void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) { initFromResources(); + myScalarMap = thePrs; myModeCombo->setCurrentItem(thePrs->GetScalarMode()); setPosAndSize( thePrs->GetPosX(), thePrs->GetPosY(), @@ -549,8 +572,136 @@ void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) { thePrs->IsBoldLabel(), thePrs->IsItalicLabel(), thePrs->IsShadowLabel()); + + // Draw Preview + if (myPreviewCheck->isChecked()) { + createScalarBar(); + updatePreview(); + } + +} +/*! Slot update preview of scalar bar, if preview is checked + */ +void VisuGUI_ScalarBarPane::updatePreview() +{ + if (myPreviewCheck->isChecked()) { + if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) { + deleteScalarBar(); + createScalarBar(); + vf->Repaint(); + } + } } +/*! Creating preview scalar bar + */ +void VisuGUI_ScalarBarPane::createScalarBar() +{ + if (VISU::GetViewWindow() == NULL) return; + if (myPreviewActor != 0) return; + if (myScalarMap == NULL) return; + + int sbCol,sbLab; + sbCol = getNbColors(); + sbLab = getNbLabels(); + if(sbCol < 2) sbCol=2; + if(sbCol > 64) sbCol=64; + if(sbLab < 2) sbLab=2; + if(sbLab > 65) sbLab=65; + myPreviewActor = VISU_ScalarMapAct::New(); + VISU_ScalarBarActor* aScalarBarActor = myPreviewActor->GetScalarBar(); + myPreviewActor->GetScalarBar()->VisibilityOn(); + myPreviewActor->PickableOff(); + + myScalarMap->SetScalarMode(myModeCombo->currentItem()); + myScalarMap->SetPosition(getX(),getY()); + myScalarMap->SetSize(getWidth(),getHeight()); + myScalarMap->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL); + if(isLogarithmic()) + myScalarMap->SetScaling(VISU::LOGARITHMIC); + else + myScalarMap->SetScaling(VISU::LINEAR); + if (RBFrange->isChecked()) { + myScalarMap->SetSourceRange(); + } else { + myScalarMap->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble()); + } + myScalarMap->SetNbColors(sbCol); + myScalarMap->SetLabels(sbLab); + + myScalarMap->GetScalarMapPL()->SetNbColors(sbCol); + myScalarMap->GetScalarMapPL()->Update(); + + aScalarBarActor->SetLookupTable(myScalarMap->GetScalarMapPL()->GetBarTable()); + + if (myTextDlg->getTitleText().latin1() != "") + aScalarBarActor->SetTitle(myTextDlg->getTitleText().latin1()); + else + aScalarBarActor->SetTitle(myScalarMap->GetTitle()); + aScalarBarActor->SetOrientation(getOrientation()); + aScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport(); + aScalarBarActor->GetPositionCoordinate()->SetValue(getX(),getY()); + aScalarBarActor->SetWidth(getWidth()); + aScalarBarActor->SetHeight(getHeight()); + aScalarBarActor->SetNumberOfLabels(sbLab); + aScalarBarActor->SetMaximumNumberOfColors(sbCol); + + // title text property + QColor aTitleColor; + int aTitleFontFamily; + bool isTitleBold; + bool isTitleItalic; + bool isTitleShadow; + myTextDlg->myTitleFont->GetData(aTitleColor,aTitleFontFamily, + isTitleBold,isTitleItalic,isTitleShadow); + vtkTextProperty* aTitleProp = aScalarBarActor->GetTitleTextProperty(); + aTitleProp->SetFontFamily(aTitleFontFamily); + aTitleProp->SetColor(float(aTitleColor.red())/255., + float(aTitleColor.green())/255., + float(aTitleColor.blue())/255.); + (isTitleBold)? aTitleProp->BoldOn() : aTitleProp->BoldOff(); + (isTitleItalic)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff(); + (isTitleShadow)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff(); + + // label text property + QColor aLabelColor; + int aLabelFontFamily; + bool isLabelBold; + bool isLabelItalic; + bool isLabelShadow; + myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily, + isLabelBold, isLabelItalic, isLabelShadow); + vtkTextProperty* aLabelProp = aScalarBarActor->GetLabelTextProperty(); + aLabelProp->SetFontFamily(aLabelFontFamily); + aLabelProp->SetColor(float(aLabelColor.red())/255., + float(aLabelColor.green())/255., + float(aLabelColor.blue())/255.); + (isLabelBold)? aLabelProp->BoldOn() : aLabelProp->BoldOff(); + (isLabelItalic)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff(); + (isLabelShadow)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff(); + + aScalarBarActor->Modified(); + + VISU::GetViewWindow()->AddActor(myPreviewActor); +} +/*! Deleting preview scalar bar + */ +void VisuGUI_ScalarBarPane::deleteScalarBar() +{ + if (myPreviewActor == 0) return; + if (SVTK_ViewWindow* vf = VISU::GetViewWindow()){ + vf->RemoveActor(myPreviewActor); + myPreviewActor->GetScalarBar()->VisibilityOff(); + } + myPreviewActor->Delete(); + myPreviewActor = 0; +} +/*! public: Deleting preview scalar bar + */ +void VisuGUI_ScalarBarPane::deletePreview() +{ + deleteScalarBar(); +} /** * Store values to presentation object */ @@ -634,6 +785,7 @@ void VisuGUI_ScalarBarPane::changeDefaults( int ) WidthSpin->setValue( myHorW ); HeightSpin->setValue( myHorH ); } + updatePreview(); } /*! @@ -671,6 +823,7 @@ void VisuGUI_ScalarBarPane::changeRange( int ) MaxEdit->setText( QString::number( Imax ) ); } myRangeMode = mode; + updatePreview(); } /*! @@ -685,6 +838,7 @@ void VisuGUI_ScalarBarPane::XYChanged( double ) if ( snd == YSpin ) { HeightSpin->setMaxValue( 1.0 - YSpin->value() ); } + updatePreview(); } /*! @@ -803,8 +957,20 @@ bool VisuGUI_ScalarBarPane::check() void VisuGUI_ScalarBarPane::onTextPref() { myIsStoreTextProp = myTextDlg->exec(); + updatePreview(); } +void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview) +{ + if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) { + if (thePreview) { + createScalarBar(); + } else { + deleteScalarBar(); + } + vf->Repaint(); + } +} //####################################################################################### @@ -857,9 +1023,19 @@ VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool Se */ void VisuGUI_ScalarBarDlg::accept() { + myScalarPane->deletePreview(); if (myScalarPane->check()) QDialog::accept(); } +/*! + Called when button is clicked, remove preview and closes dialog +*/ +void VisuGUI_ScalarBarDlg::reject() +{ + myScalarPane->deletePreview(); + QDialog::reject(); +} + //####################################################################################### VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent) diff --git a/src/VISUGUI/VisuGUI_ScalarBarDlg.h b/src/VISUGUI/VisuGUI_ScalarBarDlg.h index c8ddc6ab..33c55f96 100644 --- a/src/VISUGUI/VisuGUI_ScalarBarDlg.h +++ b/src/VISUGUI/VisuGUI_ScalarBarDlg.h @@ -61,6 +61,7 @@ class QToolButton; class QtxDblSpinBox; class SalomeApp_Module; class VisuGUI_FontWg; +class VISU_ScalarMapAct; class VisuGUI_TextPrefDlg: public QDialog { @@ -117,6 +118,7 @@ class VisuGUI_ScalarBarPane : public QVBox int storeToPrsObject(VISU::ScalarMap_i* thePrs); bool check(); + void deletePreview(); protected: QButtonGroup* RangeGroup; @@ -155,6 +157,16 @@ class VisuGUI_ScalarBarPane : public QVBox void changeRange( int ); void XYChanged( double ); void onTextPref(); + void onPreviewCheck(bool thePreview); + void updatePreview(); + + private: + void createScalarBar(); + void deleteScalarBar(); + + QCheckBox* myPreviewCheck; + VISU_ScalarMapAct* myPreviewActor; + VISU::ScalarMap_i* myScalarMap; }; @@ -176,6 +188,7 @@ class VisuGUI_ScalarBarDlg : public QDialog protected slots: void accept(); + void reject(); protected: VisuGUI_ScalarBarPane* myScalarPane;