AngleMeasure.cpp   AngleMeasure.cpp 
skipping to change at line 67 skipping to change at line 67
info.displayedName = N_("Angle Measure"); info.displayedName = N_("Angle Measure");
info.authors = "Matthew Gates, Bogdan Marinov, Alexander Wolf, Georg Zotti"; info.authors = "Matthew Gates, Bogdan Marinov, Alexander Wolf, Georg Zotti";
info.contact = "http://porpoisehead.net/"; info.contact = "http://porpoisehead.net/";
info.description = N_("Provides an angle measurement tool"); info.description = N_("Provides an angle measurement tool");
info.version = ANGLEMEASURE_VERSION; info.version = ANGLEMEASURE_VERSION;
return info; return info;
} }
AngleMeasure::AngleMeasure() AngleMeasure::AngleMeasure()
: flagShowAngleMeasure(false) : flagShowAngleMeasure(false)
, withDecimalDegree(false)
, dragging(false) , dragging(false)
, angle(0.) , angle(0.)
, flagUseDmsFormat(false) , flagUseDmsFormat(false)
, flagShowPA(false) , flagShowPA(false)
, flagShowEquatorial(false) , flagShowEquatorial(false)
, flagShowHorizontal(false) , flagShowHorizontal(false)
, flagShowHorizontalPA(false) , flagShowHorizontalPA(false)
, flagShowHorizontalStartSkylinked(false) , flagShowHorizontalStartSkylinked(false)
, flagShowHorizontalEndSkylinked(false) , flagShowHorizontalEndSkylinked(false)
, toolbarButton(NULL) , toolbarButton(NULL)
skipping to change at line 169 skipping to change at line 170
qWarning() << "WARNING: unable create toolbar button for Ang leMeasure plugin: " << e.what(); qWarning() << "WARNING: unable create toolbar button for Ang leMeasure plugin: " << e.what();
} }
} }
void AngleMeasure::update(double deltaTime) void AngleMeasure::update(double deltaTime)
{ {
messageFader.update((int)(deltaTime*1000)); messageFader.update((int)(deltaTime*1000));
lineVisible.update((int)(deltaTime*1000)); lineVisible.update((int)(deltaTime*1000));
static StelCore *core=StelApp::getInstance().getCore(); static StelCore *core=StelApp::getInstance().getCore();
withDecimalDegree = dynamic_cast<StelGui*>(StelApp::getInstance().ge
tGui())->getFlagShowDecimalDegrees();
// if altAz endpoint linked to the rotating sky, move respective poi nt(s) // if altAz endpoint linked to the rotating sky, move respective poi nt(s)
if (flagShowHorizontalStartSkylinked) if (flagShowHorizontalStartSkylinked)
{ {
startPointHor = core->equinoxEquToAltAz(startPoint, StelCore ::RefractionAuto); startPointHor = core->equinoxEquToAltAz(startPoint, StelCore ::RefractionAuto);
calculateEnds(); calculateEnds();
} }
if (flagShowHorizontalEndSkylinked) if (flagShowHorizontalEndSkylinked)
{ {
endPointHor = core->equinoxEquToAltAz(endPoint, StelCore::Re fractionAuto); endPointHor = core->equinoxEquToAltAz(endPoint, StelCore::Re fractionAuto);
calculateEnds(); calculateEnds();
} }
} }
void AngleMeasure::drawOne(StelCore *core, const StelCore::FrameType frameT ype, const StelCore::RefractionMode refractionMode, const Vec3f txtColor, c onst Vec3f lineColor) void AngleMeasure::drawOne(StelCore *core, const StelCore::FrameType frameT ype, const StelCore::RefractionMode refractionMode, const Vec3f txtColor, c onst Vec3f lineColor)
{ {
const StelProjectorP prj = core->getProjection(frameType, refraction Mode); const StelProjectorP prj = core->getProjection(frameType, refraction Mode);
StelPainter painter(prj); StelPainter painter(prj);
painter.setFont(font); painter.setFont(font);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
if (lineVisible.getInterstate() > 0.000001f) if (lineVisible.getInterstate() > 0.000001f)
{ {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
Vec3d xy; Vec3d xy;
QString displayedText; QString displayedText;
if (frameType==StelCore::FrameEquinoxEqu) if (frameType==StelCore::FrameEquinoxEqu)
{ {
if (prj->project(perp1EndPoint,xy)) if (prj->project(perp1EndPoint,xy))
{ {
painter.setColor(txtColor[0], txtColor[1], t xtColor[2], lineVisible.getInterstate()); painter.setColor(txtColor[0], txtColor[1], t xtColor[2], lineVisible.getInterstate());
if (flagShowPA) if (flagShowPA)
displayedText = QString("%1 (%2%3)") .arg(calculateAngle(), messagePA, calculatePositionAngle(startPoint, endPoi nt)); displayedText = QString("%1 (%2%3)") .arg(calculateAngle(), messagePA, calculatePositionAngle(startPoint, endPoi nt));
else else
skipping to change at line 222 skipping to change at line 223
painter.setColor(txtColor[0], txtColor[1], t xtColor[2], lineVisible.getInterstate()); painter.setColor(txtColor[0], txtColor[1], t xtColor[2], lineVisible.getInterstate());
if (flagShowHorizontalPA) if (flagShowHorizontalPA)
displayedText = QString("%1 (%2%3)") .arg(calculateAngle(true), messagePA, calculatePositionAngle(startPointHor, endPointHor)); displayedText = QString("%1 (%2%3)") .arg(calculateAngle(true), messagePA, calculatePositionAngle(startPointHor, endPointHor));
else else
displayedText = calculateAngle(true) ; displayedText = calculateAngle(true) ;
painter.drawText(xy[0], xy[1], displayedText , 0, 15, -5); painter.drawText(xy[0], xy[1], displayedText , 0, 15, -5);
} }
} }
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
// OpenGL ES 2.0 doesn't have GL_LINE_SMOOTH // OpenGL ES 2.0 doesn't have GL_LINE_SMOOTH. But it looks m
// glEnable(GL_LINE_SMOOTH); uch better.
glEnable(GL_BLEND); #ifdef GL_LINE_SMOOTH
if (QOpenGLContext::currentContext()->format().renderableTyp
e()==QSurfaceFormat::OpenGL)
glEnable(GL_LINE_SMOOTH);
#endif
// main line is a great circle // main line is a great circle
painter.setColor(lineColor[0], lineColor[1], lineColor[2], l ineVisible.getInterstate()); painter.setColor(lineColor[0], lineColor[1], lineColor[2], l ineVisible.getInterstate());
if (frameType==StelCore::FrameEquinoxEqu) if (frameType==StelCore::FrameEquinoxEqu)
{ {
painter.drawGreatCircleArc(startPoint, endPoint, NUL L); painter.drawGreatCircleArc(startPoint, endPoint, NUL L);
// End lines // End lines
painter.drawGreatCircleArc(perp1StartPoint, perp1End Point, NULL); painter.drawGreatCircleArc(perp1StartPoint, perp1End Point, NULL);
painter.drawGreatCircleArc(perp2StartPoint, perp2End Point, NULL); painter.drawGreatCircleArc(perp2StartPoint, perp2End Point, NULL);
} }
else else
{ {
painter.drawGreatCircleArc(startPointHor, endPointHo r, NULL); painter.drawGreatCircleArc(startPointHor, endPointHo r, NULL);
// End lines // End lines
painter.drawGreatCircleArc(perp1StartPointHor, perp1 EndPointHor, NULL); painter.drawGreatCircleArc(perp1StartPointHor, perp1 EndPointHor, NULL);
painter.drawGreatCircleArc(perp2StartPointHor, perp2 EndPointHor, NULL); painter.drawGreatCircleArc(perp2StartPointHor, perp2 EndPointHor, NULL);
} }
#ifdef GL_LINE_SMOOTH
if (QOpenGLContext::currentContext()->format().renderableTyp
e()==QSurfaceFormat::OpenGL)
glDisable(GL_LINE_SMOOTH);
#endif
} }
if (messageFader.getInterstate() > 0.000001f) if (messageFader.getInterstate() > 0.000001f)
{ {
painter.setColor(txtColor[0], txtColor[1], txtColor[2], mess ageFader.getInterstate()); painter.setColor(txtColor[0], txtColor[1], txtColor[2], mess ageFader.getInterstate());
int x = 83; int x = 83;
int y = 120; int y = 120;
int ls = painter.getFontMetrics().lineSpacing(); int ls = painter.getFontMetrics().lineSpacing();
painter.drawText(x, y, messageEnabled); painter.drawText(x, y, messageEnabled);
y -= ls; y -= ls;
painter.drawText(x, y, messageLeftButton); painter.drawText(x, y, messageLeftButton);
y -= ls; y -= ls;
painter.drawText(x, y, messageRightButton); painter.drawText(x, y, messageRightButton);
} }
glDisable(GL_BLEND);
} }
//! Draw any parts on the screen which are for our module //! Draw any parts on the screen which are for our module
void AngleMeasure::draw(StelCore* core) void AngleMeasure::draw(StelCore* core)
{ {
if (lineVisible.getInterstate() < 0.000001f && messageFader.getInter state() < 0.000001f) if (lineVisible.getInterstate() < 0.000001f && messageFader.getInter state() < 0.000001f)
return; return;
if (flagShowHorizontal) if (flagShowHorizontal)
{ {
drawOne(core, StelCore::FrameAltAz, StelCore::RefractionOff, horTextColor, horLineColor); drawOne(core, StelCore::FrameAltAz, StelCore::RefractionOff, horTextColor, horLineColor);
skipping to change at line 280 skipping to change at line 287
{ {
drawOne(core, StelCore::FrameEquinoxEqu, StelCore::Refractio nAuto, textColor, lineColor); drawOne(core, StelCore::FrameEquinoxEqu, StelCore::Refractio nAuto, textColor, lineColor);
} }
} }
QString AngleMeasure::calculatePositionAngle(const Vec3d p1, const Vec3d p2 ) const QString AngleMeasure::calculatePositionAngle(const Vec3d p1, const Vec3d p2 ) const
{ {
double y = cos(p2.latitude())*sin(p2.longitude()-p1.longitude()); double y = cos(p2.latitude())*sin(p2.longitude()-p1.longitude());
double x = cos(p1.latitude())*sin(p2.latitude()) - sin(p1.latitude() )*cos(p2.latitude())*cos(p2.longitude()-p1.longitude()); double x = cos(p1.latitude())*sin(p2.latitude()) - sin(p1.latitude() )*cos(p2.latitude())*cos(p2.longitude()-p1.longitude());
double r = std::atan2(y,x); double r = std::atan2(y,x);
// GZ ATAN2 makes many tests unnecessary...
// if (x<0)
// r += M_PI;
// if (y<0)
// r += 2*M_PI;
// if (r>(2*M_PI))
// r -= 2*M_PI;
if (r<0) if (r<0)
r+= 2*M_PI; r+= 2*M_PI;
unsigned int d, m; unsigned int d, m;
double s; double s;
bool sign; bool sign;
StelUtils::radToDms(r, sign, d, m, s);
if (flagUseDmsFormat) if (withDecimalDegree)
return QString("%1d %2m %3s").arg(d).arg(m).arg(s, 0, 'f', 2 {
); StelUtils::radToDecDeg(r, sign, s);
if (flagUseDmsFormat)
return QString("%1d").arg(s, 0, 'f', 5);
else
return QString("%1%2").arg(s, 0, 'f', 5).arg(QChar(0
x00B0));
}
else else
return QString("%1%2 %3' %4\"").arg(d).arg(QChar(0x00B0)).ar {
g(m).arg(s, 0, 'f', 2); StelUtils::radToDms(r, sign, d, m, s);
if (flagUseDmsFormat)
return QString("%1d %2m %3s").arg(d).arg(m).arg(s, 0
, 'f', 2);
else
return QString("%1%2 %3' %4\"").arg(d).arg(QChar(0x0
0B0)).arg(m).arg(s, 0, 'f', 2);
}
} }
void AngleMeasure::handleKeys(QKeyEvent* event) void AngleMeasure::handleKeys(QKeyEvent* event)
{ {
event->setAccepted(false); event->setAccepted(false);
} }
void AngleMeasure::handleMouseClicks(class QMouseEvent* event) void AngleMeasure::handleMouseClicks(class QMouseEvent* event)
{ {
if (!flagShowAngleMeasure) if (!flagShowAngleMeasure)
{ {
event->setAccepted(false); event->setAccepted(false);
return; return;
} }
if (event->type()==QEvent::MouseButtonPress && event->button()==Qt:: LeftButton) if (event->type()==QEvent::MouseButtonPress && event->button()==Qt:: LeftButton)
{ {
const StelProjectorP prj = StelApp::getInstance().getCore()- >getProjection(StelCore::FrameEquinoxEqu); const StelProjectorP prj = StelApp::getInstance().getCore()- >getProjection(StelCore::FrameEquinoxEqu);
prj->unProject(event->x(),event->y(),startPoint); prj->unProject(event->x(),event->y(),startPoint);
{ // Nick Fedoseev patch: improve click match
Vec3d win;
prj->project(startPoint,win);
float dx = event->x() - win.v[0];
float dy = event->y() - win.v[1];
prj->unProject(event->x()+dx, event->y()+dy, startPo
int);
}
const StelProjectorP prjHor = StelApp::getInstance().getCore ()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff); const StelProjectorP prjHor = StelApp::getInstance().getCore ()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
prjHor->unProject(event->x(),event->y(),startPointHor); prjHor->unProject(event->x(),event->y(),startPointHor);
// first click reset the line... only draw it after we've dr agged a little. // first click reset the line... only draw it after we've dr agged a little.
if (!dragging) if (!dragging)
{ {
lineVisible = false; lineVisible = false;
endPoint = startPoint; endPoint = startPoint;
endPointHor=startPointHor; endPointHor=startPointHor;
} }
skipping to change at line 346 skipping to change at line 365
{ {
dragging = false; dragging = false;
calculateEnds(); calculateEnds();
event->setAccepted(true); event->setAccepted(true);
return; return;
} }
else if (event->type()==QEvent::MouseButtonPress && event->button()= =Qt::RightButton) else if (event->type()==QEvent::MouseButtonPress && event->button()= =Qt::RightButton)
{ {
const StelProjectorP prj = StelApp::getInstance().getCore()- >getProjection(StelCore::FrameEquinoxEqu); const StelProjectorP prj = StelApp::getInstance().getCore()- >getProjection(StelCore::FrameEquinoxEqu);
prj->unProject(event->x(),event->y(),endPoint); prj->unProject(event->x(),event->y(),endPoint);
{ // Nick Fedoseev patch: improve click match
Vec3d win;
prj->project(endPoint,win);
float dx = event->x() - win.v[0];
float dy = event->y() - win.v[1];
prj->unProject(event->x()+dx, event->y()+dy, endPoin
t);
}
const StelProjectorP prjHor = StelApp::getInstance().getCore ()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff); const StelProjectorP prjHor = StelApp::getInstance().getCore ()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
prjHor->unProject(event->x(),event->y(),endPointHor); prjHor->unProject(event->x(),event->y(),endPointHor);
calculateEnds(); calculateEnds();
event->setAccepted(true); event->setAccepted(true);
return; return;
} }
event->setAccepted(false); event->setAccepted(false);
} }
bool AngleMeasure::handleMouseMoves(int x, int y, Qt::MouseButtons) bool AngleMeasure::handleMouseMoves(int x, int y, Qt::MouseButtons)
{ {
if (dragging) if (dragging)
{ {
const StelProjectorP prj = StelApp::getInstance().getCore()- >getProjection(StelCore::FrameEquinoxEqu); const StelProjectorP prj = StelApp::getInstance().getCore()- >getProjection(StelCore::FrameEquinoxEqu);
prj->unProject(x,y,endPoint); prj->unProject(x,y,endPoint);
{ // Nick Fedoseev patch: improve click match
Vec3d win;
prj->project(endPoint,win);
float dx = x - win.v[0];
float dy = y - win.v[1];
prj->unProject(x+dx, y+dy, endPoint);
}
const StelProjectorP prjHor = StelApp::getInstance().getCore ()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff); const StelProjectorP prjHor = StelApp::getInstance().getCore ()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
prjHor->unProject(x,y,endPointHor); prjHor->unProject(x,y,endPointHor);
calculateEnds(); calculateEnds();
lineVisible = true; lineVisible = true;
return true; return true;
} }
else else
return false; return false;
} }
skipping to change at line 397 skipping to change at line 430
v1 = Vec3d(0,0,0) - end; v1 = Vec3d(0,0,0) - end;
p = v0 ^ v1; p = v0 ^ v1;
p *= 0.08; // end width p *= 0.08; // end width
perp2Start.set(end[0]-p[0],end[1]-p[1],end[2]-p[2]); perp2Start.set(end[0]-p[0],end[1]-p[1],end[2]-p[2]);
perp2End.set(end[0]+p[0],end[1]+p[1],end[2]+p[2]); perp2End.set(end[0]+p[0],end[1]+p[1],end[2]+p[2]);
angle = start.angle(end); angle = start.angle(end);
} }
// GZ Misnomer! should be called formatAngleString() // Misnomer! should be called formatAngleString()
QString AngleMeasure::calculateAngle(bool horizontal) const QString AngleMeasure::calculateAngle(bool horizontal) const
{ {
unsigned int d, m; unsigned int d, m;
double s; double s;
bool sign; bool sign;
if (horizontal) if (withDecimalDegree)
StelUtils::radToDms(angleHor, sign, d, m, s); {
else if (horizontal)
StelUtils::radToDms(angle, sign, d, m, s); StelUtils::radToDecDeg(angleHor, sign, s);
if (flagUseDmsFormat) else
return QString("%1d %2m %3s").arg(d).arg(m).arg(s, 0, 'f', 2 StelUtils::radToDecDeg(angle, sign, s);
);
if (flagUseDmsFormat)
return QString("%1d").arg(s, 0, 'f', 5);
else
return QString("%1%2").arg(s, 0, 'f', 5).arg(QChar(0
x00B0));
}
else else
return QString("%1%2 %3' %4\"").arg(d).arg(QChar(0x00B0)).ar {
g(m).arg(s, 0, 'f', 2); if (horizontal)
StelUtils::radToDms(angleHor, sign, d, m, s);
else
StelUtils::radToDms(angle, sign, d, m, s);
if (flagUseDmsFormat)
return QString("%1d %2m %3s").arg(d).arg(m).arg(s, 0
, 'f', 2);
else
return QString("%1%2 %3' %4\"").arg(d).arg(QChar(0x0
0B0)).arg(m).arg(s, 0, 'f', 2);
}
} }
void AngleMeasure::enableAngleMeasure(bool b) void AngleMeasure::enableAngleMeasure(bool b)
{ {
flagShowAngleMeasure = b; flagShowAngleMeasure = b;
lineVisible = b; lineVisible = b;
messageFader = b; messageFader = b;
if (b) if (b)
{ {
//qDebug() << "AngleMeasure::enableAngleMeasure starting tim er"; //qDebug() << "AngleMeasure::enableAngleMeasure starting tim er";
 End of changes. 16 change blocks. 
31 lines changed or deleted 87 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/