TelescopeMgr.cpp   TelescopeMgr.cpp 
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* 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, US A. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US A.
*/ */
#include "TelescopeMgr.hpp" #include "TelescopeMgr.hpp"
#include "Telescope.hpp" #include "Telescope.hpp"
#include "StelObject.hpp" #include "StelObject.hpp"
#include "Projector.hpp" #include "StelProjector.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelFontMgr.hpp" #include "StelFontMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelPainter.hpp"
#include <algorithm> #include <algorithm>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QDebug>
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h> // select #include <winsock2.h> // select
#else #else
#include <sys/select.h> // select #include <sys/select.h> // select
#include <sys/time.h> #include <sys/time.h>
#include <signal.h> #include <signal.h>
#endif #endif
#ifdef WIN32 #ifdef WIN32
bool wsaOk; bool wsaOk;
#endif #endif
void TelescopeMgr::TelescopeMap::clear(void) void TelescopeMgr::deleteAllTelescopes()
{ {
for (const_iterator it(begin());it!=end();++it) foreach (Telescope* t, telescope_map)
delete it->second; delete t;
std::map<int,Telescope*>::clear(); telescope_map.clear();
} }
TelescopeMgr::TelescopeMgr(void) : telescope_font(NULL) TelescopeMgr::TelescopeMgr() : telescope_font(NULL)
{ {
setObjectName("TelescopeMgr"); setObjectName("TelescopeMgr");
#ifdef WIN32 #ifdef WIN32
WSADATA wsaData; WSADATA wsaData;
if (WSAStartup(0x202,&wsaData) == 0) if (WSAStartup(0x202,&wsaData) == 0)
{ {
wsaOk = true; wsaOk = true;
} }
else else
{ {
skipping to change at line 99 skipping to change at line 100
*************************************************************************/ *************************************************************************/
double TelescopeMgr::getCallOrder(StelModuleActionName actionName) const double TelescopeMgr::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Mete orMgr")->getCallOrder(actionName)+10; return StelApp::getInstance().getModuleMgr().getModule("Mete orMgr")->getCallOrder(actionName)+10;
return 0; return 0;
} }
void TelescopeMgr::draw(StelCore* core) void TelescopeMgr::draw(StelCore* core)
{ {
Navigator* nav = core->getNavigation(); StelNavigator* nav = core->getNavigator();
Projector* prj = core->getProjection(); const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000)
;
StelPainter sPainter(prj);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND); glEnable(GL_BLEND);
prj->setCurrentFrame(Projector::FrameJ2000);
telescopeTexture->bind(); telescopeTexture->bind();
glBlendFunc(GL_ONE,GL_ONE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa rency mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa rency mode
for (TelescopeMap::const_iterator it(telescope_map.begin()); it!=tel escope_map.end();++it) foreach (Telescope* tel, telescope_map)
{ {
if (it->second->isConnected() && it->second->hasKnownPositio n()) if (tel->isConnected() && tel->hasKnownPosition())
{ {
Vec3d XY; Vec3d XY;
if (prj->projectCheck(it->second->getObsJ2000Pos(0), XY)) if (prj->projectCheck(tel->getJ2000EquatorialPos(0), XY))
{ {
if (telescopeFader.getInterstate() >= 0) if (telescopeFader.getInterstate() >= 0)
{ {
glColor4f(circleColor[0],circleColor [1],circleColor[2], telescopeFader.getInterstate()); glColor4f(circleColor[0],circleColor [1],circleColor[2], telescopeFader.getInterstate());
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
for (std::list<double>::const_iterat or it2(it->second->getOculars().begin()); it2!=it->second->getOculars().end ();++it2) foreach (double occul, tel->getOcula rs())
{ {
prj->drawCircle(XY[0],XY[1], sPainter.drawCircle(XY[0],XY
0.5*prj->getPixelPerRadAtCen [1],0.5*prj->getPixelPerRadAtCenter()*(M_PI/180)*(occul));
ter()*(M_PI/180)*(*it2));
} }
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
double radius = 15; double radius = 15;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2i(0,0); glVertex2 d(XY[0]-radius,XY[1]-radius); // Bottom left glTexCoord2i(0,0); glVertex2 d(XY[0]-radius,XY[1]-radius); // Bottom left
glTexCoord2i(1,0); glVertex2 d(XY[0]+radius,XY[1]-radius); // Bottom right glTexCoord2i(1,0); glVertex2 d(XY[0]+radius,XY[1]-radius); // Bottom right
glTexCoord2i(1,1); glVertex2 d(XY[0]+radius,XY[1]+radius); // Top right glTexCoord2i(1,1); glVertex2 d(XY[0]+radius,XY[1]+radius); // Top right
glTexCoord2i(0,1); glVertex2 d(XY[0]-radius,XY[1]+radius); // Top left glTexCoord2i(0,1); glVertex2 d(XY[0]-radius,XY[1]+radius); // Top left
glEnd(); glEnd();
} }
if (nameFader.getInterstate() >= 0) if (nameFader.getInterstate() >= 0)
{ {
glColor4f(labelColor[0],labelColor[1 ],labelColor[2], nameFader.getInterstate()); glColor4f(labelColor[0],labelColor[1 ],labelColor[2], nameFader.getInterstate());
prj->drawText(telescope_font, XY[0], XY[1],it->second->getNameI18n(), 0, 6, -4, false); sPainter.drawText(telescope_font, XY [0],XY[1],tel->getNameI18n(), 0, 6, -4, false);
telescopeTexture->bind(); telescopeTexture->bind();
} }
} }
} }
} }
drawPointer(prj, nav); drawPointer(prj, nav, sPainter);
} }
void TelescopeMgr::update(double deltaTime) void TelescopeMgr::update(double deltaTime)
{ {
nameFader.update((int)(deltaTime*1000)); nameFader.update((int)(deltaTime*1000));
telescopeFader.update((int)(deltaTime*1000)); telescopeFader.update((int)(deltaTime*1000));
// communicate with the telescopes: // communicate with the telescopes:
communicate(); communicate();
} }
void TelescopeMgr::setStelStyle(const StelStyle& style) void TelescopeMgr::setStelStyle(const StelStyle& style)
{ {
// Load colors from config file // Load colors from config file
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
QString section = style.confSectionName; QString section = style.confSectionName;
QString defaultColor = conf->value(section+"/default_color").toStrin g(); QString defaultColor = conf->value(section+"/default_color").toStrin g();
setLabelColor(StelUtils::strToVec3f(conf->value(section+"/telescope_ label_color", defaultColor).toString())); setLabelColor(StelUtils::strToVec3f(conf->value(section+"/telescope_ label_color", defaultColor).toString()));
set_circleColor(StelUtils::strToVec3f(conf->value(section+"/telescop e_circleColor", defaultColor).toString())); setCircleColor(StelUtils::strToVec3f(conf->value(section+"/telescope _circleColor", defaultColor).toString()));
} }
QList<StelObjectP> TelescopeMgr::searchAround(const Vec3d& vv, double limit Fov, const StelCore* core) const QList<StelObjectP> TelescopeMgr::searchAround(const Vec3d& vv, double limit Fov, const StelCore* core) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
if (!getFlagTelescopes()) if (!getFlagTelescopes())
return result; return result;
Vec3d v(vv); Vec3d v(vv);
v.normalize(); v.normalize();
double cosLimFov = cos(limitFov * M_PI/180.); double cosLimFov = cos(limitFov * M_PI/180.);
for (TelescopeMap::const_iterator it(telescope_map.begin()); it!=tel escope_map.end();++it) foreach (Telescope* tel, telescope_map)
{ {
if (it->second->getObsJ2000Pos(0).dot(v) >= cosLimFov) if (tel->getJ2000EquatorialPos(0).dot(v) >= cosLimFov)
{ {
result.push_back(it->second); result.push_back(tel);
} }
} }
return result; return result;
} }
StelObjectP TelescopeMgr::searchByNameI18n(const QString &nameI18n) const StelObjectP TelescopeMgr::searchByNameI18n(const QString &nameI18n) const
{ {
for (TelescopeMap::const_iterator it(telescope_map.begin()); it!=tel escope_map.end();++it) foreach (Telescope* tel, telescope_map)
{ {
if (it->second->getNameI18n() == nameI18n) if (tel->getNameI18n() == nameI18n)
return it->second; return tel;
} }
return 0; return 0;
} }
StelObjectP TelescopeMgr::searchByName(const QString &name) const StelObjectP TelescopeMgr::searchByName(const QString &name) const
{ {
for (TelescopeMap::const_iterator it(telescope_map.begin()); it!=tel escope_map.end();++it) foreach (Telescope* tel, telescope_map)
{ {
if (it->second->getEnglishName() == name) if (tel->getEnglishName() == name)
return it->second; return tel;
} }
return 0; return 0;
} }
QStringList TelescopeMgr::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const QStringList TelescopeMgr::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0) return result;
QString objw = objPrefix.toUpper(); QString objw = objPrefix.toUpper();
for (TelescopeMap::const_iterator it(telescope_map.begin());it!=tele scope_map.end();++it) foreach (const Telescope* tel, telescope_map)
{ {
QString constw = it->second->getNameI18n().mid(0, objw.size( )).toUpper(); QString constw = tel->getNameI18n().mid(0, objw.size()).toUp per();
if (constw==objw) if (constw==objw)
{ {
result << it->second->getNameI18n(); result << tel->getNameI18n();
} }
} }
result.sort(); result.sort();
if (result.size()>maxNbItem) if (result.size()>maxNbItem)
{ {
result.erase(result.begin()+maxNbItem, result.end()); result.erase(result.begin()+maxNbItem, result.end());
} }
return result; return result;
} }
void TelescopeMgr::setFontSize(float fontSize) void TelescopeMgr::setFontSize(float fontSize)
{ {
telescope_font = &StelApp::getInstance().getFontManager().getStandar dFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize); telescope_font = &StelApp::getInstance().getFontManager().getStandar dFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize);
} }
void TelescopeMgr::moveTelescopeToSelected(void)
{
if (StelApp::getInstance().getStelObjectMgr().getSelectedObject().is
Empty())
return;
if (sender() == NULL)
return;
StelObjectP selectObject = StelApp::getInstance().getStelObjectMgr()
.getSelectedObject().at(0);
if (!selectObject) // should never happen
return;
Vec3d objectPos = selectObject->getJ2000EquatorialPos(StelApp::getIn
stance().getCore()->getNavigator());
int telNum = sender()->objectName().right(1).toInt();
telescopeGoto(telNum, objectPos);
}
void TelescopeMgr::init() void TelescopeMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
assert(conf); Q_ASSERT(conf);
setFontSize(12.f); setFontSize(12.f);
StelApp::getInstance().getTextureManager().setDefaultParams(); StelApp::getInstance().getTextureManager().setDefaultParams();
StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR);
telescopeTexture = StelApp::getInstance().getTextureManager().create Texture("telescope.png"); telescopeTexture = StelApp::getInstance().getTextureManager().create Texture("telescope.png");
#ifdef WIN32 #ifdef WIN32
if (!wsaOk) return; if (!wsaOk) return;
#endif #endif
telescope_map.clear(); deleteAllTelescopes();
for (int i=0;i<9;i++) for (int i=0;i<9;i++)
{ {
char name[2] = {'0'+i,'\0'}; char name[2] = {'0'+i,'\0'};
const QString telescope_name(name); const QString telescope_name(name);
const QString url = conf->value("telescopes/"+telescope_name ,"").toString(); const QString url = conf->value("telescopes/"+telescope_name ,"").toString();
//qWarning() << telescope_name;
if (!url.isEmpty()) if (!url.isEmpty())
{ {
qWarning() << url;
Telescope *t = Telescope::create(url); Telescope *t = Telescope::create(url);
if (t) if (t)
{ {
for (int j=0;j<9;j++) for (int j=0;j<9;j++)
{ {
name[0] = '0'+j; name[0] = '0'+j;
const double fov = conf->value("tele scopes/"+telescope_name+"_ocular_"+name, -1.0).toDouble(); const double fov = conf->value("tele scopes/"+telescope_name+"_ocular_"+name, -1.0).toDouble();
t->addOcular(fov); t->addOcular(fov);
} }
telescope_map[i] = t; telescope_map[i] = t;
skipping to change at line 271 skipping to change at line 290
setFlagTelescopes(conf->value("astro/flag_telescopes",false).toBool( )); setFlagTelescopes(conf->value("astro/flag_telescopes",false).toBool( ));
setFlagTelescopeName(conf->value("astro/flag_telescope_name",false). toBool()); setFlagTelescopeName(conf->value("astro/flag_telescope_name",false). toBool());
StelApp::getInstance().getStelObjectMgr().registerStelObjectMgr(this ); StelApp::getInstance().getStelObjectMgr().registerStelObjectMgr(this );
// Load pointer texture // Load pointer texture
texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur2.png"); texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur2.png");
} }
void TelescopeMgr::drawPointer(const Projector* prj, const Navigator * nav) void TelescopeMgr::drawPointer(const StelProjectorP& prj, const StelNavigat or * nav, const StelPainter& sPainter)
{ {
const QList<StelObjectP> newSelected = StelApp::getInstance().getSte lObjectMgr().getSelectedObject("Telescope"); const QList<StelObjectP> newSelected = StelApp::getInstance().getSte lObjectMgr().getSelectedObject("Telescope");
if (!newSelected.empty()) if (!newSelected.empty())
{ {
const StelObjectP obj = newSelected[0]; const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getObsJ2000Pos(nav); Vec3d pos=obj->getJ2000EquatorialPos(nav);
Vec3d screenpos; Vec3d screenpos;
// Compute 2D pos and return if outside screen // Compute 2D pos and return if outside screen
if (!prj->project(pos, screenpos)) return; if (!prj->project(pos, screenpos)) return;
glColor3fv(obj->getInfoColor()); glColor3fv(obj->getInfoColor());
texPointer->bind(); texPointer->bind();
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 50., S
prj->drawSprite2dMode(screenpos[0], screenpos[1], 50., StelA telApp::getInstance().getTotalRunTime()*40.);
pp::getInstance().getTotalRunTime()*40.);
} }
} }
void TelescopeMgr::telescopeGoto(int telescope_nr,const Vec3d &j2000Pos) void TelescopeMgr::telescopeGoto(int telescope_nr,const Vec3d &j2000Pos)
{ {
TelescopeMap::const_iterator it(telescope_map.find(telescope_nr)); QMap<int, Telescope*>::ConstIterator it(telescope_map.find(telescope _nr));
if (it != telescope_map.end()) if (it != telescope_map.end())
{ {
it->second->telescopeGoto(j2000Pos); it.value()->telescopeGoto(j2000Pos);
} }
} }
void TelescopeMgr::communicate(void) void TelescopeMgr::communicate(void)
{ {
// The actual workhorse that does the TCP/IP communication with th
e
// controlled telescopes:
if (!telescope_map.empty()) if (!telescope_map.empty())
{ {
// long long int t = GetNow();
fd_set read_fds,write_fds; fd_set read_fds,write_fds;
FD_ZERO(&read_fds); FD_ZERO(&read_fds);
FD_ZERO(&write_fds); FD_ZERO(&write_fds);
int fd_max = -1; int fd_max = -1;
for (TelescopeMap::const_iterator it(telescope_map.begin()); // check the file descriptors
it!=telescope_map.end();++it) foreach (Telescope* tel, telescope_map)
{ {
it->second->prepareSelectFds(read_fds,write_fds,fd_m ax); tel->prepareSelectFds(read_fds,write_fds,fd_max);
} }
if (fd_max >= 0) if (fd_max >= 0)
{ {
struct timeval tv; struct timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
// Check that data is ready to be read/write in file descriptors sets
const int select_rc = select(fd_max+1,&read_fds,&wri te_fds,0,&tv); const int select_rc = select(fd_max+1,&read_fds,&wri te_fds,0,&tv);
if (select_rc > 0) if (select_rc > 0)
{ {
for (TelescopeMap::const_iterator it(telesco // perform the IO for each telescope:
pe_map.begin());it!=telescope_map.end();++it) foreach (Telescope* tel, telescope_map)
{ {
it->second->handleSelectFds(read_fds ,write_fds); tel->handleSelectFds(read_fds,write_ fds);
} }
} }
} }
// t = GetNow() - t; // t = GetNow() - t;
// qDebug() << "TelescopeMgr::communicate: " << t; // qDebug() << "TelescopeMgr::communicate: " << t;
} }
} }
 End of changes. 44 change blocks. 
48 lines changed or deleted 73 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/