3 #include <QApplication>
11 #include <QPrintDialog>
16 #include "BrowseDialog.h"
19 #include "FileDialog.h"
21 #include "MainWindow.h"
29 #include "SaveAsDialog.h"
44 p_dir =
"/thisDirDoesNotExist!";
46 p_open->setShortcut(Qt::CTRL + Qt::Key_O);
47 p_open->setText(
"&Open...");
49 p_open->setToolTip(
"Open cube");
51 "<b>Function:</b> Open an <i>Isis cube</i> in new viewport \
52 <p><b>Shortcut:</b> Ctrl+O\n</p> \
53 <p><b>Hint:</b> Use Ctrl or Shift in file dialog to open \
55 p_open->setWhatsThis(whatsThis);
56 connect(
p_open, SIGNAL(activated()),
this, SLOT(
open()));
59 p_browse->setShortcut(Qt::CTRL + Qt::Key_B);
61 p_browse->setToolTip(
"Browse cubes");
63 "<b>Function:</b> Browse a <i>Isis cubes</i> in new viewport \
64 <p><b>Shortcut:</b> Ctrl+B\n</p>";
69 p_save->setShortcut(Qt::CTRL + Qt::Key_S);
72 p_save->setToolTip(
"Save");
74 "<b>Function:</b> Save changes to the current Cube \
75 <p><b>Shortcut:</b> Ctrl+S</p>";
76 p_save->setWhatsThis(whatsThis);
77 connect(
p_save, SIGNAL(activated()),
this, SLOT(
save()));
85 "<b>Function:</b> Save the current Cube to the specified location";
95 "<b>Function:</b> Save the current Cube's Whatsthis Info to the specified location";
105 "<b>Function:</b> Save visible contents of the active \
106 viewport as a png, jpg, tiff \
107 <p><b>Hint:</b> Your local installation of Qt may not support \
108 all formats. Reinstall Qt if necessary</p>";
115 p_print->setShortcut(Qt::CTRL + Qt::Key_P);
119 "<b>Function:</b> Print visible contents of the active viewport \
120 <p><b>Shortcut:</b> Ctrl+P</b>";
121 p_print->setWhatsThis(whatsThis);
122 connect(
p_print, SIGNAL(activated()),
this, SLOT(
print()));
129 "<b>Function:</b> Close all cube viewports.";
133 p_exit->setShortcut(Qt::CTRL + Qt::Key_Q);
137 "<b>Function:</b> Quit qview \
138 <p><b>Shortcut:</b> Ctrl+Q</p>";
139 p_exit->setWhatsThis(whatsThis);
140 connect(
p_exit, SIGNAL(activated()),
this, SLOT(
exit()));
174 ws, SLOT(addCubeViewport(QString)));
176 connect(
p_closeAll, SIGNAL(activated()), ws->mdiArea(), SLOT(closeAllSubWindows()));
201 if (!
p_dir.exists()) {
202 p_dir = QDir::current();
221 if (!
p_dir.exists()) {
222 p_dir = QDir::current();
239 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to save");
244 p_save->setEnabled(
false);
264 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to save");
271 if (!
p_dir.exists()) {
296 QMessageBox::information((
QWidget *)parent(),
"Error",
297 "No active cube to save");
303 QMessageBox::information((
QWidget *)parent(),
"Error",
304 "No output file selected");
311 for (it = vwportList->begin(); it != vwportList->end(); ++it){
312 if (QString((*it)->cube()->fileName()) == psOutFile) {
313 QMessageBox::information((
QWidget *)parent(),
"Error",
314 "Output File is already open\n\""+ psOutFile +
"\"");
335 if (
p_saveAsDialog->getSaveAsType() != SaveAsDialog::ExportAsIs ||
349 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
350 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
352 if (
p_saveAsDialog->getSaveAsType() == SaveAsDialog::ExportFullRes ||
356 int numSamples = (int)((dEndSample - dStartSample + 1) + 0.5);
357 int numLines = (int)((dEndLine - dStartLine + 1) + 0.5);
362 else if (
p_saveAsDialog->getSaveAsType() == SaveAsDialog::ExportAsIs ) {
370 p_save->setEnabled(
false);
389 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
390 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
392 double ins = dEndSample - dStartSample + 1;
393 double inl = dEndLine - dStartLine + 1;
395 double ons = (int)(ins * dScale + 0.5);
396 double onl = (int)(inl * dScale + 0.5);
407 imgEnlarge->
SetInputArea((
int)dStartSample, (
int)dEndSample, (
int)dStartLine, (
int)dEndLine);
417 QMessageBox::critical((
QWidget *)parent(),
418 "Error",
"Cannot open file, please check permissions");
435 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
436 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
438 double ins = dEndSample - dStartSample + 1;
439 double inl = dEndLine - dStartLine + 1;
441 double ons = (int)(ins * dScale + 0.5);
442 double onl = (int)(inl * dScale + 0.5);
445 std::vector<QString> bands = cai.
bands();
446 int inb = bands.size();
450 for(
int i = 1; i <= inb; i++) {
473 near->
setInputBoundary((
int)dStartSample, (
int)dEndSample, (
int)dStartLine, (
int)dEndLine);
518 Cube *ocube,
int piNumSamples,
int piNumLines,
int piNumBands) {
541 double base = icube->
base();
548 QString msg =
"Looks like your refactoring to add different pixel types";
549 msg +=
" you'll need to make changes here";
553 QString msg =
"You've chosen to reduce your output PixelType for [" +
554 psOutFile +
"] you must specify the output pixel range too";
563 int needLabBytes = icube->
labelSize(
true) + (1024 * 6);
574 for(
int i = 0; i < incube.
groups(); i++) {
580 for(
int i = 0; i < inlab.
objects(); i++) {
589 inlab = *icube->
label();
590 for(
int i = 0; i < inlab.
objects(); i++) {
599 inlab = *icube->
label();
600 for(
int i = 0; i < inlab.
objects(); i++) {
630 if (ibrick.Bricks() > obrick.Bricks()) {
631 numBricks = ibrick.
Bricks();
634 numBricks = obrick.Bricks();
640 for(
int i = 0; i < numBricks; i++) {
643 copy(ibrick, obrick);
644 ocube->
write(obrick);
662 Cube *pOutCube,
int pNumSamples,
int pNumLines) {
664 double dStartSample=0, dEndSample=0, dStartLine=0, dEndLine=0;
665 p_lastViewport->getCubeArea(dStartSample, dEndSample, dStartLine, dEndLine);
681 dEndLine, dEndSample, 1.0, 1.0);
687 for(
int iBand=1; iBand<=iNumBands; iBand++) {
689 for(
int iLine=(
int)dStartLine; iLine<=(int)dEndLine; iLine++) {
691 pInCube->
read(iPortal);
693 oPortal.SetPosition(1, ol++, iBand);
694 pOutCube->
read(oPortal);
696 oPortal.Copy(iPortal);
697 pOutCube->
write(oPortal);
711 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to save info");
717 QFileDialog::getSaveFileName((
QWidget *)parent(),
718 "Choose output file",
720 QString(
"PVL Files (*.pvl)"));
723 if (output.isEmpty()) {
726 else if (!output.endsWith(
".pvl")) {
732 whatsThisPvl.
write(output);
760 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to export");
765 QFileDialog::getSaveFileName((
QWidget *)parent(),
766 QString(
"Choose output file"),
768 QString(
"PNG (*.png);;JPG (*.jpg);;TIF (*.tif)"));
769 if (output.isEmpty())
return;
773 QString format = QFileInfo(output).suffix();
775 if (format.isEmpty()) {
776 if (output.endsWith(
'.')) {
777 output.append(QString(
"png"));
780 output.append(QString(
".png"));
783 else if (format.compare(
"png", Qt::CaseInsensitive) &&
784 format.compare(
"jpg", Qt::CaseInsensitive) &&
785 format.compare(
"tif", Qt::CaseInsensitive)) {
787 QMessageBox::information((
QWidget *)parent(),
"Error", format +
" is an invalid extension.");
791 QPixmap pm = QPixmap::grabWidget(
cubeViewport()->viewport());
795 if (!pm.save(output)) {
796 QMessageBox::information((
QWidget *)parent(),
"Error",
"Unable to save " + output);
808 QMessageBox::information((
QWidget *)parent(),
"Error",
"No active cube to print");
813 static QPrinter *printer = NULL;
814 if (printer == NULL) printer =
new QPrinter;
815 printer->setPageSize(QPrinter::Letter);
816 printer->setColorMode(QPrinter::GrayScale);
817 if (
cubeViewport()->isColor()) printer->setColorMode(QPrinter::Color);
819 QPrintDialog printDialog(printer, (
QWidget *)parent());
820 if (printDialog.exec() == QDialog::Accepted) {
822 QPixmap pixmap = QPixmap::grabWidget(
cubeViewport()->viewport());
823 QImage img = pixmap.toImage();
826 QPainter painter(printer);
827 QRect rect = painter.viewport();
828 QSize size = img.size();
829 size.scale(rect.size(), Qt::KeepAspectRatio);
830 painter.setViewport(rect.x(), rect.y(),
831 size.width(), size.height());
832 painter.setWindow(img.rect());
833 painter.drawImage(0, 0, img);
847 for(
int i = 0; i < (int)tempList.size(); i++) {
852 if (!d->parentWidget()->close()) {
880 p_save->setEnabled(enable);
893 p_save->setEnabled(
false);
907 if (
cubeViewport()->parentWidget()->windowTitle().endsWith(
"*")) {
912 p_save->setEnabled(
false);