Isis 3 Programmer Reference
ChipViewportsWidget.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "IsisDebug.h"
10 
11 #include "ChipViewportsWidget.h"
12 
13 #include <sstream>
14 #include <vector>
15 #include <iomanip>
16 
17 #include <QtWidgets>
18 #include <QMessageBox>
19 #include <QMouseEvent>
20 
21 #include "Application.h"
22 #include "Camera.h"
23 #include "ChipViewport.h"
24 #include "ControlMeasureEditWidget.h"
25 #include "ControlMeasure.h"
26 #include "ControlMeasureLogData.h"
27 #include "ControlNet.h"
28 #include "ControlPoint.h"
29 #include "Cube.h"
30 #include "FileName.h"
31 #include "IException.h"
32 #include "Latitude.h"
33 #include "Longitude.h"
34 #include "MainWindow.h"
35 #include "MdiCubeViewport.h"
36 #include "Pvl.h"
37 #include "PvlEditDialog.h"
38 #include "SerialNumber.h"
39 #include "SerialNumberList.h"
40 #include "SpecialPixel.h"
41 #include "ToolPad.h"
42 #include "ViewportMainWindow.h"
43 #include "Workspace.h"
44 
45 using namespace std;
46 
47 namespace Isis {
48  const int VIEWSIZE = 301;
49 
56  ChipViewportsWidget::ChipViewportsWidget (QWidget *parent) : QWidget(parent) {
57 
58  m_netChanged = false;
59 
60  m_parent = parent;
61 
62  // TODO 05/10/2016 TLS What is the right way to handle serial number lists in IPCE?
63  m_serialNumberList = NULL;
64 
65 // m_cubeMeasureEditMap = QMap<Cube *, ControlMeasureEditWidget *>();
66 
67  createChipViewports(parent);
68 
69  installEventFilter(this);
70 
71 // connect(this, SIGNAL(newControlNetwork(ControlNet *)),
72 // m_measureEditor, SIGNAL(newControlNetwork(ControlNet *)));
73  }
74 
75 
76  ChipViewportsWidget::~ChipViewportsWidget () {
77  // TODO: Don't write settings in destructor, must do this earlier in close event
78 // writeSettings();
79 
80  }
81 
82 
83 
91 
92  setWindowTitle("ChipViewports");
93  setObjectName("ChipViewportsWidget");
94  connect(this, SIGNAL(destroyed(QObject *)), this, SLOT(clearPoint()));
95 
96 // createActions();
97 
98  m_chipViewportsLayout = new QGridLayout;
99 
100  QWidget *centralWidget = new QWidget;
101  centralWidget->setLayout(m_chipViewportsLayout);
102 
103  QScrollArea *scrollArea = new QScrollArea();
104  scrollArea->setObjectName("ChipViewportsWidgetScroll");
105  scrollArea->setWidgetResizable(true);
106  scrollArea->setWidget(centralWidget);
107  centralWidget->adjustSize();
108 
109  QVBoxLayout *mainLayout = new QVBoxLayout;
110 
111  m_ptIdValue = new QLabel();
112 
113  QCheckBox *showPoints = new QCheckBox("Show control points");
114  showPoints->setToolTip("Draw control point crosshairs");
115  showPoints->setWhatsThis("This will toggle whether crosshairs are drawn"
116  " for the control points located within the measure''s"
117  " view. For areas of dense measurements, turning this"
118  " off will allow easier viewing of features.");
119  connect(showPoints, SIGNAL(toggled(bool)), this, SLOT(showPoints(bool)));
120  showPoints->setChecked(true);
121 
122  QCheckBox *geomChips = new QCheckBox("Geom Chips to Reference");
123  geomChips->setToolTip("Geom Chips to Reference Control Measure");
124  geomChips->setWhatsThis("This will toggle whether chips are geomed to"
125  " the reference control measure.");
126  connect(geomChips, SIGNAL(toggled(bool)), this, SLOT(geomChips(bool)));
127  geomChips->setChecked(false);
128 
129  QHBoxLayout *pointsGeomLayout = new QHBoxLayout;
130  pointsGeomLayout->addWidget(showPoints);
131  pointsGeomLayout->addWidget(geomChips);
132  pointsGeomLayout->addStretch();
133 
134  mainLayout->addWidget(m_ptIdValue);
135  mainLayout->addLayout(pointsGeomLayout);
136  mainLayout->addWidget(scrollArea);
137  setLayout(mainLayout);
138 
139 // readSettings();
140  }
141 
142 
143 
144  void ChipViewportsWidget::createActions() {
145 
146  }
147 
148 
149 
150  void ChipViewportsWidget::setSerialNumberList(SerialNumberList *snList) {
151 
152 // qDebug()<<"ChipViewportsWidget::setSerialNumberList snList = "<<snList;
153  // TODO If network & snList already exists do some error checking
154  m_serialNumberList = snList;
155  }
156 
157 
158 
167  void ChipViewportsWidget::setControlNet(ControlNet *cnet, QString cnetFilename) {
168 // qDebug()<<"ChipViewportsWidget::setControlNet cnet = "<<cnet<<" filename = "<<cnetFilename;
169  // TODO more error checking
170  m_controlNet = cnet;
171  m_cnetFileName = cnetFilename;
172 // setWindowTitle("Control Point Editor- Control Network File: " + cnetFilename);
173 
174  //qDebug()<<"ChipViewportsWidget::setControlNet cnetFilename = "<<cnetFilename<<" cnet = "<<cnet;
175  emit newControlNetwork(cnet);
176  }
177 
178 
179 
180  void ChipViewportsWidget::setPoint(ControlPoint *controlPoint) {
181 
182  // TODO TLS 5/2/2016 Error checks - Make sure there is control net, serial list
183  // and valid edit point (make sure editpoint exists in control net).
184 
185  //qDebug()<<"ChipViewportsWidget::setEditPoint incoming ptId = "<<controlPoint->GetId();
186  // Create the measure editor widget for the reference measure first if it exists.
187  // TODO, is there always a reference measure returned, or could there be an exception thrown?
188 
189  // Create a control measure editor for each measure first since we need to get its templateFileName
190  // later
191  // TODO 5-23-2016 TLS Delete measure widgets before clearing QList
192 // qDebug()<<"ChipViewportsWidget::setEditPoint #measureEditors = "<<m_measureEditors.size();
193  if (m_chipViewports.size() > 0) clearPoint();
194  m_controlPoint = controlPoint;
195 
196  // Write pointId
197  QString CPId = m_controlPoint->GetId();
198  QString ptId("Point ID: ");
199  ptId += (QString) CPId;
200  m_ptIdValue->setText(ptId);
201 
202 // m_cubeMeasureEditMap.clear();
203 // qDebug()<<"ChipViewportsWidget::setEditPoint pt = "<<controlPoint->GetId();
204 // qDebug()<<" Control Net = "<<m_controlNet;
205  // Find reference measure first, the measure editor needs the reference measure to load the
206  // chip viewport properly (needs to geom to Reference measure).
207  if (m_controlPoint->IsReferenceExplicit()) {
208 
209 
210  Cube *measureCube = new Cube(m_serialNumberList->fileName(
211  m_controlPoint->GetRefMeasure()->GetCubeSerialNumber()));
212  Chip *chip = new Chip(VIEWSIZE, VIEWSIZE);
213  ControlMeasure *measure = m_controlPoint->GetRefMeasure();
214  chip->TackCube(measure->GetSample(), measure->GetLine());
215  chip->Load(*measureCube);
216  ChipViewport *measureChipViewport = new ChipViewport(VIEWSIZE, VIEWSIZE, this);
217  measureChipViewport->setChip(chip, measureCube);
218  measureChipViewport->setControlNet(m_controlNet);
219  measureChipViewport->setPoints(true);
220  m_chipViewports.append(measureChipViewport);
221  }
222 
223 // qDebug()<<"ChipViewportsWidget::setPoint Before measure loop #measureEditors = "<<m_measureEditors.size();
224 // bool referenceMeasure = false;
225  for (int i = 0; i < m_controlPoint->GetNumMeasures(); i++) {
226  ControlMeasure *measure = (*m_controlPoint)[i];
227  if (!m_controlPoint->IsReferenceExplicit() && i == 0) {
228  // Use first as reference measure
229 // referenceMeasure = true;
230 // qDebug()<<"ChipViewportsWidget::setPoint NO Skip Reference Measure i= "<<i;
231  }
232  else if (m_controlPoint->IsReferenceExplicit() &&
233  (QString) measure->GetCubeSerialNumber() == m_controlPoint->GetReferenceSN()) {
234  // We've already added explicit reference measure, so skip
235 // qDebug()<<"ChipViewportsWidget::setPoint Skip Reference Measure i= "<<i;
236  continue;
237  }
238 // qDebug()<<" after Test for Skip Reference Measure i= "<<i;
239  Cube *measureCube = new Cube(m_serialNumberList->fileName(measure->GetCubeSerialNumber()));
240  Chip *chip = new Chip(VIEWSIZE, VIEWSIZE);
241 // measure = m_controlPoint->GetRefMeasure();
242  chip->TackCube(measure->GetSample(), measure->GetLine());
243  chip->Load(*measureCube);
244  ChipViewport *measureChipViewport = new ChipViewport(VIEWSIZE, VIEWSIZE, this);
245  measureChipViewport->setChip(chip, measureCube);
246  measureChipViewport->setControlNet(m_controlNet);
247  measureChipViewport->setPoints(true);
248  m_chipViewports.append(measureChipViewport);
249  }
250 
251 // qDebug()<<"ChipViewportsWidget::setPoint before adding editors to layout #editors = "<<m_measureEditors.size();
252 // TODO 5/19/2016 TLS Clear old measure widgets before re-filling
253  // Add all measure editors to layout
254  int gridDimension = sqrt(qreal(m_chipViewports.size())) -1;
255  int x = 0;
256  int y = 0;
257  foreach(ChipViewport *measurechipViewport, m_chipViewports) {
258  if (x > gridDimension) {
259  x = 0;
260  y++;
261  }
262  m_chipViewportsLayout->addWidget(measurechipViewport, y, x);
263  x++;
264  }
265  }
266 
267 
268 
274 #if 0
275  void ChipViewportsWidget::readSettings() {
276  FileName config("$HOME/.Isis/qview/ChipViewportsWidget.config");
277  QSettings settings(config.expanded(),
278  QSettings::NativeFormat);
279  QPoint pos = settings.value("pos", QPoint(300, 100)).toPoint();
280  QSize size = settings.value("size", QSize(900, 500)).toSize();
281  this->resize(size);
282  this->move(pos);
283  }
284 
285 
292  void ChipViewportsWidget::writeSettings() const {
293  /*We do not want to write the settings unless the window is
294  visible at the time of closing the application*/
295  if (!this->isVisible()) return;
296  FileName config("$HOME/.Isis/qview/ChipViewportsWidget.config");
297  QSettings settings(config.expanded(),
298  QSettings::NativeFormat);
299  settings.setValue("pos", this->pos());
300  settings.setValue("size", this->size());
301  }
302 #endif
303 
304 
305 
306  void ChipViewportsWidget::showPoints(bool showPoints) {
307 
308  foreach (ChipViewport *chipViewport, m_chipViewports) {
309  chipViewport->setPoints(showPoints);
310  }
311  }
312 
313 
314 
315  void ChipViewportsWidget::geomChips(bool geomChips) {
316 
317  if (!geomChips) {
318  for (int i=1; i<m_chipViewports.size(); i++) {
319  m_chipViewports.at(i)->nogeomChip();
320  }
321  }
322 
323  if (geomChips) {
324  for (int i=1; i<m_chipViewports.size(); i++) {
325  m_chipViewports.at(i)->geomChip(m_chipViewports.at(0)->chip(),
326  m_chipViewports.at(0)->chipCube());
327  }
328  }
329  }
330 
331 
332 
333  void ChipViewportsWidget::clearPoint() {
334 // qDebug()<<"ChipViewportsWidget::clearPoint #measureEditors = "<<m_measureEditors.size();
335  if (m_chipViewports.size() > 0) {
336  foreach (ChipViewport *measureChipViewport, m_chipViewports) {
337 // qDebug()<<" measureEditor = "<<measureEditor;
338  delete measureChipViewport;
339  }
340  m_chipViewports.clear();
341  }
342 // m_controlPoint = NULL;
343  }
344 
345 
346  bool ChipViewportsWidget::eventFilter(QObject *object, QEvent *event) {
347 
348  bool blockEvent = false;
349 
350  switch (event->type()) {
351  case QEvent::MouseButtonPress: {
352  mousePressEvent(object, (QMouseEvent *)event);
353  blockEvent = true;
354  break;
355  }
356 
357  default:
358  break;
359  }
360  return blockEvent;
361  }
362 
363 
364  void ChipViewportsWidget::mousePressEvent(QObject *object, QMouseEvent *event) {
365 
366  if (event->button() == Qt::RightButton) {
367  qDebug()<<"ChipViewportsWidget::mousePressEvent right mouse";
368  // Find child widget (ChipViewport) under the mouse
369  ChipViewport *chipViewport = qobject_cast<ChipViewport *>(focusWidget());
370 
371  QMenu contextMenu;
372 
373  QAction *setReferenceMeasureAction = new QAction(tr("Set as Reference Measure"), this);
374  contextMenu.addAction(setReferenceMeasureAction);
375 
376  QAction *chosenAction =
377  contextMenu.exec(qobject_cast<QWidget *>(object)->mapToGlobal(event->pos()));
378 
379  if (chosenAction == setReferenceMeasureAction) {
380  qDebug()<<"ChipViewportsWidget::mousePressEvent setRefMeasureAction chipViewport = "<<chipViewport;
381  //setNewReferenceMeasure(chipViewport);
382  }
383  }
384  }
385 }
QWidget
Isis::VIEWSIZE
const int VIEWSIZE
Constant representing the length and width of the chip viewports.
Definition: ChipViewportsWidget.cpp:48
Isis::Chip::TackCube
void TackCube(const double cubeSample, const double cubeLine)
This sets which cube position will be located at the chip tack position.
Definition: Chip.cpp:182
QMenu
Isis::ChipViewportsWidget::showPoints
void showPoints(bool showPoints)
This method is called from the constructor so that when the Main window is created,...
Definition: ChipViewportsWidget.cpp:306
Isis::Chip::Load
void Load(Cube &cube, const double rotation=0.0, const double scale=1.0, const int band=1)
Load cube data into the Chip.
Definition: Chip.cpp:203
Isis::ChipViewport::setControlNet
void setControlNet(ControlNet *newControlNet)
sets the ControlNet to be used for drawing measure locations
Definition: ChipViewport.h:167
Isis::ControlPoint
A single control point.
Definition: ControlPoint.h:354
Isis::ChipViewportsWidget::createChipViewports
void createChipViewports(QWidget *parent)
create the widget for display all ControlMeasures for ControlPoint as ChipViewports
Definition: ChipViewportsWidget.cpp:90
Isis::ControlNet
a control network
Definition: ControlNet.h:257
Isis::Cube
IO Handler for Isis Cubes.
Definition: Cube.h:167
Isis::ChipViewport
Viewport for Isis Chips.
Definition: ChipViewport.h:71
Isis::ChipViewport::setChip
void setChip(Chip *chip, Cube *chipCube)
Set chip.
Definition: ChipViewport.cpp:110
std
Namespace for the standard library.
Isis::Chip
A small chip of data used for pattern matching.
Definition: Chip.h:86
Isis::ChipViewport::setPoints
void setPoints(bool checked)
Slot to set whether control points are drawn.
Definition: ChipViewport.cpp:556
Isis::SerialNumberList::fileName
QString fileName(const QString &sn)
Return a filename given a serial number.
Definition: SerialNumberList.cpp:399
QObject
QAction
Isis::ChipViewportsWidget::setControlNet
void setControlNet(ControlNet *cnet, QString cnetFilename)
New control network being edited.
Definition: ChipViewportsWidget.cpp:167
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::ControlMeasure
a control measurement
Definition: ControlMeasure.h:175