Salome HOME
refs #327 - Polyline is not shown during creation
authornds <nds@opencascade.com>
Fri, 31 Jan 2014 08:12:12 +0000 (08:12 +0000)
committernds <nds@opencascade.com>
Fri, 31 Jan 2014 08:12:12 +0000 (08:12 +0000)
Fix for polyline presentation only.

src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx
src/HYDROGUI/HYDROGUI_OCCDisplayer.h
src/HYDROGUI/HYDROGUI_Operation.cxx
src/HYDROGUI/HYDROGUI_Operation.h
src/HYDROGUI/HYDROGUI_PolylineOp.cxx
src/HYDROGUI/HYDROGUI_PolylineOp.h

index 14715ec82d069a81d270b1368d8110ecc98a2a1e..64ef551a60a040790e96827bb0cdf8c31a4715ab 100644 (file)
@@ -80,9 +80,9 @@ int HYDROGUI_OCCDisplayer::AddTopZLayer( OCCViewer_ViewManager* theMgr )
 
   Standard_Integer aNewId = -1;
   if ( aViewer->getViewer3d()->AddZLayer( aNewId ) )
-    aZLayer = aNewId;
+    aLayer = aNewId;
 
-  return aZLayer;
+  return aLayer;
 }
 
 void HYDROGUI_OCCDisplayer::RemoveZLayer( OCCViewer_ViewManager* theMgr,
index 681e137abcdc629e70073b385194cd52eb4582e4..d34936547a8a6702c575a55d05588a890543a416 100644 (file)
@@ -27,6 +27,7 @@
 
 class HYDROGUI_Shape;
 class Handle(AIS_InteractiveContext);
+class OCCViewer_ViewManager;
 
 /**
  * \class HYDROGUI_OCCDisplayer
@@ -60,6 +61,20 @@ public:
    */
   virtual QString  GetType() const;
 
+  /**
+   * \brief Add the top z layer and returns its index.
+   * \param theMgr OCC view manager
+   */
+  int                             AddTopZLayer( OCCViewer_ViewManager* theMgr );
+
+  /**
+   * \brief Removes the z layer.
+   * \param theMgr OCC view manager
+   * \param theLayer a layer index
+   */
+  void                            RemoveZLayer( OCCViewer_ViewManager* theMgr,
+                                                const int theLayer );
+
 protected:
   /**
    * \brief Erase all viewer objects.
index cd2ac6849a993eed670e8b5dad3bf86dae7263c9..8b397f151c77e5938f4e07fef8cb5c800ed7e8b0 100644 (file)
@@ -25,6 +25,7 @@
 #include "HYDROGUI_InputPanel.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
+#include "HYDROGUI_OCCDisplayer.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Iterator.h>
@@ -42,7 +43,9 @@ HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
 : LightApp_Operation(),
   myModule( theModule ),
   myPanel( 0 ),
-  myIsPrintErrorMessage( true )
+  myIsPrintErrorMessage( true ),
+  myPreviewManager( 0 ),
+  myPreviewZLayer( -1 )
 {
   connect( this, SIGNAL( helpContextModule( const QString&, const QString&,
                                             const QString& ) ),
@@ -86,9 +89,51 @@ HYDROGUI_Module* HYDROGUI_Operation::module() const
   return myModule;
 }
 
+/**
+  * Returns Z layer of the operation preview.
+  \ returns a layer position
+ */
+int HYDROGUI_Operation::getPreviewZLayer() const
+{
+  return myPreviewZLayer;
+}
+
+/**
+ * Set Z layer for the operation preview.
+ \param theLayer a layer position
+ */
+void HYDROGUI_Operation::setPreviewZLayer( int theLayer )
+{
+  if ( theLayer != myPreviewZLayer )
+    myPreviewZLayer = theLayer;
+}
+
+/**
+ * Return the operation preview manager
+ */
+OCCViewer_ViewManager* HYDROGUI_Operation::getPreviewManager()
+{
+  return myPreviewManager;
+}
+
+/**
+ * Set the preview manager
+ */
+void HYDROGUI_Operation::setPreviewManager( OCCViewer_ViewManager* theManager )
+{
+  if ( !theManager && myPreviewManager )
+    module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() );
+
+  myPreviewManager = theManager;
+
+  if ( myPreviewManager )
+    setPreviewZLayer( module()->getOCCDisplayer()->AddTopZLayer( myPreviewManager ) );
+}
+
 void HYDROGUI_Operation::startOperation()
 {
   LightApp_Operation::startOperation();
+  myModule->getActiveOperations().push( this );
 
   if( inputPanel() )
   {
@@ -109,6 +154,34 @@ void HYDROGUI_Operation::commitOperation()
   closeInputPanel();
 }
 
+void HYDROGUI_Operation::stopOperation()
+{
+  LightApp_Operation::stopOperation();
+
+  // pop the operation from the cached map of active operations
+  QStack<HYDROGUI_Operation*>& anOperations = myModule->getActiveOperations();
+  if ( anOperations.top() == this )
+  {
+    anOperations.pop();
+  }
+  else {
+    // find in the stack the current operation and remove it from the stack
+    QVectorIterator<HYDROGUI_Operation*> aVIt( anOperations );
+    aVIt.toBack();
+    aVIt.previous(); // skip the top show/hide operation
+    while ( aVIt.hasPrevious() )
+    {
+      HYDROGUI_Operation* anOp = aVIt.previous();
+      if ( anOp == this )
+        anOperations.remove( anOperations.lastIndexOf( anOp ) );
+    }
+  }
+
+  // removes the Z layer, created for the operation preview
+  if ( myPreviewManager && getPreviewZLayer() >= 0 )
+    module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() );
+}
+
 void HYDROGUI_Operation::setDialogActive( const bool active )
 {
   LightApp_Operation::setDialogActive( active );
index 5388d34b5b95aea64561291efcbe5a3acf025ed0..5f03771882d62d67c2e17693979404af6cd4410e 100644 (file)
 
 class HYDROGUI_Module;
 class HYDROGUI_InputPanel;
+
 class SUIT_SelectionMgr;
+class OCCViewer_ViewManager;
+
 class Handle_HYDROData_Document;
 class Handle_HYDROData_Object;
 
@@ -49,6 +52,9 @@ public:
   SUIT_SelectionMgr*                  selectionMgr() const;
   HYDROGUI_Module*                    module() const;
 
+  int                                 getPreviewZLayer() const;
+  virtual void                        updatePreviewZLayer( int theLayer ) {};
+
 signals:
   void                                helpContextModule( const QString&,
                                                          const QString&,
@@ -58,6 +64,7 @@ protected:
   virtual void                        startOperation();
   virtual void                        abortOperation();
   virtual void                        commitOperation();
+  virtual void                        stopOperation();
   virtual void                        setDialogActive( const bool );
 
   virtual HYDROGUI_InputPanel*        createInputPanel() const;
@@ -89,12 +96,18 @@ protected:
   QString                             getHelpFile() const;
   QString                             getHelpContext() const;
 
+  virtual void                        setPreviewZLayer( int theLayer );
+  OCCViewer_ViewManager*              getPreviewManager();
+  void                                setPreviewManager( OCCViewer_ViewManager* theManager );
+
 private:
 
   HYDROGUI_Module*                    myModule;
   HYDROGUI_InputPanel*                myPanel;
+  OCCViewer_ViewManager*              myPreviewManager;
   QString                             myName;
   bool                                myIsPrintErrorMessage;
+  int                                 myPreviewZLayer;
 };
 
 #endif
index dc0d2d6b12f85d497a8e9b55ff765a7cb358faf8..2c299e2f778c38e300cb5ce9f59c7df6891d07a3 100755 (executable)
@@ -52,8 +52,7 @@
 HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit )
 : HYDROGUI_Operation( theModule ), 
   myIsEdit( theIsEdit ),
