Isis 3 Programmer Reference
CubeDnView.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "CubeDnView.h"
10
11#include <QAction>
12#include <QDebug>
13#include <QHBoxLayout>
14#include <QKeySequence>
15#include <QMap>
16#include <QMdiArea>
17#include <QMdiSubWindow>
18#include <QMenu>
19#include <QMenuBar>
20#include <QModelIndex>
21#include <QSize>
22#include <QStatusBar>
23#include <QToolBar>
24#include <QToolButton>
25#include <QVBoxLayout>
26#include <QWidgetAction>
27#include <QXmlStreamWriter>
28
29#include "AdvancedTrackTool.h"
30#include "BandTool.h"
31#include "BlinkTool.h"
32#include "Cube.h"
33#include "CubeAttribute.h"
34#include "Directory.h"
35#include "EditTool.h"
36#include "FeatureNomenclatureTool.h"
37#include "FileName.h"
38#include "FileTool.h"
39#include "FindTool.h"
40#include "HistogramTool.h"
41#include "Image.h"
42#include "ImageList.h"
43#include "ControlNetTool.h"
44#include "IString.h"
45#include "MatchTool.h"
46#include "MdiCubeViewport.h"
47#include "MeasureTool.h"
48#include "PanTool.h"
49#include "Project.h"
50#include "ProjectItem.h"
51#include "ProjectItemModel.h"
52#include "ProjectItemProxyModel.h"
53#include "RubberBandTool.h"
54#include "ScatterPlotTool.h"
55#include "Shape.h"
56#include "SpatialPlotTool.h"
57#include "SpecialPixelTool.h"
58#include "SpectralPlotTool.h"
59#include "StatisticsTool.h"
60#include "StereoTool.h"
61#include "StretchTool.h"
62#include "SunShadowTool.h"
63#include "TrackTool.h"
64#include "ToolList.h"
65#include "ToolPad.h"
66
67#include "ViewportMdiSubWindow.h"
68#include "Workspace.h"
69#include "WindowTool.h"
70#include "ZoomTool.h"
71
72#include "ProjectItemViewMenu.h"
73
74namespace Isis {
82 connect( internalModel()->selectionModel(),
83 SIGNAL( currentChanged(const QModelIndex &, const QModelIndex &) ),
84 this, SLOT( onCurrentChanged(const QModelIndex &) ) );
85
86 connect( internalModel(), SIGNAL( itemAdded(ProjectItem *) ),
87 this, SLOT( onItemAdded(ProjectItem *) ) );
88
89 m_cubeItemMap = QMap<Cube *, ProjectItem *>();
90
91 m_workspace = new Workspace(false, this);
92 m_workspace->mdiArea()->setActivationOrder(QMdiArea::StackingOrder);
93
94 m_directory = directory;
95
96 // Since this is a QMainWindow, set the workspace as the central widget.
97 setCentralWidget(m_workspace);
98
99 createActions(directory);
100
101 connect(m_workspace, SIGNAL( cubeViewportActivated(MdiCubeViewport *) ),
102 this, SLOT( onCubeViewportActivated(MdiCubeViewport *) ) );
103
104 connect(m_workspace, SIGNAL( cubeViewportAdded(MdiCubeViewport *) ),
105 this, SLOT( onCubeViewportAdded(MdiCubeViewport *) ) );
106 }
107
108
109 void CubeDnView::createActions(Directory *directory) {
110
111 m_permToolBar = new QToolBar("Standard Tools", this);
112 m_permToolBar->setObjectName("permToolBar");
113 m_permToolBar->setIconSize(QSize(22, 22));
114 addToolBar(m_permToolBar);
115
116 m_activeToolBar = new QToolBar("Active Tool", this);
117 m_activeToolBar->setObjectName("activeToolBar");
118 m_activeToolBar->setIconSize(QSize(22, 22));
119 addToolBar(m_activeToolBar);
120
121 m_toolPad = new ToolPad("Tool Pad", this);
122 m_toolPad->setObjectName("toolPad");
123 addToolBar(Qt::RightToolBarArea, m_toolPad);
124
125 // Create tools
126 ToolList *tools = new ToolList;
127
128 tools->append(new RubberBandTool(this));
129
130 // 2018-07-02 Kaitlyn Lee - Commented this out; not sure why it was here
131 //tools->append(NULL);
132
133 ControlNetTool *controlNetTool = new ControlNetTool(directory, this);
134 tools->append(controlNetTool);
135
136 if (directory->project()->activeControl()) {
137 controlNetTool->setControlNet(directory->project()->activeControl()->controlNet());
138 }
139 // Pass on Signals emitted from ControlNetTool
140 // TODO 2016-09-09 TLS Design: Use a proxy model instead of signals?
141 connect(controlNetTool, SIGNAL(modifyControlPoint(ControlPoint *, QString)),
142 this, SIGNAL(modifyControlPoint(ControlPoint *, QString)));
143
144 connect(controlNetTool, SIGNAL(deleteControlPoint(ControlPoint *)),
145 this, SIGNAL(deleteControlPoint(ControlPoint *)));
146
147 connect(controlNetTool, SIGNAL(createControlPoint(double, double, Cube *, bool)),
148 this, SIGNAL(createControlPoint(double, double, Cube *, bool)));
149
150 // Pass on signals emitted from Directory (by way of ControlPointEditWidget)
151 // This is done to redraw the control points on the cube viewports
152 connect(this, SIGNAL(controlPointAdded(QString)), controlNetTool, SLOT(paintAllViewports()));
153
154 // Pass on redrawMeasure signal from Directory, so the control measures are redrawn on all
155 // CubeViewports.
156 connect(this, SIGNAL(redrawMeasures()), controlNetTool, SLOT(paintAllViewports()));
157
158 tools->append(new BandTool(this));
159 ZoomTool *zoomTool = new ZoomTool(this);
160 tools->append(zoomTool);
161 tools->append(new PanTool(this));
162 tools->append(new StretchTool(this));
163 tools->append(new FindTool(this));
164 tools->append(new BlinkTool(this));
165 tools->append(new AdvancedTrackTool(this));
166 tools->append(new EditTool(this));
167 tools->append(new WindowTool(this));
168 tools->append(new MeasureTool(this));
169 tools->append(new SunShadowTool(this));
170 tools->append(new FeatureNomenclatureTool(this));
171 tools->append(new SpecialPixelTool(this));
172 tools->append(new SpatialPlotTool(this));
173 tools->append(new SpectralPlotTool(this));
174 tools->append(new ScatterPlotTool(this));
175 tools->append(new HistogramTool(this));
176 tools->append(new StatisticsTool(this));
177 tools->append(new StereoTool(this));
178 tools->append(new TrackTool(statusBar()));
179
180 m_separatorAction = new QAction(this);
181 m_separatorAction->setSeparator(true);
182
183 m_viewMenu = new ProjectItemViewMenu("&View");
184 connect(m_viewMenu, SIGNAL(menuClosed()), this, SLOT(disableActions()));
185 menuBar()->addMenu(m_viewMenu);
186
187 m_optionsMenu = new ProjectItemViewMenu("&Options");
188 connect(m_optionsMenu, SIGNAL(menuClosed()), this, SLOT(disableActions()));
189 menuBar()->addMenu(m_optionsMenu);
190
191 m_windowMenu = new ProjectItemViewMenu("&Window");
192 connect(m_windowMenu, SIGNAL(menuClosed()), this, SLOT(disableActions()));
193 menuBar()->addMenu(m_windowMenu);
194
195 for (int i = 0; i < tools->count(); i++) {
196 Tool *tool = (*tools)[i];
197
198 if (tool) {
199 tool->addTo(m_workspace);
200 tool->addToPermanent(m_permToolBar);
201 tool->addToActive(m_activeToolBar);
202 tool->addTo(m_toolPad);
203
204 if (!tool->menuName().isEmpty()) {
205 QString menuName = tool->menuName();
206
207 if (menuName == "&View") {
208 tool->addTo(m_viewMenu);
209 }
210 else if (menuName == "&Options") {
211 tool->addTo(m_optionsMenu);
212 }
213 else if (menuName == "&Window") {
214 tool->addTo(m_windowMenu);
215 }
216 }
217 }
218 else {
219 m_permToolBar->addSeparator();
220 }
221 }
222
223 // Store the actions and widgets for easy enable/disable.
224 foreach (QAction *action, findChildren<QAction *>()) {
225 // Remove the edit tool's save button shortcut because the ipce main window
226 // already has one and this causes an ambiquous shortcut error.
227 if (action->toolTip() == "Save") {
228 action->setShortcut(QKeySequence());
229 }
230 // The active toolbar's actions are inside of a container that is a QWidgetAction.
231 // We want to skip adding this because we want to disable the active toolbar's
232 // actions separately to skip the combo boxes.
233 if (QString(action->metaObject()->className()) == "QWidgetAction") {
234 continue;
235 }
236 addAction(action);
237 }
238
239 // There was a problem with disabling/enabling the combo boxes. The only way to
240 // get this to work was to skip disabling the combo boxes. We also skip QWidgets
241 // because the combo boxes are contained inside of a QWidget.
242 foreach (QWidget *child, m_activeToolBar->findChildren<QWidget *>()) {
243 if (QString(child->metaObject()->className()).contains("ComboBox") ||
244 QString(child->metaObject()->className()).contains("Widget")) {
245 continue;
246 }
247 m_childWidgets.append(child);
248 }
249
250 // On default, actions are disabled until the cursor enters the view.
252
253 zoomTool->activate(true);
254 }
255
256
265 void CubeDnView::leaveEvent(QEvent *event) {
266 if (m_optionsMenu->isVisible() || m_viewMenu->isVisible() || m_windowMenu->isVisible()) {
267 return;
268 }
269 // Find the toolpad actions (buttons) with menus and check if they are visible
270 foreach (QToolButton *button, findChildren<QToolButton *>()) {
271 if (button->menu() && button->menu()->isVisible()) {
272 return;
273 }
274 }
276 }
277
278
283 foreach (QAction *action, actions()) {
284 action->setDisabled(true);
285 }
286 foreach (QWidget *widget, m_childWidgets) {
287 widget->setDisabled(true);
288 }
289 }
290
291
297 foreach (QAction *action, actions()) {
298 if (action->objectName() == "ControlNetTool" && !m_directory->project()->activeControl()) {
299 continue;
300 }
301 action->setEnabled(true);
302 }
303 foreach (QWidget *widget, m_childWidgets) {
304 widget->setEnabled(true);
305 }
306 }
307
308
317 foreach (QAction *action, m_toolPad->actions()) {
318 if (action->objectName() == "ControlNetTool") {
319 action->setEnabled(value);
320 if (value) {
321 ControlNetTool *cnetTool = static_cast<ControlNetTool *>(action->parent());
322 cnetTool->loadNetwork();
323 }
324 }
325 }
326 }
327
332 delete m_permToolBar;
333 delete m_activeToolBar;
334 delete m_toolPad;
335 delete m_viewMenu;
336 delete m_optionsMenu;
337 delete m_windowMenu;
338
339
340 m_permToolBar = 0;
341 m_activeToolBar = 0;
342 m_toolPad = 0;
343 m_viewMenu = 0;
344 m_optionsMenu = 0;
345 m_windowMenu = 0;
346 }
347
348
356 if ( !item->isImageList() && !item->isImage() && !item->isShapeList() && !item->isShape()) {
357 return;
358 }
359
361 }
362
363
364 bool CubeDnView::viewportContainsShape(MdiCubeViewport *viewport) {
365
366 ProjectItem *item = m_cubeItemMap.value( viewport->cube() );
367
368 if (!item) {
369 return false;
370 }
371
372 return item->isShape();
373 }
374
382 void CubeDnView::onCurrentChanged(const QModelIndex &current) {
383
384 ProjectItem *item = internalModel()->itemFromIndex(current);
385
386 if (!item) {
387 return;
388 }
389
390 if (!item->isImage()) {
391 return;
392 }
393
395 }
396
397
406 if ( !isVisible() ) {
407 return;
408 }
409
410 if (!viewport) {
411 return;
412 }
413
414 ProjectItem *item = m_cubeItemMap.value( viewport->cube() );
415
416 if (!item) {
417 return;
418 }
419
420 internalModel()->selectionModel()->setCurrentIndex(item->index(),
421 QItemSelectionModel::SelectCurrent);
422 }
423
424
433 connect(viewport, SIGNAL( destroyed(QObject *) ),
434 this, SLOT( onCubeViewportDeleted(QObject *) ) );
435 }
436
437
445 MdiCubeViewport *viewport = qobject_cast<MdiCubeViewport *>(obj);
446
447 if (!viewport) {
448 return;
449 }
450
451 if ( ProjectItemProxyModel *proxyModel =
452 qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
453 proxyModel->removeItem( m_cubeItemMap.value( viewport->cube() ) );
454 }
455 }
456
457
466
467 if (!item) {
468 return;
469 }
470 Cube *cube;
471 if (item->isImage()) {
472 cube = item->image()->cube();
473 }
474 else if (item->isShape()) {
475 cube = item->shape()->cube();
476 }
477 else {
478 return;
479 }
480 if (m_workspace->cubeToMdiWidget(cube)) {
481 return;
482 }
484 m_cubeItemMap.insert(cube, item);
485 }
486
487
495 QMdiArea *mdiArea = m_workspace->mdiArea();
496 ViewportMdiSubWindow *subWindow = qobject_cast<ViewportMdiSubWindow *>( mdiArea->currentSubWindow() );
497 if (!subWindow) {
498 return 0;
499 }
500 MdiCubeViewport *viewport = subWindow->viewport();
501 return viewport->cube();
502 }
503
504
509 if (!image) {
510 return;
511 }
512
513 QWidget *mdiWidget = m_workspace->cubeToMdiWidget(image->cube());
514
515 if (!mdiWidget) {
516 return;
517 }
518
519 QMdiSubWindow *subWindow = qobject_cast<QMdiSubWindow *>( mdiWidget->parent() );
520
521 if (!subWindow) {
522 return;
523 }
524
525 subWindow->raise();
526
527 // Activating the subwindow activates the view, which is annoying
528 //m_workspace->mdiArea()->setActiveSubWindow(subWindow);
529 }
530
531
532 void CubeDnView::save(QXmlStreamWriter &stream, Project *, FileName) const {
533 stream.writeStartElement("cubeDnView");
534 stream.writeAttribute("objectName", objectName());
535
536 foreach (MdiCubeViewport *cvp, *(m_workspace->cubeViewportList())) {
537 ProjectItem *item = m_cubeItemMap.value(cvp->cube());
538 if (item->isImage()) {
539 stream.writeStartElement("image");
540 stream.writeAttribute("id", item->image()->id());
541 }
542 else if (item->isShape()) {
543 stream.writeStartElement("shape");
544 stream.writeAttribute("id", item->shape()->id());
545 }
546 stream.writeEndElement();
547 }
548 stream.writeEndElement();
549 }
550}
AbstractProjectItemView is a base class for views of a ProjectItemModel in Qt's model-view framework.
virtual void addItem(ProjectItem *item)
Adds an item to the view.
virtual ProjectItemModel * internalModel()
Returns the internal model of the view.
Tool to display info for a point on a cube.
ControlNet * controlNet()
Open and return a pointer to the ControlNet for this Control.
Definition Control.cpp:130
ControlNetTool Handles mouse events on CubeDnViews for control point editing for the ipce app.
A single control point.
void onCubeViewportActivated(MdiCubeViewport *)
Slot to connect to the cubeViewportActivated signal from the Workspace.
void disableActions()
Disables toolbars and toolpad actions/widgets.
ProjectItemViewMenu * m_windowMenu
Window menu for storing actions.
Definition CubeDnView.h:143
ProjectItemViewMenu * m_viewMenu
View menu for storing actions.
Definition CubeDnView.h:141
void leaveEvent(QEvent *event)
Disables actions when the cursor leaves the view.
QMap< Cube *, ProjectItem * > m_cubeItemMap
Maps cubes to their items.
Definition CubeDnView.h:137
void onCurrentChanged(const QModelIndex &current)
Slot to connect to the currentChanged() signal from a selection model.
QToolBar * m_permToolBar
A tool bar for storing actions.
Definition CubeDnView.h:147
ProjectItemViewMenu * m_optionsMenu
Options menu for storing actions.
Definition CubeDnView.h:142
void addItem(ProjectItem *item)
Adds an item to the view.
Directory * m_directory
The directory.
Definition CubeDnView.h:139
Cube * workspaceActiveCube()
Returns the cube of the active viewport in the Workspace, or a null pointer if no viewports are activ...
ToolPad * m_toolPad
A tool bar for storing actions.
Definition CubeDnView.h:149
void enableActions()
Enables toolbars and toolpad actions/widgets.
void onItemAdded(ProjectItem *item)
Slot to connect to the itemAdded signal from a ProjectItemModel.
Workspace * m_workspace
The workspace.
Definition CubeDnView.h:138
QList< QWidget * > m_childWidgets
Child widgets of the active toolbar.
Definition CubeDnView.h:150
CubeDnView(Directory *directory, QWidget *parent=0)
Constructs the view, initializing the tools.
~CubeDnView()
Destructor.
QToolBar * m_activeToolBar
A tool bar for storing actions.
Definition CubeDnView.h:148
void onCubeViewportDeleted(QObject *obj)
Slot to connect to the destroyed signal from a viewport.
void onCubeViewportAdded(MdiCubeViewport *viewport)
Slot to connect to the viewportAdded signal from a Workspace.
void setWorkspaceActiveCube(Image *image)
Raises the subwindow corresponding with an image to the top.
QAction * m_separatorAction
A separator action that is reused.
Definition CubeDnView.h:145
void enableControlNetTool(bool value)
A slot function that is called when directory emits a signal that an active control network is set.
IO Handler for Isis Cubes.
Definition Cube.h:168
Cube * cube() const
Project * project() const
Gets the Project for this directory.
Interactive image edit tool.
Definition EditTool.h:70
Display nomenclature on MDI Cube Viewports.
File name manipulation and expansion.
Definition FileName.h:100
Tool to locate a point on a cube that is projected and/or has a camera model.
Definition FindTool.h:115
Tool for histograms.
This represents a cube in a project-based GUI interface.
Definition Image.h:105
Cube * cube()
Get the Cube pointer associated with this display property.
Definition Image.cpp:262
QString id() const
Get a unique, identifying string associated with this image.
Definition Image.cpp:420
Cube display widget for certain Isis MDI applications.
Tool for measuring distances.
Definition MeasureTool.h:58
The main project for ipce.
Definition Project.h:287
Control * activeControl()
Return the Active Control (control network)
Definition Project.cpp:1964
Represents an item of a ProjectItemModel in Qt's model-view framework.
bool isShape() const
Returns true if an Shape is stored in the data of the item.
bool isShapeList() const
Returns true if an ShapeList is stored in the data of the item.
Shape * shape() const
Returns the Shape stored in the data of the item.
bool isImageList() const
Returns true if an ImageList is stored in the data of the item.
Image * image() const
Returns the Image stored in the data of the item.
bool isImage() const
Returns true if an Image is stored in the data of the item.
Allows access to items in a ProjectItemModel through a proxy model.
QMenu subclass that overrides the closeEvent.
Rubber banding tool.
Scatter Plot Tool.
QString id() const
Get a unique, identifying string associated with this shape.
Definition Shape.cpp:443
Cube * cube()
Get the Cube * associated with this display property.
Definition Shape.cpp:308
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.
QMdiArea * mdiArea()
This method returns the QMdiArea.
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.
QVector< MdiCubeViewport * > * cubeViewportList()
This method returns a Vector of MdiCubeViewports.
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