From 6dafcfa00c225808f5dfd76aa940e08d584ae35c Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 10 Jan 2020 15:29:28 -0700 Subject: [PATCH 01/14] Update meta.yaml to rename conda package to isis from isis3 --- recipe/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 7ec852a89b..3a47842618 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -26,7 +26,7 @@ {% set build_number = "0" %} package: - name: isis3 + name: isis version: {{ version }} source: From fc80fdd3ef5c0e686f663e096c80f112c0ee07d6 Mon Sep 17 00:00:00 2001 From: Kristin Date: Mon, 10 Feb 2020 12:57:23 -0700 Subject: [PATCH 02/14] Initial stretch attempt --- .../objs/StretchTool/AdvancedStretch.cpp | 7 ++++++ .../qisis/objs/StretchTool/AdvancedStretch.h | 5 ++++ .../StretchTool/AdvancedStretchDialog.cpp | 3 +++ .../qisis/objs/StretchTool/StretchTool.cpp | 25 +++++++++++++++++++ isis/src/qisis/objs/StretchTool/StretchTool.h | 1 + .../qisis/objs/StretchTool/StretchType.cpp | 8 ++++++ isis/src/qisis/objs/StretchTool/StretchType.h | 4 ++- 7 files changed, 52 insertions(+), 1 deletion(-) diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index ae237ddd05..1fe46e67f8 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -5,8 +5,10 @@ #include #include #include +#include #include "Stretch.h" +#include "StretchTool.h" #include "IString.h" #include "IException.h" #include "StretchType.h" @@ -48,6 +50,7 @@ namespace Isis { LinearStretchType *linear = new LinearStretchType(hist, curStretch, name, color); connect(linear, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); + connect(linear, SIGNAL(saveToCube()), this, SLOT(saveMe())); p_stretchTypeStack->addWidget(linear); SawtoothStretchType *sawtooth = new SawtoothStretchType(hist, curStretch, @@ -72,6 +75,10 @@ namespace Isis { this, SIGNAL(stretchChanged())); } + void AdvancedStretch::saveMe() { + Cube* icube = ((StretchTool*)parentWidget())->cubeViewport()->cube(); + QMessageBox::information((QWidget *)parent(), "Error", "Cube is Read here Only"); + } /** * Destructor diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h index acd80e8f32..1b7c842273 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h @@ -41,9 +41,14 @@ namespace Isis { signals: //! Emitted when a new stretch is available void stretchChanged(); + void saveToCube(); + + protected slots: + void saveMe(); protected: + private: QStackedWidget *p_stretchTypeStack; //!< StretchType's }; diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index 7055a49a2c..76ada202e2 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -21,7 +21,10 @@ namespace Isis { p_bluStretch = NULL; p_enabled = false; + setWindowTitle("Advanced Stretch Tool"); + QHBoxLayout *layout = new QHBoxLayout(); + setLayout(layout); } diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 09660aecdb..1b3caa9f09 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -51,6 +51,8 @@ namespace Isis { this, SLOT(advancedStretchChanged())); connect(m_advancedStretch, SIGNAL(visibilityChanged()), this, SLOT(updateTool())); + connect(m_advancedStretch, SIGNAL(saveToCube()), + this, SLOT(saveMe())); QPushButton *hiddenButton = new QPushButton(); hiddenButton->setVisible(false); @@ -370,6 +372,29 @@ namespace Isis { } } + + void StretchTool::saveMe() { + QMessageBox::information((QWidget *)parent(), "Error", "Cube is Read Only"); + +// MdiCubeViewport *cvp = cubeViewport(); +// Cube* icube = cvp->cube(); + + // If cube readonly print error +// if (icube->isReadOnly()) { +// QMessageBox::information((QWidget *)parent(), "Error", "Cube is Read Only"); +// return; +// } + + +// QMessageBox::information((QWidget *) parent(), "Worked" , "vp->cube()->Lines()"); + +// Stretch stretch = getStretch(); + + //Add the pairs to the file +// stream << stretch.Text() << endl; + + } + /** * This is called when the visible area changes. */ diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.h b/isis/src/qisis/objs/StretchTool/StretchTool.h index cfa9cb0f40..df7263370b 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.h +++ b/isis/src/qisis/objs/StretchTool/StretchTool.h @@ -171,6 +171,7 @@ namespace Isis { protected slots: void mouseButtonRelease(QPoint p, Qt::MouseButton s); + void saveMe(); void enableRubberBandTool(); void screenPixelsChanged(); void updateHistograms(); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index 87a93dba2e..a6231094b2 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -59,6 +59,10 @@ namespace Isis { connect(saveAsButton, SIGNAL(clicked(bool)), this, SLOT(savePairs())); p_mainLayout->addWidget(saveAsButton, 3, 0); + QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube!"); + connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); + p_mainLayout->addWidget(saveToCubeButton, 4, 0); + QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); sizePolicy.setHeightForWidth(true); p_graph->setSizePolicy(sizePolicy); @@ -174,6 +178,10 @@ namespace Isis { outfile.close(); } + void StretchType::emitTest() { + emit saveToCube(); + } + /** * Returns the current stretch object diff --git a/isis/src/qisis/objs/StretchTool/StretchType.h b/isis/src/qisis/objs/StretchTool/StretchType.h index 00808f2677..54a011f1b2 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.h +++ b/isis/src/qisis/objs/StretchTool/StretchType.h @@ -72,11 +72,13 @@ namespace Isis { signals: //! Emitted when a new Stretch object is available + void saveToCube(); void stretchChanged(); - private slots: void savePairs(); + void emitTest(); + }; }; From d7a14f51ad9a4c3b64ac9d68186fc0856ae5626d Mon Sep 17 00:00:00 2001 From: Kristin Date: Wed, 26 Feb 2020 13:25:17 -0700 Subject: [PATCH 03/14] Now will write a single stretch with a name and type to the cube --- .../objs/StretchTool/AdvancedStretch.cpp | 19 +++-- .../qisis/objs/StretchTool/AdvancedStretch.h | 10 ++- .../StretchTool/AdvancedStretchDialog.cpp | 14 +++- .../objs/StretchTool/AdvancedStretchDialog.h | 3 + .../objs/StretchTool/LinearStretchType.cpp | 10 +++ .../objs/StretchTool/LinearStretchType.h | 2 +- .../qisis/objs/StretchTool/StretchTool.cpp | 74 +++++++++++++++---- .../qisis/objs/StretchTool/StretchType.cpp | 18 ++++- isis/src/qisis/objs/StretchTool/StretchType.h | 8 +- 9 files changed, 131 insertions(+), 27 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index 1fe46e67f8..5ec2f9c0eb 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -50,7 +50,8 @@ namespace Isis { LinearStretchType *linear = new LinearStretchType(hist, curStretch, name, color); connect(linear, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); - connect(linear, SIGNAL(saveToCube()), this, SLOT(saveMe())); +// connect(linear, SIGNAL(saveToCube()), this, SLOT(saveMe())); + connect(linear, SIGNAL(saveToCube()), this, SIGNAL(saveToCube())); p_stretchTypeStack->addWidget(linear); SawtoothStretchType *sawtooth = new SawtoothStretchType(hist, curStretch, @@ -75,10 +76,10 @@ namespace Isis { this, SIGNAL(stretchChanged())); } - void AdvancedStretch::saveMe() { - Cube* icube = ((StretchTool*)parentWidget())->cubeViewport()->cube(); - QMessageBox::information((QWidget *)parent(), "Error", "Cube is Read here Only"); - } +// void AdvancedStretch::saveMe() { +// Cube* icube = ((StretchTool*)parentWidget())->cubeViewport()->cube(); +// QMessageBox::information((QWidget *)parent(), "Error", "advanced stretch"); +// } /** * Destructor @@ -96,6 +97,14 @@ namespace Isis { return ((StretchType *)p_stretchTypeStack->currentWidget())->getStretch(); } + // This seems like a bad idea? (if keep, can eliminate at the StretchType level? In theory???? + QString AdvancedStretch::getStretchType() { + return ((StretchType *)p_stretchTypeStack->currentWidget())->getStretchType(); + } + + QString AdvancedStretch::getName() { + return ((StretchType *)p_stretchTypeStack->currentWidget())->getName(); + } /** * This is called when the user creates a stretch outside of the diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h index 1b7c842273..25f6e48a57 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h @@ -37,16 +37,18 @@ namespace Isis { Stretch getStretch(); void setStretch(Stretch newStretch); void setHistogram(const Histogram &newHist); + QString getStretchType(); + QString getName(); signals: //! Emitted when a new stretch is available void stretchChanged(); - void saveToCube(); + void saveToCube(); - protected slots: - void saveMe(); +// protected slots: +// void saveMe(); - protected: +// protected: private: diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index 76ada202e2..c6f8772235 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -72,6 +72,7 @@ namespace Isis { this, SIGNAL(stretchChanged())); connect(p_bluStretch, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); + // add signal for RGB } /** @@ -127,6 +128,8 @@ namespace Isis { connect(p_grayStretch, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); + connect(p_grayStretch, SIGNAL(saveToCube()), + this, SIGNAL(saveToCube())); } @@ -216,7 +219,7 @@ namespace Isis { /** - * This calls setHistogram on the gray advanced stretche. This + * This calls setHistogram on the gray advanced stretches. This * should be called every time the visible area changes. * * @param grayHist Histogram of visible area on gray band @@ -276,6 +279,15 @@ namespace Isis { } + // also bad idea? /// THIS IS OF TYPE AdvancedStretch, so ... something. need to draw out. + QString AdvancedStretchDialog::getStretchType() { + return p_grayStretch->getStretchType(); + } + + QString AdvancedStretchDialog::getName() { + return p_grayStretch->getName(); + } + /** * This returns the advanced stretch's stretch for red. * diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index 2799f5a15f..e1f5d027ac 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -50,6 +50,8 @@ namespace Isis { bool isRgbMode() const; Stretch getGrayStretch(); + QString getStretchType(); + QString getName(); Stretch getRedStretch(); Stretch getGrnStretch(); Stretch getBluStretch(); @@ -77,6 +79,7 @@ namespace Isis { void stretchChanged(); //! Emitted when this dialog is shown or hidden void visibilityChanged(); + void saveToCube(); public slots: void updateStretch(CubeViewport *); diff --git a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp index a1211598ed..b414695471 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp @@ -258,4 +258,14 @@ namespace Isis { Stretch LinearStretchType::getStretch() { return *p_stretch; } + + // work out the flow in a minute + QString LinearStretchType::getStretchType() { + return "LinearStretch"; + } + + // work out the flow in a minute +// QString LinearStretchType::getName() { +// return "UserSetName"; +// } } diff --git a/isis/src/qisis/objs/StretchTool/LinearStretchType.h b/isis/src/qisis/objs/StretchTool/LinearStretchType.h index 1ca66618ec..c07a0c5d40 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.h +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.h @@ -34,9 +34,9 @@ namespace Isis { ~LinearStretchType(); virtual Stretch getStretch(); + virtual QString getStretchType(); virtual void setStretch(Stretch); - private slots: void startSliderMoved(int); void startEditChanged(const QString &); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 1b3caa9f09..68725ecfd3 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -13,9 +13,11 @@ #include #include #include +#include #include "AdvancedStretchDialog.h" #include "Brick.h" +#include "Blob.h" #include "CubeViewport.h" #include "Histogram.h" #include "IException.h" @@ -372,27 +374,73 @@ namespace Isis { } } - +// HERE void StretchTool::saveMe() { - QMessageBox::information((QWidget *)parent(), "Error", "Cube is Read Only"); + MdiCubeViewport *cvp = cubeViewport(); + Cube* icube = cvp->cube(); + //Pvl* lab = icube->label(); -// MdiCubeViewport *cvp = cubeViewport(); -// Cube* icube = cvp->cube(); + // iterate over relevant PVL objects to make sure not taken + // PvlObjectIterator object = lab-> ->findObject("LinearStretch"); - // If cube readonly print error -// if (icube->isReadOnly()) { -// QMessageBox::information((QWidget *)parent(), "Error", "Cube is Read Only"); -// return; -// } + //PvlObject object = lab->findObject("LinearStretch"); +// PvlKeyword currentName = object.findKeyword("Name"); + + // can I get a list of objects and search by name??? +/* QStringList namelist; + + PvlObject::PvlObjectIterator objIter; + PvlGroup fpgrp; + for (objIter=lab->beginObject(); objIter<=lab->endObject(); objIter++) { + if (objIter->name() == "Stretch") { + PvlKeyword tempKeyword = objIter->findKeyword("Name"); +// QString tempName = tempKeyword[0]; +// namelist.append(tempName); + } + } -// QMessageBox::information((QWidget *) parent(), "Worked" , "vp->cube()->Lines()"); -// Stretch stretch = getStretch(); + bool ok; + QString name; + QString text = QInputDialog::getText(m_advancedStretch, tr("Save Stretch"), + tr("Name of Stretch Pair:"), QLineEdit::Normal, + "temp", &ok); + if (ok && !text.isEmpty()) { +// && !lab->hasObject(text)) { + name = text; + } + else { + QString text = QInputDialog::getText(m_advancedStretch, tr("Save Stretch"), + tr("Name of Stretch Pair not already selected:"), QLineEdit::Normal, + text, &ok); + }*/ + + Stretch stretch = m_advancedStretch->getGrayStretch(); + QString stretchType = m_advancedStretch->getStretchType(); + QString name = "foxtail_fern"; + + // If cube readonly print error + if (icube->isReadOnly()) { + // ReOpen cube as read/write + // If cube readonly print error + try { + cvp->cube()->reopen("rw"); + } + catch(IException &) { + cvp->cube()->reopen("r"); + QMessageBox::information((QWidget *)parent(), "Error", "Cannot open cube read/write to save stretch"); + return; + } + } - //Add the pairs to the file -// stream << stretch.Text() << endl; + // how to get name and stretchtype from AdvancedStretchTool? + Blob blob(name, stretchType); +// stretch.Text()); <-- contents + icube->write(blob); + // Don't leave open rw -- not optimal. + cvp->cube()->reopen("r"); } /** diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index a6231094b2..e5b4e0e80e 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "Stretch.h" #include "Histogram.h" @@ -35,6 +36,7 @@ namespace Isis { p_cubeHist = NULL; p_graph = NULL; p_mainLayout = NULL; + p_name = "no name"; p_cubeHist = new Histogram(hist); @@ -61,6 +63,7 @@ namespace Isis { QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube!"); connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); +// connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SLOT(promptName())); p_mainLayout->addWidget(saveToCubeButton, 4, 0); QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); @@ -178,8 +181,19 @@ namespace Isis { outfile.close(); } - void StretchType::emitTest() { - emit saveToCube(); + + void StretchType::promptName() { +// bool ok; +// QString text = QInputDialog::getText(this, tr("Save Stretch"), +// tr("Name of Stretch Pair:"), QLineEdit::Normal, +// "stretch", &ok); +// if (ok && !text.isEmpty()) { +// p_name = text; +// } + + // warn if a stretch of the same name already exists and that it will be over-written + QString nothing("nothing"); +// emit saveToCube(); } diff --git a/isis/src/qisis/objs/StretchTool/StretchType.h b/isis/src/qisis/objs/StretchTool/StretchType.h index 54a011f1b2..4baeec338e 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.h +++ b/isis/src/qisis/objs/StretchTool/StretchType.h @@ -45,6 +45,9 @@ namespace Isis { virtual ~StretchType(); virtual Stretch getStretch(); + virtual QString getStretchType() { return "unknown";}; // change to pure virutal + virtual QString getName() { return p_name;}; // change to pure virutal?? + /** * Children must re-implement this to update their stretch pairs and GUI * elements appropriately. This could be called with a @@ -61,6 +64,7 @@ namespace Isis { protected slots: void updateGraph(); void updateTable(); + void promptName(); protected: // data QGridLayout *p_mainLayout; //!< Main layout @@ -77,7 +81,9 @@ namespace Isis { private slots: void savePairs(); - void emitTest(); + + private: + QString p_name; }; }; From b09c930002ff251b5d3473d5892508f03f220f38 Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 27 Feb 2020 19:32:10 -0700 Subject: [PATCH 04/14] Stretch updated to inherit from Blob, re-loading a saved stretch works but only if Linear right now --- isis/src/base/objs/Stretch/Stretch.cpp | 83 +++++++++- isis/src/base/objs/Stretch/Stretch.h | 12 +- .../objs/StretchTool/AdvancedStretch.cpp | 47 +++++- .../qisis/objs/StretchTool/AdvancedStretch.h | 11 +- .../StretchTool/AdvancedStretchDialog.cpp | 10 ++ .../objs/StretchTool/AdvancedStretchDialog.h | 3 + .../objs/StretchTool/BinaryStretchType.cpp | 4 + .../objs/StretchTool/BinaryStretchType.h | 1 + .../objs/StretchTool/LinearStretchType.cpp | 5 - .../objs/StretchTool/ManualStretchType.cpp | 4 + .../objs/StretchTool/ManualStretchType.h | 1 + .../objs/StretchTool/SawtoothStretchType.cpp | 4 + .../objs/StretchTool/SawtoothStretchType.h | 2 +- .../qisis/objs/StretchTool/StretchTool.cpp | 154 +++++++++++++++--- isis/src/qisis/objs/StretchTool/StretchTool.h | 2 + .../qisis/objs/StretchTool/StretchType.cpp | 9 + isis/src/qisis/objs/StretchTool/StretchType.h | 2 + 17 files changed, 309 insertions(+), 45 deletions(-) diff --git a/isis/src/base/objs/Stretch/Stretch.cpp b/isis/src/base/objs/Stretch/Stretch.cpp index 24458fd21e..076173737f 100644 --- a/isis/src/base/objs/Stretch/Stretch.cpp +++ b/isis/src/base/objs/Stretch/Stretch.cpp @@ -38,7 +38,7 @@ namespace Isis { * Constructs a Stretch object with default mapping of special pixel values to * themselves. */ - Stretch::Stretch() { + Stretch::Stretch() : Blob("NAME", "Stretch") { p_null = Isis::NULL8; p_lis = Isis::LOW_INSTR_SAT8; p_lrs = Isis::LOW_REPR_SAT8; @@ -47,6 +47,19 @@ namespace Isis { p_minimum = p_lrs; p_maximum = p_hrs; p_pairs = 0; + p_type = "none"; + } + + Stretch::Stretch(QString name) : Blob(name, "Stretch") { + p_null = Isis::NULL8; + p_lis = Isis::LOW_INSTR_SAT8; + p_lrs = Isis::LOW_REPR_SAT8; + p_his = Isis::HIGH_INSTR_SAT8; + p_hrs = Isis::HIGH_REPR_SAT8; + p_minimum = p_lrs; + p_maximum = p_hrs; + p_pairs = 0; + p_type = "none"; } /** @@ -410,6 +423,74 @@ namespace Isis { this->p_output = other.p_output; } + + void Stretch::ReadData(std::istream &is) { + streampos sbyte = p_startByte - 1; + is.seekg(sbyte, std::ios::beg); + if (!is.good()) { + QString msg = "Error preparing to read data from " + p_type + + " [" + p_blobName + "]"; + throw IException(IException::Io, msg, _FILEINFO_); + } + + char *buf = new char[p_nbytes+1]; + memset(buf, 0, p_nbytes + 1); + + is.read(buf, p_nbytes); + + string temp(buf); + QString tempFriend = QString::fromStdString(temp); + Parse(tempFriend); + + delete [] buf; + + if (!is.good()) { + QString msg = "Error reading data from " + p_type + " [" + + p_blobName + "]"; + throw IException(IException::Io, msg, _FILEINFO_); + } + + p_type = p_blobPvl["StretchType"][0]; + } + + QString Stretch::getType(){ + return p_type; + } + +// void Stretch::ReadInit() { +// p_nbytes = Text().toStdString().size(); +// } + + //! Initializes for writing polygon to cube blob + void Stretch::WriteInit() { +/* geos::io::WKTWriter *wkt = new geos::io::WKTWriter(); + + // Check to see p_polygons is valid data + if (!p_polygons) { + string msg = "Cannot write a NULL polygon!"; + throw IException(IException::Programmer, msg, _FILEINFO_); + } + p_polyStr = wkt->write(p_polygons); + p_nbytes = p_polyStr.size(); + + delete wkt;*/ + p_nbytes = Text().toStdString().size(); + } + + + void Stretch::WriteData(std::fstream &os) { + // std::string temp( +// QString temp("Legolas Greenleaf, long under tree..."); +// os.write(Text().toStdString().c_str(), Text().toStdString().size()); + // qDebug() << temp; + // qDebug() << temp.toStdString().size(); + + // QByteArray fred = temp.toUtf8(); +// os.write(temp.toStdString().c_str(), temp.size()); +// os.write(fred.data(), fred.size()); + os.write(Text().toStdString().c_str(), p_nbytes); + } + } // end namespace isis diff --git a/isis/src/base/objs/Stretch/Stretch.h b/isis/src/base/objs/Stretch/Stretch.h index 144bb41251..34fd415708 100644 --- a/isis/src/base/objs/Stretch/Stretch.h +++ b/isis/src/base/objs/Stretch/Stretch.h @@ -26,6 +26,7 @@ #include #include "Pvl.h" #include "Histogram.h" +#include "Blob.h" namespace Isis { /** @@ -69,7 +70,7 @@ namespace Isis { * to check both sides of boundry condition for valid data * */ - class Stretch { + class Stretch : public Isis::Blob { private: std::vector p_input; //!< Array for input side of stretch pairs std::vector p_output; //!< Array for output side of stretch pairs @@ -88,10 +89,13 @@ namespace Isis { double p_minimum; //! NextPair(QString &pairs); public: Stretch(); + Stretch(QString name); //! Destroys the Stretch object ~Stretch() {}; @@ -177,6 +181,7 @@ namespace Isis { return p_pairs; }; + QString getType(); double Input(const int index) const; double Output(const int index) const; @@ -188,6 +193,11 @@ namespace Isis { }; void CopyPairs(const Stretch &other); + + protected: + void ReadData(std::istream &is); + void WriteInit(); + void WriteData(std::fstream &os); }; }; diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index 5ec2f9c0eb..89f091662d 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -37,7 +37,8 @@ namespace Isis { typeSelectionArea->setLayout(new QHBoxLayout()); typeSelectionArea->layout()->addWidget(new QLabel("Stretch Type")); - QComboBox *stretchTypeSelection = new QComboBox(); +// QComboBox *stretchTypeSelection = new QComboBox(); + stretchTypeSelection = new QComboBox(); stretchTypeSelection->addItem("Linear", 0); stretchTypeSelection->addItem("Sawtooth", 1); stretchTypeSelection->addItem("Binary", 2); @@ -50,23 +51,33 @@ namespace Isis { LinearStretchType *linear = new LinearStretchType(hist, curStretch, name, color); connect(linear, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); -// connect(linear, SIGNAL(saveToCube()), this, SLOT(saveMe())); - connect(linear, SIGNAL(saveToCube()), this, SIGNAL(saveToCube())); + connect(linear, SIGNAL(saveToCube()), this, SIGNAL(saveToCube())); + connect(linear, SIGNAL(deleteFromCube()), this, SIGNAL(deleteFromCube())); + connect(linear, SIGNAL(loadStretch()), this, SIGNAL(loadStretch())); p_stretchTypeStack->addWidget(linear); SawtoothStretchType *sawtooth = new SawtoothStretchType(hist, curStretch, name, color); connect(sawtooth, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); + connect(sawtooth, SIGNAL(saveToCube()), this, SIGNAL(saveToCube())); + connect(sawtooth, SIGNAL(deleteFromCube()), this, SIGNAL(deleteFromCube())); + connect(sawtooth, SIGNAL(loadStretch()), this, SIGNAL(loadStretch())); p_stretchTypeStack->addWidget(sawtooth); BinaryStretchType *binary = new BinaryStretchType(hist, curStretch, name, color); connect(binary, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); + connect(binary, SIGNAL(saveToCube()), this, SIGNAL(saveToCube())); + connect(binary, SIGNAL(deleteFromCube()), this, SIGNAL(deleteFromCube())); + connect(binary, SIGNAL(loadStretch()), this, SIGNAL(loadStretch())); p_stretchTypeStack->addWidget(binary); ManualStretchType *manual = new ManualStretchType(hist, curStretch, name, color); connect(manual, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); + connect(manual, SIGNAL(saveToCube()), this, SIGNAL(saveToCube())); + connect(manual, SIGNAL(deleteFromCube()), this, SIGNAL(deleteFromCube())); + connect(manual, SIGNAL(loadStretch()), this, SIGNAL(loadStretch())); p_stretchTypeStack->addWidget(manual); layout()->addWidget(p_stretchTypeStack); @@ -76,10 +87,6 @@ namespace Isis { this, SIGNAL(stretchChanged())); } -// void AdvancedStretch::saveMe() { -// Cube* icube = ((StretchTool*)parentWidget())->cubeViewport()->cube(); -// QMessageBox::information((QWidget *)parent(), "Error", "advanced stretch"); -// } /** * Destructor @@ -121,6 +128,32 @@ namespace Isis { } + void AdvancedStretch::setStretchFromCube(Stretch newStretch, QString stretchTypeName) { + int index = 0; + if (stretchTypeName.compare("LinearStretch") == 0 ) { + index = 0; + } + else if (stretchTypeName.compare("SawtoothStretch") == 0 ) { + index = 1; + } + else if (stretchTypeName.compare("BinaryStretch") == 0) { + index = 2; + } + else if (stretchTypeName.compare("ManualStretch") == 0) { + index = 3; + } + + qDebug() << "INDEX" << index; + // never other option + + //p_stretchTypeStack->setCurrentIndex(index); + stretchTypeSelection->setCurrentIndex(index); + StretchType *stretchType = (StretchType *) + p_stretchTypeStack->currentWidget(); + stretchType->setStretch(newStretch); + } + + /** * This is called when the visible area changes, so that the * histogram can be updated. It is essential that the stretch diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h index 25f6e48a57..9c1e4ee9b8 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h @@ -4,6 +4,7 @@ #include class QStackedWidget; +class QComboBox; class QLayout; class QString; class QColor; @@ -36,6 +37,7 @@ namespace Isis { ~AdvancedStretch(); Stretch getStretch(); void setStretch(Stretch newStretch); + void setStretchFromCube(Stretch newStretch, QString stretchType); void setHistogram(const Histogram &newHist); QString getStretchType(); QString getName(); @@ -44,15 +46,12 @@ namespace Isis { //! Emitted when a new stretch is available void stretchChanged(); void saveToCube(); - -// protected slots: -// void saveMe(); - -// protected: - + void deleteFromCube(); + void loadStretch(); private: QStackedWidget *p_stretchTypeStack; //!< StretchType's + QComboBox *stretchTypeSelection; }; }; diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index c6f8772235..ad09448afd 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -130,9 +130,19 @@ namespace Isis { this, SIGNAL(stretchChanged())); connect(p_grayStretch, SIGNAL(saveToCube()), this, SIGNAL(saveToCube())); + connect(p_grayStretch, SIGNAL(deleteFromCube()), + this, SIGNAL(deleteFromCube())); + connect(p_grayStretch, SIGNAL(loadStretch()), + this, SIGNAL(loadStretch())); + + emit(stretchChanged()); } + void AdvancedStretchDialog::setStretchFromCube(Stretch stretch, QString stretchType){ + p_grayStretch->setStretchFromCube(stretch, stretchType); + } + /** * This cleans up memory from currently displayed advanced * stretches. No stretches are visible after this is called. diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index e1f5d027ac..935c5c7bb0 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -48,6 +48,7 @@ namespace Isis { Histogram &grayHist); void updateHistogram(const Histogram &grayHist); bool isRgbMode() const; + void setStretchFromCube(Stretch stretch, QString stretchType); Stretch getGrayStretch(); QString getStretchType(); @@ -80,6 +81,8 @@ namespace Isis { //! Emitted when this dialog is shown or hidden void visibilityChanged(); void saveToCube(); + void deleteFromCube(); + void loadStretch(); public slots: void updateStretch(CubeViewport *); diff --git a/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp b/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp index d3c7b7e3f5..67c30da8bf 100644 --- a/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp @@ -374,4 +374,8 @@ namespace Isis { return newStretch; } + + QString BinaryStretchType::getStretchType() { + return "BinaryStretch"; + } } diff --git a/isis/src/qisis/objs/StretchTool/BinaryStretchType.h b/isis/src/qisis/objs/StretchTool/BinaryStretchType.h index e659f9f7c5..7391480a64 100644 --- a/isis/src/qisis/objs/StretchTool/BinaryStretchType.h +++ b/isis/src/qisis/objs/StretchTool/BinaryStretchType.h @@ -35,6 +35,7 @@ namespace Isis { ~BinaryStretchType(); virtual void setStretch(Stretch); + QString getStretchType(); private slots: void startSliderMoved(int); diff --git a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp index b414695471..dc10beb6ae 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp @@ -259,13 +259,8 @@ namespace Isis { return *p_stretch; } - // work out the flow in a minute QString LinearStretchType::getStretchType() { return "LinearStretch"; } - // work out the flow in a minute -// QString LinearStretchType::getName() { -// return "UserSetName"; -// } } diff --git a/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp b/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp index 4ae247c0c5..08aae580a4 100644 --- a/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp @@ -149,4 +149,8 @@ namespace Isis { return stretch; } + + QString ManualStretchType::getStretchType() { + return "ManualStretch"; + } } diff --git a/isis/src/qisis/objs/StretchTool/ManualStretchType.h b/isis/src/qisis/objs/StretchTool/ManualStretchType.h index b7b86b967a..0dab8b0956 100644 --- a/isis/src/qisis/objs/StretchTool/ManualStretchType.h +++ b/isis/src/qisis/objs/StretchTool/ManualStretchType.h @@ -37,6 +37,7 @@ namespace Isis { ~ManualStretchType(); virtual void setStretch(Stretch); + QString getStretchType(); private slots: void addButtonPressed(bool); diff --git a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp index 5b1e46589c..16d2ba6305 100644 --- a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp @@ -308,5 +308,9 @@ namespace Isis { return calculateNewStretch(p_offsetEdit->text().toDouble(), p_widthEdit->text().toDouble()); } + + QString SawtoothStretchType::getStretchType() { + return "SawtoothStretch"; + } } diff --git a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h index 1da8bda35b..ebc8ff1028 100644 --- a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h +++ b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h @@ -38,7 +38,7 @@ namespace Isis { ~SawtoothStretchType(); virtual void setStretch(Stretch); - + QString getStretchType(); private slots: void offsetSliderMoved(int); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 68725ecfd3..ff7b194031 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -1,5 +1,7 @@ #include "StretchTool.h" +#include + #include #include #include @@ -55,6 +57,10 @@ namespace Isis { this, SLOT(updateTool())); connect(m_advancedStretch, SIGNAL(saveToCube()), this, SLOT(saveMe())); + connect(m_advancedStretch, SIGNAL(deleteFromCube()), + this, SLOT(deleteFromCube())); + connect(m_advancedStretch, SIGNAL(loadStretch()), + this, SLOT(loadStretchFromCube())); QPushButton *hiddenButton = new QPushButton(); hiddenButton->setVisible(false); @@ -374,11 +380,86 @@ namespace Isis { } } + + // ALSO HERE + void StretchTool::loadStretchFromCube(){ + bool ok; + QString text = QInputDialog::getText(m_advancedStretch, tr("Load Stretch"), + tr("Name of Stretch to Load:"), QLineEdit::Normal, + "stretch", &ok); + + MdiCubeViewport *cvp = cubeViewport(); + Cube* icube = cvp->cube(); + Pvl* lab = icube->label(); + + QString stretchType = "LinearStretch"; + PvlObject::PvlObjectIterator objIter; + for (objIter=lab->beginObject(); objIterendObject(); objIter++) { + if (objIter->name() == "Stretch") { + // needs case where there are none + PvlKeyword tempKeyword = objIter->findKeyword("Name"); + QString tempName = tempKeyword[0]; + if (tempName.compare(text) == 0) { + PvlKeyword temp2 = objIter->findKeyword("StretchType"); + QString stretchType = temp2[0]; + } + break; + } + } + + Stretch stretch(text); + icube->read(stretch); + m_advancedStretch->setStretchFromCube(stretch, stretchType); + } + + void StretchTool::deleteFromCube() { + bool ok; + QString text = QInputDialog::getText(m_advancedStretch, tr("Delete Stretch"), + tr("Name of Stretch to Delete:"), QLineEdit::Normal, + "stretch", &ok); + + if (ok) { + MdiCubeViewport *cvp = cubeViewport(); + Cube* icube = cvp->cube(); + Pvl* lab = icube->label(); + + if (icube->isReadOnly()) { + // ReOpen cube as read/write + // If cube readonly print error + try { + cvp->cube()->reopen("rw"); + } + catch(IException &) { + cvp->cube()->reopen("r"); + QMessageBox::information((QWidget *)parent(), "Error", + "Cannot open cube read/write to delete stretch"); + return; + } + } + + // need to add error-checking + bool cubeDeleted = icube->deleteBlob("Stretch", text); + + if (!cubeDeleted) { + QMessageBox msgBox; + msgBox.setText("Stretch Could Not Be Deleted!"); + msgBox.setInformativeText("A stretch with name: \"" + text + "\. Could not be found, so " + "there was nothing to delete from the Cube."); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Critical); + int ret = msgBox.exec(); + } + // Don't leave open rw -- not optimal. + cvp->cube()->reopen("r"); + } + } + + // HERE void StretchTool::saveMe() { MdiCubeViewport *cvp = cubeViewport(); Cube* icube = cvp->cube(); - //Pvl* lab = icube->label(); + Pvl* lab = icube->label(); // iterate over relevant PVL objects to make sure not taken // PvlObjectIterator object = lab-> ->findObject("LinearStretch"); @@ -388,39 +469,61 @@ namespace Isis { // can I get a list of objects and search by name??? -/* QStringList namelist; + QStringList namelist; PvlObject::PvlObjectIterator objIter; - PvlGroup fpgrp; - for (objIter=lab->beginObject(); objIter<=lab->endObject(); objIter++) { + for (objIter=lab->beginObject(); objIterendObject(); objIter++) { if (objIter->name() == "Stretch") { + // needs case where there are none PvlKeyword tempKeyword = objIter->findKeyword("Name"); -// QString tempName = tempKeyword[0]; -// namelist.append(tempName); + QString tempName = tempKeyword[0]; + namelist.append(tempName); } } - + + // DEBUG OUTPUT + QString testme = ""; + + for (int i=0; ihasObject(text)) { - name = text; + "stretch", &ok); + + // Stretch Name Already Exists Dialog! + if (namelist.contains(text)) { + QMessageBox msgBox; + msgBox.setText("Stretch Name Already Exists!"); + msgBox.setInformativeText("A stretch pair with name: \"" + text + "\" already exists and the existing saved data will be overwritten. Are you sure you wish to proceed?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setDefaultButton(QMessageBox::Cancel); + int ret = msgBox.exec(); + + switch (ret) { + case QMessageBox::Save: + break; + case QMessageBox::Cancel: + // Cancel was clicked + return; + break; + default: + // should never be reached + break; } - else { - QString text = QInputDialog::getText(m_advancedStretch, tr("Save Stretch"), - tr("Name of Stretch Pair not already selected:"), QLineEdit::Normal, - text, &ok); - }*/ + } - Stretch stretch = m_advancedStretch->getGrayStretch(); - QString stretchType = m_advancedStretch->getStretchType(); - QString name = "foxtail_fern"; + // actually needs YES/NO + // NO - close this dialog and other dialog, do nothing + // YES - saved stretch pair to cube! - // If cube readonly print error if (icube->isReadOnly()) { // ReOpen cube as read/write // If cube readonly print error @@ -434,10 +537,13 @@ namespace Isis { } } - // how to get name and stretchtype from AdvancedStretchTool? - Blob blob(name, stretchType); -// stretch.Text()); <-- contents - icube->write(blob); + Stretch stretch = m_advancedStretch->getGrayStretch(); + QString stretchType = m_advancedStretch->getStretchType(); + + stretch.Label()["Name"] = text; + stretch.Label() += PvlKeyword("StretchType", stretchType); + + icube->write(stretch); // Don't leave open rw -- not optimal. cvp->cube()->reopen("r"); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.h b/isis/src/qisis/objs/StretchTool/StretchTool.h index df7263370b..78f447e4d1 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.h +++ b/isis/src/qisis/objs/StretchTool/StretchTool.h @@ -172,6 +172,8 @@ namespace Isis { protected slots: void mouseButtonRelease(QPoint p, Qt::MouseButton s); void saveMe(); + void deleteFromCube(); + void loadStretchFromCube(); void enableRubberBandTool(); void screenPixelsChanged(); void updateHistograms(); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index e5b4e0e80e..67a0c0779f 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -61,11 +61,20 @@ namespace Isis { connect(saveAsButton, SIGNAL(clicked(bool)), this, SLOT(savePairs())); p_mainLayout->addWidget(saveAsButton, 3, 0); + QPushButton *loadStretchButton = new QPushButton("Load Saved Stretch From Cube"); + connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); +// connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SLOT(promptName())); + p_mainLayout->addWidget(loadStretchButton, 6, 0); + QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube!"); connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); // connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SLOT(promptName())); p_mainLayout->addWidget(saveToCubeButton, 4, 0); + QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube!"); + connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); + p_mainLayout->addWidget(deleteFromCubeButton, 5, 0); + QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); sizePolicy.setHeightForWidth(true); p_graph->setSizePolicy(sizePolicy); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.h b/isis/src/qisis/objs/StretchTool/StretchType.h index 4baeec338e..5433b3b3a5 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.h +++ b/isis/src/qisis/objs/StretchTool/StretchType.h @@ -77,7 +77,9 @@ namespace Isis { signals: //! Emitted when a new Stretch object is available void saveToCube(); + void deleteFromCube(); void stretchChanged(); + void loadStretch(); private slots: void savePairs(); From 91314ebf4dac9be107d86964ca5f289ab52ebab5 Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 27 Feb 2020 20:18:37 -0700 Subject: [PATCH 05/14] Clean up Stretch class --- isis/src/base/objs/Stretch/Stretch.cpp | 74 +++++++++++++++----------- isis/src/base/objs/Stretch/Stretch.h | 7 +-- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/isis/src/base/objs/Stretch/Stretch.cpp b/isis/src/base/objs/Stretch/Stretch.cpp index 076173737f..2c4a830733 100644 --- a/isis/src/base/objs/Stretch/Stretch.cpp +++ b/isis/src/base/objs/Stretch/Stretch.cpp @@ -47,9 +47,16 @@ namespace Isis { p_minimum = p_lrs; p_maximum = p_hrs; p_pairs = 0; - p_type = "none"; + p_type = "None"; } + + /** + * Constructs a Stretch object with default mapping of special pixel values to + * themselves and a provided name. + * + * @param name Name to use for Stretch + */ Stretch::Stretch(QString name) : Blob(name, "Stretch") { p_null = Isis::NULL8; p_lis = Isis::LOW_INSTR_SAT8; @@ -59,9 +66,10 @@ namespace Isis { p_minimum = p_lrs; p_maximum = p_hrs; p_pairs = 0; - p_type = "none"; + p_type = "None"; } + /** * Adds a stretch pair to the list of pairs. Note that all input pairs must be * in ascending order. @@ -424,7 +432,19 @@ namespace Isis { } + /** + * Read saved Stretch data from a Cube into this object. + * + * This is called by Blob::Read() and is the actual data reading function + * ultimately called when running something like cube->read(stretch); + * + * @param is input stream containing the saved Stretch information + */ void Stretch::ReadData(std::istream &is) { + // Set the Stretch Type + p_type = p_blobPvl["StretchType"][0]; + + // Read in the Stretch Pairs streampos sbyte = p_startByte - 1; is.seekg(sbyte, std::ios::beg); if (!is.good()) { @@ -438,9 +458,10 @@ namespace Isis { is.read(buf, p_nbytes); - string temp(buf); - QString tempFriend = QString::fromStdString(temp); - Parse(tempFriend); + // Read buffer data into a QString so we can call Parse() + string stringFromBuffer(buf); + QString qStringFromBuffer = QString::fromStdString(stringfromBuffer); + Parse(qStringFromBuffer); delete [] buf; @@ -449,45 +470,36 @@ namespace Isis { p_blobName + "]"; throw IException(IException::Io, msg, _FILEINFO_); } - - p_type = p_blobPvl["StretchType"][0]; } + + /** + * Get the Type of Stretch. This is only used by the AdvancedStretchTool. + * + * @return QString Type of Stretch. + */ QString Stretch::getType(){ return p_type; } -// void Stretch::ReadInit() { -// p_nbytes = Text().toStdString().size(); -// } - //! Initializes for writing polygon to cube blob + /** + * Initializes for writing stretch to cube blob + */ void Stretch::WriteInit() { -/* geos::io::WKTWriter *wkt = new geos::io::WKTWriter(); - - // Check to see p_polygons is valid data - if (!p_polygons) { - string msg = "Cannot write a NULL polygon!"; - throw IException(IException::Programmer, msg, _FILEINFO_); - } - p_polyStr = wkt->write(p_polygons); - p_nbytes = p_polyStr.size(); - - delete wkt;*/ p_nbytes = Text().toStdString().size(); } + /** + * Writes the stretch information to a cube. + * + * This is called by Blob::write() and is ultimately the function + * called when running something like cube->write(stretch); + * + * @param os output stream to write the stretch data to. + */ void Stretch::WriteData(std::fstream &os) { - // std::string temp( -// QString temp("Legolas Greenleaf, long under tree..."); -// os.write(Text().toStdString().c_str(), Text().toStdString().size()); - // qDebug() << temp; - // qDebug() << temp.toStdString().size(); - - // QByteArray fred = temp.toUtf8(); -// os.write(temp.toStdString().c_str(), temp.size()); -// os.write(fred.data(), fred.size()); os.write(Text().toStdString().c_str(), p_nbytes); } diff --git a/isis/src/base/objs/Stretch/Stretch.h b/isis/src/base/objs/Stretch/Stretch.h index 34fd415708..b7179c5ba1 100644 --- a/isis/src/base/objs/Stretch/Stretch.h +++ b/isis/src/base/objs/Stretch/Stretch.h @@ -68,7 +68,8 @@ namespace Isis { * Created second Parse method for handling pairs where the * input side is a perentage. Fixed Input and Output getters * to check both sides of boundry condition for valid data - * + * @history 2020-02-27 Kristin Berry - Updated to inherit from Blob so Stretches can be + * saved and restored from cubes. */ class Stretch : public Isis::Blob { private: @@ -89,7 +90,7 @@ namespace Isis { double p_minimum; //! NextPair(QString &pairs); @@ -195,8 +196,8 @@ namespace Isis { void CopyPairs(const Stretch &other); protected: - void ReadData(std::istream &is); void WriteInit(); + void ReadData(std::istream &is); void WriteData(std::fstream &os); }; }; From 143dc951d92cf5dcdb9d40f97427f4439ffaff78 Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 27 Feb 2020 20:41:24 -0700 Subject: [PATCH 06/14] Completely move stretchTypes into stretch class, and some minor cleanup --- isis/src/base/objs/Stretch/Stretch.cpp | 15 ++++++++-- isis/src/base/objs/Stretch/Stretch.h | 2 ++ .../objs/StretchTool/BinaryStretchType.cpp | 6 ++-- .../objs/StretchTool/BinaryStretchType.h | 1 - .../objs/StretchTool/LinearStretchType.cpp | 6 +--- .../objs/StretchTool/LinearStretchType.h | 1 - .../objs/StretchTool/ManualStretchType.cpp | 6 ++-- .../objs/StretchTool/ManualStretchType.h | 1 - .../objs/StretchTool/SawtoothStretchType.cpp | 6 ++-- .../objs/StretchTool/SawtoothStretchType.h | 1 - .../qisis/objs/StretchTool/StretchTool.cpp | 2 +- .../qisis/objs/StretchTool/StretchType.cpp | 29 ++++--------------- isis/src/qisis/objs/StretchTool/StretchType.h | 2 -- 13 files changed, 29 insertions(+), 49 deletions(-) diff --git a/isis/src/base/objs/Stretch/Stretch.cpp b/isis/src/base/objs/Stretch/Stretch.cpp index 2c4a830733..e3d8401c7c 100644 --- a/isis/src/base/objs/Stretch/Stretch.cpp +++ b/isis/src/base/objs/Stretch/Stretch.cpp @@ -459,8 +459,8 @@ namespace Isis { is.read(buf, p_nbytes); // Read buffer data into a QString so we can call Parse() - string stringFromBuffer(buf); - QString qStringFromBuffer = QString::fromStdString(stringfromBuffer); + std::string stringFromBuffer(buf); + QString qStringFromBuffer = QString::fromStdString(stringFromBuffer); Parse(qStringFromBuffer); delete [] buf; @@ -483,6 +483,17 @@ namespace Isis { } + /** + * Set the Type of Stretch. This is only used by the AdvancedStretchTool. + * + * @param stretchType The type of stretch. + */ + void Stretch::setType(QString stretchType){ + // check to see if valid input + p_type = stretchType; + } + + /** * Initializes for writing stretch to cube blob */ diff --git a/isis/src/base/objs/Stretch/Stretch.h b/isis/src/base/objs/Stretch/Stretch.h index b7179c5ba1..5da48bbe74 100644 --- a/isis/src/base/objs/Stretch/Stretch.h +++ b/isis/src/base/objs/Stretch/Stretch.h @@ -183,6 +183,8 @@ namespace Isis { }; QString getType(); + void setType(QString type); + double Input(const int index) const; double Output(const int index) const; diff --git a/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp b/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp index 67c30da8bf..2e67c7011e 100644 --- a/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp @@ -73,6 +73,8 @@ namespace Isis { sliderWidget->setLayout(sliderLayout); p_mainLayout->addWidget(sliderWidget, 1, 0); + p_stretch->setType("BinaryStretch"); + setLayout(p_mainLayout); setStretch(calculateNewStretch()); } @@ -374,8 +376,4 @@ namespace Isis { return newStretch; } - - QString BinaryStretchType::getStretchType() { - return "BinaryStretch"; - } } diff --git a/isis/src/qisis/objs/StretchTool/BinaryStretchType.h b/isis/src/qisis/objs/StretchTool/BinaryStretchType.h index 7391480a64..e659f9f7c5 100644 --- a/isis/src/qisis/objs/StretchTool/BinaryStretchType.h +++ b/isis/src/qisis/objs/StretchTool/BinaryStretchType.h @@ -35,7 +35,6 @@ namespace Isis { ~BinaryStretchType(); virtual void setStretch(Stretch); - QString getStretchType(); private slots: void startSliderMoved(int); diff --git a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp index dc10beb6ae..66953c5320 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp @@ -71,6 +71,7 @@ namespace Isis { sliderWidget->setLayout(sliderLayout); p_mainLayout->addWidget(sliderWidget, 1, 0); + p_stretch->setType("LinearStretch"); setLayout(p_mainLayout); setStretch(stretch); @@ -254,13 +255,8 @@ namespace Isis { } } - Stretch LinearStretchType::getStretch() { return *p_stretch; } - QString LinearStretchType::getStretchType() { - return "LinearStretch"; - } - } diff --git a/isis/src/qisis/objs/StretchTool/LinearStretchType.h b/isis/src/qisis/objs/StretchTool/LinearStretchType.h index c07a0c5d40..b41d46b8ef 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.h +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.h @@ -34,7 +34,6 @@ namespace Isis { ~LinearStretchType(); virtual Stretch getStretch(); - virtual QString getStretchType(); virtual void setStretch(Stretch); private slots: diff --git a/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp b/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp index 08aae580a4..2c8d20f697 100644 --- a/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp @@ -55,6 +55,8 @@ namespace Isis { this, SLOT(readTable())); disconnect(this, SIGNAL(stretchChanged()), this, SLOT(updateTable())); + p_stretch->setType("ManualStretch"); + setLayout(p_mainLayout); setStretch(stretch); } @@ -149,8 +151,4 @@ namespace Isis { return stretch; } - - QString ManualStretchType::getStretchType() { - return "ManualStretch"; - } } diff --git a/isis/src/qisis/objs/StretchTool/ManualStretchType.h b/isis/src/qisis/objs/StretchTool/ManualStretchType.h index 0dab8b0956..b7b86b967a 100644 --- a/isis/src/qisis/objs/StretchTool/ManualStretchType.h +++ b/isis/src/qisis/objs/StretchTool/ManualStretchType.h @@ -37,7 +37,6 @@ namespace Isis { ~ManualStretchType(); virtual void setStretch(Stretch); - QString getStretchType(); private slots: void addButtonPressed(bool); diff --git a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp index 16d2ba6305..2e97c93ed1 100644 --- a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp @@ -71,6 +71,8 @@ namespace Isis { sliderWidget->setLayout(sliderLayout); p_mainLayout->addWidget(sliderWidget, 1, 0); + p_stretch->setType("SawtoothStretch"); + setLayout(p_mainLayout); p_widthEdit->setText(QString::number( @@ -308,9 +310,5 @@ namespace Isis { return calculateNewStretch(p_offsetEdit->text().toDouble(), p_widthEdit->text().toDouble()); } - - QString SawtoothStretchType::getStretchType() { - return "SawtoothStretch"; - } } diff --git a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h index ebc8ff1028..7801f8b114 100644 --- a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h +++ b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h @@ -38,7 +38,6 @@ namespace Isis { ~SawtoothStretchType(); virtual void setStretch(Stretch); - QString getStretchType(); private slots: void offsetSliderMoved(int); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index ff7b194031..bc41883b54 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -541,7 +541,7 @@ namespace Isis { QString stretchType = m_advancedStretch->getStretchType(); stretch.Label()["Name"] = text; - stretch.Label() += PvlKeyword("StretchType", stretchType); + stretch.Label() += PvlKeyword("StretchType", stretch.getType()); icube->write(stretch); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index 67a0c0779f..8b75e50b44 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -61,20 +61,18 @@ namespace Isis { connect(saveAsButton, SIGNAL(clicked(bool)), this, SLOT(savePairs())); p_mainLayout->addWidget(saveAsButton, 3, 0); - QPushButton *loadStretchButton = new QPushButton("Load Saved Stretch From Cube"); - connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); -// connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SLOT(promptName())); - p_mainLayout->addWidget(loadStretchButton, 6, 0); - - QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube!"); + QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube..."); connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); -// connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SLOT(promptName())); p_mainLayout->addWidget(saveToCubeButton, 4, 0); - QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube!"); + QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube..."); connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); p_mainLayout->addWidget(deleteFromCubeButton, 5, 0); + QPushButton *loadStretchButton = new QPushButton("Load Saved Stretch from Cube..."); + connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); + p_mainLayout->addWidget(loadStretchButton, 6, 0); + QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); sizePolicy.setHeightForWidth(true); p_graph->setSizePolicy(sizePolicy); @@ -191,21 +189,6 @@ namespace Isis { } - void StretchType::promptName() { -// bool ok; -// QString text = QInputDialog::getText(this, tr("Save Stretch"), -// tr("Name of Stretch Pair:"), QLineEdit::Normal, -// "stretch", &ok); -// if (ok && !text.isEmpty()) { -// p_name = text; -// } - - // warn if a stretch of the same name already exists and that it will be over-written - QString nothing("nothing"); -// emit saveToCube(); - } - - /** * Returns the current stretch object * diff --git a/isis/src/qisis/objs/StretchTool/StretchType.h b/isis/src/qisis/objs/StretchTool/StretchType.h index 5433b3b3a5..4e6ceea719 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.h +++ b/isis/src/qisis/objs/StretchTool/StretchType.h @@ -45,8 +45,6 @@ namespace Isis { virtual ~StretchType(); virtual Stretch getStretch(); - virtual QString getStretchType() { return "unknown";}; // change to pure virutal - virtual QString getName() { return p_name;}; // change to pure virutal?? /** * Children must re-implement this to update their stretch pairs and GUI From b73939728fa782542daa00fdb97846df1f5ac01b Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 27 Feb 2020 20:52:02 -0700 Subject: [PATCH 07/14] Fixed combo-box not updating bug and more cleanup --- .../objs/StretchTool/AdvancedStretch.cpp | 9 +--- .../qisis/objs/StretchTool/AdvancedStretch.h | 2 - .../StretchTool/AdvancedStretchDialog.cpp | 9 ---- .../objs/StretchTool/AdvancedStretchDialog.h | 2 - .../qisis/objs/StretchTool/StretchTool.cpp | 45 ++++++++++--------- isis/src/qisis/objs/StretchTool/StretchType.h | 1 - 6 files changed, 24 insertions(+), 44 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index 89f091662d..47b3389f7e 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -104,14 +104,6 @@ namespace Isis { return ((StretchType *)p_stretchTypeStack->currentWidget())->getStretch(); } - // This seems like a bad idea? (if keep, can eliminate at the StretchType level? In theory???? - QString AdvancedStretch::getStretchType() { - return ((StretchType *)p_stretchTypeStack->currentWidget())->getStretchType(); - } - - QString AdvancedStretch::getName() { - return ((StretchType *)p_stretchTypeStack->currentWidget())->getName(); - } /** * This is called when the user creates a stretch outside of the @@ -143,6 +135,7 @@ namespace Isis { index = 3; } + qDebug() << "stretchTypeName" << stretchTypeName; qDebug() << "INDEX" << index; // never other option diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h index 9c1e4ee9b8..d9fe543299 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h @@ -39,8 +39,6 @@ namespace Isis { void setStretch(Stretch newStretch); void setStretchFromCube(Stretch newStretch, QString stretchType); void setHistogram(const Histogram &newHist); - QString getStretchType(); - QString getName(); signals: //! Emitted when a new stretch is available diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index ad09448afd..6ca5613e38 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -289,15 +289,6 @@ namespace Isis { } - // also bad idea? /// THIS IS OF TYPE AdvancedStretch, so ... something. need to draw out. - QString AdvancedStretchDialog::getStretchType() { - return p_grayStretch->getStretchType(); - } - - QString AdvancedStretchDialog::getName() { - return p_grayStretch->getName(); - } - /** * This returns the advanced stretch's stretch for red. * diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index 935c5c7bb0..d7881e63fa 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -51,8 +51,6 @@ namespace Isis { void setStretchFromCube(Stretch stretch, QString stretchType); Stretch getGrayStretch(); - QString getStretchType(); - QString getName(); Stretch getRedStretch(); Stretch getGrnStretch(); Stretch getBluStretch(); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index bc41883b54..a0781db7d1 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -387,29 +387,30 @@ namespace Isis { QString text = QInputDialog::getText(m_advancedStretch, tr("Load Stretch"), tr("Name of Stretch to Load:"), QLineEdit::Normal, "stretch", &ok); - - MdiCubeViewport *cvp = cubeViewport(); - Cube* icube = cvp->cube(); - Pvl* lab = icube->label(); - - QString stretchType = "LinearStretch"; - PvlObject::PvlObjectIterator objIter; - for (objIter=lab->beginObject(); objIterendObject(); objIter++) { - if (objIter->name() == "Stretch") { - // needs case where there are none - PvlKeyword tempKeyword = objIter->findKeyword("Name"); - QString tempName = tempKeyword[0]; - if (tempName.compare(text) == 0) { - PvlKeyword temp2 = objIter->findKeyword("StretchType"); - QString stretchType = temp2[0]; + if (ok) { + MdiCubeViewport *cvp = cubeViewport(); + Cube* icube = cvp->cube(); + Pvl* lab = icube->label(); + +/* QString stretchType = "LinearStretch"; // default if setting fails + + PvlObject::PvlObjectIterator objIter; + for (objIter=lab->beginObject(); objIterendObject(); objIter++) { + if (objIter->name() == "Stretch") { + PvlKeyword tempKeyword = objIter->findKeyword("Name"); + QString tempName = tempKeyword[0]; +// if (tempName.compare(text) == 0) { +// PvlKeyword temp2 = objIter->findKeyword("StretchType"); +// stretchType = temp2[0]; + } + break; } - break; - } - } + }*/ - Stretch stretch(text); - icube->read(stretch); - m_advancedStretch->setStretchFromCube(stretch, stretchType); + Stretch stretch(text); + icube->read(stretch); + m_advancedStretch->setStretchFromCube(stretch, stretch.getType()); + } } void StretchTool::deleteFromCube() { @@ -538,7 +539,7 @@ namespace Isis { } Stretch stretch = m_advancedStretch->getGrayStretch(); - QString stretchType = m_advancedStretch->getStretchType(); +// QString stretchType = m_advancedStretch->getStretchType(); stretch.Label()["Name"] = text; stretch.Label() += PvlKeyword("StretchType", stretch.getType()); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.h b/isis/src/qisis/objs/StretchTool/StretchType.h index 4e6ceea719..f3511f8d90 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.h +++ b/isis/src/qisis/objs/StretchTool/StretchType.h @@ -62,7 +62,6 @@ namespace Isis { protected slots: void updateGraph(); void updateTable(); - void promptName(); protected: // data QGridLayout *p_mainLayout; //!< Main layout From ad7dc7bd9121b5e9e9d0a87f24650896dec37e4d Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 27 Feb 2020 21:16:01 -0700 Subject: [PATCH 08/14] Further cleanup of propagated earlier changes with types and names being removed from unnecessary classes --- .../objs/StretchTool/AdvancedStretch.cpp | 38 +++++++------ .../qisis/objs/StretchTool/AdvancedStretch.h | 4 +- .../StretchTool/AdvancedStretchDialog.cpp | 10 +++- .../objs/StretchTool/AdvancedStretchDialog.h | 2 +- .../qisis/objs/StretchTool/StretchTool.cpp | 57 +++++++------------ 5 files changed, 53 insertions(+), 58 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index 47b3389f7e..5b4803ab3e 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -8,7 +8,6 @@ #include #include "Stretch.h" -#include "StretchTool.h" #include "IString.h" #include "IException.h" #include "StretchType.h" @@ -37,14 +36,13 @@ namespace Isis { typeSelectionArea->setLayout(new QHBoxLayout()); typeSelectionArea->layout()->addWidget(new QLabel("Stretch Type")); -// QComboBox *stretchTypeSelection = new QComboBox(); - stretchTypeSelection = new QComboBox(); - stretchTypeSelection->addItem("Linear", 0); - stretchTypeSelection->addItem("Sawtooth", 1); - stretchTypeSelection->addItem("Binary", 2); - stretchTypeSelection->addItem("Manual", 3); + p_stretchTypeSelection = new QComboBox(); + p_stretchTypeSelection->addItem("Linear", 0); + p_stretchTypeSelection->addItem("Sawtooth", 1); + p_stretchTypeSelection->addItem("Binary", 2); + p_stretchTypeSelection->addItem("Manual", 3); - typeSelectionArea->layout()->addWidget(stretchTypeSelection); + typeSelectionArea->layout()->addWidget(p_stretchTypeSelection); layout()->addWidget(typeSelectionArea); p_stretchTypeStack = new QStackedWidget(); @@ -81,9 +79,9 @@ namespace Isis { p_stretchTypeStack->addWidget(manual); layout()->addWidget(p_stretchTypeStack); - connect(stretchTypeSelection, SIGNAL(currentIndexChanged(int)), + connect(p_stretchTypeSelection, SIGNAL(currentIndexChanged(int)), p_stretchTypeStack, SLOT(setCurrentIndex(int))); - connect(stretchTypeSelection, SIGNAL(currentIndexChanged(int)), + connect(p_stretchTypeSelection, SIGNAL(currentIndexChanged(int)), this, SIGNAL(stretchChanged())); } @@ -120,7 +118,16 @@ namespace Isis { } - void AdvancedStretch::setStretchFromCube(Stretch newStretch, QString stretchTypeName) { + /** + * Used to restore a saved Stretch from a cube. This function is + * distinct from setStretch in that setStretch delibrately _does not_ + * change the stretch type, and this function does change the stretch type. + * + * @param newStretch saved stretch to restore + */ + void AdvancedStretch::setStretchFromCube(Stretch newStretch) { + QString stretchTypeName = newStretch.getType(); + int index = 0; if (stretchTypeName.compare("LinearStretch") == 0 ) { index = 0; @@ -134,13 +141,12 @@ namespace Isis { else if (stretchTypeName.compare("ManualStretch") == 0) { index = 3; } + // Fail by defaulting to Linear + - qDebug() << "stretchTypeName" << stretchTypeName; - qDebug() << "INDEX" << index; - // never other option +// p_stretchTypeStack->setCurrentIndex(index); <- does not work. - //p_stretchTypeStack->setCurrentIndex(index); - stretchTypeSelection->setCurrentIndex(index); + p_stretchTypeSelection->setCurrentIndex(index); StretchType *stretchType = (StretchType *) p_stretchTypeStack->currentWidget(); stretchType->setStretch(newStretch); diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h index d9fe543299..1b19d711da 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h @@ -37,7 +37,7 @@ namespace Isis { ~AdvancedStretch(); Stretch getStretch(); void setStretch(Stretch newStretch); - void setStretchFromCube(Stretch newStretch, QString stretchType); + void setStretchFromCube(Stretch newStretch); void setHistogram(const Histogram &newHist); signals: @@ -49,7 +49,7 @@ namespace Isis { private: QStackedWidget *p_stretchTypeStack; //!< StretchType's - QComboBox *stretchTypeSelection; + QComboBox *p_stretchTypeSelection; //!< ComboBox of StretchTypes }; }; diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index 6ca5613e38..3a208efbf0 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -139,10 +139,16 @@ namespace Isis { } - void AdvancedStretchDialog::setStretchFromCube(Stretch stretch, QString stretchType){ - p_grayStretch->setStretchFromCube(stretch, stretchType); + /** + * Restores a saved stretch from the cube + * + * @param stretch + */ + void AdvancedStretchDialog::setStretchFromCube(Stretch stretch){ + p_grayStretch->setStretchFromCube(stretch); } + /** * This cleans up memory from currently displayed advanced * stretches. No stretches are visible after this is called. diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index d7881e63fa..fcf4c620e0 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -48,7 +48,7 @@ namespace Isis { Histogram &grayHist); void updateHistogram(const Histogram &grayHist); bool isRgbMode() const; - void setStretchFromCube(Stretch stretch, QString stretchType); + void setStretchFromCube(Stretch stretch); Stretch getGrayStretch(); Stretch getRedStretch(); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index a0781db7d1..c551656d91 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -381,41 +381,32 @@ namespace Isis { } - // ALSO HERE + /** + * Restores a saved stretch from the cube + */ void StretchTool::loadStretchFromCube(){ bool ok; - QString text = QInputDialog::getText(m_advancedStretch, tr("Load Stretch"), - tr("Name of Stretch to Load:"), QLineEdit::Normal, - "stretch", &ok); + QString stretchName = QInputDialog::getText(m_advancedStretch, tr("Load Stretch"), + tr("Name of Stretch to Load:"), QLineEdit::Normal, + "stretch", &ok); if (ok) { MdiCubeViewport *cvp = cubeViewport(); Cube* icube = cvp->cube(); Pvl* lab = icube->label(); -/* QString stretchType = "LinearStretch"; // default if setting fails - - PvlObject::PvlObjectIterator objIter; - for (objIter=lab->beginObject(); objIterendObject(); objIter++) { - if (objIter->name() == "Stretch") { - PvlKeyword tempKeyword = objIter->findKeyword("Name"); - QString tempName = tempKeyword[0]; -// if (tempName.compare(text) == 0) { -// PvlKeyword temp2 = objIter->findKeyword("StretchType"); -// stretchType = temp2[0]; - } - break; - } - }*/ - - Stretch stretch(text); + Stretch stretch(stretchName); icube->read(stretch); - m_advancedStretch->setStretchFromCube(stretch, stretch.getType()); + m_advancedStretch->setStretchFromCube(stretch); } } + + /** + * Deletes a saved stretch from the cube + */ void StretchTool::deleteFromCube() { bool ok; - QString text = QInputDialog::getText(m_advancedStretch, tr("Delete Stretch"), + QString toDelete = QInputDialog::getText(m_advancedStretch, tr("Delete Stretch"), tr("Name of Stretch to Delete:"), QLineEdit::Normal, "stretch", &ok); @@ -425,8 +416,6 @@ namespace Isis { Pvl* lab = icube->label(); if (icube->isReadOnly()) { - // ReOpen cube as read/write - // If cube readonly print error try { cvp->cube()->reopen("rw"); } @@ -438,38 +427,32 @@ namespace Isis { } } - // need to add error-checking - bool cubeDeleted = icube->deleteBlob("Stretch", text); + bool cubeDeleted = icube->deleteBlob("Stretch", toDelete); if (!cubeDeleted) { QMessageBox msgBox; msgBox.setText("Stretch Could Not Be Deleted!"); - msgBox.setInformativeText("A stretch with name: \"" + text + "\. Could not be found, so " - "there was nothing to delete from the Cube."); + msgBox.setInformativeText("A stretch with name: \"" + toDelete + "\. Could not be found, so " + "there was nothing to delete from the Cube."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setIcon(QMessageBox::Critical); int ret = msgBox.exec(); } + // Don't leave open rw -- not optimal. cvp->cube()->reopen("r"); } } -// HERE + /** + * Saves a strech to the cube. + */ void StretchTool::saveMe() { MdiCubeViewport *cvp = cubeViewport(); Cube* icube = cvp->cube(); Pvl* lab = icube->label(); - // iterate over relevant PVL objects to make sure not taken - // PvlObjectIterator object = lab-> ->findObject("LinearStretch"); - - //PvlObject object = lab->findObject("LinearStretch"); -// PvlKeyword currentName = object.findKeyword("Name"); - - // can I get a list of objects and search by name??? - QStringList namelist; PvlObject::PvlObjectIterator objIter; From e5c8a7dfc4672e71f4c66bcc032dc3f7396f93f4 Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 27 Feb 2020 21:20:01 -0700 Subject: [PATCH 09/14] Removed added unneeded member variables from StretchType --- isis/src/qisis/objs/StretchTool/StretchType.cpp | 3 +-- isis/src/qisis/objs/StretchTool/StretchType.h | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index 8b75e50b44..fbc5141f25 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -36,7 +36,6 @@ namespace Isis { p_cubeHist = NULL; p_graph = NULL; p_mainLayout = NULL; - p_name = "no name"; p_cubeHist = new Histogram(hist); @@ -57,7 +56,7 @@ namespace Isis { connect(this, SIGNAL(stretchChanged()), this, SLOT(updateTable())); p_mainLayout->addWidget(p_table, 2, 0); - QPushButton *saveAsButton = new QPushButton("Save Stretch Pairs..."); + QPushButton *saveAsButton = new QPushButton("Save Stretch Pairs to File..."); connect(saveAsButton, SIGNAL(clicked(bool)), this, SLOT(savePairs())); p_mainLayout->addWidget(saveAsButton, 3, 0); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.h b/isis/src/qisis/objs/StretchTool/StretchType.h index f3511f8d90..d54979dfa5 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.h +++ b/isis/src/qisis/objs/StretchTool/StretchType.h @@ -81,9 +81,6 @@ namespace Isis { private slots: void savePairs(); - private: - QString p_name; - }; }; From 1f00cfa3c757d3ee202351926925a84748c58cf3 Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 27 Feb 2020 21:31:30 -0700 Subject: [PATCH 10/14] Cleanup StretchTool class --- .../StretchTool/AdvancedStretchDialog.cpp | 2 - .../qisis/objs/StretchTool/StretchTool.cpp | 105 +++++++++--------- isis/src/qisis/objs/StretchTool/StretchTool.h | 2 +- .../qisis/objs/StretchTool/StretchType.cpp | 1 - 4 files changed, 51 insertions(+), 59 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index 3a208efbf0..be93ad2879 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -134,8 +134,6 @@ namespace Isis { this, SIGNAL(deleteFromCube())); connect(p_grayStretch, SIGNAL(loadStretch()), this, SIGNAL(loadStretch())); - - emit(stretchChanged()); } diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index c551656d91..d4b5cd34c9 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -56,7 +56,7 @@ namespace Isis { connect(m_advancedStretch, SIGNAL(visibilityChanged()), this, SLOT(updateTool())); connect(m_advancedStretch, SIGNAL(saveToCube()), - this, SLOT(saveMe())); + this, SLOT(saveStretchToCube())); connect(m_advancedStretch, SIGNAL(deleteFromCube()), this, SLOT(deleteFromCube())); connect(m_advancedStretch, SIGNAL(loadStretch()), @@ -392,7 +392,6 @@ namespace Isis { if (ok) { MdiCubeViewport *cvp = cubeViewport(); Cube* icube = cvp->cube(); - Pvl* lab = icube->label(); Stretch stretch(stretchName); icube->read(stretch); @@ -413,7 +412,6 @@ namespace Isis { if (ok) { MdiCubeViewport *cvp = cubeViewport(); Cube* icube = cvp->cube(); - Pvl* lab = icube->label(); if (icube->isReadOnly()) { try { @@ -448,17 +446,16 @@ namespace Isis { /** * Saves a strech to the cube. */ - void StretchTool::saveMe() { + void StretchTool::saveStretchToCube() { MdiCubeViewport *cvp = cubeViewport(); Cube* icube = cvp->cube(); Pvl* lab = icube->label(); + // Create a list of existing Stretch names QStringList namelist; - PvlObject::PvlObjectIterator objIter; for (objIter=lab->beginObject(); objIterendObject(); objIter++) { if (objIter->name() == "Stretch") { - // needs case where there are none PvlKeyword tempKeyword = objIter->findKeyword("Name"); QString tempName = tempKeyword[0]; namelist.append(tempName); @@ -467,72 +464,70 @@ namespace Isis { // DEBUG OUTPUT - QString testme = ""; - - for (int i=0; iisReadOnly()) { - // ReOpen cube as read/write - // If cube readonly print error - try { - cvp->cube()->reopen("rw"); - } - catch(IException &) { - cvp->cube()->reopen("r"); - QMessageBox::information((QWidget *)parent(), "Error", "Cannot open cube read/write to save stretch"); + switch (ret) { + case QMessageBox::Save: + break; + case QMessageBox::Cancel: + // Cancel was clicked, exist this function return; + break; + default: + // should never be reached + break; + } + } + + if (icube->isReadOnly()) { + // ReOpen cube as read/write + // If cube readonly print error + try { + cvp->cube()->reopen("rw"); + } + catch(IException &) { + cvp->cube()->reopen("r"); + QMessageBox::information((QWidget *)parent(), "Error", "Cannot open cube read/write to save stretch"); + return; + } } - } - Stretch stretch = m_advancedStretch->getGrayStretch(); -// QString stretchType = m_advancedStretch->getStretchType(); + Stretch stretch = m_advancedStretch->getGrayStretch(); - stretch.Label()["Name"] = text; - stretch.Label() += PvlKeyword("StretchType", stretch.getType()); + // consider moving into Stretch::WriteInit() + stretch.Label()["Name"] = text; + stretch.Label() += PvlKeyword("StretchType", stretch.getType()); - icube->write(stretch); + icube->write(stretch); - // Don't leave open rw -- not optimal. - cvp->cube()->reopen("r"); + // Don't leave open rw -- not optimal. + cvp->cube()->reopen("r"); + } } + /** * This is called when the visible area changes. */ diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.h b/isis/src/qisis/objs/StretchTool/StretchTool.h index 78f447e4d1..13a5e938ec 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.h +++ b/isis/src/qisis/objs/StretchTool/StretchTool.h @@ -171,7 +171,7 @@ namespace Isis { protected slots: void mouseButtonRelease(QPoint p, Qt::MouseButton s); - void saveMe(); + void saveStretchToCube(); void deleteFromCube(); void loadStretchFromCube(); void enableRubberBandTool(); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index fbc5141f25..f02ae523ac 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include "Stretch.h" #include "Histogram.h" From 1a92f553834e127b473311665c3ff7fecdff97d9 Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 28 Feb 2020 07:55:00 -0700 Subject: [PATCH 11/14] Update enter-text dialogs to drop down selection options --- .../qisis/objs/StretchTool/StretchTool.cpp | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index d4b5cd34c9..b5e8424935 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -385,14 +385,27 @@ namespace Isis { * Restores a saved stretch from the cube */ void StretchTool::loadStretchFromCube(){ + MdiCubeViewport *cvp = cubeViewport(); + Cube* icube = cvp->cube(); + Pvl* lab = icube->label(); + + // Create a list of existing Stretch names + QStringList namelist; + PvlObject::PvlObjectIterator objIter; + for (objIter=lab->beginObject(); objIterendObject(); objIter++) { + if (objIter->name() == "Stretch") { + PvlKeyword tempKeyword = objIter->findKeyword("Name"); + QString tempName = tempKeyword[0]; + namelist.append(tempName); + } + } + bool ok; - QString stretchName = QInputDialog::getText(m_advancedStretch, tr("Load Stretch"), - tr("Name of Stretch to Load:"), QLineEdit::Normal, - "stretch", &ok); + QString stretchName = QInputDialog::getItem(m_advancedStretch, tr("Load Stretch"), + tr("Name of Stretch to Load:"), namelist, 0, + false, &ok); + if (ok) { - MdiCubeViewport *cvp = cubeViewport(); - Cube* icube = cvp->cube(); - Stretch stretch(stretchName); icube->read(stretch); m_advancedStretch->setStretchFromCube(stretch); @@ -404,15 +417,26 @@ namespace Isis { * Deletes a saved stretch from the cube */ void StretchTool::deleteFromCube() { - bool ok; - QString toDelete = QInputDialog::getText(m_advancedStretch, tr("Delete Stretch"), - tr("Name of Stretch to Delete:"), QLineEdit::Normal, - "stretch", &ok); + MdiCubeViewport *cvp = cubeViewport(); + Cube* icube = cvp->cube(); + Pvl* lab = icube->label(); - if (ok) { - MdiCubeViewport *cvp = cubeViewport(); - Cube* icube = cvp->cube(); + // Create a list of existing Stretch names + QStringList namelist; + PvlObject::PvlObjectIterator objIter; + for (objIter=lab->beginObject(); objIterendObject(); objIter++) { + if (objIter->name() == "Stretch") { + PvlKeyword tempKeyword = objIter->findKeyword("Name"); + QString tempName = tempKeyword[0]; + namelist.append(tempName); + } + } + bool ok; + QString toDelete = QInputDialog::getItem(m_advancedStretch, tr("Delete Stretch"), + tr("Name of Stretch to Delete:"), namelist, 0, + false, &ok); + if (ok) { if (icube->isReadOnly()) { try { cvp->cube()->reopen("rw"); @@ -430,11 +454,9 @@ namespace Isis { if (!cubeDeleted) { QMessageBox msgBox; msgBox.setText("Stretch Could Not Be Deleted!"); - msgBox.setInformativeText("A stretch with name: \"" + toDelete + "\. Could not be found, so " - "there was nothing to delete from the Cube."); + msgBox.setInformativeText("A stretch with name: \"" + toDelete + "\" Could not be found, so there was nothing to delete from the Cube."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setIcon(QMessageBox::Critical); - int ret = msgBox.exec(); } // Don't leave open rw -- not optimal. @@ -462,13 +484,6 @@ namespace Isis { } } - - // DEBUG OUTPUT -// QString testme = ""; -// for (int i=0; i Date: Fri, 28 Feb 2020 11:54:06 -0700 Subject: [PATCH 12/14] Wrapped some long strings --- isis/src/qisis/objs/StretchTool/StretchTool.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index b5e8424935..0766bb25d8 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -454,7 +454,8 @@ namespace Isis { if (!cubeDeleted) { QMessageBox msgBox; msgBox.setText("Stretch Could Not Be Deleted!"); - msgBox.setInformativeText("A stretch with name: \"" + toDelete + "\" Could not be found, so there was nothing to delete from the Cube."); + msgBox.setInformativeText("A stretch with name: \"" + toDelete + + "\" Could not be found, so there was nothing to delete from the Cube."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setIcon(QMessageBox::Critical); } @@ -497,7 +498,8 @@ namespace Isis { if (namelist.contains(text)) { QMessageBox msgBox; msgBox.setText("Stretch Name Already Exists!"); - msgBox.setInformativeText("A stretch pair with name: \"" + text + "\" already exists and the existing saved data will be overwritten. Are you sure you wish to proceed?"); + msgBox.setInformativeText("A stretch pair with name: \"" + text + + "\" already exists and the existing saved data will be overwritten. Are you sure you wish to proceed?"); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); msgBox.setIcon(QMessageBox::Warning); msgBox.setDefaultButton(QMessageBox::Cancel); From 1cfcf3803da82b97d4e20b63fa65d80d316ca647 Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 28 Feb 2020 13:03:48 -0700 Subject: [PATCH 13/14] Initial commit to address most of review comments --- isis/src/base/objs/Stretch/Stretch.cpp | 2 +- isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp | 7 ++----- isis/src/qisis/objs/StretchTool/AdvancedStretch.h | 2 +- .../objs/StretchTool/AdvancedStretchDialog.cpp | 5 ++--- .../qisis/objs/StretchTool/AdvancedStretchDialog.h | 2 +- isis/src/qisis/objs/StretchTool/StretchTool.cpp | 13 +++++++++---- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/isis/src/base/objs/Stretch/Stretch.cpp b/isis/src/base/objs/Stretch/Stretch.cpp index e3d8401c7c..a16f37379b 100644 --- a/isis/src/base/objs/Stretch/Stretch.cpp +++ b/isis/src/base/objs/Stretch/Stretch.cpp @@ -38,7 +38,7 @@ namespace Isis { * Constructs a Stretch object with default mapping of special pixel values to * themselves. */ - Stretch::Stretch() : Blob("NAME", "Stretch") { + Stretch::Stretch() : Blob("ImageStretch", "Stretch") { p_null = Isis::NULL8; p_lis = Isis::LOW_INSTR_SAT8; p_lrs = Isis::LOW_REPR_SAT8; diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index 5b4803ab3e..6b41d0b892 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -120,12 +120,12 @@ namespace Isis { /** * Used to restore a saved Stretch from a cube. This function is - * distinct from setStretch in that setStretch delibrately _does not_ + * distinct from setStretch in that setStretch deliberately _does not_ * change the stretch type, and this function does change the stretch type. * * @param newStretch saved stretch to restore */ - void AdvancedStretch::setStretchFromCube(Stretch newStretch) { + void AdvancedStretch::restoreSavedStretch(Stretch newStretch) { QString stretchTypeName = newStretch.getType(); int index = 0; @@ -143,9 +143,6 @@ namespace Isis { } // Fail by defaulting to Linear - -// p_stretchTypeStack->setCurrentIndex(index); <- does not work. - p_stretchTypeSelection->setCurrentIndex(index); StretchType *stretchType = (StretchType *) p_stretchTypeStack->currentWidget(); diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h index 1b19d711da..3f49826e3c 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h @@ -37,7 +37,7 @@ namespace Isis { ~AdvancedStretch(); Stretch getStretch(); void setStretch(Stretch newStretch); - void setStretchFromCube(Stretch newStretch); + void restoreSavedStretch(Stretch newStretch); void setHistogram(const Histogram &newHist); signals: diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index be93ad2879..63a05e2fa2 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -72,7 +72,6 @@ namespace Isis { this, SIGNAL(stretchChanged())); connect(p_bluStretch, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); - // add signal for RGB } /** @@ -142,8 +141,8 @@ namespace Isis { * * @param stretch */ - void AdvancedStretchDialog::setStretchFromCube(Stretch stretch){ - p_grayStretch->setStretchFromCube(stretch); + void AdvancedStretchDialog::restoreSavedStretch(Stretch stretch){ + p_grayStretch->restoreSavedStretch(stretch); } diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index fcf4c620e0..24a41f331e 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -48,7 +48,7 @@ namespace Isis { Histogram &grayHist); void updateHistogram(const Histogram &grayHist); bool isRgbMode() const; - void setStretchFromCube(Stretch stretch); + void restoreSavedStretch(Stretch stretch); Stretch getGrayStretch(); Stretch getRedStretch(); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index b5e8424935..d1783d8d18 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -408,7 +408,7 @@ namespace Isis { if (ok) { Stretch stretch(stretchName); icube->read(stretch); - m_advancedStretch->setStretchFromCube(stretch); + m_advancedStretch->restoreSavedStretch(stretch); } } @@ -489,15 +489,17 @@ namespace Isis { // "Get the name for the stretch" dialog QString text = QInputDialog::getText(m_advancedStretch, tr("Save Stretch"), - tr("Name of Stretch Pair:"), QLineEdit::Normal, + tr("Enter a name to save the stretch as:"), QLineEdit::Normal, "stretch", &ok); if (ok) { // Stretch Name Already Exists Dialog! if (namelist.contains(text)) { QMessageBox msgBox; - msgBox.setText("Stretch Name Already Exists!"); - msgBox.setInformativeText("A stretch pair with name: \"" + text + "\" already exists and the existing saved data will be overwritten. Are you sure you wish to proceed?"); + msgBox.setText(tr("Stretch Name Already Exists!")); + msgBox.setInformativeText("A stretch pair with name: \"" + text + "\" already exists and " + "the existing saved data will be overwritten. Are you sure you " + "wish to proceed?"); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); msgBox.setIcon(QMessageBox::Warning); msgBox.setDefaultButton(QMessageBox::Cancel); @@ -536,6 +538,9 @@ namespace Isis { stretch.Label()["Name"] = text; stretch.Label() += PvlKeyword("StretchType", stretch.getType()); + // Greyscale is only available option for now + stretch.Label() += PvlKeyword("Color", "Greyscale"); + icube->write(stretch); // Don't leave open rw -- not optimal. From 199753c129f53e4b446b63095dc029fc0eab3d0b Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 28 Feb 2020 13:34:40 -0700 Subject: [PATCH 14/14] Removed buttons in case of RGB stretch and add a 'Color' PvlKeyword to Stretch output --- .../qisis/objs/StretchTool/StretchTool.cpp | 1 + .../qisis/objs/StretchTool/StretchType.cpp | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index da97c3d2ef..466ade83fc 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -458,6 +458,7 @@ namespace Isis { "\" Could not be found, so there was nothing to delete from the Cube."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); } // Don't leave open rw -- not optimal. diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index f02ae523ac..2e69622a04 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -59,17 +59,20 @@ namespace Isis { connect(saveAsButton, SIGNAL(clicked(bool)), this, SLOT(savePairs())); p_mainLayout->addWidget(saveAsButton, 3, 0); - QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube..."); - connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); - p_mainLayout->addWidget(saveToCubeButton, 4, 0); - - QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube..."); - connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); - p_mainLayout->addWidget(deleteFromCubeButton, 5, 0); - - QPushButton *loadStretchButton = new QPushButton("Load Saved Stretch from Cube..."); - connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); - p_mainLayout->addWidget(loadStretchButton, 6, 0); + // Save/Restore strech only supported for Grayscale images. Hide buttons if in RGB. + if (name.compare("Gray") == 0) { + QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube..."); + connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); + p_mainLayout->addWidget(saveToCubeButton, 4, 0); + + QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube..."); + connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); + p_mainLayout->addWidget(deleteFromCubeButton, 5, 0); + + QPushButton *loadStretchButton = new QPushButton("Load Saved Stretch from Cube..."); + connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); + p_mainLayout->addWidget(loadStretchButton, 6, 0); + } QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); sizePolicy.setHeightForWidth(true);