From: nds Date: Fri, 29 Nov 2013 03:39:38 +0000 (+0000) Subject: Set 2d mode for OCC widget. X-Git-Tag: BR_hydro_v_0_4~139 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=32fa2c8f9f80e7d33fdb7efeff53a1a12f54083f;p=modules%2Fhydro.git Set 2d mode for OCC widget. --- diff --git a/src/HYDROCurveCreator/OCCViewer_Utilities.cxx b/src/HYDROCurveCreator/OCCViewer_Utilities.cxx index 425179f9..c683c014 100644 --- a/src/HYDROCurveCreator/OCCViewer_Utilities.cxx +++ b/src/HYDROCurveCreator/OCCViewer_Utilities.cxx @@ -1,5 +1,6 @@ #include "OCCViewer_Utilities.h" +#include "OCCViewer_ViewWidget.h" #include #include @@ -57,3 +58,44 @@ void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer, break; } } + +void OCCViewer_Utilities::setViewWidget2DMode( OCCViewer_ViewWidget* theViewWidget, + const OCCViewer_ViewWidget::Mode2dType& theMode ) +{ + if ( !theViewWidget ) + return; + + // set a view mode + theViewWidget->set2dMode( theMode ); + bool is2dMode = theMode != OCCViewer_ViewWindow::No2dMode; + + // enable/disable view actions + QList aNo2dActions; + aNo2dActions << OCCViewer_ViewWidget::RotationId + << OCCViewer_ViewWidget::FrontId + << OCCViewer_ViewWidget::BackId + << OCCViewer_ViewWidget::TopId + << OCCViewer_ViewWidget::BottomId + << OCCViewer_ViewWidget::LeftId + << OCCViewer_ViewWidget::RightId; + + QAction* anAction; + for ( int i = 0, aNb = aNo2dActions.size(); i < aNb; i++ ) { + anAction = theViewWidget->action( aNo2dActions[i] ); + if ( anAction ) + anAction->setVisible( !is2dMode ); + } + + // change view position + switch ( theMode ) { + case OCCViewer_ViewWindow::XYPlane: + theViewWidget->onTopView(); + break; + case OCCViewer_ViewWindow::XZPlane: + theViewWidget->onLeftView(); + break; + case OCCViewer_ViewWindow::YZPlane: + theViewWidget->onFrontView(); + break; + } +} diff --git a/src/HYDROCurveCreator/OCCViewer_Utilities.h b/src/HYDROCurveCreator/OCCViewer_Utilities.h index c89eb45f..ce83e2a3 100644 --- a/src/HYDROCurveCreator/OCCViewer_Utilities.h +++ b/src/HYDROCurveCreator/OCCViewer_Utilities.h @@ -4,6 +4,7 @@ #include "CurveCreator_Macro.hxx" #include +#include "OCCViewer_ViewWidget.h" class OCCViewer_Viewer; @@ -23,6 +24,14 @@ public: static void setViewer2DMode( OCCViewer_Viewer* theViewer, const OCCViewer_ViewWindow::Mode2dType& theMode ); + + /*! + * Set 2D mode for the view widget. Hide or show 3D actions. + * \param theViewWidget an OCC view widget + * \param theMode OCC view window mode + */ + static void setViewWidget2DMode( OCCViewer_ViewWidget* theViewWidget, + const OCCViewer_ViewWidget::Mode2dType& theMode ); }; #endif diff --git a/src/HYDROCurveCreator/OCCViewer_ViewWidget.cxx b/src/HYDROCurveCreator/OCCViewer_ViewWidget.cxx index 08d25bb9..ad86a6cf 100644 --- a/src/HYDROCurveCreator/OCCViewer_ViewWidget.cxx +++ b/src/HYDROCurveCreator/OCCViewer_ViewWidget.cxx @@ -152,8 +152,8 @@ const char* imageCrossCursor[] = { "................................"}; // ---------------- OCC view widget -------- -OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent) - : QFrame(parent), myShowTrihedron(true) +OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent, const bool isUseMultiAction) + : QFrame(parent), myShowTrihedron(true), myUseMultiAction(isUseMultiAction) { setObjectName("OCC_view_widget"); mySelectedPoint = gp_Pnt(0.,0.,0.); @@ -170,16 +170,17 @@ OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent) myToolBar = new QToolBar(aBtnBox); aBtnLay->addWidget(myToolBar); - myZoomBtns = new QtxMultiAction(aBtnBox); - myZoomBtns->setObjectName("zoomBtn"); - myToolBar->addAction(myZoomBtns); - myPanBtns = new QtxMultiAction(aBtnBox); - myPanBtns->setObjectName("panBtn"); - myToolBar->addAction(myPanBtns); - myProjBtns = new QtxMultiAction(aBtnBox); - myProjBtns->setObjectName("projectionBtn"); - myToolBar->addAction(myProjBtns); - + if (myUseMultiAction) { + myZoomBtns = new QtxMultiAction(aBtnBox); + myZoomBtns->setObjectName("zoomBtn"); + myToolBar->addAction(myZoomBtns); + myPanBtns = new QtxMultiAction(aBtnBox); + myPanBtns->setObjectName("panBtn"); + myToolBar->addAction(myPanBtns); + myProjBtns = new QtxMultiAction(aBtnBox); + myProjBtns->setObjectName("projectionBtn"); + myToolBar->addAction(myProjBtns); + } // Rotation aBtnLay->addStretch(1); anAnalLay->addWidget(aBtnBox, 0, 0, 1, 2); @@ -230,6 +231,8 @@ OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent) createActions(); myButsMap[TrihId]->setChecked(false); onTrihChanged(); + + my2dMode = No2dMode; } OCCViewer_ViewWidget::~OCCViewer_ViewWidget() @@ -375,19 +378,36 @@ void OCCViewer_ViewWidget::createActions() myToolBar->addAction(aAction); myButsMap[ TrihId ] = aAction; - myZoomBtns->insertAction(myButsMap[ FitAllId ]); - myZoomBtns->insertAction(myButsMap[ FitRectId ]); - myZoomBtns->insertAction(myButsMap[ ZoomId ]); + if (myUseMultiAction) { + myZoomBtns->insertAction(myButsMap[ FitAllId ]); + myZoomBtns->insertAction(myButsMap[ FitRectId ]); + myZoomBtns->insertAction(myButsMap[ ZoomId ]); - myPanBtns->insertAction(myButsMap[ PanId ]); - myPanBtns->insertAction(myButsMap[ GlobalPanId ]); + myPanBtns->insertAction(myButsMap[ PanId ]); + myPanBtns->insertAction(myButsMap[ GlobalPanId ]); - myProjBtns->insertAction(myButsMap[ FrontId ]); - myProjBtns->insertAction(myButsMap[ BackId ]); - myProjBtns->insertAction(myButsMap[ TopId ]); - myProjBtns->insertAction(myButsMap[ BottomId ]); - myProjBtns->insertAction(myButsMap[ LeftId ]); - myProjBtns->insertAction(myButsMap[ RightId ]); + myProjBtns->insertAction(myButsMap[ FrontId ]); + myProjBtns->insertAction(myButsMap[ BackId ]); + myProjBtns->insertAction(myButsMap[ TopId ]); + myProjBtns->insertAction(myButsMap[ BottomId ]); + myProjBtns->insertAction(myButsMap[ LeftId ]); + myProjBtns->insertAction(myButsMap[ RightId ]); + } + else { + myToolBar->addAction(myButsMap[ FitAllId ]); + myToolBar->addAction(myButsMap[ FitRectId ]); + myToolBar->addAction(myButsMap[ ZoomId ]); + + myToolBar->addAction(myButsMap[ PanId ]); + myToolBar->addAction(myButsMap[ GlobalPanId ]); + + myToolBar->addAction(myButsMap[ FrontId ]); + myToolBar->addAction(myButsMap[ BackId ]); + myToolBar->addAction(myButsMap[ TopId ]); + myToolBar->addAction(myButsMap[ BottomId ]); + myToolBar->addAction(myButsMap[ LeftId ]); + myToolBar->addAction(myButsMap[ RightId ]); + } } /*! @@ -443,6 +463,16 @@ bool OCCViewer_ViewWidget::eventFilter(QObject* watched, QEvent* e) return aRes; } +void OCCViewer_ViewWidget::set2dMode(OCCViewer_ViewWidget::Mode2dType theType) +{ + my2dMode = theType; +} + +QAction* OCCViewer_ViewWidget::action( const ButtonsType& theId ) +{ + return myButsMap.contains( theId ) ? myButsMap[theId] : 0; +} + void OCCViewer_ViewWidget::onActivated() { if(!sender() || !sender()->inherits("QtxAction")) @@ -658,7 +688,8 @@ OCCViewer_ViewWidget::OperationType OCCViewer_ViewWidget::getButtonState(QMouseE (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN])) aOp = PANVIEW; else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) && - (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE])) + (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) && + (my2dMode == No2dMode)) aOp = ROTATE; return aOp; diff --git a/src/HYDROCurveCreator/OCCViewer_ViewWidget.h b/src/HYDROCurveCreator/OCCViewer_ViewWidget.h index af70a8f4..455a1294 100644 --- a/src/HYDROCurveCreator/OCCViewer_ViewWidget.h +++ b/src/HYDROCurveCreator/OCCViewer_ViewWidget.h @@ -33,7 +33,10 @@ class CURVECREATOR_EXPORT OCCViewer_ViewWidget : public QFrame Q_OBJECT public: - OCCViewer_ViewWidget(QWidget* parent); + typedef enum { FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, TrihId, + FrontId, BackId, TopId, BottomId, LeftId, RightId, None } ButtonsType; + + OCCViewer_ViewWidget(QWidget* parent, const bool isUseMultiAction = true); ~OCCViewer_ViewWidget(); OCCViewer_ViewPort3d* getViewPort(); @@ -44,7 +47,14 @@ public: void Display(const TopoDS_Shape shape, const bool theShaded, const QColor& shapeColor); -private slots: + enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane}; + + void set2dMode( Mode2dType ); + Mode2dType get2dMode() const { return my2dMode; } + + QAction* action( const ButtonsType& theId ); + +public slots: void onActivated(); void onTrihChanged(); void onFrontView(); @@ -78,8 +88,6 @@ private: bool setTransformRequested (OperationType op); void clearViewer(const bool theUpdate = true); - typedef enum { FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, TrihId, - FrontId, BackId, TopId, BottomId, LeftId, RightId, None } ButtonsType; typedef QMap ActionsMap; private: @@ -109,6 +117,9 @@ private: OCCViewer_ViewWindow::RotationPointType myCurrPointType; gp_Pnt mySelectedPoint; bool myShowTrihedron; + + Mode2dType my2dMode; + bool myUseMultiAction; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx b/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx index 37a295ca..d732b05e 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -51,12 +52,13 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr myEditorWidget = new CurveCreator_Widget( this, NULL ); addWidget( myEditorWidget, 3 ); - myViewWidget = new OCCViewer_ViewWidget( this ); + myViewWidget = new OCCViewer_ViewWidget( this, false ); OCCViewer_ViewPort3d* aViewPort = myViewWidget->getViewPort(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); if ( aResMgr ) aViewPort->setBackground( aResMgr->backgroundValue( "OCCViewer", "background", Qtx::BackgroundData( Qt::black ) ) ); + OCCViewer_Utilities::setViewWidget2DMode( myViewWidget, OCCViewer_ViewWidget::XZPlane ); addWidget( myViewWidget, 4 ); //myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );