1#include "MosaicGridTool.h"
6#include <QDoubleValidator>
7#include <QGraphicsScene>
20#include "GridGraphicsItem.h"
21#include "IException.h"
24#include "MosaicGraphicsView.h"
25#include "MosaicGridToolConfigDialog.h"
26#include "Projection.h"
27#include "TProjection.h"
28#include "MosaicSceneWidget.h"
62 connect(getWidget(), SIGNAL(projectionChanged(
Projection *)),
63 this, SLOT(onProjectionChanged()), Qt::UniqueConnection);
146 if (getWidget()->getProjection()) {
149 result = tproj->LatitudeTypeString();
165 if (getWidget()->getProjection()) {
168 result = tproj->LongitudeDomainString();
308 Projection *proj = getWidget()->getProjection();
311 PvlGroup mappingGroup(tproj->Mapping());
313 Distance equatorialRadius(tproj->EquatorialRadius(),
317 QRectF boundingRect = getWidget()->cubesBoundingRect();
319 double topLeft = 100;
320 double topRight = 100;
321 double bottomLeft = 100;
322 double bottomRight = 100;
323 bool cubeRectWorked =
true;
333 if (tproj->SetCoordinate(boundingRect.topLeft().x(), -boundingRect.topLeft().y())) {
334 topLeft = tproj->Latitude();
337 cubeRectWorked =
false;
339 if (tproj->SetCoordinate(boundingRect.topRight().x(), -boundingRect.topRight().y())) {
340 topRight = tproj->Latitude();
343 cubeRectWorked =
false;
345 if (tproj->SetCoordinate(boundingRect.bottomLeft().x(), -boundingRect.bottomLeft().y())) {
346 bottomLeft = tproj->Latitude();
349 cubeRectWorked =
false;
351 if (tproj->SetCoordinate(boundingRect.bottomRight().x(),
352 -boundingRect.bottomRight().y())) {
353 bottomRight = tproj->Latitude();
356 cubeRectWorked =
false;
359 if (cubeRectWorked) {
361 std::min(bottomLeft, bottomRight)), mappingGroup,
364 std::max(bottomLeft, bottomRight)), mappingGroup,
367 if (tproj->SetUniversalGround(-90.0, 0) &&
368 boundingRect.contains(QPointF(tproj->XCoord(), -tproj->YCoord()))) {
372 if (tproj->SetUniversalGround(90.0, 0) &&
373 boundingRect.contains(QPointF(tproj->XCoord(), -tproj->YCoord()))) {
382 static Projection *lastProjWithThisError = NULL;
384 if (proj != lastProjWithThisError) {
385 lastProjWithThisError = proj;
386 QMessageBox::warning(NULL, tr(
"Latitude Extent Failure"),
387 tr(
"<p/>Could not extract latitude extents from the cubes.<br/>"
388 "<br/>The option <strong>\"Compute From Images\"</strong> "
389 "will default to using the <strong>Manual</strong> option "
390 "for latitude extents with a range of -90 to 90."));
432 Projection *proj = getWidget()->getProjection();
435 QRectF boundingRect = getWidget()->cubesBoundingRect();
439 double bottomLeft = 0;
440 double bottomRight = 0;
441 bool cubeRectWorked =
true;
451 if (tproj->SetCoordinate(boundingRect.topLeft().x(), -boundingRect.topLeft().y())) {
453 topLeft = tproj->Longitude();
456 cubeRectWorked =
false;
458 if (tproj->SetCoordinate(boundingRect.topRight().x(), -boundingRect.topRight().y())) {
459 topRight = tproj->Longitude();
462 cubeRectWorked =
false;
464 if (tproj->SetCoordinate(boundingRect.bottomLeft().x(), -boundingRect.bottomLeft().y())) {
465 bottomLeft = tproj->Longitude();
468 cubeRectWorked =
false;
470 if (tproj->SetCoordinate(boundingRect.bottomRight().x(),
471 -boundingRect.bottomRight().y())) {
472 bottomRight = tproj->Longitude();
475 cubeRectWorked =
false;
478 if (cubeRectWorked) {
480 std::min(bottomLeft, bottomRight)),
483 std::max(bottomLeft, bottomRight)),
503 static Projection *lastProjWithThisError = NULL;
505 if (proj != lastProjWithThisError) {
506 lastProjWithThisError = proj;
507 QMessageBox::warning(NULL, tr(
"Longitude Extent Failure"),
508 tr(
"<p/>Could not extract longitude extents from the cubes.<br/>"
509 "<br/>The option <strong>\"Compute From Images\"</strong> "
510 "will default to using the <strong>Manual</strong> option "
511 "for longitude extents with a range of 0 to 360."));
561 Projection *proj = getWidget()->getProjection();
565 tproj->EquatorialRadius(),
570 if (obj[
"BaseLatitude"][0] !=
"Null")
574 if (obj[
"BaseLongitude"][0] !=
"Null")
577 if (obj[
"LatitudeIncrement"][0] !=
"Null")
580 if (obj[
"LongitudeIncrement"][0] !=
"Null")
583 if (obj.hasKeyword(
"LatitudeExtentType")) {
584 if (obj[
"LatitudeExtentType"][0] !=
"Null")
588 if (obj.hasKeyword(
"MinimumLatitude")) {
589 if (obj[
"MinimumLatitude"][0] !=
"Null")
594 if (obj.hasKeyword(
"MaximumLatitude")) {
595 if (obj[
"MaximumLatitude"][0] !=
"Null")
600 if (obj.hasKeyword(
"LongitudeExtentType")) {
601 if (obj[
"LongitudeExtentType"][0] !=
"Null")
605 if (obj.hasKeyword(
"MinimumLongitude")) {
606 if (obj[
"MinimumLongitude"][0] !=
"Null")
610 if (obj.hasKeyword(
"MaximumLongitude")) {
611 if (obj[
"MaximumLongitude"][0] !=
"Null")
615 if (obj[
"Density"][0] !=
"Null")
619 if (obj.hasKeyword(
"CheckTheBoxes")) {
620 if (obj[
"CheckTheBoxes"][0] !=
"Null") {
625 if(
toBool(obj[
"Visible"][0])) {
638 return "MosaicGridTool";
673 Longitude MosaicGridTool::domainMinLon() {
676 if (getWidget() && getWidget()->getProjection()) {
679 if (tproj->Has360Domain()) {
691 Longitude MosaicGridTool::domainMaxLon() {
694 if (getWidget() && getWidget()->getProjection()) {
696 TProjection *tproj = (TProjection *) getWidget()->getProjection();
697 if (tproj->Has360Domain()) {
718 FileName(QString(
"$HOME/.Isis/%1/mosaicSceneGridTool.config")
719 .arg(QApplication::applicationName())).expanded(),
720 QSettings::NativeFormat);
721 settings.setValue(
"autoGrid", draw);
723 Projection *proj = getWidget()->getProjection();
726 QRectF boundingRect = getWidget()->cubesBoundingRect();
728 if (!boundingRect.isNull()) {
735 if (tproj->Mapping()[
"LatitudeType"][0] ==
"Planetographic") {
758 double latOffsetMultiplier = pow(10, qFloor(log10(latRange) - 1));
759 double lonOffsetMultiplier = pow(10, qFloor(log10(lonRange) - 1));
761 double idealLatInc = latRange / 10.0;
762 double idealLonInc = lonRange / 10.0;
764 double roundedLatInc = qRound(idealLatInc / latOffsetMultiplier) * latOffsetMultiplier ;
765 double roundedLonInc = qRound(idealLonInc / lonOffsetMultiplier) * lonOffsetMultiplier ;
782 if(m_gridItem != NULL) {
783 disconnect(getWidget(), SIGNAL(projectionChanged(
Projection *)),
786 getWidget()->getScene()->removeItem(m_gridItem);
800 qobject_cast<QWidget *>(parent()));
801 configDialog->setAttribute(Qt::WA_DeleteOnClose);
802 configDialog->show();
810 void MosaicGridTool::onProjectionChanged() {
813 PvlGroup mappingGroup(tproj->Mapping());
841 if(m_gridItem != NULL) {
851 if (!getWidget()->getProjection()) {
852 QString msg =
"Please set the mosaic scene's projection before trying to "
853 "draw a grid. This means either open a cube (a projection "
854 "will be calculated) or set the projection explicitly";
855 QMessageBox::warning(NULL, tr(
"Grid Tool Requires Projection"), msg);
864 connect(getWidget(), SIGNAL(projectionChanged(
Projection *)),
865 this, SLOT(
drawGrid()), Qt::UniqueConnection);
867 connect(getWidget(), SIGNAL(cubesChanged()),
870 if (m_gridItem != NULL)
871 getWidget()->getScene()->addItem(m_gridItem);
904 emit boundingRectChanged();
908 getWidget()->getView()->update();
909 QApplication::processEvents();
923 FileName(QString(
"$HOME/.Isis/%1/mosaicSceneGridTool.config")
924 .arg(QApplication::applicationName())).expanded(),
925 QSettings::NativeFormat);
927 bool drawAuto = settings.value(
"autoGrid",
true).toBool();
967 m_action->setIcon(
getIcon(
"grid.png"));
968 m_action->setToolTip(
"Grid (g)");
969 m_action->setShortcut(Qt::Key_G);
971 "<b>Function:</b> Superimpose a map grid over the area of displayed "
972 "footprints in the 'mosaic scene.'<br><br>"
973 "This tool allows you to overlay a ground grid onto the mosaic scene. "
974 "The inputs are standard ground grid parameters and a grid density."
975 "<p><b>Shortcut:</b> g</p> ";
976 m_action->setWhatsThis(text);
990 QHBoxLayout *actionLayout =
new QHBoxLayout();
992 QString autoGridWhatsThis =
993 "Draws a grid based on the current lat/lon extents (from the cubes, map, or user).";
1003 QPushButton *optionsButton =
new QPushButton(
"Grid Options");
1004 optionsButton->setWhatsThis(
"Opens a dialog box that has the options to change the base"
1005 " latitude, base longitude, latitude increment, longitude"
1006 " increment, and grid density.");
1007 connect(optionsButton, SIGNAL(clicked()),
this, SLOT(
configure()));
1008 actionLayout->addWidget(optionsButton);
1010 QString drawGridWhatsThis =
1011 "Draws a grid based on the current lat/lon extents (from the cubes, map, or user).";
1012 QLabel *drawGridLabel =
new QLabel(
"Show Grid");
1013 drawGridLabel->setWhatsThis(drawGridWhatsThis);
1017 actionLayout->addWidget(drawGridLabel);
1020 connect(
this, SIGNAL(activated(
bool)),
this, SLOT(
onToolOpen(
bool)));
1022 actionLayout->addStretch(1);
1023 actionLayout->setMargin(0);
1026 toolBarWidget->setLayout(actionLayout);
1028 return toolBarWidget;
Defines an angle and provides unit conversions.
double degrees() const
Get the angle in units of Degrees.
@ Degrees
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
Distance measurement, usually in meters.
@ Meters
The distance is being specified in meters.
File name manipulation and expansion.
The visual display of the find point.
This class is designed to encapsulate the concept of a Latitude.
@ Planetocentric
This is the universal (and default) latitude coordinate system.
double planetographic(Angle::Units units=Angle::Radians) const
Get the latitude in the planetographic coordinate system.
This class is designed to encapsulate the concept of a Longitude.
Base class for Map Projections.
@ Triaxial
These projections are used to map triaxial and irregular-shaped bodies.
Contains multiple PvlContainers.
A single keyword-value pair.
Contains Pvl Groups and Pvl Objects.
Base class for Map TProjections.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
int toInt(const QString &string)
Global function to convert from a string to an integer.
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
double toDouble(const QString &string)
Global function to convert from a string to a double.