Salome HOME
Copyright update 2020
[modules/gui.git] / src / SUIT / SUIT_ViewModel.cxx
1 // Copyright (C) 2007-2020  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 // SUIT_ViewModel.cxx: implementation of the SUIT_ViewModel class.
24 //
25 #include "SUIT_ViewModel.h"
26 #include "SUIT_ViewWindow.h"
27
28 SUIT_ViewModel::InteractionStyle2StatesMap SUIT_ViewModel::myStateMap;
29 SUIT_ViewModel::InteractionStyle2ButtonsMap SUIT_ViewModel::myButtonMap;
30
31 static bool isInitialized = false;
32
33 /*!Constructor.*/
34 SUIT_ViewModel::SUIT_ViewModel()
35 {
36   if ( !isInitialized )
37   {
38     isInitialized = true;
39
40     // standard interaction style
41     SUIT_ViewModel::myStateMap[STANDARD][ZOOM]  = Qt::ControlModifier;
42     SUIT_ViewModel::myButtonMap[STANDARD][ZOOM] = Qt::LeftButton;
43
44     SUIT_ViewModel::myStateMap[STANDARD][PAN]   = Qt::ControlModifier;
45     SUIT_ViewModel::myButtonMap[STANDARD][PAN]  = Qt::MidButton;
46
47     SUIT_ViewModel::myStateMap[STANDARD][ROTATE]  = Qt::ControlModifier;
48     SUIT_ViewModel::myButtonMap[STANDARD][ROTATE] = Qt::RightButton;
49
50     SUIT_ViewModel::myStateMap[STANDARD][FIT_AREA]  = Qt::ControlModifier;
51     SUIT_ViewModel::myButtonMap[STANDARD][FIT_AREA] = Qt::RightButton;
52
53     // "key free" interaction style
54     SUIT_ViewModel::myStateMap[KEY_FREE][ZOOM]  = Qt::NoModifier;
55     SUIT_ViewModel::myButtonMap[KEY_FREE][ZOOM] = Qt::RightButton;
56
57     SUIT_ViewModel::myStateMap[KEY_FREE][PAN]   = Qt::NoModifier;
58     SUIT_ViewModel::myButtonMap[KEY_FREE][PAN]  = Qt::MidButton;
59
60     SUIT_ViewModel::myStateMap[KEY_FREE][ROTATE]  = Qt::NoModifier;
61     SUIT_ViewModel::myButtonMap[KEY_FREE][ROTATE] = Qt::LeftButton;
62
63     SUIT_ViewModel::myStateMap[KEY_FREE][FIT_AREA]  = Qt::NoModifier; // unused
64     SUIT_ViewModel::myButtonMap[KEY_FREE][FIT_AREA] = Qt::NoButton;   // unused
65   }
66   myViewManager = 0;
67 }
68
69 /*!Destructor..*/
70 SUIT_ViewModel::~SUIT_ViewModel()
71 {
72 }
73
74 /*!Create new instance of view window on desktop \a theDesktop.
75  *\retval SUIT_ViewWindow* - created view window pointer.
76  */
77 SUIT_ViewWindow* SUIT_ViewModel::createView(SUIT_Desktop* theDesktop)
78 {
79   return new SUIT_ViewWindow(theDesktop);
80 }
81
82 /*!Set view manager.
83   \param theViewManager view manager
84  */
85 void SUIT_ViewModel::setViewManager(SUIT_ViewManager* theViewManager)
86 {
87   myViewManager = theViewManager;
88 }
89
90 /*!Get view manager.
91   \return view manager
92  */
93 SUIT_ViewManager* SUIT_ViewModel::getViewManager() const
94 {
95   return myViewManager;
96 }
97
98 /*! Sets hot button
99  *\param theOper - hot operation
100  *\param theState - adding state to state map operations.
101  *\param theButton - adding state to button map operations.
102  */
103 void SUIT_ViewModel::setHotButton( InteractionStyle theInteractionStyle, HotOperation theOper,
104                                    Qt::KeyboardModifiers theState, Qt::MouseButtons theButton )
105 {
106   myStateMap[theInteractionStyle][theOper]  = theState;
107   myButtonMap[theInteractionStyle][theOper] = theButton;
108 }
109
110 /*! Gets hot button for operation \a theOper.
111  *\param theOper - input hot operation
112  *\param theState - output state from state map operations.
113  *\param theButton - output state from button map operations.
114 */
115 void SUIT_ViewModel::getHotButton( InteractionStyle theInteractionStyle, HotOperation theOper,
116                                    Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton )
117 {
118   theState  = myStateMap[theInteractionStyle][theOper];
119   theButton = myButtonMap[theInteractionStyle][theOper];
120 }