Asterism.cpp   Asterism.cpp 
skipping to change at line 38 skipping to change at line 38
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "AsterismMgr.hpp" #include "AsterismMgr.hpp"
#include <algorithm> #include <algorithm>
#include <QString> #include <QString>
#include <QTextStream> #include <QTextStream>
#include <QDebug> #include <QDebug>
#include <QFontMetrics> #include <QFontMetrics>
Vec3f Asterism::lineColor = Vec3f(0.4,0.4,0.8); Vec3f Asterism::lineColor = Vec3f(0.4,0.4,0.8);
Vec3f Asterism::rayHelperColor = Vec3f(1.0,1.0,0.0);
Vec3f Asterism::labelColor = Vec3f(0.4,0.4,0.8); Vec3f Asterism::labelColor = Vec3f(0.4,0.4,0.8);
const QString Asterism::ASTERISM_TYPE = QStringLiteral("Asterism"); const QString Asterism::ASTERISM_TYPE = QStringLiteral("Asterism");
Asterism::Asterism() Asterism::Asterism()
: numberOfSegments(0) : numberOfSegments(0)
, typeOfAsterism(1)
, flagAsterism(true)
, asterism(Q_NULLPTR) , asterism(Q_NULLPTR)
{ {
} }
Asterism::~Asterism() Asterism::~Asterism()
{ {
delete[] asterism; delete[] asterism;
asterism = Q_NULLPTR; asterism = Q_NULLPTR;
} }
bool Asterism::read(const QString& record, StarMgr *starMgr) bool Asterism::read(const QString& record, StarMgr *starMgr)
{ {
unsigned int HP;
abbreviation.clear(); abbreviation.clear();
numberOfSegments = 0; numberOfSegments = 0;
typeOfAsterism = 1;
flagAsterism = true;
QString buf(record); QString buf(record);
QTextStream istr(&buf, QIODevice::ReadOnly); QTextStream istr(&buf, QIODevice::ReadOnly);
QString abb; QString abb;
istr >> abb >> numberOfSegments; istr >> abb >> typeOfAsterism >> numberOfSegments;
if (istr.status()!=QTextStream::Ok) if (istr.status()!=QTextStream::Ok)
return false; return false;
// It's better to allow mixed-case abbreviations now that they can b e displayed on screen. We then need toUpper() in comparisons. // It's better to allow mixed-case abbreviations now that they can b e displayed on screen. We then need toUpper() in comparisons.
//abbreviation = abb.toUpper(); //abbreviation = abb.toUpper();
abbreviation=abb; abbreviation=abb;
StelCore *core = StelApp::getInstance().getCore();
asterism = new StelObjectP[numberOfSegments*2]; asterism = new StelObjectP[numberOfSegments*2];
for (unsigned int i=0;i<numberOfSegments*2;++i) for (unsigned int i=0;i<numberOfSegments*2;++i)
{ {
HP = 0; switch (typeOfAsterism)
istr >> HP;
if(HP == 0)
{ {
// TODO: why is this delete commented? case 0: // Ray helpers
// delete[] asterism; case 1: // A big asterism with lines by HIP stars
return false; {
} unsigned int HP = 0;
istr >> HP;
if(HP == 0)
{
// TODO: why is this delete commente
d?
// delete[] asterism;
return false;
}
asterism[i]=starMgr->searchHP(HP);
if (!asterism[i])
{
qWarning() << "Error in Asterism " <
< abbreviation << ": can't find star HIP" << HP;
return false;
}
break;
}
case 2: // A small asterism with lines by J2000.0 co
ordinates
{
double RA, DE;
Vec3d coords;
istr >> RA >> DE;
StelUtils::spheToRect(RA*M_PI/12., DE*M_PI/1
80., coords);
QList<StelObjectP> stars = starMgr->searchAr
ound(coords, 0.1, core);
StelObjectP s = NULL;
float d = 10.f;
foreach (const StelObjectP &p, stars)
{
float a = coords.angle(p->getJ2000Eq
uatorialPos(core));
if (a<d)
{
d = a;
s = p;
}
}
asterism[i] = s;
if (!asterism[i])
{
qWarning() << "Error in Asterism " <
< abbreviation << ": can't find star with coordinates" << RA << "/" << DE;
return false;
}
asterism[i]=starMgr->searchHP(HP); break;
if (!asterism[i]) }
{
qWarning() << "Error in Asterism " << abbreviation <
< ": can't find star HP= " << HP;
// TODO: why is this delete commented?
// delete[] asterism;
return false;
} }
} }
XYZname.set(0.,0.,0.); if (typeOfAsterism>0)
for(unsigned int ii=0;ii<numberOfSegments*2;++ii)
{ {
XYZname+= asterism[ii]->getJ2000EquatorialPos(StelApp::getIn XYZname.set(0.,0.,0.);
stance().getCore()); for(unsigned int ii=0;ii<numberOfSegments*2;++ii)
{
XYZname+= asterism[ii]->getJ2000EquatorialPos(StelAp
p::getInstance().getCore());
}
XYZname.normalize();
} }
XYZname.normalize(); else
flagAsterism = false;
return true; return true;
} }
void Asterism::drawOptim(StelPainter& sPainter, const StelCore* core, const SphericalCap& viewportHalfspace) const void Asterism::drawOptim(StelPainter& sPainter, const StelCore* core, const SphericalCap& viewportHalfspace) const
{ {
if (lineFader.getInterstate()<=0.0001f) if (flagAsterism)
return; {
if (lineFader.getInterstate()<=0.0001f)
return;
sPainter.setColor(lineColor[0], lineColor[1], lineColor[2], lineFade sPainter.setColor(lineColor[0], lineColor[1], lineColor[2],
r.getInterstate()); lineFader.getInterstate());
}
else
{
if (rayHelperFader.getInterstate()<=0.0001f)
return;
sPainter.setColor(rayHelperColor[0], rayHelperColor[1], rayH
elperColor[2], rayHelperFader.getInterstate());
}
Vec3d star1; Vec3d star1;
Vec3d star2; Vec3d star2;
for (unsigned int i=0;i<numberOfSegments;++i) for (unsigned int i=0;i<numberOfSegments;++i)
{ {
star1=asterism[2*i]->getJ2000EquatorialPos(core); star1=asterism[2*i]->getJ2000EquatorialPos(core);
star2=asterism[2*i+1]->getJ2000EquatorialPos(core); star2=asterism[2*i+1]->getJ2000EquatorialPos(core);
star1.normalize(); star1.normalize();
star2.normalize(); star2.normalize();
sPainter.drawGreatCircleArc(star1, star2, &viewportHalfspace ); sPainter.drawGreatCircleArc(star1, star2, &viewportHalfspace );
} }
} }
void Asterism::drawName(StelPainter& sPainter) const void Asterism::drawName(StelPainter& sPainter) const
{ {
if (!nameFader.getInterstate()) if (!nameFader.getInterstate() || !flagAsterism)
return;
if (typeOfAsterism==2 && sPainter.getProjector()->getFov()>60.f)
return; return;
QString name = getNameI18n(); QString name = getNameI18n();
sPainter.setColor(labelColor[0], labelColor[1], labelColor[2], nameF ader.getInterstate()); sPainter.setColor(labelColor[0], labelColor[1], labelColor[2], nameF ader.getInterstate());
sPainter.drawText(XYname[0], XYname[1], name, 0., -sPainter.getFontM etrics().width(name)/2, 0, false); sPainter.drawText(XYname[0], XYname[1], name, 0., -sPainter.getFontM etrics().width(name)/2, 0, false);
} }
const Asterism* Asterism::isStarIn(const StelObject* s) const const Asterism* Asterism::isStarIn(const StelObject* s) const
{ {
for(unsigned int i=0;i<numberOfSegments*2;++i) for(unsigned int i=0;i<numberOfSegments*2;++i)
{ {
if (asterism[i]->getEnglishName()==s->getEnglishName()) if (asterism[i]==s)
return this; return this;
} }
return Q_NULLPTR; return Q_NULLPTR;
} }
void Asterism::update(int deltaTime) void Asterism::update(int deltaTime)
{ {
lineFader.update(deltaTime); lineFader.update(deltaTime);
rayHelperFader.update(deltaTime);
nameFader.update(deltaTime); nameFader.update(deltaTime);
} }
QString Asterism::getInfoString(const StelCore *core, const InfoStringGroup &flags) const QString Asterism::getInfoString(const StelCore *core, const InfoStringGroup &flags) const
{ {
Q_UNUSED(core); Q_UNUSED(core);
QString str; QString str;
QTextStream oss(&str); QTextStream oss(&str);
if (flags&Name) if (flags&Name)
oss << "<h2>" << getNameI18n() << "</h2>"; oss << "<h2>" << getNameI18n() << "</h2>";
if (flags&ObjectType) if (flags&ObjectType)
oss << q_("Type: <b>%1</b>").arg(q_("asterism")) << "<br />" ; oss << QString("%1: <b>%2</b>").arg(q_("Type"), q_("asterism ")) << "<br />";
postProcessInfoString(str, flags); postProcessInfoString(str, flags);
return str; return str;
} }
 End of changes. 19 change blocks. 
30 lines changed or deleted 99 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/