Isis 3 Programmer Reference
BandTool.cpp
1
6
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "BandTool.h"
10
11#include <QAction>
12#include <QComboBox>
13#include <QHBoxLayout>
14#include <QLabel>
15#include <QMenu>
16#include <QPixmap>
17#include <QRadioButton>
18#include <QSpinBox>
19#include <QStackedWidget>
20#include <QToolButton>
21
22#include "Cube.h"
23#include "MdiCubeViewport.h"
24#include "Pvl.h"
25#include "ToolPad.h"
26
27namespace Isis {
28
35 BandTool::BandTool(QWidget *parent) : Tool(parent) {
36 p_bandBinViewport = NULL;
37 }
38
47 QAction *action = new QAction(pad);
48 action->setIcon(QPixmap(toolIconDir() + "/rgb.png"));
49 action->setToolTip("Band Selection (B)");
50 action->setShortcut(Qt::Key_B);
51 QString text =
52 "<b>Function:</b> Change the view of the cube from gray scale to RGB.\
53 <p><b>Shortcut:</b> B</p> ";
54 action->setWhatsThis(text);
55 return action;
56 }
57
65 QWidget *BandTool::createToolBarWidget(QStackedWidget *active) {
66 QWidget *hbox = new QWidget(active);
67
68 p_rgbButton = new QRadioButton(hbox);
69 p_blackwhiteButton = new QRadioButton(hbox);
70
71
72 QMenu *copyMenu = new QMenu();
73 QAction *copyLinked = new QAction(active);
74 copyLinked->setText("to Linked Viewports");
75 connect(copyLinked, SIGNAL(triggered(bool)), this, SLOT(copyLinkedViewports()));
76
77 QAction *copyAll = new QAction(active);
78 copyAll->setText("to All Viewports");
79 connect(copyAll, SIGNAL(triggered(bool)), this, SLOT(copyAllViewports()));
80
81 copyMenu->addAction(copyLinked);
82 copyMenu->addAction(copyAll);
83
84 QToolButton *copyButton = new QToolButton(hbox);
85 copyButton->setAutoRaise(true);
86 copyButton->setIconSize(QSize(22, 22));
87 copyButton->setPopupMode(QToolButton::MenuButtonPopup);
88 copyButton->setMenu(copyMenu);
89 copyButton->setDefaultAction(copyAll);
90 copyButton->setIcon(QPixmap(toolIconDir() + "/copy_bands.png"));
91 copyButton->setToolTip("Copy");
92 QString text =
93 "<b>Function:</b>";
94 copyButton->setWhatsThis(text);
95
96 QIcon colorIcon;
97 QIcon grayIcon;
98 colorIcon.addPixmap(toolIconDir() + "/rgb.png", QIcon::Normal, QIcon::On);
99 grayIcon.addPixmap(toolIconDir() + "/gray.png", QIcon::Normal, QIcon::Off);
100 p_rgbButton->setIcon(colorIcon);
101 p_rgbButton->setText("RGB");
102 p_blackwhiteButton->setIcon(grayIcon);
103 p_blackwhiteButton->setText("Gray");
104 p_rgbButton->setCheckable(true);
105 p_rgbButton->setIconSize(QSize(22, 22));
106 p_blackwhiteButton->setIconSize(QSize(22, 22));
107 p_rgbButton->setToolTip("Change to RGB");
108 p_blackwhiteButton->setToolTip("Change to grayscale");
109 text =
110 "<b>Function:</b> Toggle the active viewport between color or \
111 grayscale display of the cube. Color display is only possible if \
112 the cube has two or more bands";
113 p_rgbButton->setWhatsThis(text);
114 p_blackwhiteButton->setWhatsThis(text);
115
116 p_comboBox = new QComboBox(hbox);
117 p_comboBox->setEditable(false);
118 p_comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
119 p_comboBox->addItem("Wavelength");
120 p_comboBox->setToolTip("Select BandBin keyword");
121 text =
122 "<b>Function:</b> The default option \"Wavelength\" \
123 simply shows the current band displayed in the viewport. However, \
124 the labels of many cubes contain the BandBin group. \
125 Keywords in this group describe the bands in a meaningful way, \
126 such as WaveLength, Filter, Temperature, iTime, etc. \
127 Selecting an alternative BandBin keyword will cause those values \
128 to show in the spin boxes to the right.";
129 p_comboBox->setWhatsThis(text);
130
131 p_stack = new QStackedWidget(hbox);
132
133 QWidget *stuff1 = new QWidget(p_stack);
134 p_graySpin = new QSpinBox(stuff1);
135 p_graySpin->setToolTip("Change gray band");
136 p_stack->addWidget(stuff1);
137
138 QWidget *stuff2 = new QWidget(p_stack);
139 p_redSpin = new QSpinBox(stuff2);
140 p_redSpin->setToolTip("Change red band");
141 p_grnSpin = new QSpinBox(stuff2);
142 p_grnSpin->setToolTip("Change green band");
143 p_bluSpin = new QSpinBox(stuff2);
144 p_bluSpin->setToolTip("Change blue band");
145 p_stack->addWidget(stuff2);
146
147 p_stack2 = new QStackedWidget(hbox);
148 QWidget *grayWidget = new QWidget(p_stack2);
149 p_grayDisplay = new QLabel(grayWidget);
150 p_grayDisplay->setFrameStyle(QFrame::Panel | QFrame::Sunken);
151 p_stack2->addWidget(grayWidget);
152
153 QWidget *colorWidget = new QWidget(p_stack2);
154 p_redDisplay = new QLabel(colorWidget);
155 p_greenDisplay = new QLabel(colorWidget);
156 p_blueDisplay = new QLabel(colorWidget);
157 p_redDisplay->setFrameStyle(QFrame::Panel | QFrame::Sunken);
158 p_greenDisplay->setFrameStyle(QFrame::Panel | QFrame::Sunken);
159 p_blueDisplay->setFrameStyle(QFrame::Panel | QFrame::Sunken);
160 p_stack2->addWidget(colorWidget);
161
162
163 QHBoxLayout *displayLayout = new QHBoxLayout(grayWidget);
164 displayLayout->addWidget(p_grayDisplay);
165 displayLayout->addStretch(1);
166 grayWidget->setLayout(displayLayout);
167
168 displayLayout = new QHBoxLayout(colorWidget);
169 displayLayout->addWidget(p_redDisplay);
170 displayLayout->addWidget(p_greenDisplay);
171 displayLayout->addWidget(p_blueDisplay);
172 colorWidget->setLayout(displayLayout);
173
174 QHBoxLayout *layout = new QHBoxLayout(stuff1);
175 layout->setMargin(0);
176 layout->addWidget(p_graySpin);
177 layout->addStretch(1);
178 stuff1->setLayout(layout);
179
180 layout = new QHBoxLayout(stuff2);
181 layout->setMargin(0);
182 layout->addWidget(p_redSpin);
183 layout->addWidget(p_grnSpin);
184 layout->addWidget(p_bluSpin);
185
186 stuff2->setLayout(layout);
187
188 p_stack->setCurrentIndex(0);
189 p_stack2->setCurrentIndex(0);
190 p_rgbButton->setChecked(false);
191 p_blackwhiteButton->setChecked(true);
192
193 QFrame *vertLine = new QFrame();
194 vertLine->setFrameShape(QFrame::VLine);
195 vertLine->setFrameShadow(QFrame::Sunken);
196
197 layout = new QHBoxLayout(hbox);
198 layout->setMargin(0);
199 layout->addWidget(p_rgbButton);
200 layout->addWidget(p_blackwhiteButton);
201 layout->addWidget(copyButton);
202 layout->addWidget(p_stack);
203 layout->addWidget(vertLine);
204 layout->addWidget(p_comboBox);
205 layout->addWidget(p_stack2);
206 layout->addStretch(1);
207 hbox->setLayout(layout);
208
209 return hbox;
210 }
211
212
220 cvp->setComboCount(p_comboBox->count());
221 cvp->setComboIndex(p_comboBox->currentIndex());
222 if(p_pvl.findObject("IsisCube").hasGroup("BandBin") &&
223 p_comboBox->count() > 0) {
224
225 PvlGroup &bandBin = p_pvl.findObject("IsisCube")
226 .findGroup("BandBin");
227 p_comboBox->setVisible(true);
228 p_grayDisplay->setVisible(true);
229 p_redDisplay->setVisible(true);
230 p_greenDisplay->setVisible(true);
231 p_blueDisplay->setVisible(true);
232
233 for(int i = 0; i < bandBin.keywords(); i++) {
234 if(bandBin[i].name() == p_comboBox->currentText()) {
235 p_lineEditValueList.clear();
236 for(int j = 0; j < bandBin[i].size(); j++) {
237 p_lineEditValueList.push_back(QString(bandBin[i][j]));
238 }
239 }
240 }
241 }
242 else {
243 for(int i = 1; i <= p_bands; i++) {
244 p_lineEditValueList.push_back(QString::number(i));
245 }
246 p_comboBox->setVisible(false);
247 p_grayDisplay->setVisible(false);
248 p_redDisplay->setVisible(false);
249 p_greenDisplay->setVisible(false);
250 p_blueDisplay->setVisible(false);
251 }
252 }
253
254
264 p_pvl = *cube->label();
265
266 // Get the number of bands and setup the spin box
267 p_bands = cube->bandCount();
268
269 p_graySpin->setValue(1);
270 p_graySpin->adjustSize();
271 p_graySpin->setMinimum(1);
272 p_graySpin->setMaximum(p_bands);
273
274 p_redSpin->setValue(1);
275 p_redSpin->setMinimum(1);
276 p_redSpin->setMaximum(p_bands);
277
278 p_bluSpin->setValue(1);
279 p_bluSpin->setMinimum(1);
280 p_bluSpin->setMaximum(p_bands);
281
282 p_grnSpin->setValue(1);
283 p_grnSpin->setMinimum(1);
284 p_grnSpin->setMaximum(p_bands);
285
286 p_comboBox->clear();
288 if(p_pvl.findObject("IsisCube").hasGroup("BandBin")) {
289 PvlGroup &bandBin = p_pvl.findObject("IsisCube")
290 .findGroup("BandBin");
291 for(int i = 0; i < bandBin.keywords(); i++) {
292 //only add band bin keywords have a size that equals the number of bands
293 if(bandBin[i].size() == p_bands) {
294 QString bandBinName = bandBin[i].name();
295 p_comboBox->addItem(QString(bandBinName));
296 }
297
298 }
299
300 if(cvp->comboCount() > 0) {
301 p_comboBox->setCurrentIndex(cvp->comboIndex());
302 }
303 else if(p_comboBox->findText("Center") > 0) {
304 p_comboBox->setCurrentIndex(p_comboBox->findText("Center"));
305 }
306
307 cvp->setComboCount(p_comboBox->count());
308 cvp->setComboIndex(p_comboBox->currentIndex());
309 }
310 setList();
311 }
312
313
323
324 if(v == NULL) return;
325
326 if(p_rgbButton->isChecked()) {
327 p_stack->setCurrentIndex(1);
328 p_stack2->setCurrentIndex(1);
329 if(v->isGray() ||
330 p_redSpin->value() != v->redBand() ||
331 p_grnSpin->value() != v->greenBand() ||
332 p_bluSpin->value() != v->blueBand()) {
333 v->viewRGB(p_redSpin->value(), p_grnSpin->value(), p_bluSpin->value());
334 }
335 }
336 else {
337 p_stack->setCurrentIndex(0);
338 p_stack2->setCurrentIndex(0);
339 if(v->isColor() || p_graySpin->value() != v->grayBand()) {
340 v->viewGray(p_graySpin->value());
341 }
342 }
343
344 setDisplay();
345
346 }
347
348
354 //Gray
355 if(p_graySpin->value() - 1 < p_lineEditValueList.size()) {
356 p_grayDisplay->setText
357 (p_lineEditValueList[p_graySpin->value()-1]);
358 }
359 else {
360 p_grayDisplay->setText("N/A");
361 }
362 p_grayDisplay->adjustSize();
363
364 //Red
365 if(p_redSpin->value() - 1 < p_lineEditValueList.size()) {
366 p_redDisplay->setText
367 (p_lineEditValueList[p_redSpin->value()-1]);
368 }
369 else {
370 p_redDisplay->setText("N/A");
371 }
372 p_redDisplay->adjustSize();
373
374 //Green
375 if(p_grnSpin->value() - 1 < p_lineEditValueList.size()) {
376 p_greenDisplay->setText
377 (p_lineEditValueList[p_grnSpin->value()-1]);
378 }
379 else {
380 p_greenDisplay->setText("N/A");
381 }
382 p_greenDisplay->adjustSize();
383
384 //Blue
385 if(p_bluSpin->value() - 1 < p_lineEditValueList.size()) {
386 p_blueDisplay->setText
387 (p_lineEditValueList[p_bluSpin->value()-1]);
388 }
389 else {
390 p_blueDisplay->setText("N/A");
391 }
392 p_blueDisplay->adjustSize();
393
394 }
395
401 if(!cubeViewport()->isLinked()) return;
402
403 for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
404 MdiCubeViewport *cvp = cubeViewportList()->at(i);
405 if(!cvp->isLinked() || cvp == cubeViewport()) continue;
406
407 int bands = cvp->cubeBands();
408
409 if(p_rgbButton->isChecked()) {
410 if(cvp->isGray() ||
411 p_redSpin->value() != cvp->redBand() ||
412 p_grnSpin->value() != cvp->greenBand() ||
413 p_bluSpin->value() != cvp->blueBand()) {
414
415 if(p_redSpin->value() > bands ||
416 p_grnSpin->value() > bands ||
417 p_bluSpin->value() > bands) continue;
418
419 cvp->viewRGB(p_redSpin->value(), p_grnSpin->value(),
420 p_bluSpin->value());
421 }
422 }
423 else {
424 if(cvp->isColor() || p_graySpin->value() != cvp->grayBand()) {
425 if(p_graySpin->value() > bands) continue;
426
427 cvp->viewGray(p_graySpin->value());
428 }
429 }
430 }
431 }
432
438 for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
439 MdiCubeViewport *cvp = cubeViewportList()->at(i);
440
441 int bands = cvp->cubeBands();
442
443 if(p_rgbButton->isChecked()) {
444 if(cvp->isGray() ||
445 p_redSpin->value() != cvp->redBand() ||
446 p_grnSpin->value() != cvp->greenBand() ||
447 p_bluSpin->value() != cvp->blueBand()) {
448
449 if(p_redSpin->value() > bands ||
450 p_grnSpin->value() > bands ||
451 p_bluSpin->value() > bands) continue;
452
453 cvp->viewRGB(p_redSpin->value(), p_grnSpin->value(),
454 p_bluSpin->value());
455 }
456 }
457 else {
458 if(cvp->isColor() || p_graySpin->value() != cvp->grayBand()) {
459 if(p_graySpin->value() > bands) continue;
460
461 cvp->viewGray(p_graySpin->value());
462 }
463 }
464 }
465 }
466
472
473 disconnect(p_comboBox, 0, 0, 0);
474 disconnect(p_graySpin, 0, 0, 0);
475 disconnect(p_redSpin, 0, 0, 0);
476 disconnect(p_grnSpin, 0, 0, 0);
477 disconnect(p_bluSpin, 0, 0, 0);
478 disconnect(p_rgbButton, 0, 0, 0);
479
481 if(cvp != NULL) {
482 if(p_bandBinViewport != cvp) {
483 setBandBin(cvp->cube());
484 }
485
486 if(cvp->isGray()) {
487
488 p_rgbButton->setChecked(false);
489 p_blackwhiteButton->setChecked(true);
490 p_stack->setCurrentIndex(0);
491 p_stack2->setCurrentIndex(0);
492
493 }
494 else {
495 p_rgbButton->setChecked(true);
496 p_blackwhiteButton->setChecked(false);
497 p_stack->setCurrentIndex(1);
498 p_stack2->setCurrentIndex(1);
499 }
500
501 p_graySpin->setValue(cvp->grayBand());
502 p_graySpin->updateGeometry();
503
504 p_redSpin->setValue(cvp->redBand());
505 p_redSpin->updateGeometry();
506
507 p_grnSpin->setValue(cvp->greenBand());
508 p_grnSpin->updateGeometry();
509
510 p_bluSpin->setValue(cvp->blueBand());
511 p_bluSpin->updateGeometry();
512
513 changeView();
514
515 connect(p_comboBox, SIGNAL(activated(int)), this, SLOT(setList()));
516 connect(p_comboBox, SIGNAL(activated(int)), this, SLOT(setDisplay()));
517
518 connect(p_graySpin, SIGNAL(valueChanged(int)), this, SLOT(changeView()));
519 connect(p_redSpin, SIGNAL(valueChanged(int)), this, SLOT(changeView()));
520 connect(p_grnSpin, SIGNAL(valueChanged(int)), this, SLOT(changeView()));
521 connect(p_bluSpin, SIGNAL(valueChanged(int)), this, SLOT(changeView()));
522
523 connect(p_rgbButton, SIGNAL(toggled(bool)), this, SLOT(changeView()));
524 }
525
526 p_bandBinViewport = cvp;
527 }
528
529
530}
int p_bands
Number of possible bands.
Definition BandTool.h:90
QSpinBox * p_redSpin
Red spin box.
Definition BandTool.h:78
QLabel * p_redDisplay
red display
Definition BandTool.h:82
QStackedWidget * p_stack2
Stacked widget for displays and combo box.
Definition BandTool.h:87
QLabel * p_greenDisplay
green display
Definition BandTool.h:83
QWidget * createToolBarWidget(QStackedWidget *active)
Definition BandTool.cpp:65
QAction * toolPadAction(ToolPad *pad)
Definition BandTool.cpp:46
void copyAllViewports()
This methods copies the selected bands to all viewports.
Definition BandTool.cpp:437
QLabel * p_blueDisplay
blue display
Definition BandTool.h:84
QStackedWidget * p_stack
Stacked widget for spin boxes.
Definition BandTool.h:86
QSpinBox * p_bluSpin
Blue spin box.
Definition BandTool.h:80
QSpinBox * p_grnSpin
Green spin box.
Definition BandTool.h:79
QSpinBox * p_graySpin
Gray spin box.
Definition BandTool.h:77
void changeView()
This method is connected to the qspinboxes.
Definition BandTool.cpp:321
void setList()
This method sets the p_lineEditValueList to the proper values according to what the user has selected...
Definition BandTool.cpp:218
QRadioButton * p_rgbButton
RGB radio button.
Definition BandTool.h:75
void updateTool()
updates the band tool
Definition BandTool.cpp:471
void setBandBin(Cube *cube)
This method fills the p_comboBox with the keywords from the band bin group of the currently selected ...
Definition BandTool.cpp:263
void setDisplay()
This method updates the values displayed in the gray boxes.
Definition BandTool.cpp:353
void copyLinkedViewports()
This method copies the selected bands to all linked viewports.
Definition BandTool.cpp:400
QRadioButton * p_blackwhiteButton
Black and White radio button.
Definition BandTool.h:76
QComboBox * p_comboBox
display selection combo box
Definition BandTool.h:85
BandTool(QWidget *parent)
BandTool constructor.
Definition BandTool.cpp:35
QStringList p_lineEditValueList
Value list.
Definition BandTool.h:92
Pvl p_pvl
pvl
Definition BandTool.h:91
QLabel * p_grayDisplay
gray display
Definition BandTool.h:81
IO Handler for Isis Cubes.
Definition Cube.h:168
virtual int bandCount() const
Returns the number of virtual bands for the cube.
Definition Cube.cpp:1423
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition Cube.cpp:1734
int comboCount() const
int greenBand() const
int cubeBands() const
Return the number of bands in the cube.
int redBand() const
void setComboCount(int count)
Sets the band bin combo box count.
bool isColor() const
int grayBand() const
Cube * cube() const
int comboIndex() const
void setComboIndex(int index)
Sets the band bin combo box index.
bool isGray() const
int blueBand() const
Cube display widget for certain Isis MDI applications.
bool isLinked() const
Is the viewport linked with other viewports.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
QString name() const
Returns the container name.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Tool(QWidget *parent)
Tool constructor.
Definition Tool.cpp:27
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition Tool.cpp:390
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition Tool.h:197
QString toolIconDir() const
returns the path to the icon directory.
Definition Tool.h:113
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16