Isis 3.0 Programmer Reference
Back | Home
CubeDnView.cpp
Go to the documentation of this file.
1 
23 #include "CubeDnView.h"
24 
25 #include <QAction>
26 #include <QDataStream>
27 #include <QHBoxLayout>
28 #include <QMap>
29 #include <QMdiArea>
30 #include <QMdiSubWindow>
31 #include <QMenu>
32 #include <QModelIndex>
33 #include <QSize>
34 #include <QSizePolicy>
35 #include <QStatusBar>
36 #include <QToolBar>
37 #include <QVBoxLayout>
38 #include <QWidgetAction>
39 #include <QXmlStreamWriter>
40 
41 #include "AdvancedTrackTool.h"
42 #include "BandTool.h"
43 #include "BlinkTool.h"
44 #include "Cube.h"
45 #include "CubeAttribute.h"
46 #include "Directory.h"
47 #include "EditTool.h"
48 #include "FeatureNomenclatureTool.h"
49 #include "FileName.h"
50 #include "FileTool.h"
51 #include "FindTool.h"
52 #include "HelpTool.h"
53 #include "HistogramTool.h"
54 #include "Image.h"
55 #include "ImageList.h"
56 #include "IpceTool.h"
57 #include "IString.h"
58 #include "MatchTool.h"
59 #include "MdiCubeViewport.h"
60 #include "MeasureTool.h"
61 #include "PanTool.h"
62 #include "Project.h"
63 #include "ProjectItem.h"
64 #include "ProjectItemModel.h"
65 #include "ProjectItemProxyModel.h"
66 #include "RubberBandTool.h"
67 #include "ScatterPlotTool.h"
68 #include "Shape.h"
69 #include "SpatialPlotTool.h"
70 #include "SpecialPixelTool.h"
71 #include "SpectralPlotTool.h"
72 #include "StatisticsTool.h"
73 #include "StereoTool.h"
74 #include "StretchTool.h"
75 #include "SunShadowTool.h"
76 #include "TrackTool.h"
77 #include "ToolList.h"
78 #include "ToolPad.h"
79 #include "ViewportMdiSubWindow.h"
80 #include "Workspace.h"
81 #include "WindowTool.h"
82 #include "XmlStackedHandlerReader.h"
83 #include "ZoomTool.h"
84 
85 namespace Isis {
91  CubeDnView::CubeDnView(Directory *directory, QWidget *parent) :
92  AbstractProjectItemView(parent) {
93  connect( internalModel()->selectionModel(),
94  SIGNAL( currentChanged(const QModelIndex &, const QModelIndex &) ),
95  this, SLOT( onCurrentChanged(const QModelIndex &) ) );
96 
97  connect( internalModel(), SIGNAL( itemAdded(ProjectItem *) ),
98  this, SLOT( onItemAdded(ProjectItem *) ) );
99 
101 
102  m_workspace = new Workspace(false, this);
103  m_workspace->mdiArea()->setActivationOrder(QMdiArea::StackingOrder);
104 
105  connect(m_workspace, SIGNAL( cubeViewportActivated(MdiCubeViewport *) ),
106  this, SLOT( onCubeViewportActivated(MdiCubeViewport *) ) );
107 
108  connect(m_workspace, SIGNAL( cubeViewportAdded(MdiCubeViewport *) ),
109  this, SLOT( onCubeViewportAdded(MdiCubeViewport *) ) );
110 
111 
112  QVBoxLayout *layout = new QVBoxLayout;
113  setLayout(layout);
114 
115  //m_toolBar = new QWidget(this);
116 
117  //QHBoxLayout *toolBarLayout = new QHBoxLayout;
118 
119  m_permToolBar = new QToolBar("Standard Tools", 0);
120  m_permToolBar->setObjectName("permToolBar");
121  m_permToolBar->setIconSize(QSize(22, 22));
122  //toolBarLayout->addWidget(m_permToolBar);
123 
124  m_activeToolBar = new QToolBar("Active Tool", 0);
125  m_activeToolBar->setObjectName("activeToolBar");
126  m_activeToolBar->setIconSize(QSize(22, 22));
127  //toolBarLayout->addWidget(m_activeToolBar);
128 
129  m_toolPad = new ToolPad("Tool Pad", 0);
130  m_toolPad->setObjectName("toolPad");
131  //toolBarLayout->addWidget(m_toolPad);
132 
133  //m_toolBar->setLayout(toolBarLayout);
134 
135  //layout->addWidget(m_toolBar);
136  layout->addWidget(m_workspace);
137 
138  // Create tools
139  ToolList *tools = new ToolList;
140 
141  Tool *defaultActiveTool = NULL;
142 
143  tools->append(new RubberBandTool(this));
144 // QnetTool *qnetTool = new QnetTool(m_workspace);
145  //tools->append(new FileTool(this));
146  //tools->append(new QnetFileTool(qnetTool, this));
147  tools->append(NULL);
148  tools->append(new BandTool(this));
149 
150  IpceTool *ipceTool = new IpceTool(directory, this);
151  defaultActiveTool = ipceTool;
152  tools->append(defaultActiveTool);
153 
154  if (directory->project()->activeControl()) {
155  ipceTool->setControlNet(directory->project()->activeControl()->controlNet());
156  }
157  // Pass on Signals emitted from IpceTool
158  // TODO 2016-09-09 TLS Design: Use a proxy model instead of signals?
159  connect(ipceTool, SIGNAL(modifyControlPoint(ControlPoint *)),
160  this, SIGNAL(modifyControlPoint(ControlPoint *)));
161 
162  connect(ipceTool, SIGNAL(deleteControlPoint(ControlPoint *)),
163  this, SIGNAL(deleteControlPoint(ControlPoint *)));
164 
165  connect(ipceTool, SIGNAL(createControlPoint(double, double, Cube *, bool)),
166  this, SIGNAL(createControlPoint(double, double, Cube *, bool)));
167 
168  // Pass on signals emitted from Directory (by way of ControlPointEditWidget)
169  // This is done to redraw the control points on the cube viewports
170  connect(this, SIGNAL(controlPointAdded(QString)), ipceTool, SLOT(refresh()));
171 
172  tools->append(new ZoomTool(this));
173  tools->append(new PanTool(this));
174  tools->append(new StretchTool(this));
175  tools->append(new FindTool(this));
176  tools->append(new BlinkTool(this));
177  tools->append(new AdvancedTrackTool(this));
178  tools->append(new EditTool(this));
179  tools->append(new WindowTool(this));
180  tools->append(new MeasureTool(this));
181  tools->append(new SunShadowTool(this));
182  tools->append(new FeatureNomenclatureTool(this));
183  tools->append(new SpecialPixelTool(this));
184  tools->append(new SpatialPlotTool(this));
185  tools->append(new SpectralPlotTool(this));
186  tools->append(new ScatterPlotTool(this));
187  tools->append(new HistogramTool(this));
188  tools->append(new StatisticsTool(this));
189  tools->append(new StereoTool(this));
190  tools->append(new HelpTool(this));
191 
192  QStatusBar *statusBar = new QStatusBar(this);
193  layout->addWidget(statusBar);
194  tools->append(new TrackTool(statusBar));
195 
196 // QnetNavTool *ntool = new QnetNavTool(qnetTool, this);
197 // tools->append(ntool);
198 // tools->append(qnetTool);
199 //
200 // connect(qnetTool, SIGNAL(showNavTool()), ntool, SLOT(showNavTool()));
201 
202  //QMenuBar *menuBar = new QMenuBar;
203  //QMap<QString, QMenu *> subMenus;
204 
205  m_separatorAction = new QAction(this);
206  m_separatorAction->setSeparator(true);
207 
208  m_fileMenu = new QMenu;
209  m_viewMenu = new QMenu;
210  m_optionsMenu = new QMenu;
211  m_windowMenu = new QMenu;
212  m_helpMenu = new QMenu;
213 
214  for (int i = 0; i < tools->count(); i++) {
215  Tool *tool = (*tools)[i];
216 
217  if (tool) {
218  tool->addTo(m_workspace);
221  tool->addTo(m_toolPad);
222 
223  if (!tool->menuName().isEmpty()) {
224  QString menuName = tool->menuName();
225 
226  if (menuName == "&File") {
227  tool->addTo(m_fileMenu);
228  }
229  else if (menuName == "&View") {
230  tool->addTo(m_viewMenu);
231  }
232  else if (menuName == "&Options") {
233  tool->addTo(m_optionsMenu);
234  }
235  else if (menuName == "&Window") {
236  tool->addTo(m_windowMenu);
237  }
238  else if (menuName == "&Help") {
239  tool->addTo(m_helpMenu);
240  }
241  }
242  }
243  else {
244  m_permToolBar->addSeparator();
245  }
246  }
247 
248  m_permToolBarActions.append( m_permToolBar->actions() );
249 
250  m_activeToolBarAction = new QWidgetAction(this);
251  m_activeToolBarAction->setDefaultWidget(m_activeToolBar);
252 
253  m_toolPadActions.append( m_toolPad->actions() );
254 
255  QSizePolicy policy = sizePolicy();
256  policy.setHorizontalPolicy(QSizePolicy::Expanding);
257  policy.setVerticalPolicy(QSizePolicy::Expanding);
258  setSizePolicy(policy);
259  }
260 
261 
266  delete m_permToolBar;
267  delete m_activeToolBar;
268  delete m_toolPad;
269 
270  m_permToolBar = 0;
271  m_activeToolBar = 0;
272  m_toolPad = 0;
273  }
274 
275 
283  if ( !item->isImageList() && !item->isImage() && !item->isShapeList() && !item->isShape()) {
284  return;
285  }
286 
288  }
289 
290 
296  QSize CubeDnView::sizeHint() const {
297  return QSize(800, 600);
298  }
299 
300 
301  bool CubeDnView::viewportContainsShape(MdiCubeViewport *viewport) {
302 
303  ProjectItem *item = m_cubeItemMap.value( viewport->cube() );
304 
305  if (!item) {
306  return false;
307  }
308 
309  return item->isShape();
310  }
311 
312 
319  return m_fileMenu->actions();
320  }
321 
322 
329  return QList<QAction *>();
330  }
331 
338  return QList<QAction *>();
339  }
340 
341 
348  QList<QAction *> result;
349  result.append( m_viewMenu->actions() );
350  result.append(m_separatorAction);
351  result.append( m_windowMenu->actions() );
352  return result;
353  }
354 
355 
362  return m_optionsMenu->actions();
363  }
364 
365 
372  return m_helpMenu->actions();
373  }
374 
375 
382  return m_permToolBar->actions();
383  }
384 
385 
392  QList<QAction *> actions;
393  actions.append(m_activeToolBarAction);
394  return actions;
395  }
396 
397 
404  return m_toolPad->actions();
405  }
406 
407 
415  void CubeDnView::onCurrentChanged(const QModelIndex &current) {
416 
417  ProjectItem *item = internalModel()->itemFromIndex(current);
418 
419  if (!item) {
420  return;
421  }
422 
423  if (!item->isImage()) {
424  return;
425  }
426 
427  setWorkspaceActiveCube(item->image());
428  }
429 
430 
439  if ( !isVisible() ) {
440  return;
441  }
442 
443  if (!viewport) {
444  return;
445  }
446 
447  ProjectItem *item = m_cubeItemMap.value( viewport->cube() );
448 
449  if (!item) {
450  return;
451  }
452 
453  internalModel()->selectionModel()->setCurrentIndex(item->index(),
454  QItemSelectionModel::SelectCurrent);
455  }
456 
457 
466  connect(viewport, SIGNAL( destroyed(QObject *) ),
467  this, SLOT( onCubeViewportDeleted(QObject *) ) );
468  }
469 
470 
478  MdiCubeViewport *viewport = qobject_cast<MdiCubeViewport *>(obj);
479 
480  if (!viewport) {
481  return;
482  }
483 
484  if ( ProjectItemProxyModel *proxyModel =
485  qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
486  proxyModel->removeItem( m_cubeItemMap.value( viewport->cube() ) );
487  }
488  }
489 
490 
499 
500  if (!item) {
501  return;
502  }
503  Cube *cube;
504  if (item->isImage()) {
505  cube = item->image()->cube();
506  }
507  else if (item->isShape()) {
508  cube = item->shape()->cube();
509  }
510  else {
511  return;
512  }
513  if (m_workspace->cubeToMdiWidget(cube)) {
514  return;
515  }
517  m_cubeItemMap.insert(cube, item);
518  }
519 
520 
528  QMdiArea *mdiArea = m_workspace->mdiArea();
529  ViewportMdiSubWindow *subWindow = qobject_cast<ViewportMdiSubWindow *>( mdiArea->currentSubWindow() );
530  if (!subWindow) {
531  return 0;
532  }
533  MdiCubeViewport *viewport = subWindow->viewport();
534  return viewport->cube();
535  }
536 
537 
542  if (!image) {
543  return;
544  }
545 
546  QWidget *mdiWidget = m_workspace->cubeToMdiWidget(image->cube());
547 
548  if (!mdiWidget) {
549  return;
550  }
551 
552  QMdiSubWindow *subWindow = qobject_cast<QMdiSubWindow *>( mdiWidget->parent() );
553 
554  if (!subWindow) {
555  return;
556  }
557 
558  subWindow->raise();
559 
560  // Activating the subwindow activates the view, which is annoying
561  //m_workspace->mdiArea()->setActiveSubWindow(subWindow);
562  }
563 
564 
565  void CubeDnView::load(XmlStackedHandlerReader *xmlReader, Project *project) {
566  xmlReader->pushContentHandler(new XmlHandler(this, project));
567  }
568 
569 
570  void CubeDnView::save(QXmlStreamWriter &stream, Project *, FileName) const {
571  stream.writeStartElement("cubeDnView");
572 
573  foreach (MdiCubeViewport *cvp, *(m_workspace->cubeViewportList())) {
574  ProjectItem *item = m_cubeItemMap.value(cvp->cube());
575  if (item->isImage()) {
576  stream.writeStartElement("image");
577  stream.writeAttribute("id", item->image()->id());
578  }
579  else if (item->isShape()) {
580  stream.writeStartElement("shape");
581  stream.writeAttribute("id", item->shape()->id());
582  }
583  stream.writeEndElement();
584  }
585  stream.writeEndElement();
586  }
587 
588 
589  CubeDnView::XmlHandler::XmlHandler(CubeDnView *cubeDnView, Project *project) {
590 
591  m_cubeDnView = cubeDnView;
592  m_project = project;
593  }
594 
595 
596  CubeDnView::XmlHandler::~XmlHandler() {
597  }
598 
599 
600  bool CubeDnView::XmlHandler::startElement(const QString &namespaceURI,
601  const QString &localName, const QString &qName, const QXmlAttributes &atts) {
602  bool result = XmlStackedHandler::startElement(namespaceURI, localName, qName, atts);
603 
604  if (result) {
605  ProjectItemProxyModel *proxy = (ProjectItemProxyModel *) m_cubeDnView->internalModel();
606  ProjectItemModel *source = proxy->sourceModel();
607  QString id = atts.value("id");
608 
609  ProjectItem *item = NULL;
610  if (localName == "image") {
611  Image *image = m_project->image(id);
612  if (image) {
613  // Find ProjectItem and append to list
614  item = source->findItemData(qVariantFromValue(image));
615  }
616  }
617  else if (localName == "shape") {
618  Shape *shape = m_project->shape(id);
619  if (shape) {
620  item = source->findItemData(qVariantFromValue(shape));
621  }
622  }
623  if (item) {
624  proxy->addItem(item);
625  }
626  }
627 
628  return result;
629  }
630 
631 
632  bool CubeDnView::XmlHandler::endElement(const QString &namespaceURI,
633  const QString &localName, const QString &qName) {
634  bool result = XmlStackedHandler::endElement(namespaceURI, localName, qName);
635 
636  return result;
637  }
638 }
Cube display widget for certain Isis MDI applications.
void setWorkspaceActiveCube(Image *image)
Raises the subwindow corresponding with an image to the top.
Definition: CubeDnView.cpp:541
CubeDnView * m_cubeDnView
The view we are working with.
Definition: CubeDnView.h:143
$Revision$ $Date$
virtual void addItem(ProjectItem *item)
Adds an item to the view.
$Date$ $Revision$
virtual QList< QAction * > activeToolBarActions()
Returns a list of actions for the active tool bar.
Definition: CubeDnView.cpp:391
void onItemAdded(ProjectItem *item)
Slot to connect to the itemAdded signal from a ProjectItemModel.
Definition: CubeDnView.cpp:498
The main project for cnetsuite.
Definition: Project.h:105
Workspace * m_workspace
The workspace.
Definition: CubeDnView.h:148
void addToActive(QToolBar *toolbar)
Definition: Tool.cpp:112
QString id() const
Get a unique, identifying string associated with this image.
Definition: Image.cpp:394
File name manipulation and expansion.
Definition: FileName.h:111
ProjectItem * itemFromIndex(const QModelIndex &index)
Returns the ProjectItem corresponding to a given QModelIndex.
bool isShape() const
Returns true if an Shape is stored in the data of the item.
QVector< MdiCubeViewport * > * cubeViewportList()
Repopulates the list of MdiCubeViewports and returns a pointer to this list.
Definition: Workspace.cpp:237
void onCubeViewportActivated(MdiCubeViewport *)
Slot to connect to the cubeViewportActivated signal from the Workspace.
Definition: CubeDnView.cpp:438
$Date$ $Revision$
QToolBar * m_activeToolBar
A tool bar for storing actions.
Definition: CubeDnView.h:159
QList< QAction * > m_toolPadActions
The tool pad actions.
Definition: CubeDnView.h:164
void onCubeViewportDeleted(QObject *obj)
Slot to connect to the destroyed signal from a viewport.
Definition: CubeDnView.cpp:477
Stretch image edit tool.
Definition: StretchTool.h:99
virtual void addToPermanent(QToolBar *toolbar)
Definition: Tool.h:111
QAction * m_separatorAction
A separator action that is reused.
Definition: CubeDnView.h:156
bool isImageList() const
Returns true if an ImageList is stored in the data of the item.
virtual QList< QAction * > viewMenuActions()
Returns a list of actions appropriate for a view menu.
Definition: CubeDnView.cpp:347
QMap< Cube *, ProjectItem * > m_cubeItemMap
Maps cubes to their items.
Definition: CubeDnView.h:147
bool isImage() const
Returns true if an Image is stored in the data of the item.
Shape * shape() const
Returns the Shape stored in the data of the item.
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
Control * activeControl()
Return the Active Control (control network)
Definition: Project.cpp:1182
Cube * workspaceActiveCube()
Returns the cube of the active viewport in the Workspace, or a null pointer if no viewports are activ...
Definition: CubeDnView.cpp:527
Project * project() const
Gets the Project for this directory.
Definition: Directory.cpp:923
Handles zoom operations for Isis qt apps.
Definition: ZoomTool.h:65
QMenu * m_optionsMenu
Options menu for storing actions.
Definition: CubeDnView.h:152
AbstractProjectItemView is a base class for views of a ProjectItemModel in Qt&#39;s model-view framework...
Provides access to data stored in a Project through Qt&#39;s model-view framework.
ProjectItem * addItem(ProjectItem *sourceItem)
Adds an item and its children to the proxy model.
ProjectItem * findItemData(const QVariant &data, int role=Qt::UserRole+1)
Returns the first item found that contains the given data in the given role or a null pointer if no i...
virtual QList< QAction * > permToolBarActions()
Returns a list of actions for the permanent tool bar.
Definition: CubeDnView.cpp:381
QMenu * m_windowMenu
Window menu for storing actions.
Definition: CubeDnView.h:153
QMenu * m_viewMenu
View menu for storing actions.
Definition: CubeDnView.h:151
virtual ProjectItemModel * internalModel()
Returns the internal model of the view.
CubeDnView(Directory *directory, QWidget *parent=0)
Constructs the view, initializing the tools.
Definition: CubeDnView.cpp:91
Cube * cube() const
Return the cube associated with viewport.
Definition: CubeViewport.h:228
Image * image() const
Returns the Image stored in the data of the item.
Interactive image edit tool.
Definition: EditTool.h:80
Allows access to items in a ProjectItemModel through a proxy model.
QItemSelectionModel * selectionModel()
Returns the internal selection model.
QWidgetAction * m_activeToolBarAction
Widget of the active tool.
Definition: CubeDnView.h:163
Cube * cube()
Get the Cube * associated with this display property.
Definition: Shape.cpp:282
virtual QList< QAction * > projectMenuActions()
Returns a list of actions appropriate for a project menu.
Definition: CubeDnView.cpp:328
Tool for measuring distances.
Definition: MeasureTool.h:58
Project * m_project
The current project.
Definition: CubeDnView.h:142
QMenu * m_helpMenu
Help menu for storing actions.
Definition: CubeDnView.h:154
Plot cube DN statistics against the cube band numbers.
A single control point.
Definition: ControlPoint.h:339
This represents a cube in a project-based GUI interface.
Definition: Image.h:91
QString id() const
Get a unique, identifying string associated with this shape.
Definition: Shape.cpp:417
ToolPad * m_toolPad
A tool bar for storing actions.
Definition: CubeDnView.h:160
void addTo(ViewportMainWindow *mw)
Adds the tool to the application.
Definition: Tool.cpp:78
This is an actual viewport window in qview/qnet/etc.
QSize sizeHint() const
Returns the suggested size.
Definition: CubeDnView.cpp:296
virtual QList< QAction * > toolPadActions()
Returns a list of actions for the tool pad.
Definition: CubeDnView.cpp:403
ControlNet * controlNet()
Open and return a pointer to the ControlNet for this Control.
Definition: Control.cpp:106
virtual QList< QAction * > settingsMenuActions()
Returns a list of actions appropriate for a settings menu.
Definition: CubeDnView.cpp:361
ProjectItemModel * sourceModel()
Returns the source model.
void onCubeViewportAdded(MdiCubeViewport *viewport)
Slot to connect to the viewportAdded signal from a Workspace.
Definition: CubeDnView.cpp:465
bool isShapeList() const
Returns true if an ShapeList is stored in the data of the item.
~CubeDnView()
Destructor.
Definition: CubeDnView.cpp:265
QMenu * m_fileMenu
File menu for storing actions.
Definition: CubeDnView.h:150
Rubber banding tool.
void addItem(ProjectItem *item)
Adds an item to the view.
Definition: CubeDnView.cpp:282
$Date$ $Revision$
Display nomenclature on MDI Cube Viewports.
This represents a shape in a project-based GUI interface.
Definition: Shape.h:70
View that displays cubes in a QView-like way.
Definition: CubeDnView.h:74
QToolBar * m_permToolBar
A tool bar for storing actions.
Definition: CubeDnView.h:158
void addCubeViewport(QString cube)
Add a cubeViewport to the workspace, open the cube.
Definition: Workspace.cpp:326
Represents an item of a ProjectItemModel in Qt&#39;s model-view framework.
Definition: ProjectItem.h:113
Tool to locate a point on a cube that is projected and/or has a camera model.
Definition: FindTool.h:128
virtual QList< QAction * > fileMenuActions()
Returns a list of actions appropriate for a file menu.
Definition: CubeDnView.cpp:318
Base class for the Qisis tools.
Definition: Tool.h:81
Cube * cube()
Get the Cube pointer associated with this display property.
Definition: Image.cpp:254
virtual QList< QAction * > editMenuActions()
Returns a list of actions appropriate for an edit menu.
Definition: CubeDnView.cpp:337
Tool for histograms.
Definition: HistogramTool.h:40
Tool for measuring shadow heights.
Definition: SunShadowTool.h:39
void onCurrentChanged(const QModelIndex &current)
Slot to connect to the currentChanged() signal from a selection model.
Definition: CubeDnView.cpp:415
Scatter Plot Tool.
QList< QAction * > m_permToolBarActions
The permanent tool bar actions.
Definition: CubeDnView.h:162
Ipce (Qnet) tool operations.
Definition: IpceTool.h:44
virtual QList< QAction * > helpMenuActions()
Returns a list of actions appropriate for a help menu.
Definition: CubeDnView.cpp:371
Sets the colors for the special pixel values.
his enables stack-based XML parsing of XML files.
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
virtual QString menuName() const
Anytime a tool is created, you must give it a name for the menu.
Definition: Tool.h:97
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:17:05