From 43fce0c79196b05197b76ba4cad50776dba86ddb Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 31 Jan 2014 08:12:12 +0000 Subject: [PATCH] refs #327 - Polyline is not shown during creation Fix for polyline presentation only. --- src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx | 4 +- src/HYDROGUI/HYDROGUI_OCCDisplayer.h | 15 ++++++ src/HYDROGUI/HYDROGUI_Operation.cxx | 75 +++++++++++++++++++++++++- src/HYDROGUI/HYDROGUI_Operation.h | 13 +++++ src/HYDROGUI/HYDROGUI_PolylineOp.cxx | 46 ++++++++++++---- src/HYDROGUI/HYDROGUI_PolylineOp.h | 5 +- 6 files changed, 142 insertions(+), 16 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 14715ec8..64ef551a 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -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, diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h index 681e137a..d3493654 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h @@ -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. diff --git a/src/HYDROGUI/HYDROGUI_Operation.cxx b/src/HYDROGUI/HYDROGUI_Operation.cxx index cd2ac684..8b397f15 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.cxx +++ b/src/HYDROGUI/HYDROGUI_Operation.cxx @@ -25,6 +25,7 @@ #include "HYDROGUI_InputPanel.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" +#include "HYDROGUI_OCCDisplayer.h" #include #include @@ -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& anOperations = myModule->getActiveOperations(); + if ( anOperations.top() == this ) + { + anOperations.pop(); + } + else { + // find in the stack the current operation and remove it from the stack + QVectorIterator 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 ); diff --git a/src/HYDROGUI/HYDROGUI_Operation.h b/src/HYDROGUI/HYDROGUI_Operation.h index 5388d34b..5f037718 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.h +++ b/src/HYDROGUI/HYDROGUI_Operation.h @@ -27,7 +27,10 @@ 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 diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index dc0d2d6b..2c299e2f 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -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( 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; diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.h b/src/HYDROGUI/HYDROGUI_PolylineOp.h index 2192aa5f..d79d582d 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.h +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.h @@ -27,7 +27,6 @@ #include -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; -- 2.30.2