File failed to load: https://isis.astrogeology.usgs.gov/9.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
FileTool.cpp
1#include "FileTool.h"
2
3#include <cmath>
4
5#include <QAction>
6#include <QApplication>
7#include <QFileDialog>
8#include <QFileInfo>
9#include <QImage>
10#include <QMenu>
11#include <QMessageBox>
12#include <QPainter>
13#include <QPixmap>
14#include <QPrinter>
15#include <QPrintDialog>
16#include <QToolBar>
17
18#include "Brick.h"
19#include "BrowseDialog.h"
20#include "CubeAttribute.h"
21#include "Enlarge.h"
22#include "FileDialog.h"
23#include "Interpolator.h"
24#include "MainWindow.h"
25#include "MdiCubeViewport.h"
26#include "OriginalLabel.h"
27#include "Portal.h"
28#include "ProcessRubberSheet.h"
29#include "ProcessByLine.h"
30#include "Pvl.h"
31#include "Reduce.h"
32#include "SaveAsDialog.h"
33#include "SubArea.h"
34#include "ViewportMainWindow.h"
35#include "Workspace.h"
36
37namespace Isis {
46 FileTool::FileTool(QWidget *parent) : Tool(parent) {
47 p_parent = parent;
48 p_dir.setPath("/thisDirDoesNotExist!");
49 p_open = new QAction(parent);
50 p_open->setShortcut(Qt::CTRL + Qt::Key_O);
51 p_open->setText("&Open...");
52 p_open->setIcon(QPixmap(toolIconDir() + "/fileopen.png"));
53 p_open->setToolTip("Open cube");
54 QString whatsThis =
55 "<b>Function:</b> Open an <i>Isis cube</i> in new viewport \
56 <p><b>Shortcut:</b> Ctrl+O\n</p> \
57 <p><b>Hint:</b> Use Ctrl or Shift in file dialog to open \
58 multiple cubes</p>";
59 p_open->setWhatsThis(whatsThis);
60 connect(p_open, SIGNAL(triggered()), this, SLOT(open()));
61
62 p_browse = new QAction(parent);
63 p_browse->setShortcut(Qt::CTRL + Qt::Key_B);
64 p_browse->setText("&Browse...");
65 p_browse->setToolTip("Browse cubes");
66 whatsThis =
67 "<b>Function:</b> Browse a <i>Isis cubes</i> in new viewport \
68 <p><b>Shortcut:</b> Ctrl+B\n</p>";
69 p_browse->setWhatsThis(whatsThis);
70 connect(p_browse, SIGNAL(triggered()), this, SLOT(browse()));
71
72 p_save = new QAction(parent);
73 p_save->setShortcut(Qt::CTRL + Qt::Key_S);
74 p_save->setText("&Save");
75 p_save->setIcon(QPixmap(toolIconDir() + "/filesave.png"));
76 p_save->setToolTip("Save");
77 whatsThis =
78 "<b>Function:</b> Save changes to the current Cube \
79 <p><b>Shortcut:</b> Ctrl+S</p>";
80 p_save->setWhatsThis(whatsThis);
81 connect(p_save, SIGNAL(triggered()), this, SLOT(save()));
82 p_save->setEnabled(false);
83
84 p_saveAs = new QAction(parent);
85 p_saveAs->setText("Save &As...");
86 p_saveAs->setIcon(QPixmap(toolIconDir() + "/filesaveas.png"));
87 p_saveAs->setToolTip("Save As");
88 whatsThis =
89 "<b>Function:</b> Save the current Cube to the specified location";
90 p_saveAs->setWhatsThis(whatsThis);
91 connect(p_saveAs, SIGNAL(triggered()), this, SLOT(saveAs()));
92 p_saveAs->setEnabled(false);
93
94 p_saveInfo = new QAction(parent);
95 p_saveInfo->setText("Save &Info...");
96 p_saveInfo->setIcon(QPixmap(toolIconDir() + "/filesaveas.png"));
97 p_saveInfo->setToolTip("Save Info");
98 whatsThis =
99 "<b>Function:</b> Save the current Cube's Whatsthis Info to the specified location";
100 p_saveInfo->setWhatsThis(whatsThis);
101 connect(p_saveInfo, SIGNAL(triggered()), this, SLOT(saveInfo()));
102 p_saveInfo->setEnabled(false);
103
104 p_exportView = new QAction(parent);
105 p_exportView->setText("Export View");
106 p_exportView->setIcon(QPixmap(toolIconDir() + "/fileexport.png"));
107 p_exportView->setToolTip("Export View");
108 whatsThis =
109 "<b>Function:</b> Save visible contents of the active \
110 viewport as a png, jpg, tiff \
111 <p><b>Hint:</b> Your local installation of Qt may not support \
112 all formats. Reinstall Qt if necessary</p>";
113 p_exportView->setWhatsThis(whatsThis);
114 connect(p_exportView, SIGNAL(triggered()), this, SLOT(exportView()));
115 p_exportView->setEnabled(false);
116
117 p_exportToList = new QAction(parent);
118 p_exportToList->setText("Export to List");
119 p_exportToList->setIcon(QPixmap(toolIconDir() + "/fileexport.png"));
120 p_exportToList->setToolTip("Export active cubes to a .lis file");
121 whatsThis =
122 "<b>Function:</b> Save all open cubes \
123 to a .lis file containing their file names";
124 p_exportToList->setWhatsThis(whatsThis);
125 connect(p_exportToList, SIGNAL(triggered()), this, SLOT(exportToList()));
126 p_exportToList->setEnabled(false);
127
128 p_print = new QAction(parent);
129 p_print->setText("&Print...");
130 p_print->setShortcut(Qt::CTRL + Qt::Key_P);
131 p_print->setIcon(QPixmap(toolIconDir() + "/fileprint.png"));
132 p_print->setToolTip("Print");
133 whatsThis =
134 "<b>Function:</b> Print visible contents of the active viewport \
135 <p><b>Shortcut:</b> Ctrl+P</b>";
136 p_print->setWhatsThis(whatsThis);
137 connect(p_print, SIGNAL(triggered()), this, SLOT(print()));
138 p_print->setEnabled(false);
139
140 p_closeAll = new QAction(parent);
141 p_closeAll->setText("&Close All...");
142 p_closeAll->setToolTip("Close All");
143 whatsThis =
144 "<b>Function:</b> Close all cube viewports.";
145 p_closeAll->setWhatsThis(whatsThis);
146
147 p_exit = new QAction(this);
148 p_exit->setShortcut(Qt::CTRL + Qt::Key_Q);
149 p_exit->setText("E&xit");
150 p_exit->setIcon(QPixmap(toolIconDir() + "/fileclose.png"));
151 whatsThis =
152 "<b>Function:</b> Quit qview \
153 <p><b>Shortcut:</b> Ctrl+Q</p>";
154 p_exit->setWhatsThis(whatsThis);
155 connect(p_exit, SIGNAL(triggered()), this, SLOT(exit()));
156
157 p_lastViewport = NULL;
158
159 p_saveAsDialog = NULL;
160 activate(true);
161 }
162
163
169 void FileTool::addTo(QMenu *menu) {
170 menu->addAction(p_open);
171 menu->addAction(p_browse);
172 menu->addAction(p_save);
173 menu->addAction(p_saveAs);
174 menu->addAction(p_saveInfo);
175 menu->addAction(p_exportView);
176 menu->addAction(p_exportToList);
177 menu->addAction(p_print);
178 menu->addAction(p_closeAll);
179 menu->addAction(p_exit);
180 }
181
182
189 p_workSpace = ws;
190 Tool::addTo(ws);
191 connect(this, SIGNAL(fileSelected(QString)),
192 ws, SLOT(addCubeViewport(QString)));
193
194 connect(p_closeAll, SIGNAL(triggered()), ws->mdiArea(), SLOT(closeAllSubWindows()));
195 }
196
197
204 perm->addAction(p_open);
205 perm->addAction(p_exportView);
206 perm->addAction(p_print);
207 perm->addAction(p_exit);
208 }
209
210
216 //Set up the list of filters that are default with this dialog.
217 if (!p_filterList.contains("Isis cubes (*.cub)")) {
218 p_filterList.append("Isis cubes (*.cub)");
219 p_filterList.append("All files (*)");
220 }
221 if (!p_dir.exists()) {
222 p_dir = QDir::current();
223 }
224
225 FileDialog *fileDialog = new FileDialog("Open", p_filterList, p_dir, (QWidget *)parent());
226 fileDialog->show();
227 connect(fileDialog, SIGNAL(fileSelected(QString)),
228 p_workSpace, SLOT(addCubeViewport(QString)));
229 }
230
231
237 //Set up the list of filters that are default with this dialog.
238 if (!p_filterList.contains("Isis cubes (*.cub)")) {
239 p_filterList.append("Isis cubes (*.cub)");
240 p_filterList.append("All files (*)");
241 }
242 if (!p_dir.exists()) {
243 p_dir = QDir::current();
244 }
245 BrowseDialog *browser = new BrowseDialog("Browse", p_filterList, p_dir, (QWidget *)parent());
246 browser->show();
247 connect(browser, SIGNAL(fileSelected(QString)),
248 p_workSpace, SLOT(addBrowseView(QString)));
249 }
250
251
259 //If the current viewport is null (safety check), return from this method
260 if (cubeViewport() == NULL) {
261 QMessageBox::information((QWidget *)parent(), "Error", "No active cube to save");
262 return;
263 }
264
266 p_save->setEnabled(false);
267
268 cubeViewport()->cube()->reopen("rw");
269 }
270
271
285 //If the current viewport is null (safety check), return from this method
286 if (cubeViewport() == NULL) {
287 QMessageBox::information((QWidget *)parent(), "Error", "No active cube to save");
288 return;
289 }
290 //Set up the list of filters that are default with this dialog.
291 if (!p_filterList.contains("Isis cubes (*.cub)")) {
292 p_filterList.append("Isis cubes (*.cub)");
293 }
294 if (!p_dir.exists()) {
295 p_dir = QDir(p_lastDir);
296 }
297 if (p_saveAsDialog) {
298 delete p_saveAsDialog;
299 p_saveAsDialog = NULL;
300 }
301
302 p_saveAsDialog = new SaveAsDialog("Save As", p_filterList, p_dir, (QWidget *)parent());
303 connect(p_saveAsDialog, SIGNAL(fileSelected(QString)), this, SLOT(saveAsCubeByOption(QString)));
304
305 p_saveAsDialog->show();
306 }
307
308
317 void FileTool::saveAsCubeByOption(QString psOutFile) {
318 //If the current viewport is null (safety check), return from this method
319 if (cubeViewport() == NULL) {
320 QMessageBox::information((QWidget *)parent(), "Error",
321 "No active cube to save");
322 return;
323 }
324
325 //If the filename is empty, return
326 if (psOutFile.isEmpty() || (p_saveAsDialog==NULL)){
327 QMessageBox::information((QWidget *)parent(), "Error",
328 "No output file selected");
329 return;
330 }
331
332 //Check if the output file is already opened
333 QVector< MdiCubeViewport *> *vwportList = p_workSpace->cubeViewportList();
335 for (it = vwportList->begin(); it != vwportList->end(); ++it){
336 if (QString((*it)->cube()->fileName()) == psOutFile) {
337 QMessageBox::information((QWidget *)parent(), "Error",
338 "Output File is already open\n\""+ psOutFile + "\"");
339 return;
340 }
341 }
342
343 //If the filename is the same as the current cube's filename, just save it
344 if (p_saveAsDialog->getSaveAsType() == SaveAsDialog::FullImage &&
345 psOutFile == cubeViewport()->cube()->fileName()) {
346 save();
347 return;
348 }
349
350 //Save the current cube's changes by reopening it, and open an input cube
351 //from the current cube's location
352 Cube *icube = new Cube();
353 icube->open(cubeViewport()->cube()->fileName(), "rw");
354 Cube *ocube = NULL;
355
356 // The output cube needs to be created if the scale is 1 since saveAs_FullResolution will be
357 // called, which expects a cube.
358 // NOTE: This really should be cleaned up and the cube should be created in 1 place.
359 if (p_saveAsDialog->getSaveAsType() != SaveAsDialog::ExportAsIs ||
360 p_lastViewport->scale() == 1) {
361 //Create the output cube
362 ocube = new Cube;
363 }
364
365 if (p_saveAsDialog->getSaveAsType() == SaveAsDialog::FullImage) {
366 copyCubeDetails(psOutFile, icube, ocube, icube->sampleCount(),
367 icube->lineCount(), icube->bandCount());
368 saveAsFullImage(icube, ocube);
369 ocube->close();
370 }
371 else {
372 // start and end Samples and Lines
373 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
374 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
375
376 if (p_saveAsDialog->getSaveAsType() == SaveAsDialog::ExportFullRes ||
377 p_lastViewport->scale() == 1) {
378// int numSamples = (int)ceil(dEndSample-dStartSample);
379// int numLines = (int)ceil(dEndLine-dStartLine);
380 int numSamples = (int)((dEndSample - dStartSample + 1) + 0.5);
381 int numLines = (int)((dEndLine - dStartLine + 1) + 0.5);
382 copyCubeDetails(psOutFile, icube, ocube, numSamples, numLines, icube->bandCount());
383 saveAs_FullResolution(icube, ocube, numSamples, numLines);
384 ocube->close();
385 }
386 else if (p_saveAsDialog->getSaveAsType() == SaveAsDialog::ExportAsIs ) {
387 saveAs_AsIs(icube, psOutFile);
388 }
389 }
390
391 emit(fileSelected(psOutFile));
392
393 //Disable the save action
394 p_save->setEnabled(false);
395
396 p_lastDir = psOutFile;
397 }
398
399
410 void FileTool::saveAsEnlargedCube(Cube *icube, const QString & psOutFile) {
411 double dScale = p_lastViewport->scale();
412
413 // start and end Samples and Lines
414 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
415 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
416
417 double ins = dEndSample - dStartSample + 1;
418 double inl = dEndLine - dStartLine + 1;
419
420 double ons = (int)(ins * dScale + 0.5);
421 double onl = (int)(inl * dScale + 0.5);
422
423 try {
425 p.SetInputCube (icube);
426 Cube *ocube = p.SetOutputCube(psOutFile, CubeAttributeOutput(" "),
427 ons, onl, icube->bandCount());
428
429 Interpolator *interp = new Interpolator(Interpolator::NearestNeighborType);
430
431 Enlarge *imgEnlarge = new Enlarge(icube, dScale, dScale);
432 imgEnlarge->SetInputArea((int)dStartSample, (int)dEndSample, (int)dStartLine, (int)dEndLine);
433
434 p.StartProcess(*imgEnlarge, *interp);
435 imgEnlarge->UpdateOutputLabel(ocube);
436 p.EndProcess();
437
438 delete imgEnlarge;
439 delete interp;
440
441 } catch(IException &e) {
442 // Stacks error message from Cube's create method
443 throw IException(e,
445 QObject::tr("The cube could not be saved, unable to create the cube"),
446 _FILEINFO_);
447 }
448 }
449
450
460 void FileTool::saveAsReducedCube(Cube *icube, const QString & psOutFile) {
461
462 double dScale = p_lastViewport->scale();
463 // start and end Samples and Lines
464 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
465 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
466
467 double ins = dEndSample - dStartSample + 1;
468 double inl = dEndLine - dStartLine + 1;
469
470 double ons = (int)(ins * dScale + 0.5);
471 double onl = (int)(inl * dScale + 0.5);
472
473 CubeAttributeInput cai(icube->fileName());
474 std::vector<QString> bands = cai.bands();
475 int inb = bands.size();
476
477 if (inb == 0) {
478 inb = cubeViewport()->cube()->bandCount();
479 for(int i = 1; i <= inb; i++) {
480 bands.push_back(toString(i));
481 }
482 }
483
484 try {
486 p.SetInputCube (icube);
487 Cube *ocube = NULL;
488 ocube = p.SetOutputCube(psOutFile, CubeAttributeOutput(""), ons, onl, inb);
489 // Our processing routine only needs 1
490 // the original set was for info about the cube only
491 p.ClearInputCubes();
492
493 Cube *tempcube=new Cube;
494 tempcube->open(cubeViewport()->cube()->fileName(), "r");
495 Nearest *near = new Nearest(tempcube, ins/ons, inl/onl);
496 near->setInputBoundary((int)dStartSample, (int)dEndSample, (int)dStartLine, (int)dEndLine);
497
498 p.ProcessCubeInPlace(*near, false);
499 near->UpdateOutputLabel(ocube);
500 p.EndProcess();
501
502 delete near;
503 near=NULL;
504 }
505 catch(IException &e) {
506 // If there is a problem, catch it and close the cube so it isn't open next time around
507 icube->close();
508 // Stacks error message from Cube's create method
509 throw IException(e,
511 QObject::tr("The cube could not be saved, unable to create the cube"),
512 _FILEINFO_);
513 }
514 }
515
516
525 void FileTool::saveAs_AsIs(Cube *icube, const QString & psOutFile) {
526 double dScale = p_lastViewport->scale();
527 // Enlarge the cube area
528 if (dScale > 1) {
529 saveAsEnlargedCube(icube, psOutFile);
530 }
531 // Reduce the cube area
532 else {
533 saveAsReducedCube(icube, psOutFile);
534 }
535 }
536
537
552 void FileTool::copyCubeDetails(const QString & psOutFile, Cube *icube,
553 Cube *ocube, int piNumSamples, int piNumLines, int piNumBands) {
554 //Create the default output attribute with the output filename
555 CubeAttributeOutput outAtt(psOutFile);
556
557 //Propagate all labels, tables, blobs, etc from the input to output cube
558 try {
559 ocube->setDimensions(piNumSamples, piNumLines, piNumBands);
560 ocube->setByteOrder(outAtt.byteOrder());
561 ocube->setFormat(outAtt.fileFormat());
562 ocube->setLabelsAttached(outAtt.labelAttachment() == AttachedLabel);
563
564 if (outAtt.propagatePixelType()) {
565 ocube->setPixelType(icube->pixelType());
566 }
567 else {
568 ocube->setPixelType(outAtt.pixelType());
569 }
570
571 if (outAtt.propagateMinimumMaximum()) {
572 if (ocube->pixelType() == Real) {
573 ocube->setBaseMultiplier(0.0, 1.0);
574 }
575 else if (ocube->pixelType() >= icube->pixelType()) {
576 double base = icube->base();
577 double mult = icube->multiplier();
578 ocube->setBaseMultiplier(base, mult);
579 }
580 else if ((ocube->pixelType() != Real) &&
581 (ocube->pixelType() != UnsignedByte) &&
582 (ocube->pixelType() != SignedWord) &&
583 (ocube->pixelType() != UnsignedWord) &&
584 (ocube->pixelType() != Isis::UnsignedInteger) &&
585 (ocube->pixelType() != Isis::SignedInteger)) {
586 QString msg = "Looks like your refactoring to add different pixel types";
587 msg += " you'll need to make changes here";
588 throw IException(IException::Programmer, msg, _FILEINFO_);
589 }
590 else {
591 QString msg = "You've chosen to reduce your output PixelType for [" +
592 psOutFile + "] you must specify the output pixel range too";
593 throw IException(IException::User, msg, _FILEINFO_);
594 }
595 }
596 else {
597 // Not propagating so either the user entered or the programmer did
598 ocube->setMinMax(outAtt.minimum(), outAtt.maximum());
599 }
600
601 int needLabBytes = icube->labelSize(true) + (1024 * 6);
602 if (needLabBytes > ocube->labelSize()) {
603 ocube->setLabelSize(needLabBytes);
604 }
605
606 // Allocate the cube
607 ocube->create(psOutFile);
608
609 // Transfer labels from the first input cube
610 PvlObject &incube = icube->label()->findObject("IsisCube");
611 PvlObject &outcube = ocube->label()->findObject("IsisCube");
612 for(int i = 0; i < incube.groups(); i++) {
613 outcube.addGroup(incube.group(i));
614 }
615
616 // Transfer tables from the first input cube
617 Pvl &inlab = *icube->label();
618 for(int i = 0; i < inlab.objects(); i++) {
619 if (inlab.object(i).isNamed("Table")) {
620 Blob t((QString)inlab.object(i)["Name"], inlab.object(i).name());
621 icube->read(t);
622 ocube->write(t);
623 }
624 }
625
626 // Transfer blobs from the first input cube
627 inlab = *icube->label();
628 for(int i = 0; i < inlab.objects(); i++) {
629 if (inlab.object(i).isNamed("Polygon")) {
630 Blob t((QString)inlab.object(i)["Name"], inlab.object(i).name());
631 icube->read(t);
632 ocube->write(t);
633 }
634 }
635
636 // Transfer tables from the first input cube
637 inlab = *icube->label();
638 for(int i = 0; i < inlab.objects(); i++) {
639 if (inlab.object(i).isNamed("OriginalLabel")) {
640 OriginalLabel ol = icube->readOriginalLabel();
641 ocube->write(ol);
642 }
643 }
644 }
645 catch(IException &) {
646 delete ocube;
647 throw;
648 }
649 }
650
651
662 void FileTool::saveAsFullImage(Cube *icube, Cube *ocube) {
663 //Start the copy process line by line
664 Brick ibrick(*icube, icube->sampleCount(), 1, 1);
665 Brick obrick(*ocube, ocube->sampleCount(), 1, 1);
666
667 int numBricks;
668 if (ibrick.Bricks() > obrick.Bricks()) {
669 numBricks = ibrick.Bricks();
670 }
671 else {
672 numBricks = obrick.Bricks();
673 }
674
675 // Loop and let the app programmer work with the bricks
676 ibrick.begin();
677 obrick.begin();
678 for(int i = 0; i < numBricks; i++) {
679 icube->read(ibrick);
680 //Copy the contents to the output cube
681 copy(ibrick, obrick);
682 ocube->write(obrick);
683 ibrick++;
684 obrick++;
685 }
686 }
687
688
701 Cube *pOutCube, int pNumSamples, int pNumLines) {
702 // start and end Samples and Lines
703 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
704 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
705 int iNumBands = pInCube->bandCount();
706
707 PvlGroup results("Results");
708 results += PvlKeyword("InputLines", toString(pInCube->lineCount()));
709 results += PvlKeyword("InputSamples", toString(pInCube->sampleCount()));
710 results += PvlKeyword("StartingLine", toString(dStartLine));
711 results += PvlKeyword("StartingSample", toString(dStartSample));
712 results += PvlKeyword("EndingLine", toString(dEndLine));
713 results += PvlKeyword("EndingSample", toString(dEndSample));
714 results += PvlKeyword("LineIncrement", toString(1));
715 results += PvlKeyword("SampleIncrement", toString(1));
716 results += PvlKeyword("OutputLines", toString(pNumLines));
717 results += PvlKeyword("OutputSamples", toString(pNumSamples));
718 SubArea subArea;
719 subArea.SetSubArea(pInCube->lineCount(), pInCube->sampleCount(), dStartLine, dStartSample,
720 dEndLine, dEndSample, 1.0, 1.0);
721 subArea.UpdateLabel(pInCube, pOutCube, results);
722
723 Portal iPortal (pNumSamples, 1, pInCube->pixelType());
724 Portal oPortal (pNumSamples, 1, pOutCube->pixelType());
725
726 for(int iBand=1; iBand<=iNumBands; iBand++) {
727 int ol=1;
728 for(int iLine=(int)dStartLine; iLine<=(int)dEndLine; iLine++) {
729 iPortal.SetPosition(dStartSample, iLine, iBand);
730 pInCube->read(iPortal);
731
732 oPortal.SetPosition(1, ol++, iBand);
733 pOutCube->read(oPortal);
734
735 oPortal.Copy(iPortal);
736 pOutCube->write(oPortal);
737 }
738 }
739 }
740
741
749 {
750 if (cubeViewport() == NULL) {
751 QMessageBox::information((QWidget *)parent(), "Error", "No active cube to save info");
752 return;
753 }
754
755 //Get the new cube's filename
756 QString output =
757 QFileDialog::getSaveFileName((QWidget *)parent(),
758 "Choose output file",
759 p_lastDir,
760 QString("PVL Files (*.pvl)"));
761
762 //If the filename is empty, return
763 if (output.isEmpty()) {
764 return;
765 }
766 else if (!output.endsWith(".pvl")) {
767 output += ".pvl";
768 }
769
770 Pvl whatsThisPvl;
771 cubeViewport()->getAllWhatsThisInfo(whatsThisPvl);
772 whatsThisPvl.write(output);
773 }
774
775
782 void FileTool::copy(Buffer &in, Buffer &out) {
783 out.Copy(in);
784 }
785
786
794 }
795
796
802 if (cubeViewport() == NULL) {
803 QMessageBox::information((QWidget *)parent(), "Error", "No active cube to export");
804 return;
805 }
806
807 QString output =
808 QFileDialog::getSaveFileName((QWidget *)parent(),
809 QString("Choose output file"),
810 p_lastDir,
811 QString("PNG (*.png);;JPG (*.jpg);;TIF (*.tif)"));
812 if (output.isEmpty()) return;
813
814 p_lastDir = output;
815
816 QString format = QFileInfo(output).suffix();
817
818 if (format.isEmpty()) {
819 if (output.endsWith('.')) {
820 output.append(QString("png"));
821 }
822 else {
823 output.append(QString(".png"));
824 }
825 }
826 else if (format.compare("png", Qt::CaseInsensitive) &&
827 format.compare("jpg", Qt::CaseInsensitive) &&
828 format.compare("tif", Qt::CaseInsensitive)) {
829
830 QMessageBox::information((QWidget *)parent(), "Error", format + " is an invalid extension.");
831 return;
832 }
833
834 QPixmap pm = cubeViewport()->viewport()->grab();
835
836 //if (!cubeViewport()->pixmap().save(output,format)) {
837
838 if (!pm.save(output)) {
839 QMessageBox::information((QWidget *)parent(), "Error", "Unable to save " + output);
840 return;
841 }
842 }
843
844
854 if (cubeViewport() == NULL) {
855 QMessageBox::information((QWidget *)parent(), "Error", "No active cubes to export");
856 return;
857 }
858
859 // The ViewportMainWindow is the parent container to the FileTool.
860 // We need to grab that object so that we can loop through it's children
861 // To find the active cube viewports.
862 ViewportMainWindow* window = dynamic_cast<ViewportMainWindow*>(parent());
863
864 if (window == NULL) {
865 QMessageBox::critical((QWidget *)parent(), "Error", "There was an error reading the viewport window.");
866 return;
867 }
868
869 QList<CubeViewport*> openCubes = window->findChildren<CubeViewport*>();
870 QList<QString> cubeFilePaths;
871
872 for (int i = 0; i < openCubes.size(); i++) {
873
874 CubeViewport* cubeViewport = openCubes.value(i);
875
876// QString cubeFileName(cubeViewport->cube()->fileName());
877 QFileInfo cubeFileName(cubeViewport->cube()->fileName());
878
879 cubeFilePaths.append(cubeFileName.absoluteFilePath());
880 }
881
882 QString fileName = QFileDialog::getSaveFileName((QWidget *) parent(),
883 "Export to cube list",
884 ".",
885 "Cube List (*.lis)");
886
887 if (!fileName.contains(".lis")) {
888 fileName.append(".lis");
889 }
890
891 QFile outputFile(fileName);
892 outputFile.open(QIODevice::WriteOnly | QIODevice::Text);
893
894 QTextStream out(&outputFile);
895
896 // Write each cube filename onto it's own line inside of that file.
897 for (int i = 0; i < cubeFilePaths.size(); i++){
898 out << cubeFilePaths.value(i) << "\n";
899 }
900 outputFile.close();
901 }
902
903
909 // Is there anything to print
910 if (cubeViewport() == NULL) {
911 QMessageBox::information((QWidget *)parent(), "Error", "No active cube to print");
912 return;
913 }
914
915 // Initialize a printer
916 static QPrinter *printer = NULL;
917 if (printer == NULL) printer = new QPrinter;
918 QPageSize pageSize(QPageSize::Letter);
919 printer->setPageSize(pageSize);
920 printer->setColorMode(QPrinter::GrayScale);
921 if (cubeViewport()->isColor()) printer->setColorMode(QPrinter::Color);
922
923 QPrintDialog printDialog(printer, (QWidget *)parent());
924 if (printDialog.exec() == QDialog::Accepted) {
925 // Get display widget as a pixmap and convert to an image
926 QPixmap pixmap = cubeViewport()->viewport()->grab();
927 QImage img = pixmap.toImage();
928
929 // C++ Gui Programmign with Qt, page 201
930 QPainter painter(printer);
931 QRect rect = painter.viewport();
932 QSize size = img.size();
933 size.scale(rect.size(), Qt::KeepAspectRatio);
934 painter.setViewport(rect.x(), rect.y(),
935 size.width(), size.height());
936 painter.setWindow(img.rect());
937 painter.drawImage(0, 0, img);
938 }
939 }
940
941
946 // Close all cubes
947 // We must create a temporary list. If not the actual
948 // list size gets modified when a close occurs and not all
949 // windows were being closed.
952 for(int i = 0; i < (int)tempList.size(); i++) {
953 d = tempList.at(i);
954 //Set the current viewport to the one being closed
956
957 if (!d->parentWidget()->close()) {
958 return false;
959 }
960 }
961 return true;
962 }
963
964
974 QWidget *mainWindow = qobject_cast<QWidget *>(p_parent);
975
976 if (mainWindow)
977 mainWindow->close();
978 }
979
985 void FileTool::enableSave(bool enable) {
986 p_save->setEnabled(enable);
987 }
988
994 if (cubeViewport() == NULL) {
995 if (p_lastViewport != NULL) {
996 p_lastViewport = NULL;
997 }
998 p_print->setEnabled(false);
999 p_save->setEnabled(false);
1000 p_exportView->setEnabled(false);
1001 p_exportToList->setEnabled(false);
1002 p_saveAs->setEnabled(false);
1003 p_saveInfo->setEnabled(false);
1004 }
1005 else {
1006 if (p_lastViewport == NULL) {
1007 //Set the last viewport to the current viewport and connect signals to save and discard
1009 connect(p_lastViewport, SIGNAL(saveChanges(CubeViewport *)), this, SLOT(save()));
1010 }
1011 else {
1012 if (p_lastViewport != cubeViewport()) {
1013 //If the viewport has changes made to it enable the save action
1014 if (cubeViewport()->parentWidget()->windowTitle().endsWith("*")) {
1015 p_save->setEnabled(true);
1016 }
1017 //Else disable it
1018 else {
1019 p_save->setEnabled(false);
1020 }
1021 //disconnect signals from the old viewport and connect them to the new viewport
1022 disconnect(p_lastViewport, SIGNAL(saveChanges(CubeViewport *)), this, SLOT(save()));
1023 disconnect(p_lastViewport, SIGNAL(discardChanges(CubeViewport *)), this, SLOT(discard()));
1025 connect(p_lastViewport, SIGNAL(saveChanges(CubeViewport *)), this, SLOT(save()));
1026 connect(p_lastViewport, SIGNAL(discardChanges(CubeViewport *)), this, SLOT(discard()));
1027 }
1028 }
1029 p_print->setEnabled(true);
1030 p_exportView->setEnabled(true);
1031 p_exportToList->setEnabled(true);
1032 p_saveAs->setEnabled(true);
1033 p_saveInfo->setEnabled(true);
1034 }
1035 }
1036}
Buffer for containing a three dimensional section of an image.
Definition Brick.h:45
int Bricks()
Returns the number of Bricks in the cube.
Definition Brick.h:168
Class for browsing cubes.
Buffer for reading and writing cube data.
Definition Buffer.h:53
void Copy(const Buffer &in, bool includeRawBuf=true)
Allows copying of the buffer contents to another Buffer.
Definition Buffer.cpp:255
bool begin()
Moves the shape buffer to the first position.
Manipulate and parse attributes of input cube filenames.
std::vector< QString > bands() const
Return a vector of the input bands specified.
Manipulate and parse attributes of output cube filenames.
double minimum() const
Return the output cube attribute minimum.
ByteOrder byteOrder() const
Return the byte order as an Isis::ByteOrder.
double maximum() const
Return the output cube attribute maximum.
bool propagateMinimumMaximum() const
Return true if the min/max are to be propagated from an input cube.
bool propagatePixelType() const
Return true if the pixel type is to be propagated from an input cube.
Cube::Format fileFormat() const
Return the file format an Cube::Format.
PixelType pixelType() const
Return the pixel type as an Isis::PixelType.
IO Handler for Isis Cubes.
Definition Cube.h:168
void setPixelType(PixelType pixelType)
Used prior to the Create method, this will specify the output pixel type.
Definition Cube.cpp:1317
void setFormat(Format format)
Used prior to the Create method, this will specify the format of the cube, either band,...
Definition Cube.cpp:1279
int lineCount() const
Definition Cube.cpp:1767
double multiplier() const
Returns the multiplier value for converting 8-bit/16-bit pixels to 32-bit.
Definition Cube.cpp:1781
void setLabelsAttached(bool attached)
Use prior to calling create, this sets whether or not to use separate label and data files.
Definition Cube.cpp:1291
void setDimensions(int ns, int nl, int nb)
Used prior to the Create method to specify the size of the cube.
Definition Cube.cpp:1230
int sampleCount() const
Definition Cube.cpp:1840
void setBaseMultiplier(double base, double mult)
Used prior to the Create method, this will specify the base and multiplier for converting 8-bit/16-bi...
Definition Cube.cpp:1164
double base() const
Returns the base value for converting 8-bit/16-bit pixels to 32-bit.
Definition Cube.cpp:1440
void setMinMax(double min, double max)
Used prior to the Create method, this will compute a good base and multiplier value given the minimum...
Definition Cube.cpp:1181
void create(const QString &cfile)
This method will create an isis cube for writing.
Definition Cube.cpp:416
void open(const QString &cfile, QString access="r")
This method will open an existing isis cube for reading or reading/writing.
Definition Cube.cpp:629
PixelType pixelType() const
Definition Cube.cpp:1791
void read(Blob &blob, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
This method will read data from the specified Blob object.
Definition Cube.cpp:820
OriginalLabel readOriginalLabel(const QString &name="IsisCube") const
Read the original PDS3 label from a cube.
Definition Cube.cpp:902
void setLabelSize(int labelBytes)
Used prior to the Create method, this will allocate a specific number of bytes in the label area for ...
Definition Cube.cpp:1304
virtual QString fileName() const
Returns the opened cube's filename.
Definition Cube.cpp:1596
void write(Blob &blob, bool overwrite=true)
This method will write a blob of data (e.g.
Definition Cube.cpp:984
void close(bool remove=false)
Closes the cube and updates the labels.
Definition Cube.cpp:262
int labelSize(bool actual=false) const
Returns the number of bytes used by the label.
Definition Cube.cpp:1746
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
void reopen(QString access="r")
This method will reopen an isis sube for reading or reading/writing.
Definition Cube.cpp:787
void setByteOrder(ByteOrder byteOrder)
Used prior to the Create method, this will specify the byte order of pixels, either least or most sig...
Definition Cube.cpp:1215
Widget to display Isis cubes for qt apps.
void getAllWhatsThisInfo(Pvl &pWhatsThisPvl)
Get All WhatsThis info - viewport, cube, area in PVL format.
Cube * cube() const
Enlarge the pixel dimensions of an image.
Definition Enlarge.h:34
void SetInputArea(double pdStartSample, double pdEndSample, double pdStartLine, double pdEndLine)
Sets the sub area dimensions of the input image.
Definition Enlarge.cpp:76
PvlGroup UpdateOutputLabel(Cube *pOutCube)
Update the Mapping, Instrument, and AlphaCube groups in the output cube label.
Definition Enlarge.cpp:114
Class for browsing cubes.
Definition FileDialog.h:32
virtual void save()
This method saves any changes made to the current cube, these changes are finalized!
Definition FileTool.cpp:258
virtual void saveAs()
SaveAs Action - Displays the FileDialog with the filterlist (*.cub) to select the output cube.
Definition FileTool.cpp:284
void saveAsFullImage(Cube *icube, Cube *ocube)
Saves the cube as a full image.
Definition FileTool.cpp:662
virtual void open()
This method allows the user to navigate and open a cube with a file dialog.
Definition FileTool.cpp:215
virtual void exportToList()
FileTool::exportToList.
Definition FileTool.cpp:853
virtual bool closeAll()
Try to close all open cubes and save/discard if necessary.
Definition FileTool.cpp:945
FileTool(QWidget *parent)
Constructs a FileTool object.
Definition FileTool.cpp:46
virtual void exportView()
This method allows the user to export the current view as an image file.
Definition FileTool.cpp:801
QPointer< QAction > p_saveInfo
Action to save the current cube's Whatsthis info.
Definition FileTool.h:126
QPointer< Workspace > p_workSpace
The workspace being used.
Definition FileTool.h:133
void updateTool()
Updates the tool.
Definition FileTool.cpp:993
void print()
This method allows the user to print the current viewport.
Definition FileTool.cpp:908
QPointer< QAction > p_closeAll
Action to close all windows.
Definition FileTool.h:129
QPointer< SaveAsDialog > p_saveAsDialog
SaveAs Dialog with different save options.
Definition FileTool.h:135
QPointer< QAction > p_print
Action to print the current view.
Definition FileTool.h:123
QPointer< QAction > p_exportToList
Action to export active cubes to a cube list.
Definition FileTool.h:128
QDir p_dir
Directory.
Definition FileTool.h:76
void enableSave(bool enable)
This slot enables or disables save and save as.
Definition FileTool.cpp:985
QPointer< QAction > p_saveAs
Action save the current cube as a user specified file.
Definition FileTool.h:125
QPointer< MdiCubeViewport > p_lastViewport
The last cubeviewport that was used.
Definition FileTool.h:134
void saveAsEnlargedCube(Cube *icube, const QString &psOutFile)
Save image AsIs Enlarged into output.
Definition FileTool.cpp:410
void addToPermanent(QToolBar *perm)
Adds the file tool's actions to the permanent toolbar.
Definition FileTool.cpp:203
QString p_lastDir
The last directory opened.
Definition FileTool.h:132
static void copy(Buffer &in, Buffer &out)
This method copies from the input buffer to the output buffer.
Definition FileTool.cpp:782
void fileSelected(QString)
This signal is called when a file is selected.
QPointer< QAction > p_save
Action to save the current cube.
Definition FileTool.h:124
QPointer< QAction > p_exit
Action to exit qview.
Definition FileTool.h:130
void discardChanges(CubeViewport *vp)
This signal is called when changes should be discarded.
virtual void exit()
Exit the program, this slot called when the exit is chosen from the File menu.
Definition FileTool.cpp:973
QPointer< QAction > p_open
Action to open a file.
Definition FileTool.h:121
void discard()
This slot emits a signal to discard all changes to the current viewport.
Definition FileTool.cpp:792
void addTo(QMenu *menu)
Adds the file tool's actions to the menu.
Definition FileTool.cpp:169
void saveChanges(CubeViewport *vp)
This signal is called when changes should be saved.
void saveAs_FullResolution(Cube *pInCube, Cube *pOutCube, int pNumSamples, int pNumLines)
Save image Full Resolution (image viewed in the viewport window) into output.
Definition FileTool.cpp:700
QPointer< QAction > p_exportView
Action to export the view as a picture.
Definition FileTool.h:127
void saveAsCubeByOption(QString)
Save as Isis Cube (FullImage, AsIs, FullRes)
Definition FileTool.cpp:317
virtual void saveInfo()
Saves the whatsthis info of the cubeviewport.
Definition FileTool.cpp:748
QPointer< QWidget > p_parent
The parent widget of this object.
Definition FileTool.h:131
void copyCubeDetails(const QString &psFileName, Cube *icube, Cube *ocube, int piNumSamples, int piNumLines, int piNumBands)
Copy input cube details into output file given its dimensions.
Definition FileTool.cpp:552
QStringList p_filterList
Filter List.
Definition FileTool.h:75
QPointer< QAction > p_browse
Action to browse and open files.
Definition FileTool.h:122
void saveAs_AsIs(Cube *icube, const QString &psOutFile)
Save image AsIs (As viewed in the viewport window) into output file.
Definition FileTool.cpp:525
void saveAsReducedCube(Cube *icube, const QString &psOutFile)
For AsIs option, save the reduced input image visible in the viewport window using the Reduce functio...
Definition FileTool.cpp:460
virtual void browse()
This method allows the user to navigate and browse cubes with a file dialog .
Definition FileTool.cpp:236
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition IException.h:155
Pixel interpolator.
Cube display widget for certain Isis MDI applications.
Functor for reduce using near functionality.
Definition Reduce.h:88
Read and store original labels.
Buffer for containing a two dimensional section of an image.
Definition Portal.h:36
void SetPosition(const double sample, const double line, const int band)
Sets the line and sample position of the buffer.
Definition Portal.h:93
void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
virtual Cube * SetOutputCube(const QString &fname, const CubeAttributeOutput &att)
Create the output file.
Process cubes by line.
Isis::Cube * SetInputCube(const QString &parameter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
void ProcessCubeInPlace(const Functor &funct, bool threaded=true)
Same functionality as StartProcess(void funct(Isis::Buffer &inout)) using Functors.
virtual void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
Definition Process.cpp:462
virtual Isis::Cube * SetOutputCube(const QString &parameter)
Allocates a user-specified output cube whose size matches the first input cube.
Definition Process.cpp:163
virtual Isis::Cube * SetInputCube(const QString &parameter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
Definition Process.cpp:139
void ClearInputCubes()
Close owned input cubes from the list and clear the list.
Definition Process.cpp:614
Derivative of Process, designed for geometric transformations.
virtual void StartProcess(Transform &trans, Interpolator &interp)
Applies a Transform and an Interpolator to every pixel in the output cube.
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
QString name() const
Returns the container name.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
void write(const QString &file)
Opens and writes PVL information to a file and handles the end of line sequence.
Definition Pvl.cpp:130
A single keyword-value pair.
Definition PvlKeyword.h:87
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
PvlGroup & group(const int index)
Return the group at the specified index.
int groups() const
Returns the number of groups contained.
Definition PvlObject.h:75
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition PvlObject.h:274
int objects() const
Returns the number of objects.
Definition PvlObject.h:219
PvlObject & object(const int index)
Return the object at the specified index.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition PvlObject.h:186
Isis::PvlGroup UpdateOutputLabel(Isis::Cube *pOutCube)
Create label for the reduced output image.
Definition Reduce.cpp:112
void setInputBoundary(int startSample, int endSample, int startLine, int endLine)
Parameters to input image sub area.
Definition Reduce.cpp:87
Widget to save(Save As) Isis cubes(used in qview) to display the FileDialog to select the output cube...
Apply corrections to a cube label for subarea extraction.
Definition SubArea.h:47
void UpdateLabel(Cube *icube, Cube *ocube, PvlGroup &results)
Modifies a label for a file containing a subarea.
Definition SubArea.cpp:126
void SetSubArea(const int orignl, const int origns, const int sl, const int ss, const int el, const int es, const double linc, const double sinc)
Defines the subarea.
Definition SubArea.cpp:60
Tool(QWidget *parent)
Tool constructor.
Definition Tool.cpp:27
void addTo(ViewportMainWindow *mw)
Adds the tool to the application.
Definition Tool.cpp:78
void activate(bool)
Activates the tool.
Definition Tool.cpp:131
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition Tool.cpp:390
void setCubeViewport(MdiCubeViewport *cvp)
Sets the current viewport to the given cvp.
Definition Tool.cpp:160
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 was called the Qisis MainWindow.
QMdiArea * mdiArea()
This method returns the QMdiArea.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Calculator.h:18
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
@ AttachedLabel
The input label is embedded in the image file.