USGS

Isis 3.0 Object Programmers' Reference

Home

BandTool.cpp
1 #include "BandTool.h"
2 
3 #include <QAction>
4 #include <QComboBox>
5 #include <QHBoxLayout>
6 #include <QLabel>
7 #include <QMenu>
8 #include <QPixmap>
9 #include <QRadioButton>
10 #include <QSpinBox>
11 #include <QStackedWidget>
12 #include <QToolButton>
13 
14 #include "Cube.h"
15 #include "MdiCubeViewport.h"
16 #include "Pvl.h"
17 #include "ToolPad.h"
18 
19 namespace Isis {
20 
27  BandTool::BandTool(QWidget *parent) : Tool(parent) {
28  p_bandBinViewport = NULL;
29  }
30 
39  QAction *action = new QAction(pad);
40  action->setIcon(QPixmap(toolIconDir() + "/rgb.png"));
41  action->setToolTip("Band Selection (B)");
42  action->setShortcut(Qt::Key_B);
43  QString text =
44  "<b>Function:</b> Change the view of the cube from gray scale to RGB.\
45  <p><b>Shortcut:</b> B</p> ";
46  action->setWhatsThis(text);
47  return action;
48  }
49 
57  QWidget *BandTool::createToolBarWidget(QStackedWidget *active) {
58  QWidget *hbox = new QWidget(active);
59 
60  p_rgbButton = new QRadioButton(hbox);
61  p_blackwhiteButton = new QRadioButton(hbox);
62 
63 
64  QMenu *copyMenu = new QMenu();
65  QAction *copyLinked = new QAction(active);
66  copyLinked->setText("to Linked Viewports");
67  connect(copyLinked, SIGNAL(triggered(bool)), this, SLOT(copyLinkedViewports()));
68 
69  QAction *copyAll = new QAction(active);
70  copyAll->setText("to All Viewports");
71  connect(copyAll, SIGNAL(triggered(bool)), this, SLOT(copyAllViewports()));
72 
73  copyMenu->addAction(copyLinked);
74  copyMenu->addAction(copyAll);
75 
76  QToolButton *copyButton = new QToolButton(hbox);
77  copyButton->setAutoRaise(true);
78  copyButton->setIconSize(QSize(22, 22));
79  copyButton->setPopupMode(QToolButton::MenuButtonPopup);
80  copyButton->setMenu(copyMenu);
81  copyButton->setDefaultAction(copyAll);
82  copyButton->setIcon(QPixmap(toolIconDir() + "/copy_bands.png"));
83  copyButton->setToolTip("Copy");
84  QString text =
85  "<b>Function:</b>";
86  copyButton->setWhatsThis(text);
87 
88  QIcon colorIcon;
89  QIcon grayIcon;
90  colorIcon.addPixmap(toolIconDir() + "/rgb.png", QIcon::Normal, QIcon::On);
91  grayIcon.addPixmap(toolIconDir() + "/gray.png", QIcon::Normal, QIcon::Off);
92  p_rgbButton->setIcon(colorIcon);
93  p_rgbButton->setText("RGB");
94  p_blackwhiteButton->setIcon(grayIcon);
95  p_blackwhiteButton->setText("Gray");
96  p_rgbButton->setCheckable(true);
97  p_rgbButton->setIconSize(QSize(22, 22));
98  p_blackwhiteButton->setIconSize(QSize(22, 22));
99  p_rgbButton->setToolTip("Change to RGB");
100  p_blackwhiteButton->setToolTip("Change to grayscale");
101  text =
102  "<b>Function:</b> Toggle the active viewport between color or \
103  grayscale display of the cube. Color display is only possible if \
104  the cube has two or more bands";
105  p_rgbButton->setWhatsThis(text);
106  p_blackwhiteButton->setWhatsThis(text);
107 
108  p_comboBox = new QComboBox(hbox);
109  p_comboBox->setEditable(false);
110  p_comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
111  p_comboBox->addItem("Wavelength");
112  p_comboBox->setToolTip("Select BandBin keyword");
113  text =
114  "<b>Function:</b> The default option \"Wavelength\" \
115  simply shows the current band displayed in the viewport. However, \
116  the labels of many cubes contain the BandBin group. \
117  Keywords in this group describe the bands in a meaningful way, \
118  such as WaveLength, Filter, Temperature, iTime, etc. \
119  Selecting an alternative BandBin keyword will cause those values \
120  to show in the spin boxes to the right.";
121  p_comboBox->setWhatsThis(text);
122 
123  p_stack = new QStackedWidget(hbox);
124 
125  QWidget *stuff1 = new QWidget(p_stack);
126  p_graySpin = new QSpinBox(stuff1);
127  p_graySpin->setToolTip("Change gray band");
128  p_stack->addWidget(stuff1);
129 
130  QWidget *stuff2 = new QWidget(p_stack);
131  p_redSpin = new QSpinBox(stuff2);
132  p_redSpin->setToolTip("Change red band");
133  p_grnSpin = new QSpinBox(stuff2);
134  p_grnSpin->setToolTip("Change green band");
135  p_bluSpin = new QSpinBox(stuff2);
136  p_bluSpin->setToolTip("Change blue band");
137  p_stack->addWidget(stuff2);
138 
139  p_stack2 = new QStackedWidget(hbox);
140  QWidget *grayWidget = new QWidget(p_stack2);
141  p_grayDisplay = new QLabel(grayWidget);
142  p_grayDisplay->setFrameStyle(QFrame::Panel | QFrame::Sunken);
143  p_stack2->addWidget(grayWidget);
144 
145  QWidget *colorWidget = new QWidget(p_stack2);
146  p_redDisplay = new QLabel(colorWidget);
147  p_greenDisplay = new QLabel(colorWidget);
148  p_blueDisplay = new QLabel(colorWidget);
149  p_redDisplay->setFrameStyle(QFrame::Panel | QFrame::Sunken);
150  p_greenDisplay->setFrameStyle(QFrame::Panel | QFrame::Sunken);
151  p_blueDisplay->setFrameStyle(QFrame::Panel | QFrame::Sunken);
152  p_stack2->addWidget(colorWidget);
153 
154 
155  QHBoxLayout *displayLayout = new QHBoxLayout(grayWidget);
156  displayLayout->addWidget(p_grayDisplay);
157  displayLayout->addStretch(1);
158  grayWidget->setLayout(displayLayout);
159 
160  displayLayout = new QHBoxLayout(colorWidget);
161  displayLayout->addWidget(p_redDisplay);
162  displayLayout->addWidget(p_greenDisplay);
163  displayLayout->addWidget(p_blueDisplay);
164  colorWidget->setLayout(displayLayout);
165 
166  QHBoxLayout *layout = new QHBoxLayout(stuff1);
167  layout->setMargin(0);
168  layout->addWidget(p_graySpin);
169  layout->addStretch(1);
170  stuff1->setLayout(layout);
171 
172  layout = new QHBoxLayout(stuff2);
173  layout->setMargin(0);
174  layout->addWidget(p_redSpin);
175  layout->addWidget(p_grnSpin);
176  layout->addWidget(p_bluSpin);
177 
178  stuff2->setLayout(layout);
179 
180  p_stack->setCurrentIndex(0);
181  p_stack2->setCurrentIndex(0);
182  p_rgbButton->setChecked(false);
183  p_blackwhiteButton->setChecked(true);
184 
185  QFrame *vertLine = new QFrame();
186  vertLine->setFrameShape(QFrame::VLine);
187  vertLine->setFrameShadow(QFrame::Sunken);
188 
189  layout = new QHBoxLayout(hbox);
190  layout->setMargin(0);
191  layout->addWidget(p_rgbButton);
192  layout->addWidget(p_blackwhiteButton);
193  layout->addWidget(copyButton);
194  layout->addWidget(p_stack);
195  layout->addWidget(vertLine);
196  layout->addWidget(p_comboBox);
197  layout->addWidget(p_stack2);
198  layout->addStretch(1);
199  hbox->setLayout(layout);
200 
201  return hbox;
202  }
203 
204 
211  MdiCubeViewport *cvp = cubeViewport();
212  cvp->setComboCount(p_comboBox->count());
213  cvp->setComboIndex(p_comboBox->currentIndex());
214  if(p_pvl.findObject("IsisCube").hasGroup("BandBin") &&
215  p_comboBox->count() > 0) {
216 
217  PvlGroup &bandBin = p_pvl.findObject("IsisCube")
218  .findGroup("BandBin");
219  p_comboBox->setVisible(true);
220  p_grayDisplay->setVisible(true);
221  p_redDisplay->setVisible(true);
222  p_greenDisplay->setVisible(true);
223  p_blueDisplay->setVisible(true);
224 
225  for(int i = 0; i < bandBin.keywords(); i++) {
226  if(bandBin[i].name() == p_comboBox->currentText()) {
227  p_lineEditValueList.clear();
228  for(int j = 0; j < bandBin[i].size(); j++) {
229  p_lineEditValueList.push_back(QString(bandBin[i][j]));
230  }
231  }
232  }
233  }
234  else {
235  for(int i = 1; i <= p_bands; i++) {
236  p_lineEditValueList.push_back(QString::number(i));
237  }
238  p_comboBox->setVisible(false);
239  p_grayDisplay->setVisible(false);
240  p_redDisplay->setVisible(false);
241  p_greenDisplay->setVisible(false);
242  p_blueDisplay->setVisible(false);
243  }
244  }
245 
246 
256  p_pvl = *cube->label();
257 
258  // Get the number of bands and setup the spin box
259  p_bands = cube->bandCount();
260 
261  p_graySpin->setValue(1);
262  p_graySpin->adjustSize();
263  p_graySpin->setMinimum(1);
264  p_graySpin->setMaximum(p_bands);
265 
266  p_redSpin->setValue(1);
267  p_redSpin->setMinimum(1);
268  p_redSpin->setMaximum(p_bands);
269 
270  p_bluSpin->setValue(1);
271  p_bluSpin->setMinimum(1);
272  p_bluSpin->setMaximum(p_bands);
273 
274  p_grnSpin->setValue(1);
275  p_grnSpin->setMinimum(1);
276  p_grnSpin->setMaximum(p_bands);
277 
278  p_comboBox->clear();
279  MdiCubeViewport *cvp = cubeViewport();
280  if(p_pvl.findObject("IsisCube").hasGroup("BandBin")) {
281  PvlGroup &bandBin = p_pvl.findObject("IsisCube")
282  .findGroup("BandBin");
283  for(int i = 0; i < bandBin.keywords(); i++) {
284  //only add band bin keywords have a size that equals the number of bands
285  if(bandBin[i].size() == p_bands) {
286  QString bandBinName = bandBin[i].name();
287  p_comboBox->addItem(QString(bandBinName));
288  }
289 
290  }
291 
292  if(cvp->comboCount() > 0) {
293  p_comboBox->setCurrentIndex(cvp->comboIndex());
294  }
295  else if(p_comboBox->findText("Center") > 0) {
296  p_comboBox->setCurrentIndex(p_comboBox->findText("Center"));
297  }
298 
299  cvp->setComboCount(p_comboBox->count());
300  cvp->setComboIndex(p_comboBox->currentIndex());
301  }
302  setList();
303  }
304 
305 
315 
316  if(v == NULL) return;
317 
318  if(p_rgbButton->isChecked()) {
319  p_stack->setCurrentIndex(1);
320  p_stack2->setCurrentIndex(1);
321  if(v->isGray() ||
322  p_redSpin->value() != v->redBand() ||
323  p_grnSpin->value() != v->greenBand() ||
324  p_bluSpin->value() != v->blueBand()) {
325  v->viewRGB(p_redSpin->value(), p_grnSpin->value(), p_bluSpin->value());
326  }
327  }
328  else {
329  p_stack->setCurrentIndex(0);
330  p_stack2->setCurrentIndex(0);
331  if(v->isColor() || p_graySpin->value() != v->grayBand()) {
332  v->viewGray(p_graySpin->value());
333  }
334  }
335 
336  setDisplay();
337 
338  }
339 
340 
346  //Gray
347  if(p_graySpin->value() - 1 < p_lineEditValueList.size()) {
348  p_grayDisplay->setText
349  (p_lineEditValueList[p_graySpin->value()-1]);
350  }
351  else {
352  p_grayDisplay->setText("N/A");
353  }
354  p_grayDisplay->adjustSize();
355 
356  //Red
357  if(p_redSpin->value() - 1 < p_lineEditValueList.size()) {
358  p_redDisplay->setText
359  (p_lineEditValueList[p_redSpin->value()-1]);
360  }
361  else {
362  p_redDisplay->setText("N/A");
363  }
364  p_redDisplay->adjustSize();
365 
366  //Green
367  if(p_grnSpin->value() - 1 < p_lineEditValueList.size()) {
368  p_greenDisplay->setText
369  (p_lineEditValueList[p_grnSpin->value()-1]);
370  }
371  else {
372  p_greenDisplay->setText("N/A");
373  }
374  p_greenDisplay->adjustSize();
375 
376  //Blue
377  if(p_bluSpin->value() - 1 < p_lineEditValueList.size()) {
378  p_blueDisplay->setText
379  (p_lineEditValueList[p_bluSpin->value()-1]);
380  }
381  else {
382  p_blueDisplay->setText("N/A");
383  }
384  p_blueDisplay->adjustSize();
385 
386  }
387 
393  if(!cubeViewport()->isLinked()) return;
394 
395  for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
396  MdiCubeViewport *cvp = cubeViewportList()->at(i);
397  if(!cvp->isLinked() || cvp == cubeViewport()) continue;
398 
399  int bands = cvp->cubeBands();
400 
401  if(p_rgbButton->isChecked()) {
402  if(cvp->isGray() ||
403  p_redSpin->value() != cvp->redBand() ||
404  p_grnSpin->value() != cvp->greenBand() ||
405  p_bluSpin->value() != cvp->blueBand()) {
406 
407  if(p_redSpin->value() > bands ||
408  p_grnSpin->value() > bands ||
409  p_bluSpin->value() > bands) continue;
410 
411  cvp->viewRGB(p_redSpin->value(), p_grnSpin->value(),
412  p_bluSpin->value());
413  }
414  }
415  else {
416  if(cvp->isColor() || p_graySpin->value() != cvp->grayBand()) {
417  if(p_graySpin->value() > bands) continue;
418 
419  cvp->viewGray(p_graySpin->value());
420  }
421  }
422  }
423  }
424 
430  for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
431  MdiCubeViewport *cvp = cubeViewportList()->at(i);
432 
433  int bands = cvp->cubeBands();
434 
435  if(p_rgbButton->isChecked()) {
436  if(cvp->isGray() ||
437  p_redSpin->value() != cvp->redBand() ||
438  p_grnSpin->value() != cvp->greenBand() ||
439  p_bluSpin->value() != cvp->blueBand()) {
440 
441  if(p_redSpin->value() > bands ||
442  p_grnSpin->value() > bands ||
443  p_bluSpin->value() > bands) continue;
444 
445  cvp->viewRGB(p_redSpin->value(), p_grnSpin->value(),
446  p_bluSpin->value());
447  }
448  }
449  else {
450  if(cvp->isColor() || p_graySpin->value() != cvp->grayBand()) {
451  if(p_graySpin->value() > bands) continue;
452 
453  cvp->viewGray(p_graySpin->value());
454  }
455  }
456  }
457  }
458 
464 
465  disconnect(p_comboBox, 0, 0, 0);
466  disconnect(p_graySpin, 0, 0, 0);
467  disconnect(p_redSpin, 0, 0, 0);
468  disconnect(p_grnSpin, 0, 0, 0);
469  disconnect(p_bluSpin, 0, 0, 0);
470  disconnect(p_rgbButton, 0, 0, 0);
471 
472  MdiCubeViewport *cvp = cubeViewport();
473  if(cvp != NULL) {
474  if(p_bandBinViewport != cvp) {
475  setBandBin(cvp->cube());
476  }
477 
478  if(cvp->isGray()) {
479 
480  p_rgbButton->setChecked(false);
481  p_blackwhiteButton->setChecked(true);
482  p_stack->setCurrentIndex(0);
483  p_stack2->setCurrentIndex(0);
484 
485  }
486  else {
487  p_rgbButton->setChecked(true);
488  p_blackwhiteButton->setChecked(false);
489  p_stack->setCurrentIndex(1);
490  p_stack2->setCurrentIndex(1);
491  }
492 
493  p_graySpin->setValue(cvp->grayBand());
494  p_graySpin->updateGeometry();
495 
496  p_redSpin->setValue(cvp->redBand());
497  p_redSpin->updateGeometry();
498 
499  p_grnSpin->setValue(cvp->greenBand());
500  p_grnSpin->updateGeometry();
501 
502  p_bluSpin->setValue(cvp->blueBand());
503  p_bluSpin->updateGeometry();
504 
505  changeView();
506 
507  connect(p_comboBox, SIGNAL(activated(int)), this, SLOT(setList()));
508  connect(p_comboBox, SIGNAL(activated(int)), this, SLOT(setDisplay()));
509 
510  connect(p_graySpin, SIGNAL(valueChanged(int)), this, SLOT(changeView()));
511  connect(p_redSpin, SIGNAL(valueChanged(int)), this, SLOT(changeView()));
512  connect(p_grnSpin, SIGNAL(valueChanged(int)), this, SLOT(changeView()));
513  connect(p_bluSpin, SIGNAL(valueChanged(int)), this, SLOT(changeView()));
514 
515  connect(p_rgbButton, SIGNAL(toggled(bool)), this, SLOT(changeView()));
516  }
517 
518  p_bandBinViewport = cvp;
519  }
520 
521 
522 }