Isis 3.0 Programmer Reference
Back | Home
Control.cpp
1 #include "Control.h"
2 
3 #include <QDebug>
4 #include <QDir>
5 #include <QFileInfo>
6 #include <QMutex>
7 #include <QString>
8 #include <QUuid>
9 #include <QXmlStreamWriter>
10 
12 #include "ControlNet.h"
13 #include "FileName.h"
14 #include "IException.h"
15 #include "IString.h"
16 #include "Project.h"
17 #include "PvlObject.h"
18 #include "XmlStackedHandlerReader.h"
19 
20 namespace Isis {
27  Control::Control(QString cNetFileName, QObject *parent) : QObject(parent) {
28 
29  m_fileName = cNetFileName;
30 
31  m_controlNet = NULL;
32  m_displayProperties = NULL;
33 
35 
37  = new ControlDisplayProperties(FileName(m_fileName).name(), this);
38 
39  m_id = new QUuid(QUuid::createUuid());
40  }
41 
42 
50  Control::Control(ControlNet *controlNet, QString cnetFileName, QObject *parent) :
51  QObject(parent) {
52 
53  m_fileName = cnetFileName;
54 
56  m_displayProperties = NULL;
57 
59  = new ControlDisplayProperties(FileName(m_fileName).name(), this);
60 
61  m_id = new QUuid(QUuid::createUuid());
62  }
63 
64 
72  Control::Control(FileName cnetFolder, XmlStackedHandlerReader *xmlReader, QObject *parent) :
73  QObject(parent) {
74  m_controlNet = NULL;
75  m_displayProperties = NULL;
76  m_id = NULL;
77 
78  xmlReader->pushContentHandler(new XmlHandler(this, cnetFolder));
79  }
80 
81 
86  delete m_controlNet;
87  m_controlNet = NULL;
88 
89  delete m_id;
90  m_id = NULL;
91 
92  // Image is a "Qt" parent of display properties, so the Image QObject
93  // destructor will take care of deleting the display props. See call to
94  // DisplayProperties' constructor.
95  m_displayProperties = NULL;
96  }
97 
98 
107  if (!m_controlNet) {
108  openControlNet();
109  }
110 
111  return m_controlNet;
112  }
113 
114 
122  if (!m_controlNet) {
123  try {
125  }
126  catch (IException &e) {
127  throw IException(e, IException::Programmer, "Error opening control net.", _FILEINFO_);
128  }
129  }
130  }
131 
132 
139  if (m_controlNet) {
140  delete m_controlNet;
141  m_controlNet = NULL;
142  }
143  }
144 
145 
152  return m_displayProperties;
153  }
154 
155 
162  return m_displayProperties;
163  }
164 
165 
171  QString Control::fileName() const {
172  return m_fileName;
173  }
174 
175 
181  QString Control::id() const {
182  return m_id->toString().remove(QRegExp("[{}]"));
183  }
184 
185 
193  void Control::copyToNewProjectRoot(const Project *project, FileName newProjectRoot) {
194  if (FileName(newProjectRoot) != FileName(project->projectRoot())) {
195 
196  FileName newCnetFileName(project->cnetRoot(newProjectRoot.toString()) + "/" +
197  FileName(m_fileName).dir().dirName() + "/" + FileName(m_fileName).name());
198  controlNet()->Write(newCnetFileName.toString());
199  }
200 
201  }
202 
203 
211 
212  if (!QFile::remove(m_fileName)) {
214  tr("Could not remove file [%1]").arg(m_fileName),
215  _FILEINFO_);
216  }
217 
218  // If we're the last thing in the folder, remove the folder too.
219  QDir dir;
220  dir.rmdir(FileName(m_fileName).path());
221  }
222 
223 
231  closeControlNet();
232 
233  FileName original(m_fileName);
234  FileName newName(project->cnetRoot() + "/" +
235  original.dir().dirName() + "/" + original.name());
236  m_fileName = newName.expanded();
237  }
238 
239 
248  void Control::save(QXmlStreamWriter &stream, const Project *project,
249  FileName newProjectRoot) const {
250  stream.writeStartElement("controlNet");
251  stream.writeAttribute("id", m_id->toString());
252  // Change filename to new path
253  stream.writeAttribute("fileName", FileName(m_fileName).name());
254 
255  m_displayProperties->save(stream, project, newProjectRoot);
256 
257  stream.writeEndElement();
258  }
259 
260 
269  m_xmlHandlerControl = control;
270  m_xmlHandlerCnetFolderName = cnetFolder;
271  }
272 
273 
286  bool Control::XmlHandler::startElement(const QString &namespaceURI, const QString &localName,
287  const QString &qName, const QXmlAttributes &atts) {
288  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
289  if (localName == "controlNet") {
290  QString id = atts.value("id");
291  QString path = atts.value("path");
292  QString fileName = atts.value("fileName");
293 
294  if (!id.isEmpty()) {
295  delete m_xmlHandlerControl->m_id;
296  m_xmlHandlerControl->m_id = NULL;
297  m_xmlHandlerControl->m_id = new QUuid(id.toLatin1());
298  }
299 
300  if (!fileName.isEmpty()) {
301  m_xmlHandlerControl->m_fileName = m_xmlHandlerCnetFolderName.expanded() + "/" + fileName;
302  m_xmlHandlerControl->openControlNet();
303  }
304  }
305  else if (localName == "displayProperties") {
306  m_xmlHandlerControl->m_displayProperties = new ControlDisplayProperties(reader());
307  }
308  }
309 
310  return true;
311  }
312 }
313 
314 
315 
This represents an ISIS control net in a project-based GUI interface.
Definition: Control.h:57
The main project for cnetsuite.
Definition: Project.h:105
void deleteFromDisk()
Delete the control net from disk.
Definition: Control.cpp:210
File name manipulation and expansion.
Definition: FileName.h:111
Control(QString cnetFileName, QObject *parent=0)
Create a Control from control net located on disk.
Definition: Control.cpp:27
ControlDisplayProperties * m_displayProperties
Contains the display properties for this Control object.
Definition: Control.h:111
QUuid * m_id
A unique ID for this Control.
Definition: Control.h:119
void copyToNewProjectRoot(const Project *project, FileName newProjectRoot)
Copies the files of the given Project to the given location.
Definition: Control.cpp:193
FileName m_xmlHandlerCnetFolderName
The name of the folder for the control xml.
Definition: Control.h:102
Nested class used to write the Control object information to an XML file for the purpose of saving an...
Definition: Control.h:90
QString id() const
Access the unique ID associated with this Control.
Definition: Control.cpp:181
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:163
static QString cnetRoot(QString projectRoot)
Appends the root directory name &#39;cnets&#39; to the project.
Definition: Project.cpp:1220
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Method to read the given XML formatted attribute for a Control object into the XmlHandler.
Definition: Control.cpp:286
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Method to write this Control object&#39;s member data to an XML stream.
Definition: Control.cpp:248
void closeControlNet()
Cleans up the ControlNet pointer.
Definition: Control.cpp:138
This is the GUI communication mechanism for cubes.
void openControlNet()
Sets the ControlNet from the control net file name provided in the constructor.
Definition: Control.cpp:121
a control network
Definition: ControlNet.h:207
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
~Control()
Destroys Control object.
Definition: Control.cpp:85
QString fileName() const
Access the name of the control network file associated with this Control.
Definition: Control.cpp:171
void updateFileName(Project *)
Change the on-disk file name for this control to be where the control ought to be in the given projec...
Definition: Control.cpp:230
ControlNet * controlNet()
Open and return a pointer to the ControlNet for this Control.
Definition: Control.cpp:106
XmlHandler(Control *control, FileName cnetFolder)
Constructor for the Control object&#39;s XmlHandler.
Definition: Control.cpp:268
ControlNet * m_controlNet
A pointer to the ControlNet object associated with this Control object.
Definition: Control.h:109
QString m_fileName
File name of the control net associated with this control.
Definition: Control.h:113
ControlDisplayProperties * displayProperties()
Access a pointer to the display properties for the control network.
Definition: Control.cpp:151
Isis exception class.
Definition: IException.h:99
Control * m_xmlHandlerControl
A pointer to the Control object to be read or written.
Definition: Control.h:100
his enables stack-based XML parsing of XML files.
QString projectRoot() const
Get the top-level folder of the project.
Definition: Project.cpp:1087
void Write(const QString &filename, bool pvl=false)
Writes out the control network.
Definition: ControlNet.cpp:302

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:16:13