Isis 3.0 Programmer Reference
Back | Home
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 
12 #include "Application.h"
13 #include "Camera.h"
14 #include "ChipViewport.h"
15 #include "ControlMeasureEditWidget.h"
16 #include "ControlMeasure.h"
17 #include "ControlMeasureLogData.h"
18 #include "ControlNet.h"
19 #include "ControlPoint.h"
20 #include "Cube.h"
21 #include "FileName.h"
22 #include "IException.h"
23 #include "Latitude.h"
24 #include "Longitude.h"
25 #include "MainWindow.h"
26 #include "MdiCubeViewport.h"
27 #include "Pvl.h"
28 #include "PvlEditDialog.h"
29 #include "SerialNumber.h"
30 #include "SerialNumberList.h"
31 #include "SpecialPixel.h"
32 #include "ToolPad.h"
33 #include "ViewportMainWindow.h"
34 #include "Workspace.h"
35 
36 using namespace std;
37 
38 namespace Isis {
39  const int VIEWSIZE = 301;
40 
47  ChipViewportsWidget::ChipViewportsWidget (QWidget *parent) : QWidget(parent) {
48 
49  m_netChanged = false;
50 
51  m_parent = parent;
52 
53  // TODO 05/10/2016 TLS What is the right way to handle serial number lists in IPCE?
54  m_serialNumberList = NULL;
55 
56 // m_cubeMeasureEditMap = QMap<Cube *, ControlMeasureEditWidget *>();
57 
58  createChipViewports(parent);
59 
60 // connect(this, SIGNAL(newControlNetwork(ControlNet *)),
61 // m_measureEditor, SIGNAL(newControlNetwork(ControlNet *)));
62  }
63 
64 
65  ChipViewportsWidget::~ChipViewportsWidget () {
66  // TODO: Don't write settings in destructor, must do this earlier in close event
67 // writeSettings();
68 
69  }
70 
71 
72 
80 
81  setWindowTitle("ChipViewports");
82  setObjectName("ChipViewportsWidget");
83  connect(this, SIGNAL(destroyed(QObject *)), this, SLOT(clearPoint()));
84 
85 // createActions();
86 
87  m_chipViewportsLayout = new QGridLayout;
88 
89  QWidget *centralWidget = new QWidget;
90  centralWidget->setLayout(m_chipViewportsLayout);
91 
92  QScrollArea *scrollArea = new QScrollArea();
93  scrollArea->setObjectName("ChipViewportsWidgetScroll");
94  scrollArea->setWidgetResizable(true);
95  scrollArea->setWidget(centralWidget);
96  centralWidget->adjustSize();
97 
98  QVBoxLayout *mainLayout = new QVBoxLayout;
99 
100  m_ptIdValue = new QLabel();
101 
102  QCheckBox *showPoints = new QCheckBox("Show control points");
103  showPoints->setToolTip("Draw control point crosshairs");
104  showPoints->setWhatsThis("This will toggle whether crosshairs are drawn"
105  " for the control points located within the measure''s"
106  " view. For areas of dense measurements, turning this"
107  " off will allow easier viewing of features.");
108  connect(showPoints, SIGNAL(toggled(bool)), this, SLOT(showPoints(bool)));
109  showPoints->setChecked(true);
110 
111  QCheckBox *geomChips = new QCheckBox("Geom Chips to Reference");
112  geomChips->setToolTip("Geom Chips to Reference Control Measure");
113  geomChips->setWhatsThis("This will toggle whether chips are geomed to"
114  " the reference control measure.");
115  connect(geomChips, SIGNAL(toggled(bool)), this, SLOT(geomChips(bool)));
116  geomChips->setChecked(false);
117 
118  QHBoxLayout *pointsGeomLayout = new QHBoxLayout;
119  pointsGeomLayout->addWidget(showPoints);
120  pointsGeomLayout->addWidget(geomChips);
121  pointsGeomLayout->addStretch();
122 
123  mainLayout->addWidget(m_ptIdValue);
124  mainLayout->addLayout(pointsGeomLayout);
125  mainLayout->addWidget(scrollArea);
126  setLayout(mainLayout);
127 
128 // readSettings();
129  }
130 
131 
132 
133  void ChipViewportsWidget::createActions() {
134 
135  }
136 
137 
138 
139  void ChipViewportsWidget::setSerialNumberList(SerialNumberList *snList) {
140 
141 // qDebug()<<"ChipViewportsWidget::setSerialNumberList snList = "<<snList;
142  // TODO If network & snList already exists do some error checking
143  m_serialNumberList = snList;
144  }
145 
146 
147 
156  void ChipViewportsWidget::setControlNet(ControlNet *cnet, QString cnetFilename) {
157 // qDebug()<<"ChipViewportsWidget::setControlNet cnet = "<<cnet<<" filename = "<<cnetFilename;
158  // TODO more error checking
159  m_controlNet = cnet;
160  m_cnetFileName = cnetFilename;
161 // setWindowTitle("Control Point Editor- Control Network File: " + cnetFilename);
162 
163  //qDebug()<<"ChipViewportsWidget::setControlNet cnetFilename = "<<cnetFilename<<" cnet = "<<cnet;
164  emit newControlNetwork(cnet);
165  }
166 
167 
168 
169  void ChipViewportsWidget::setPoint(ControlPoint *controlPoint) {
170 
171  // TODO TLS 5/2/2016 Error checks - Make sure there is control net, serial list
172  // and valid edit point (make sure editpoint exists in control net).
173 
174  //qDebug()<<"ChipViewportsWidget::setEditPoint incoming ptId = "<<controlPoint->GetId();
175  // Create the measure editor widget for the reference measure first if it exists.
176  // TODO, is there always a reference measure returned, or could there be an exception thrown?
177 
178  // Create a control measure editor for each measure first since we need to get its templateFileName
179  // later
180  // TODO 5-23-2016 TLS Delete measure widgets before clearing QList
181 // qDebug()<<"ChipViewportsWidget::setEditPoint #measureEditors = "<<m_measureEditors.size();
182  if (m_chipViewports.size() > 0) clearPoint();
183  m_controlPoint = controlPoint;
184 
185  // Write pointId
186  QString CPId = m_controlPoint->GetId();
187  QString ptId("Point ID: ");
188  ptId += (QString) CPId;
189  m_ptIdValue->setText(ptId);
190 
191 // m_cubeMeasureEditMap.clear();
192 // qDebug()<<"ChipViewportsWidget::setEditPoint pt = "<<controlPoint->GetId();
193  qDebug()<<" Control Net = "<<m_controlNet;
194  // Find reference measure first, the measure editor needs the reference measure to load the
195  // chip viewport properly (needs to geom to Reference measure).
196  if (m_controlPoint->IsReferenceExplicit()) {
197 
198 
199  Cube *measureCube = new Cube(m_serialNumberList->fileName(
200  m_controlPoint->GetRefMeasure()->GetCubeSerialNumber()));
201  Chip *chip = new Chip(VIEWSIZE, VIEWSIZE);
202  ControlMeasure *measure = m_controlPoint->GetRefMeasure();
203  chip->TackCube(measure->GetSample(), measure->GetLine());
204  chip->Load(*measureCube);
205  ChipViewport *measureChipViewport = new ChipViewport(VIEWSIZE, VIEWSIZE, this);
206  measureChipViewport->setChip(chip, measureCube);
207  measureChipViewport->setControlNet(m_controlNet);
208  measureChipViewport->setPoints(true);
209  m_chipViewports.append(measureChipViewport);
210  }
211 
212 // qDebug()<<"ChipViewportsWidget::setPoint Before measure loop #measureEditors = "<<m_measureEditors.size();
213 // bool referenceMeasure = false;
214  for (int i = 0; i < m_controlPoint->GetNumMeasures(); i++) {
215  ControlMeasure *measure = (*m_controlPoint)[i];
216  if (!m_controlPoint->IsReferenceExplicit() && i == 0) {
217  // Use first as reference measure
218 // referenceMeasure = true;
219 // qDebug()<<"ChipViewportsWidget::setPoint NO Skip Reference Measure i= "<<i;
220  }
221  else if (m_controlPoint->IsReferenceExplicit() &&
222  (QString) measure->GetCubeSerialNumber() == m_controlPoint->GetReferenceSN()) {
223  // We've already added explicit reference measure, so skip
224 // qDebug()<<"ChipViewportsWidget::setPoint Skip Reference Measure i= "<<i;
225  continue;
226  }
227 // qDebug()<<" after Test for Skip Reference Measure i= "<<i;
228  Cube *measureCube = new Cube(m_serialNumberList->fileName(measure->GetCubeSerialNumber()));
229  Chip *chip = new Chip(VIEWSIZE, VIEWSIZE);
230 // measure = m_controlPoint->GetRefMeasure();
231  chip->TackCube(measure->GetSample(), measure->GetLine());
232  chip->Load(*measureCube);
233  ChipViewport *measureChipViewport = new ChipViewport(VIEWSIZE, VIEWSIZE, this);
234  measureChipViewport->setChip(chip, measureCube);
235  measureChipViewport->setControlNet(m_controlNet);
236  measureChipViewport->setPoints(true);
237  m_chipViewports.append(measureChipViewport);
238  }
239 
240 // qDebug()<<"ChipViewportsWidget::setPoint before adding editors to layout #editors = "<<m_measureEditors.size();
241 // TODO 5/19/2016 TLS Clear old measure widgets before re-filling
242  // Add all measure editors to layout
243  int gridDimension = sqrt(qreal(m_chipViewports.size())) -1;
244  int x = 0;
245  int y = 0;
246  foreach(ChipViewport *measurechipViewport, m_chipViewports) {
247  if (x > gridDimension) {
248  x = 0;
249  y++;
250  }
251  m_chipViewportsLayout->addWidget(measurechipViewport, y, x);
252  x++;
253  }
254  }
255 
256 
257 
263 #if 0
264  void ChipViewportsWidget::readSettings() {
265  FileName config("$HOME/.Isis/qview/ChipViewportsWidget.config");
266  QSettings settings(config.expanded(),
267  QSettings::NativeFormat);
268  QPoint pos = settings.value("pos", QPoint(300, 100)).toPoint();
269  QSize size = settings.value("size", QSize(900, 500)).toSize();
270  this->resize(size);
271  this->move(pos);
272  }
273 
274 
281  void ChipViewportsWidget::writeSettings() const {
282  /*We do not want to write the settings unless the window is
283  visible at the time of closing the application*/
284  if (!this->isVisible()) return;
285  FileName config("$HOME/.Isis/qview/ChipViewportsWidget.config");
286  QSettings settings(config.expanded(),
287  QSettings::NativeFormat);
288  settings.setValue("pos", this->pos());
289  settings.setValue("size", this->size());
290  }
291 #endif
292 
293 
294 
295  void ChipViewportsWidget::showPoints(bool showPoints) {
296 
297  foreach (ChipViewport *chipViewport, m_chipViewports) {
298  chipViewport->setPoints(showPoints);
299  }
300  }
301 
302 
303 
304  void ChipViewportsWidget::geomChips(bool geomChips) {
305 
306  if (!geomChips) {
307  for (int i=1; i<m_chipViewports.size(); i++) {
308  m_chipViewports.at(i)->nogeomChip();
309  }
310  }
311 
312  if (geomChips) {
313  for (int i=1; i<m_chipViewports.size(); i++) {
314  m_chipViewports.at(i)->geomChip(m_chipViewports.at(0)->chip(),
315  m_chipViewports.at(0)->chipCube());
316  }
317  }
318  }
319 
320 
321 
322  void ChipViewportsWidget::clearPoint() {
323 // qDebug()<<"ChipViewportsWidget::clearPoint #measureEditors = "<<m_measureEditors.size();
324  if (m_chipViewports.size() > 0) {
325  foreach (ChipViewport *measureChipViewport, m_chipViewports) {
326 // qDebug()<<" measureEditor = "<<measureEditor;
327  delete measureChipViewport;
328  }
329  m_chipViewports.clear();
330  }
331 // m_controlPoint = NULL;
332  }
333 }
334 
A small chip of data used for pattern matching.
Definition: Chip.h:101
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:207
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:339
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.
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: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:15:53