Isis 3 Programmer Reference
NewControlPointDialog.cpp
1 #include "NewControlPointDialog.h"
2 
3 #include <algorithm>
4 
5 #include <QComboBox>
6 
7 #include <QHBoxLayout>
8 #include <QLabel>
9 #include <QLineEdit>
10 #include <QListWidget>
11 #include <QPushButton>
12 #include <QRadioButton>
13 #include <QString>
14 #include <QtDebug>
15 
16 #include "ControlNet.h"
17 #include "ControlPoint.h"
18 #include "IString.h"
19 #include "SerialNumberList.h"
20 
21 namespace Isis {
45  SerialNumberList *serialNumberList,
46  QString defaultPointId,
47  QWidget *parent,
48  bool pointType,
49  bool groundSource,
50  bool subpixelRegisterMeasures) : QDialog(parent) {
51 
52  m_controlNet = controlNet;
53  m_serialNumberList = serialNumberList;
54 
55  m_ptIdEdit = NULL;
56 
57  m_subpixelRegisterButton = NULL;
58  m_fileList = NULL;
59  m_ptIdLabel = NULL;
60  m_okButton = NULL;
61 
62  m_ptIdLabel = new QLabel("Point ID:");
63  m_ptIdEdit = new QLineEdit;
64  m_ptIdLabel->setBuddy(m_ptIdEdit);
65  m_ptIdEdit->setText(defaultPointId);
66  m_ptIdEdit->selectAll();
67  connect(m_ptIdEdit, SIGNAL(textChanged(const QString &)),
68  this, SLOT(enableOkButton(const QString &)));
69 
70  QHBoxLayout *pointTypeLayout = new QHBoxLayout();
71  if (pointType) {
72  m_pointTypeCombo = new QComboBox;
73  for (int i=0; i<ControlPoint::PointTypeCount; i++) {
74  m_pointTypeCombo->insertItem(i, ControlPoint::PointTypeToString(
76  }
77  m_pointTypeCombo->setCurrentText("Free");
78  QLabel *pointTypeLabel = new QLabel("Point Type:");
79  pointTypeLayout->addWidget(pointTypeLabel);
80  pointTypeLayout->addWidget(m_pointTypeCombo);
81  connect(m_pointTypeCombo, SIGNAL(currentIndexChanged(QString)),
82  this, SLOT(pointTypeChanged(QString)));
83  }
84 
85  QHBoxLayout *groundSourceLayout = NULL;
86  QHBoxLayout *radiusSourceLayout = NULL;
87  if (groundSource) {
88  groundSourceLayout = new QHBoxLayout();
89  m_groundSourceCombo = new QComboBox;
90  QLabel *groundSourceLabel = new QLabel("Ground Source:");
91  groundSourceLayout->addWidget(groundSourceLabel);
92  groundSourceLayout->addWidget(m_groundSourceCombo);
93  m_groundSourceCombo->setVisible(false);
94 
95  radiusSourceLayout = new QHBoxLayout();
96  m_radiusSourceCombo = new QComboBox;
97  QLabel *radiusSourceLabel = new QLabel("Radius Source:");
98  radiusSourceLayout->addWidget(radiusSourceLabel);
99  radiusSourceLayout->addWidget(m_radiusSourceCombo);
100  m_radiusSourceCombo->setVisible(false);
101  }
102 
103  if (subpixelRegisterMeasures) {
104  m_subpixelRegisterButton = new QRadioButton("Subpixel Register Measures");
105  m_subpixelRegisterButton->setChecked(true);
106  m_subpixelRegisterButton->setToolTip("Each measure will be subpixel registered to the reference"
107  " as it is created.");
108  }
109 
110  QLabel *listLabel = new QLabel("Select Files:");
111 
112  m_fileList = new QListWidget;
113  m_fileList->setSelectionMode(QAbstractItemView::ExtendedSelection);
114 
115  // Create OK & Cancel buttons
116  m_okButton = new QPushButton("OK");
117 
118  // If the last point id used was never saved to network, do not set ok
119  // button to faslse
120  enableOkButton("");
121 
122  QPushButton *cancelButton = new QPushButton("Cancel");
123  QHBoxLayout *buttonLayout = new QHBoxLayout;
124  buttonLayout->addWidget(m_okButton);
125  buttonLayout->addWidget(cancelButton);
126 
127  connect(m_okButton, SIGNAL(clicked()), this, SLOT(accept()));
128  connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
129 
130  QHBoxLayout *ptIdLayout = new QHBoxLayout;
131  ptIdLayout->addWidget(m_ptIdLabel);
132  ptIdLayout->addWidget(m_ptIdEdit);
133 
134  QVBoxLayout *vLayout = new QVBoxLayout;
135 
136  vLayout->addLayout(ptIdLayout);
137 
138  if (pointType) {
139  vLayout->addLayout(pointTypeLayout);
140  }
141 
142  if (groundSource) {
143  vLayout->addLayout(groundSourceLayout);
144  vLayout->addLayout(radiusSourceLayout);
145  }
146 
147  if (subpixelRegisterMeasures) {
148  vLayout->addWidget(m_subpixelRegisterButton);
149  }
150 
151  vLayout->addWidget(listLabel);
152  vLayout->addWidget(m_fileList);
153  vLayout->addLayout(buttonLayout);
154 
155  setLayout(vLayout);
156  setWindowTitle("Create New ControlPoint");
157 
158  }
159 
160 
161  QString NewControlPointDialog::pointId() const {
162  return m_ptIdEdit->text();
163  }
164 
165 
166  int NewControlPointDialog::pointType() const {
167  int result = ControlPoint::Free;
168  if (m_pointTypeCombo->currentText() == "Constrained") {
169  result = ControlPoint::Constrained;
170  }
171  if (m_pointTypeCombo->currentText() == "Fixed") {
172  result = ControlPoint::Fixed;
173  }
174  return result;
175  }
176 
177 
178  QStringList NewControlPointDialog::selectedFiles() const {
179  QStringList result;
180 
181  foreach (QListWidgetItem *fileItem, m_fileList->selectedItems()) {
182  result.append(fileItem->text());
183  }
184 
185  return result;
186  }
187 
188 
189  bool NewControlPointDialog::subpixelRegisterPoint() {
190  return m_subpixelRegisterButton->isChecked();
191  }
192 
193 
194  QString NewControlPointDialog::groundSource() const {
195  return m_groundSourceCombo->currentText();
196  }
197 
198 
199  QString NewControlPointDialog::radiusSource() const {
200  return m_radiusSourceCombo->currentText();
201  }
202 
203 
204  void NewControlPointDialog::pointTypeChanged(QString pointType) {
205  if (pointType == "Fixed" || pointType == "Constrained") {
206  m_groundSourceCombo->setVisible(true);
207  m_radiusSourceCombo->setVisible(true);
208  }
209  }
210 
211 
212  void NewControlPointDialog::setGroundSource(QStringList groundFiles, int numberShapesWithPoint) {
213  // If groundFiles not empty, add to the list widget for selection
214  if (groundFiles.count() != 0) {
215  m_groundSourceCombo->addItems(groundFiles);
216  for (int i = 0; i < numberShapesWithPoint; i++) {
217  m_groundSourceCombo->setItemData(i, QColor(Qt::red), Qt::ForegroundRole);
218  }
219  m_groundSourceCombo->insertSeparator(numberShapesWithPoint);
220  }
221  // If groundFiles is empty, remove option to change point type to Constrained or Fixed, add a
222  // tooltip to give user hint as to why they don't have option to change point type and set
223  // default point type back to "Free".
224  else {
225  m_pointTypeCombo->setToolTip("The Point Type cannot be changed to \"Fixed\" or "
226  "\"Constrained\", because there are no shapes imported into "
227  "your project.");
228  m_pointTypeCombo->removeItem(m_pointTypeCombo->findText("Constrained"));
229  m_pointTypeCombo->removeItem(m_pointTypeCombo->findText("Fixed"));
230  m_pointTypeCombo->setCurrentText("Free");
231  }
232  }
233 
234 
235  void NewControlPointDialog::setRadiusSource(QStringList radiusFiles) {
236  // If radiusFiles not empty, add to the radius source combo, first adding "None" as option.
237  m_radiusSourceCombo->addItem("None");
238  m_radiusSourceCombo->setCurrentText("None");
239  if (radiusFiles.count() != 0) {
240  m_radiusSourceCombo->addItems(radiusFiles);
241  }
242  }
243 
244 
253 
254  int bottomMostSelectedItemIndex = 0;
255 
256  for (int i = 0; i < m_serialNumberList->size(); i++) {
257 
258  // build new item...
259  QString label = m_serialNumberList->fileName(i);
260  QListWidgetItem *item = new QListWidgetItem(label);
261 
262  // if this entry of the SerialNumberList is also in the pointFiles then
263  // mark it as selected and insert after the last selected item (toward
264  // the top of the list). Otherwise just add the item to the end of the
265  // list
266  if (pointFiles.contains(label)) {
267  m_fileList->insertItem(bottomMostSelectedItemIndex++, item);
268  item->setSelected(true);
269  }
270  else {
271  m_fileList->addItem(item);
272  }
273  }
274  }
275 
276 
284  bool enable = !m_ptIdEdit->text().isEmpty() &&
285  !m_controlNet->ContainsPoint(m_ptIdEdit->text());
286  m_okButton->setEnabled(enable);
287  if (enable) {
288  m_okButton->setToolTip("");
289  }
290  else {
291  m_okButton->setToolTip("Cannot create point because Point Id is either empty or the active "
292  "control net already contains a control point with this point Id.");
293  }
294  }
295 }
A Constrained point is a Control Point whose lat/lon/radius is somewhat established and should not be...
Definition: ControlPoint.h:391
A Fixed point is a Control Point whose lat/lon is well established and should not be changed...
Definition: ControlPoint.h:386
PointType
These are the valid &#39;types&#39; of point.
Definition: ControlPoint.h:379
NewControlPointDialog(ControlNet *controlNet, SerialNumberList *serialNumberList, QString defaultPointId, QWidget *parent=0, bool pointType=false, bool groundSource=false, bool subpixelRegisterMeasures=false)
Create dialog for creating a new Control Point
A Free point is a Control Point that identifies common measurements between two or more cubes...
Definition: ControlPoint.h:399
QString fileName(const QString &sn)
Return a filename given a serial number.
void enableOkButton(const QString &text)
a control network
Definition: ControlNet.h:271
int size() const
How many serial number / filename combos are in the list.
bool ContainsPoint(QString pointId) const
Definition: ControlNet.cpp:943
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void setFiles(QStringList pointFiles)
Serial Number list generator.
static QString PointTypeToString(PointType type)
Obtain a string representation of a given PointType.