-  myCurve( NULL ), 
-  myViewManager( NULL )
+  myCurve( NULL )
 {
   setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) );
 }
@@ -81,6 +80,32 @@ bool HYDROGUI_PolylineOp::deleteEnabled()
   return aPanel->deleteEnabled();
 }
 
+/**
+ * Set Z layer for the operation preview.
+ \param theLayer a layer position
+ */
+void HYDROGUI_PolylineOp::updatePreviewZLayer( int theLayer )
+{
+  setPreviewZLayer( theLayer );
+
+  int aZLayer = getPreviewZLayer();
+  if ( aZLayer >= 0 )
+  {
+    if( getPreviewManager() )
+    {
+      if ( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
+      {
+        Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+        if( !aCtx.IsNull() )
+        {
+          Handle(AIS_InteractiveObject) anObject = myCurve->getAISObject( true );
+          aCtx->SetZLayer( anObject, aZLayer );
+        }
+      }
+    }
+  }
+}
+
 void HYDROGUI_PolylineOp::startOperation()
 {
   if( myIsEdit )
@@ -109,9 +134,10 @@ void HYDROGUI_PolylineOp::startOperation()
   aPanel->reset();
 
   LightApp_Application* anApp = module()->getApp();
-  myViewManager =
+  OCCViewer_ViewManager* aViewManager =
     dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
-  aPanel->setOCCViewer( myViewManager ? myViewManager->getOCCViewer() : 0 );
+  aPanel->setOCCViewer( aViewManager ? aViewManager->getOCCViewer() : 0 );
+  setPreviewManager( aViewManager );
 
   QString aPolylineName;
   if( !myEditedObject.IsNull() )
@@ -320,14 +346,14 @@ void HYDROGUI_PolylineOp::onEditorSelectionChanged()
 
 void HYDROGUI_PolylineOp::displayPreview()
 {
-  if( myViewManager )
+  if( getPreviewManager() )
   {
-    if( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
+    if( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
     {
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if( !aCtx.IsNull() )
       {
-        CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
+        CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx, getPreviewZLayer() );
         myCurve->setDisplayer( aDisplayer );
         aDisplayer->display( myCurve->getAISObject( true ), true );
       }
@@ -338,9 +364,9 @@ void HYDROGUI_PolylineOp::displayPreview()
 void HYDROGUI_PolylineOp::erasePreview()
 {
   CurveCreator_Displayer* aDisplayer = myCurve ? myCurve->getDisplayer() : 0;
-  if( myViewManager && aDisplayer )
+  if( getPreviewManager() && aDisplayer )
   {
-    if( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
+    if( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
     {
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if( !aCtx.IsNull() )
@@ -350,7 +376,7 @@ void HYDROGUI_PolylineOp::erasePreview()
     }
   }
 
-  myViewManager = NULL;
+  setPreviewManager( NULL );
   if ( myCurve )
   {
     delete myCurve;
index 2192aa5fe4df7aa955b62f43dcd8efde547b9b34..d79d582dff2cd5f89f3b416494f20a39bf7262d5 100755 (executable)
@@ -27,7 +27,6 @@
 
 #include <HYDROData_PolylineXY.h>
 
-class OCCViewer_ViewManager;
 class CurveCreator_Curve;
 
 class HYDROGUI_PolylineOp : public HYDROGUI_Operation
@@ -41,6 +40,8 @@ public:
   void                       deleteSelected();
   bool                       deleteEnabled();
 
+  virtual void               updatePreviewZLayer( int theLayer );
+
 protected:
   virtual void               startOperation();
   virtual void               abortOperation();
@@ -58,8 +59,6 @@ private:
   void                       erasePreview();
 
 private:
-  OCCViewer_ViewManager*       myViewManager;
-
   bool                         myIsEdit;
   Handle(HYDROData_PolylineXY) myEditedObject;
   CurveCreator_Curve*          myCurve;