Isis 3.0 Programmer Reference
Back | Home
Workspace.cpp
1 #include "Workspace.h"
2 
3 #include <QMenuBar>
4 #include <QMessageBox>
5 #include <QProgressBar>
6 #include <QStatusBar>
7 #include <QToolBar>
8 #include <QVBoxLayout>
9 #include <QVector>
10 #include <QWeakPointer>
11 
12 #include "AdvancedTrackTool.h"
13 #include "BandTool.h"
14 #include "BlinkTool.h"
15 #include "Cube.h"
16 #include "CubeAttribute.h"
17 #include "EditTool.h"
18 #include "FeatureNomenclatureTool.h"
19 #include "FileName.h"
20 #include "FileTool.h"
21 #include "FindTool.h"
22 #include "HelpTool.h"
23 #include "HistogramTool.h"
24 #include "Image.h"
25 #include "ImageList.h"
26 #include "IString.h"
27 #include "MatchTool.h"
28 #include "MdiCubeViewport.h"
29 #include "MeasureTool.h"
30 #include "PanTool.h"
31 #include "RubberBandTool.h"
32 #include "QnetFileTool.h"
33 #include "QnetNavTool.h"
34 #include "QnetTool.h"
35 #include "ScatterPlotTool.h"
36 #include "SpatialPlotTool.h"
37 #include "SpecialPixelTool.h"
38 #include "SpectralPlotTool.h"
39 #include "StatisticsTool.h"
40 #include "StereoTool.h"
41 #include "StretchTool.h"
42 #include "SunShadowTool.h"
43 #include "TrackTool.h"
44 #include "ToolList.h"
45 #include "ToolPad.h"
46 #include "ViewportMdiSubWindow.h"
47 #include "WindowTool.h"
48 #include "ZoomTool.h"
49 
50 namespace Isis {
51 
57  Workspace::Workspace(bool selfContained, QWidget *parent) : QWidget(parent) {
58  m_cubeViewportList = NULL;
59  m_tools = NULL;
60 
61  m_cubeViewportList = new QVector< MdiCubeViewport * >;
62  m_tools = new ToolList;
63 
64  m_mdi = new QMdiArea(this);
65 
66  QGridLayout *layout = new QGridLayout;
67  setLayout(layout);
68 
69  if (!selfContained) {
70  layout->setContentsMargins(0, 0, 0, 0);
71  layout->addWidget(m_mdi, 0, 0);
72  }
73  else {
74  /*
75  * Layout:
76  *
77  * ----- MENU ----------------------
78  * -PERM TOOLBAR-ACTIVE TOOLBAR------
79  * | |T|
80  * | |O|
81  * | |O|
82  * | MDI AREA |L|
83  * | | |
84  * | |L|
85  * | |I|
86  * | |S|
87  * | |T|
88  * ------------Status Bar------------
89  *
90  * The perm/active tool bar are in an hbox layout, the rest follows the grid.
91  */
92  int row = 0;
93 
94  QMenuBar *menuBar = new QMenuBar;
95  layout->addWidget(menuBar, row, 0, 1, 2);
96  row++;
97 
98  QHBoxLayout *permActiveToolBarLayout = new QHBoxLayout;
99 
100  QToolBar *permToolBar = new QToolBar("Standard Tools", this);
101  permToolBar->setObjectName("permToolBar");
102  permToolBar->setIconSize(QSize(22, 22));
103  permActiveToolBarLayout->addWidget(permToolBar);
104 
105  QToolBar *activeToolBar = new QToolBar("Active Tool", this);
106  activeToolBar->setObjectName("activeToolBar");
107  activeToolBar->setIconSize(QSize(22, 22));
108  permActiveToolBarLayout->addWidget(activeToolBar);
109 
110  layout->addLayout(permActiveToolBarLayout, row, 0, 1, 2);
111  row++;
112 
113  layout->addWidget(m_mdi, row, 0, 1, 1);
114 
115  ToolPad *toolPad = new ToolPad("Tool Pad", this);
116  toolPad->setObjectName("toolPad");
117  toolPad->setOrientation(Qt::Vertical);
118  layout->addWidget(toolPad, row, 1, 1, 1);
119  row++;
120 
121  QStatusBar *statusBar = new QStatusBar(this);
122  layout->addWidget(statusBar, row, 0, 1, 2);
123  row++;
124 
125  // Create tools
126  Tool *defaultActiveTool = NULL;
127 
128  m_tools->append(new RubberBandTool(this));
129  QnetTool *qnetTool = new QnetTool(this);
130  //m_tools->append(new FileTool(this));
131  m_tools->append(new QnetFileTool(qnetTool, this));
132  m_tools->append(NULL);
133  m_tools->append(new BandTool(this));
134 
135  defaultActiveTool = new ZoomTool(this);
136  m_tools->append(defaultActiveTool);
137 
138  m_tools->append(new PanTool(this));
139  m_tools->append(new StretchTool(this));
140  m_tools->append(new FindTool(this));
141  m_tools->append(new BlinkTool(this));
142  m_tools->append(new AdvancedTrackTool(this));
143  m_tools->append(new EditTool(this));
144  m_tools->append(new WindowTool(this));
145  m_tools->append(new MeasureTool(this));
146  m_tools->append(new SunShadowTool(this));
147  m_tools->append(new FeatureNomenclatureTool(this));
148  m_tools->append(new SpecialPixelTool(this));
149  m_tools->append(new SpatialPlotTool(this));
150  m_tools->append(new SpectralPlotTool(this));
151  m_tools->append(new ScatterPlotTool(this));
152  m_tools->append(new HistogramTool(this));
153  m_tools->append(new StatisticsTool(this));
154  m_tools->append(new StereoTool(this));
155  m_tools->append(new MatchTool(this));
156  m_tools->append(new HelpTool(this));
157  m_tools->append(new TrackTool(statusBar));
158 
159  m_tools->append(new QnetNavTool(qnetTool, this));
160  m_tools->append(qnetTool);
161 
162  QMap<QString, QMenu *> subMenus;
163 
164  for (int i = 0; i < m_tools->count(); i++) {
165  Tool *tool = (*m_tools)[i];
166 
167  if (tool) {
168  tool->addTo(this);
169  tool->addToPermanent(permToolBar);
170  tool->addToActive(activeToolBar);
171  tool->addTo(toolPad);
172 
173  if (!tool->menuName().isEmpty()) {
174  QString menuName = tool->menuName();
175 
176  QMenu *subMenu = subMenus[menuName];
177 
178  if (!subMenu) {
179  subMenus[menuName] = menuBar->addMenu(menuName);
180  subMenu = subMenus[menuName];
181  }
182 
183  tool->addTo(subMenu);
184  }
185  }
186  else {
187  permToolBar->addSeparator();
188  }
189  }
190 
191  permToolBar->addSeparator();
192  defaultActiveTool->activate(true);
193  }
194 
195  connect(m_mdi, SIGNAL(subWindowActivated(QMdiSubWindow *)),
196  this, SLOT(activateViewport(QMdiSubWindow *)));
197  m_mdi->setActivationOrder(QMdiArea::ActivationHistoryOrder);
198  }
199 
200 
201  Workspace::Workspace(const Workspace &other) : m_cubeViewportList(NULL) {
202  m_cubeViewportList =
203  new QVector< MdiCubeViewport * >(*other.m_cubeViewportList);
204  }
205 
206 
207  Workspace::~Workspace() {
208  delete m_cubeViewportList;
209  m_cubeViewportList = NULL;
210 
211  delete m_tools;
212  m_tools = NULL;
213  }
214 
215 
222  if(w) {
223  emit cubeViewportActivated((MdiCubeViewport *) w->widget()->layout()->itemAt(0)->widget());
224  }
225  //Check if there is no current window (on close)
226  else if(!m_mdi->currentSubWindow()) {
227  emit cubeViewportActivated((MdiCubeViewport *)NULL);
228  }
229  }
230 
238  m_cubeViewportList->clear();
239 
240  for(int i = 0; i < m_mdi->subWindowList().size(); i++) {
241  m_cubeViewportList->push_back(
242  (MdiCubeViewport *)m_mdi->subWindowList()[i]->widget()->layout()->itemAt(0)->widget());
243  }
244 
245  return m_cubeViewportList;
246  }
247 
248 
249  Workspace &Workspace::operator=(Workspace other) {
250  delete m_cubeViewportList;
251  m_cubeViewportList = NULL;
252 
253  m_cubeViewportList = new QVector< MdiCubeViewport * >;
254  *m_cubeViewportList = *other.m_cubeViewportList;
255  return *this;
256  }
257 
258 
259  void Workspace::addImages(ImageList *images) {
260  foreach (Image *image, *images) {
261  addCubeViewport(image->cube());
262  }
263  }
264 
265 
266  bool Workspace::confirmClose() {
268 
269  bool confirmed = true;
270 
271  for (int viewportIndex = 0; confirmed && viewportIndex < viewports.count(); viewportIndex++) {
272  confirmed = viewports[viewportIndex]->confirmClose();
273  }
274 
275  return confirmed;
276  }
277 
278 
279  QWidget *Workspace::cubeToMdiWidget(Cube *cube) {
280  QWidget *result = NULL;
281 
282  for (int i = 0; !result && i < m_cubeViewportList->count(); i++) {
283  MdiCubeViewport *viewport = (*m_cubeViewportList)[i];
284 
285  if (viewport->cube() == cube) {
286  result = qobject_cast<QWidget *>(viewport->parent());
287  }
288  }
289 
290  return result;
291  }
292 
293 
294  QMdiArea *Workspace::mdiArea() {
295  return m_mdi;
296  }
297 
298 
326  void Workspace::addCubeViewport(QString cubename) {
327  Cube *cube = new Cube;
328 
329  //Read in the CubeAttribueInput from the cube name
330  CubeAttributeInput inAtt(cubename);
331  std::vector<QString> bands = inAtt.bands();
332 
333  //Set the virtual bands to the bands specified by the input
334  cube->setVirtualBands(bands);
335  cube->open(cubename);
336 
337  // this slot is connected to FileTool fileSelected signal
338  try {
339  MdiCubeViewport *cvp = addCubeViewport(cube);
340 
341  // Check for RGB format (#R,#G,#B)
342  if(bands.size() == 3) {
343  IString st = IString(bands.at(0));
344  int index_red = st.ToInteger();
345  st = IString(bands.at(1));
346  int index_green = st.ToInteger();
347  st = IString(bands.at(2));
348  int index_blue = st.ToInteger();
349  cvp->viewRGB(index_red, index_green, index_blue);
350  }
351  }
352  catch (IException &e) {
353  QMessageBox::critical((QWidget *)parent(), "Error", e.toString());
354  return;
355  }
356  }
357 
377  MdiCubeViewport *result = NULL;
378 
379  try {
380  ViewportMdiSubWindow *window(new ViewportMdiSubWindow(cube));
381  window->setAttribute(Qt::WA_DeleteOnClose);
382 
383  m_mdi->addSubWindow(window);
384 
385  window->show();
386 
387  result = window->viewport();
388  emit cubeViewportAdded(result);
389  }
390  catch(IException &e) {
391  throw IException(e,
393  tr("Error when attempting to show cube [%1]")
394  .arg(cube->fileName()),
395  _FILEINFO_);
396  }
397 
398  return result;
399  }
400 
401 
402  void Workspace::addBrowseView(QString cubename) {
403  /* Close the last browse window if necessary. */
404  if (m_mdi->subWindowList().size()) {
405  QPointer<QMdiSubWindow> windowToRemove =
406  m_mdi->subWindowList().last();
407 
408  m_mdi->removeSubWindow(windowToRemove.data());
409 
410  delete windowToRemove.data();
411  }
412 
413  addCubeViewport(cubename);
414  }
415 }
Cube display widget for certain Isis MDI applications.
Manipulate and parse attributes of input cube filenames.
void addToActive(QToolBar *toolbar)
Definition: Tool.cpp:112
Workspace(bool selfContained, QWidget *parent=0)
Workspace constructor.
Definition: Workspace.cpp:57
QVector< MdiCubeViewport * > * cubeViewportList()
Repopulates the list of MdiCubeViewports and returns a pointer to this list.
Definition: Workspace.cpp:237
Stretch image edit tool.
Definition: StretchTool.h:99
virtual void addToPermanent(QToolBar *toolbar)
Definition: Tool.h:111
Qisis Help Tool.
Definition: HelpTool.h:37
This tool is part of the Qisis namespace and displays the statusbar of the window.
Definition: TrackTool.h:42
int ToInteger() const
Returns the object string as an integer.
Definition: IString.cpp:733
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
Handles zoom operations for Isis qt apps.
Definition: ZoomTool.h:65
Interactive image edit tool.
Definition: EditTool.h:80
Tool for measuring distances.
Definition: MeasureTool.h:58
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
void setVirtualBands(const QList< QString > &vbands)
This allows the programmer to specify a subset of bands to work with.
Definition: Cube.cpp:993
Plot cube DN statistics against the cube band numbers.
void open(const QString &cfile, QString access="r")
This method will open an isis cube for reading or reading/writing.
Definition: Cube.cpp:509
void addTo(ViewportMainWindow *mw)
Adds the tool to the application.
Definition: Tool.cpp:78
This is an actual viewport window in qview/qnet/etc.
Rubber banding tool.
Display nomenclature on MDI Cube Viewports.
Qnet Navigation Tool.
Definition: QnetNavTool.h:131
void addCubeViewport(QString cube)
Add a cubeViewport to the workspace, open the cube.
Definition: Workspace.cpp:326
QString toString() const
Returns a string representation of this exception.
Definition: IException.cpp:553
Tool to locate a point on a cube that is projected and/or has a camera model.
Definition: FindTool.h:128
Isis exception class.
Definition: IException.h:99
Adds specific functionality to C++ strings.
Definition: IString.h:179
std::vector< QString > bands() const
Return a vector of the input bands specified.
Base class for the Qisis tools.
Definition: Tool.h:81
Tool for histograms.
Definition: HistogramTool.h:40
QString fileName() const
Returns the opened cube&#39;s filename.
Definition: Cube.cpp:1160
Tool for measuring shadow heights.
Definition: SunShadowTool.h:39
Scatter Plot Tool.
Qnet tool operations.
Definition: QnetTool.h:251
void activate(bool)
Activates the tool.
Definition: Tool.cpp:131
Sets the colors for the special pixel values.
Match tool operations.
Definition: MatchTool.h:211
Tool to display info for a point on a cube.
Tool for computing parallax.
Definition: StereoTool.h:57
Allows tools to share data between each other.
Definition: ToolList.h:46
void activateViewport(QMdiSubWindow *w)
This gets called when a window is activated or the workspace loses focus.
Definition: Workspace.cpp:221
virtual QString menuName() const
Anytime a tool is created, you must give it a name for the menu.
Definition: Tool.h:97
Qnet File operations.
Definition: QnetFileTool.h:85
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:31:50