Isis 3 Programmer Reference
AbstractMeasureItem.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "IsisDebug.h"
10 
11 #include "AbstractMeasureItem.h"
12 
13 #include <QMessageBox>
14 #include <QString>
15 #include <QVariant>
16 
17 #include "CnetDisplayProperties.h"
18 #include "ControlMeasure.h"
19 #include "ControlMeasureLogData.h"
20 #include "ControlPoint.h"
21 #include "IException.h"
22 
23 
24 #include "TableColumn.h"
25 #include "TableColumnList.h"
26 
27 
28 namespace Isis {
29  QString AbstractMeasureItem::getColumnName(Column col) {
30  switch (col) {
31  case PointId:
32  return "Point ID";
33  case ImageId:
34  return "Image ID";
35  case Sample:
36  return "Sample";
37  case Line:
38  return "Line";
39  case EditLock:
40  return "Edit Locked";
41  case Ignored:
42  return "Ignored";
43  case Reference:
44  return "Reference";
45  case Type:
46  return "Measure Type";
47  case Obsolete_Eccentricity:
48  return "Obsolete_Eccentricity";
49  case GoodnessOfFit:
50  return "Goodness of Fit";
51  case MinPixelZScore:
52  return "Minimum Pixel Z-Score";
53  case MaxPixelZScore:
54  return "Maximum Pixel Z-Score";
55  case SampleShift:
56  return "Sample Shift";
57  case LineShift:
58  return "Line Shift";
59  case SampleSigma:
60  return "Sample Sigma";
61  case LineSigma:
62  return "Line Sigma";
63  case APrioriSample:
64  return "A Priori Sample";
65  case APrioriLine:
66  return "A Priori Line";
67  case Diameter:
68  return "Diameter";
69  case JigsawRejected:
70  return "Rejected by Jigsaw";
71  case ResidualSample:
72  return "Residual Sample";
73  case ResidualLine:
74  return "Residual Line";
75  case ResidualMagnitude:
76  return "Residual Magnitude";
77  }
78 
79  ASSERT(0);
80  return QString();
81  }
82 
83 
84  AbstractMeasureItem::Column AbstractMeasureItem::getColumn(
85  QString columnTitle) {
86  for (int i = 0; i < COLS; i++) {
87  if (columnTitle == getColumnName((Column) i))
88  return (Column) i;
89  }
90 
91  QString msg = "Column title [" + columnTitle + "] does not match any of "
92  "the defined column types";
93  throw IException(IException::Programmer, msg, _FILEINFO_);
94  }
95 
96 
97  TableColumnList *AbstractMeasureItem::createColumns() {
98  TableColumnList *columnList = new TableColumnList;
99 
100  columnList->append(new TableColumn(getColumnName(PointId), true, false));
101  columnList->append(new TableColumn(getColumnName(ImageId), true,
102  true));
103  columnList->append(new TableColumn(getColumnName(Sample), true, false));
104  columnList->append(new TableColumn(getColumnName(Line), true, false));
105  columnList->append(new TableColumn(getColumnName(EditLock), false,
106  false));
107  columnList->append(new TableColumn(getColumnName(Ignored), false, true));
108  columnList->append(new TableColumn(getColumnName(Reference), true, true));
109  columnList->append(new TableColumn(getColumnName(Type), false, false));
110  columnList->append(new TableColumn(getColumnName(Obsolete_Eccentricity), true,
111  false));
112  columnList->append(new TableColumn(getColumnName(GoodnessOfFit), true,
113  false));
114  columnList->append(new TableColumn(getColumnName(MinPixelZScore), true,
115  false));
116  columnList->append(new TableColumn(getColumnName(MaxPixelZScore), true,
117  false));
118  columnList->append(new TableColumn(getColumnName(SampleShift), true,
119  false));
120  columnList->append(new TableColumn(getColumnName(LineShift), true,
121  false));
122  columnList->append(new TableColumn(getColumnName(SampleSigma), false,
123  false));
124  columnList->append(new TableColumn(getColumnName(LineSigma), false,
125  false));
126  columnList->append(new TableColumn(getColumnName(APrioriSample), true,
127  false));
128  columnList->append(new TableColumn(getColumnName(APrioriLine), true,
129  false));
130  columnList->append(new TableColumn(getColumnName(Diameter), false,
131  false));
132  columnList->append(new TableColumn(getColumnName(JigsawRejected), true,
133  false));
134  columnList->append(new TableColumn(getColumnName(ResidualSample), true,
135  false));
136  columnList->append(new TableColumn(getColumnName(ResidualLine), true,
137  false));
138  columnList->append(new TableColumn(getColumnName(ResidualMagnitude),
139  true, false));
140 
141  return columnList;
142  }
143 
144  AbstractMeasureItem::AbstractMeasureItem(ControlMeasure *cm,
145  int avgCharWidth, AbstractTreeItem *parent)
146  : AbstractTreeItem(parent) {
147  ASSERT(cm);
148  m_measure = cm;
149  calcDataWidth(avgCharWidth);
150 
151  connect(m_measure, SIGNAL(destroyed(QObject *)), this, SLOT(sourceDeleted()));
152  }
153 
154 
155  AbstractMeasureItem::~AbstractMeasureItem() {
156  m_measure = NULL;
157  }
158 
159 
160  QVariant AbstractMeasureItem::getData() const {
161  return getData(getColumnName(ImageId));
162  }
163 
164 
165  QVariant AbstractMeasureItem::getData(QString columnTitle) const {
166  if (m_measure) {
167  Column column = getColumn(columnTitle);
168 
169  switch ((Column) column) {
170  case PointId:
171  return QVariant((QString) m_measure->Parent()->GetId());
172  case ImageId:
173  return QVariant(CnetDisplayProperties::getInstance()->getImageName(
174  (QString) m_measure->GetCubeSerialNumber()));
175  case Sample:
176  return QVariant(m_measure->GetSample());
177  case Line:
178  return QVariant(m_measure->GetLine());
179  case EditLock:
180  if (m_measure->IsEditLocked())
181  return QVariant("Yes");
182  else
183  return QVariant("No");
184  case Ignored:
185  if (m_measure->IsIgnored())
186  return QVariant("Yes");
187  else
188  return QVariant("No");
189  case Reference:
190  if (m_measure->Parent()->GetRefMeasure() == m_measure)
191  return QVariant("Yes");
192  else
193  return QVariant("No");
194  case Type:
195  return QVariant(
196  (QString)m_measure->MeasureTypeToString(m_measure->GetType()));
197  case Obsolete_Eccentricity:
198  return QVariant(
199  m_measure->GetLogData(
201  case GoodnessOfFit:
202  return QVariant(
203  m_measure->GetLogData(
205  case MinPixelZScore:
206  return QVariant(
207  m_measure->GetLogData(ControlMeasureLogData::MinimumPixelZScore).
208  GetNumericalValue());
209  case MaxPixelZScore:
210  return QVariant(
211  m_measure->GetLogData(ControlMeasureLogData::MaximumPixelZScore).
212  GetNumericalValue());
213  case SampleShift:
214  return QVariant(m_measure->GetSampleShift());
215  case LineShift:
216  return QVariant(m_measure->GetLineShift());
217  case SampleSigma:
218  return QVariant(m_measure->GetSampleSigma());
219  case LineSigma:
220  return QVariant(m_measure->GetLineSigma());
221  case APrioriSample:
222  return QVariant(m_measure->GetAprioriSample());
223  case APrioriLine:
224  return QVariant(m_measure->GetAprioriLine());
225  case Diameter:
226  return QVariant(m_measure->GetDiameter());
227  case JigsawRejected:
228  if (m_measure->IsRejected())
229  return QVariant("Yes");
230  else
231  return QVariant("No");
232  case ResidualSample:
233  return QVariant(m_measure->GetSampleResidual());
234  case ResidualLine:
235  return QVariant(m_measure->GetLineResidual());
236  case ResidualMagnitude:
237  return QVariant(
238  m_measure->GetResidualMagnitude());
239  }
240  }
241 
242  return QVariant();
243  }
244 
245 
246  void AbstractMeasureItem::setData(QString const &columnTitle,
247  QString const &newData) {
248  if (m_measure) {
249  Column column = getColumn(columnTitle);
250 
251  switch ((Column) column) {
252  case PointId:
253  // PointId is not editable in the measure table
254  break;
255  case ImageId:
256  m_measure->SetCubeSerialNumber(
257  CnetDisplayProperties::getInstance()->getSerialNumber(newData));
258  break;
259  case Sample:
260  m_measure->SetCoordinate(catchNull(newData),
261  m_measure->GetLine());
262  break;
263  case Line:
264  m_measure->SetCoordinate(m_measure->GetSample(),
265  catchNull(newData));
266  break;
267  case EditLock:
268  if (newData == "Yes")
269  m_measure->SetEditLock(true);
270  else
271  m_measure->SetEditLock(false);
272  break;
273  case Ignored:
274  if (newData == "Yes")
275  m_measure->SetIgnored(true);
276  else if (newData == "No")
277  m_measure->SetIgnored(false);
278  break;
279  case Reference:
280  // A measure's reference status should never be editable. It should
281  // only be changed through the point.
282  break;
283  case Type:
284  m_measure->SetType(m_measure->StringToMeasureType(
285  CnetDisplayProperties::getInstance()->getSerialNumber(
286  newData)));
287  break;
288  case Obsolete_Eccentricity:
289  setLogData(m_measure, ControlMeasureLogData::Obsolete_Eccentricity, newData);
290  break;
291  case GoodnessOfFit:
292  setLogData(m_measure, ControlMeasureLogData::GoodnessOfFit, newData);
293  break;
294  case MinPixelZScore:
295  setLogData(m_measure, ControlMeasureLogData::MinimumPixelZScore,
296  newData);
297  break;
298  case MaxPixelZScore:
299  setLogData(m_measure, ControlMeasureLogData::MaximumPixelZScore,
300  newData);
301  break;
302  case SampleShift:
303  // This is not editable anymore.
304  break;
305  case LineShift:
306  // This is not editable anymore.
307  break;
308  case SampleSigma:
309  m_measure->SetSampleSigma(catchNull(newData));
310  break;
311  case LineSigma:
312  m_measure->SetLineSigma(catchNull(newData));
313  break;
314  case APrioriSample:
315  m_measure->SetAprioriSample(catchNull(newData));
316  break;
317  case APrioriLine:
318  m_measure->SetAprioriLine(catchNull(newData));
319  break;
320  case Diameter:
321  m_measure->SetDiameter(catchNull(newData));
322  break;
323  case JigsawRejected:
324  // jigsaw rejected is not editable!
325  break;
326  case ResidualSample:
327  m_measure->SetResidual(
328  catchNull(newData), m_measure->GetLineResidual());
329  break;
330  case ResidualLine:
331  m_measure->SetResidual(
332  m_measure->GetSampleResidual(), catchNull(newData));
333  break;
334  case ResidualMagnitude:
335  // residual magnitude is not editable!
336  break;
337  }
338  }
339  }
340 
341 
342  // Returns true if the data at the given column is locked (i.e. is
343  // edit-locked). If the m_measure is edit-locked, all columns except the edit
344  // lock column should be uneditable. If the m_measure's parent point is
345  // edit-locked, none of the columns should be editable as it should only be
346  // unlocked from the parent point.
347  bool AbstractMeasureItem::isDataEditable(QString columnTitle) const {
348  bool parentLocked = !m_measure->Parent() ||
349  m_measure->Parent()->IsEditLocked();
350  bool locked = m_measure->IsEditLocked() || parentLocked;
351 
352  if (getColumn(columnTitle) == EditLock && !parentLocked) {
353  locked = false;
354  }
355 
356  return !locked;
357  }
358 
359 
360  void AbstractMeasureItem::deleteSource() {
361  if (m_measure) {
362  if (m_measure->Parent()->IsEditLocked()) {
363  QString msg = "Measures in point [" +
364  getFormattedData(getColumnName(PointId)) +
365  "] cannot be deleted because point is edit locked";
366  throw IException(IException::User, msg, _FILEINFO_);
367  }
368 
369  else if (m_measure->IsEditLocked()) {
370  QString msg = "Measure [" + getFormattedData() + "] in point [" +
371  getFormattedData(getColumnName(PointId)) +
372  "] cannot be deleted because m_measure is edit locked";
373  throw IException(IException::User, msg, _FILEINFO_);
374  }
375  // else if (m_measure->Parent()->GetRefMeasure() == m_measure) {
376  // QString msg = "Measure [" + getData() + "] in point [" +
377  // getData(getColumnName(PointId)) + "] cannot be deleted because "
378  // "it is the reference";
379  // throw iException::Message(iException::User, msg, _FILEINFO_);
380  // }
381 
382  ControlMeasure *tempMeasure = m_measure;
383  m_measure = NULL;
384  tempMeasure->Parent()->Delete(tempMeasure);
385  }
386  }
387 
388 
389  AbstractTreeItem::InternalPointerType AbstractMeasureItem::getPointerType()
390  const {
391  return AbstractTreeItem::Measure;
392  }
393 
394 
395  void *AbstractMeasureItem::getPointer() const {
396  return m_measure;
397  }
398 
399 
400  bool AbstractMeasureItem::hasMeasure(ControlMeasure *m) const {
401  return m_measure == m;
402  }
403 
404 
405  void AbstractMeasureItem::sourceDeleted() {
406  m_measure = NULL;
407  }
408 
409 
410  void AbstractMeasureItem::setLogData(ControlMeasure *m_measure,
411  int m_measureLogDataEnum, const QString &value) {
412  ASSERT(m_measure);
413 
414  QString newDataStr = value.toLower();
416  (ControlMeasureLogData::NumericLogDataType) m_measureLogDataEnum;
417 
418  if (newDataStr == "null") {
419  m_measure->DeleteLogData(type);
420  }
421  else {
422  m_measure->SetLogData(ControlMeasureLogData(type,
423  value.toDouble()));
424  }
425  }
426 }
Isis::ControlMeasure::GetResidualMagnitude
double GetResidualMagnitude() const
Return Residual magnitude.
Definition: ControlMeasure.cpp:712
Isis::ControlMeasureLogData::GetNumericalValue
double GetNumericalValue() const
Get the value associated with this log data.
Definition: ControlMeasureLogData.cpp:123
Isis::ControlMeasure::SetCubeSerialNumber
Status SetCubeSerialNumber(QString newSerialNumber)
Set cube serial number.
Definition: ControlMeasure.cpp:187
Isis::ControlMeasure::StringToMeasureType
static MeasureType StringToMeasureType(QString str)
Definition: ControlMeasure.cpp:919
Isis::ControlMeasureLogData::NumericLogDataType
NumericLogDataType
Please do not change existing values in this list except the size - it will break backwards compadibi...
Definition: ControlMeasureLogData.h:49
Isis::ControlMeasureLogData::MaximumPixelZScore
@ MaximumPixelZScore
Definition: ControlMeasureLogData.h:81
Isis::ControlMeasure::SetResidual
Status SetResidual(double sampResidual, double lineResidual)
Set the BundleAdjust Residual of the coordinate.
Definition: ControlMeasure.cpp:399
Isis::ControlPoint::GetId
QString GetId() const
Return the Id of the control point.
Definition: ControlPoint.cpp:1306
Isis::ControlMeasure::GetCubeSerialNumber
QString GetCubeSerialNumber() const
Return the serial number of the cube containing the coordinate.
Definition: ControlMeasure.cpp:557
Isis::ControlMeasureLogData::MinimumPixelZScore
@ MinimumPixelZScore
Control measures store z-scores in pairs.
Definition: ControlMeasureLogData.h:76
Isis::ControlMeasure::MeasureTypeToString
static QString MeasureTypeToString(MeasureType type)
Return the String Control Measure type.
Definition: ControlMeasure.cpp:951
Isis::ControlMeasure::IsEditLocked
bool IsEditLocked() const
Return value for p_editLock or implicit lock on reference measure.
Definition: ControlMeasure.cpp:601
Isis::ControlMeasure::GetDiameter
double GetDiameter() const
Return the diameter of the crater in pixels (0 implies no crater)
Definition: ControlMeasure.cpp:580
Isis::ControlMeasure::SetDiameter
Status SetDiameter(double diameter)
Set the crater diameter at the coordinate.
Definition: ControlMeasure.cpp:272
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::ControlPoint::GetRefMeasure
const ControlMeasure * GetRefMeasure() const
Get the reference control measure.
Definition: ControlPoint.cpp:457
Isis::ControlPoint::Delete
int Delete(ControlMeasure *measure)
Remove a measurement from the control point, deleting reference measure is allowed.
Definition: ControlPoint.cpp:354
Isis::ControlMeasureLogData::GoodnessOfFit
@ GoodnessOfFit
GoodnessOfFit is pointreg information for reference measures.
Definition: ControlMeasureLogData.h:67
Isis::ControlMeasure::SetType
Status SetType(MeasureType type)
Set how the coordinate was obtained.
Definition: ControlMeasure.cpp:420
Isis::ControlMeasureLogData::Obsolete_Eccentricity
@ Obsolete_Eccentricity
Deprecated keyword kept for backwards compatability with older Control Networks.
Definition: ControlMeasureLogData.h:59
QObject
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::ControlMeasure::SetCoordinate
Status SetCoordinate(double sample, double line)
Set the coordinate of the measurement.
Definition: ControlMeasure.cpp:219
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126