Isis 3.0 Programmer Reference
Back | Home
QnetFileTool.cpp
1 #include <QApplication>
2 #include <QFileDialog>
3 #include <QMessageBox>
4 #include <QString>
5 
6 #include "Application.h"
7 #include "Camera.h"
8 #include "ControlMeasure.h"
9 #include "ControlNet.h"
10 #include "ControlPoint.h"
11 #include "Cube.h"
12 #include "FileName.h"
13 #include "MdiCubeViewport.h"
14 #include "Progress.h"
15 #include "QnetFileTool.h"
16 #include "QnetTool.h"
17 #include "SerialNumber.h"
18 #include "SerialNumberList.h"
19 #include "Target.h"
20 #include "Workspace.h"
21 
22 using namespace std;
23 
24 namespace Isis {
33  QnetFileTool::QnetFileTool(QnetTool *qnetTool, QWidget *parent) : FileTool(parent) {
34  m_qnetTool = qnetTool;
35 
36  openAction()->setText("Open control network and cube list");
37  openAction()->setToolTip("Open control network and cube list");
38  QString whatsThis =
39  "<b>Function:</b> Open a <i>control network</i> \
40  <p><b>Shortcut:</b> Ctrl+O\n</p>";
41  openAction()->setWhatsThis(whatsThis);
42 
43  saveAction()->setText("Save Control Network &As...");
44  whatsThis =
45  "<b>Function:</b> Save the current <i>control network</i> under chosen filename";
46  saveAction()->setWhatsThis(whatsThis);
47  saveAction()->setEnabled(true);
48 
49  m_isDirty = false;
50 
51  m_openGround = new QAction(parent);
52  m_openGround->setText("Open &Ground Source");
53  m_openGround->setStatusTip("Open a ground source for choosing ground points");
54  whatsThis =
55  "<b>Function:</b> Open and display a ground source for choosing ground points."
56  "This can be level1, level2 or dem cube.";
57  m_openGround->setWhatsThis(whatsThis);
58  m_openGround->setEnabled(false);
59  connect (m_openGround,SIGNAL(triggered()),this,SIGNAL(newGroundFile()));
60 
61  m_openDem = new QAction(parent);
62  m_openDem->setText("Open &Radius Source");
63  whatsThis =
64  "<b>Function:</b> Open a DEM for determining the radius when "
65  "choosing ground points. This is not the file that will be displayed "
66  "to be used for visually picking points. This is strictly used to "
67  "determine the radius value.";
68  m_openDem->setWhatsThis(whatsThis);
69  m_openDem->setEnabled(false);
70  connect (m_openDem,SIGNAL(triggered()),this,SIGNAL(newDemFile()));
71  }
72 
73 
74  QnetFileTool::~QnetFileTool() {
75  }
76 
77 
78  void QnetFileTool::addTo(QMenu *menu) {
79  menu->addAction(m_openGround);
80  menu->addAction(m_openDem);
81  menu->addSeparator();
82  FileTool::addTo(menu);
83  }
84 
85 
86  ControlNet *QnetFileTool::controlNet() {
87  return m_qnetTool->controlNet();
88  }
89 
90 
91  SerialNumberList *QnetFileTool::serialNumberList() {
92  return m_qnetTool->serialNumberList();
93  }
94 
95 
119 
120  // If network already opened, prompt for saving
121  if (serialNumberList() != NULL && m_isDirty) {
122  // If control net has been changed , prompt for user to save
123  int resp = QMessageBox::warning((QWidget *)parent(), "Qnet",
124  "The control network files has been modified.\n"
125  "Do you want to save your changes?",
126  QMessageBox::Yes | QMessageBox::Default,
127  QMessageBox::No,
128  QMessageBox::Cancel | QMessageBox::Escape);
129  if (resp == QMessageBox::Yes) {
130  saveAs();
131  }
132  m_isDirty = false;
133  }
134 
135  QString filter = "List of cubes (*.lis *.lst *.list);;";
136  filter += "Text file (*.txt);;";
137  filter += "All (*)";
138  QString list = QFileDialog::getOpenFileName((QWidget *)parent(),
139  "Select a list of cubes",
140  ".",
141  filter);
142  if (list.isEmpty())
143  return;
144 
145  // Find directory and save for use in file dialog for net file
146  FileName file(list);
147  QString dir = file.path();
148 
149  QApplication::setOverrideCursor(Qt::WaitCursor);
150  // Use the list to get serial numbers and polygons
151  try {
152  *serialNumberList() = SerialNumberList(list);
153  *controlNet() = ControlNet();
154  }
155  catch (IException &e) {
156  QString message = "Error processing cube list. \n";
157  QString errors = e.toString();
158  message += errors;
159  QMessageBox::information((QWidget *)parent(), "Error", message);
160  QApplication::restoreOverrideCursor();
161  return;
162  }
163 
164  QApplication::restoreOverrideCursor();
165  filter = "Control net (*.net *.cnet *.ctl);;";
166  filter += "Pvl file (*.pvl);;";
167  filter += "Text file (*.txt);;";
168  filter += "All (*)";
169  QString cNetFileName = QFileDialog::getOpenFileName((QWidget *)parent(),
170  "Select a control network",
171  dir,
172  filter);
173  QApplication::setOverrideCursor(Qt::WaitCursor);
174  if (cNetFileName.isEmpty()) {
175  controlNet()->SetUserName(Application::UserName());
176 
177  // Determine target from first file in cube list
178  QScopedPointer<Cube> cube(new Cube());
179  cube->open(serialNumberList()->fileName(0));
180  controlNet()->SetTarget(*cube->label());
181  }
182  else {
183  try {
184  Progress progress;
185  *controlNet() = ControlNet(cNetFileName, &progress);
186  }
187  catch (IException &e) {
188  QString message = "Invalid control network. \n";
189  QString errors = e.toString();
190  message += errors;
191  QMessageBox::information((QWidget *)parent(), "Error", message);
192  QApplication::restoreOverrideCursor();
193  return;
194  }
195  }
196 
197  // Initialize cameras for control net
198  try {
199  Progress progress;
200  controlNet()->SetImages(*serialNumberList(), &progress);
201  }
202  catch (IException &e) {
203  QString message = "Cannot initialize images in control network. \n";
204  QString errors = e.toString();
205  message += errors;
206  QMessageBox::information((QWidget *)parent(), "Error", message);
207  QApplication::restoreOverrideCursor();
208  return;
209  }
210 
211  m_openGround->setEnabled(true);
212  m_openDem->setEnabled(true);
213 
214  QApplication::restoreOverrideCursor();
215 
216  m_cnetFileName = cNetFileName;
217  emit serialNumberListUpdated();
218  emit controlNetworkUpdated(cNetFileName);
219  emit newControlNetwork(controlNet());
220  }
221 
222 
227  // If control net has been changed , prompt for user to save
228  if (m_isDirty) {
229  int resp = QMessageBox::warning((QWidget *)parent(), "QnetTool",
230  "The control network files has been modified.\n"
231  "Do you want to save your changes?",
232  QMessageBox::Yes | QMessageBox::Default,
233  QMessageBox::No,
234  QMessageBox::Cancel | QMessageBox::Escape);
235  if (resp == QMessageBox::Yes) {
236  saveAs();
237  }
238  if (resp == QMessageBox::Cancel) {
239  return;
240  }
241  }
242  qApp->quit();
243  }
244 
245 
246 
257  controlNet()->Write(m_cnetFileName);
258  m_isDirty = false;
259  }
260 
261 
262 
273  QString filter = "Control net (*.net *.cnet *.ctl);;";
274  filter += "Pvl file (*.pvl);;";
275  filter += "Text file (*.txt);;";
276  filter += "All (*)";
277  QString fn = QFileDialog::getSaveFileName((QWidget *)parent(),
278  "Choose filename to save under",
279  ".", filter);
280  if (!fn.isEmpty()) {
281  try {
282  controlNet()->Write(fn);
283  }
284  catch (IException &e) {
285  QString message = "Error saving control network. \n";
286  QString errors = e.toString();
287  message += errors;
288  QMessageBox::information((QWidget *)parent(), "Error", message);
289  return;
290  }
291  }
292  else {
293  QMessageBox::information((QWidget *)parent(),
294  "Error", "Saving Aborted");
295  }
296  m_cnetFileName = fn;
297  emit controlNetworkUpdated(fn);
298  m_isDirty = false;
299  }
300 
320  void QnetFileTool::loadImage(const QString &serialNumber) {
321 
322  QString tempFileName = serialNumberList()->fileName(serialNumber);
323  QString filename = tempFileName;
324  QVector< MdiCubeViewport * > * cvpList = m_qnetTool->workspace()->cubeViewportList();
325  bool found = false;
326  for (int i = 0; i < (int)cvpList->size(); i++) {
327  QString sn = SerialNumber::Compose(*((*cvpList)[i]->cube()));
328  if (sn == serialNumber) {
329  m_qnetTool->workspace()->mdiArea()->setActiveSubWindow(
330  (QMdiSubWindow *)(*cvpList)[i]->parentWidget()->parent());
331  found = true;
332  break;
333  }
334  }
335  // If viewport doesn't already exist for this serial number, emit
336  // signal so that FileTool will add a viewport.
337  if (!found)
338  emit fileSelected(filename);
339  }
340 
351  for (int i = 0; i < point->GetNumMeasures(); i++) {
352  QString cubeSN = (*point)[i]->GetCubeSerialNumber();
353  loadImage(cubeSN);
354  }
355  }
356 
361  m_isDirty = true;
362  }
363 
364 
365 }
QPointer< QAction > saveAction()
Returns the save as action.
Definition: FileTool.h:67
void SetTarget(const QString &target)
Sets the target name and target radii, if available.
void fileSelected(QString)
This signal is called when a file is selected.
File name manipulation and expansion.
Definition: FileName.h:111
virtual void addTo(QMenu *menu)
Adds the file tool&#39;s actions to the menu.
QVector< MdiCubeViewport * > * cubeViewportList()
Repopulates the list of MdiCubeViewports and returns a pointer to this list.
Definition: Workspace.cpp:237
QPointer< QAction > openAction()
Returns the open action.
Definition: FileTool.h:63
void addTo(QMenu *menu)
Adds the file tool&#39;s actions to the menu.
Definition: FileTool.cpp:155
void loadImage(const QString &serialNumber)
Load given cube in Workspace.
void SetUserName(const QString &name)
Set the user name of the control network.
static QString Compose(Pvl &label, bool def2filename=false)
Compose a SerialNumber from a PVL.
QString fileName(const QString &sn)
Return a filename given a serial number.
Program progress reporter.
Definition: Progress.h:58
a control network
Definition: ControlNet.h:207
void setDirty()
Sets save net flag to true.
A single control point.
Definition: ControlPoint.h:339
void SetImages(const QString &imageListFile)
Creates the ControlNet&#39;s image cameras based on an input file.
virtual void exit()
Exit the program.
void loadPointImages(ControlPoint *point)
Load images for the given point.
QString toString() const
Returns a string representation of this exception.
Definition: IException.cpp:553
static QString UserName()
Returns the user name.
Isis exception class.
Definition: IException.h:99
virtual void saveAs()
Save control network with given file.
virtual void save()
Save control network with given file.
Qnet tool operations.
Definition: QnetTool.h:251
Serial Number list generator.
QString path() const
Returns the path.
Definition: FileName.cpp:88
virtual void open()
Open a list of cubes.
void Write(const QString &filename, bool pvl=false)
Writes out the control network.
Definition: ControlNet.cpp:302
IO Handler for Isis Cubes.
Definition: Cube.h:158

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:27:34