Isis 3.0 Programmer Reference
Back | Home
AbstractPointItem.cpp
1 #include "IsisDebug.h"
2 
3 #include "AbstractPointItem.h"
4 
5 #include <QDateTime>
6 #include <QMessageBox>
7 #include <QString>
8 #include <QVariant>
9 
10 #include "CnetDisplayProperties.h"
11 #include "ControlMeasure.h"
12 #include "ControlNet.h"
13 #include "ControlPoint.h"
14 #include "IException.h"
15 #include "Latitude.h"
16 #include "Longitude.h"
17 #include "TableColumn.h"
18 #include "TableColumnList.h"
19 
20 
21 namespace Isis {
22  namespace CnetViz {
23  QString AbstractPointItem::getColumnName(Column col) {
24  switch (col) {
25  case Id:
26  return "Point ID";
27  case PointType:
28  return "Point Type";
29  case ChooserName:
30  return "Chooser Name";
31  case DateTime:
32  return "Date Time";
33  case EditLock:
34  return "Edit Lock";
35  case Ignored:
36  return "Ignored";
37  case Reference:
38  return "Reference";
39  case AdjustedSPLat:
40  return "Adjusted SP Lat";
41  case AdjustedSPLon:
42  return "Adjusted SP Lon";
43  case AdjustedSPRadius:
44  return "Adjusted SP Radius";
45  case AdjustedSPLatSigma:
46  return "Adjusted SP Lat Sigma";
47  case AdjustedSPLonSigma:
48  return "Adjusted SP Lon Sigma";
49  case AdjustedSPRadiusSigma:
50  return "Adjusted SP Radius Sigma";
51  case APrioriSPLat:
52  return "A Priori SP Lat";
53  case APrioriSPLon:
54  return "A Priori SP Lon";
55  case APrioriSPRadius:
56  return "A Priori SP Radius";
57  case APrioriSPLatSigma:
58  return "A Priori SP Lat Sigma";
59  case APrioriSPLonSigma:
60  return "A Priori SP Lon Sigma";
61  case APrioriSPRadiusSigma:
62  return "A Priori SP Radius Sigma";
63  case APrioriSPSource:
64  return "A Priori SP Source";
65  case APrioriSPSourceFile:
66  return "A Priori SP Source File";
67  case APrioriRadiusSource:
68  return "A Priori Radius Source";
69  case APrioriRadiusSourceFile:
70  return "A Priori Radius Source File";
71  case JigsawRejected:
72  return "Jigsaw Rejected";
73  }
74 
75  ASSERT(0);
76  return QString();
77  }
78 
79 
80  AbstractPointItem::Column AbstractPointItem::getColumn(QString columnTitle) {
81  for (int i = 0; i < COLS; i++) {
82  if (columnTitle == getColumnName((Column)i))
83  return (Column)i;
84  }
85 
86  QString msg = "Column title [" + columnTitle + "] does not match any of "
87  "the defined column types";
88  throw IException(IException::Programmer, msg, _FILEINFO_);
89  }
90 
91 
92  TableColumnList *AbstractPointItem::createColumns() {
93  TableColumnList *columnList = new TableColumnList;
94 
95  columnList->append(new TableColumn(getColumnName(Id), false, false));
96  columnList->append(
97  new TableColumn(getColumnName(PointType), false, false));
98  columnList->append(
99  new TableColumn(getColumnName(ChooserName), false, false));
100  columnList->append(
101  new TableColumn(getColumnName(DateTime), true, false));
102  columnList->append(
103  new TableColumn(getColumnName(EditLock), false, false));
104  columnList->append(
105  new TableColumn(getColumnName(Ignored), false, true));
106  columnList->append(
107  new TableColumn(getColumnName(Reference), false, false));
108  columnList->append(
109  new TableColumn(getColumnName(AdjustedSPLat), true, false));
110  columnList->append(
111  new TableColumn(getColumnName(AdjustedSPLon), true, false));
112  columnList->append(
113  new TableColumn(getColumnName(AdjustedSPRadius), true, false));
114  columnList->append(
115  new TableColumn(getColumnName(AdjustedSPLatSigma), true, false));
116  columnList->append(
117  new TableColumn(getColumnName(AdjustedSPLonSigma), true, false));
118  columnList->append(
119  new TableColumn(getColumnName(AdjustedSPRadiusSigma), true, false));
120  columnList->append(
121  new TableColumn(getColumnName(APrioriSPLat), false, false));
122  columnList->append(
123  new TableColumn(getColumnName(APrioriSPLon), false, false));
124  columnList->append(
125  new TableColumn(getColumnName(APrioriSPRadius), false, false));
126  columnList->append(
127  new TableColumn(getColumnName(APrioriSPLatSigma), false, false));
128  columnList->append(
129  new TableColumn(getColumnName(APrioriSPLonSigma), false, false));
130  columnList->append(
131  new TableColumn(getColumnName(APrioriSPRadiusSigma), false, false));
132  columnList->append(
133  new TableColumn(getColumnName(APrioriSPSource), false, false));
134  columnList->append(
135  new TableColumn(getColumnName(APrioriSPSourceFile), false, false));
136  columnList->append(
137  new TableColumn(getColumnName(APrioriRadiusSource), false, false));
138  columnList->append(new TableColumn(
139  getColumnName(APrioriRadiusSourceFile), false, false));
140  columnList->append(
141  new TableColumn(getColumnName(JigsawRejected), true, false));
142 
143  return columnList;
144  }
145 
146 
147  AbstractPointItem::AbstractPointItem(ControlPoint *cp,
148  int avgCharWidth, AbstractTreeItem *parent)
149  : AbstractTreeItem(parent) {
150  ASSERT(cp);
151  m_point = cp;
152  calcDataWidth(avgCharWidth);
153 
154  connect(m_point, SIGNAL(destroyed(QObject *)), this, SLOT(sourceDeleted()));
155  }
156 
157 
158  AbstractPointItem::~AbstractPointItem() {
159  m_point = NULL;
160  }
161 
162 
163  QVariant AbstractPointItem::getData() const {
164  return getData(getColumnName(Id));
165  }
166 
167 
168  QVariant AbstractPointItem::getData(QString columnTitle) const {
169  if (m_point) {
170  Column column = getColumn(columnTitle);
171 
172  switch ((Column) column) {
173  case Id:
174  return QVariant((QString)m_point->GetId());
175  case PointType:
176  return QVariant((QString)m_point->GetPointTypeString());
177  case ChooserName:
178  return QVariant((QString)m_point->GetChooserName());
179  case DateTime:
180  // return QVariant(QDateTime::fromString(
181  // m_point->GetDateTime(), "yyyy-MM-ddTHH:mm:ss"));
182  return QVariant((QString)m_point->GetDateTime());
183  case EditLock:
184  if (m_point->IsEditLocked())
185  return QVariant("Yes");
186  else
187  return QVariant("No");
188  break;
189  case Ignored:
190  if (m_point->IsIgnored())
191  return QVariant("Yes");
192  else
193  return QVariant("No");
194  case Reference:
195  if (m_point->GetNumMeasures())
196  return QVariant(
197  CnetDisplayProperties::getInstance()->getImageName(
198  (QString) m_point->GetRefMeasure()->GetCubeSerialNumber()));
199  else
200  return QVariant();
201  case AdjustedSPLat:
202  return QVariant(
203  m_point->GetAdjustedSurfacePoint().GetLatitude().degrees());
204  case AdjustedSPLon:
205  return QVariant(
206  m_point->GetAdjustedSurfacePoint().GetLongitude().degrees());
207  case AdjustedSPRadius:
208  return QVariant(
209  m_point->GetAdjustedSurfacePoint().GetLocalRadius().meters());
210  case AdjustedSPLatSigma:
211  return QVariant(
212  m_point->GetAdjustedSurfacePoint().
213  GetLatSigmaDistance().meters());
214  case AdjustedSPLonSigma:
215  return QVariant(
216  m_point->GetAdjustedSurfacePoint().
217  GetLonSigmaDistance().meters());
218  case AdjustedSPRadiusSigma:
219  return QVariant(
220  m_point->GetAdjustedSurfacePoint().
221  GetLocalRadiusSigma().meters());
222  case APrioriSPLat:
223  return QVariant(
224  m_point->GetAprioriSurfacePoint().GetLatitude().degrees());
225  case APrioriSPLon:
226  return QVariant(
227  m_point->GetAprioriSurfacePoint().GetLongitude().degrees());
228  case APrioriSPRadius:
229  return QVariant(
230  m_point->GetAprioriSurfacePoint().GetLocalRadius().meters());
231  case APrioriSPLatSigma:
232  return QVariant(
233  m_point->GetAprioriSurfacePoint().
234  GetLatSigmaDistance().meters());
235  case APrioriSPLonSigma:
236  return QVariant(
237  m_point->GetAprioriSurfacePoint().
238  GetLonSigmaDistance().meters());
239  case APrioriSPRadiusSigma:
240  return QVariant(
241  m_point->GetAprioriSurfacePoint().
242  GetLocalRadiusSigma().meters());
243  case APrioriSPSource:
244  return QVariant((QString)m_point->GetSurfacePointSourceString());
245  case APrioriSPSourceFile:
246  return QVariant((QString)m_point->GetAprioriSurfacePointSourceFile());
247  case APrioriRadiusSource:
248  return QVariant((QString)m_point->GetRadiusSourceString());
249  case APrioriRadiusSourceFile:
250  return QVariant((QString)m_point->GetAprioriRadiusSourceFile());
251  case JigsawRejected:
252  if (m_point->IsRejected())
253  return QVariant("Yes");
254  else
255  return QVariant("No");
256  }
257  }
258 
259  return QVariant();
260  }
261 
262 
263  void AbstractPointItem::setData(QString const &columnTitle,
264  QString const &newData) {
265  if (m_point) {
266  Column column = getColumn(columnTitle);
267 
268  switch ((Column) column) {
269  case Id:
270  m_point->SetId(newData);
271  break;
272  case PointType:
273  m_point->SetType(m_point->StringToPointType(newData));
274  break;
275  case ChooserName:
276  m_point->SetChooserName(newData);
277  break;
278  case DateTime:
279  m_point->SetDateTime(newData);
280  break;
281  case EditLock:
282  if (newData == "Yes")
283  m_point->SetEditLock(true);
284  else
285  m_point->SetEditLock(false);
286  break;
287  case Ignored:
288  m_point->SetIgnored(newData == "Yes");
289  break;
290  case Reference:
291  ASSERT(m_point->HasSerialNumber(newData));
292  m_point->SetRefMeasure(newData);
293  break;
294  case AdjustedSPLat:
295  m_point->SetAdjustedSurfacePoint(SurfacePoint(
296  Latitude(catchNull(newData), Angle::Degrees),
297  m_point->GetAdjustedSurfacePoint().GetLongitude(),
298  m_point->GetAdjustedSurfacePoint().GetLocalRadius()));
299  break;
300  case AdjustedSPLon:
301  m_point->SetAdjustedSurfacePoint(SurfacePoint(
302  m_point->GetAdjustedSurfacePoint().GetLatitude(),
303  Longitude(catchNull(newData), Angle::Degrees),
304  m_point->GetAdjustedSurfacePoint().GetLocalRadius()));
305  break;
306  case AdjustedSPRadius:
307  m_point->SetAdjustedSurfacePoint(SurfacePoint(
308  m_point->GetAdjustedSurfacePoint().GetLatitude(),
309  m_point->GetAdjustedSurfacePoint().GetLongitude(),
310  Distance(catchNull(newData), Distance::Meters)));
311  break;
312  case AdjustedSPLatSigma: {
313  QString msg = "Cannot set adjusted surface point latitude sigma";
314  throw IException(IException::Programmer, msg, _FILEINFO_);
315  break;
316  }
317  case AdjustedSPLonSigma: {
318  QString msg = "Cannot set adjusted surface point longitude sigma";
319  throw IException(IException::Programmer, msg, _FILEINFO_);
320  break;
321  }
322  case AdjustedSPRadiusSigma: {
323  QString msg = "Cannot set adjusted surface point radius sigma";
324  throw IException(IException::Programmer, msg, _FILEINFO_);
325  break;
326  }
327  case APrioriSPLat: {
328  Latitude newLat(catchNull(newData), Angle::Degrees);
329  SurfacePoint newSurfacePoint(prepareSurfacePoint(newLat,
330  m_point->GetAprioriSurfacePoint()));
331 
332  newSurfacePoint.SetSphericalCoordinates(newLat,
333  newSurfacePoint.GetLongitude(),
334  newSurfacePoint.GetLocalRadius());
335  m_point->SetAprioriSurfacePoint(newSurfacePoint);
336  break;
337  }
338  case APrioriSPLon: {
339  Longitude newLon(catchNull(newData), Angle::Degrees);
340  SurfacePoint newSurfacePoint(prepareSurfacePoint(newLon,
341  m_point->GetAprioriSurfacePoint()));
342 
343  newSurfacePoint.SetSphericalCoordinates(
344  newSurfacePoint.GetLatitude(),
345  newLon,
346  newSurfacePoint.GetLocalRadius());
347  m_point->SetAprioriSurfacePoint(newSurfacePoint);
348  break;
349  }
350  case APrioriSPRadius: {
351  Distance newRadius(catchNull(newData), Distance::Meters);
352  SurfacePoint newSurfacePoint(prepareSurfacePoint(newRadius,
353  m_point->GetAprioriSurfacePoint()));
354 
355  newSurfacePoint.SetSphericalCoordinates(
356  newSurfacePoint.GetLatitude(),
357  newSurfacePoint.GetLongitude(),
358  newRadius);
359  m_point->SetAprioriSurfacePoint(newSurfacePoint);
360  break;
361  }
362  case APrioriSPLatSigma: {
363  Distance newSigma(catchNull(newData), Distance::Meters);
364  SurfacePoint newSurfacePoint(prepareSigmas(newSigma,
365  m_point->GetAprioriSurfacePoint()));
366 
367  newSurfacePoint.SetSphericalSigmasDistance(
368  newSigma, newSurfacePoint.GetLonSigmaDistance(),
369  newSurfacePoint.GetLocalRadiusSigma());
370 
371  m_point->SetAprioriSurfacePoint(newSurfacePoint);
372  break;
373  }
374  case APrioriSPLonSigma: {
375  Distance newSigma(catchNull(newData), Distance::Meters);
376  SurfacePoint newSurfacePoint(prepareSigmas(newSigma,
377  m_point->GetAprioriSurfacePoint()));
378 
379  newSurfacePoint.SetSphericalSigmasDistance(
380  newSurfacePoint.GetLatSigmaDistance(), newSigma,
381  newSurfacePoint.GetLocalRadiusSigma());
382 
383  m_point->SetAprioriSurfacePoint(newSurfacePoint);
384  break;
385  }
386  case APrioriSPRadiusSigma: {
387  Distance newSigma(catchNull(newData), Distance::Meters);
388  SurfacePoint newSurfacePoint(prepareSigmas(newSigma,
389  m_point->GetAprioriSurfacePoint()));
390 
391  newSurfacePoint.SetSphericalSigmasDistance(
392  newSurfacePoint.GetLatSigmaDistance(),
393  newSurfacePoint.GetLonSigmaDistance(),
394  newSigma);
395 
396  m_point->SetAprioriSurfacePoint(newSurfacePoint);
397  break;
398  }
399  case APrioriSPSource:
401  m_point->StringToSurfacePointSource(newData));
402  break;
403  case APrioriSPSourceFile:
404  m_point->SetAprioriSurfacePointSourceFile(newData);
405  break;
406  case APrioriRadiusSource:
407  m_point->SetAprioriRadiusSource(
408  m_point->StringToRadiusSource(newData));
409  break;
410  case APrioriRadiusSourceFile:
411  m_point->SetAprioriRadiusSourceFile(newData);
412  break;
413  case JigsawRejected:
414  // jigsaw rejected is not editable!
415  break;
416  }
417  }
418  }
419 
420 
421  // Returns true if the data at the given column is locked (i.e.
422  // edit-locked). If the m_point is edit-locked, all columns except the edit
423  // lock column should be uneditable.
424  bool AbstractPointItem::isDataEditable(QString columnTitle) const {
425  bool locked = true;
426  if (m_point->IsEditLocked()) {
427  if (getColumn(columnTitle) == EditLock)
428  locked = false;
429  }
430  else {
431  locked = false;
432  }
433 
434  return !locked;
435  }
436 
437 
438  void AbstractPointItem::deleteSource() {
439  if (m_point) {
440  if (m_point->IsEditLocked()) {
441  QString msg = "Point [" + getFormattedData() + "] is edit locked and "
442  "cannot be deleted";
443  throw IException(IException::User, msg, _FILEINFO_);
444  }
445  else if (m_point->GetNumLockedMeasures() > 0) {
446  QString msg = "Point [" + getFormattedData() + "] has at least one "
447  "edit locked measure and cannot be deleted";
448  throw IException(IException::User, msg, _FILEINFO_);
449  }
450 
451  ControlPoint *tempPoint = m_point;
452  m_point = NULL;
453  tempPoint->Parent()->DeletePoint(tempPoint);
454  }
455  }
456 
457 
458  AbstractTreeItem::InternalPointerType AbstractPointItem::getPointerType() const {
459  return AbstractTreeItem::Point;
460  }
461 
462 
463  void *AbstractPointItem::getPointer() const {
464  return m_point;
465  }
466 
467 
468  bool AbstractPointItem::hasPoint(ControlPoint *p) const {
469  return m_point == p;
470  }
471 
472  void AbstractPointItem::sourceDeleted() {
473  m_point = NULL;
474  }
475 
476 
477  SurfacePoint AbstractPointItem::prepareSigmas(Distance newSigma,
478  SurfacePoint surfacePoint) {
479  const Distance free(10000, Distance::Meters);
480  Distance latSigDist = surfacePoint.GetLatSigmaDistance();
481  Distance lonSigDist = surfacePoint.GetLonSigmaDistance();
482  Distance radiusSigDist = surfacePoint.GetLocalRadiusSigma();
483 
484  if (newSigma.isValid()) {
485  if (!latSigDist.isValid())
486  latSigDist = free;
487  if (!lonSigDist.isValid())
488  lonSigDist = free;
489  if (!radiusSigDist.isValid())
490  radiusSigDist = free;
491  }
492  else {
493  latSigDist = Distance();
494  lonSigDist = Distance();
495  radiusSigDist = Distance();
496  }
497 
498  surfacePoint.SetSphericalSigmasDistance(
499  latSigDist, lonSigDist, radiusSigDist);
500  return surfacePoint;
501  }
502 
503 
504  SurfacePoint AbstractPointItem::prepareSurfacePoint(Latitude newLat,
505  SurfacePoint surfacePoint) {
506  if (newLat.isValid()) {
507  surfacePoint = prepareSurfacePoint(surfacePoint);
508  }
509  else {
510  surfacePoint.SetSphericalCoordinates(Latitude(), Longitude(),
511  Distance());
512  }
513 
514  return surfacePoint;
515  }
516 
517 
518  SurfacePoint AbstractPointItem::prepareSurfacePoint(Longitude newLon,
519  SurfacePoint surfacePoint) {
520  if (newLon.isValid()) {
521  surfacePoint = prepareSurfacePoint(surfacePoint);
522  }
523  else {
524  surfacePoint.SetSphericalCoordinates(Latitude(), Longitude(),
525  Distance());
526  }
527 
528  return surfacePoint;
529  }
530 
531 
532  SurfacePoint AbstractPointItem::prepareSurfacePoint(
533  Distance newRadius, SurfacePoint surfacePoint) {
534  if (newRadius.isValid()) {
535  surfacePoint = prepareSurfacePoint(surfacePoint);
536  }
537  else {
538  surfacePoint.SetSphericalCoordinates(Latitude(), Longitude(),
539  Distance());
540  }
541 
542  return surfacePoint;
543  }
544 
545 
546  SurfacePoint AbstractPointItem::prepareSurfacePoint(
547  SurfacePoint surfacePoint) {
548  Latitude lat = surfacePoint.GetLatitude();
549  Longitude lon = surfacePoint.GetLongitude();
550  Distance radius = surfacePoint.GetLocalRadius();
551 
552  if (!lat.isValid())
553  lat = Latitude(0, Angle::Degrees);
554  if (!lon.isValid())
555  lon = Longitude(0, Angle::Degrees);
556  if (!radius.isValid())
557  radius = Distance(10000, Distance::Meters);
558 
559  surfacePoint.SetSphericalCoordinates(lat, lon, radius);
560  return surfacePoint;
561  }
562  }
563 }
564 
Status SetAprioriSurfacePointSource(SurfacePointSource::Source source)
This updates the source of the surface point.
double degrees() const
Get the angle in units of Degrees.
Definition: Angle.h:245
Distance GetLocalRadius() const
Return the radius of the surface point.
Status SetAprioriRadiusSourceFile(QString sourceFile)
This updates the filename of the DEM that the apriori radius came from.
Status SetIgnored(bool newIgnoreStatus)
Set whether to ignore or use control point.
QString GetPointTypeString() const
Obtain a string representation of the PointType.
Status SetChooserName(QString name)
Set the point&#39;s chooser name.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
Status SetEditLock(bool editLock)
Set the EditLock state.
const ControlMeasure * GetRefMeasure() const
Get the reference control measure.
Longitude GetLongitude() const
Return the body-fixed longitude for the surface point.
Status SetAdjustedSurfacePoint(SurfacePoint newSurfacePoint)
Set or update the surface point relating to this control point.
bool HasSerialNumber(QString serialNumber) const
Return true if given serial number exists in point.
Status SetAprioriSurfacePointSourceFile(QString sourceFile)
This updates the filename of where the apriori surface point came from.
QString GetRadiusSourceString() const
Obtain a string representation of the RadiusSource.
double meters() const
Get the distance in meters.
Definition: Distance.cpp:97
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
Definition: Angle.h:69
QString GetId() const
Return the Id of the control point.
static RadiusSource::Source StringToRadiusSource(QString str)
Obtain a RadiusSource::Source from a string.
Latitude GetLatitude() const
Return the body-fixed latitude for the surface point.
Status SetDateTime(QString newDateTime)
Set the point&#39;s last modified time.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
Status SetRefMeasure(ControlMeasure *cm)
Set the point&#39;s reference measure.
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:134
Status SetAprioriSurfacePoint(SurfacePoint aprioriSP)
This updates the apriori surface point.
int DeletePoint(ControlPoint *point)
Delete a ControlPoint from the network by the point&#39;s address.
Definition: ControlNet.cpp:692
Status SetType(PointType newType)
Updates the control point&#39;s type.
Status SetId(QString id)
Sets the Id of the control point.
static SurfacePointSource::Source StringToSurfacePointSource(QString str)
Obtain a SurfacePoint::Source from a string.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
QString GetCubeSerialNumber() const
Return the serial number of the cube containing the coordinate.
The distance is being specified in meters.
Definition: Distance.h:56
int GetNumLockedMeasures() const
Returns the number of locked control measures.
QString GetSurfacePointSourceString() const
Obtain a string representation of the SurfacePointSource.
Status SetAprioriRadiusSource(RadiusSource::Source source)
This updates the source of the radius of the apriori surface point.
static PointType StringToPointType(QString pointTypeString)
Obtain a PointType given a string representation of it.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.

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:13:44