Commit 26356206 authored by Jesse Mapel's avatar Jesse Mapel
Browse files

PROG Added plotspice tool

parent 06420af9
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
ifeq ($(ISISROOT), $(BLANK))
.SILENT:
error:
	echo "Please set ISISROOT";
else
	include $(ISISROOT)/make/isismake.apps
endif
 No newline at end of file
+286 −0
Original line number Diff line number Diff line
#include "IsisDebug.h"

#include <fcntl.h>
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>

#include <QApplication>
#include <QCoreApplication>
#include <QFontDialog>
#include <QMdiArea>

#include "Application.h"
#include "AdvancedTrackTool.h"
#include "BandTool.h"
#include "BlinkTool.h"
#include "EditTool.h"
#include "EphemeridesPlotTool.h"
#include "FeatureNomenclatureTool.h"
#include "FileName.h"
#include "FileTool.h"
#include "FindTool.h"
#include "Gui.h"
#include "HelpTool.h"
#include "HistogramTool.h"
#include "IString.h"
#include "MatchTool.h"
#include "MeasureTool.h"
#include "PanTool.h"
#include "Preference.h"
#include "PvlGroup.h"
#include "QIsisApplication.h"
#include "RubberBandTool.h"
#include "ScatterPlotTool.h"
#include "SpecialPixelTool.h"
#include "SpatialPlotTool.h"
#include "SpectralPlotTool.h"
#include "SocketThread.h"
#include "StatisticsTool.h"
#include "StereoTool.h"
#include "StretchTool.h"
#include "SunShadowTool.h"
#include "ToolList.h"
#include "ViewportMainWindow.h"
#include "WindowTool.h"
#include "Workspace.h"
#include "ZoomTool.h"

using namespace Isis;

template<typename ToolClass>
ToolClass *createTool(ViewportMainWindow *viewportMainWindow, ToolList *tools) {
  ToolClass *result = new ToolClass(viewportMainWindow);

  tools->append(result);
  ((Tool *)result)->addTo(viewportMainWindow);

  return result;
}

