Isis 3 Programmer Reference
LatLonGridTool.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "LatLonGridTool.h"
10
11#include <QAction>
12#include <QPixmap>
13#include <QStackedWidget>
14#include <QHBoxLayout>
15#include <QCheckBox>
16#include <QPainter>
17
18#include "MdiCubeViewport.h"
19#include "ToolPad.h"
20#include "Camera.h"
21
22
23namespace Isis {
30 }
31
40 QAction *action = new QAction(pad);
41 action->setIcon(QPixmap(toolIconDir() + "/grid.png"));
42 action->setToolTip("Lat Lon Grid Tool (G)");
43 action->setShortcut(Qt::Key_G);
44
45 QString text =
46 "<b>Function:</b> View lat lon grid \
47 <p><b>Shortcut:</b> G</p> ";
48 action->setWhatsThis(text);
49
50 return action;
51 }
52
62 QWidget *container = new QWidget(active);
63 container->setObjectName("LatLonGridToolActiveToolBarWidget");
64
65 m_gridCheckBox = new QCheckBox;
66 m_gridCheckBox->setText("Show Grid");
67
68 QHBoxLayout *layout = new QHBoxLayout;
69 layout->setMargin(0);
70 layout->addWidget(m_gridCheckBox);
71 layout->addStretch(1);
72 container->setLayout(layout);
73
74 m_container = container;
75 return container;
76 }
77
85 void LatLonGridTool::paintViewport(MdiCubeViewport *mvp, QPainter *painter) {
86 int x1, x2, y1, y2;
87 double lat, lon;
88
89 QFont font;
90 QBrush brush(Qt::gray);
91 QPen pen(brush, 1);
92
93 // Only draws if "Show Grid" checkbox is checked
94 if (m_gridCheckBox->isChecked()) {
95 painter->setPen(pen);
96 font.setPixelSize(8);
97 painter->setFont(font);
98
99 // Draws Longitude Lines
100 for (int i = mvp->cubeSamples(); i > 0; i -= mvp->cubeSamples() / 12) {
101 if (mvp->camera() != NULL) {
102 mvp->camera()->SetImage(i, 0);
103 lon = mvp->camera()->UniversalLongitude();
104
105 lon = ceil(lon * 100.0) / 100.0;
106
107 mvp->cubeToViewport(i, 0, x1, y1);
108 mvp->cubeToViewport(0, mvp->cubeLines(), x2, y2);
109 painter->drawLine(x1, y1, x1, y2);
110
111 painter->drawText(x1, y2 + 10, toString(lon));
112 }
113 }
114
115 // Draws Latitude Lines
116 for (int i = mvp->cubeLines(); i > 0; i -= mvp->cubeLines() / 12) {
117 if (mvp->camera() != NULL) {
118 mvp->camera()->SetImage(0, i);
119 lat = mvp->camera()->UniversalLatitude();
120
121 lat = ceil(lat * 100.0) / 100.0;
122
123 mvp->cubeToViewport(0, i, x1, y1);
124 mvp->cubeToViewport(mvp->cubeSamples(), 0, x2, y2);
125 painter->drawLine(x1, y1, x2, y1);
126
127 painter->drawText(x2 + 5, y1, toString(lat));
128 }
129 }
130 }
131 // remove grid by updating viewport to original cubeViewport
132 else {
133 mvp = cubeViewport();
134 }
135 }
136
142
143 if (vp != NULL) {
144 if (vp->camera() == NULL) {
145 m_gridCheckBox->setEnabled(false);
146 }
147 else {
148 m_gridCheckBox->setEnabled(true);
149 }
150 }
151 }
152}
QAction * toolPadAction(ToolPad *pad)
Adds the LatLonGridTool to the tool pad.
void paintViewport(MdiCubeViewport *mvp, QPainter *painter)
Draws grid onto cube viewport This is overiding the parents paintViewport member.
LatLonGridTool(QWidget *parent)
Constructs an LatLonGridTool object.
void updateTool()
Enables/Disable grid option tool based on camera model.
QWidget * createToolBarWidget(QStackedWidget *active)
Creates the toolbar containing the lat-lon grid tool widgets.
Cube display widget for certain Isis MDI applications.
Base class for the Qisis tools.
Definition Tool.h:67
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition Tool.h:197
QString toolIconDir() const
returns the path to the icon directory.
Definition Tool.h:113
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211