Isis 3 Programmer Reference
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 
234  void QnetFileTool::exit(QCloseEvent *event) {
235  // If control net has been changed , prompt for user to save
236  if (m_isDirty) {
237  int resp = QMessageBox::warning((QWidget *)parent(), "QnetTool",
238  "The control network files has been modified.\n"
239  "Do you want to save your changes?",
240  QMessageBox::Yes | QMessageBox::Default,
241  QMessageBox::No,
242  QMessageBox::Cancel | QMessageBox::Escape);
243  if (resp == QMessageBox::Yes) {
244  saveAs();
245  }
246  if (resp == QMessageBox::Cancel) {
247  if (event) {
248  event->setAccepted(false);
249  }
250  return;
251  }
252  }
253  qApp->quit();
254  }
255 
266  controlNet()->Write(m_cnetFileName);
267  m_isDirty = false;
268  }
269 
270 
271 
282  QString filter = "Control net (*.net *.cnet *.ctl);;";
283  filter += "Pvl file (*.pvl);;";
284  filter += "Text file (*.txt);;";
285  filter += "All (*)";
286  QString fn = QFileDialog::getSaveFileName((QWidget *)parent(),
287  "Choose filename to save under",
288  ".", filter);
289  if (!fn.isEmpty()) {
290  try {
291  controlNet()->Write(fn);
292  }
293  catch (IException &e) {
294  QString message = "Error saving control network. \n";
295  QString errors = e.toString();
296  message += errors;
297  QMessageBox::information((QWidget *)parent(), "Error", message);
298  return;
299  }
300  }
301  else {
302  QMessageBox::information((QWidget *)parent(),
303  "Error", "Saving Aborted");
304  }
305  m_cnetFileName = fn;
306  emit controlNetworkUpdated(fn);
307  m_isDirty = false;
308  }
309 
329  void QnetFileTool::loadImage(const QString &serialNumber) {
330 
331  QString tempFileName = serialNumberList()->fileName(serialNumber);
332  QString filename = tempFileName;
333  QVector< MdiCubeViewport * > * cvpList = m_qnetTool->workspace()->cubeViewportList();
334  bool found = false;
335  for (int i = 0; i < (int)cvpList->size(); i++) {
336  QString sn = SerialNumber::Compose(*((*cvpList)[i]->cube()));
337  if (sn == serialNumber) {
338  m_qnetTool->workspace()->mdiArea()->setActiveSubWindow(
339  (QMdiSubWindow *)(*cvpList)[i]->parentWidget()->parent());
340  found = true;
341  break;
342  }
343  }
344  // If viewport doesn't already exist for this serial number, emit
345  // signal so that FileTool will add a viewport.
346  if (!found)
347  emit fileSelected(filename);
348  }
349 
360  for (int i = 0; i < point->GetNumMeasures(); i++) {
361  QString cubeSN = (*point)[i]->GetCubeSerialNumber();
362  loadImage(cubeSN);
363  }
364  }
365 
370  m_isDirty = true;
371  }
372 
373 
374 }
Isis::QnetFileTool::saveAs
virtual void saveAs()
Save control network with given file.
Definition: QnetFileTool.cpp:281
QWidget
Isis::FileTool::saveAction
QPointer< QAction > saveAction()
Definition: FileTool.h:72
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::FileTool::addTo
void addTo(QMenu *menu)
Adds the file tool's actions to the menu.
Definition: FileTool.cpp:169
QMenu
Isis::ControlNet::SetTarget
void SetTarget(const QString &target)
Sets the target name and target radii, if available.
Definition: ControlNet.cpp:1692
Isis::ControlNet::Write
void Write(const QString &filename, bool pvl=false)
Writes out the control network.
Definition: ControlNet.cpp:311
Isis::SerialNumber::Compose
static QString Compose(Pvl &label, bool def2filename=false)
Compose a SerialNumber from a PVL.
Definition: SerialNumber.cpp:38
Isis::QnetFileTool::save
virtual void save()
Save control network with given file.
Definition: QnetFileTool.cpp:265
Isis::SerialNumberList
Serial Number list generator.
Definition: SerialNumberList.h:64
Isis::QnetFileTool::loadPointImages
void loadPointImages(ControlPoint *point)
Load images for the given point.
Definition: QnetFileTool.cpp:359
Isis::ControlPoint
A single control point.
Definition: ControlPoint.h:354
Isis::ControlNet::SetUserName
void SetUserName(const QString &name)
Set the user name of the control network.
Definition: ControlNet.cpp:1730
Isis::FileTool::openAction
QPointer< QAction > openAction()
Definition: FileTool.h:68
Isis::Workspace::mdiArea
QMdiArea * mdiArea()
This method returns the QMdiArea.
Definition: Workspace.cpp:295
Isis::IException::toString
QString toString() const
Returns a string representation of this exception.
Definition: IException.cpp:537
Isis::FileTool::fileSelected
void fileSelected(QString)
This signal is called when a file is selected.
Isis::ControlNet::SetImages
void SetImages(const QString &imageListFile)
Creates the ControlNet's image cameras based on an input file.
Definition: ControlNet.cpp:1566
Isis::QnetTool
Qnet tool operations.
Definition: QnetTool.h:256
Isis::ControlNet
a control network
Definition: ControlNet.h:257
Isis::Cube
IO Handler for Isis Cubes.
Definition: Cube.h:167
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::QnetFileTool::open
virtual void open()
Open a list of cubes.
Definition: QnetFileTool.cpp:118
Isis::FileTool::exit
virtual void exit()
Exit the program, this slot called when the exit is chosen from the File menu.
Definition: FileTool.cpp:972
Isis::Progress
Program progress reporter.
Definition: Progress.h:42
Isis::QnetFileTool::addTo
virtual void addTo(QMenu *menu)
Adds the file tool's actions to the menu.
Definition: QnetFileTool.cpp:78
Isis::FileTool
Definition: FileTool.h:59
std
Namespace for the standard library.
Isis::QnetFileTool::setDirty
void setDirty()
Sets save net flag to true.
Definition: QnetFileTool.cpp:369
Isis::Workspace::cubeViewportList
QVector< MdiCubeViewport * > * cubeViewportList()
This method returns a Vector of MdiCubeViewports.
Definition: Workspace.cpp:238
Isis::QnetFileTool::loadImage
void loadImage(const QString &serialNumber)
Load given cube in Workspace.
Definition: QnetFileTool.cpp:329
Isis::SerialNumberList::fileName
QString fileName(const QString &sn)
Return a filename given a serial number.
Definition: SerialNumberList.cpp:399
QMdiSubWindow
Isis::Application::UserName
static QString UserName()
Returns the user name.
Definition: Application.cpp:816
QVector
This is free and unencumbered software released into the public domain.
Definition: Calculator.h:18
QAction
Isis::FileName::path
QString path() const
Returns the path of the file name.
Definition: FileName.cpp:103
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16