Commit 7589d2d3 authored by Jeannie Backer's avatar Jeannie Backer
Browse files

PROG: Merged from IPCE branch. Added documentation to qisis Control class.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6932 41f8697f-d340-4b68-9986-7bafba869bb8
parent 068b36b9
Loading
Loading
Loading
Loading
+93 −36
Original line number Diff line number Diff line
@@ -3,16 +3,18 @@
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QMutex>
#include <QString>
#include <QUuid>
#include <QXmlStreamWriter>

#include "ControlNet.h"
#include "ControlDisplayProperties.h"
#include "ControlNet.h"
#include "FileName.h"
#include "IString.h"
#include "IException.h"
#include "IString.h"
#include "Project.h"
#include "PvlObject.h"
#include "XmlStackedHandlerReader.h"

namespace Isis {
@@ -61,15 +63,14 @@ namespace Isis {


  /**
   * Construct this control from XML.  TODO:  Is this for reading saved project?
   * Construct this control from XML.
   *  
   * @param cnetFolder Location of control xml - /work/.../projectRoot/cnets/controlNetwork1 
   * @param cnetFolder Location of control xml
   * @param xmlReader An XML reader that's up to an <control/> tag.  
   * @param parent The Qt-relationship parent
   */
  Control::Control(FileName cnetFolder, XmlStackedHandlerReader *xmlReader, QObject *parent) :
      QObject(parent) {

    m_controlNet = NULL;
    m_displayProperties = NULL;
    m_id = NULL;
@@ -78,8 +79,10 @@ namespace Isis {
  }


  /**
   * Destroys Control object.
   */
  Control::~Control() {
    
    delete m_controlNet;
    m_controlNet = NULL;

@@ -93,8 +96,14 @@ namespace Isis {
  }


  /**
   * Open and return a pointer to the ControlNet for this Control. 
   *  
   * @see openControlNet() 
   * @return @b ControlNet* Pointer to the ControlNet object associated with 
   *         this Control.
   */
  ControlNet *Control::controlNet() {
    
    if (!m_controlNet) {
      openControlNet();
    }
@@ -104,11 +113,12 @@ namespace Isis {


  /**
   * Get the ControlNet * associated with this display property. This will
   *   allocate the ControlNet * if one is not already present.
   * Sets the ControlNet from the control net file name provided in the 
   * constructor. 
   *  
   * @throws IException::Programmer  "Error opening control net."
   */
  void Control::openControlNet() {
    
    if (!m_controlNet) {
      try {
        m_controlNet = new ControlNet(m_fileName);
@@ -121,12 +131,11 @@ namespace Isis {


  /**
   * Cleans up the ControlNet *. You want to call this once you're sure you are
   *   done with the ControlNet because the OS will limit how many of these we
    *  have open.
   * Cleans up the ControlNet pointer. This method should be called
   * once there is no more need for this network because the OS will limit 
   * how many of these can be open. 
   */  
  void Control::closeControlNet() {
    
    if (m_controlNet) {
      delete m_controlNet;
      m_controlNet = NULL;
@@ -134,44 +143,69 @@ namespace Isis {
  }


  /**
   * Access a pointer to the display properties for the control network.
   * 
   * @return @b ControlDisplayProperties * A pointer to the display properties.
   */
  ControlDisplayProperties *Control::displayProperties() {
    
    return m_displayProperties;
  }


  /**
   * Access a const pointer to the display properties for the control network.
   * 
   * @return @b ControlDisplayProperties * A pointer to the display properties.
   */
  const ControlDisplayProperties *Control::displayProperties() const {

    return m_displayProperties;
  }


  /**
   * Access the name of the control network file associated with this Control.
   * 
   * @return @b QString The file name of the control network.
   */
  QString Control::fileName() const {
    
    return m_fileName;
  }


  /**
   * Access the unique ID associated with this Control.
   * 
   * @return @b QString The Control ID.
   */
  QString Control::id() const {
    
    return m_id->toString().remove(QRegExp("[{}]"));
  }


  /**
   * Copies the files of the given Project to the given location. 
   *  
   * @param project A pointer to the Project.
   * @param newProjectRoot The name of the new root directory where the project 
   *                       will be copied.
   */
  void Control::copyToNewProjectRoot(const Project *project, FileName newProjectRoot) {
    
    if (FileName(newProjectRoot) != FileName(project->projectRoot())) {

      FileName newCnetFileName(project->cnetRoot(newProjectRoot.toString()) + "/" +
          FileName(m_fileName).dir().dirName() + "/" + FileName(m_fileName).name());
      controlNet()->Write(newCnetFileName.toString());
    }

  }


  /**
   * Delete the control net from disk. The control net will no longer be accessible until you call
   * updateFileName(). 
   *  
   * @throws IException::Io  "Could not remove file."
   */
  void Control::deleteFromDisk() {

@@ -194,7 +228,6 @@ namespace Isis {
   * @param project The project that this control is stored in
   */
  void Control::updateFileName(Project *project) {
    
    closeControlNet();

    FileName original(m_fileName);
@@ -204,9 +237,16 @@ namespace Isis {
  }


  /**
   * Method to write this Control object's member data to an XML stream. 
   *  
   * @param stream The stream to which the Control will be saved.
   * @param project The Project to which this Control will be added.
   * @param newProjectRoot The location of the project root directory.
   * 
   */
  void Control::save(QXmlStreamWriter &stream, const Project *project,
                     FileName newProjectRoot) const {

    stream.writeStartElement("controlNet");
    stream.writeAttribute("id", m_id->toString());
    //  Change filename to new path
@@ -218,16 +258,33 @@ namespace Isis {
  }


  /**
   * Constructor for the Control object's XmlHandler 
   *  
   * @param control A pointer to the Control object.
   * @param cnetFolder The name of the folder for the Control xml
   * 
   */
  Control::XmlHandler::XmlHandler(Control *control, FileName cnetFolder) {
    
    m_control = control;
    m_cnetFolder = cnetFolder;
    m_xmlHandlerControl = control;
    m_xmlHandlerCnetFolderName = cnetFolder;
  }


  /**
   * Method to read the given XML formatted attribute for a Control object 
   * into the XmlHandler. 
   *  
   * @param namespaceURI ???
   * @param localName The keyword name given to the member variable in the XML.
   * @param qName ???
   * @param atts The attribute containing the keyword value for the given 
   *             localName.
   *  
   * @return @b bool Indicates whether the localName is recognized.
   */
  bool Control::XmlHandler::startElement(const QString &namespaceURI, const QString &localName,
                                         const QString &qName, const QXmlAttributes &atts) {
    
    if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
      if (localName == "controlNet") {
        QString id = atts.value("id");
@@ -235,18 +292,18 @@ namespace Isis {
        QString fileName = atts.value("fileName");

        if (!id.isEmpty()) {
          delete m_control->m_id;
          m_control->m_id = NULL;
          m_control->m_id = new QUuid(id.toAscii());
          delete m_xmlHandlerControl->m_id;
          m_xmlHandlerControl->m_id = NULL;
          m_xmlHandlerControl->m_id = new QUuid(id.toLatin1());
        }

        if (!fileName.isEmpty()) {
          m_control->m_fileName = m_cnetFolder.expanded() + "/" + fileName;
          m_control->openControlNet();
          m_xmlHandlerControl->m_fileName = m_xmlHandlerCnetFolderName.expanded() + "/" + fileName;
          m_xmlHandlerControl->openControlNet();
        }
      }
      else if (localName == "displayProperties") {
        m_control->m_displayProperties = new ControlDisplayProperties(reader());
        m_xmlHandlerControl->m_displayProperties = new ControlDisplayProperties(reader());
      }
    }

+28 −12
Original line number Diff line number Diff line

#ifndef Control_H
#define Control_H
/**
@@ -23,26 +22,27 @@
 *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
 *   http://www.usgs.gov/privacy.html.
 */
#include <QObject>
#include <QObject> // parent

#include <QString>

#include "FileName.h"
#include "XmlStackedHandler.h"

class QUuid;
class QMutex;
class QUuid;
class QXmlStreamWriter;

namespace Isis {
  class ControlNet;
  class ControlDisplayProperties;
  class ControlNet;
  class FileName;
  class Project;
  class PvlObject;

  /**
   * @brief 
   * This represents an ISIS control net in a project-based GUI interface. 
   * This encapsulates ideas about a control net such as it's filename and display properties.
   *
   * @author 2012-06-12 Ken Edmundson and Tracie Sucharski
   *
@@ -50,6 +50,9 @@ namespace Isis {
   *   @history 2012-08-02 Kimberly Oyama - Added comments to some of the methods and
   *                           member variables.
   *   @history 2012-09-11 Tracie Sucharski - Added new constructor that takes a ControlNet *. 
   *   @history 2015-10-14 Jeffrey Covington - Declared Control * as a Qt
   *                           metatype for use with QVariant. References #3949
   *   @history 2016-06-02 Jeannie Backer - Updated documentation. Fixes #3949
   */
  class Control : public QObject {
    Q_OBJECT
@@ -77,7 +80,10 @@ namespace Isis {

    private:
      /**
       * @author 2012-??-?? ???
       * Nested class used to write the Control object information to an XML file for the 
       * purpose of saving and restoring the state of the project.
       *
       * @author 2012-??-?? Steven Lambright
       *
       * @internal
       */
@@ -91,19 +97,29 @@ namespace Isis {
        private:
          Q_DISABLE_COPY(XmlHandler);

          Control *m_control;
          FileName m_cnetFolder;
          Control *m_xmlHandlerControl;        /**< A pointer to the Control object to be read or
                                                    written.*/
          FileName m_xmlHandlerCnetFolderName; /**< The name of the folder for the control xml.*/
      };

    private:
      Control(const Control &other);
      Control &operator=(const Control &rhs);

      ControlNet *m_controlNet;
      ControlDisplayProperties *m_displayProperties;
      QString m_fileName; //! File name of the control net associated with this control.
      ControlNet *m_controlNet; /**< A pointer to the ControlNet object associated with this
                                     Control object.*/
      ControlDisplayProperties *m_displayProperties; /**< Contains the display properties for this
                                                          Control object.*/
      QString m_fileName; /**< File name of the control net associated with this control.*/

      /**
       * A unique ID for this Control.
       * (useful for others to reference this Control when saving to disk).
       */
      QUuid *m_id;
  };
}

Q_DECLARE_METATYPE(Isis::Control *);

#endif // Control_H