15#include <QPrintDialog>
19#include "BrowseDialog.h"
20#include "CubeAttribute.h"
22#include "FileDialog.h"
23#include "Interpolator.h"
24#include "MainWindow.h"
25#include "MdiCubeViewport.h"
26#include "OriginalLabel.h"
28#include "ProcessRubberSheet.h"
29#include "ProcessByLine.h"
32#include "SaveAsDialog.h"
34#include "ViewportMainWindow.h"
48 p_dir.setPath(
"/thisDirDoesNotExist!");
50 p_open->setShortcut(Qt::CTRL + Qt::Key_O);
51 p_open->setText(
"&Open...");
53 p_open->setToolTip(
"Open cube");
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 \
59 p_open->setWhatsThis(whatsThis);
60 connect(
p_open, SIGNAL(triggered()),
this, SLOT(
open()));
63 p_browse->setShortcut(Qt::CTRL + Qt::Key_B);
65 p_browse->setToolTip(
"Browse cubes");
67 "<b>Function:</b> Browse a <i>Isis cubes</i> in new viewport \
68 <p><b>Shortcut:</b> Ctrl+B\n</p>";
73 p_save->setShortcut(Qt::CTRL + Qt::Key_S);
76 p_save->setToolTip(
"Save");
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()));
89 "<b>Function:</b> Save the current Cube to the specified location";
99 "<b>Function:</b> Save the current Cube's Whatsthis Info to the specified location";
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>";
122 "<b>Function:</b> Save all open cubes \
123 to a .lis file containing their file names";
130 p_print->setShortcut(Qt::CTRL + Qt::Key_P);
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()));
144 "<b>Function:</b> Close all cube viewports.";
148 p_exit->setShortcut(Qt::CTRL + Qt::Key_Q);
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()));
192 ws, SLOT(addCubeViewport(QString)));
194 connect(
p_closeAll, SIGNAL(triggered()), ws->mdiArea(), SLOT(closeAllSubWindows()));
221 if (!
p_dir.exists()) {
222 p_dir = QDir::current();
242 if (!
p_dir.exists()) {
243 p_dir = QDir::current();
261 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to save");
266 p_save->setEnabled(
false);
287 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to save");
294 if (!
p_dir.exists()) {
320 QMessageBox::information((
QWidget *)parent(),
"Error",
321 "No active cube to save");
327 QMessageBox::information((
QWidget *)parent(),
"Error",
328 "No output file selected");
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 +
"\"");
359 if (
p_saveAsDialog->getSaveAsType() != SaveAsDialog::ExportAsIs ||
367 icube->lineCount(), icube->bandCount());
373 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
374 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
376 if (
p_saveAsDialog->getSaveAsType() == SaveAsDialog::ExportFullRes ||
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());
386 else if (
p_saveAsDialog->getSaveAsType() == SaveAsDialog::ExportAsIs ) {
394 p_save->setEnabled(
false);
414 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
415 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
417 double ins = dEndSample - dStartSample + 1;
418 double inl = dEndLine - dStartLine + 1;
420 double ons = (int)(ins * dScale + 0.5);
421 double onl = (int)(inl * dScale + 0.5);
427 ons, onl, icube->bandCount());
432 imgEnlarge->SetInputArea((
int)dStartSample, (
int)dEndSample, (
int)dStartLine, (
int)dEndLine);
434 p.StartProcess(*imgEnlarge, *interp);
435 imgEnlarge->UpdateOutputLabel(ocube);
445 QObject::tr(
"The cube could not be saved, unable to create the cube"),
464 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
465 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
467 double ins = dEndSample - dStartSample + 1;
468 double inl = dEndLine - dStartLine + 1;
470 double ons = (int)(ins * dScale + 0.5);
471 double onl = (int)(inl * dScale + 0.5);
474 std::vector<QString> bands = cai.bands();
475 int inb = bands.size();
479 for(
int i = 1; i <= inb; i++) {
496 near->setInputBoundary((
int)dStartSample, (
int)dEndSample, (
int)dStartLine, (
int)dEndLine);
498 p.ProcessCubeInPlace(*near,
false);
499 near->UpdateOutputLabel(ocube);
511 QObject::tr(
"The cube could not be saved, unable to create the cube"),
553 Cube *ocube,
int piNumSamples,
int piNumLines,
int piNumBands) {
559 ocube->setDimensions(piNumSamples, piNumLines, piNumBands);
560 ocube->setByteOrder(outAtt.byteOrder());
561 ocube->setFormat(outAtt.fileFormat());
562 ocube->setLabelsAttached(outAtt.labelAttachment() ==
AttachedLabel);
564 if (outAtt.propagatePixelType()) {
565 ocube->setPixelType(icube->pixelType());
568 ocube->setPixelType(outAtt.pixelType());
571 if (outAtt.propagateMinimumMaximum()) {
572 if (ocube->pixelType() == Real) {
573 ocube->setBaseMultiplier(0.0, 1.0);
575 else if (ocube->pixelType() >= icube->pixelType()) {
576 double base = icube->base();
577 double mult = icube->multiplier();
578 ocube->setBaseMultiplier(base, mult);
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";
591 QString msg =
"You've chosen to reduce your output PixelType for [" +
592 psOutFile +
"] you must specify the output pixel range too";
598 ocube->setMinMax(outAtt.minimum(), outAtt.maximum());
601 int needLabBytes = icube->labelSize(
true) + (1024 * 6);
602 if (needLabBytes > ocube->labelSize()) {
603 ocube->setLabelSize(needLabBytes);
607 ocube->create(psOutFile);
612 for(
int i = 0; i < incube.groups(); i++) {
613 outcube.addGroup(incube.group(i));
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());
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());
637 inlab = *icube->label();
638 for(
int i = 0; i < inlab.objects(); i++) {
639 if (inlab.object(i).isNamed(
"OriginalLabel")) {
664 Brick ibrick(*icube, icube->sampleCount(), 1, 1);
665 Brick obrick(*ocube, ocube->sampleCount(), 1, 1);
668 if (ibrick.Bricks() > obrick.Bricks()) {
669 numBricks = ibrick.Bricks();
672 numBricks = obrick.Bricks();
678 for(
int i = 0; i < numBricks; i++) {
681 copy(ibrick, obrick);
682 ocube->write(obrick);
701 Cube *pOutCube,
int pNumSamples,
int pNumLines) {
703 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
704 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
705 int iNumBands = pInCube->bandCount();
719 subArea.
SetSubArea(pInCube->lineCount(), pInCube->sampleCount(), dStartLine, dStartSample,
720 dEndLine, dEndSample, 1.0, 1.0);
721 subArea.UpdateLabel(pInCube, pOutCube, results);
723 Portal iPortal (pNumSamples, 1, pInCube->pixelType());
724 Portal oPortal (pNumSamples, 1, pOutCube->pixelType());
726 for(
int iBand=1; iBand<=iNumBands; iBand++) {
728 for(
int iLine=(
int)dStartLine; iLine<=(int)dEndLine; iLine++) {
729 iPortal.SetPosition(dStartSample, iLine, iBand);
730 pInCube->read(iPortal);
732 oPortal.SetPosition(1, ol++, iBand);
733 pOutCube->read(oPortal);
735 oPortal.Copy(iPortal);
736 pOutCube->write(oPortal);
751 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to save info");
757 QFileDialog::getSaveFileName((
QWidget *)parent(),
758 "Choose output file",
760 QString(
"PVL Files (*.pvl)"));
763 if (output.isEmpty()) {
766 else if (!output.endsWith(
".pvl")) {
772 whatsThisPvl.write(output);
803 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to export");
808 QFileDialog::getSaveFileName((
QWidget *)parent(),
809 QString(
"Choose output file"),
811 QString(
"PNG (*.png);;JPG (*.jpg);;TIF (*.tif)"));
812 if (output.isEmpty())
return;
816 QString format = QFileInfo(output).suffix();
818 if (format.isEmpty()) {
819 if (output.endsWith(
'.')) {
820 output.append(QString(
"png"));
823 output.append(QString(
".png"));
826 else if (format.compare(
"png", Qt::CaseInsensitive) &&
827 format.compare(
"jpg", Qt::CaseInsensitive) &&
828 format.compare(
"tif", Qt::CaseInsensitive)) {
830 QMessageBox::information((
QWidget *)parent(),
"Error", format +
" is an invalid extension.");
838 if (!pm.save(output)) {
839 QMessageBox::information((
QWidget *)parent(),
"Error",
"Unable to save " + output);
855 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cubes to export");
864 if (window == NULL) {
865 QMessageBox::critical((
QWidget *)parent(),
"Error",
"There was an error reading the viewport window.");
869 QList<CubeViewport*> openCubes = window->findChildren<
CubeViewport*>();
870 QList<QString> cubeFilePaths;
872 for (
int i = 0; i < openCubes.size(); i++) {
879 cubeFilePaths.append(cubeFileName.absoluteFilePath());
882 QString fileName = QFileDialog::getSaveFileName((
QWidget *) parent(),
883 "Export to cube list",
885 "Cube List (*.lis)");
887 if (!fileName.contains(
".lis")) {
888 fileName.append(
".lis");
891 QFile outputFile(fileName);
892 outputFile.open(QIODevice::WriteOnly | QIODevice::Text);
894 QTextStream out(&outputFile);
897 for (
int i = 0; i < cubeFilePaths.size(); i++){
898 out << cubeFilePaths.value(i) <<
"\n";
911 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to print");
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);
923 QPrintDialog printDialog(printer, (
QWidget *)parent());
924 if (printDialog.exec() == QDialog::Accepted) {
927 QImage img = pixmap.toImage();
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);
952 for(
int i = 0; i < (int)tempList.size(); i++) {
957 if (!d->parentWidget()->close()) {
986 p_save->setEnabled(enable);
999 p_save->setEnabled(
false);
1014 if (
cubeViewport()->parentWidget()->windowTitle().endsWith(
"*")) {
1015 p_save->setEnabled(
true);
1019 p_save->setEnabled(
false);
Buffer for containing a three dimensional section of an image.
Class for browsing cubes.
Buffer for reading and writing cube data.
Manipulate and parse attributes of output cube filenames.
IO Handler for Isis Cubes.
void open(const QString &cfile, QString access="r")
This method will open an existing isis cube for reading or reading/writing.
virtual QString fileName() const
Returns the opened cube's filename.
virtual int bandCount() const
Returns the number of virtual bands for the cube.
void reopen(QString access="r")
This method will reopen an isis sube for reading or reading/writing.
Widget to display Isis cubes for qt apps.
void getAllWhatsThisInfo(Pvl &pWhatsThisPvl)
Get All WhatsThis info - viewport, cube, area in PVL format.
Enlarge the pixel dimensions of an image.
Class for browsing cubes.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
@ Io
A type of error that occurred when performing an actual I/O operation.
Cube display widget for certain Isis MDI applications.
Functor for reduce using near functionality.
Read and store original labels.
Buffer for containing a two dimensional section of an image.
Isis::Cube * SetInputCube(const QString ¶meter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
virtual Isis::Cube * SetInputCube(const QString ¶meter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
Derivative of Process, designed for geometric transformations.
Contains multiple PvlContainers.
Container for cube-like labels.
A single keyword-value pair.
Contains Pvl Groups and Pvl Objects.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
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.
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.
This was called the Qisis MainWindow.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
@ AttachedLabel
The input label is embedded in the image file.