int main(int argc, char *argv[]) {
  Isis::Gui::checkX11();

  // Add the Qt plugin directory to the library path
  FileName qtpluginpath("$ISISROOT/3rdParty/plugins");
  QCoreApplication::addLibraryPath(qtpluginpath.expanded());

  // Check to see if the user wants to force a new window
  int newWindow = -1;
  for (int i = 1; i < argc; i++) {
    if (IString(argv[i]).UpCase() == "-NEW") {
      newWindow = i;
    }
  }

  QString p_socketFile = "/tmp/isis_plotspice_" + Application::UserName();
  if (newWindow < 0) {
    struct sockaddr_un p_socketName;
    p_socketName.sun_family = AF_UNIX;
    strcpy(p_socketName.sun_path, p_socketFile.toLatin1().data());
    int p_socket;

    if (((FileName)p_socketFile).fileExists()) {
      // Create a socket
      if ((p_socket = socket(PF_UNIX, SOCK_STREAM, 0)) >= 0) {
        // Try to connect to the socket
        if ((connect(p_socket, (struct sockaddr *)&p_socketName,
                    sizeof(p_socketName))) >= 0) {
          QString temp;
          /*
           * We need a very uncommon token to use for parsing.
           */
          QChar escape(27);
          for (int i = 1; i < argc; i++) {
            temp += QFileInfo(FileName(argv[i]).expanded()).absoluteFilePath();
            temp += QString(escape);
          }
          temp += "raise";
          // Try to send data to the socket
          if (send(p_socket, temp.toLatin1().data(), temp.size(), 0) >= 0) {
            // Success, the other plotspice will open this file.
            exit(0);
          }
          else {
            QString msg = "Unable to write to socket";
            std::cout << msg << std::endl;
            remove(p_socketFile.toLatin1().data());
          }
        }

        // If the file already exists but we can't connect to it, assume the
        //   socket is no longer running & remove the tmp file...it falls out &
        //   create a new one. This happens if plotspice is not already running.
        else {
          remove(p_socketFile.toLatin1().data());
        }
      }
      else {
        QString msg = "Unable to create socket";
        std::cout << msg << std::endl;
        remove(p_socketFile.toLatin1().data());
      }
    }
  }

  // Creates the plotspice application window
  QIsisApplication *app = new QIsisApplication(argc, argv);
  QApplication::setApplicationName("plotspice");

  // check for forcing of gui style
  PvlGroup &uiPref = Preference::Preferences().findGroup(
                             "UserInterface");
  if (uiPref.hasKeyword("GuiStyle")) {
    QString style = uiPref["GuiStyle"];
    QApplication::setStyle((QString) style);
  }

  ViewportMainWindow *vw = new ViewportMainWindow("plotspice");

  ToolList tools;
  Tool *rubberBandTool = createTool<RubberBandTool>(vw, &tools);

  Tool *fileTool = createTool<FileTool>(vw, &tools);
  vw->permanentToolBar()->addSeparator();

  Tool *bandTool = createTool<BandTool>(vw, &tools);

  Tool *zoomTool = createTool<ZoomTool>(vw, &tools);
  zoomTool->activate(true);
  vw->getMenu("&View")->addSeparator();

  Tool *panTool = createTool<PanTool>(vw, &tools);
  vw->getMenu("&View")->addSeparator();

  Tool *stretchTool = createTool<StretchTool>(vw, &tools);

  Tool *findTool = createTool<FindTool>(vw, &tools);

  Tool *blinkTool = createTool<BlinkTool>(vw, &tools);

  Tool *advancedTrackTool = createTool<AdvancedTrackTool>(vw, &tools);

  Tool *editTool = createTool<EditTool>(vw, &tools);

  Tool *windowTool = createTool<WindowTool>(vw, &tools);

  Tool *measureTool = createTool<MeasureTool>(vw, &tools);

  Tool *sunShadowTool = createTool<SunShadowTool>(vw, &tools);

  Tool *featureNomenclatureTool = createTool<FeatureNomenclatureTool>(vw, &tools);

  Tool *specialPixelTool = createTool<SpecialPixelTool>(vw, &tools);

  Tool *spatialPlotTool = createTool<SpatialPlotTool>(vw, &tools);

  Tool *spectralPlotTool = createTool<SpectralPlotTool>(vw, &tools);

  Tool *scatterPlotTool = createTool<ScatterPlotTool>(vw, &tools);

  Tool *histTool = createTool<HistogramTool>(vw, &tools);

  Tool *statsTool = createTool<StatisticsTool>(vw, &tools);

  Tool *stereoTool = createTool<StereoTool>(vw, &tools);

  Tool *matchTool = createTool<MatchTool>(vw, &tools);
  
  Tool *ephemeridesTool = createTool<EphemeridesPlotTool>(vw, &tools);

  Tool *helpTool = createTool<HelpTool>(vw, &tools);

  // Show the application window & open the cubes
  vw->show();

  bool openingAFileSucceeded = false;
  for (int i = 1; i < argc; i++) {
    if (i != newWindow) {
      try {
        vw->workspace()->addCubeViewport(QString(argv[i]));
        openingAFileSucceeded = true;
      }
      catch (IException &e) {
        e.print();

        // If we're trying to open more later or have opened a file, allow
        //   plotspice to continue running. Otherwise (this if), crash.
        if (i == argc - 1 && !openingAFileSucceeded) {
          // since we intend to exit, we need to cleanup our heap
          // (tools cleaned since they are vw's children)
          delete vw;
          vw = NULL;
          delete app;
          app = NULL;
          return 1;
        }
      }
    }
  }

  SocketThread *temp = NULL;
  // We don't want to start a thread if the user is forcing a new window
  if (newWindow < 0) {
    temp = new SocketThread();
    temp->connect(temp, SIGNAL(newImage(const QString &)),
                  vw->workspace(), SLOT(addCubeViewport(const QString &)));
    temp->connect(temp, SIGNAL(focusApp()), vw, SLOT(raise()));
    temp->start();
  }

  //Connect the editTool to the file tool in order to save and discard changes
  QObject::connect(editTool, SIGNAL(cubeChanged(bool)),
                   fileTool, SLOT(enableSave(bool)));
  QObject::connect(fileTool, SIGNAL(saveChanges(CubeViewport *)),
                   editTool, SLOT(save(CubeViewport *)));
  QObject::connect(fileTool, SIGNAL(discardChanges(CubeViewport *)),
                   editTool, SLOT(undoAll(CubeViewport *)));
  QObject::connect(editTool, SIGNAL(save()), fileTool, SLOT(save()));
  QObject::connect(editTool, SIGNAL(saveAs()), fileTool, SLOT(saveAs()));
  // Connect the FindTool to the AdvancedTrackTool to record the point if the
  // "record" button is clicked
  QObject::connect(findTool, SIGNAL(recordPoint(QPoint)),
                   advancedTrackTool, SLOT(record(QPoint)));

  //Connect the viewport's close signal to the all windows/subwindows
  QObject::connect(vw, SIGNAL(closeWindow()), fileTool, SLOT(exit()));

  int status = app->exec();

  // If we created a thread for listening to plotspice connections, then stop the thread and free its memory
  if (temp) {
    temp->stop();
    temp->wait(); // wait for the stop to finish
    delete temp;

    remove(p_socketFile.toLatin1().data());
  }

  delete panTool;
  delete statsTool;
  delete helpTool;
  delete ephemeridesTool;
  delete matchTool;
  delete stereoTool;
  delete histTool;
  delete spatialPlotTool;
  delete spectralPlotTool;
  delete scatterPlotTool;
  delete specialPixelTool;
  delete featureNomenclatureTool;
  delete sunShadowTool;
  delete measureTool;
  delete windowTool;
  delete advancedTrackTool;
  delete blinkTool;
  delete findTool;
  delete stretchTool;
  delete bandTool;
  delete rubberBandTool;
  delete vw;
  delete app;
  //delete QCoreApplication::instance();
  return status;
}
+168 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>

