From: rkv Date: Mon, 23 Dec 2013 10:42:38 +0000 (+0000) Subject: Fix for the bug #255: VTK viewer is not updated after modification of objects. X-Git-Tag: BR_hydro_v_0_7~80 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a1431f03eac1d1aed4203d0568d987c41ce939b3;p=modules%2Fhydro.git Fix for the bug #255: VTK viewer is not updated after modification of objects. --- diff --git a/src/HYDROGUI/HYDROGUI_BathymetryBoundsOp.cxx b/src/HYDROGUI/HYDROGUI_BathymetryBoundsOp.cxx index 35540e01..cf042190 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryBoundsOp.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetryBoundsOp.cxx @@ -23,6 +23,7 @@ #include #include #include +#include HYDROGUI_BathymetryBoundsOp::HYDROGUI_BathymetryBoundsOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) @@ -53,8 +54,10 @@ bool HYDROGUI_BathymetryBoundsOp::processApply( int& theUpdateFlags, QString& th { bool isOK = myBath->CreateBoundaryPolyline(); theUpdateFlags = 0; - if( isOK ) - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + if( isOK ) { + module()->setIsToUpdate( myBath ); + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; + } else theErrorMsg = tr( "CANNOT_CREATE_BOUNDARY_POLYLINE" ); return isOK; diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 9ebcae43..aead39e1 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -505,7 +505,7 @@ bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags, if ( !aPanel ) return false; - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init; return true; } diff --git a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx index 0149a1c8..2f7074ae 100644 --- a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx @@ -169,7 +169,9 @@ bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags, if( !myIsEdit ) module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true ); - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + module()->setIsToUpdate( myEditedObject ); + + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; return true; } diff --git a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx index f7534146..da2cd373 100644 --- a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx +++ b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx @@ -118,6 +118,6 @@ void HYDROGUI_DeleteOp::startOperation() commitDocOperation(); - module()->update( UF_Model | UF_Viewer | UF_OCCViewer ); + module()->update( UF_Model | UF_Viewer | UF_OCCViewer | UF_VTKViewer ); commit(); } diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx index a3b5295e..a88a3e57 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx @@ -117,7 +117,7 @@ HYDROGUI_InputPanel* HYDROGUI_GeoreferencementOp::createInputPanel() const bool HYDROGUI_GeoreferencementOp::processApply( int& theUpdateFlags, QString& theErrorMsg ) { - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init; return store( theErrorMsg ); } diff --git a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx index aa0e89cf..d59e7d10 100644 --- a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx @@ -229,7 +229,9 @@ bool HYDROGUI_ImmersibleZoneOp::processApply( int& theUpdateFlags, if( !myIsEdit ) module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aZoneObj, true ); - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + module()->setIsToUpdate( aZoneObj ); + + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; return true; } diff --git a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx index 8715e918..a454cd98 100644 --- a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx @@ -261,7 +261,8 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags, // Check operation status if ( anIsOk ) { anObject->Update(); - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + module()->setIsToUpdate( anObject ); + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; } } } diff --git a/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx b/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx index d51c0985..301e826d 100644 --- a/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx @@ -174,7 +174,8 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags, // Set operation status anIsOk = true; - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;; + module()->setIsToUpdate( anObstacle ); + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; } else { theErrorMsg = tr( "BAD_IMPORTED_OBSTACLE_FILE" ).arg( aFileName ); } diff --git a/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx b/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx index e41732b2..10f16236 100644 --- a/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx @@ -24,6 +24,7 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" +#include "HYDROGUI_UpdateFlags.h" #include @@ -88,7 +89,7 @@ bool HYDROGUI_ImportProfilesOp::processApply( int& theUpdateFlags, abort(); } - theUpdateFlags = UF_Model; + theUpdateFlags = UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init; return aRes; } diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index dfcc1921..adf9b38c 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -834,6 +834,42 @@ void HYDROGUI_Module::setObjectVisible( const int theViewId, } } +void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject, + const bool theState ) +{ + if( !theObject.IsNull() ) + { + // Process OCC shapes + ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() ); + while( aShapesMapIter != myShapesMap.end() ) + { + const ListOfShapes& aShapesList = aShapesMapIter.value(); + foreach ( HYDROGUI_Shape* aShape, aShapesList ) + { + if ( aShape && IsEqual( aShape->getObject(), theObject ) ) + { + aShape->setIsToUpdate( theState ); + } + } + aShapesMapIter++; + } + // Process VTK shapes + ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() ); + while( aVTKPrsMapIter != myVTKPrsMap.end() ) + { + const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value(); + foreach ( HYDROGUI_VTKPrs* aShape, aShapesList ) + { + if ( aShape && IsEqual( aShape->getObject(), theObject ) ) + { + aShape->setIsToUpdate( theState ); + } + } + aVTKPrsMapIter++; + } + } +} + /////////////////// OCC SHAPES PROCESSING HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject ) const diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 3f46027b..f7957e9c 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -125,7 +125,14 @@ public: void setObjectVisible( const int theViewId, const Handle(HYDROData_Entity)& theObject, const bool theState ); - + /** + * Set IsToUpdate flag for all presentations of the given object to recompute them during + * the next viewer(s) updating. + * @param theObject the data model object + * @param theState the flag to set for object's presentations, it's true by default. + */ + void setIsToUpdate( const Handle(HYDROData_Entity)& theObject, + const bool theState = true ); HYDROGUI_Shape* getObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject ) const; void setObjectShape( const int theViewId, @@ -143,6 +150,7 @@ public: void removeViewVTKPrs( const int theViewId ); void removeObjectVTKPrs( const int theViewId, const Handle(HYDROData_Entity)& theObject ); + /** * Update global imposed range of Z values for the given VTK viewer id */ diff --git a/src/HYDROGUI/HYDROGUI_Poly3DOp.cxx b/src/HYDROGUI/HYDROGUI_Poly3DOp.cxx index 6235cda2..8259381a 100644 --- a/src/HYDROGUI/HYDROGUI_Poly3DOp.cxx +++ b/src/HYDROGUI/HYDROGUI_Poly3DOp.cxx @@ -184,7 +184,8 @@ bool HYDROGUI_Poly3DOp::processApply( int& theUpdateFlags, module()->setObjectVisible( aViewId, aProfile, false ); module()->setObjectVisible( aViewId, aResult, true ); } + module()->setIsToUpdate( aResult ); - theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced; + theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; return true; } diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index 83d3d7ef..dc0d2d6b 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -272,6 +272,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, // Update the wire of polyline aPolylineObj->Update(); + module()->setIsToUpdate( aPolylineObj ); // the viewer should be release from the widget before the module update it // because it has an opened local context and updated presentation should not be displayed in it @@ -283,6 +284,7 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, // the polyline should be rebuild in all viewers, where it is displayed theUpdateFlags |= UF_Viewer | UF_GV_Forced; theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced; + theUpdateFlags |= UF_VTKViewer; size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); if ( anActiveViewId == 0 ) diff --git a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx index a81c4f76..bda67417 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx @@ -234,8 +234,9 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags, // And now we update our edited object aProfileObj->Update(); + module()->setIsToUpdate( aProfileObj ); - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; return true; } diff --git a/src/HYDROGUI/HYDROGUI_SetColorOp.cxx b/src/HYDROGUI/HYDROGUI_SetColorOp.cxx index 511f56b8..fa24977f 100644 --- a/src/HYDROGUI/HYDROGUI_SetColorOp.cxx +++ b/src/HYDROGUI/HYDROGUI_SetColorOp.cxx @@ -150,7 +150,9 @@ bool HYDROGUI_SetColorOp::processApply( int& theUpdateFlags, aPolyObject->SetWireColor( aFirstColor ); } - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + module()->setIsToUpdate( myEditedObject ); + + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; return true; } diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index 822175be..bd7085f4 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -188,8 +188,10 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true ); } + module()->setIsToUpdate( myEditedObject ); + // Set update flags - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; return true; } diff --git a/src/HYDROGUI/HYDROGUI_UpdateObjectOp.cxx b/src/HYDROGUI/HYDROGUI_UpdateObjectOp.cxx index ec2285e5..c653c107 100644 --- a/src/HYDROGUI/HYDROGUI_UpdateObjectOp.cxx +++ b/src/HYDROGUI/HYDROGUI_UpdateObjectOp.cxx @@ -56,7 +56,7 @@ void HYDROGUI_UpdateObjectOp::startOperation() commitDocOperation(); - module()->update( UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced ); + module()->update( UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer ); commit(); } @@ -79,5 +79,6 @@ void HYDROGUI_UpdateObjectOp::updateObject( const Handle(HYDROData_Entity)& theO return; theObject->Update(); + module()->setIsToUpdate( theObject ); } diff --git a/src/HYDROGUI/HYDROGUI_VTKPrs.cxx b/src/HYDROGUI/HYDROGUI_VTKPrs.cxx index 671a2cdc..87a86d5c 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrs.cxx @@ -56,6 +56,7 @@ HYDROGUI_VTKPrs::~HYDROGUI_VTKPrs() //======================================================================= void HYDROGUI_VTKPrs::compute() { + setIsToUpdate( false ); } //======================================================================= diff --git a/src/HYDROGUI/HYDROGUI_VTKPrs.h b/src/HYDROGUI/HYDROGUI_VTKPrs.h index 558d7ba5..f5a3f86f 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrs.h +++ b/src/HYDROGUI/HYDROGUI_VTKPrs.h @@ -28,9 +28,36 @@ #include #include +#include class vtkMapper; +template ActorType* getActor(SVTK_Prs* thePrs); + +/** + * Get a VTK actor of the given presentation. Create a new one if there is no actor yet. + */ +template +ActorType* getActor(SVTK_Prs* thePrs) +{ + ActorType* anActor = 0; + vtkActorCollection* aContent = thePrs->GetObjects(); + if ( aContent ) + { + // Remove old actor because of the problem of GEOM_Actor updating. + //anActor = dynamic_cast( aContent->GetLastActor() ); + aContent->RemoveAllItems(); + } + if ( !anActor ) + { + anActor = ActorType::New(); + thePrs->AddObject( anActor ); + anActor->Delete(); + } + return anActor; +} + + /* Class : HYDROGUI_VTKPrs Description : Base class for all HYDRO presentation in VTK viewer diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx index 31817f2c..5b7a850b 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx @@ -67,6 +67,8 @@ HYDROGUI_VTKPrsBathymetry::~HYDROGUI_VTKPrsBathymetry() //================================================================ void HYDROGUI_VTKPrsBathymetry::compute() { + HYDROGUI_VTKPrs::compute(); + if ( !getObject().IsNull() ) { Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( getObject() ); @@ -141,12 +143,11 @@ void HYDROGUI_VTKPrsBathymetry::compute() myMapper->SetInputData( aVertexGrid ); - SALOME_Actor* anActor = SALOME_Actor::New(); + SALOME_Actor* anActor = getActor(this); anActor->SetMapper( myMapper.GetPointer() ); anActor->setIO( getIO() ); AddObject( anActor ); - anActor->Delete(); aVertexGrid->Delete(); aZValues->Delete(); } diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx index 94d0d405..d4317fcd 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx @@ -200,6 +200,12 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb bool anIsInserted = ( aPrs != 0 ); if( anIsVisible && ( !aPrs || aPrs->getIsToUpdate() || theIsForced ) ) { + // 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 ) diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx index c1a20685..168fd3ad 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx @@ -88,22 +88,18 @@ HYDROGUI_VTKPrsShape::~HYDROGUI_VTKPrsShape() //================================================================ void HYDROGUI_VTKPrsShape::compute() { + HYDROGUI_VTKPrs::compute(); + if ( !getObject().IsNull() ) { buildShape(); if ( !myTopoShape.IsNull() ) { - HYDROGUI_Actor* anActor = HYDROGUI_Actor::New(); + HYDROGUI_Actor* anActor = getActor(this); anActor->SetShape( myTopoShape, VTK_MIN_DEFLECTION ); anActor->setDisplayMode( myDisplayMode ); anActor->setIO( getIO() ); - AddObject( anActor ); - - //double bounds[6]; - //anActor->GetBounds( bounds ); - - anActor->Delete(); } } }