StelMovementMgr.cpp   StelMovementMgr.cpp 
skipping to change at line 26 skipping to change at line 26
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelScriptMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include <QString> #include <QString>
#include <QTextStream> #include <QTextStream>
#include <QSettings> #include <QSettings>
#include <QKeyEvent> #include <QKeyEvent>
#include <QDebug> #include <QDebug>
StelMovementMgr::StelMovementMgr(StelCore* acore) : core(acore), StelMovementMgr::StelMovementMgr(StelCore* acore) : core(acore),
flagLockEquPos(false), flagLockEquPos(false),
flagTracking(false), flagTracking(false),
isMouseMovingHoriz(false), isMouseMovingHoriz(false),
isMouseMovingVert(false), isMouseMovingVert(false),
flagEnableMouseNavigation(true), flagEnableMouseNavigation(true),
keyMoveSpeed(0.00025), keyMoveSpeed(0.00025),
flagMoveSlow(false), flagMoveSlow(false),
flagAutoMove(false), flagAutoMove(false),
deltaFov(0.), deltaFov(0.),
deltaAlt(0.), deltaAlt(0.),
deltaAz(0.), deltaAz(0.),
dragTimeMode(false),
flagAutoZoom(0), flagAutoZoom(0),
flagAutoZoomOutResetsDirection(0) flagAutoZoomOutResetsDirection(0),
dragTriggerDistance(4.f)
{ {
setObjectName("StelMovementMgr"); setObjectName("StelMovementMgr");
isDragging = false; isDragging = false;
mountMode = MountAltAzimuthal; // default mountMode = MountAltAzimuthal; // default
upVectorMountFrame.set(0,0,1);
} }
StelMovementMgr::~StelMovementMgr() StelMovementMgr::~StelMovementMgr()
{ {
} }
void StelMovementMgr::init() void StelMovementMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
objectMgr = GETSTELMODULE(StelObjectMgr); objectMgr = GETSTELMODULE(StelObjectMgr);
Q_ASSERT(conf); Q_ASSERT(conf);
Q_ASSERT(objectMgr); Q_ASSERT(objectMgr);
movementsSpeedFactor=1.; movementsSpeedFactor=1.;
flagEnableMoveAtScreenEdge = conf->value("navigation/flag_enable_mov e_at_screen_edge",false).toBool(); flagEnableMoveAtScreenEdge = conf->value("navigation/flag_enable_mov e_at_screen_edge",false).toBool();
mouseZoomSpeed = conf->value("navigation/mouse_zoom",30).toInt(); mouseZoomSpeed = conf->value("navigation/mouse_zoom",30).toInt();
flagEnableZoomKeys = conf->value("navigation/flag_enable_zoom_keys") .toBool(); flagEnableZoomKeys = conf->value("navigation/flag_enable_zoom_keys") .toBool();
flagEnableMoveKeys = conf->value("navigation/flag_enable_move_keys") .toBool(); flagEnableMoveKeys = conf->value("navigation/flag_enable_move_keys") .toBool();
keyMoveSpeed = conf->value("navigation/move_speed",0.0004).toDouble( keyMoveSpeed = conf->value("navigation/move_speed",0.0004f).toFloat(
); );
keyZoomSpeed = conf->value("navigation/zoom_speed", 0.0004).toDouble keyZoomSpeed = conf->value("navigation/zoom_speed", 0.0004f).toFloat
(); ();
autoMoveDuration = conf->value ("navigation/auto_move_duration",1.5) autoMoveDuration = conf->value ("navigation/auto_move_duration",1.5f
.toDouble(); ).toFloat();
flagManualZoom = conf->value("navigation/flag_manual_zoom").toBool() ; flagManualZoom = conf->value("navigation/flag_manual_zoom").toBool() ;
flagAutoZoomOutResetsDirection = conf->value("navigation/auto_zoom_o ut_resets_direction", true).toBool(); flagAutoZoomOutResetsDirection = conf->value("navigation/auto_zoom_o ut_resets_direction", true).toBool();
flagEnableMouseNavigation = conf->value("navigation/flag_enable_mous e_navigation",true).toBool(); flagEnableMouseNavigation = conf->value("navigation/flag_enable_mous e_navigation",true).toBool();
minFov = 0.0001; minFov = 0.0001;
maxFov = 100.; maxFov = 100.;
initFov = conf->value("navigation/init_fov",60.).toDouble(); initFov = conf->value("navigation/init_fov",60.f).toFloat();
currentFov = initFov; currentFov = initFov;
initViewPos = StelUtils::strToVec3f(conf->value("navigation/init_vie Vec3f tmp = StelUtils::strToVec3f(conf->value("navigation/init_view_
w_pos").toString()); pos").toString());
initViewPos.set(tmp[0], tmp[1], tmp[2]);
viewDirectionJ2000 = core->getNavigator()->altAzToJ2000(initViewPos) ; viewDirectionJ2000 = core->getNavigator()->altAzToJ2000(initViewPos) ;
QString tmpstr = conf->value("navigation/viewing_mode", "horizon").t oString(); QString tmpstr = conf->value("navigation/viewing_mode", "horizon").t oString();
if (tmpstr=="equator") if (tmpstr=="equator")
setMountMode(StelMovementMgr::MountEquinoxEquatorial); setMountMode(StelMovementMgr::MountEquinoxEquatorial);
else else
{ {
if (tmpstr=="horizon") if (tmpstr=="horizon")
setMountMode(StelMovementMgr::MountAltAzimuthal); setMountMode(StelMovementMgr::MountAltAzimuthal);
else else
skipping to change at line 112 skipping to change at line 115
{ {
mountMode = m; mountMode = m;
setViewDirectionJ2000(viewDirectionJ2000); setViewDirectionJ2000(viewDirectionJ2000);
} }
void StelMovementMgr::setFlagLockEquPos(bool b) void StelMovementMgr::setFlagLockEquPos(bool b)
{ {
flagLockEquPos=b; flagLockEquPos=b;
} }
void StelMovementMgr::setViewUpVectorJ2000(const Vec3d& up)
{
upVectorMountFrame = j2000ToMountFrame(up);
}
Vec3d StelMovementMgr::getViewUpVectorJ2000() const Vec3d StelMovementMgr::getViewUpVectorJ2000() const
{ {
return mountFrameToJ2000(Vec3d(0,0,1)); return mountFrameToJ2000(upVectorMountFrame);
} }
bool StelMovementMgr::handleMouseMoves(int x, int y, Qt::MouseButtons b) bool StelMovementMgr::handleMouseMoves(int x, int y, Qt::MouseButtons)
{ {
// Turn if the mouse is at the edge of the screen unless config asks otherwise // Turn if the mouse is at the edge of the screen unless config asks otherwise
if (flagEnableMoveAtScreenEdge) if (flagEnableMoveAtScreenEdge)
{ {
if (x <= 1) if (x <= 1)
{ {
turnLeft(1); turnLeft(1);
isMouseMovingHoriz = true; isMouseMovingHoriz = true;
} }
else if (x >= core->getProjection2d()->getViewportWidth() - 2) else if (x >= core->getProjection2d()->getViewportWidth() - 2)
skipping to change at line 157 skipping to change at line 165
} }
else if (isMouseMovingVert) else if (isMouseMovingVert)
{ {
turnUp(0); turnUp(0);
isMouseMovingVert = false; isMouseMovingVert = false;
} }
} }
if (isDragging && flagEnableMouseNavigation) if (isDragging && flagEnableMouseNavigation)
{ {
if (hasDragged || (std::sqrt((double)((x-previousX)*(x-previ ousX) +(y-previousY)*(y-previousY)))>4.)) if (hasDragged || (std::sqrt((float)((x-previousX)*(x-previo usX) +(y-previousY)*(y-previousY)))>dragTriggerDistance))
{ {
hasDragged = true; hasDragged = true;
setFlagTracking(false); setFlagTracking(false);
dragView(previousX, previousY, x, y); dragView(previousX, previousY, x, y);
previousX = x; previousX = x;
previousY = y; previousY = y;
return true; return true;
} }
} }
return false; return false;
skipping to change at line 195 skipping to change at line 203
case Qt::Key_Down: case Qt::Key_Down:
if (event->modifiers().testFlag(Qt::ControlM odifier)) zoomOut(true); if (event->modifiers().testFlag(Qt::ControlM odifier)) zoomOut(true);
else turnDown(true); else turnDown(true);
break; break;
case Qt::Key_PageUp: case Qt::Key_PageUp:
zoomIn(true); break; zoomIn(true); break;
case Qt::Key_PageDown: case Qt::Key_PageDown:
zoomOut(true); break; zoomOut(true); break;
case Qt::Key_Shift: case Qt::Key_Shift:
moveSlow(true); break; moveSlow(true); break;
case Qt::Key_Space:
if (event->modifiers().testFlag(Qt::ControlM
odifier))
setDragTimeMode(true);
break;
default: default:
return; return;
} }
} }
else else
{ {
// When a deplacement key is released stop mooving // When a deplacement key is released stop mooving
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Left: case Qt::Key_Left:
skipping to change at line 222 skipping to change at line 234
case Qt::Key_Down: case Qt::Key_Down:
zoomOut(false); zoomOut(false);
turnDown(false); turnDown(false);
break; break;
case Qt::Key_PageUp: case Qt::Key_PageUp:
zoomIn(false); break; zoomIn(false); break;
case Qt::Key_PageDown: case Qt::Key_PageDown:
zoomOut(false); break; zoomOut(false); break;
case Qt::Key_Shift: case Qt::Key_Shift:
moveSlow(false); break; moveSlow(false); break;
case Qt::Key_Control:
setDragTimeMode(false);
break;
default: default:
return; return;
} }
} }
event->accept(); event->accept();
} }
//! Handle mouse wheel events. //! Handle mouse wheel events.
void StelMovementMgr::handleMouseWheel(QWheelEvent* event) void StelMovementMgr::handleMouseWheel(QWheelEvent* event)
{ {
if (flagEnableMouseNavigation==false) if (flagEnableMouseNavigation==false)
return; return;
int numDegrees = event->delta() / 8; int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15; int numSteps = numDegrees / 15;
zoomTo(getAimFov()-mouseZoomSpeed*numSteps*getAimFov()/60., 0.2); zoomTo(getAimFov()-mouseZoomSpeed*numSteps*getAimFov()/60., 0.2);
event->accept(); event->accept();
} }
void StelMovementMgr::addTimeDragPoint()
{
timeDragHistory.append(QPair<double, double>(StelApp::getInstance().
getTotalRunTime(), core->getNavigator()->getJDay()));
if (timeDragHistory.size()>3)
timeDragHistory.removeFirst();
}
void StelMovementMgr::handleMouseClicks(QMouseEvent* event) void StelMovementMgr::handleMouseClicks(QMouseEvent* event)
{ {
switch (event->button()) switch (event->button())
{ {
case Qt::RightButton : break; case Qt::RightButton:
{
if (event->type()==QEvent::MouseButtonRelease)
{
// Deselect the selected object
StelApp::getInstance().getStelObjectMgr().un
Select();
event->accept();
return;
}
break;
}
case Qt::LeftButton : case Qt::LeftButton :
if (event->type()==QEvent::MouseButtonPress) if (event->type()==QEvent::MouseButtonPress)
{ {
isDragging = true; isDragging = true;
hasDragged = false; hasDragged = false;
previousX = event->x(); previousX = event->x();
previousY = event->y(); previousY = event->y();
beforeTimeDragTimeRate=core->getNavigator()-
>getTimeRate();
if (dragTimeMode)
{
timeDragHistory.clear();
addTimeDragPoint();
}
event->accept(); event->accept();
return; return;
} }
else else
{ {
if (isDragging) isDragging = false;
if (hasDragged)
{
event->accept();
if (dragTimeMode)
{
addTimeDragPoint();
if (timeDragHistory.size()>=
3)
{
const double deltaT
= timeDragHistory.last().first-timeDragHistory.first().first;
const double deltaJd
= timeDragHistory.last().second-timeDragHistory.first().second;
const double newTime
Rate = deltaJd/deltaT;
if (deltaT>0.0000000
1)
{
if (newTimeR
ate>=0)
core
->getNavigator()->setTimeRate(qMax(newTimeRate, JD_SECOND));
else
core
->getNavigator()->setTimeRate(qMin(newTimeRate, -JD_SECOND));
}
else
core->getNav
igator()->setTimeRate(beforeTimeDragTimeRate);
}
else
core->getNavigator()
->setTimeRate(beforeTimeDragTimeRate);
}
return;
}
else
{ {
isDragging = false; // It's a normal click release
if (hasDragged) #ifdef Q_OS_MAC
// CTRL + left clic = right clic for
1 button mouse
if (event->modifiers().testFlag(Qt::
ControlModifier))
{ {
StelApp::getInstance().getSt elObjectMgr().unSelect();
event->accept(); event->accept();
return; return;
} }
else
return; // Try to select object at that posi
tion
StelApp::getInstance().getStelObject
Mgr().findAndSelect(StelApp::getInstance().getCore(), event->x(), event->y(
),
event->modifiers().testFlag(
Qt::MetaModifier) ? StelModule::AddToSelection : StelModule::ReplaceSelecti
on);
#else
StelApp::getInstance().getStelObject
Mgr().findAndSelect(StelApp::getInstance().getCore(), event->x(), event->y(
),
event->modifiers().testFlag(
Qt::ControlModifier) ? StelModule::AddToSelection : StelModule::ReplaceSele
ction);
#endif
if (StelApp::getInstance().getStelOb
jectMgr().getWasSelected())
{
setFlagTracking(false);
}
event->accept();
return;
} }
} }
break; break;
case Qt::MidButton : case Qt::MidButton :
if (event->type()==QEvent::MouseButtonRelease) if (event->type()==QEvent::MouseButtonRelease)
{ {
if (objectMgr->getWasSelected()) if (objectMgr->getWasSelected())
{ {
moveToObject(objectMgr->getSelectedO bject()[0],autoMoveDuration); moveToObject(objectMgr->getSelectedO bject()[0],autoMoveDuration);
setFlagTracking(true); setFlagTracking(true);
skipping to change at line 295 skipping to change at line 375
void StelMovementMgr::setInitViewDirectionToCurrent() void StelMovementMgr::setInitViewDirectionToCurrent()
{ {
initViewPos = core->getNavigator()->j2000ToAltAz(viewDirectionJ2000) ; initViewPos = core->getNavigator()->j2000ToAltAz(viewDirectionJ2000) ;
QString dirStr = QString("%1,%2,%3").arg(initViewPos[0]).arg(initVie wPos[1]).arg(initViewPos[2]); QString dirStr = QString("%1,%2,%3").arg(initViewPos[0]).arg(initVie wPos[1]).arg(initViewPos[2]);
StelApp::getInstance().getSettings()->setValue("navigation/init_view _pos", dirStr); StelApp::getInstance().getSettings()->setValue("navigation/init_view _pos", dirStr);
} }
/************************************************************************* /*************************************************************************
The selected objects changed, follow it it we were already following anoth er one The selected objects changed, follow it it we were already following anoth er one
*************************************************************************/ *************************************************************************/
void StelMovementMgr::selectedObjectChangeCallBack(StelModuleSelectAction a ction) void StelMovementMgr::selectedObjectChangeCallBack(StelModuleSelectAction)
{ {
// If an object was selected keep the earth following // If an object was selected keep the earth following
if (objectMgr->getWasSelected()) if (objectMgr->getWasSelected())
{ {
if (getFlagTracking()) if (getFlagTracking())
setFlagLockEquPos(true); setFlagLockEquPos(true);
setFlagTracking(false); setFlagTracking(false);
} }
} }
skipping to change at line 714 skipping to change at line 794
setFlagTracking(false); setFlagTracking(false);
Vec3d tmp; Vec3d tmp;
StelUtils::spheToRect(azVision, altVision, tmp); StelUtils::spheToRect(azVision, altVision, tmp);
setViewDirectionJ2000(mountFrameToJ2000(tmp)); setViewDirectionJ2000(mountFrameToJ2000(tmp));
} }
} }
//! Make the first screen position correspond to the second (useful for mou se dragging) //! Make the first screen position correspond to the second (useful for mou se dragging)
void StelMovementMgr::dragView(int x1, int y1, int x2, int y2) void StelMovementMgr::dragView(int x1, int y1, int x2, int y2)
{ {
Vec3d tempvec1, tempvec2; if (dragTimeMode)
double az1, alt1, az2, alt2; {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) core->getNavigator()->setTimeRate(0);
; Vec3d v1, v2;
prj->unProject(x2,y2, tempvec2); const StelProjectorP prj = core->getProjection(StelCore::Fra
prj->unProject(x1,y1, tempvec1); meEquinoxEqu);
StelUtils::rectToSphe(&az1, &alt1, j2000ToMountFrame(tempvec1)); prj->unProject(x2,y2, v2);
StelUtils::rectToSphe(&az2, &alt2, j2000ToMountFrame(tempvec2)); prj->unProject(x1,y1, v1);
panView(az2-az1, alt1-alt2); v1[2]=0; v1.normalize();
v2[2]=0; v2.normalize();
double angle = (v2^v1)[2];
double deltaDay = angle/(2.*M_PI)*core->getNavigator()->getL
ocalSideralDayLength();
core->getNavigator()->setJDay(core->getNavigator()->getJDay(
)+deltaDay);
addTimeDragPoint();
}
else
{
Vec3d tempvec1, tempvec2;
const StelProjectorP prj = core->getProjection(StelCore::Fra
meJ2000);
prj->unProject(x2,y2, tempvec2);
prj->unProject(x1,y1, tempvec1);
double az1, alt1, az2, alt2;
StelUtils::rectToSphe(&az1, &alt1, j2000ToMountFrame(tempvec
1));
StelUtils::rectToSphe(&az2, &alt2, j2000ToMountFrame(tempvec
2));
panView(az2-az1, alt1-alt2);
}
setFlagTracking(false); setFlagTracking(false);
setFlagLockEquPos(false); setFlagLockEquPos(false);
} }
// Update autoZoom if activated // Update autoZoom if activated
void StelMovementMgr::updateAutoZoom(double deltaTime) void StelMovementMgr::updateAutoZoom(double deltaTime)
{ {
if (flagAutoZoom) if (flagAutoZoom)
{ {
// Use a smooth function // Use a smooth function
 End of changes. 22 change blocks. 
30 lines changed or deleted 158 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/