TelescopeMgr.cpp   TelescopeMgr.cpp 
skipping to change at line 27 skipping to change at line 27
* 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 "StelProjector.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 "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 "StelPainter.hpp"
#include <algorithm>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QDebug>
#ifdef WIN32
#include <winsock2.h> // select
#else
#include <sys/select.h> // select
#include <sys/time.h>
#include <signal.h>
#endif
#ifdef WIN32
bool wsaOk;
#endif
void TelescopeMgr::deleteAllTelescopes() void TelescopeMgr::deleteAllTelescopes()
{ {
foreach (Telescope* t, telescope_map) foreach (Telescope* t, telescope_map)
delete t; delete t;
telescope_map.clear(); telescope_map.clear();
} }
TelescopeMgr::TelescopeMgr() : telescope_font(NULL) TelescopeMgr::TelescopeMgr()
{ {
setObjectName("TelescopeMgr"); setObjectName("TelescopeMgr");
#ifdef WIN32
WSADATA wsaData;
if (WSAStartup(0x202,&wsaData) == 0)
{
wsaOk = true;
}
else
{
qWarning() << "WARNING TelescopeMgr::TelescopeMgr: WSAStartu
p failed, " << "you will not be able to control telescopes";
wsaOk = false;
}
#else
// SIGPIPE is normal operation when we send while the other side
// has already closed the socket. We must ignore it:
signal(SIGPIPE,SIG_IGN);
#endif
} }
TelescopeMgr::~TelescopeMgr(void) TelescopeMgr::~TelescopeMgr(void)
{ {
#ifdef WIN32
if (wsaOk)
WSACleanup();
#endif
} }
/************************************************************************* /*************************************************************************
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*************************************************************************/ *************************************************************************/
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)
{ {
StelNavigator* nav = core->getNavigator(); StelNavigator* nav = core->getNavigator();
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
StelPainter sPainter(prj); StelPainter sPainter(prj);
sPainter.setFont(telescope_font);
glEnable(GL_TEXTURE_2D); sPainter.enableTexture2d(true);
glEnable(GL_BLEND); glEnable(GL_BLEND);
telescopeTexture->bind(); telescopeTexture->bind();
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
foreach (Telescope* tel, telescope_map) foreach (Telescope* tel, telescope_map)
{ {
if (tel->isConnected() && tel->hasKnownPosition()) if (tel->isConnected() && tel->hasKnownPosition())
{ {
Vec3d XY; Vec3d XY;
if (prj->projectCheck(tel->getJ2000EquatorialPos(nav ),XY)) if (prj->projectCheck(tel->getJ2000EquatorialPos(nav ),XY))
{ {
if (telescopeFader.getInterstate() >= 0) if (telescopeFader.getInterstate() >= 0)
{ {
glColor4f(circleColor[0],circleColor sPainter.setColor(circleColor[0],cir
[1],circleColor[2], telescopeFader.getInterstate()); cleColor[1],circleColor[2], telescopeFader.getInterstate());
glDisable(GL_TEXTURE_2D); sPainter.enableTexture2d(false);
foreach (double occul, tel->getOcula rs()) foreach (double occul, tel->getOcula rs())
{ {
sPainter.drawCircle(XY[0],XY [1],0.5*prj->getPixelPerRadAtCenter()*(M_PI/180)*(occul)); sPainter.drawCircle(XY[0],XY [1],0.5*prj->getPixelPerRadAtCenter()*(M_PI/180)*(occul));
} }
glEnable(GL_TEXTURE_2D); sPainter.enableTexture2d(true);
double radius = 15; sPainter.drawSprite2dMode(XY[0],XY[1
glBegin(GL_QUADS); ],15.f);
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,1); glVertex2
d(XY[0]+radius,XY[1]+radius); // Top right
glTexCoord2i(0,1); glVertex2
d(XY[0]-radius,XY[1]+radius); // Top left
glEnd();
} }
if (nameFader.getInterstate() >= 0) if (nameFader.getInterstate() >= 0)
{ {
glColor4f(labelColor[0],labelColor[1 sPainter.setColor(labelColor[0],labe
],labelColor[2], nameFader.getInterstate()); lColor[1],labelColor[2], nameFader.getInterstate());
sPainter.drawText(telescope_font, XY sPainter.drawText(XY[0],XY[1],tel->g
[0],XY[1],tel->getNameI18n(), 0, 6, -4, false); etNameI18n(), 0, 6, -4, false);
telescopeTexture->bind(); telescopeTexture->bind();
} }
} }
} }
} }
drawPointer(prj, nav, sPainter); drawPointer(prj, nav, sPainter);
} }
void TelescopeMgr::update(double deltaTime) void TelescopeMgr::update(double deltaTime)
{ {
skipping to change at line 160 skipping to change at line 120
} }
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()));
setCircleColor(StelUtils::strToVec3f(conf->value(section+"/telescope _circleColor", defaultColor).toString())); setCircleColor(StelUtils::strToVec3f(conf->value(section+"/telescope _circle_color", 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.);
skipping to change at line 225 skipping to change at line 185
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.setPixelSize(fontSize);
} }
void TelescopeMgr::moveTelescopeToSelected(void) void TelescopeMgr::moveTelescopeToSelected(void)
{ {
StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr); StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
if (omgr->getSelectedObject().isEmpty()) if (omgr->getSelectedObject().isEmpty())
return; return;
if (sender() == NULL) if (sender() == NULL)
return; return;
skipping to change at line 252 skipping to change at line 212
int telNum = sender()->objectName().right(1).toInt(); int telNum = sender()->objectName().right(1).toInt();
telescopeGoto(telNum, objectPos); telescopeGoto(telNum, objectPos);
} }
void TelescopeMgr::init() void TelescopeMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
setFontSize(12.f); setFontSize(12.f);
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
if (!wsaOk) return;
#endif
deleteAllTelescopes(); 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; //qWarning() << telescope_name;
if (!url.isEmpty()) if (!url.isEmpty())
{ {
qWarning() << url; qWarning() << url;
skipping to change at line 291 skipping to change at line 247
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());
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->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 StelProjectorP& prj, const StelNavigat or * nav, const StelPainter& sPainter) void TelescopeMgr::drawPointer(const StelProjectorP& prj, const StelNavigat or * nav, StelPainter& sPainter)
{ {
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Telescope"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Telescope");
if (!newSelected.empty()) if (!newSelected.empty())
{ {
const StelObjectP obj = newSelected[0]; const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getJ2000EquatorialPos(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()); const Vec3d& c(obj->getInfoColor());
sPainter.setColor(c[0],c[1],c[2]);
texPointer->bind(); texPointer->bind();
glEnable(GL_TEXTURE_2D); sPainter.enableTexture2d(true);
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 telApp::getInstance().getTotalRunTime()*40.); sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 25., S telApp::getInstance().getTotalRunTime()*40.);
} }
} }
void TelescopeMgr::telescopeGoto(int telescope_nr,const Vec3d &j2000Pos) void TelescopeMgr::telescopeGoto(int telescope_nr,const Vec3d &j2000Pos)
{ {
QMap<int, Telescope*>::ConstIterator 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.value()->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())
{ {
fd_set read_fds,write_fds;
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
int fd_max = -1;
// check the file descriptors
foreach (Telescope* tel, telescope_map) foreach (Telescope* tel, telescope_map)
{ {
tel->prepareSelectFds(read_fds,write_fds,fd_max); if(tel->prepareCommunication())
tel->performCommunication();
} }
if (fd_max >= 0)
{
struct timeval tv;
tv.tv_sec = 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);
if (select_rc > 0)
{
// perform the IO for each telescope:
foreach (Telescope* tel, telescope_map)
{
tel->handleSelectFds(read_fds,write_
fds);
}
}
}
// t = GetNow() - t;
// qDebug() << "TelescopeMgr::communicate: " << t;
} }
// t = getNow() - t;
// qDebug() << "TelescopeMgr::communicate: " << t;
} }
 End of changes. 23 change blocks. 
98 lines changed or deleted 25 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/