USGS

Isis 3.0 Object Programmers' Reference

Home

MosaicGridTool.cpp
00001 #include "MosaicGridTool.h"
00002 
00003 #include <QApplication>
00004 #include <QCheckBox>
00005 #include <QDialog>
00006 #include <QDoubleValidator>
00007 #include <QGraphicsScene>
00008 #include <QGridLayout>
00009 #include <QLabel>
00010 #include <QLineEdit>
00011 #include <QMenu>
00012 #include <QMessageBox>
00013 #include <QPointF>
00014 #include <QPushButton>
00015 #include <QtCore>
00016 
00017 #include "Angle.h"
00018 #include "Distance.h"
00019 #include "GridGraphicsItem.h"
00020 #include "IException.h"
00021 #include "Latitude.h"
00022 #include "Longitude.h"
00023 #include "MosaicGraphicsView.h"
00024 #include "MosaicGridToolConfigDialog.h"
00025 #include "Projection.h"
00026 #include "MosaicSceneWidget.h"
00027 #include "PvlObject.h"
00028 
00029 namespace Isis {
00036   MosaicGridTool::MosaicGridTool(MosaicSceneWidget *scene) :
00037       MosaicTool(scene) {
00038     m_gridItem = NULL;
00039 
00040     if (getWidget())
00041       m_previousBoundingRect = getWidget()->cubesBoundingRect();
00042 
00043     m_shouldCheckBoxes = true;
00044 
00045     m_baseLat = Latitude(0, Angle::Degrees);
00046     m_baseLon = Longitude(0, Angle::Degrees);
00047 
00048     m_latInc = Angle(45, Angle::Degrees);
00049     m_lonInc = Angle(45, Angle::Degrees);
00050 
00051     m_latExtents = Cubes;
00052     m_minLat = Latitude(-50.0, Angle::Degrees);
00053     m_maxLat = Latitude(50.0, Angle::Degrees);
00054 
00055     m_lonExtents = Cubes;
00056     m_minLon = Longitude(0.0, Angle::Degrees);
00057     m_maxLon = Longitude(360.0, Angle::Degrees);
00058     m_density = 10000;
00059 
00060   }
00061 
00062 
00068   void MosaicGridTool::addToMenu(QMenu *menu) {
00069   }
00070 
00071 
00077   bool MosaicGridTool::autoGridCheckBox() {
00078     return m_autoGridCheckBox->isChecked();
00079   }
00080 
00081 
00087   Latitude MosaicGridTool::baseLat() {
00088     return m_baseLat;
00089   }
00090 
00091 
00097   Longitude MosaicGridTool::baseLon() {
00098     return m_baseLon;
00099   }
00100 
00101 
00108   int MosaicGridTool::density() {
00109     return m_density;
00110   }
00111 
00112 
00118   Angle MosaicGridTool::latInc() {
00119     return m_latInc;
00120   }
00121 
00122 
00128   MosaicGridTool::GridExtentSource MosaicGridTool::latExtents() {
00129     return m_latExtents;
00130   }
00131 
00132 
00138   QString MosaicGridTool::latType() {
00139     QString result;
00140     if (getWidget()->getProjection())
00141       result = getWidget()->getProjection()->LatitudeTypeString();
00142     return result;
00143   }
00144 
00145 
00151   QString MosaicGridTool::lonDomain() {
00152     QString result;
00153     if (getWidget()->getProjection())
00154       result = getWidget()->getProjection()->LongitudeDomainString();
00155     return result;
00156   }
00157 
00158 
00164   MosaicGridTool::GridExtentSource MosaicGridTool::lonExtents() {
00165     return m_lonExtents;
00166   }
00167 
00168 
00174   Angle MosaicGridTool::lonInc() {
00175     return m_lonInc;
00176   }
00177 
00178 
00184   Latitude MosaicGridTool::maxLat() {
00185     return m_maxLat;
00186   }
00187 
00188 
00194   Longitude MosaicGridTool::maxLon() {
00195     return m_maxLon;
00196   }
00197 
00198 
00204   Latitude MosaicGridTool::minLat() {
00205     return m_minLat;
00206   }
00207 
00208 
00214   Longitude MosaicGridTool::minLon() {
00215     return m_minLon;
00216   }
00217 
00218 
00224   MosaicSceneWidget* MosaicGridTool::sceneWidget() {
00225     return getWidget();
00226   }
00227 
00228 
00234   bool MosaicGridTool::showGrid() {
00235     return m_drawGridCheckBox->isChecked();
00236   }
00237 
00238 
00244   void MosaicGridTool::setAutoGridCheckBox(bool checked) {
00245     m_autoGridCheckBox->setChecked(checked);
00246   }
00247 
00248 
00254   void MosaicGridTool::setBaseLat(Latitude baseLat) {
00255     m_baseLat = Latitude(baseLat);
00256   }
00257 
00258 
00264   void MosaicGridTool::setBaseLon(Longitude baseLon) {
00265     m_baseLon = baseLon;
00266   }
00267 
00268 
00274   void MosaicGridTool::setDensity(int density) {
00275     m_density = density;
00276   }
00277 
00278 
00286   void MosaicGridTool::setLatExtents(GridExtentSource source,
00287                                      Latitude minLat = Latitude(),
00288                                      Latitude maxLat = Latitude()) {
00289     m_latExtents = source;
00290 
00291     Projection *proj = getWidget()->getProjection();
00292     if (proj) {
00293       PvlGroup mappingGroup(proj->Mapping());
00294 
00295       Distance equatorialRadius(proj->EquatorialRadius(),
00296                                 Distance::Meters);
00297       Distance polarRadius(proj->PolarRadius(), Distance::Meters);
00298 
00299       QRectF boundingRect = getWidget()->cubesBoundingRect();
00300 
00301       double topLeft = 100;
00302       double topRight = 100;
00303       double bottomLeft = 100;
00304       double bottomRight = 100;
00305       bool cubeRectWorked = true;
00306 
00307       switch (source) {
00308 
00309         case Map:
00310           m_minLat = Latitude(proj->MinimumLatitude(), mappingGroup, Angle::Degrees);
00311           m_maxLat = Latitude(proj->MaximumLatitude(), mappingGroup,  Angle::Degrees);
00312           break;
00313 
00314         case Cubes:
00315           if (proj->SetCoordinate(boundingRect.topLeft().x(), -boundingRect.topLeft().y())) {
00316             topLeft = proj->Latitude();
00317           }
00318           else {
00319             cubeRectWorked = false;
00320           }
00321           if (proj->SetCoordinate(boundingRect.topRight().x(), -boundingRect.topRight().y())) {
00322             topRight = proj->Latitude();
00323           }
00324           else {
00325             cubeRectWorked = false;
00326           }
00327           if (proj->SetCoordinate(boundingRect.bottomLeft().x(), -boundingRect.bottomLeft().y())) {
00328             bottomLeft = proj->Latitude();
00329           }
00330           else {
00331             cubeRectWorked = false;
00332           }
00333           if (proj->SetCoordinate(boundingRect.bottomRight().x(),
00334               -boundingRect.bottomRight().y())) {
00335             bottomRight = proj->Latitude();
00336           }
00337           else {
00338             cubeRectWorked = false;
00339           }
00340 
00341           if (cubeRectWorked) {
00342             m_minLat = Latitude(std::min(std::min(topLeft, topRight),
00343                                         std::min(bottomLeft, bottomRight)), mappingGroup,
00344                                 Angle::Degrees);
00345             m_maxLat = Latitude(std::max(std::max(topLeft, topRight),
00346                                         std::max(bottomLeft, bottomRight)), mappingGroup,
00347                                 Angle::Degrees);
00348 
00349             if (proj->SetUniversalGround(-90.0, 0) &&
00350                 boundingRect.contains(QPointF(proj->XCoord(), -proj->YCoord()))) {
00351               m_minLat = Latitude(-90.0, mappingGroup, Angle::Degrees);
00352             }
00353 
00354             if (proj->SetUniversalGround(90.0, 0) &&
00355                 boundingRect.contains(QPointF(proj->XCoord(), -proj->YCoord()))) {
00356               m_maxLat = Latitude(90.0, mappingGroup, Angle::Degrees);
00357             }
00358           }
00359           else {
00360             m_minLat = Latitude(-90, mappingGroup, Angle::Degrees);
00361             m_maxLat = Latitude(90, mappingGroup, Angle::Degrees);
00362             m_latExtents = Manual;
00363 
00364             static Projection *lastProjWithThisError = NULL;
00365 
00366             if (proj != lastProjWithThisError) {
00367               lastProjWithThisError = proj;
00368               QMessageBox::warning(NULL, tr("Latitude Extent Failure"),
00369                                    tr("<p/>Could not extract latitude extents from the cubes.<br/>"
00370                                       "<br/>The option <strong>\"Compute From Images\"</strong> "
00371                                       "will default to using the <strong>Manual</strong> option "
00372                                       "for latitude extents with a range of -90 to 90."));
00373             }
00374           }
00375           break;
00376 
00377         case Manual:
00378           m_minLat = Latitude(minLat);
00379           m_maxLat = Latitude(maxLat);
00380           break;
00381 
00382         default:
00383           m_minLat = Latitude(proj->MinimumLatitude(), mappingGroup, Angle::Degrees);
00384           m_maxLat = Latitude(proj->MaximumLatitude(), mappingGroup, Angle::Degrees);
00385       }
00386     }
00387   }
00388 
00389 
00395   void MosaicGridTool::setLatInc(Angle latInc) {
00396     if (latInc > Angle(0.0, Angle::Degrees)) {
00397       m_latInc = latInc;
00398     }
00399   }
00400 
00401 
00409   void MosaicGridTool::setLonExtents(GridExtentSource source,
00410                                      Longitude minLon = Longitude(),
00411                                      Longitude maxLon = Longitude()) {
00412     m_lonExtents = source;
00413 
00414     Projection *proj = getWidget()->getProjection();
00415     if (proj) {
00416       QRectF boundingRect = getWidget()->cubesBoundingRect();
00417 
00418       double topLeft = 0;
00419       double topRight = 0;
00420       double bottomLeft = 0;
00421       double bottomRight = 0;
00422       bool cubeRectWorked = true;
00423 
00424       Longitude zeroLon(0.0, Angle::Degrees);
00425       Longitude threeSixtyLon(360.0, Angle::Degrees);
00426 
00427       switch (source) {
00428 
00429         case Map:
00430           m_minLon = Longitude(proj->MinimumLongitude(), Angle::Degrees);
00431           m_maxLon = Longitude(proj->MaximumLongitude(), Angle::Degrees);
00432           break;
00433 
00434         case Cubes:
00435           if (proj->SetCoordinate(boundingRect.topLeft().x(), -boundingRect.topLeft().y())) {
00436             topLeft = proj->Longitude();
00437           }
00438           else {
00439             cubeRectWorked = false;
00440           }
00441           if (proj->SetCoordinate(boundingRect.topRight().x(), -boundingRect.topRight().y())) {
00442             topRight = proj->Longitude();
00443           }
00444           else {
00445             cubeRectWorked = false;
00446           }
00447           if (proj->SetCoordinate(boundingRect.bottomLeft().x(), -boundingRect.bottomLeft().y())) {
00448             bottomLeft = proj->Longitude();
00449           }
00450           else {
00451             cubeRectWorked = false;
00452           }
00453           if (proj->SetCoordinate(boundingRect.bottomRight().x(),
00454               -boundingRect.bottomRight().y())) {
00455             bottomRight = proj->Longitude();
00456           }
00457           else {
00458             cubeRectWorked = false;
00459           }
00460 
00461           if (cubeRectWorked) {
00462             m_minLon = Longitude(std::min(std::min(topLeft, topRight),
00463                                           std::min(bottomLeft, bottomRight)),
00464                                 Angle::Degrees);
00465             m_maxLon = Longitude(std::max(std::max(topLeft, topRight),
00466                                           std::max(bottomLeft, bottomRight)),
00467                                 Angle::Degrees);
00468             if (m_minLon < zeroLon) {
00469               m_minLon = zeroLon;
00470             }
00471             if (m_maxLon > threeSixtyLon) {
00472               m_maxLon = threeSixtyLon;
00473             }
00474             //Draw 0-360 if the pole is in the cubes' bounding rectangle.
00475             if (m_minLat == Angle(-90.0, Angle::Degrees) ||
00476                 m_maxLat == Angle(90.0, Angle::Degrees)) {
00477               m_minLon = zeroLon;
00478               m_maxLon = threeSixtyLon;
00479             }
00480           }
00481           else {
00482             m_minLon = zeroLon;
00483             m_maxLon = threeSixtyLon;
00484             m_lonExtents = Manual;
00485 
00486             static Projection *lastProjWithThisError = NULL;
00487 
00488             if (proj != lastProjWithThisError) {
00489               lastProjWithThisError = proj;
00490               QMessageBox::warning(NULL, tr("Longitude Extent Failure"),
00491                                    tr("<p/>Could not extract longitude extents from the cubes.<br/>"
00492                                       "<br/>The option <strong>\"Compute From Images\"</strong> "
00493                                       "will default to using the <strong>Manual</strong> option "
00494                                       "for longitude extents with a range of 0 to 360."));
00495             }
00496           }
00497           break;
00498 
00499         case Manual:
00500           m_minLon = minLon;
00501           m_maxLon = maxLon;
00502           break;
00503 
00504         default:
00505           m_minLon = Longitude(proj->MinimumLongitude(), Angle::Degrees);
00506           m_maxLon = Longitude(proj->MaximumLongitude(), Angle::Degrees);
00507       }
00508     }
00509   }
00510 
00511 
00517   void MosaicGridTool::setLonInc(Angle lonInc) {
00518     Angle lonRange = m_maxLon - m_minLon;
00519 
00520     if (lonInc > lonRange)
00521       m_lonInc = lonRange;
00522     else if (lonInc > Angle(0.0, Angle::Degrees))
00523       m_lonInc = lonInc;
00524   }
00525 
00526 
00532   void MosaicGridTool::setShowGrid(bool show) {
00533     m_drawGridCheckBox->setChecked(show);
00534   }
00535 
00536 
00542   void MosaicGridTool::fromPvl(const PvlObject &obj) {
00543 
00544     if (getWidget()->getProjection()) {
00545       Distance equatorialRadius(
00546           getWidget()->getProjection()->EquatorialRadius(),
00547           Distance::Meters);
00548       Distance polarRadius(
00549           getWidget()->getProjection()->PolarRadius(),
00550           Distance::Meters);
00551 
00552       if (obj["BaseLatitude"][0] != "Null")
00553         m_baseLat = Latitude(toDouble(obj["BaseLatitude"][0]), equatorialRadius, polarRadius,
00554                             Latitude::Planetocentric, Angle::Degrees);
00555 
00556       if (obj["BaseLongitude"][0] != "Null")
00557         m_baseLon = Longitude(toDouble(obj["BaseLongitude"][0]), Angle::Degrees);
00558 
00559       if (obj["LatitudeIncrement"][0] != "Null")
00560         m_latInc = Angle(toDouble(obj["LatitudeIncrement"][0]), Angle::Degrees);
00561 
00562       if (obj["LongitudeIncrement"][0] != "Null")
00563         m_lonInc = Angle(toDouble(obj["LongitudeIncrement"][0]), Angle::Degrees);
00564 
00565       if (obj.HasKeyword("LatitudeExtentType")) {
00566         if (obj["LatitudeExtentType"][0] != "Null")
00567           m_latExtents = (GridExtentSource)toInt(obj["LatitudeExtentType"][0]);
00568       }
00569 
00570       if (obj.HasKeyword("MinimumLatitude")) {
00571         if (obj["MinimumLatitude"][0] != "Null")
00572           m_minLat = Latitude(toDouble(obj["MinimumLatitude"][0]), equatorialRadius, polarRadius,
00573                               Latitude::Planetocentric, Angle::Degrees);
00574       }
00575 
00576       if (obj.HasKeyword("MaximumLatitude")) {
00577         if (obj["MaximumLatitude"][0] != "Null")
00578           m_maxLat = Latitude(toDouble(obj["MaximumLatitude"][0]), equatorialRadius, polarRadius,
00579                               Latitude::Planetocentric, Angle::Degrees);
00580       }
00581 
00582       if (obj.HasKeyword("LongitudeExtentType")) {
00583         if (obj["LongitudeExtentType"][0] != "Null")
00584           m_lonExtents = (GridExtentSource)toInt(obj["LongitudeExtentType"][0]);
00585       }
00586 
00587       if (obj.HasKeyword("MinimumLongitude")) {
00588         if (obj["MinimumLongitude"][0] != "Null")
00589           m_minLon = Longitude(toDouble(obj["MinimumLongitude"][0]), Angle::Degrees);
00590       }
00591 
00592       if (obj.HasKeyword("MaximumLongitude")) {
00593         if (obj["MaximumLongitude"][0] != "Null")
00594           m_maxLon = Longitude(toDouble(obj["MaximumLongitude"][0]), Angle::Degrees);
00595       }
00596 
00597       if (obj["Density"][0] != "Null")
00598         m_density = toDouble(obj["Density"][0]);
00599 
00600 
00601       if (obj.HasKeyword("CheckTheBoxes")) {
00602         if (obj["CheckTheBoxes"][0] != "Null") {
00603           m_shouldCheckBoxes = (obj["CheckTheBoxes"][0] == "true");
00604         }
00605       }
00606 
00607       if(toBool(obj["Visible"][0])) {
00608         drawGrid();
00609       }
00610     }
00611   }
00612 
00613 
00619   QString MosaicGridTool::projectPvlObjectName() const {
00620     return "MosaicGridTool";
00621   }
00622 
00623 
00629   PvlObject MosaicGridTool::toPvl() const {
00630     PvlObject obj(projectPvlObjectName());
00631 
00632     obj += PvlKeyword("ShouldCheckBoxes", toString((int)m_shouldCheckBoxes));
00633 
00634     obj += PvlKeyword("BaseLatitude", toString(m_baseLat.degrees()));
00635     obj += PvlKeyword("BaseLongitude", toString(m_baseLon.degrees()));
00636 
00637     obj += PvlKeyword("LatitudeIncrement", toString(m_latInc.degrees()));
00638     obj += PvlKeyword("LongitudeIncrement", toString(m_lonInc.degrees()));
00639 
00640     obj += PvlKeyword("LatitudeExtentType", toString(m_latExtents));
00641     obj += PvlKeyword("MaximumLatitude", toString(m_maxLat.degrees()));
00642     obj += PvlKeyword("MinimumLongitude", toString(m_minLon.degrees()));
00643 
00644     obj += PvlKeyword("LongitudeExtentType", toString(m_lonExtents));
00645     obj += PvlKeyword("MinimumLatitude", toString(m_minLat.degrees()));
00646     obj += PvlKeyword("MaximumLongitude", toString(m_maxLon.degrees()));
00647 
00648     obj += PvlKeyword("Density", toString(m_density));
00649     obj += PvlKeyword("Visible", toString((int)(m_gridItem != NULL)));
00650 
00651     return obj;
00652   }
00653 
00654 
00660   void MosaicGridTool::autoGrid(bool draw) {
00661     if (draw && getWidget()->getProjection()) {
00662 
00663       QRectF boundingRect = getWidget()->cubesBoundingRect();
00664 
00665       if (!boundingRect.isNull()) {
00666 
00667         setLatExtents(m_latExtents, m_minLat, m_maxLat);
00668         setLonExtents(m_lonExtents, m_minLon, m_maxLon);
00669 
00670         double latRange = m_maxLat.degrees() - m_minLat.degrees();
00671 
00672         if (getWidget()->getProjection()->Mapping()["LatitudeType"][0] == "Planetographic") {
00673           latRange =
00674               m_maxLat.planetographic(Angle::Degrees) - m_minLat.planetographic(Angle::Degrees);
00675         }
00676 
00677         double lonRange = m_maxLon.degrees() - m_minLon.degrees();
00678 
00679         /*
00680          * To calculate the lat/lon increments we divide the range by 10 (so we end up
00681          *   with about 10 sections in the range, whatever the extents may be) and we
00682          *   divide that by 1, 10, 100,... depending on the log10 of the range. We then
00683          *   round this value and multiply but the same number that we divided  by. This
00684          *   gives us a clear, sensible value for an increment.
00685          *
00686          *   Example Increments:
00687          *     Range = 1    --> Inc = .1
00688          *     Range = 10   --> Inc = 1
00689          *     Range = 100  --> Inc = 10
00690          *     Range = 5000 --> Inc = 500
00691          *
00692          *   inc = round[(range/10) / 10^floor(log(range) - 1)] * 10^floor(log(range) - 1)
00693          */
00694 
00695         double latOffsetMultiplier = pow(10, qFloor(log10(latRange) - 1));
00696         double lonOffsetMultiplier = pow(10, qFloor(log10(lonRange) - 1));
00697 
00698         double idealLatInc = latRange / 10.0;
00699         double idealLonInc = lonRange / 10.0;
00700 
00701         double roundedLatInc = qRound(idealLatInc / latOffsetMultiplier) * latOffsetMultiplier ;
00702         double roundedLonInc = qRound(idealLonInc / lonOffsetMultiplier) * lonOffsetMultiplier ;
00703 
00704         m_latInc = Angle(roundedLatInc, Angle::Degrees);
00705         m_lonInc = Angle(roundedLonInc, Angle::Degrees);
00706 
00707         m_previousBoundingRect = boundingRect;
00708 
00709         drawGrid();
00710       }
00711     }
00712   }
00713 
00714 
00718   void MosaicGridTool::clearGrid() {
00719     if(m_gridItem != NULL) {
00720       disconnect(getWidget(), SIGNAL(projectionChanged(Projection *)),
00721                  this, SLOT(drawGrid()));
00722 
00723       getWidget()->getScene()->removeItem(m_gridItem);
00724 
00725       delete m_gridItem;
00726       m_gridItem = NULL;
00727     }
00728   }
00729 
00730 
00734   void MosaicGridTool::configure() {
00735     MosaicGridToolConfigDialog *configDialog =
00736         new MosaicGridToolConfigDialog(this,
00737                                          qobject_cast<QWidget *>(parent()));
00738     configDialog->setAttribute(Qt::WA_DeleteOnClose);
00739     configDialog->show();
00740   }
00741 
00742 
00748   void MosaicGridTool::drawGrid() {
00749     if(m_gridItem != NULL) {
00750       m_drawGridCheckBox->setChecked(false);
00751       m_autoGridCheckBox->setEnabled(true);
00752       m_autoGridLabel->setEnabled(true);
00753     }
00754 
00755     m_drawGridCheckBox->blockSignals(true);
00756     m_drawGridCheckBox->setChecked(true);
00757     m_drawGridCheckBox->blockSignals(false);
00758 
00759     if (!getWidget()->getProjection()) {
00760       QString msg = "Please set the mosaic scene's projection before trying to "
00761                     "draw a grid. This means either open a cube (a projection "
00762                     "will be calculated) or set the projection explicitly";
00763       QMessageBox::warning(NULL, tr("Grid Tool Requires Projection"), msg);
00764     }
00765 
00766     if (m_minLon.degrees() < m_maxLon.degrees() && m_minLat.degrees() < m_maxLat.degrees()) {
00767       m_gridItem = new GridGraphicsItem(m_baseLat, m_baseLon, m_latInc, m_lonInc, getWidget(),
00768                                         m_density, m_minLat, m_maxLat, m_minLon, m_maxLon);
00769     }
00770 
00771     connect(getWidget(), SIGNAL(projectionChanged(Projection *)),
00772             this, SLOT(drawGrid()), Qt::UniqueConnection);
00773 
00774     connect(getWidget(), SIGNAL(cubesChanged()),
00775             this, SLOT(onCubesChanged()));
00776 
00777     if (m_gridItem != NULL)
00778       getWidget()->getScene()->addItem(m_gridItem);
00779   }
00780 
00781 
00787   void MosaicGridTool::drawGrid(bool draw) {
00788     if (draw) {
00789       m_autoGridLabel->setEnabled(true);
00790       m_autoGridCheckBox->setEnabled(true);
00791       drawGrid();
00792     }
00793     else {
00794       clearGrid();
00795       m_autoGridLabel->setEnabled(false);
00796       m_autoGridCheckBox->setEnabled(false);
00797     }
00798   }
00799 
00800 
00808   void MosaicGridTool::onCubesChanged() {
00809     if (m_previousBoundingRect != getWidget()->cubesBoundingRect()) {
00810       emit boundingRectChanged();
00811       autoGrid(m_autoGridCheckBox->isChecked());
00812 
00813       //Make sure that the grid is updated the first time new cubes are opened.
00814       getWidget()->getView()->update();
00815       QApplication::processEvents();
00816     }
00817   }
00818 
00819 
00826   void MosaicGridTool::onToolOpen(bool check) {
00827     if (check && m_shouldCheckBoxes) {
00828       m_autoGridCheckBox->setChecked(true);
00829       m_autoGridCheckBox->setEnabled(true);
00830       m_autoGridLabel->setEnabled(true);
00831       m_drawGridCheckBox->setChecked(true);
00832       m_shouldCheckBoxes = false;
00833     }
00834   }
00835 
00836 
00844   QWidget *MosaicGridTool::createToolBarWidget() {
00845     QWidget *widget = new QWidget();
00846     return widget;
00847   }
00848 
00849 
00857   QAction *MosaicGridTool::getPrimaryAction() {
00858     m_action = new QAction(this);
00859     m_action->setIcon(getIcon("grid.png"));
00860     m_action->setToolTip("Grid (g)");
00861     m_action->setShortcut(Qt::Key_G);
00862     QString text  =
00863       "<b>Function:</b>  Superimpose a map grid over the area of displayed "
00864       "footprints in the 'mosaic scene.'<br><br>"
00865       "This tool allows you to overlay a ground grid onto the mosaic scene. "
00866       "The inputs are standard ground grid parameters and a grid density."
00867       "<p><b>Shortcut:</b>  g</p> ";
00868     m_action->setWhatsThis(text);
00869     return m_action;
00870   }
00871 
00872 
00878   QWidget *MosaicGridTool::getToolBarWidget() {
00879 
00880     m_previousBoundingRect =  getWidget()->cubesBoundingRect();
00881 
00882     QHBoxLayout *actionLayout = new QHBoxLayout();
00883 
00884     QString autoGridWhatsThis =
00885         "Draws a grid based on the current lat/lon extents (from the cubes, map, or user).";
00886     m_autoGridLabel = new QLabel("Auto Grid");
00887     m_autoGridLabel->setWhatsThis(autoGridWhatsThis);
00888     m_autoGridCheckBox = new QCheckBox;
00889     m_autoGridCheckBox->setWhatsThis(autoGridWhatsThis);
00890     connect(m_autoGridCheckBox, SIGNAL(toggled(bool)), this, SLOT(autoGrid(bool)));
00891     actionLayout->addWidget(m_autoGridLabel);
00892     actionLayout->addWidget(m_autoGridCheckBox);
00893 
00894     // Create the action buttons
00895     QPushButton *optionsButton = new QPushButton("Grid Options");
00896     optionsButton->setWhatsThis("Opens a dialog box that has the options to change the base"
00897                                 " latitude, base longitude, latitude increment, longitude"
00898                                 " increment, and grid density.");
00899     connect(optionsButton, SIGNAL(clicked()), this, SLOT(configure()));
00900     actionLayout->addWidget(optionsButton);
00901 
00902     QString drawGridWhatsThis =
00903         "Draws a grid based on the current lat/lon extents (from the cubes, map, or user).";
00904     QLabel *drawGridLabel = new QLabel("Show Grid");
00905     drawGridLabel->setWhatsThis(drawGridWhatsThis);
00906     m_drawGridCheckBox = new QCheckBox;
00907     m_drawGridCheckBox->setWhatsThis(drawGridWhatsThis);
00908     connect(m_drawGridCheckBox, SIGNAL(toggled(bool)), this, SLOT(drawGrid(bool)));
00909     actionLayout->addWidget(drawGridLabel);
00910     actionLayout->addWidget(m_drawGridCheckBox);
00911 
00912     connect(this, SIGNAL(activated(bool)), this, SLOT(onToolOpen(bool)));
00913 
00914     actionLayout->addStretch(1);
00915     actionLayout->setMargin(0);
00916 
00917     QWidget *toolBarWidget = new QWidget;
00918     toolBarWidget->setLayout(actionLayout);
00919 
00920     return toolBarWidget;
00921   }
00922 }