Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
Control.cpp
1
6
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "Control.h"
10
11#include <QDebug>
12#include <QDir>
13#include <QFileInfo>
14#include <QMutex>
15#include <QRegularExpression>
16#include <QString>
17#include <QUuid>
18#include <QXmlStreamWriter>
19
20#include "ControlDisplayProperties.h"
21#include "ControlNet.h"
22#include "FileName.h"
23#include "IException.h"
24#include "IString.h"
25#include "Project.h"
26#include "PvlObject.h"
27
28namespace Isis {
35 Control::Control(QString cNetFileName, QObject *parent) : QObject(parent) {
36
37 m_fileName = cNetFileName;
38
39 m_controlNet = NULL;
41 m_project = NULL;
42 m_modified = false;
43
44 try {
46 }
47 catch (IException &e) {
48 throw IException(e, IException::Programmer, "Error opening control net.", _FILEINFO_);
49 }
50
52 = new ControlDisplayProperties(FileName(m_fileName).name(), this);
53
54 m_id = new QUuid(QUuid::createUuid());
55 }
56
57
64 Control::Control(Project *project, QString cNetFileName, QObject *parent) : QObject(parent) {
65
66 m_fileName = cNetFileName;
67
68 m_controlNet = NULL;
70 m_project = project;
71 m_modified = false;
72
74 = new ControlDisplayProperties(FileName(m_fileName).name(), this);
75
76 m_id = new QUuid(QUuid::createUuid());
77 }
78
79
87 Control::Control(ControlNet *controlNet, QString cnetFileName, QObject *parent) :
88 QObject(parent) {
89
90 m_fileName = cnetFileName;
91
94 m_project = NULL;
95 m_modified = false;
96
98 = new ControlDisplayProperties(FileName(m_fileName).name(), this);
99
100 m_id = new QUuid(QUuid::createUuid());
101 }
102
103
108 delete m_controlNet;
109 m_controlNet = NULL;
110
111 delete m_id;
112 m_id = NULL;
113
114 // Image is a "Qt" parent of display properties, so the Image QObject
115 // destructor will take care of deleting the display props. See call to
116 // DisplayProperties' constructor.
117 m_displayProperties = NULL;
118
119 // TODO: If control net is modified, prompt for save before destroying??
120
121 }
122
123
132 if (!m_controlNet) {
134 }
135
136 return m_controlNet;
137 }
138
139
147 if (!m_controlNet) {
148 try {
150 if (m_project) {
151 m_controlNet->SetMutex(m_project->mutex());
152 }
153 m_modified = false;
154
155 }
156 catch (IException &e) {
157 throw IException(e, IException::Programmer, "Error opening control net.", _FILEINFO_);
158 }
159 }
160 }
161
162
173
174 if (!m_controlNet) {
175 return false;
176 }
177
178 try {
179 m_controlNet->Write(fileName());
180 }
181 catch (IException &e) {
182 throw IException(e, IException::Programmer, "Cannot write control net.", _FILEINFO_);
183 }
184
185 m_modified = false;
186 return true;
187 }
188
189
196 if (m_controlNet) {
197 delete m_controlNet;
198 m_controlNet = NULL;
199 }
200 m_modified = false;
201 }
202
203
211 return m_modified;
212 }
213
214
222 void Control::setModified(bool modified) {
223
224 m_modified = modified;
225 }
226
227
236
237
246
247
253 QString Control::fileName() const {
254 return m_fileName;
255 }
256
257
263 QString Control::id() const {
264 return m_id->toString().remove(QRegularExpression("[{}]"));
265 }
266
267
275 void Control::copyToNewProjectRoot(const Project *project, FileName newProjectRoot) {
276
277 if (FileName(newProjectRoot).toString() != FileName(project->projectRoot()).toString()) {
278
279 QString newNetworkPath = project->cnetRoot(newProjectRoot.toString()) + "/" +
280 FileName(m_fileName).dir().dirName() + "/" + FileName(m_fileName).name();
281
282 // If there is active control & it has been modified, write to disk instead of copying
283 // Leave control net at old location in unmodified state
284 if (isModified()) {
285 controlNet()->Write(newNetworkPath);
286 setModified(false);
287 }
288 else {
289 QString oldNetworkPath = project->cnetRoot(project->projectRoot()) + "/" +
290 FileName(m_fileName).dir().dirName() + "/" + FileName(m_fileName).name();
291 if (!QFile::copy(oldNetworkPath,newNetworkPath) ) {
292 throw IException(IException::Io, "Error saving control net.", _FILEINFO_);
293 }
294 }
295 }
296 // Project "Save" to current location, if active control exists & is modified, write to disk
297 // Note: It does not look like this code is ever executed. If project is saved with a
298 // "Save" this method is not called.
299 else {
300 if (isModified()) {
301 write();
302 setModified(false);
303 }
304 }
305
306 }
307
308
316
317 if (!QFile::remove(m_fileName)) {
318 throw IException(IException::Io,
319 tr("Could not remove file [%1]").arg(m_fileName),
320 _FILEINFO_);
321 }
322
323 // If we're the last thing in the folder, remove the folder too.
324 QDir dir;
325 dir.rmdir(FileName(m_fileName).path());
326 m_modified = false;
327 }
328
329
338
339 FileName original(m_fileName);
340 FileName newName(project->cnetRoot() + "/" +
341 original.dir().dirName() + "/" + original.name());
342 m_fileName = newName.expanded();
343 }
344
345
354 void Control::save(QXmlStreamWriter &stream, const Project *project,
355 FileName newProjectRoot) const {
356 stream.writeStartElement("controlNet");
357 stream.writeAttribute("id", m_id->toString());
358 // Change filename to new path
359 stream.writeAttribute("fileName", FileName(m_fileName).name());
360
361 m_displayProperties->save(stream, project, newProjectRoot);
362
363 stream.writeEndElement();
364 }
365}
This is the GUI communication mechanism for cubes.
QString id() const
Access the unique ID associated with this Control.
Definition Control.cpp:263
ControlNet * controlNet()
Open and return a pointer to the ControlNet for this Control.
Definition Control.cpp:131
ControlDisplayProperties * displayProperties()
Access a pointer to the display properties for the control network.
Definition Control.cpp:233
QString m_fileName
Project associated with this control.
Definition Control.h:104
void deleteFromDisk()
Delete the control net from disk.
Definition Control.cpp:315
Control(QString cnetFileName, QObject *parent=0)
Create a Control from control net located on disk.
Definition Control.cpp:35
bool write()
@description Write control net to disk.
Definition Control.cpp:172
void copyToNewProjectRoot(const Project *project, FileName newProjectRoot)
Copies the files of the given Project to the given location.
Definition Control.cpp:275
void setModified(bool modified=true)
@description Sets the modification state of this control.
Definition Control.cpp:222
ControlNet * m_controlNet
A pointer to the ControlNet object associated with this Control object.
Definition Control.h:68
bool isModified()
@description Has this control been modified?
Definition Control.cpp:210
~Control()
Destroys Control object.
Definition Control.cpp:107
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:336
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Method to write this Control object's member data to an XML stream.
Definition Control.cpp:354
void openControlNet()
Sets the ControlNet from the control net file name provided in the constructor.
Definition Control.cpp:146
QString fileName() const
Access the name of the control network file associated with this Control.
Definition Control.cpp:253
ControlDisplayProperties * m_displayProperties
Contains the display properties for this Control object.
Definition Control.h:101
QUuid * m_id
A unique ID for this Control.
Definition Control.h:110
void closeControlNet()
Cleans up the ControlNet pointer.
Definition Control.cpp:195
a control network
Definition ControlNet.h:257
void Write(const QString &filename, bool pvl=false)
Writes out the control network.
The main project for ipce.
Definition Project.h:287
static QString cnetRoot(QString projectRoot)
Appends the root directory name 'cnets' to the project.
Definition Project.cpp:2081
QString projectRoot() const
Get the top-level folder of the project.
Definition Project.cpp:1728
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.