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 "XmlStackedHandlerReader.h"
71#include "ZoomTool.h"
72
73#include "ProjectItemViewMenu.h"
74
75namespace Isis {
83 connect( internalModel()->selectionModel(),
84 SIGNAL( currentChanged(const QModelIndex &, const QModelIndex &) ),
85 this, SLOT( onCurrentChanged(const QModelIndex &) ) );
86
87 connect( internalModel(), SIGNAL( itemAdded(ProjectItem *) ),
88 this, SLOT( onItemAdded(ProjectItem *) ) );
89
90 m_cubeItemMap = QMap<Cube *, ProjectItem *>();
91
92 m_workspace = new Workspace(false, this);
93 m_workspace->mdiArea()->setActivationOrder(QMdiArea::StackingOrder);
94
95 m_directory = directory;
96
97 // Since this is a QMainWindow, set the workspace as the central widget.
98 setCentralWidget(m_workspace);
99
100 createActions(directory);
101
102 connect(m_workspace, SIGNAL( cubeViewportActivated(MdiCubeViewport *) ),
103 this, SLOT( onCubeViewportActivated(MdiCubeViewport *) ) );
104
105 connect(m_workspace, SIGNAL( cubeViewportAdded(MdiCubeViewport *) ),
106 this, SLOT( onCubeViewportAdded(MdiCubeViewport *) ) );
107 }
108
109
110 void CubeDnView::createActions(Directory *directory) {
111
112 m_permToolBar = new QToolBar("Standard Tools", this);
113 m_permToolBar->setObjectName("permToolBar");
114 m_permToolBar->setIconSize(QSize(22, 22));
115 addToolBar(m_permToolBar);
116
117 m_activeToolBar = new QToolBar("Active Tool", this);
118 m_activeToolBar->setObjectName("activeToolBar");
119 m_activeToolBar->setIconSize(QSize(22, 22));
120 addToolBar(m_activeToolBar);
121
122 m_toolPad = new ToolPad("Tool Pad", this);
123 m_toolPad->setObjectName("toolPad");
124 addToolBar(Qt::RightToolBarArea, m_toolPad);
125
126 // Create tools
127 ToolList *tools = new ToolList;
128
129 tools->append(new RubberBandTool(this));
130
131 // 2018-07-02 Kaitlyn Lee - Commented this out; not sure why it was here
132 //tools->append(NULL);
133
134 ControlNetTool *controlNetTool = new ControlNetTool(directory, this);
135 tools->append(controlNetTool);
136
137 if (directory->project()->activeControl()) {
138 controlNetTool->setControlNet(directory->project()->activeControl()->controlNet());
139 }
140 // Pass on Signals emitted from ControlNetTool
141 // TODO 2016-09-09 TLS Design: Use a proxy model instead of signals?
142 connect(controlNetTool, SIGNAL(modifyControlPoint(ControlPoint *, QString)),
143 this, SIGNAL(modifyControlPoint(ControlPoint *, QString)));
144
145 connect(controlNetTool, SIGNAL(deleteControlPoint(ControlPoint *)),
146 this, SIGNAL(deleteControlPoint(ControlPoint *)));
147
148 connect(controlNetTool, SIGNAL(createControlPoint(double, double, Cube *, bool)),
149 this, SIGNAL(createControlPoint(double, double, Cube *, bool)));
150
151 // Pass on signals emitted from Directory (by way of ControlPointEditWidget)
152 // This is done to redraw the control points on the cube viewports
153 connect(this, SIGNAL(controlPointAdded(QString)), controlNetTool, SLOT(paintAllViewports()));
154
155 // Pass on redrawMeasure signal from Directory, so the control measures are redrawn on all
156 // CubeViewports.
157 connect(this, SIGNAL(redrawMeasures()), controlNetTool, SLOT(paintAllViewports()));
158
159 tools->append(new BandTool(this));
160 ZoomTool *zoomTool = new ZoomTool(this);
161 tools->append(zoomTool);
162 tools->append(new PanTool(this));
163 tools->append(new StretchTool(this));
164 tools->append(new FindTool(this));
165 tools->append(new BlinkTool(this));
166 tools->append(new AdvancedTrackTool(this));
167 tools->append(new EditTool(this));
168 tools->append(new WindowTool(this));
169 tools->append(new MeasureTool(this));
170 tools->append(new SunShadowTool(this));
171 tools->append(new FeatureNomenclatureTool(this));
172 tools->append(new SpecialPixelTool(this));
173 tools->append(new SpatialPlotTool(this));
174 tools->append(new SpectralPlotTool(this));
175 tools->append(new ScatterPlotTool(this));
176 tools->append(new HistogramTool(this));
177 tools->append(new StatisticsTool(this));
178 tools->append(new StereoTool(this));
179 tools->append(new TrackTool(statusBar()));
180
181 m_separatorAction = new QAction(this);
182 m_separatorAction->setSeparator(true);
183
184 m_viewMenu = new ProjectItemViewMenu("&View");
185 connect(m_viewMenu, SIGNAL(menuClosed()), this, SLOT(disableActions()));
186 menuBar()->addMenu(m_viewMenu);
187
188 m_optionsMenu = new ProjectItemViewMenu("&Options");
189 connect(m_optionsMenu, SIGNAL(menuClosed()), this, SLOT(disableActions()));
190 menuBar()->addMenu(m_optionsMenu);
191
192 m_windowMenu = new ProjectItemViewMenu("&Window");
193 connect(m_windowMenu, SIGNAL(menuClosed()), this, SLOT(disableActions()));
194 menuBar()->addMenu(m_windowMenu);
195
196 for (int i = 0; i < tools->count(); i++) {
197 Tool *tool = (*tools)[i];
198
199 if (tool) {
200 tool->addTo(m_workspace);
201 tool->addToPermanent(m_permToolBar);
202 tool->addToActive(m_activeToolBar);
203 tool->addTo(m_toolPad);
204
205 if (!tool->menuName().isEmpty()) {
206 QString menuName = tool->menuName();
207
208 if (menuName == "&View") {
209 tool->addTo(m_viewMenu);
210 }
211 else if (menuName == "&Options") {
212 tool->addTo(m_optionsMenu);
213 }
214 else if (menuName == "&Window") {
215 tool->addTo(m_windowMenu);
216 }
217 }
218 }
219 else {
220 m_permToolBar->addSeparator();
221 }
222 }
223
224 // Store the actions and widgets for easy enable/disable.
225 foreach (QAction *action, findChildren<QAction *>()) {
226 // Remove the edit tool's save button shortcut because the ipce main window
227 // already has one and this causes an ambiquous shortcut error.
228 if (action->toolTip() == "Save") {
229 action->setShortcut(QKeySequence());
230 }
231 // The active toolbar's actions are inside of a container that is a QWidgetAction.
232 // We want to skip adding this because we want to disable the active toolbar's
233 // actions separately to skip the combo boxes.
234 if (QString(action->metaObject()->className()) == "QWidgetAction") {
235 continue;
236 }
237 addAction(action);
238 }
239
240 // There was a problem with disabling/enabling the combo boxes. The only way to
241 // get this to work was to skip disabling the combo boxes. We also skip QWidgets
242 // because the combo boxes are contained inside of a QWidget.
243 foreach (QWidget *child, m_activeToolBar->findChildren<QWidget *>()) {
244 if (QString(child->metaObject()->className()).contains("ComboBox") ||
245 QString(child->metaObject()->className()).contains("Widget")) {
246 continue;
247 }
248 m_childWidgets.append(child);
249 }
250
251 // On default, actions are disabled until the cursor enters the view.
253
254 zoomTool->activate(true);
255 }
256
257
266 void CubeDnView::leaveEvent(QEvent *event) {
267 if (m_optionsMenu->isVisible() || m_viewMenu->isVisible() || m_windowMenu->isVisible()) {
268 return;
269 }
270 // Find the toolpad actions (buttons) with menus and check if they are visible
271 foreach (QToolButton *button, findChildren<QToolButton *>()) {
272 if (button->menu() && button->menu()->isVisible()) {
273 return;
274 }
275 }
277 }
278
279
284 foreach (QAction *action, actions()) {
285 action->setDisabled(true);
286 }
287 foreach (QWidget *widget, m_childWidgets) {
288 widget->setDisabled(true);
289 }
290 }
291
292
298 foreach (QAction *action, actions()) {
299 if (action->objectName() == "ControlNetTool" && !m_directory->project()->activeControl()) {
300 continue;
301 }
302 action->setEnabled(true);
303 }
304 foreach (QWidget *widget, m_childWidgets) {
305 widget->setEnabled(true);
306 }
307 }
308
309
318 foreach (QAction *action, m_toolPad->actions()) {
319 if (action->objectName() == "ControlNetTool") {
320 action->setEnabled(value);
321 if (value) {
322 ControlNetTool *cnetTool = static_cast<ControlNetTool *>(action->parent());
323 cnetTool->loadNetwork();
324 }
325 }
326 }
327 }
328
333 delete m_permToolBar;
334 delete m_activeToolBar;
335 delete m_toolPad;
336 delete m_viewMenu;
337 delete m_optionsMenu;
338 delete m_windowMenu;
339
340
341 m_permToolBar = 0;
342 m_activeToolBar = 0;
343 m_toolPad = 0;
344 m_viewMenu = 0;
345 m_optionsMenu = 0;
346 m_windowMenu = 0;
347 }
348
349
357 if ( !item->isImageList() && !item->isImage() && !item->isShapeList() && !item->isShape()) {
358 return;
359 }
360
362 }
363
364
365 bool CubeDnView::viewportContainsShape(MdiCubeViewport *viewport) {
366
367 ProjectItem *item = m_cubeItemMap.value( viewport->cube() );
368
369 if (!item) {
370 return false;
371 }
372
373 return item->isShape();
374 }
375
383 void CubeDnView::onCurrentChanged(const QModelIndex &current) {
384
385 ProjectItem *item = internalModel()->itemFromIndex(current);
386
387 if (!item) {
388 return;
389 }
390
391 if (!item->isImage()) {
392 return;
393 }
394
396 }
397
398
407 if ( !isVisible() ) {
408 return;
409 }
410
411 if (!viewport) {
412 return;
413 }
414
415 ProjectItem *item = m_cubeItemMap.value( viewport->cube() );
416
417 if (!item) {
418 return;
419 }
420
421 internalModel()->selectionModel()->setCurrentIndex(item->index(),
422 QItemSelectionModel::SelectCurrent);
423 }
424
425
434 connect(viewport, SIGNAL( destroyed(QObject *) ),
435 this, SLOT( onCubeViewportDeleted(QObject *) ) );
436 }
437
438
446 MdiCubeViewport *viewport = qobject_cast<MdiCubeViewport *>(obj);
447
448 if (!viewport) {
449 return;
450 }
451
452 if ( ProjectItemProxyModel *proxyModel =
453 qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
454 proxyModel->removeItem( m_cubeItemMap.value( viewport->cube() ) );
455 }
456 }
457
458
467
468 if (!item) {
469 return;
470 }
471 Cube *cube;
472 if (item->isImage()) {
473 cube = item->image()->cube();
474 }
475 else if (item->isShape()) {
476 cube = item->shape()->cube();
477 }
478 else {
479 return;
480 }
481 if (m_workspace->cubeToMdiWidget(cube)) {
482 return;
483 }
485 m_cubeItemMap.insert(cube, item);
486 }
487
488
496 QMdiArea *mdiArea = m_workspace->mdiArea();
497 ViewportMdiSubWindow *subWindow = qobject_cast<ViewportMdiSubWindow *>( mdiArea->currentSubWindow() );
498 if (!subWindow) {
499 return 0;
500 }
501 MdiCubeViewport *viewport = subWindow->viewport();
502 return viewport->cube();
503 }
504
505
510 if (!image) {
511 return;
512 }
513
514 QWidget *mdiWidget = m_workspace->cubeToMdiWidget(image->cube());
515
516 if (!mdiWidget) {
517 return;
518 }
519
520 QMdiSubWindow *subWindow = qobject_cast<QMdiSubWindow *>( mdiWidget->parent() );
521
522 if (!subWindow) {
523 return;
524 }
525
526 subWindow->raise();
527
528 // Activating the subwindow activates the view, which is annoying
529 //m_workspace->mdiArea()->setActiveSubWindow(subWindow);
530 }
531
532
533 void CubeDnView::load(XmlStackedHandlerReader *xmlReader, Project *project) {
534 xmlReader->pushContentHandler(new XmlHandler(this, project));
535 }
536
537
538 void CubeDnView::save(QXmlStreamWriter &stream, Project *, FileName) const {
539 stream.writeStartElement("cubeDnView");
540 stream.writeAttribute("objectName", objectName());
541
542 foreach (MdiCubeViewport *cvp, *(m_workspace->cubeViewportList())) {
543 ProjectItem *item = m_cubeItemMap.value(cvp->cube());
544 if (item->isImage()) {
545 stream.writeStartElement("image");
546 stream.writeAttribute("id", item->image()->id());
547 }
548 else if (item->isShape()) {
549 stream.writeStartElement("shape");
550 stream.writeAttribute("id", item->shape()->id());
551 }
552 stream.writeEndElement();
553 }
554 stream.writeEndElement();
555 }
556
557
558 CubeDnView::XmlHandler::XmlHandler(CubeDnView *cubeDnView, Project *project) {
559
560 m_cubeDnView = cubeDnView;
561 m_project = project;
562 }
563
564
565 CubeDnView::XmlHandler::~XmlHandler() {
566 }
567
568
569 bool CubeDnView::XmlHandler::startElement(const QString &namespaceURI,
570 const QString &localName, const QString &qName, const QXmlAttributes &atts) {
571 bool result = XmlStackedHandler::startElement(namespaceURI, localName, qName, atts);
572
573 if (result) {
574 ProjectItemProxyModel *proxy = (ProjectItemProxyModel *) m_cubeDnView->internalModel();
575 ProjectItemModel *source = proxy->sourceModel();
576 QString id = atts.value("id");
577
578 ProjectItem *item = NULL;
579 if (localName == "image") {
580 Image *image = m_project->image(id);
581 if (image) {
582 // Find ProjectItem and append to list
583 item = source->findItemData(qVariantFromValue(image));
584 }
585 }
586 else if (localName == "shape") {
587 Shape *shape = m_project->shape(id);
588 if (shape) {
589 item = source->findItemData(qVariantFromValue(shape));
590 }
591 }
592 if (item) {
593 proxy->addItem(item);
594 }
595 }
596
597 return result;
598 }
599
600
601 bool CubeDnView::XmlHandler::endElement(const QString &namespaceURI,
602 const QString &localName, const QString &qName) {
603 bool result = XmlStackedHandler::endElement(namespaceURI, localName, qName);
604
605 return result;
606 }
607}
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:150
ControlNetTool Handles mouse events on CubeDnViews for control point editing for the ipce app.
A single control point.
CubeDnView * m_cubeDnView
The view we are working with.
Definition CubeDnView.h:160
Project * m_project
The current project.
Definition CubeDnView.h:159
View that displays cubes in a QView-like way.
Definition CubeDnView.h:97
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:170
ProjectItemViewMenu * m_viewMenu
View menu for storing actions.
Definition CubeDnView.h:168
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:164
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:174
ProjectItemViewMenu * m_optionsMenu
Options menu for storing actions.
Definition CubeDnView.h:169
void addItem(ProjectItem *item)
Adds an item to the view.
Directory * m_directory
The directory.
Definition CubeDnView.h:166
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:176
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:165
QList< QWidget * > m_childWidgets
Child widgets of the active toolbar.
Definition CubeDnView.h:177
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:175
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:172
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:107
Cube * cube()
Get the Cube pointer associated with this display property.
Definition Image.cpp:287
QString id() const
Get a unique, identifying string associated with this image.
Definition Image.cpp:445
Cube display widget for certain Isis MDI applications.
Tool for measuring distances.
Definition MeasureTool.h:58
The main project for ipce.
Definition Project.h:289
Control * activeControl()
Return the Active Control (control network)
Definition Project.cpp:1902
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.
ProjectItem * findItemData(const QVariant &value, int role=Qt::UserRole+1)
Finds and returns the first item in the model that contains the data in the role.
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.
Provides access to data stored in a Project through Qt's model-view framework.
Allows access to items in a ProjectItemModel through a proxy model.
QMenu subclass that overrides the closeEvent.
Rubber banding tool.
Scatter Plot Tool.
This represents a shape in a project-based GUI interface.
Definition Shape.h:68
QString id() const
Get a unique, identifying string associated with this shape.
Definition Shape.cpp:459
Cube * cube()
Get the Cube * associated with this display property.
Definition Shape.cpp:324
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.
Manage a stack of content handlers for reading XML files.
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