StelObjectMgr.cpp   StelObjectMgr.cpp 
skipping to change at line 33 skipping to change at line 33
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include <QMouseEvent> #include <QMouseEvent>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QStringList> #include <QStringList>
StelObjectMgr::StelObjectMgr() StelObjectMgr::StelObjectMgr() : searchRadiusPixel(30.f), distanceWeight(1. f)
{ {
setObjectName("StelObjectMgr"); setObjectName("StelObjectMgr");
objectPointerVisibility = true; objectPointerVisibility = true;
} }
StelObjectMgr::~StelObjectMgr() StelObjectMgr::~StelObjectMgr()
{ {
} }
/************************************************************************* /*************************************************************************
Handle mouse click events.
*************************************************************************/
void StelObjectMgr::handleMouseClicks(QMouseEvent* event)
{
// Deselect the selected object
if (event->button()==Qt::RightButton && event->type()==QEvent::Mouse
ButtonRelease)
{
unSelect();
event->accept();
return;
}
StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementMgr);
if (event->button()==Qt::LeftButton && event->type()==QEvent::MouseB
uttonRelease && !mvmgr->getHasDragged())
{
#ifdef Q_OS_MAC
// CTRL + left clic = right clic for 1 button mouse
if (event->modifiers().testFlag(Qt::ControlModifier))
{
unSelect();
event->accept();
return;
}
// Try to select object at that position
findAndSelect(StelApp::getInstance().getCore(), event->x(),
event->y(),
event->modifiers().testFlag(Qt::MetaModifier) ? Stel
Module::AddToSelection : StelModule::ReplaceSelection);
#else
findAndSelect(StelApp::getInstance().getCore(), event->x(),
event->y(),
event->modifiers().testFlag(Qt::ControlModifier) ? S
telModule::AddToSelection : StelModule::ReplaceSelection);
#endif
// If an object was selected update informations
if (getWasSelected())
{
mvmgr->setFlagTracking(false);
}
}
return;
}
/*************************************************************************
Add a new StelObject manager into the list of supported modules. Add a new StelObject manager into the list of supported modules.
*************************************************************************/ *************************************************************************/
void StelObjectMgr::registerStelObjectMgr(StelObjectModule* mgr) void StelObjectMgr::registerStelObjectMgr(StelObjectModule* mgr)
{ {
objectsModule.push_back(mgr); objectsModule.push_back(mgr);
} }
StelObjectP StelObjectMgr::searchByNameI18n(const QString &name) const StelObjectP StelObjectMgr::searchByNameI18n(const QString &name) const
{ {
StelObjectP rval; StelObjectP rval;
QList<StelObjectModule*>::const_iterator iter; foreach (const StelObjectModule* m, objectsModule)
for (iter=objectsModule.begin();iter!=objectsModule.end();++iter)
{ {
rval = (*iter)->searchByNameI18n(name); rval = m->searchByNameI18n(name);
if (rval) if (rval)
return rval; return rval;
} }
return rval; return rval;
} }
//! Find any kind of object by its standard program name //! Find any kind of object by its standard program name
StelObjectP StelObjectMgr::searchByName(const QString &name) const StelObjectP StelObjectMgr::searchByName(const QString &name) const
{ {
StelObjectP rval; StelObjectP rval;
QList<StelObjectModule*>::const_iterator iter; foreach (const StelObjectModule* m, objectsModule)
for (iter=objectsModule.begin();iter!=objectsModule.end();++iter)
{ {
rval = (*iter)->searchByName(name); rval = m->searchByName(name);
if (rval) if (rval)
return rval; return rval;
} }
return rval; return rval;
} }
//! Find and select an object from its translated name //! Find and select an object from its translated name
//! @param nameI18n the case sensitive object translated name //! @param nameI18n the case sensitive object translated name
//! @return true if an object was found with the passed name //! @return true if an object was found with the passed name
bool StelObjectMgr::findAndSelectI18n(const QString &nameI18n, StelModule:: StelModuleSelectAction action) bool StelObjectMgr::findAndSelectI18n(const QString &nameI18n, StelModule:: StelModuleSelectAction action)
skipping to change at line 164 skipping to change at line 122
} }
// Find an object in a "clever" way, v in J2000 frame // Find an object in a "clever" way, v in J2000 frame
StelObjectP StelObjectMgr::cleverFind(const StelCore* core, const Vec3d& v) const StelObjectP StelObjectMgr::cleverFind(const StelCore* core, const Vec3d& v) const
{ {
StelObjectP sobj; StelObjectP sobj;
QList<StelObjectP> candidates; QList<StelObjectP> candidates;
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
// Field of view for a 30 pixel diameter circle on screen // Field of view for a searchRadiusPixel pixel diameter circle on sc
float fov_around = core->getMovementMgr()->getCurrentFov()/qMin(prj- reen
>getViewportWidth(), prj->getViewportHeight()) * 30.f; float fov_around = core->getMovementMgr()->getCurrentFov()/qMin(prj-
>getViewportWidth(), prj->getViewportHeight()) * searchRadiusPixel;
// Collect the objects inside the range // Collect the objects inside the range
for (QList<StelObjectModule*>::const_iterator iteromgr=objectsModule foreach (const StelObjectModule* m, objectsModule)
.begin();iteromgr!=objectsModule.end();++iteromgr) candidates += m->searchAround(v, fov_around, core);
{
candidates += (*iteromgr)->searchAround(v, fov_around, core)
;
}
// Now select the object minimizing the function y = distance(in pix el) + magnitude // Now select the object minimizing the function y = distance(in pix el) + magnitude
Vec3d winpos; Vec3d winpos;
prj->project(v, winpos); prj->project(v, winpos);
float xpos = winpos[0]; float xpos = winpos[0];
float ypos = winpos[1]; float ypos = winpos[1];
float best_object_value; float best_object_value;
best_object_value = 100000.f; best_object_value = 100000.f;
QList<StelObjectP>::iterator iter = candidates.begin(); foreach (const StelObjectP& obj, candidates)
while (iter != candidates.end())
{ {
prj->project((*iter)->getJ2000EquatorialPos(core->getNavigat prj->project(obj->getJ2000EquatorialPos(core->getNavigator()
or()), winpos); ), winpos);
float distance = sqrt((xpos-winpos[0])*(xpos-winpos[0]) + (y float distance = sqrt((xpos-winpos[0])*(xpos-winpos[0]) + (y
pos-winpos[1])*(ypos-winpos[1])); pos-winpos[1])*(ypos-winpos[1]))*distanceWeight;
float priority = (*iter)->getSelectPriority(core->getNaviga float priority = obj->getSelectPriority(core->getNavigator(
tor()); ));
// qDebug() << (*iter).getShortInfoString(core->getNavigator ()) << ": " << priority << " " << distance; // qDebug() << (*iter).getShortInfoString(core->getNavigator ()) << ": " << priority << " " << distance;
if (distance + priority < best_object_value) if (distance + priority < best_object_value)
{ {
best_object_value = distance + priority; best_object_value = distance + priority;
sobj = *iter; sobj = obj;
} }
++iter;
} }
return sobj; return sobj;
} }
/************************************************************************* /*************************************************************************
Find in a "clever" way an object from its equatorial position Find in a "clever" way an object from its equatorial position
*************************************************************************/ *************************************************************************/
StelObjectP StelObjectMgr::cleverFind(const StelCore* core, int x, int y) c onst StelObjectP StelObjectMgr::cleverFind(const StelCore* core, int x, int y) c onst
{ {
skipping to change at line 279 skipping to change at line 233
/************************************************************************* /*************************************************************************
Find and return the list of at most maxNbItem objects auto-completing Find and return the list of at most maxNbItem objects auto-completing
passed object I18 name passed object I18 name
*************************************************************************/ *************************************************************************/
QStringList StelObjectMgr::listMatchingObjectsI18n(const QString& objPrefix , unsigned int maxNbItem) const QStringList StelObjectMgr::listMatchingObjectsI18n(const QString& objPrefix , unsigned int maxNbItem) const
{ {
QStringList result; QStringList result;
// For all StelObjectmodules.. // For all StelObjectmodules..
QList<StelObjectModule*>::const_iterator iteromgr; foreach (const StelObjectModule* m, objectsModule)
for (iteromgr=objectsModule.begin();iteromgr!=objectsModule.end();++
iteromgr)
{ {
// Get matching object for this module // Get matching object for this module
QStringList matchingObj = (*iteromgr)->listMatchingObjectsI1 8n(objPrefix, maxNbItem); QStringList matchingObj = m->listMatchingObjectsI18n(objPref ix, maxNbItem);
result += matchingObj; result += matchingObj;
maxNbItem-=matchingObj.size(); maxNbItem-=matchingObj.size();
} }
result.sort(); result.sort();
return result; return result;
} }
 End of changes. 14 change blocks. 
76 lines changed or deleted 21 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/