Isis 3 Programmer Reference
MosaicFindTool.cpp
1 #include "MosaicFindTool.h"
2 
3 #include <QDialog>
4 #include <QDoubleValidator>
5 #include <QGraphicsEllipseItem>
6 #include <QGraphicsScene>
7 #include <QGridLayout>
8 #include <QLabel>
9 #include <QLineEdit>
10 #include <QMenu>
11 #include <QMessageBox>
12 #include <QPushButton>
13 
14 #include "IString.h"
15 #include "FindSpotGraphicsItem.h"
16 #include "MosaicGraphicsView.h"
17 #include "MosaicSceneWidget.h"
18 #include "Projection.h"
19 #include "TProjection.h"
20 #include "PvlKeyword.h"
21 #include "PvlObject.h"
22 
23 namespace Isis {
31  MosaicTool(scene) {
32  p_findSpot = NULL;
33  }
34 
35 
40  void MosaicFindTool::getUserGroundPoint() {
41 
42  //Validate latitude value
43  QString latitude = p_latLineEdit->text();
44  int cursorPos = 0;
45  QValidator::State validLat =
46  p_latLineEdit->validator()->validate(latitude, cursorPos);
47  if(validLat != QValidator::Acceptable) {
48  QMessageBox::warning(getWidget(), "Error",
49  "Latitude value must be in the range -90 to 90",
50  QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
51  return;
52  }
53 
54  //Validate longitude value
55  QString longitude = p_lonLineEdit->text();
56  QValidator::State validLon =
57  p_lonLineEdit->validator()->validate(longitude, cursorPos);
58  if(validLon != QValidator::Acceptable) {
59  QMessageBox::warning(getWidget(), "Error",
60  "Longitude value must be a double",
61  QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
62  return;
63  }
64 
65  double lat = IString(latitude.toStdString()).ToDouble();
66  double lon = IString(longitude.toStdString()).ToDouble();
67 
68  Projection *projection = getWidget()->getProjection();
69  Projection::ProjectionType ptype = projection->projectionType();
70 
71  if (projection && ptype == Projection::Triaxial) {
72  TProjection *tproj = (TProjection *) projection;
73  if (tproj->SetGround(lat, lon)) {
74  QPointF scenePos(projection->XCoord(), -1 * projection->YCoord());
75  QRectF sceneRect(getWidget()->getView()->sceneRect());
76 
77  if (sceneRect.contains(scenePos)) {
78  if(p_findSpot != NULL) {
79  clearPoint();
80  }
81 
82  p_findSpot = new FindSpotGraphicsItem(scenePos, getWidget());
83 
84  getWidget()->getScene()->addItem(p_findSpot);
85  getWidget()->getView()->centerOn(scenePos);
86  }
87  else {
88  QString message = "Lat/Lon not within this view.";
89  QMessageBox::information(getWidget(), "Point Not Found",
90  message, QMessageBox::Ok);
91  }
92  }
93  }
94  }
95 
96 
106  p_action = new QAction(this);
107  p_action->setIcon(getIcon("find.png"));
108  p_action->setToolTip("Find (f)");
109  p_action->setShortcut(Qt::Key_F);
110  QString text =
111  "<b>Function:</b> Find a specific latitude/longitude on the mosaic "
112  "scene.<br><br>"
113  "This tool allows you to type in a latitude and longitude, in the "
114  "projection's native units, and that point will be centered and given "
115  "a red dot on the mosaic scene. Alternatively, you can <b>click</b> on "
116  "the mosaic scene and it will give you the latitude and longitude values "
117  "along with drawing the red dot."
118  "<p><b>Shortcut:</b> f</p> ";
119  p_action->setWhatsThis(text);
120  return p_action;
121  }
122 
123 
125  p_latLineEdit = new QLineEdit();
126  p_latLineEdit->setValidator(new QDoubleValidator(-90.0, 90.0, 99, this));
127 
128  p_lonLineEdit = new QLineEdit();
129  p_lonLineEdit->setValidator(new QDoubleValidator(this));
130 
131  QLabel *latLabel = new QLabel("Latitude");
132  QLabel *lonLabel = new QLabel("Longitude");
133 
134  // Create the action buttons
135  QPushButton *okButton = new QPushButton("Go to Point");
136  connect(okButton, SIGNAL(clicked()), this, SLOT(getUserGroundPoint()));
137 
138  QPushButton *clearButton = new QPushButton("Clear Point");
139  connect(clearButton, SIGNAL(clicked()), this, SLOT(clearPoint()));
140 
141  // Put the buttons in a horizontal orientation
142  QHBoxLayout *actionLayout = new QHBoxLayout();
143  actionLayout->addWidget(latLabel);
144  actionLayout->addWidget(p_latLineEdit);
145  actionLayout->addWidget(lonLabel);
146  actionLayout->addWidget(p_lonLineEdit);
147  actionLayout->addWidget(okButton);
148  actionLayout->addWidget(clearButton);
149  actionLayout->addStretch(1);
150  actionLayout->setMargin(0);
151 
152  QWidget *toolBarWidget = new QWidget;
153  toolBarWidget->setLayout(actionLayout);
154 
155  return toolBarWidget;
156  }
157 
158 
166 
167  }
168 
169 
170  PvlObject MosaicFindTool::toPvl() const {
171  PvlObject obj(projectPvlObjectName());
172 
173  obj += PvlKeyword("Latitude", p_latLineEdit->text());
174  obj += PvlKeyword("Longitude", p_lonLineEdit->text());
175  obj += PvlKeyword("Visible", toString((int)(p_findSpot != NULL)));
176 
177  return obj;
178  }
179 
180 
181  void MosaicFindTool::fromPvl(const PvlObject &obj) {
182  p_latLineEdit->setText(obj["Latitude"][0]);
183  p_lonLineEdit->setText(obj["Longitude"][0]);
184  if(toBool(obj["Visible"][0])) {
185  getUserGroundPoint();
186  }
187  }
188 
189 
190  QString MosaicFindTool::projectPvlObjectName() const {
191  return "MosaicFindTool";
192  }
193 
194 
204  QWidget *widget = new QWidget();
205  return widget;
206  }
207 
208 
209  void MosaicFindTool::mouseButtonRelease(QPointF mouseLoc, Qt::MouseButton s) {
210  if(!isActive())
211  return;
212 
213  if(s == Qt::LeftButton) {
214  Projection *proj = getWidget()->getProjection();
216 
217  if (ptype == Projection::Triaxial) {
218  TProjection *tproj = (TProjection *) proj;
219  if (tproj && getWidget()->getView()->sceneRect().contains(mouseLoc)) {
220  if (tproj->SetCoordinate(mouseLoc.x(), -1 * mouseLoc.y())) {
221  if (p_findSpot != NULL) {
222  clearPoint();
223  }
224 
225  p_findSpot = new FindSpotGraphicsItem(mouseLoc, getWidget());
226 
227  getWidget()->getScene()->addItem(p_findSpot);
228 
229  p_latLineEdit->setText(QString::number(tproj->Latitude(), 'g', 10));
230  p_lonLineEdit->setText(QString::number(tproj->Longitude(), 'g', 10));
231  }
232  }
233  }
234  }
235  }
236 
237 
242  void MosaicFindTool::clearPoint() {
243  if(p_findSpot != NULL) {
244  getWidget()->getScene()->removeItem(p_findSpot);
245 
246  delete p_findSpot;
247  p_findSpot = NULL;
248  }
249  }
250 
251 
258  if(isActive()) {
259  }
260  }
261 
262 }
263 
QLineEdit * p_latLineEdit
Input for latitude.
ProjectionType projectionType() const
Returns an enum value for the projection type.
Definition: Projection.cpp:213
QAction * getPrimaryAction()
Adds the action to the toolpad.
This widget encompasses the entire mosaic scene.
Base class for Map TProjections.
Definition: TProjection.h:182
void addToMenu(QMenu *menu)
Adds the pan action to the given menu.
Base class for the MosaicTools.
Definition: MosaicTool.h:37
QLineEdit * p_lonLineEdit
Input for longitude.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
bool isActive() const
Returns the activeness of this toool.
Definition: MosaicTool.h:50
Base class for Map Projections.
Definition: Projection.h:171
void updateTool()
This method sets the QGraphicsView to allow the user to select mosaic items by dragging a rubber band...
double Longitude() const
This returns a longitude with correct longitude direction and domain as specified in the label object...
QWidget * getToolBarWidget()
This method returns a widget that will be put in a tool bar when the tool is activated.
QWidget * createToolBarWidget()
Creates the widget to add to the tool bar.
A single keyword-value pair.
Definition: PvlKeyword.h:98
MosaicFindTool(MosaicSceneWidget *)
MosaicFindTool constructor.
double ToDouble(const T &value)
Helper function to convert values to doubles.
Definition: HiCalUtil.h:248
QPixmap getIcon(QString iconName) const
returns the path to the icon directory.
Definition: MosaicTool.cpp:115
virtual bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
Definition: IString.cpp:53
double Latitude() const
This returns a latitude with correct latitude type as specified in the label object.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
ProjectionType
This enum defines the subclasses of Projection supported in Isis.
Definition: Projection.h:182
These projections are used to map triaxial and irregular-shaped bodies.
Definition: Projection.h:182