Salome HOME
refs #457: only top view button should be available in 2d mode
[modules/gui.git] / src / OCCViewer / OCCViewer_Utilities.cxx
1
2 #include "OCCViewer_Utilities.h"
3 #include "OCCViewer_ViewFrame.h"
4 #include "OCCViewer_ViewModel.h"
5 #include "OCCViewer_ViewPort3d.h"
6
7 #include "SUIT_ViewManager.h"
8 #include "QtxActionToolMgr.h"
9 #include <QtxMultiAction.h>
10 #include <V3d_View.hxx>
11
12 #include <QAction>
13
14 void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer,
15                                            const OCCViewer_ViewWindow::Mode2dType& theMode )
16 {
17   OCCViewer_ViewFrame* aFrame = dynamic_cast<OCCViewer_ViewFrame*>
18                                      ( theViewer->getViewManager()->getActiveView() );
19   OCCViewer_ViewWindow* aView = aFrame ? aFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW ) : 0;
20   if ( !aView )
21     return;
22
23   // set a view mode
24   aView->set2dMode( theMode );
25   bool is2dMode = theMode != OCCViewer_ViewWindow::No2dMode;
26
27   // enable/disable view actions
28   QList<int> aNo2dActions;
29   aNo2dActions << OCCViewer_ViewWindow::ChangeRotationPointId
30                << OCCViewer_ViewWindow::RotationId
31                << OCCViewer_ViewWindow::FrontId
32                << OCCViewer_ViewWindow::BackId
33                //<< OCCViewer_ViewWindow::TopId
34                << OCCViewer_ViewWindow::BottomId
35                << OCCViewer_ViewWindow::LeftId
36                << OCCViewer_ViewWindow::RightId
37                << OCCViewer_ViewWindow::AntiClockWiseId
38                << OCCViewer_ViewWindow::ClockWiseId
39                << OCCViewer_ViewWindow::ResetId;
40
41   QtxActionToolMgr* aToolMgr = aView->toolMgr();
42   QAction* anAction;
43   for ( int i = 0, aNb = aNo2dActions.size(); i < aNb; i++ ) {
44     anAction = aToolMgr->action( aNo2dActions[i] );
45     if ( anAction )
46       anAction->setEnabled( !is2dMode );
47   }
48   QAction* aTop = aToolMgr->action( OCCViewer_ViewWindow::TopId );
49   QtxMultiAction* aMulti = dynamic_cast<QtxMultiAction*>( aTop->parent() );
50   aMulti->setActiveAction( aTop );
51
52   // change view position
53   Handle(V3d_View) aView3d = aView->getViewPort()->getView();
54   if ( !aView3d.IsNull() ) {
55     switch ( theMode ) {
56       case OCCViewer_ViewWindow::XYPlane:
57         aView3d->SetProj (V3d_Zpos);
58         break;
59       case OCCViewer_ViewWindow::XZPlane:
60         aView3d->SetProj (V3d_Yneg);
61         break;
62       case OCCViewer_ViewWindow::YZPlane:
63         aView3d->SetProj (V3d_Xpos);
64         break;
65     }
66   }
67 }