Isis 3 Programmer Reference
Workspace.cpp
1#include "Workspace.h"
2
3#include <QMenuBar>
4#include <QMessageBox>
5#include <QProgressBar>
6#include <QStatusBar>
7#include <QString>
8#include <QToolBar>
9#include <QVBoxLayout>
10#include <QVector>
11#include <QWeakPointer>
12
13#include "AdvancedTrackTool.h"
14#include "BandTool.h"
15#include "BlinkTool.h"
16#include "Cube.h"
17#include "CubeAttribute.h"
18#include "EditTool.h"
19#include "FeatureNomenclatureTool.h"
20#include "FileName.h"
21#include "FileTool.h"
22#include "FindTool.h"
23#include "HelpTool.h"
24#include "HistogramTool.h"
25#include "Image.h"
26#include "ImageList.h"
27#include "IString.h"
28#include "MatchTool.h"
29#include "MdiCubeViewport.h"
30#include "MeasureTool.h"
31#include "PanTool.h"
32#include "RubberBandTool.h"
33#include "QnetFileTool.h"
34#include "QnetNavTool.h"
35#include "QnetTool.h"
36#include "ScatterPlotTool.h"
37#include "SpatialPlotTool.h"
38#include "SpecialPixelTool.h"
39#include "SpectralPlotTool.h"
40#include "StatisticsTool.h"
41#include "StereoTool.h"
42#include "StretchTool.h"
43#include "SunShadowTool.h"
44#include "TrackTool.h"
45#include "ToolList.h"
46#include "ToolPad.h"
47#include "ViewportMdiSubWindow.h"
48#include "WindowTool.h"
49#include "ZoomTool.h"
50
51namespace Isis {
52
58 Workspace::Workspace(bool selfContained, QWidget *parent) : QWidget(parent) {
59 m_cubeViewportList = NULL;
60 m_tools = NULL;
61
62 m_cubeViewportList = new QVector< MdiCubeViewport * >;
63 m_tools = new ToolList;
64
65 m_mdi = new QMdiArea(this);
66
67 QGridLayout *layout = new QGridLayout;
68 setLayout(layout);
69
70 if (!selfContained) {
71 layout->setContentsMargins(0, 0, 0, 0);
72 layout->addWidget(m_mdi, 0, 0);
73 }
74 else {
75 /*
76 * Layout:
77 *
78 * ----- MENU ----------------------
79 * -PERM TOOLBAR-ACTIVE TOOLBAR------
80 * | |T|
81 * | |O|
82 * | |O|
83 * | MDI AREA |L|
84 * | | |
85 * | |L|
86 * | |I|
87 * | |S|
88 * | |T|
89 * ------------Status Bar------------
90 *
91 * The perm/active tool bar are in an hbox layout, the rest follows the grid.
92 */
93 int row = 0;
94
95 QMenuBar *menuBar = new QMenuBar;
96 layout->addWidget(menuBar, row, 0, 1, 2);
97 row++;
98
99 QHBoxLayout *permActiveToolBarLayout = new QHBoxLayout;
100
101 QToolBar *permToolBar = new QToolBar("Standard Tools", this);
102 permToolBar->setObjectName("permToolBar");
103 permToolBar->setIconSize(QSize(22, 22));
104 permActiveToolBarLayout->addWidget(permToolBar);
105
106 QToolBar *activeToolBar = new QToolBar("Active Tool", this);
107 activeToolBar->setObjectName("activeToolBar");
108 activeToolBar->setIconSize(QSize(22, 22));
109 permActiveToolBarLayout->addWidget(activeToolBar);
110
111 layout->addLayout(permActiveToolBarLayout, row, 0, 1, 2);
112 row++;
113
114 layout->addWidget(m_mdi, row, 0, 1, 1);
115
116 ToolPad *toolPad = new ToolPad("Tool Pad", this);
117 toolPad->setObjectName("toolPad");
118 toolPad->setOrientation(Qt::Vertical);
119 layout->addWidget(toolPad, row, 1, 1, 1);
120 row++;
121
122 QStatusBar *statusBar = new QStatusBar(this);
123 layout->addWidget(statusBar, row, 0, 1, 2);
124 row++;
125
126 // Create tools
127 Tool *defaultActiveTool = NULL;
128
129 m_tools->append(new RubberBandTool(this));
130 QnetTool *qnetTool = new QnetTool(this);
131 //m_tools->append(new FileTool(this));
132 m_tools->append(new QnetFileTool(qnetTool, this));
133 m_tools->append(NULL);
134 m_tools->append(new BandTool(this));
135
136 defaultActiveTool = new ZoomTool(this);
137 m_tools->append(defaultActiveTool);
138
139 m_tools->append(new PanTool(this));
140 m_tools->append(new StretchTool(this));
141 m_tools->append(new FindTool(this));
142 m_tools->append(new BlinkTool(this));
143 m_tools->append(new AdvancedTrackTool(this));
144 m_tools->append(new EditTool(this));
145 m_tools->append(new WindowTool(this));
146 m_tools->append(new MeasureTool(this));
147 m_tools->append(new SunShadowTool(this));
148 m_tools->append(new FeatureNomenclatureTool(this));
149 m_tools->append(new SpecialPixelTool(this));
150 m_tools->append(new SpatialPlotTool(this));
151 m_tools->append(new SpectralPlotTool(this));
152 m_tools->append(new ScatterPlotTool(this));
153 m_tools->append(new HistogramTool(this));
154 m_tools->append(new StatisticsTool(this));
155 m_tools->append(new StereoTool(this));
156 m_tools->append(new MatchTool(this));
157 m_tools->append(new HelpTool(this));
158 m_tools->append(new TrackTool(statusBar));
159
160 m_tools->append(new QnetNavTool(qnetTool, this));
161 m_tools->append(qnetTool);
162
163 QMap<QString, QMenu *> subMenus;
164
165 for (int i = 0; i < m_tools->count(); i++) {
166 Tool *tool = (*m_tools)[i];
167
168 if (tool) {
169 tool->addTo(this);
170 tool->addToPermanent(permToolBar);
171 tool->addToActive(activeToolBar);
172 tool->addTo(toolPad);
173
174 if (!tool->menuName().isEmpty()) {
175 QString menuName = tool->menuName();
176
177 QMenu *subMenu = subMenus[menuName];
178
179 if (!subMenu) {
180 subMenus[menuName] = menuBar->addMenu(menuName);
181 subMenu = subMenus[menuName];
182 }
183
184 tool->addTo(subMenu);
185 }
186 }
187 else {
188 permToolBar->addSeparator();
189 }
190 }
191
192 permToolBar->addSeparator();
193 defaultActiveTool->activate(true);
194 }
195
196 connect(m_mdi, SIGNAL(subWindowActivated(QMdiSubWindow *)),
197 this, SLOT(activateViewport(QMdiSubWindow *)));
198 m_mdi->setActivationOrder(QMdiArea::ActivationHistoryOrder);
199 }
200
201
202 Workspace::Workspace(const Workspace &other) : m_cubeViewportList(NULL) {
204 new QVector< MdiCubeViewport * >(*other.m_cubeViewportList);
205 }
206
207
209 delete m_cubeViewportList;
210 m_cubeViewportList = NULL;
211
212 delete m_tools;
213 m_tools = NULL;
214 }
215
216
223 if(w) {
224 emit cubeViewportActivated((MdiCubeViewport *) w->widget()->layout()->itemAt(0)->widget());
225 }
226 //Check if there is no current window (on close)
227 else if(!m_mdi->currentSubWindow()) {
229 }
230 }
231
238 QVector< MdiCubeViewport * > * Workspace::cubeViewportList() {
239 m_cubeViewportList->clear();
240
241 for(int i = 0; i < m_mdi->subWindowList().size(); i++) {
242 m_cubeViewportList->push_back(
243 (MdiCubeViewport *)m_mdi->subWindowList()[i]->widget()->layout()->itemAt(0)->widget());
244 }
245
246 return m_cubeViewportList;
247 }
248
249
251 delete m_cubeViewportList;
252 m_cubeViewportList = NULL;
253
254 m_cubeViewportList = new QVector< MdiCubeViewport * >;
255 *m_cubeViewportList = *other.m_cubeViewportList;
256 return *this;
257 }
258
259
261 foreach (Image *image, *images) {
262 addCubeViewport(image->cube());
263 }
264 }
265
266
268 QVector< MdiCubeViewport * > viewports = *cubeViewportList();
269
270 bool confirmed = true;
271
272 for (int viewportIndex = 0; confirmed && viewportIndex < viewports.count(); viewportIndex++) {
273 confirmed = viewports[viewportIndex]->confirmClose();
274 }
275
276 return confirmed;
277 }
278
279
281 QWidget *result = NULL;
282
283 for (int i = 0; !result && i < m_cubeViewportList->count(); i++) {
284 MdiCubeViewport *viewport = (*m_cubeViewportList)[i];
285
286 if (viewport->cube() == cube) {
287 result = qobject_cast<QWidget *>(viewport->parent());
288 }
289 }
290
291 return result;
292 }
293
294
295 QMdiArea *Workspace::mdiArea() {
296 return m_mdi;
297 }
298
299
339 void Workspace::addCubeViewport(QString filename) {
340
341 QFileInfo cubeFileName(filename);
342
343 QString cubename = cubeFileName.filePath();
344
345 try {
346 Cube *cube = new Cube;
347
348 // Read in the CubeAttribueInput from the cube name
349 CubeAttributeInput inAtt(cubename);
350 std::vector<QString> bands = inAtt.bands();
351
352 // Set the virtual bands to the bands specified by the input
353 cube->setVirtualBands(bands);
354 cube->open(cubename);
355
356 MdiCubeViewport *cvp = addCubeViewport(cube);
357
358 // Check for RGB format (#R,#G,#B)
359 if(bands.size() == 3) {
360 IString st = IString(bands.at(0));
361 int index_red = st.ToInteger();
362 st = IString(bands.at(1));
363 int index_green = st.ToInteger();
364 st = IString(bands.at(2));
365 int index_blue = st.ToInteger();
366 cvp->viewRGB(index_red, index_green, index_blue);
367 }
368 }
369
370 catch (IException &e) {
371
372 QString message("Error opening cube [" + cubename + "]...\n");
373 message += "Attempting to open [" + cubename + "] as a cube list...\n";
374
375 try {
376 addCubeViewportFromList(cubename);
377 }
378 catch (IException &e) {
379 message += e.toString();
380 throw IException(e, IException::User, message, _FILEINFO_);
381 }
382
383 }
384 }
385
391 void Workspace::addCubeViewportFromList(QString cubelist) {
392
393 QFileInfo cubeFileName(cubelist);
394
395 QList<QString> cubesToOpen;
396
397 QFile file(cubeFileName.filePath());
398 file.open(QIODevice::ReadOnly);
399
400 QTextStream in(&file);
401
402 // Loop through every cube name in the cube list and add it to a list of cubes to open.
403 while ( !file.atEnd() ) {
404 QString line = file.readLine().replace("\n", "");
405 cubesToOpen.append(line);
406 }
407
408 file.close();
409
410 for (int i = 0; i < cubesToOpen.size(); i++) {
411
412 QString cubename;
413 try {
414 Cube *cube = new Cube;
415 cubename = cubesToOpen.at(i);
416
417 // Read in the CubeAttribueInput from the cube name
418 CubeAttributeInput inAtt(cubename);
419 std::vector<QString> bands = inAtt.bands();
420
421 // Set the virtual bands to the bands specified by the input
422 cube->setVirtualBands(bands);
423 cube->open(cubename);
424
425 MdiCubeViewport *cvp = addCubeViewport(cube);
426
427 // Check for RGB format (#R,#G,#B)
428 if(bands.size() == 3) {
429 IString st = IString(bands.at(0));
430 int index_red = st.ToInteger();
431 st = IString(bands.at(1));
432 int index_green = st.ToInteger();
433 st = IString(bands.at(2));
434 int index_blue = st.ToInteger();
435 cvp->viewRGB(index_red, index_green, index_blue);
436 }
437 }
438 catch (IException &e) {
439 QString message("Error attempting to open [" + cubename + "] from list [" + cubelist + "]...\n");
440
441 throw IException(e, IException::User, message, _FILEINFO_);
442 }
443 }
444 }
445
465 MdiCubeViewport *result = NULL;
466
467 try {
469 window->setAttribute(Qt::WA_DeleteOnClose);
470
471 m_mdi->addSubWindow(window);
472
473 window->show();
474
475 result = window->viewport();
476 emit cubeViewportAdded(result);
477 }
478 catch(IException &e) {
479 throw IException(e,
481 tr("Error when attempting to show cube [%1]")
482 .arg(cube->fileName()),
483 _FILEINFO_);
484 }
485
486 return result;
487 }
488
489
490 void Workspace::addBrowseView(QString cubename) {
491 /* Close the last browse window if necessary. */
492 if (m_mdi->subWindowList().size()) {
493 QPointer<QMdiSubWindow> windowToRemove =
494 m_mdi->subWindowList().last();
495
496 m_mdi->removeSubWindow(windowToRemove.data());
497
498 delete windowToRemove.data();
499 }
500
501 addCubeViewport(cubename);
502 }
503}
Tool to display info for a point on a cube.
Manipulate and parse attributes of input cube filenames.
IO Handler for Isis Cubes.
Definition Cube.h:168
void open(const QString &cfile, QString access="r")
This method will open an existing isis cube for reading or reading/writing.
Definition Cube.cpp:622
void setVirtualBands(const QList< QString > &vbands)
This allows the programmer to specify a subset of bands to work with.
Definition Cube.cpp:1327
virtual QString fileName() const
Returns the opened cube's filename.
Definition Cube.cpp:1569
Cube * cube() const
Interactive image edit tool.
Definition EditTool.h:70
Display nomenclature on MDI Cube Viewports.
Tool to locate a point on a cube that is projected and/or has a camera model.
Definition FindTool.h:115
Qisis Help Tool.
Definition HelpTool.h:26
Tool for histograms.
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Adds specific functionality to C++ strings.
Definition IString.h:165
This represents a cube in a project-based GUI interface.
Definition Image.h:107
Cube * cube()
Get the Cube pointer associated with this display property.
Definition Image.cpp:287
Internalizes a list of images and allows for operations on the entire list.
Definition ImageList.h:55
Match tool operations.
Definition MatchTool.h:216
Cube display widget for certain Isis MDI applications.
Tool for measuring distances.
Definition MeasureTool.h:58
Qnet File operations.
Qnet Navigation Tool.
Qnet tool operations.
Definition QnetTool.h:259
Rubber banding tool.
Scatter Plot Tool.
Sets the colors for the special pixel values.
Plot cube DN statistics against the cube band numbers.
Tool for computing parallax.
Definition StereoTool.h:59
Stretch image edit tool.
Definition StretchTool.h:85
Tool for measuring shadow heights.
Base class for the Qisis tools.
Definition Tool.h:67
void addTo(ViewportMainWindow *mw)
Adds the tool to the application.
Definition Tool.cpp:78
Allows tools to share data between each other.
Definition ToolList.h:32
This tool is part of the Qisis namespace and displays the statusbar of the window.
Definition TrackTool.h:43
This is an actual viewport window in qview/qnet/etc.
Workspace & operator=(Workspace other)
Is equal to comparsion.
virtual ~Workspace()
Deconstructor.
QMdiArea * mdiArea()
This method returns the QMdiArea.
QPointer< QMdiArea > m_mdi
The mdi area.
Definition Workspace.h:202
void cubeViewportActivated(MdiCubeViewport *)
Signal triggered when a Cube is activated in the Workspace.
void addCubeViewport(QString cubename)
Method adds the name of a cube into Workspace as a CubeViewport.
QWidget * cubeToMdiWidget(Cube *cube)
Converts a cube to an MdiWidget.
bool confirmClose()
Confirms that the user wishes toc lose the Workspace.
void cubeViewportAdded(MdiCubeViewport *)
Signal triggered when a Cube is added to the Workspace.
void addCubeViewportFromList(QString cubelist)
Method adds cubes into Workspace as a CubeViewport from a list of cubes.
void addBrowseView(QString cube)
Method is called to add a Cube from BrowseView.
ToolList * m_tools
List of all of the tools.
Definition Workspace.h:206
QVector< MdiCubeViewport * > * m_cubeViewportList
List of cube viewports.
Definition Workspace.h:204
Workspace(bool selfContained, QWidget *parent=0)
Constructor for Workspace.
Definition Workspace.cpp:58
void addImages(ImageList *images)
Adds a list of Images to a viewport.
QVector< MdiCubeViewport * > * cubeViewportList()
This method returns a Vector of MdiCubeViewports.
void activateViewport(QMdiSubWindow *w)
This method activates the Viewport.
Handles zoom operations for Isis qt apps.
Definition ZoomTool.h:56
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16