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