X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_VTKPrsDisplayer.cxx;h=20901f2b6c9dd78e10be7a8656b53d06bcc743b5;hb=dbee981213585cb317e098b0d2a288761cd3d37b;hp=afa82b5204d94016f1f54ba50693df821f65e27e;hpb=9e5f9721be88b2f58dcf4ae6564b2bee69fdb65e;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx index afa82b52..20901f2b 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx @@ -1,12 +1,8 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// Copyright (C) 2014-2015 EDF-R&D // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -26,19 +22,21 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_VTKPrs.h" #include "HYDROGUI_VTKPrsBathymetryDriver.h" +#include "HYDROGUI_VTKPrsShapeDriver.h" #include "HYDROGUI_Tool.h" #include "HYDROData_Tool.h" #include #include #include -#include +//#include #include #include #include #include #include +#include #include #include @@ -52,24 +50,14 @@ //#define SATURATION_START 1.0 //#define SATURATION_END 0.4 -#define HUE_START 1.0 -#define HUE_END 0.0 +#define HUE_START 0.7 +#define HUE_END 0.0 #define SATURATION_START 1.0 #define SATURATION_END 1.0 HYDROGUI_VTKPrsDisplayer::HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule ) -: HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL ) +: HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL ), myShapeDriver( NULL ) { - // The invalid value is used to identify the case when the table range is not initialized yet. - double anInvalidValue = HYDROGUI_VTKPrs::InvalidZValue(); - vtkLookupTable* aTable = vtkLookupTable::New(); - aTable->SetHueRange( HUE_START, HUE_END ); - aTable->SetSaturationRange( SATURATION_START, SATURATION_END ); - aTable->SetTableRange( anInvalidValue, anInvalidValue ); - aTable->SetValueRange( 1.0, 1.0 ); - aTable->SetAlphaRange( 1.0, 1.0 ); - aTable->SetNumberOfColors( NB_COLORS ); - myScalarBar->SetLookupTable( aTable ); } HYDROGUI_VTKPrsDisplayer::~HYDROGUI_VTKPrsDisplayer() @@ -98,13 +86,79 @@ void HYDROGUI_VTKPrsDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& t } } +void HYDROGUI_VTKPrsDisplayer::DisplayAll( const int theViewerId, + const bool theIsForced, + const bool theDoFitAll ) +{ + HYDROGUI_AbstractDisplayer::DisplayAll( theViewerId, theIsForced, theDoFitAll ); + + bool isEraseScalarBar = true; + + SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); + if( aViewer ) + { + SALOME_ListIO aListIO; + aViewer->GetVisible( aListIO ); + + HYDROGUI_VTKPrs* aPrs; + SALOME_ListIteratorOfListIO anIter( aListIO ); + for( ; anIter.More(); anIter.Next() ) + { + Handle(SALOME_InteractiveObject) aPrsObj = anIter.Value(); + if ( !aPrsObj.IsNull() ) + { + Handle(HYDROData_Entity) anObj = + module()->getDataModel()->objectByEntry( aPrsObj->getEntry() ); + aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anObj ); + if( aPrs->needScalarBar() ) + { + isEraseScalarBar = false; + break; + } + } + } + } + + if( isEraseScalarBar ) + EraseScalarBar( theViewerId ); +} + void HYDROGUI_VTKPrsDisplayer::EraseAll( const int theViewerId ) { SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); if( aViewer ) { - aViewer->EraseAll( true ); + aViewer->EraseAll( 0, true ); module()->removeViewVTKPrs( (size_t)aViewer ); + EraseScalarBar( theViewerId ); + } +} + +void HYDROGUI_VTKPrsDisplayer::EraseScalarBar( const int theViewerId, const bool theIsDelete ) +{ + SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); + if( aViewer ) + { + if ( myScalarBars.contains( (size_t)aViewer ) ) + { + SUIT_ViewManager* aViewMgr = dynamic_cast( aViewer->getViewManager() ); + if ( aViewMgr && aViewMgr->getViewsCount() > 0 ) + { + SVTK_ViewWindow* aView = dynamic_cast( aViewMgr->getActiveView() ); + if ( aView ) + { + vtkScalarBarActor* aScalarBar = myScalarBars[ (size_t)aViewer ]; + if ( aView->getRenderer()->HasViewProp( aScalarBar ) ) + { + aView->getRenderer()->RemoveActor2D( aScalarBar ); + } + } + } + if ( theIsDelete ) + { + myScalarBars.remove( (size_t)aViewer ); + } + } } } @@ -142,23 +196,31 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); if( aViewer ) { - // Invalidate global Z range - double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() }; - SetZRange( anInvalidRange ); // Hide colors legend bar SVTK_ViewWindow* aView = dynamic_cast( aViewer->getViewManager()->getActiveView() ); + vtkScalarBarActor* aScalarBar = 0; if ( aView ) { - if ( aView->getRenderer()->HasViewProp( myScalarBar.GetPointer() ) ) + if ( !myScalarBars.contains( (size_t)aViewer ) ) + { + createScalarBar( (size_t)aViewer ); + } + aScalarBar = myScalarBars[ (size_t)aViewer ]; + + if ( aView->getRenderer()->HasViewProp( aScalarBar ) ) { - aView->getRenderer()->RemoveActor2D( myScalarBar.GetPointer() ); + aView->getRenderer()->RemoveActor2D( aScalarBar ); } } + // Invalidate global Z range + double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() }; + SetZRange( (size_t)aViewer, anInvalidRange ); int anInvalidZ = HYDROGUI_VTKPrs::InvalidZValue(); bool isChanged = false; + bool isScalarBarNeeded = false; HYDROGUI_VTKPrs* aPrs; for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { @@ -171,7 +233,13 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb bool anIsInserted = ( aPrs != 0 ); if( anIsVisible && ( !aPrs || aPrs->getIsToUpdate() || theIsForced ) ) { - if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( anObj ) ) + // Erase the presentation in the view because of the problem with GEOM_Actor upadting on second SetShape. + if ( aPrs ) + { + aViewer->Erase( aPrs, true ); + } + // Update the presentation + if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( (size_t)aViewer, anObj ) ) { if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted ) { @@ -184,28 +252,31 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb { if ( anIsVisible ) { - - // Extend the global Z range if necessary - double* aGlobalRange = GetZRange(); - double* aRange = aPrs->getInternalZRange(); - bool anIsUpdate = false; - if ( aRange[0] < aGlobalRange[0] || ValuesEquals( aGlobalRange[0], anInvalidZ ) ) - { - aGlobalRange[0] = aRange[0]; - anIsUpdate = true; - } - if ( aRange[1] > aGlobalRange[1] || ValuesEquals( aGlobalRange[1], anInvalidZ ) ) + if ( aPrs->needScalarBar() ) { - aGlobalRange[1] = aRange[1]; - anIsUpdate = true; - } - - if ( anIsUpdate ) - { - module()->updateVTKZRange( aGlobalRange ); + // Extend the global Z range if necessary + double* aGlobalRange = GetZRange( (size_t)aViewer ); + double* aRange = aPrs->getInternalZRange(); + bool anIsUpdate = false; + if ( aRange[0] < aGlobalRange[0] || ValuesEquals( aGlobalRange[0], anInvalidZ ) ) + { + aGlobalRange[0] = aRange[0]; + anIsUpdate = true; + } + if ( aRange[1] > aGlobalRange[1] || ValuesEquals( aGlobalRange[1], anInvalidZ ) ) + { + aGlobalRange[1] = aRange[1]; + anIsUpdate = true; + } + + if ( anIsUpdate ) + { + module()->updateVTKZRange( (size_t)aViewer, aGlobalRange ); + } } aViewer->Display( aPrs ); + isScalarBarNeeded = isScalarBarNeeded || aPrs->needScalarBar(); } else @@ -217,35 +288,38 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb } } - if ( isChanged ) + if ( aView ) { - // Show colors legend bar - if ( aView ) + if ( isChanged && isScalarBarNeeded && aScalarBar ) { - aView->getRenderer()->AddActor2D( myScalarBar.GetPointer() ); + // Show colors legend bar + aView->getRenderer()->AddActor2D( aScalarBar ); } - } - if ( theDoFitAll ) - { - // Repaint is done inside OnFitAll() - aViewer->getViewManager()->getActiveView()->onAccelAction( SUIT_Accel::ZoomFit ); - } - else if ( isChanged ) - { - aViewer->Repaint(); + // Refresh the view + if ( theDoFitAll ) + { + // Repaint is done inside OnFitAll() + aView->onAccelAction( SUIT_Accel::ZoomFit ); + } + else if ( isChanged ) + { + aView->Repaint( true ); + } } } } void HYDROGUI_VTKPrsDisplayer::purgeObjects( const int theViewerId ) { + bool doEraseScalarBar = false; + SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); if( aViewer ) { SALOME_ListIO aListIO; aViewer->GetVisible( aListIO ); - + HYDROGUI_VTKPrs* aPrs; SALOME_ListIteratorOfListIO anIter( aListIO ); for( ; anIter.More(); anIter.Next() ) @@ -255,21 +329,51 @@ void HYDROGUI_VTKPrsDisplayer::purgeObjects( const int theViewerId ) { Handle(HYDROData_Entity) anOwnerObj = module()->getDataModel()->objectByEntry( aPrsObj->getEntry() ); - if ( !anOwnerObj.IsNull() && anOwnerObj->IsRemoved() ) + if ( anOwnerObj.IsNull() ) + { + // We found an unknown IO presented in the viewer. + // Remove such an orphan presentation from all the views of the viewer. + SUIT_ViewManager* aViewMgr = dynamic_cast( aViewer->getViewManager() ); + if ( aViewMgr && aViewMgr->getViewsCount() > 0 ) + { + QVector aViews = aViewMgr->getViews(); + foreach ( SUIT_ViewWindow* aView, aViews ) + { + SVTK_ViewWindow* aVTKView = dynamic_cast( aView ); + if ( aVTKView ) + { + aVTKView->Erase( aPrsObj, false ); + } + } + } + // Remove the object presentation from the module's cache + module()->removeObjectVTKPrs( (size_t)aViewer, aPrsObj->getEntry() ); + doEraseScalarBar = true; + } + else if ( anOwnerObj->IsRemoved() ) { aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anOwnerObj ); if ( aPrs ) { aViewer->Erase( aPrs ); } + else + { + } module()->removeObjectVTKPrs( (size_t)aViewer, anOwnerObj ); + doEraseScalarBar = true; } } } + + if ( doEraseScalarBar ) + { + EraseScalarBar( theViewerId ); + } } } -HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDROData_Entity)& theObj ) +HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const int theViewId, const Handle(HYDROData_Entity)& theObj ) { HYDROGUI_VTKPrsDriver* aDriver = NULL; ObjectKind aKind = theObj->GetKind(); @@ -277,10 +381,18 @@ HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDRODa { if ( !myDriver ) { - myDriver = new HYDROGUI_VTKPrsBathymetryDriver( myScalarBar.GetPointer() ); + myDriver = new HYDROGUI_VTKPrsBathymetryDriver( myScalarBars[ theViewId ] ); } aDriver = myDriver; } + else + { + if ( !myShapeDriver ) + { + myShapeDriver = new HYDROGUI_VTKPrsShapeDriver( myScalarBars[ theViewId ] ); + } + aDriver = myShapeDriver; + } return aDriver; } @@ -290,12 +402,40 @@ QString HYDROGUI_VTKPrsDisplayer::GetType() const return SVTK_Viewer::Type(); } -void HYDROGUI_VTKPrsDisplayer::SetZRange( double theRange[] ) +void HYDROGUI_VTKPrsDisplayer::SetZRange( const int theViewId, double theRange[] ) { - myScalarBar->GetLookupTable()->SetRange( theRange ); + myScalarBars[ theViewId ]->GetLookupTable()->SetRange( theRange ); } -double* HYDROGUI_VTKPrsDisplayer::GetZRange() const +double* HYDROGUI_VTKPrsDisplayer::GetZRange( const int theViewId ) const { - return myScalarBar->GetLookupTable()->GetRange(); -} \ No newline at end of file + return myScalarBars[ theViewId ]->GetLookupTable()->GetRange(); +} + +void HYDROGUI_VTKPrsDisplayer::createScalarBar( const int theViewId ) +{ + if ( !myScalarBars.contains( theViewId ) ) + { + // The invalid value is used to identify the case when the table range is not initialized yet. + double anInvalidValue = HYDROGUI_VTKPrs::InvalidZValue(); + vtkLookupTable* aTable = vtkLookupTable::New(); + aTable->SetHueRange( HUE_START, HUE_END ); + aTable->SetSaturationRange( SATURATION_START, SATURATION_END ); + aTable->SetTableRange( anInvalidValue, anInvalidValue ); + aTable->SetValueRange( 1.0, 1.0 ); + aTable->SetAlphaRange( 1.0, 1.0 ); + aTable->SetNumberOfColors( NB_COLORS ); + aTable->Build(); + vtkSmartPointer aScalarBar = vtkScalarBarActor::New(); + aScalarBar->SetLookupTable( aTable ); + aScalarBar->SetNumberOfLabels( NB_COLORS * 0.75 ); + aScalarBar->SetWidth( aScalarBar->GetWidth() / 1.5 ); + aScalarBar->SetTextureGridWidth( aScalarBar->GetTextureGridWidth() * 4. ); + aScalarBar->SetTitle( " " ); + // The call of SetTitle() with dummy string is a workaround necessary + // to avoid the problem with uninitialized variables in VTK scalar bar actor + // which leads to incorrect (very big) size of the VTK scalar bar presentation + aTable->Delete(); + myScalarBars.insert( theViewId, aScalarBar ); + } +}