From 7bbc4c40cfc71c153d805c1ebd4d054d252871c2 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Fri, 13 Nov 2020 11:52:12 +0100 Subject: [PATCH] solve bugs #22296, #22298: Error on ZLayers (Graphic3d_GraphicDriver::InsertLayerBefore) on second study (after new document). Need a patch on Occ740p3 Patch is on src/V3d/V3d_Viewer.cxx, src/V3d/V3d_Viewer.hxx Standard_EXPORT Standard_Boolean RemoveZLayer (const Graphic3d_ZLayerId theLayerId, bool isForce = false) if (isForce) myDriver->RemoveZLayer (theLayerId); --- src/HYDROGUI/HYDROGUI_Module.cxx | 2 ++ src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx | 23 ++++++++++++++++++++--- src/HYDROGUI/HYDROGUI_OCCDisplayer.h | 3 ++- src/HYDROGUI/HYDROGUI_Operation.cxx | 14 ++++++++++++++ src/HYDROGUI/HYDROGUI_Operation.h | 2 ++ src/HYDROGUI/HYDROGUI_ZLayers.cxx | 6 +++++- 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 28d55705..c6df7d3b 100755 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -30,6 +30,7 @@ #include "HYDROGUI_OCCDisplayer.h" #include "HYDROGUI_OCCSelector.h" #include "HYDROGUI_Operations.h" +#include "HYDROGUI_Operation.h" #include "HYDROGUI_PrsImage.h" #include "HYDROGUI_Tool.h" #include "HYDROGUI_Tool2.h" @@ -358,6 +359,7 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy ) void HYDROGUI_Module::studyClosed(SUIT_Study* theStudy) { DEBTRACE("HYDROGUI_Module::studyClosed"); + HYDROGUI_Operation::myIsClear = false; // force clear of Zlayers on next study Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); if (!aDoc.IsNull()) aDoc->Close(); diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 56f75bb7..f4831d03 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -55,6 +55,7 @@ HYDROGUI_OCCDisplayer::HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule ) : HYDROGUI_AbstractDisplayer( theModule ) { + DEBTRACE("HYDROGUI_OCCDisplayer"); myToUpdateColorScale = false; } @@ -85,6 +86,7 @@ void HYDROGUI_OCCDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theO int HYDROGUI_OCCDisplayer::AddPreviewZLayer( OCCViewer_ViewManager* theMgr ) { + DEBTRACE("AddPreviewZLayer"); int aLayer = -1; OCCViewer_Viewer* aViewer = theMgr->getOCCViewer(); if ( !aViewer ) @@ -105,11 +107,16 @@ int HYDROGUI_OCCDisplayer::AddPreviewZLayer( OCCViewer_ViewManager* theMgr ) } void HYDROGUI_OCCDisplayer::RemoveZLayer( OCCViewer_ViewManager* theMgr, - const int theLayer ) + const int theLayer, + bool isClearAll) { + DEBTRACE("RemoveZLayer " << theLayer << " " << isClearAll); if ( theLayer < 0 ) return; + if ( !theMgr ) + return; + OCCViewer_Viewer* aViewer = theMgr->getOCCViewer(); if ( !aViewer ) return; @@ -119,8 +126,18 @@ void HYDROGUI_OCCDisplayer::RemoveZLayer( OCCViewer_ViewManager* theMgr, aViewer->getViewer3d()->GetAllZLayers( anExistingZLayers ); int aNbLayers = anExistingZLayers.Length(); - if ( theLayer < aNbLayers ) - aViewer->getViewer3d()->RemoveZLayer( theLayer ); + if (isClearAll) + { + for ( int i = 1; i <= aNbLayers; i++ ) + { + int val = anExistingZLayers.Value( i ); + if (val > 0) + aViewer->getViewer3d()->RemoveZLayer( val, true ); + } + } + else + if ( theLayer < aNbLayers ) + aViewer->getViewer3d()->RemoveZLayer( theLayer ); } void HYDROGUI_OCCDisplayer::EraseAll( const size_t theViewerId ) diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h index 80a55c9c..370732ab 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h @@ -71,7 +71,8 @@ public: * \param theLayer a layer index */ void RemoveZLayer( OCCViewer_ViewManager* theMgr, - const int theLayer ); + const int theLayer, + bool isClearAll = false); void SetToUpdateColorScale(); diff --git a/src/HYDROGUI/HYDROGUI_Operation.cxx b/src/HYDROGUI/HYDROGUI_Operation.cxx index 9a7d14f6..f95f891f 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.cxx +++ b/src/HYDROGUI/HYDROGUI_Operation.cxx @@ -43,6 +43,8 @@ //#define _DEVDEBUG_ #include "HYDRO_trace.hxx" +bool HYDROGUI_Operation::myIsClear = false; + HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule ) : LightApp_Operation(), myModule( theModule ), @@ -53,6 +55,7 @@ HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule ) myPreviewZLayer( -1 ), myIsApplyAndClose( true ) { + DEBTRACE("HYDROGUI_Operation"); connect( this, SIGNAL( helpContextModule( const QString&, const QString&, const QString& ) ), theModule->application(), SLOT( onHelpContextModule( const QString&, @@ -61,6 +64,7 @@ HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule ) HYDROGUI_Operation::~HYDROGUI_Operation() { + DEBTRACE("~HYDROGUI_Operation"); } void HYDROGUI_Operation::setName( const QString& theName ) @@ -158,7 +162,17 @@ void HYDROGUI_Operation::setPreviewManager( OCCViewer_ViewManager* theManager ) // module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() ); myPreviewManager = theManager; + // the manager can be null on abort Operation and we need to clear ZLayers on first call, when on new document (second study without SALOME restart) + OCCViewer_ViewManager* aViewManager = myPreviewManager; + if ( !aViewManager ) + aViewManager = dynamic_cast( module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ); + DEBTRACE("aViewManager, myPreviewManager " << aViewManager << " " << myPreviewManager); + if (!myIsClear) + { + module()->getOCCDisplayer()->RemoveZLayer(aViewManager, 0, true); + myIsClear = true; + } if ( myPreviewManager ) setPreviewZLayer( module()->getOCCDisplayer()->AddPreviewZLayer( myPreviewManager ) ); } diff --git a/src/HYDROGUI/HYDROGUI_Operation.h b/src/HYDROGUI/HYDROGUI_Operation.h index 92ccf50c..f8ac3643 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.h +++ b/src/HYDROGUI/HYDROGUI_Operation.h @@ -42,6 +42,8 @@ public: HYDROGUI_Operation( HYDROGUI_Module* theModule ); virtual ~HYDROGUI_Operation(); + static bool myIsClear; + public: void setName( const QString& theName ); diff --git a/src/HYDROGUI/HYDROGUI_ZLayers.cxx b/src/HYDROGUI/HYDROGUI_ZLayers.cxx index d3aa9fc8..d44736bd 100644 --- a/src/HYDROGUI/HYDROGUI_ZLayers.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLayers.cxx @@ -22,6 +22,9 @@ #include #include +//#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" + void SetZLayerForPrs( const Handle(PrsMgr_Presentation)& thePrs, int theLayerId ); void SetPrsZLayer( const Handle(PrsMgr_PresentableObject)& thePresentableObject, @@ -68,12 +71,13 @@ void SetZLayerSettings( const Handle(V3d_Viewer)& theViewer3d, int theLayerId, b int CreateTopZLayer( const Handle(V3d_Viewer)& theViewer3d ) { + DEBTRACE("CreateTopZLayer"); int aTopZLayer = Graphic3d_ZLayerId_Top; if ( theViewer3d && !theViewer3d->AddZLayer( aTopZLayer ) ) { aTopZLayer = Graphic3d_ZLayerId_Top; } - + DEBTRACE(" aTopZLayer: " << aTopZLayer); return aTopZLayer; } -- 2.39.2