#include "VisuGUI.h"
#include "VisuGUI_Tools.h"
-#include "VisuGUI_FontWg.h"
+
+#include "SVTK_FontWidget.h"
+
+#include "SVTK_ViewWindow.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"
#include <qvalidator.h>
#include <qcolordialog.h>
+#include <vtkTextProperty.h>
+
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;
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 ) );
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"), CheckGroup);
+ myPreviewCheck->setChecked(false);
+ CheckGroupLayout->addWidget(myPreviewCheck , 0, 0 );
+
// 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 ) ) );
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( CBLog, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ));
changeRange( 0 );
changeDefaults( 0 );
myIsStoreTextProp = false;
+ myBusy = false;
}
-
/**
* Initializes dialog box values from resources
*/
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);
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);
*/
void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
initFromResources();
- myModeCombo->setCurrentItem(thePrs->GetScalarMode());
+ myScalarMap = thePrs;
setPosAndSize( thePrs->GetPosX(),
thePrs->GetPosY(),
thePrs->GetWidth(),
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);
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;
+
+ if(!check()) return;
+
+ if ( myBusy ) return;
+
+ myBusy = true;
+
+ 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);
+
+ myBusy = false;
+}
+/*! Deleting preview scalar bar
+ */
+void VisuGUI_ScalarBarPane::deleteScalarBar()
+{
+ if ( myBusy ) return;
+
+ 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
*/
WidthSpin->setValue( myHorW );
HeightSpin->setValue( myHorH );
}
+ updatePreview();
}
/*!
MaxEdit->setText( QString::number( Imax ) );
}
myRangeMode = mode;
+ updatePreview();
}
/*!
if ( snd == YSpin ) {
HeightSpin->setMaxValue( 1.0 - YSpin->value() );
}
+ 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] ) );
+ }
+ }
}
/*!
changeRange( 0 );
}
+/*!
+ Sets default values and range mode
+*/
+void VisuGUI_ScalarBarPane::setDefaultRange(double imin, double imax){
+ Rmin = imin;
+ Rmax = imax;
+}
+
/*!
Sets size and position
*/
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();
+ }
+}
//#######################################################################################
*/
void VisuGUI_ScalarBarDlg::accept()
{
- if (myScalarPane->check()) QDialog::accept();
+ if (myScalarPane->check())
+ {
+ myScalarPane->deletePreview();
+ QDialog::accept();
+ }
+}
+
+/*!
+ Called when <Cancel> button is clicked, remove preview and closes dialog
+*/
+void VisuGUI_ScalarBarDlg::reject()
+{
+ myScalarPane->deletePreview();
+ QDialog::reject();
}
// font
QHBox* aHBox = new QHBox (aTitleGrp);
aHBox->setSpacing(5);
- myTitleFont = new VisuGUI_FontWg (aHBox);
+ myTitleFont = new SVTK_FontWidget (aHBox);
TopLayout->addWidget(aTitleGrp);
// font
aHBox = new QHBox (aLabelsGrp);
aHBox->setSpacing(5);
- myLabelFont = new VisuGUI_FontWg (aHBox);
+ myLabelFont = new SVTK_FontWidget (aHBox);
TopLayout->addWidget(aLabelsGrp);