Salome HOME
solve bugs #22296, #22298: Error on ZLayers (Graphic3d_GraphicDriver::InsertLayerBefo...
authorPaul RASCLE <paul.rascle@openfields.fr>
Fri, 13 Nov 2020 10:52:12 +0000 (11:52 +0100)
committerYOANN AUDOUIN <B61570@dsp0919998.atlas.edf.fr>
Tue, 1 Dec 2020 16:23:10 +0000 (17:23 +0100)
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx
src/HYDROGUI/HYDROGUI_OCCDisplayer.h
src/HYDROGUI/HYDROGUI_Operation.cxx
src/HYDROGUI/HYDROGUI_Operation.h
src/HYDROGUI/HYDROGUI_ZLayers.cxx

index 28d55705cb63b6b9e441d597532b4e359a8c15e2..c6df7d3ba3ae21c0be4aa2406df18bda05d826be 100755 (executable)
@@ -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();
index 56f75bb725be11f557bd1d3ed488799e033a0185..f4831d03dc97aa775fc9caf8beb12c315407be7c 100644 (file)
@@ -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 )
index 80a55c9ce0e6ffa4fff1a3d4798874fdcdbe0fed..370732ab1c744de3facea6ef7f188974ce1363d0 100644 (file)
@@ -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();
 
index 9a7d14f69bdb291cc524c718c378f65352d4d1e4..f95f891f9d1fb1661052f855ebcf4eacbeda24b5 100644 (file)
@@ -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<OCCViewer_ViewManager*>( 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 ) );
 }
index 92ccf50cf3546d94e7bb15c8ddda031b5d20fd45..f8ac3643b633e7d457c3692dd320ca0ef2abeb24 100644 (file)
@@ -42,6 +42,8 @@ public:
   HYDROGUI_Operation( HYDROGUI_Module* theModule );
   virtual ~HYDROGUI_Operation();
 
+  static bool                         myIsClear;
+
 public:
 
   void                                setName( const QString& theName );
index d3aa9fc83253935594f35fca8b8890501b7c5e12..d44736bd7715541c1c1b2fd33de0b2088518cb27 100644 (file)
@@ -22,6 +22,9 @@
 #include <TColStd_SequenceOfInteger.hxx>
 #include <Graphic3d_ZLayerId.hxx>
 
+//#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;
 }