Unverified Commit 4763bf4f authored by Stuart Sides's avatar Stuart Sides Committed by GitHub
Browse files

Add ability for Cube class to handle input attributes. Closes #3805 (#4767)

* Add ability for Cube class to handle input attributes

* Update IsisAml.cpp

* unittest updated for GetCubeName
parent 7bfa6914
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
using namespace std;

namespace Isis {

// Function to create a keyword with same values of a specified count
  template <typename T> PvlKeyword makeKey(const QString &name,
                                           const int &nvals,
@@ -30,22 +31,21 @@ namespace Isis {
    double m_albedo;
  };


  // Computes the special MORPHOLOGYRANK and ALBEDORANK planes
  static MosData *getMosaicIndicies(Camera &camera, MosData &md);
  // Updates BandBin keyword
  static void UpdateBandKey(const QString &keyname, PvlGroup &bb, const int &nvals,
                     const QString &default_value = "Null");


  void phocube(UserInterface &ui) {
    Cube icube;
    CubeAttributeInput inAtt = ui.GetInputAttribute("FROM");
    if (inAtt.bands().size() != 0) {
      icube.setVirtualBands(inAtt.bands());
    }
    icube.open(ui.GetFileName("FROM"));
    icube.open(ui.GetCubeName("FROM"));
    phocube(&icube, ui);
  }


  void phocube(Cube *icube, UserInterface &ui)  {

    // Get the camera information if this is not a mosaic. Otherwise, get the
+10 −2
Original line number Diff line number Diff line
@@ -617,7 +617,9 @@ namespace Isis {


  /**
   * This method will open an isis cube for reading or reading/writing.
   * This method will open an existing isis cube for reading or 
   * reading/writing. Any input cube attributes following the file
   * name will be applied.
   *
   * @param[in] cubeFileName Name of the cube file to open. Environment
   *     variables in the filename will be automatically expanded.
@@ -625,8 +627,8 @@ namespace Isis {
   *     accessed. Either read-only "r" or read-write "rw".
   */
  void Cube::open(const QString &cubeFileName, QString access) {
    // Already opened?

    // Already opened?
    if (isOpen()) {
      string msg = "You already have a cube opened";
      throw IException(IException::Programmer, msg, _FILEINFO_);
@@ -634,6 +636,12 @@ namespace Isis {

    initLabelFromFile(cubeFileName, (access == "rw"));

    Isis::CubeAttributeInput att(cubeFileName);
    if(att.bands().size() != 0) {
      vector<QString> bands = att.bands();
      setVirtualBands(bands);
    }

    // Figure out the name of the data file
    try {
      PvlObject &core = m_label->findObject("IsisCube").findObject("Core");
+133 −6
Original line number Diff line number Diff line
@@ -258,6 +258,39 @@ void IsisAml::PutFileName(const QString &paramName,
}


/**
 * Allows the insertion of a value for a parameter of type 
 * "cubename". A validity check is performed on the value passed
 * in. 
 *
 * @param paramName The partial or full name of the parameter to be modified.
 * @param value The QString representation of the value to be placed in the
 * cubename's value data member.
 */
void IsisAml::PutCubeName(const QString &paramName,
                          const QString &value) {

  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));

  if(param->type != "cube") {
    QString message = "Parameter [" + paramName + "] is not a cubename.";
    throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
  }

  if(param->values.size() > 0) {
    QString message = "A value for this parameter [" + paramName + "] has "
                     "already been saved (possibly by IsisGui). If you need to "
                     "change the value use \"Clear\" before the Put.";
    throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
  }

  param->values.clear();
  param->values.push_back(value);

  Verify(param);
}


// Public: Sets the value member of a parameter of type integer whose name
// starts with paramName

@@ -339,8 +372,6 @@ void IsisAml::PutInteger(const QString &paramName,
}




// Public: Sets the value member of a parameter of type double whose name
// starts with paramName
/**
@@ -425,7 +456,6 @@ void IsisAml::PutDouble(const QString &paramName,
}



// Public: Sets the value member of a parameter of type boolean whose name
// starts with paramName
/**
@@ -554,6 +584,7 @@ QString IsisAml::GetAsString(const QString &paramName) const {
  return value;
}


// Public: Returns the value member of a parameter whose name starts with paramName
// as a vector<QString>
/**
@@ -678,6 +709,50 @@ void IsisAml::GetFileName(const QString &paramName,
}


/**
 * Retrieves of a value for a parameter of type "cubename".
 *
 * @param paramName The partial or full name of the parameter to be retrieved.
 * @param extension A default extension to add if it does not already exist on
 * the file name.  For example, "txt" will make /mydir/myfile into
 * /mydir/myfile.txt
 *
 * @return The value of the parameter.
 */
QString IsisAml::GetCubeName(const QString &paramName, QString extension) const {

  const IsisParameterData *param = ReturnParam(paramName);

  if (param->type != "cube") {
    QString message = "Parameter [" + paramName + "] is not a cubename.";
    throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
  }

  QString value;
  if (param->values.size() == 0) {
    if (param->defaultValues.size() == 0) {
      QString message = "Parameter [" + paramName + "] has no value.";
      throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
    }
    else {
      value = param->defaultValues[0];
    }
  }
  else {
    value = param->values[0];
  }

  Isis::FileName name(value);
  if (extension != "") name = name.addExtension(extension);
  value = name.expanded();
  if (name.attributes().length() > 0) {
    value += "+" + name.attributes();
  }

  return value;
}


// Public: Returns the first element of the value member of a parameter whos
// name starts with paramName as a QString
/**
@@ -792,7 +867,6 @@ void IsisAml::GetString(const QString &paramName,
}



// Public: Returns the first element of the value member of a parameter whos
// name starts with paramName as an integer
/**
@@ -876,7 +950,6 @@ void IsisAml::GetInteger(const QString &paramName,
}



// Public: Returns the first element of the value member of a parameter whos
// name starts with paramName as a doubble
/**
@@ -914,6 +987,7 @@ double IsisAml::GetDouble(const QString &paramName) const {
  return value.ToDouble();
}


// Public: Returns the value member of a parameter whose name starts with paramName
// as a vector<doubble>
/**
@@ -1079,6 +1153,7 @@ QString IsisAml::Description() const {
  return description;
}


/**
 * Returns the number of groups found in the XML.
 *
@@ -1088,6 +1163,7 @@ int IsisAml::NumGroups() const {
  return groups.size();
}


/**
 * Returns the group name of group[index].
 *
@@ -1100,6 +1176,7 @@ QString IsisAml::GroupName(const int &index) const {
  return s;
}


/**
 * Given group name return its index in the Gui
 *
@@ -1118,6 +1195,7 @@ int IsisAml::GroupIndex(const QString & grpName) const {
  return -1;
}


/**
 * Create a PVL file from the parameters in a Group given the Gui group name,
 * Pvl Object and Group names and the list of parameters to be included in the
@@ -1178,6 +1256,7 @@ void IsisAml::CreatePVL(Isis::Pvl &pvlDef , QString guiGrpName, QString pvlObjNa
  }
}


/**
 * Verify if the Parameter is in the Included list
 *
@@ -1197,6 +1276,8 @@ bool IsisAml::IsParamInPvlInclude(QString & paramName, vector<QString> & include
  }
  return false;
}


/**
 * Returns the number of parameters in a group.
 *
@@ -1208,6 +1289,7 @@ int IsisAml::NumParams(const int &group) const {
  return groups[group].parameters.size();
}


/**
 * Returns the parameter name.
 *
@@ -1221,6 +1303,7 @@ QString IsisAml::ParamName(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the brief description of a parameter in a specified group.
 *
@@ -1234,6 +1317,7 @@ QString IsisAml::ParamBrief(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the long description of a parameter in a specified group.
 *
@@ -1247,6 +1331,7 @@ QString IsisAml::ParamDescription(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the minimum value of a parameter in a specified group.
 *
@@ -1260,6 +1345,7 @@ QString IsisAml::ParamMinimum(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the maximum value of a parameter in a specified group.
 *
@@ -1273,6 +1359,7 @@ QString IsisAml::ParamMaximum(const int &group, const int &param) const {
  return s;
}


/**
 * Returns whether the minimum value is inclusive or not.
 *
@@ -1286,6 +1373,7 @@ QString IsisAml::ParamMinimumInclusive(const int &group, const int &param) const
  return s;
}


/**
 * Returns whether the maximum value is inclusive or not.
 *
@@ -1299,6 +1387,7 @@ QString IsisAml::ParamMaximumInclusive(const int &group, const int &param) const
  return s;
}


/**
 * Returns whether the selected parameter has a restriction on odd values or
 * not.
@@ -1313,6 +1402,7 @@ QString IsisAml::ParamOdd(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the number of values in the parameters greater than list.
 *
@@ -1325,6 +1415,7 @@ int IsisAml::ParamGreaterThanSize(const int &group, const int &param) const {
  return groups[group].parameters[param].greaterThan.size();
}


/**
 * Returns the number of values in the parameters greater than or equal list.
 *
@@ -1338,6 +1429,7 @@ int IsisAml::ParamGreaterThanOrEqualSize(const int &group,
  return groups[group].parameters[param].greaterThanOrEqual.size();
}


/**
 * Returns the number of values in the parameters less than list.
 *
@@ -1350,6 +1442,7 @@ int IsisAml::ParamLessThanSize(const int &group, const int &param) const {
  return groups[group].parameters[param].lessThan.size();
}


/**
 * Returns the number of values in the parameters less than or equal list.
 *
@@ -1363,6 +1456,7 @@ int IsisAml::ParamLessThanOrEqualSize(const int &group,
  return groups[group].parameters[param].lessThanOrEqual.size();
}


/**
 * Returns the number of values in the not equal list.
 *
@@ -1375,6 +1469,7 @@ int IsisAml::ParamNotEqualSize(const int &group, const int &param) const {
  return groups[group].parameters[param].notEqual.size();
}


/**
 * Returns the name of the specified greaterThan parameter
 *
@@ -1390,6 +1485,7 @@ QString IsisAml::ParamGreaterThan(const int &group, const int &param,
  return s;
}


/**
 * Returns the name of the specified greaterThanOrEqual parameter
 *
@@ -1405,6 +1501,7 @@ QString IsisAml::ParamGreaterThanOrEqual(const int &group, const int &param,
  return s;
}


/**
 * Returns the name of the specified lessThan parameter
 *
@@ -1420,6 +1517,7 @@ QString IsisAml::ParamLessThan(const int &group, const int &param,
  return s;
}


/**
 * Returns the name of the specified lessThanOrEqual parameter
 *
@@ -1435,6 +1533,7 @@ QString IsisAml::ParamLessThanOrEqual(const int &group, const int &param,
  return s;
}


/**
 * Returns the name of the specified notEqual parameter
 *
@@ -1450,6 +1549,7 @@ QString IsisAml::ParamNotEqual(const int &group, const int &param,
  return s;
}


/**
 * Returns the name of the specified excluded parameter
 *
@@ -1465,6 +1565,7 @@ QString IsisAml::ParamExclude(const int &group, const int &param,
  return s;
}


/**
 * Returns the name of the specified included parameter
 *
@@ -1494,6 +1595,7 @@ QString IsisAml::ParamType(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the default for a parameter in a specified group.
 *
@@ -1513,6 +1615,7 @@ QString IsisAml::ParamDefault(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the internal default for a parameter in a specified group
 *
@@ -1532,6 +1635,7 @@ QString IsisAml::ParamInternalDefault(const int &group, const int &param) const
  return s;
}


/**
 * Returns the parameter filter for a parameter in a specified group.
 *
@@ -1551,6 +1655,7 @@ QString IsisAml::ParamFilter(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the default path for a filename/cube parameter
 *
@@ -1570,6 +1675,7 @@ QString IsisAml::ParamPath(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the file mode for a parameter in a specified group.
 *
@@ -1589,6 +1695,7 @@ QString IsisAml::ParamFileMode(const int &group, const int &param) const {
  return s;
}


/**
 * Returns the number of options in the specified parameter's list.
 *
@@ -1618,6 +1725,7 @@ QString IsisAml::ParamListValue(const int &group, const int &param,
  return s;
}


/**
 * Returns the brief description for a specific option to a parameter.
 *
@@ -1633,6 +1741,7 @@ QString IsisAml::ParamListBrief(const int &group, const int &param,
  return s;
}


/**
 * Returns the full description for a specific option to a parameter.
 *
@@ -1648,6 +1757,7 @@ QString IsisAml::ParamListDescription(const int &group, const int &param,
  return s;
}


/**
 * Returns the number of items in a parameters list exclude section.
 *
@@ -1662,6 +1772,7 @@ int IsisAml::ParamListExcludeSize(const int &group, const int &param,
  return groups[group].parameters[param].listOptions[option].exclude.size();
}


/**
 * Returns the parameter name to be excluded if this option is selected.
 *
@@ -1678,6 +1789,7 @@ QString IsisAml::ParamListExclude(const int &group, const int &param,
  return s;
}


/**
 * Returns the number of items in a parameters list include section.
 *
@@ -1692,6 +1804,7 @@ int IsisAml::ParamListIncludeSize(const int &group, const int &param,
  return groups[group].parameters[param].listOptions[option].include.size();
}


/**
 * Returns the parameter name to be included if this option is selected.
 *
@@ -1708,6 +1821,7 @@ QString IsisAml::ParamListInclude(const int &group, const int &param,
  return s;
}


/**
 * Returns the number of parameters excluded in this parameter's exclusions
 *
@@ -1720,6 +1834,7 @@ int IsisAml::ParamExcludeSize(const int &group, const int &param) const {
  return groups[group].parameters[param].exclude.size();
}


/**
 * Returns the number of parameters included in this parameter's inclusions
 *
@@ -1732,6 +1847,7 @@ int IsisAml::ParamIncludeSize(const int &group, const int &param) const {
  return groups[group].parameters[param].include.size();
}


/**
 * Returns the default pixel type from the XML
 *
@@ -1744,6 +1860,7 @@ QString IsisAml::PixelType(const int &group, const int &param) const {
  return groups[group].parameters[param].pixelType;
}


/**
 * Returns the number of helpers the parameter has
 *
@@ -1756,6 +1873,7 @@ int IsisAml::HelpersSize(const int &group, const int &param) const {
  return groups[group].parameters[param].helpers.size();
}


/**
 * Returns the name of the helper button
 *
@@ -1770,6 +1888,7 @@ QString IsisAml::HelperButtonName(const int &group, const int &param,
  return groups[group].parameters[param].helpers[helper].name;
}


/**
 * Returns the name of the helper function
 *
@@ -1784,6 +1903,7 @@ QString IsisAml::HelperFunction(const int &group, const int &param,
  return groups[group].parameters[param].helpers[helper].function;
}


/**
 * Returns the brief description of the helper button
 *
@@ -1798,6 +1918,7 @@ QString IsisAml::HelperBrief(const int &group, const int &param,
  return groups[group].parameters[param].helpers[helper].brief;
}


/**
 * Returns the long description of the helper button
 *
@@ -1812,6 +1933,7 @@ QString IsisAml::HelperDescription(const int &group, const int &param,
  return groups[group].parameters[param].helpers[helper].description;
}


/**
 * Returns the name of the icon for the helper button
 *
@@ -1826,6 +1948,7 @@ QString IsisAml::HelperIcon(const int &group, const int &param,
  return groups[group].parameters[param].helpers[helper].icon;
}


/**
 * Returns a true if the parameter has a value, and false if it does not
 *
@@ -1844,6 +1967,7 @@ bool IsisAml::WasEntered(const QString &paramName) const {
  return true;
}


/**
 * Clears the value(s) in the named parameter
 *
@@ -1906,6 +2030,7 @@ Isis::CubeAttributeInput &IsisAml::GetInputAttribute(const QString &paramName) {
  return param->inCubeAtt;
}


/**
 * Gets the attributes for an output cube
 *
@@ -1952,6 +2077,7 @@ Isis::CubeAttributeOutput &IsisAml::GetOutputAttribute(const QString &paramName)
  return param->outCubeAtt;
}


/**
 * Returns a pointer to a parameter whose name starts with paramName
 *
@@ -2004,6 +2130,7 @@ const IsisParameterData *IsisAml::ReturnParam(const QString &paramName) const {
  return param;
}


/**
 * Throws an Isis::iExceptionXxxxxxxx if the parameter value(s) is invalid
 *
@@ -2855,6 +2982,7 @@ void IsisAml::VerifyAll() {
  }
}


/**
 * Returns a boolean value based on the QString contents
 *
@@ -3077,4 +3205,3 @@ void IsisAml::StartParser(const char *xmlfile) {
  delete appHandler;
  return;
}
+4 −0
Original line number Diff line number Diff line
@@ -154,6 +154,8 @@ class IsisAml : protected IsisAmlData {
    void PutFileName(const QString &paramName, const QString &value);
    void PutFileName(const QString &paramName, const std::vector<QString> &value);

    void PutCubeName(const QString &paramName, const QString &value);

    void PutDouble(const QString &paramName, const double &value);
    void PutDouble(const QString &paramName, const std::vector<double> &value);

@@ -172,6 +174,8 @@ class IsisAml : protected IsisAmlData {
    QString GetFileName(const QString &paramName, QString extension = "") const;
    void GetFileName(const QString &paramName, std::vector<QString> &values) const;

    QString GetCubeName(const QString &paramName, QString extension = "") const;

    QString GetString(const QString &paramName) const;
    void GetString(const QString &paramName, std::vector<QString> &values) const;

+1 −1
Original line number Diff line number Diff line
@@ -1449,7 +1449,7 @@ Exact and partial name match tests:
  PutFileName:
**PROGRAMMER ERROR** A value for this parameter [G0P0] has already been saved (possibly by IsisGui). If you need to change the value use "Clear" before the Put.

**PROGRAMMER ERROR** Parameter [G2P4] is not a filename.
**PROGRAMMER ERROR** Parameter [G2P4] is not a cubename.

  Cube tests:
**PROGRAMMER ERROR** Unable to get input cube attributes.  Parameter [CUBE2] is not an input. Parameter fileMode = [output].
Loading