1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SUIT_AutoRotate.h"
24 #include "SUIT_ViewWindow.h"
28 #include <QMouseEvent>
33 SUIT_AutoRotate::SUIT_AutoRotate(SUIT_ViewWindow* theWindow)
40 // Let's intercept all view rotation relevant signals inside this class
41 connect( myWindow, SIGNAL( vpStartRotate(int, int, qint64) ), this, SLOT( onStartRotate(int, int, qint64) ) );
42 connect( myWindow, SIGNAL( vpRotate(int, int, qint64) ), this, SLOT( onRotate(int, int, qint64) ) );
43 connect( myWindow, SIGNAL( vpEndRotate(int, int, qint64) ), this, SLOT( onEndRotate(int, int, qint64) ) );
44 connect( myWindow, SIGNAL( mousePressed(SUIT_ViewWindow*, QMouseEvent*) ), this, SLOT( onStopRotate() ) );
49 SUIT_AutoRotate::~SUIT_AutoRotate()
51 delete [] myLog.myPosition;
52 delete [] myLog.myTime;
56 void SUIT_AutoRotate::initialize()
59 myLog.myPosition = new QPoint [16];
60 myLog.myTime = new qint64 [16];
61 myLog.myHistorySize = 0;
65 void SUIT_AutoRotate::onStartRotate(int theMouseX, int theMouseY, qint64 theTime)
67 myLog.myHistorySize = 0;
68 addToLog(QPoint(theMouseX, theMouseY), theTime);
72 void SUIT_AutoRotate::onRotate(int theMouseX, int theMouseY, qint64 theTime)
74 addToLog(QPoint(theMouseX, theMouseY), theTime);
78 void SUIT_AutoRotate::onEndRotate(int theMouseX, int theMouseY, qint64 theTime)
84 void SUIT_AutoRotate::onStopRotate()
90 void SUIT_AutoRotate::addToLog(const QPoint& thePos, qint64 theTime)
92 if (myLog.myHistorySize > 0 && thePos == myLog.myPosition[0]) {
96 int aLastIdx = myLog.myHistorySize;
97 // If we have filled up the log, throw away the last item
98 if (aLastIdx == myLog.mySize) { aLastIdx--; }
100 for (int i = aLastIdx; i > 0; i--) {
101 myLog.myPosition[i] = myLog.myPosition[i-1];
102 myLog.myTime[i] = myLog.myTime[i-1];
105 myLog.myPosition[0] = thePos;
106 myLog.myTime[0] = theTime;
107 if (myLog.myHistorySize < myLog.mySize)
108 myLog.myHistorySize++;