Salome HOME
Copyright update 2022
[modules/gui.git] / src / SOCC / SOCC_ViewWindow.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SOCC_ViewWindow.h"
24
25 #include "OCCViewer_ViewPort3d.h"
26
27 #include "SUIT_Accel.h"
28
29 /*!
30   Constructor
31 */
32 SOCC_ViewWindow
33 ::SOCC_ViewWindow( SUIT_Desktop* theDesktop, 
34                    OCCViewer_Viewer* theModel)
35   : OCCViewer_ViewWindow( theDesktop, theModel )
36 {
37 }
38
39 /*!
40   Destructor
41 */
42 SOCC_ViewWindow
43 ::~SOCC_ViewWindow()
44 {
45 }
46
47 /*!
48   Performs action
49   \param theAction - type of action
50 */
51 bool 
52 SOCC_ViewWindow
53 ::action( const int theAction  )
54 {
55   const int inc = 10;
56   int cx = 0, cy = 0;
57   if ( theAction == SUIT_Accel::ZoomIn || theAction == SUIT_Accel::ZoomOut ||
58        theAction == SUIT_Accel::RotateLeft || theAction == SUIT_Accel::RotateRight ||
59        theAction == SUIT_Accel::RotateUp || theAction == SUIT_Accel::RotateDown ) {
60     cx = myViewPort->width() / 2;
61     cy = myViewPort->height() / 2;
62   }
63   switch ( theAction ) {
64   case SUIT_Accel::PanLeft     : 
65     myViewPort->pan( -inc, 0 );   
66     break;
67   case SUIT_Accel::PanRight    : 
68     myViewPort->pan(  inc, 0 );   
69     break;
70   case SUIT_Accel::PanUp       : 
71     myViewPort->pan( 0, inc );   
72     break;
73   case SUIT_Accel::PanDown     : 
74     myViewPort->pan( 0, -inc );   
75     break;
76   case SUIT_Accel::ZoomIn      : 
77     myViewPort->zoom( cx, cy, cx + inc, cy + inc );
78     break;
79   case SUIT_Accel::ZoomOut     : 
80     myViewPort->zoom( cx, cy, cx - inc, cy - inc );
81     break;
82   case SUIT_Accel::ZoomFit     :
83     myViewPort->fitAll();
84     break;
85   case SUIT_Accel::RotateLeft  : 
86     myViewPort->startRotation( cx, cy, myCurrPointType, mySelectedPoint );
87     myViewPort->rotate( cx - inc, cy, myCurrPointType, mySelectedPoint );
88     myViewPort->endRotation();
89     break;
90   case SUIT_Accel::RotateRight :  
91     myViewPort->startRotation( cx, cy, myCurrPointType, mySelectedPoint );
92     myViewPort->rotate( cx + inc, cy, myCurrPointType, mySelectedPoint );
93     myViewPort->endRotation();
94     break;
95   case SUIT_Accel::RotateUp    :  
96     myViewPort->startRotation( cx, cy, myCurrPointType, mySelectedPoint );
97     myViewPort->rotate( cx, cy - inc, myCurrPointType, mySelectedPoint );
98     myViewPort->endRotation();
99     break;
100   case SUIT_Accel::RotateDown  :  
101     myViewPort->startRotation( cx, cy, myCurrPointType, mySelectedPoint );
102     myViewPort->rotate( cx, cy + inc, myCurrPointType, mySelectedPoint );
103     myViewPort->endRotation();
104     break;
105   }
106   return true;
107 }