AngleMeasure.cpp   AngleMeasure.cpp 
skipping to change at line 19 skipping to change at line 19
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelUtils.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelPainter.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include "StelIniParser.hpp" #include "StelVertexArray.hpp"
#include "AngleMeasure.hpp" #include "AngleMeasure.hpp"
#include "renderer/StelCircleArcRenderer.hpp" #include "AngleMeasureDialog.hpp"
#include "renderer/StelRenderer.hpp"
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
#include <QAction>
#include <QPixmap> #include <QPixmap>
#include <QtNetwork> #include <QtNetwork>
#include <QSettings> #include <QSettings>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <cmath> #include <cmath>
//! This method is the one called automatically by the StelModuleMgr just //! This method is the one called automatically by the StelModuleMgr just
//! after loading the dynamic library //! after loading the dynamic library
StelModule* AngleMeasureStelPluginInterface::getStelModule() const StelModule* AngleMeasureStelPluginInterface::getStelModule() const
skipping to change at line 60 skipping to change at line 60
{ {
// Allow to load the resources when used as a static plugin // Allow to load the resources when used as a static plugin
Q_INIT_RESOURCE(AngleMeasure); Q_INIT_RESOURCE(AngleMeasure);
StelPluginInfo info; StelPluginInfo info;
info.id = "AngleMeasure"; info.id = "AngleMeasure";
info.displayedName = N_("Angle Measure"); info.displayedName = N_("Angle Measure");
info.authors = "Matthew Gates"; info.authors = "Matthew Gates";
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;
return info; return info;
} }
Q_EXPORT_PLUGIN2(AngleMeasure, AngleMeasureStelPluginInterface)
AngleMeasure::AngleMeasure() AngleMeasure::AngleMeasure()
: flagShowAngleMeasure(false), dragging(false), : flagShowAngleMeasure(false)
angleText(""), flagUseDmsFormat(false), toolbarButton(NULL) , dragging(false)
, angle(0.)
, flagUseDmsFormat(false)
, flagShowPA(false)
, toolbarButton(NULL)
{ {
setObjectName("AngleMeasure"); setObjectName("AngleMeasure");
font.setPixelSize(16); font.setPixelSize(16);
configDialog = new AngleMeasureDialog();
conf = StelApp::getInstance().getSettings();
messageTimer = new QTimer(this); messageTimer = new QTimer(this);
messageTimer->setInterval(7000); messageTimer->setInterval(7000);
messageTimer->setSingleShot(true); messageTimer->setSingleShot(true);
connect(messageTimer, SIGNAL(timeout()), this, SLOT(clearMessage())) ; connect(messageTimer, SIGNAL(timeout()), this, SLOT(clearMessage())) ;
QSettings* conf = StelApp::getInstance().getSettings();
if (!conf->contains("AngleMeasure/angle_format_dms"))
{
// Create the "AngleMeasure" section and set default paramet
ers
conf->setValue("AngleMeasure/angle_format_dms", false);
conf->setValue("AngleMeasure/text_color", "0,0.5,1");
conf->setValue("AngleMeasure/line_color", "0,0.5,1");
}
flagUseDmsFormat = conf->value("AngleMeasure/angle_format_dms", fals
e).toBool();
textColor = StelUtils::strToVec3f(conf->value("AngleMeasure/text_col
or", "0,0.5,1").toString());
lineColor = StelUtils::strToVec3f(conf->value("AngleMeasure/line_col
or", "0,0.5,1").toString());
} }
AngleMeasure::~AngleMeasure() AngleMeasure::~AngleMeasure()
{ {
delete configDialog;
} }
//! Determine which "layer" the plagin's drawing will happen on. bool AngleMeasure::configureGui(bool show)
{
if (show)
configDialog->setVisible(true);
return true;
}
//! Determine which "layer" the plugin's drawing will happen on.
double AngleMeasure::getCallOrder(StelModuleActionName actionName) const double AngleMeasure::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName)+10.; return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName)+10.;
if (actionName==StelModule::ActionHandleMouseClicks) if (actionName==StelModule::ActionHandleMouseClicks)
return -11; return -11;
return 0; return 0;
} }
void AngleMeasure::init() void AngleMeasure::init()
{ {
qDebug() << "AngleMeasure plugin - press control-A to toggle angle m if (!conf->childGroups().contains("AngleMeasure"))
easure mode"; restoreDefaultSettings();
loadSettings();
startPoint.set(0.,0.,0.); startPoint.set(0.,0.,0.);
endPoint.set(0.,0.,0.); endPoint.set(0.,0.,0.);
perp1StartPoint.set(0.,0.,0.); perp1StartPoint.set(0.,0.,0.);
perp1EndPoint.set(0.,0.,0.); perp1EndPoint.set(0.,0.,0.);
perp2StartPoint.set(0.,0.,0.); perp2StartPoint.set(0.,0.,0.);
perp2EndPoint.set(0.,0.,0.); perp2EndPoint.set(0.,0.,0.);
StelApp& app = StelApp::getInstance(); StelApp& app = StelApp::getInstance();
// Create action for enable/disable & hook up signals // Create action for enable/disable & hook up signals
StelGui* gui = dynamic_cast<StelGui*>(app.getGui()); addAction("actionShow_Angle_Measure", N_("Angle Measure"), N_("Angle
Q_ASSERT(gui); measure"), "enabled", "Ctrl+A");
QAction* action = gui->getGuiAction("actionShow_Angle_Measure");
action->setChecked(flagShowAngleMeasure);
connect(action, SIGNAL(toggled(bool)), this, SLOT(enableAngleMeasure
(bool)));
// Initialize the message strings and make sure they are translated when // Initialize the message strings and make sure they are translated when
// the language changes. // the language changes.
updateMessageText(); updateMessageText();
connect(&app, SIGNAL(languageChanged()), this, SLOT(updateMessageTex t())); connect(&app, SIGNAL(languageChanged()), this, SLOT(updateMessageTex t()));
// Add a toolbar button // Add a toolbar button
try try
{ {
toolbarButton = new StelButton(NULL, QPixmap(":/angleMeasure StelGui* gui = dynamic_cast<StelGui*>(app.getGui());
/bt_anglemeasure_on.png"), QPixmap(":/angleMeasure/bt_anglemeasure_off.png" if (gui!=NULL)
), {
toolbarButton = new StelButton(NULL,
QPixmap(":/gra QPixmap(":/angleMeasu
phicGui/glow32x32.png"), gui->getGuiAction("actionShow_Angle_Measure")); re/bt_anglemeasure_on.png"),
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr QPixmap(":/angleMeasu
oup"); re/bt_anglemeasure_off.png"),
QPixmap(":/graphicGui
/glow32x32.png"),
"actionShow_Angle_Mea
sure");
gui->getButtonBar()->addButton(toolbarButton, "065-p
luginsGroup");
}
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
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));
} }
//! 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, StelRenderer* renderer) 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;
const StelProjectorP prj = core->getProjection(StelCore::FrameEquino xEqu); const StelProjectorP prj = core->getProjection(StelCore::FrameEquino xEqu);
StelPainter painter(prj);
renderer->setFont(font); painter.setFont(font);
const bool night = StelApp::getInstance().getVisionModeNight();
const Vec3f tColor = night ? StelUtils::getNightColor(textColor) : l
ineColor;
const Vec3f lColor = night ? StelUtils::getNightColor(lineColor) : l
ineColor;
if (lineVisible.getInterstate() > 0.000001f) if (lineVisible.getInterstate() > 0.000001f)
{ {
renderer->setBlendMode(BlendMode_Alpha); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
Vec3d xy; Vec3d xy;
QString displayedText;
if (prj->project(perp1EndPoint,xy)) if (prj->project(perp1EndPoint,xy))
{ {
renderer->setGlobalColor(tColor[0], tColor[1], tColo painter.setColor(textColor[0], textColor[1], textCol
r[2], or[2], lineVisible.getInterstate());
lineVisible.getInterstate() if (flagShowPA)
); displayedText = QString("%1 (%2%3)").arg(cal
renderer->drawText(TextParams(xy[0], xy[1], angleTex culateAngle(), messagePA, calculatePositionAngle(startPoint, endPoint));
t).shift(15, 15)); else
displayedText = calculateAngle();
painter.drawText(xy[0], xy[1], displayedText, 0, 15,
15);
} }
renderer->setGlobalColor(lColor[0], lColor[1], lColor[2], glDisable(GL_TEXTURE_2D);
lineVisible.getInterstate()); // OpenGL ES 2.0 doesn't have GL_LINE_SMOOTH
// glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
// main line is a great circle // main line is a great circle
StelCircleArcRenderer circleArcRenderer(renderer, prj); painter.setColor(lineColor[0], lineColor[1], lineColor[2], l
circleArcRenderer.drawGreatCircleArc(startPoint, endPoint); ineVisible.getInterstate());
painter.drawGreatCircleArc(startPoint, endPoint, NULL);
// End lines // End lines
circleArcRenderer.drawGreatCircleArc(perp1StartPoint, perp1E painter.drawGreatCircleArc(perp1StartPoint, perp1EndPoint, N
ndPoint); ULL);
circleArcRenderer.drawGreatCircleArc(perp2StartPoint, perp2E painter.drawGreatCircleArc(perp2StartPoint, perp2EndPoint, N
ndPoint); ULL);
} }
if (messageFader.getInterstate() > 0.000001f) if (messageFader.getInterstate() > 0.000001f)
{ {
renderer->setGlobalColor(tColor[0], tColor[1], tColor[2], painter.setColor(textColor[0], textColor[1], textColor[2], m
messageFader.getInterstate()); essageFader.getInterstate());
int x = 83; int x = 83;
int y = 120; int y = 120;
const int ls = QFontMetrics(font).lineSpacing(); int ls = painter.getFontMetrics().lineSpacing();
renderer->drawText(TextParams(x, y, messageEnabled)); painter.drawText(x, y, messageEnabled);
y -= ls; y -= ls;
renderer->drawText(TextParams(x, y, messageLeftButton)); painter.drawText(x, y, messageLeftButton);
y -= ls; y -= ls;
renderer->drawText(TextParams(x, y, messageRightButton)); painter.drawText(x, y, messageRightButton);
} }
} }
QString AngleMeasure::calculatePositionAngle(const Vec3d p1, const Vec3d p2
) const
{
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 r = std::atan(y/x);
if (x<0)
r += M_PI;
if (y<0)
r += 2*M_PI;
if (r>(2*M_PI))
r -= 2*M_PI;
unsigned int d, m;
double s;
bool sign;
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(0x00B0)).ar
g(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);
skipping to change at line 281 skipping to change at line 314
p *= 0.08; // end width p *= 0.08; // end width
perp1StartPoint.set(startPoint[0]-p[0],startPoint[1]-p[1],startPoint [2]-p[2]); perp1StartPoint.set(startPoint[0]-p[0],startPoint[1]-p[1],startPoint [2]-p[2]);
perp1EndPoint.set(startPoint[0]+p[0],startPoint[1]+p[1],startPoint[2 ]+p[2]); perp1EndPoint.set(startPoint[0]+p[0],startPoint[1]+p[1],startPoint[2 ]+p[2]);
v1 = Vec3d(0,0,0) - endPoint; v1 = Vec3d(0,0,0) - endPoint;
p = v0 ^ v1; p = v0 ^ v1;
p *= 0.08; // end width p *= 0.08; // end width
perp2StartPoint.set(endPoint[0]-p[0],endPoint[1]-p[1],endPoint[2]-p[ 2]); perp2StartPoint.set(endPoint[0]-p[0],endPoint[1]-p[1],endPoint[2]-p[ 2]);
perp2EndPoint.set(endPoint[0]+p[0],endPoint[1]+p[1],endPoint[2]+p[2] ); perp2EndPoint.set(endPoint[0]+p[0],endPoint[1]+p[1],endPoint[2]+p[2] );
angle = startPoint.angle(endPoint);
}
QString AngleMeasure::calculateAngle() const
{
unsigned int d, m; unsigned int d, m;
double s; double s;
bool sign; bool sign;
StelUtils::radToDms(startPoint.angle(endPoint), sign, d, m, s);
StelUtils::radToDms(angle, sign, d, m, s);
if (flagUseDmsFormat) if (flagUseDmsFormat)
angleText = QString("%1d %2m %3s").arg(d).arg(m).arg(s, 0, ' f', 2); return QString("%1d %2m %3s").arg(d).arg(m).arg(s, 0, 'f', 2 );
else else
angleText = QString("%1%2 %3' %4\"").arg(d).arg(QChar(0x00B0 )).arg(m).arg(s, 0, 'f', 2); return QString("%1%2 %3' %4\"").arg(d).arg(QChar(0x00B0)).ar g(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";
messageTimer->start(); messageTimer->start();
} }
} }
void AngleMeasure::showPositionAngle(bool b)
{
flagShowPA = b;
}
void AngleMeasure::useDmsFormat(bool b)
{
flagUseDmsFormat=b;
}
void AngleMeasure::updateMessageText() void AngleMeasure::updateMessageText()
{ {
// TRANSLATORS: instructions for using the AngleMeasure plugin. // TRANSLATORS: instructions for using the AngleMeasure plugin.
messageEnabled = q_("The Angle Measure is enabled:"); messageEnabled = q_("The Angle Measure is enabled:");
// TRANSLATORS: instructions for using the AngleMeasure plugin. // TRANSLATORS: instructions for using the AngleMeasure plugin.
messageLeftButton = q_("Drag with the left button to measure, left-c lick to clear."); messageLeftButton = q_("Drag with the left button to measure, left-c lick to clear.");
// TRANSLATORS: instructions for using the AngleMeasure plugin. // TRANSLATORS: instructions for using the AngleMeasure plugin.
messageRightButton = q_("Right-clicking changes the end point only." ); messageRightButton = q_("Right-clicking changes the end point only." );
// TRANSLATORS: PA is abbreviation for phrase "Position Angle"
messagePA = q_("PA=");
} }
void AngleMeasure::clearMessage() void AngleMeasure::clearMessage()
{ {
//qDebug() << "AngleMeasure::clearMessage"; //qDebug() << "AngleMeasure::clearMessage";
messageFader = false; messageFader = false;
} }
void AngleMeasure::restoreDefaultSettings()
{
Q_ASSERT(conf);
// Remove the old values...
conf->remove("AngleMeasure");
// ...load the default values...
loadSettings();
// ...and then save them.
saveSettings();
// But this doesn't save the colors, so:
conf->beginGroup("AngleMeasure");
conf->setValue("text_color", "0,0.5,1");
conf->setValue("line_color", "0,0.5,1");
conf->endGroup();
}
void AngleMeasure::loadSettings()
{
conf->beginGroup("AngleMeasure");
useDmsFormat(conf->value("angle_format_dms", false).toBool());
showPositionAngle(conf->value("show_position_angle", false).toBool()
);
textColor = StelUtils::strToVec3f(conf->value("text_color", "0,0.5,1
").toString());
lineColor = StelUtils::strToVec3f(conf->value("line_color", "0,0.5,1
").toString());
conf->endGroup();
}
void AngleMeasure::saveSettings()
{
conf->beginGroup("AngleMeasure");
conf->setValue("angle_format_dms", isDmsFormat());
conf->setValue("show_position_angle", isPaDisplayed());
conf->endGroup();
}
 End of changes. 35 change blocks. 
75 lines changed or deleted 125 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/