From 1d47757b42f36d93f5fb10cdaf760924d81442be Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 21 Apr 2006 15:50:00 +0000 Subject: [PATCH] PAL10462. --- src/OCCViewer/OCCViewer_ClippingDlg.cxx | 48 ++++++++++++++++++--- src/OCCViewer/OCCViewer_ClippingDlg.h | 8 ++++ src/OCCViewer/OCCViewer_ViewWindow.cxx | 57 +++++++++++-------------- src/OCCViewer/OCCViewer_ViewWindow.h | 3 ++ 4 files changed, 79 insertions(+), 37 deletions(-) diff --git a/src/OCCViewer/OCCViewer_ClippingDlg.cxx b/src/OCCViewer/OCCViewer_ClippingDlg.cxx index c17bfd33d..f529ec8d4 100644 --- a/src/OCCViewer/OCCViewer_ClippingDlg.cxx +++ b/src/OCCViewer/OCCViewer_ClippingDlg.cxx @@ -1,17 +1,15 @@ #include "OCCViewer_ClippingDlg.h" #include +#include #include "SUIT_Session.h" #include "SUIT_ViewWindow.h" #include "OCCViewer_ViewWindow.h" #include "OCCViewer_ViewPort3d.h" -//#include "utilities.h" - #include -#include -#include +//#include #include #include #include @@ -210,6 +208,15 @@ OCCViewer_ClippingDlg::~ OCCViewer_ClippingDlg() void OCCViewer_ClippingDlg::closeEvent( QCloseEvent* e ) { erasePreview(); + + // Set the clipping plane back + Handle(V3d_View) aView3d = myView->getViewPort()->getView(); + if ( !aView3d.IsNull() && !myClippingPlane.IsNull() ) + aView3d->SetPlaneOn( myClippingPlane ); + + if (!myView->isCuttingPlane()) + myAction->setOn( false ); + QDialog::closeEvent( e ); } @@ -220,6 +227,8 @@ void OCCViewer_ClippingDlg::closeEvent( QCloseEvent* e ) //================================================================================= void OCCViewer_ClippingDlg::showEvent( QShowEvent* e ) { + ReserveClippingPlane(); + QDialog::showEvent( e ); onPreview( PreviewChB->isChecked() ); } @@ -243,6 +252,15 @@ void OCCViewer_ClippingDlg::hideEvent( QHideEvent* e ) void OCCViewer_ClippingDlg::ClickOnClose() { erasePreview(); + + // Set the clipping plane back + Handle(V3d_View) aView3d = myView->getViewPort()->getView(); + if ( !aView3d.IsNull() && !myClippingPlane.IsNull() ) + aView3d->SetPlaneOn( myClippingPlane ); + + if (!myView->isCuttingPlane()) + myAction->setOn( false ); + reject(); } @@ -261,8 +279,10 @@ void OCCViewer_ClippingDlg::ClickOnApply() SpinBox_Dx->value(), SpinBox_Dy->value(), SpinBox_Dz->value() ); QApplication::restoreOverrideCursor(); - + erasePreview(); + + ReserveClippingPlane(); } @@ -440,6 +460,9 @@ void OCCViewer_ClippingDlg::displayPreview() myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ) ); myPreviewPlane->SetSize( aSize, aSize ); + // Deactivate clipping planes + myView->getViewPort()->getView()->SetPlaneOff(); + ic->Display( myPreviewPlane, 1, -1, false ); ic->SetWidth( myPreviewPlane, 10, false ); ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false ); @@ -507,3 +530,18 @@ bool OCCViewer_ClippingDlg::isValid() { return ( SpinBox_Dx->value()!=0 || SpinBox_Dy->value()!=0 || SpinBox_Dz->value()!=0 ); } + +//================================================================ +// Function : ReserveClippingPlane +// Purpose : Remember the current clipping plane +//================================================================ +void OCCViewer_ClippingDlg::ReserveClippingPlane() +{ + Handle(V3d_View) aView3d = myView->getViewPort()->getView(); + if ( !aView3d.IsNull() ) + { + aView3d->InitActivePlanes(); + if ( aView3d->MoreActivePlanes() ) + myClippingPlane = aView3d->ActivePlane(); + } +} diff --git a/src/OCCViewer/OCCViewer_ClippingDlg.h b/src/OCCViewer/OCCViewer_ClippingDlg.h index e46903a05..44f1943b3 100644 --- a/src/OCCViewer/OCCViewer_ClippingDlg.h +++ b/src/OCCViewer/OCCViewer_ClippingDlg.h @@ -6,6 +6,7 @@ #include #include +#include class QGroupBox; class QLabel; @@ -13,6 +14,7 @@ class QPushButton; class QComboBox; class QCheckBox; class QtxDblSpinBox; +class QtxAction; class OCCViewer_ViewWindow; @@ -28,6 +30,8 @@ class OCCViewer_ClippingDlg : public QDialog public: OCCViewer_ClippingDlg(OCCViewer_ViewWindow* , QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0); ~OCCViewer_ClippingDlg(); + + void SetAction( QtxAction* theAction ) { myAction = theAction; } private : @@ -36,6 +40,7 @@ private : virtual void hideEvent ( QHideEvent * ); void displayPreview(); void erasePreview(); + void ReserveClippingPlane(); bool isValid(); @@ -67,8 +72,11 @@ private : OCCViewer_ViewWindow* myView; Handle(AIS_Plane) myPreviewPlane; + Handle(V3d_Plane) myClippingPlane; bool myBusy; + + QtxAction* myAction; private slots: void ClickOnApply(); diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index dbd2618b6..98227235f 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -671,12 +671,12 @@ void OCCViewer_ViewWindow::createActions() connect(aAction, SIGNAL(activated()), this, SLOT(onCloneView())); myActionsMap[ CloneId ] = aAction; - aAction = new QtxAction(tr("MNU_CLIPPING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" ) ), + myClippingAction = new QtxAction(tr("MNU_CLIPPING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" ) ), tr( "MNU_CLIPPING" ), 0, this); - aAction->setStatusTip(tr("DSC_CLIPPING")); - aAction->setToggleAction( true ); - connect(aAction, SIGNAL(toggled( bool )), this, SLOT(onClipping( bool ))); - myActionsMap[ ClippingId ] = aAction; + myClippingAction->setStatusTip(tr("DSC_CLIPPING")); + myClippingAction->setToggleAction( true ); + connect(myClippingAction, SIGNAL(toggled( bool )), this, SLOT(onClipping( bool ))); + myActionsMap[ ClippingId ] = myClippingAction; aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ), tr( "MNU_SHOOT_VIEW" ), 0, this); @@ -835,7 +835,10 @@ void OCCViewer_ViewWindow::onClipping( bool on ) if ( on ) { if ( !myClippingDlg ) - myClippingDlg = new OCCViewer_ClippingDlg( this, myDesktop ); + { + myClippingDlg = new OCCViewer_ClippingDlg( this, myDesktop ); + myClippingDlg->SetAction( myClippingAction ); + } if ( !myClippingDlg->isShown() ) myClippingDlg->show(); @@ -904,9 +907,12 @@ QImage OCCViewer_ViewWindow::dumpView() void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z, const double dx, const double dy, const double dz ) { + Handle(V3d_View) view = myViewPort->getView(); + if ( view.IsNull() ) + return; + if ( on ) { Handle(V3d_Viewer) viewer = myViewPort->getViewer(); - Handle(V3d_View) view = myViewPort->getView(); // try to use already existing plane or create a new one Handle(V3d_Plane) clipPlane; @@ -922,33 +928,20 @@ void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const dou pln.Coefficients( a, b, c, d ); clipPlane->SetPlane( a, b, c, d ); - Handle(V3d_View) v = myViewPort->getView(); - v->SetPlaneOn( clipPlane ); - v->Update(); - v->Redraw(); + view->SetPlaneOn( clipPlane ); } - else { - Handle(V3d_View) view = myViewPort->getView(); + else + view->SetPlaneOff(); + + view->Update(); + view->Redraw(); +} - // try to use already existing plane - Handle(V3d_Plane) clipPlane; - view->InitActivePlanes(); - if ( view->MoreActivePlanes() ) - clipPlane = view->ActivePlane(); - - Handle(V3d_View) v = myViewPort->getView(); - if ( !clipPlane.IsNull() ) - v->SetPlaneOff( clipPlane ); - else - v->SetPlaneOff(); - - v->Update(); - v->Redraw(); - } - - Handle(V3d_View) v = myViewPort->getView(); - v->Update(); - v->Redraw(); +bool OCCViewer_ViewWindow::isCuttingPlane() +{ + Handle(V3d_View) view = myViewPort->getView(); + view->InitActivePlanes(); + return (view->MoreActivePlanes()); } /*! The method returns the visual parameters of this view as a viewAspect object diff --git a/src/OCCViewer/OCCViewer_ViewWindow.h b/src/OCCViewer/OCCViewer_ViewWindow.h index b6bda965a..439b40cd6 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.h +++ b/src/OCCViewer/OCCViewer_ViewWindow.h @@ -63,6 +63,8 @@ public: void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0, const double dx = 0, const double dy = 0, const double dz = 1); + bool isCuttingPlane(); + virtual QString getVisualParameters(); virtual void setVisualParameters( const QString& parameters ); @@ -151,6 +153,7 @@ protected: private: OCCViewer_ClippingDlg* myClippingDlg; + QtxAction* myClippingAction; }; -- 2.39.2