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