From: ouv Date: Mon, 26 May 2014 09:31:14 +0000 (+0400) Subject: GUITHARE issue 0002109: External 20696 2D 3D surfaces X-Git-Tag: CTH_1_10_a~7^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4ffe70cec8132dd36958805d99400ba9782abc30;p=modules%2Fgui.git GUITHARE issue 0002109: External 20696 2D 3D surfaces 4) Combine scalar bar --- diff --git a/adm_local/win32/Plot3d.vcproj b/adm_local/win32/Plot3d.vcproj index 9d6125e36..9f77799b0 100644 --- a/adm_local/win32/Plot3d.vcproj +++ b/adm_local/win32/Plot3d.vcproj @@ -233,6 +233,30 @@ /> + + + + + + + + diff --git a/src/Plot3d/Plot3d_Actor.cxx b/src/Plot3d/Plot3d_Actor.cxx index d42f0cee7..047090a6c 100644 --- a/src/Plot3d/Plot3d_Actor.cxx +++ b/src/Plot3d/Plot3d_Actor.cxx @@ -44,6 +44,9 @@ Plot3d_Actor::Plot3d_Actor() { myColorDic = new Plot3d_ColorDic(); + myIsGlobalColorDic = false; + myGlobalColorDic = 0; + myIsDistance = false; myStartPoint = 0; @@ -181,6 +184,33 @@ Plot3d_ColorDic* Plot3d_Actor::GetColorDic() return myColorDic; } +//======================================================================= +//function : SetIsGlobalColorDic +//purpose : +//======================================================================= +void Plot3d_Actor::SetIsGlobalColorDic( const bool theIsGlobalColorDic ) +{ + myIsGlobalColorDic = theIsGlobalColorDic; +} + +//======================================================================= +//function : IsGlobalColorDic +//purpose : +//======================================================================= +bool Plot3d_Actor::IsGlobalColorDic() const +{ + return myIsGlobalColorDic; +} + +//============================================================================= +// Function : SetGlobalColorDic +// Purpose : +//============================================================================= +void Plot3d_Actor::SetGlobalColorDic( Plot3d_ColorDic* theColorDic ) +{ + myGlobalColorDic = theColorDic; +} + //============================================================================= // Function : GetScalarBarActor // Purpose : @@ -273,19 +303,20 @@ void Plot3d_Actor::Build( const int theNX, //============================================================================= void Plot3d_Actor::RecomputeLookupTable() { - if( !myColorDic ) + Plot3d_ColorDic* aColorDic = IsGlobalColorDic() && myGlobalColorDic ? myGlobalColorDic : myColorDic; + if( !aColorDic ) return; vtkPolyDataMapper* aMapper = dynamic_cast( GetMapper() ); if( !aMapper ) return; - double myMinimum = myColorDic->GetMin(); - double myMaximum = myColorDic->GetMax(); + double myMinimum = aColorDic->GetMin(); + double myMaximum = aColorDic->GetMax(); - int aScaleMode = (int)myColorDic->GetScaleMode(); + int aScaleMode = (int)aColorDic->GetScaleMode(); - int nbColors = myColorDic->GetNumber(); + int nbColors = aColorDic->GetNumber(); if ( aScaleMode == Plot3d_ColorDic::Specific ) { nbColors = 1000; @@ -303,7 +334,7 @@ void Plot3d_Actor::RecomputeLookupTable() double range[2] = { aMin, aMax }; double aHueMin, aHueMax, aSaturationMin, aSaturationMax, aValueMin, aValueMax; - myColorDic->GetHSVRange( aHueMin, aHueMax, aSaturationMin, aSaturationMax, aValueMin, aValueMax ); + aColorDic->GetHSVRange( aHueMin, aHueMax, aSaturationMin, aSaturationMax, aValueMin, aValueMax ); double range1[2] = { 0, 0 }; if ( aScaleMode == Plot3d_ColorDic::Linear || @@ -341,7 +372,7 @@ void Plot3d_Actor::RecomputeLookupTable() { if ( aScaleMode == Plot3d_ColorDic::Specific ) { - const Value2ColorList& aSpecificScale = myColorDic->GetSpecificScale(); + const Value2ColorList& aSpecificScale = aColorDic->GetSpecificScale(); if ( aSpecificScale.size() < 2 ) return; diff --git a/src/Plot3d/Plot3d_Actor.h b/src/Plot3d/Plot3d_Actor.h index 5d3899fa8..aab2b4c38 100644 --- a/src/Plot3d/Plot3d_Actor.h +++ b/src/Plot3d/Plot3d_Actor.h @@ -57,6 +57,11 @@ public: Plot3d_ColorDic* GetColorDic(); + void SetIsGlobalColorDic( const bool ); + bool IsGlobalColorDic() const; + + void SetGlobalColorDic( Plot3d_ColorDic* ); + vtkSmartPointer GetScalarBarActor() const; void DisplayScalarBar( const bool ); @@ -83,6 +88,9 @@ public: protected: Plot3d_ColorDic* myColorDic; + bool myIsGlobalColorDic; + Plot3d_ColorDic* myGlobalColorDic; + vtkLookupTable* myLookupTable; vtkSmartPointer myScalarBarActor; diff --git a/src/Plot3d/Plot3d_SetupColorScaleDlg.cxx b/src/Plot3d/Plot3d_SetupColorScaleDlg.cxx index 8421dab82..1dedd54b2 100644 --- a/src/Plot3d/Plot3d_SetupColorScaleDlg.cxx +++ b/src/Plot3d/Plot3d_SetupColorScaleDlg.cxx @@ -42,8 +42,10 @@ // Function : Plot3d_SetupColorScaleDlg // Purpose : Constructor //============================================================================= -Plot3d_SetupColorScaleDlg::Plot3d_SetupColorScaleDlg( QWidget* theParent ) -: QtxDialog( theParent, true, false, QtxDialog::OKCancel ) +Plot3d_SetupColorScaleDlg::Plot3d_SetupColorScaleDlg( QWidget* theParent, + bool theIsGlobal ) +: QtxDialog( theParent, true, false, QtxDialog::OKCancel ), + myIsGlobal( theIsGlobal ) { setWindowTitle( tr( "SETUP_COLOR_SCALE" ) ); @@ -144,6 +146,10 @@ Plot3d_SetupColorScaleDlg::Plot3d_SetupColorScaleDlg( QWidget* theParent ) connect( aScaleModeSpecific, SIGNAL( toggled( bool ) ), aScaleModeSpecificSetup, SLOT( setEnabled( bool ) ) ); connect( aScaleModeSpecificSetup, SIGNAL( clicked() ), this, SLOT( onColorScaleSpecificSetup() ) ); + aScaleModeSpecific->setVisible( !myIsGlobal ); + aScaleModeSpecificSetup->setVisible( !myIsGlobal ); + aRangeGroup->setVisible( !myIsGlobal ); + onColorModeChanged( 0 ); // Blue-Red by default setButtonPosition( Right, Cancel ); @@ -334,26 +340,35 @@ int Plot3d_SetupColorScaleDlg::checkScaleMode() bool isMaxIncorrect = aMax < 0 || fabs( aMax ) < Precision::Confusion(); if ( isMinIncorrect || isMaxIncorrect ) { - if ( SUIT_MessageBox::warning( this, tr( "WARNING" ), tr( "INCORRECT_RANGE" ), - tr( "CORRECT_RANGE" ), tr( "SWITCH_TO_LINEAR" ), 0, 1 ) == 0 ) - { // correct range - if ( isMinIncorrect ) - aMin = aCorrectValue; - - if ( isMaxIncorrect ) - aMax = aCorrectValue; - - bool minBlock = myMinLimit->blockSignals( true ); - bool maxBlock = myMaxLimit->blockSignals( true ); - - myMinLimit->setValue( aMin ); - myMaxLimit->setValue( aMax ); - - myMinLimit->blockSignals( minBlock ); - myMaxLimit->blockSignals( maxBlock ); - } - else // switch to linear mode + int anAnswer = 0; + if( myIsGlobal ) + { + SUIT_MessageBox::warning( this, tr( "WARNING" ), tr( "INCORRECT_RANGE" ) ); setColorScaleMode( Plot3d_ColorDic::Linear ); + } + else + { + if ( SUIT_MessageBox::warning( this, tr( "WARNING" ), tr( "INCORRECT_RANGE" ), + tr( "CORRECT_RANGE" ), tr( "SWITCH_TO_LINEAR" ), 0, 1 ) == 0 ) + { // correct range + if ( isMinIncorrect ) + aMin = aCorrectValue; + + if ( isMaxIncorrect ) + aMax = aCorrectValue; + + bool minBlock = myMinLimit->blockSignals( true ); + bool maxBlock = myMaxLimit->blockSignals( true ); + + myMinLimit->setValue( aMin ); + myMaxLimit->setValue( aMax ); + + myMinLimit->blockSignals( minBlock ); + myMaxLimit->blockSignals( maxBlock ); + } + else // switch to linear mode + setColorScaleMode( Plot3d_ColorDic::Linear ); + } } } return colorScaleMode(); diff --git a/src/Plot3d/Plot3d_SetupColorScaleDlg.h b/src/Plot3d/Plot3d_SetupColorScaleDlg.h index 3287c8790..defd2c966 100644 --- a/src/Plot3d/Plot3d_SetupColorScaleDlg.h +++ b/src/Plot3d/Plot3d_SetupColorScaleDlg.h @@ -48,6 +48,21 @@ struct ColorDicData TCollection_AsciiString Quantity; int ColorMode; QColor CustomColors[2]; + + ColorDicData() + { + Num = 99; + Min = 0; + Max = 1; + HueMin = 0.667; + HueMax = 0; + SaturationMin = 1; + SaturationMax = 1; + ValueMin = 1; + ValueMax = 1; + TimeStep = 0; + ColorMode = 0; + }; }; typedef QList < ColorDicData > ColorDicDataList; @@ -65,7 +80,8 @@ public: enum { BlueRed = 0, BlueWhite, Monochrome, Custom }; public: - Plot3d_SetupColorScaleDlg( QWidget* theParent = 0 ); + Plot3d_SetupColorScaleDlg( QWidget* theParent = 0, + bool theIsGlobal = false ); virtual ~Plot3d_SetupColorScaleDlg(); void setData( const ColorDicData& theColorDicData ); @@ -91,6 +107,8 @@ private: void updateMinMax(); private: + bool myIsGlobal; + QtxIntSpinBox* myInterval; QComboBox* myColorMode; diff --git a/src/Plot3d/Plot3d_SetupSurfacesDlg.cxx b/src/Plot3d/Plot3d_SetupSurfacesDlg.cxx index d703246f9..36c2ffb14 100644 --- a/src/Plot3d/Plot3d_SetupSurfacesDlg.cxx +++ b/src/Plot3d/Plot3d_SetupSurfacesDlg.cxx @@ -48,15 +48,16 @@ Plot3d_SetupSurfacesDlg::Plot3d_SetupSurfacesDlg( QWidget* theParent ) QVBoxLayout* aMainLay = new QVBoxLayout( aMainFrame ); aMainLay->setMargin( 5 ); - myGrp = new QtxGroupBox( aMainFrame ); - myGrp->setTitle( tr( "PARAMETERS" ) ); - aMainLay->addWidget( myGrp ); + QtxGroupBox* aParamGrp = new QtxGroupBox( aMainFrame ); + aParamGrp->setTitle( tr( "PARAMETERS" ) ); + aMainLay->addWidget( aParamGrp ); - QVBoxLayout* aLay = new QVBoxLayout( myGrp ); - aLay->setMargin( 0 ); + QVBoxLayout* aLay = new QVBoxLayout( aParamGrp ); + aLay->setMargin( 5 ); + aLay->setSpacing( 5 ); // Create table - myTable = new QTableWidget( myGrp ); + myTable = new QTableWidget( aParamGrp ); myTable->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); aLay->addWidget( myTable ); @@ -85,12 +86,18 @@ Plot3d_SetupSurfacesDlg::Plot3d_SetupSurfacesDlg( QWidget* theParent ) // Minus button QPixmap minusPix = aResMgr->loadPixmap( "VTKViewer", tr( "ICON_PLOT3D_MINUS" ) ); - myRemoveBtn = new QToolButton( 0 ); - myRemoveBtn->setIcon( minusPix ); - myRemoveBtn->setFixedSize( minusPix.size() ); - myGrp->insertTitleWidget( myRemoveBtn ); + QToolButton* aRemoveBtn = new QToolButton( 0 ); + aRemoveBtn->setIcon( minusPix ); + aRemoveBtn->setFixedSize( minusPix.size() ); + aParamGrp->insertTitleWidget( aRemoveBtn ); - connect( myRemoveBtn, SIGNAL( clicked() ), SLOT( onRemove() ) ); + connect( aRemoveBtn, SIGNAL( clicked() ), SLOT( onRemove() ) ); + + // "Edit global color scale" button + QPushButton* anEditGlobalBtn = new QPushButton( tr( "EDIT_GLOBAL_COLOR_SCALE" ), aParamGrp ); + aLay->addWidget( anEditGlobalBtn ); + + connect( anEditGlobalBtn, SIGNAL( clicked() ), SLOT( onGlobalColorScale() ) ); setButtonPosition( Right, Cancel ); setMinimumWidth( 300 ); @@ -128,7 +135,8 @@ void Plot3d_SetupSurfacesDlg::setText( const int theRow, // Purpose : //============================================================================= void Plot3d_SetupSurfacesDlg::SetParameters( const QStringList& theTexts, - const ColorDicDataList& theColorDicDataList ) + const ColorDicDataList& theColorDicDataList, + const ColorDicData& theGlobalColorDicData ) { int nbRows = theTexts.size(); @@ -147,6 +155,8 @@ void Plot3d_SetupSurfacesDlg::SetParameters( const QStringList& theTexts, myColorDicDataList = theColorDicDataList; + myGlobalColorDicData = theGlobalColorDicData; + myRemovedIndexes.clear(); } @@ -155,7 +165,8 @@ void Plot3d_SetupSurfacesDlg::SetParameters( const QStringList& theTexts, // Purpose : //============================================================================= void Plot3d_SetupSurfacesDlg::GetParameters( QStringList& theTexts, - ColorDicDataList& theColorDicDataList ) const + ColorDicDataList& theColorDicDataList, + ColorDicData& theGlobalColorDicData ) const { int nbRows = myTable->rowCount(); @@ -170,6 +181,8 @@ void Plot3d_SetupSurfacesDlg::GetParameters( QStringList& theTexts, } theColorDicDataList = myColorDicDataList; + + theGlobalColorDicData = myGlobalColorDicData; } //============================================================================= @@ -265,3 +278,16 @@ void Plot3d_SetupSurfacesDlg::onColorScaleBtn() myColorDicDataList[ aRow ] = aColorDicData; } } + +//============================================================================= +// Function : onGlobalColorScale +// Purpose : +//============================================================================= +void Plot3d_SetupSurfacesDlg::onGlobalColorScale() +{ + Plot3d_SetupColorScaleDlg aDlg( this, true ); + aDlg.setData( myGlobalColorDicData ); + + if( aDlg.exec() ) + myGlobalColorDicData = aDlg.getData(); +} diff --git a/src/Plot3d/Plot3d_SetupSurfacesDlg.h b/src/Plot3d/Plot3d_SetupSurfacesDlg.h index 5d9f53f0e..b70cacf9f 100644 --- a/src/Plot3d/Plot3d_SetupSurfacesDlg.h +++ b/src/Plot3d/Plot3d_SetupSurfacesDlg.h @@ -24,13 +24,10 @@ #include "Plot3d_SetupColorScaleDlg.h" #include -#include + #include -class QtxGroupBox; class QTableWidget; -class QwtLegend; -class QToolButton; /* Class : Plot3d_SetupSurfacesDlg @@ -45,27 +42,29 @@ public: virtual ~Plot3d_SetupSurfacesDlg(); void SetParameters( const QStringList& theTexts, - const ColorDicDataList& theColorDicDataList ); + const ColorDicDataList& theColorDicDataList, + const ColorDicData& theGlobalColorDicData ); + void GetParameters( QStringList& theTexts, - ColorDicDataList& theColorDicDataList ) const; + ColorDicDataList& theColorDicDataList, + ColorDicData& theGlobalColorDicData ) const; const QList< int >& GetRemovedIndexes() const; private slots: void onRemove(); void onColorScaleBtn(); + void onGlobalColorScale(); private: void setText( const int theRow, const int theCol, const QString& theText ); private: - - QtxGroupBox* myGrp; QTableWidget* myTable; - QToolButton* myRemoveBtn; ColorDicDataList myColorDicDataList; + ColorDicData myGlobalColorDicData; QList< int > myRemovedIndexes; }; diff --git a/src/Plot3d/Plot3d_ViewWindow.cxx b/src/Plot3d/Plot3d_ViewWindow.cxx index 8f1dfa466..6b8e7a02d 100644 --- a/src/Plot3d/Plot3d_ViewWindow.cxx +++ b/src/Plot3d/Plot3d_ViewWindow.cxx @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -42,9 +43,14 @@ #include #include +#include #include #include #include +#include +#include + +#include /*! Constructor @@ -54,6 +60,56 @@ Plot3d_ViewWindow::Plot3d_ViewWindow( SUIT_Desktop* theDesktop ): myMode2D( false ), myMode2DNormalAxis( AxisZ ) { + // Global scalar bar + myColorDic = new Plot3d_ColorDic(); + + myToDisplayScalarBar = false; + + myScalarBarActor = vtkScalarBarActor::New(); + myScalarBarActor->SetTitle( "All surfaces" ); + myScalarBarActor->SetVisibility( false ); + + // Title props + QColor aTextColor = Qt::white; + + vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New(); + aScalarBarTitleProp->SetColor( aTextColor.redF(), aTextColor.greenF(), aTextColor.blueF() ); + aScalarBarTitleProp->SetFontFamilyToArial(); + int aSize = 24; + aScalarBarTitleProp->SetFontSize( aSize ); + myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp ); + aScalarBarTitleProp->Delete(); + + // Label props + vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New(); + aScalarBarLabelProp->SetColor( aTextColor.redF(), aTextColor.greenF(), aTextColor.blueF() ); + aScalarBarLabelProp->SetFontFamilyToArial(); + myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp ); + aScalarBarLabelProp->Delete(); + + // Position + double aXPos = 0.01, aYPos = 0.1; + myScalarBarActor->SetPosition( aXPos, aYPos ); + + // Width + double aWidth = 0.10, aHeight = 0.80; + myScalarBarActor->SetWidth( aWidth ); + myScalarBarActor->SetHeight( aHeight ); + + // Number of labels and Maximum number of colors + myScalarBarActor->SetNumberOfLabels( 5 ); + myScalarBarActor->SetMaximumNumberOfColors( 99 ); + + // ScalarBar widget + myScalarBarWg = vtkScalarBarWidget::New(); + myScalarBarWg->SetScalarBarActor( myScalarBarActor.GetPointer() ); + + // Lookup table + myLookupTable = vtkLookupTable::New(); + myLookupTable->SetHueRange( 0.667, 0.0 ); + myLookupTable->ForceBuild(); + + myScalarBarActor->SetLookupTable( myLookupTable ); } /*! @@ -61,6 +117,15 @@ Plot3d_ViewWindow::Plot3d_ViewWindow( SUIT_Desktop* theDesktop ): */ Plot3d_ViewWindow::~Plot3d_ViewWindow() { + myScalarBarWg->EnabledOff(); + if( vtkRenderer* aRenderer = getRenderer() ) + aRenderer->RemoveActor( myScalarBarActor.GetPointer() ); + + if( myColorDic ) + { + delete myColorDic; + myColorDic = 0; + } } /*! @@ -71,6 +136,20 @@ void Plot3d_ViewWindow::Initialize( SVTK_ViewModelBase* theModel ) myPlot3dToolBar = toolMgr()->createToolBar( tr( "PLOT3D" ), -1, this ); SVTK_ViewWindow::Initialize( theModel ); + + // Initialize global scalar bar + if( vtkRenderWindow* aRenderWindow = getRenderWindow() ) + { + if( vtkRenderWindowInteractor* aRWI = aRenderWindow->GetInteractor() ) + { + myScalarBarWg->SetInteractor( aRWI ); + if( myToDisplayScalarBar ) + myScalarBarWg->EnabledOn(); + } + } + + if( vtkRenderer* aRenderer = getRenderer() ) + aRenderer->AddActor( myScalarBarActor.GetPointer() ); } /*! @@ -109,6 +188,14 @@ void Plot3d_ViewWindow::createActions( SUIT_ResourceMgr* theResourceMgr ) anAction->setStatusTip( tr( "DSC_PLOT3D_SURFACES_SETTINGS" ) ); connect( anAction, SIGNAL( activated() ), this, SLOT( onSurfacesSettings() ) ); mgr->registerAction( anAction, SurfacesSettingsId ); + + anAction = new QtxAction( tr( "MNU_PLOT3D_MERGE_SCALAR_BARS" ), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_PLOT3D_MERGE_SCALAR_BARS" ) ), + tr( "MNU_PLOT3D_MERGE_SCALAR_BARS" ), 0, this ); + anAction->setStatusTip( tr( "DSC_PLOT3D_MERGE_SCALAR_BARS" ) ); + anAction->setCheckable( true ); + connect( anAction, SIGNAL( toggled( bool ) ), this, SLOT( onMergeScalarBars( bool ) ) ); + mgr->registerAction( anAction, MergeScalarBarsId ); } /*! @@ -122,6 +209,7 @@ void Plot3d_ViewWindow::createToolBar() mgr->append( Mode2DId, myPlot3dToolBar ); mgr->append( SurfacesSettingsId, myPlot3dToolBar ); + mgr->append( MergeScalarBarsId, myPlot3dToolBar ); } /*! @@ -258,12 +346,11 @@ void Plot3d_ViewWindow::onSurfacesSettings() QList< Plot3d_Actor* > aSurfaces; QStringList aTexts; ColorDicDataList aColorDicDataList; - vtkActor* anActor = 0; VTK::ActorCollectionCopy aCopy( aRenderer->GetActors() ); vtkActorCollection* aCollection = aCopy.GetActors(); aCollection->InitTraversal(); - while( anActor = aCollection->GetNextActor() ) + while( vtkActor* anActor = aCollection->GetNextActor() ) { if( Plot3d_Actor* aSurface = dynamic_cast( anActor ) ) { @@ -297,13 +384,27 @@ void Plot3d_ViewWindow::onSurfacesSettings() } } + ColorDicData aGlobalColorDicData; + if( myColorDic ) + { + aGlobalColorDicData.Num = myColorDic->GetNumber(); + aGlobalColorDicData.Min = myColorDic->GetMin(); // non-editable, just to check log scale + aGlobalColorDicData.Max = myColorDic->GetMax(); // non-editable, just to check log scale + myColorDic->GetHSVRange( aGlobalColorDicData.HueMin, aGlobalColorDicData.HueMax, + aGlobalColorDicData.SaturationMin, aGlobalColorDicData.SaturationMax, + aGlobalColorDicData.ValueMin, aGlobalColorDicData.ValueMax ); + aGlobalColorDicData.ScaleMode = myColorDic->GetScaleMode(); + aGlobalColorDicData.ColorMode = myColorDic->GetColorMode(); + myColorDic->GetCustomColors( aGlobalColorDicData.CustomColors[0], aGlobalColorDicData.CustomColors[1] ); + } + Plot3d_SetupSurfacesDlg aDlg( this ); - aDlg.SetParameters( aTexts, aColorDicDataList ); + aDlg.SetParameters( aTexts, aColorDicDataList, aGlobalColorDicData ); if ( aDlg.exec() != QDialog::Accepted ) return; - aDlg.GetParameters( aTexts, aColorDicDataList ); + aDlg.GetParameters( aTexts, aColorDicDataList, aGlobalColorDicData ); // Note: Indexes retrieved from dialog do not correspond to the real indexes of // plot 3d surfaces. They correspond to the user actions. For example, if user removes @@ -368,6 +469,19 @@ void Plot3d_ViewWindow::onSurfacesSettings() } } + if( myColorDic ) + { + myColorDic->SetNumber( aGlobalColorDicData.Num ); + myColorDic->SetHSVRange( aGlobalColorDicData.HueMin, aGlobalColorDicData.HueMax, + aGlobalColorDicData.SaturationMin, aGlobalColorDicData.SaturationMax, + aGlobalColorDicData.ValueMin, aGlobalColorDicData.ValueMax ); + myColorDic->SetScaleMode( aGlobalColorDicData.ScaleMode ); + myColorDic->SetColorMode( aGlobalColorDicData.ColorMode ); + myColorDic->SetCustomColors( aGlobalColorDicData.CustomColors[0], aGlobalColorDicData.CustomColors[1] ); + } + + UpdateScalarBar( false ); + vtkFloatingPointType aGlobalBounds[6] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MIN, VTK_DOUBLE_MAX, VTK_DOUBLE_MIN, VTK_DOUBLE_MAX, VTK_DOUBLE_MIN }; @@ -400,10 +514,19 @@ void Plot3d_ViewWindow::onSurfacesSettings() aScale[0] = fabs( aDX ) > DBL_EPSILON ? 1.0 / aDX : 1.0; aScale[1] = fabs( aDY ) > DBL_EPSILON ? 1.0 / aDY : 1.0; aScale[2] = fabs( aDZ ) > DBL_EPSILON ? 1.0 / aDZ : 1.0; - SetScale( aScale ); + SetScale( aScale, false ); onFitAll(); } +/*! + Merge the scalar bars of all surfaces to a global scalar bar +*/ +void Plot3d_ViewWindow::onMergeScalarBars( bool theOn ) +{ + myToDisplayScalarBar = theOn; + UpdateScalarBar(); +} + /*! Fit 2D surfaces to the specified data range */ @@ -464,3 +587,100 @@ void Plot3d_ViewWindow::clearViewState( const bool theIs2D ) else myStored3DViewState.IsInitialized = false; } + +/*! + Get actor of the global scalar bar + \return actor of the global scalar bar +*/ +vtkSmartPointer Plot3d_ViewWindow::GetScalarBarActor() const +{ + return myScalarBarActor; +} + +/*! + Update representation of the global scalar bar + \param theIsRepaint flag used to repaint the view +*/ +void Plot3d_ViewWindow::UpdateScalarBar( const bool theIsRepaint ) +{ + vtkRenderer* aRenderer = getRenderer(); + if( !aRenderer ) + return; + + QList< Plot3d_Actor* > aSurfaces; + + double aMin = VTK_DOUBLE_MAX; + double aMax = VTK_DOUBLE_MIN; + + VTK::ActorCollectionCopy aCopy( aRenderer->GetActors() ); + vtkActorCollection* aCollection = aCopy.GetActors(); + aCollection->InitTraversal(); + while( vtkActor* anActor = aCollection->GetNextActor() ) + { + if( Plot3d_Actor* aSurface = dynamic_cast( anActor ) ) + { + if( aSurface->GetVisibility() ) + { + if( Plot3d_ColorDic* aColorDic = aSurface->GetColorDic() ) + { + aSurfaces << aSurface; + aMin = qMin( aMin, aColorDic->GetMin() ); + aMax = qMax( aMax, aColorDic->GetMax() ); + } + } + } + } + + bool anIsDisplayedSurfaces = !aSurfaces.isEmpty(); + if( anIsDisplayedSurfaces ) + { + // check the range and reset the scale mode to linear if necessary + if( myColorDic->GetScaleMode() == Plot3d_ColorDic::Logarithmic ) + { + bool isMinIncorrect = aMin < 0 || fabs( aMin ) < Precision::Confusion(); + bool isMaxIncorrect = aMax < 0 || fabs( aMax ) < Precision::Confusion(); + if( isMinIncorrect || isMaxIncorrect ) + { + SUIT_MessageBox::warning( this, tr( "WARNING" ), tr( "INCORRECT_RANGE" ) ); + myColorDic->SetScaleMode( Plot3d_ColorDic::Linear ); + myLookupTable->SetScale( (int)myColorDic->GetScaleMode() ); + } + } + + myColorDic->SetRange( aMin, aMax ); + + myLookupTable->SetRange( aMin, aMax ); + + myLookupTable->SetNumberOfTableValues( myColorDic->GetNumber() ); + + double aHueMin, aHueMax, aSaturationMin, aSaturationMax, aValueMin, aValueMax; + myColorDic->GetHSVRange( aHueMin, aHueMax, aSaturationMin, aSaturationMax, aValueMin, aValueMax ); + myLookupTable->SetHueRange( aHueMin, aHueMax ); + myLookupTable->SetSaturationRange( aSaturationMin, aSaturationMax ); + myLookupTable->SetValueRange( aValueMin, aValueMax ); + + myLookupTable->SetScale( (int)myColorDic->GetScaleMode() ); + myLookupTable->ForceBuild(); + } + + bool anIsDisplayScalarBar = myToDisplayScalarBar && anIsDisplayedSurfaces; + + myScalarBarActor->SetVisibility( anIsDisplayScalarBar ); + myScalarBarWg->SetEnabled( anIsDisplayScalarBar ); + + QListIterator< Plot3d_Actor* > aSurfaceIter( aSurfaces ); + while( aSurfaceIter.hasNext() ) + { + if( Plot3d_Actor* aSurface = aSurfaceIter.next() ) + { + aSurface->SetIsGlobalColorDic( myToDisplayScalarBar ); + aSurface->SetGlobalColorDic( myColorDic ); + + aSurface->RecomputeLookupTable(); + aSurface->DisplayScalarBar( !anIsDisplayScalarBar ); + } + } + + if( theIsRepaint ) + Repaint(); +} diff --git a/src/Plot3d/Plot3d_ViewWindow.h b/src/Plot3d/Plot3d_ViewWindow.h index 61c8d4d7a..d55b4c408 100644 --- a/src/Plot3d/Plot3d_ViewWindow.h +++ b/src/Plot3d/Plot3d_ViewWindow.h @@ -23,13 +23,19 @@ #include +class vtkLookupTable; +class vtkScalarBarActor; +class vtkScalarBarWidget; + +class Plot3d_ColorDic; + class PLOT3D_EXPORT Plot3d_ViewWindow : public SVTK_ViewWindow { Q_OBJECT public: enum { FirstId = SVTK_ViewWindow::LastId, - Mode2DId, SurfacesSettingsId, + Mode2DId, SurfacesSettingsId, MergeScalarBarsId, LastId }; enum Axis { AxisX = 0, AxisY, AxisZ }; @@ -48,9 +54,13 @@ public: void clearViewState( const bool theIs2D ); + vtkSmartPointer GetScalarBarActor() const; + void UpdateScalarBar( const bool theIsRepaint = true ); + public slots: void onMode2D( bool theOn ); void onSurfacesSettings(); + void onMergeScalarBars( bool theOn ); void onFitData(); protected: @@ -83,6 +93,12 @@ protected: int myMode2DNormalAxis; ViewState myStored2DViewState; ViewState myStored3DViewState; + + Plot3d_ColorDic* myColorDic; + vtkSmartPointer myLookupTable; + vtkSmartPointer myScalarBarActor; + vtkSmartPointer myScalarBarWg; + bool myToDisplayScalarBar; }; #endif diff --git a/src/Plot3d/resources/Plot3d_images.ts b/src/Plot3d/resources/Plot3d_images.ts index 09fa563fa..80a805147 100644 --- a/src/Plot3d/resources/Plot3d_images.ts +++ b/src/Plot3d/resources/Plot3d_images.ts @@ -2,16 +2,20 @@ @default - ICON_PLOT3D_SURFACES_SETTINGS - plot3d_surfaces_settings.png + ICON_PLOT3D_MERGE_SCALAR_BARS + plot3d_merge_scalar_bars.png + + + ICON_PLOT3D_MINUS + plot3d_minus.png ICON_PLOT3D_MODE_2D plot3d_mode_2d.png - ICON_PLOT3D_MINUS - plot3d_minus.png + ICON_PLOT3D_SURFACES_SETTINGS + plot3d_surfaces_settings.png diff --git a/src/Plot3d/resources/Plot3d_msg_en.ts b/src/Plot3d/resources/Plot3d_msg_en.ts index 8ab341b40..3cc3c51fd 100644 --- a/src/Plot3d/resources/Plot3d_msg_en.ts +++ b/src/Plot3d/resources/Plot3d_msg_en.ts @@ -6,6 +6,18 @@ ERROR Error + + INCORRECT_RANGE + Logarithmic scale could not be used when the +minimum value of the range is less or equal zero. +The scale has been switched to linear. + + + INCORRECT_RANGE_WITH_QUESTION + Logarithmic scale could not be used when the +minimum value of the range is less or equal zero. +Correct the range or switch to linear scale? + WARNING Warning @@ -80,12 +92,6 @@ CUSTOM Custom - - INCORRECT_RANGE - Logarithmic scale could not be used when the -minimum value of the range is less or equal zero. -Correct the range or switch to linear scale? - LINEAR Linear @@ -200,14 +206,12 @@ Correct the range or switch to linear scale? WRN_INCORRECT_RANGE_MIN_MAX The minimum value of the range should not be greater -or equal the maximum value. - +or equal the maximum value. WRN_INCORRECT_RANGE_LOGARITHMIC The minimum value of the range should not be less -or equal zero in case of logarithmic interpolation. - +or equal zero in case of logarithmic interpolation. WRN_INCONSISTENT_VALUES @@ -228,6 +232,10 @@ or equal zero in case of logarithmic interpolation. EDIT Edit + + EDIT_GLOBAL_COLOR_SCALE + Edit global color scale + PARAMETERS Parameters @@ -250,6 +258,10 @@ or equal zero in case of logarithmic interpolation. Plot3d_ViewWindow + + DSC_PLOT3D_MERGE_SCALAR_BARS + Merge scalar bars + DSC_PLOT3D_MODE_2D Toggle 2D mode @@ -262,6 +274,10 @@ or equal zero in case of logarithmic interpolation. FIT_RANGE Fit range + + MNU_PLOT3D_MERGE_SCALAR_BARS + Merge scalar bars + MNU_PLOT3D_MODE_2D Toggle 2D mode diff --git a/src/Plot3d/resources/plot3d_merge_scalar_bars.png b/src/Plot3d/resources/plot3d_merge_scalar_bars.png new file mode 100644 index 000000000..083740f51 Binary files /dev/null and b/src/Plot3d/resources/plot3d_merge_scalar_bars.png differ diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 2fac0c3e3..cd44acd12 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -431,12 +431,13 @@ namespace SVTK */ void SVTK_View -::EraseAll() +::EraseAll(const bool theIsUpdate) { using namespace SVTK; ForEach(getRenderer()->GetActors(), TErase()); - Repaint(); + if(theIsUpdate) + Repaint(); } /*! @@ -444,12 +445,13 @@ SVTK_View */ void SVTK_View -::DisplayAll() +::DisplayAll(const bool theIsUpdate) { using namespace SVTK; ForEach(getRenderer()->GetActors(), TSetVisibility(true)); - Repaint(); + if(theIsUpdate) + Repaint(); } /*! @@ -460,7 +462,7 @@ SVTK_View void SVTK_View ::Erase(SALOME_Actor* theActor, - bool theIsUpdate) + const bool theIsUpdate) { SVTK::TErase()(theActor); @@ -477,7 +479,7 @@ SVTK_View void SVTK_View ::Erase(const Handle(SALOME_InteractiveObject)& theIObject, - bool theIsUpdate) + const bool theIsUpdate) { using namespace SVTK; ForEachIf(getRenderer()->GetActors(), @@ -493,7 +495,7 @@ SVTK_View void SVTK_View ::Display(SALOME_Actor* theActor, - bool theIsUpdate) + const bool theIsUpdate) { GetRenderer()->AddActor(theActor); theActor->SetVisibility(true); @@ -508,7 +510,7 @@ SVTK_View void SVTK_View ::Display(const Handle(SALOME_InteractiveObject)& theIObject, - bool theIsUpdate) + const bool theIsUpdate) { using namespace SVTK; ForEachIf(getRenderer()->GetActors(), @@ -524,10 +526,11 @@ SVTK_View */ void SVTK_View -::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject) +::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject, + const bool theIsUpdate) { - EraseAll(); - Display(theIObject); + EraseAll(theIsUpdate); + Display(theIObject, theIsUpdate); } @@ -553,7 +556,7 @@ namespace SVTK void SVTK_View ::Remove(const Handle(SALOME_InteractiveObject)& theIObject, - bool theIsUpdate) + const bool theIsUpdate) { using namespace SVTK; ForEachIf(getRenderer()->GetActors(), @@ -569,7 +572,7 @@ SVTK_View void SVTK_View ::Remove(SALOME_Actor* theActor, - bool theIsUpdate) + const bool theIsUpdate) { GetRenderer()->RemoveActor(theActor); if(theIsUpdate) @@ -581,7 +584,7 @@ SVTK_View */ void SVTK_View -::RemoveAll(bool theIsUpdate) +::RemoveAll(const bool theIsUpdate) { vtkRenderer* aRenderer = getRenderer(); if(vtkActorCollection* anActors = aRenderer->GetActors()){ diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 3861add92..6864e14c9 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -198,47 +198,48 @@ public: // Erase Display functions //! To erase all existing VTK presentations void - EraseAll(); + EraseAll(const bool theIsUpdate = true); //! To display all existing VTK presentations void - DisplayAll(); + DisplayAll(const bool theIsUpdate = true); //! To remove from the view all existing VTK presentations void - RemoveAll( const bool immediatly ); + RemoveAll(const bool theIsUpdate = true); //! To erase VTK presentation with defined #SALOME_InteractiveObject void Erase(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true); + const bool theIsUpdate = true); void Remove(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true); + const bool theIsUpdate = true); //! To display VTK presentation with defined #SALOME_InteractiveObject void Display(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true); + const bool theIsUpdate = true); //! To display VTK presentation with defined #SALOME_InteractiveObject and erase all anothers void - DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject); + DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject, + const bool theIsUpdate = true); //! To display the VTK presentation void Display(SALOME_Actor* SActor, - bool immediatly = true); + const bool theIsUpdate = true); //! To erase the VTK presentation void Erase(SALOME_Actor* SActor, - bool immediatly = true); + const bool theIsUpdate = true); //! To remove the VTK presentation void Remove(SALOME_Actor* SActor, - bool updateViewer = true); + const bool theIsUpdate = true); //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_Renderer::SetPreselectionProp diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 20e3569dc..93a788c2a 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -458,48 +458,52 @@ Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEnt /*! Display object \param theIO - object - \param theImmediatly - update viewer + \param theIsUpdate - update viewer */ void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO, - bool theImmediatly) + bool theIsUpdate) { - myView->Display(theIO,theImmediatly); + myView->Display(theIO,theIsUpdate); } /*! Erase object \param theIO - object - \param theImmediatly - update viewer + \param theIsUpdate - update viewer */ void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO, - bool theImmediatly) + bool theIsUpdate) { - myView->Erase(theIO,theImmediatly); + myView->Erase(theIO,theIsUpdate); } /*! Display only passed object \param theIO - object + \param theIsUpdate - update viewer */ -void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO) +void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO, + bool theIsUpdate) { - myView->DisplayOnly(theIO); + myView->DisplayOnly(theIO,theIsUpdate); } /*! Display all objects in view + \param theIsUpdate - update viewer */ -void SVTK_ViewWindow::DisplayAll() +void SVTK_ViewWindow::DisplayAll(bool theIsUpdate) { - myView->DisplayAll(); + myView->DisplayAll(theIsUpdate); } /*! Erase all objects in view + \param theIsUpdate - update viewer */ -void SVTK_ViewWindow::EraseAll() +void SVTK_ViewWindow::EraseAll(bool theIsUpdate) { - myView->EraseAll(); + myView->EraseAll(theIsUpdate); } /*! @@ -580,11 +584,13 @@ void SVTK_ViewWindow::GetScale( double theScale[3] ) /*! Redirect the request to #SVTK_Renderer::SetScale */ -void SVTK_ViewWindow::SetScale( double theScale[3] ) +void SVTK_ViewWindow::SetScale( double theScale[3], + bool theIsUpdate ) { //myMainWindow->SetScale( theScale ); GetRenderer()->SetScale( theScale ); - Repaint(); + if( theIsUpdate ) + Repaint(); } /*! diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 1ec37344f..c2612fc0f 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -171,27 +171,29 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_View::Display (to support old code) virtual void Display(const Handle(SALOME_InteractiveObject)& theIObject, - bool theImmediatly = true); + bool theIsUpdate = true); //! Redirect the request to #SVTK_View::DisplayOnly (to support old code) - virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject); + virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject, + bool theIsUpdate = true); //! Redirect the request to #SVTK_View::Erase (to support old code) virtual void Erase(const Handle(SALOME_InteractiveObject)& theIObject, - bool theImmediatly = true); + bool theIsUpdate = true); //! Redirect the request to #SVTK_View::DisplayAll (to support old code) - virtual void DisplayAll(); + virtual void DisplayAll(bool theIsUpdate = true); //! Redirect the request to #SVTK_View::EraseAll (to support old code) - virtual void EraseAll(); + virtual void EraseAll(bool theIsUpdate = true); //! To repaint the viewer virtual void Repaint(bool theUpdateTrihedron = true); //---------------------------------------------------------------------------- //! Redirect the request to #SVTK_Renderer::SetScale - virtual void SetScale( double theScale[3] ); + virtual void SetScale( double theScale[3], + bool theIsUpdate = true ); //! Redirect the request to #SVTK_Renderer::GetScale virtual void GetScale( double theScale[3] );