<application name="plotspice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Application/application.xsd">
  <brief>
    Display and analyze cubes
  </brief>

  <description>
    This program will display cubes and allow for interactive analysis.
  </description>

  <category>
    <categoryItem>Display</categoryItem>
  </category>

  <history>
    <change name="Jeff Anderson" date="2004-12-01">
      Original version
    </change>
    <change name="Jeff Anderson" date="2006-01-06">
      Port to Qt4 and add blink tool
    </change>
    <change name="Elizabeth Miller" date="2006-07-26">
      Fixed bug with filename expansion and added the MeasureTool
    </change>
    <change name="Brendan George" date="2006-09-19">
      Documentation fixes
    </change>
    <change name="Steven Lambright" date="2007-09-11">
      Added new rubber band functionality
    </change>
    <change name="Sharmila Prasad" date="2009-10-19">
      Added Mosaic Tracking info like image index, serial number and file name
      in the Advanced Tracking window to have the ability to track mosaic
      origin.
    </change>
    <change name="Jeannie Walldren" date="2010-03-08">
      Modified FindTool.  If a user enters a line/sample in the Image tab, then
      the corresponding lat/lon is displayed in the Ground tab.  Added Record
      button to FindTool to record clicked or typed point in the
      AdvancedTrackTool window.
    </change>
    <change name="Sharmila Prasad" date="2010-03-19">
      "qview" now has the ability to handle exceptions. The status bar now
      displays a default NoWarning icon with "Ready" message. If an
      exception is caught, the icon changes to Warning and displays the error
      message. Clicking on the Warning icon will display a dialog window with
      the details of the most recent error occured. Closing the dialog or any
      other mouse activity will reset the Warning status.
    </change>
    <change name="Eric Hyer" date="2010-03-22">
      Discontinued forcing of gui style to windows
    </change>
    <change name="Sharmila Prasad" date="2010-03-24">
      Enable FindTool for images without camera and/or projection
    </change>
    <change name="Sharmila Prasad" date="2011-02-16">Added columns Local
     Emission and  Incidence Angles for Advanced Tracking Tool
    </change>
    <change name="Sharmila Prasad" date="2011-03-18">
      Connect the viewport's close signal to the all windows/subwindows like
      plottool and histogram tools as well.
    </change>
    <change name="Sharmila Prasad" date="2011-05-11">
      Added options for SaveAs to save cube as fullImage, Export AsIs or Export
      FullResolution options
    </change>
    <change name="Steven Lambright, Jai Rideout and Tracie Sucharski" date="2012-01-18">
      Re-implemented all of the plotting functionality in order to improve the
      user interface and capabilities. Added best fit lines and a scatter plot.
    </change>
    <change name="Steven Lambright" date="2012-03-22">
      Added the sun shadow and feature nomenclature tools.
    </change>
    <change name="Tracie Sucharski" date="2012-04-24">
      Added the stereo tool which calculates spot elevations and elevation profiles
      from pairs of stereo images.
    </change>
    <change name="Steven Lambright" date="2012-05-29">
      Fixed prompts for saving edited files on closing so they are functional once again.
      Fixes #854.
    </change>
    <change name="Steven Lambright and Kimberly Oyama" date="2012-06-11">
      Updated the nomenclature tool to include the option to choose from three
      types of extent displays (4 arrows, 8 arrows, or a box) and the option
      to display all features or only IAU approved features.
    </change>
    <change name="Kimberly Oyama and Steven Lambright" date="2012-06-22">
      Updated the Advanced Track Tool to include a help menu and a help dialog that opesn with the
      tool and when the user opens it through the help menu. Fixes #772.
    </change>
    <change name="Kimberly Oyama and Steven Lambright" date="2012-06-26">
      Fixed query range problems with the nomenclature tool. It can now handle longitudinal ranges
      that encompass the 0/360 line. Fixes #958.
    </change>
    <change name="Steven Lambright" date="2012-06-28">
      The special pixel colorization tool's settings won't be forgotten when restretching.
      Also, images that are opened after using this tool will now take on the appropriate
      colors. Fixes #684.
    </change>
    <change name="Steven Lambright" date="2012-06-29">
      Improved handling of special pixels in the statistics tool so that they are reported
      correctly. Fixes #199.
    </change>
    <change name="Steven Lambright" date="2012-07-03">
      Added M/KM options to the spatial plot tool. Fixes #853.
    </change>
    <change name="Tracie Sucharski" date="2012-07-30">
      Added the match tool which allows registration (control points) to be edited
      between cubes without a camera model.
    </change>
    <change name="Tracie Sucharski" date="2012-10-01">
      Fixed bug in the match tool which caused qview to to print error messages and possibly
      crash when closing cube viewports either individually or from the File Menu.
    </change>
    <change name="Tracie Sucharski" date="2013-01-08">
      Add the AlphaCube to the labels of and exported cropped cube.  Fixes #706.
    </change>
    <change name="Tracie Sucharski" date="2013-01-08">
      Fixed bug when saving a cube viewport that is displayed at full resolution,  the application
      would seg fault.  Fixes #1386.
    </change>
    <change name="Steven Lambright" date="2013-01-24">
      Fixed spatial plot tool functionality on single line images. Fixes #997.
    </change>
    <change name="Steven Lambright" date="2013-01-31">
      Improved upon the accuracy of the find tool's sync scale option. Fixes #953.
    </change>
    <change name="Steven Lambright" date="2013-02-12">
      The red boxes that indicate the current selection (i.e. the rubber band) shown
      while creating plots, updating stretches, and other actions should now only draw
      on cubes (viewports) that are relevant to the action being performed. Fixes #1035.
    </change>
    <change name="Steven Lambright" date="2013-02-07">
      The plot tables should no longer have multiple rows with the same X value. Also, fixed a crash
      related to closing the plot table windows. Fixes #710. Fixes #818.
    </change>
    <change name="Kimberly Oyama and Stuart Sices" date="2013-12-30">
      Changed the character that is used as a token when parsing the list of file names used when
      the socket is already open. Fixes #1551.
    </change>
    <change name="Ian Humphrey" date="2014-07-30">
      Modified spectral plot tool to more accurately compute statistics for rectangular and
      polygonal selections. Fixes #2071.
    </change>
    <change name="Ian Humphrey" date="2014-07-31">
      Added configurePlotCurves() method to PlotWindow. User can activate configure dialog on
      single curve with right-click or activate dialog with combo box of all curves using the
      toolbar button. Added What's This for SpatialPlotTool and removed the configure toolbar button
      for ScatterPlotWindow. Fixes #2089.
    </change>
    <change name="Ian Humphrey" date="2015-10-07">
      Updated icons. Fixes #1041.
    </change>
    <change name="Ian Humphrey" date="2015-11-19">
      Added shortcuts to Match Tool window for selecting right measures, registration, undo
      registration, saving measures, saving the point, and saving the control network. Fixes #2324.
    </change>
    <change name="Ian Humphrey" date="2017-05-10">
      Fixed initial loading of viewport and Fit to viewport zoom to correctly zoom to the center
      of the image. Fixes #4756.
    </change>
    <change name="Adam Paquette" date="2017-05-19">
      Readded help menu for the 2D and 3D plot tools. Now properly display in both tools.
      Fixes #2126.
    </change>
  </history>
</application>