Loading isis/src/base/objs/PvlToPvlTranslationManager/PvlToPvlTranslationManager.cpp +13 −7 Original line number Diff line number Diff line Loading @@ -104,10 +104,11 @@ namespace Isis { /** * Returns a translated value. The output name is used to find the input * group, keyword, default and tranlations in the translation table. If the * keyword does not exist in the input label, the input default if * available will be used as the input value. This input value * is then used to search all of the translations. If a match is * found the translated value is returned. * keyword does not exist in the input label and an input * default is available, then this default will be used as the * input value. This input value is then used to search all of * the translations. If a match is found the translated value is * returned. * * @param nName The output name used to identify the input keyword to be * translated. Loading Loading @@ -136,7 +137,12 @@ namespace Isis { /** * Translate the requested output name to output values using the input name * and values or default value * and values or default value. * * Note: This is a protected method used when automatically * translating * * @see Auto(). * * @param nName The output name used to identify the input keyword to be * translated. Loading isis/src/base/objs/PvlToPvlTranslationManager/PvlToPvlTranslationManager.h +20 −26 Original line number Diff line number Diff line Loading @@ -44,42 +44,36 @@ namespace Isis { * @author 2003-05-29 Stuart Sides * * @internal * @history 2003-09-03 Stuart Sides - Modified to work with new isis label * format * @history 2003-09-25 Stuart Sides - Added the Translate member * @history 2005-02-15 Elizabeth Ribelin - Modified file to support Doxygen * documentation * @history 2006-08-09 Brendan George - Modified to support Optional keyword * translation * @history 2003-09-03 Stuart Sides - Modified to work with new isis label format. * @history 2003-09-25 Stuart Sides - Added the Translate member. * @history 2005-02-15 Elizabeth Ribelin - Modified file to support Doxygen documentation. * @history 2006-08-09 Brendan George - Modified to support Optional keyword translation. * @history 2006-10-01 Stuart Sides - Fixed bug with Optional keyword. * Non-optional keywords were being reported * instantly. * Non-optional keywords were being reported instantly. * @history 2006-11-16 Brendan George - Changed instances of "Foreign" to "Input" * and "Native" to "Output" * and "Native" to "Output". * @history 2007-06-22 Stuart Sides - Added ability to have more than one input location * keyword for a translation. The first one found * which contains the input keyword is used. * keyword for a translation. The first one found which contains * the input keyword is used. * @history 2008-05-09 Steven Lambright - Added ability to change input label without * re-reading the translation file. * @history 2008-07-10 Noah Hilt - Changed while loops to continue searching * other groups if a group has been found, but the keyword does not * exist in that group. * @history 2008-07-10 Steven Lambright - Changed to use new accessors * @history 2008-07-10 Noah Hilt - Changed while loops to continue searching other groups * if a group has been found, but the keyword does not exist in * that group. * @history 2008-07-10 Steven Lambright - Changed to use new accessors. * @history 2010-01-04 Steven Lambright - Added InputKeyword method and removed * InputSize, InputUnits, InputValue. * Renamed private Translate method to * DoTranslation to remove ambiguity * with a parent method, instead of * using a dummy parameter. * @history 2017-01-11 Jeannie Backer - Moved several methods to a generic * parent class, LabelTranslationManager. Fixes #4584. * InputSize, InputUnits, InputValue. Renamed private Translate() method * to DoTranslation() to remove ambiguity with a parent method, * instead of using a dummy parameter. * @history 2017-01-11 Jeannie Backer - Moved several methods to a generic parent class, * LabelTranslationManager. Fixes #4584. * @history 2017-06-13 Adam Paquette - Changed PvlTranslationManager file name to * PvlToPvlTranslationManager. Fixes #4901. * @history 2018-01-10 Christopher Combs - Changed ProcessDataFilePointer call to reflect * changes made to voy2isis. Fixes #4345, #4421. * @todo 2005-02-15 Stuart Sides - add coded example and implementation example * to class documentation, and finish * documentation * documentation. */ class PvlToPvlTranslationManager : public LabelTranslationManager { public: Loading isis/src/base/objs/PvlTranslationTable/PvlTranslationTable.cpp +199 −140 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <fstream> #include <sstream> #include <QDebug> #include "IException.h" #include "IString.h" #include "Message.h" Loading @@ -37,7 +39,7 @@ namespace Isis { * * @param transFile The translation file to be used * * @throws iException::Io * @throws IException::Io */ PvlTranslationTable::PvlTranslationTable(FileName transFile) { AddTable(transFile.expanded()); Loading @@ -54,23 +56,39 @@ namespace Isis { } //! Construct an empty PvlTranslationTable /** * Construct an empty PvlTranslationTable */ PvlTranslationTable::PvlTranslationTable() { } //! Destroys the PvlTranslationTable object. /** * Destroys the PvlTranslationTable object. */ PvlTranslationTable::~PvlTranslationTable() { } //! Protected accessor for pvl translation table passed into class. /** * Protected accessor for pvl translation table passed into * class. This method returns a reference to the translation * table member. * * @return @b Pvl The translation table as a PVL object. */ Pvl &PvlTranslationTable::TranslationTable() { return p_trnsTbl; } //! Protected accessor for const pvl translation table passed into class. /** * Protected accessor for const pvl translation table passed * into class. This method returns a @b const reference to the * translation table member. * * @return @b Pvl The translation table as a PVL object. */ const Pvl &PvlTranslationTable::TranslationTable() const { return p_trnsTbl; } Loading Loading @@ -103,20 +121,20 @@ namespace Isis { vector< pair<QString, int> > validKeywordSizes = validKeywords(); for (int i = 0; i < p_trnsTbl.groups(); i++) { PvlGroup currGrp = p_trnsTbl.group(i); PvlGroup currGroup = p_trnsTbl.group(i); if(!currGrp.hasKeyword("InputKey")) { if (!currGroup.hasKeyword("InputKey")) { QString message = "Unable to find InputKey for group [" + currGrp.name() + "] in file [" + + currGroup.name() + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::User, message, _FILEINFO_); } for(int j = 0; j < currGrp.keywords(); j++) { for (int j = 0; j < currGroup.keywords(); j++) { bool validKeyword = false; bool keywordSizeMismatch = false; const PvlKeyword &currKey = currGrp[j]; const PvlKeyword &currKey = currGroup[j]; // Test this keyword for validity for (int key = 0; Loading Loading @@ -184,53 +202,53 @@ namespace Isis { validKeywords.push_back(pair<QString, int>("Optional", 0)); validKeywords.push_back(pair<QString, int>("InputKey", 1)); validKeywords.push_back(pair<QString, int>("InputDefault", -1)); validKeywords.push_back(pair<QString, int>("InputKeyDependencies", -1)); return validKeywords; } /** * Translates the output name and input value. * Translates a single output value from the given translation * group name and input value. * * @param nName The output name to be used to search the translation table. * @param fValue The input value to be translated * @param translationGroupName The name of the pvl translation * group. Often, this is the same * as the output keyword name. * @param inputKeyValue The value to be translated, from the * input keyword. * * @return QString The translated QString * @return QString The translated value, for the * output keyword. * * @throws iException::Programmer * @throws IException::Programmer */ QString PvlTranslationTable::Translate(const QString nName, const QString fValue) const { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } QString PvlTranslationTable::Translate(const QString translationGroupName, const QString inputKeyValue) const { const PvlGroup &tgrp = p_trnsTbl.findGroup(nName); const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); // If no input value was passed in search using the input default QString tmpFValue = fValue; QString tmpFValue = inputKeyValue; if (tmpFValue.isEmpty()) { if(tgrp.hasKeyword("InputDefault")) { tmpFValue = (QString) tgrp["InputDefault"]; if (translationGroup.hasKeyword("InputDefault")) { tmpFValue = (QString) translationGroup["InputDefault"]; } else { QString msg = "No value or default value to translate for "; msg += "translation group ["; msg += nName; msg += translationGroupName; msg += "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } } // Search the Translation keywords for a match to the input value Pvl::ConstPvlKeywordIterator it = tgrp.findKeyword("Translation", tgrp.begin(), tgrp.end()); Pvl::ConstPvlKeywordIterator it = translationGroup.findKeyword("Translation", translationGroup.begin(), translationGroup.end()); while(it != tgrp.end()) { while (it != translationGroup.end()) { const PvlKeyword &key = *it; // compare the value from the input file to the second value of each Translation in the trans file. // ignore cases for input values Loading @@ -246,11 +264,11 @@ namespace Isis { } } it = tgrp.findKeyword("Translation", it + 1, tgrp.end()); it = translationGroup.findKeyword("Translation", it + 1, translationGroup.end()); } QString msg = "Unable to find a translation value for [" + nName + ", " + fValue + "] in file [" + translationGroupName + ", " + inputKeyValue + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); Loading @@ -261,41 +279,35 @@ namespace Isis { * Returns the input group name from the translation table corresponding to * the output name argument. * * @param nName The output name to be used to search the translation table. * @param translationGroupName The output name to be used to search the translation table. * @param inst The occurence number of the "InputGroup" keyword * (first one is zero) * * @return QString The input group name * * @throws iException::Programmer * @throws IException::Programmer */ PvlKeyword PvlTranslationTable::InputGroup(const QString nName, PvlKeyword PvlTranslationTable::InputGroup(const QString translationGroupName, const int inst) const { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } const PvlGroup &transGrp = p_trnsTbl.findGroup(nName); const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); //bool foundLegalInputGroup = false; Pvl::ConstPvlKeywordIterator it = transGrp.findKeyword("InputPosition", transGrp.begin(), transGrp.end()); Pvl::ConstPvlKeywordIterator it = translationGroup.findKeyword("InputPosition", translationGroup.begin(), translationGroup.end()); int currentInstance = 0; // If no InputPosition keyword exists, the answer is root if(inst == 0 && it == transGrp.end()) { if (inst == 0 && it == translationGroup.end()) { PvlKeyword root("InputPosition"); root += "ROOT"; return root; } while(it != transGrp.end()) { while (it != translationGroup.end()) { const PvlKeyword &result = *it; // This check is to prevent backtracking to the old "value,value" way of Loading @@ -318,17 +330,17 @@ namespace Isis { currentInstance ++; } it = transGrp.findKeyword("InputPosition", it + 1, transGrp.end()); it = translationGroup.findKeyword("InputPosition", it + 1, translationGroup.end()); } /* Error if no containers were listed if (!foundLegalInputGroup) { QString msg = "No input position found for translation ["; msg += nName; msg += translationGroupName; msg += "] in translation file ["; msg += p_trnsTbl.FileName(); msg += "]"; throw iException::Message(iException::Programmer, msg, _FILEINFO_); throw IException::Message(IException::Programmer, msg, _FILEINFO_); }*/ PvlKeyword empty; Loading @@ -340,22 +352,17 @@ namespace Isis { * Returns the input keyword name from the translation table corresponding to * the output name argument. * * @param nName The output name to be used to search the translation table. * @param translationGroupName The output name to be used to search the translation table. * * @return QString The input keyword name * * @throws iException::Programmer * @throws IException::Programmer */ QString PvlTranslationTable::InputKeywordName(const QString nName) const { QString PvlTranslationTable::InputKeywordName(const QString translationGroupName) const { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); PvlGroup tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("InputKey")) return tgrp["InputKey"]; if (translationGroup.hasKeyword("InputKey")) return translationGroup["InputKey"]; return ""; } Loading @@ -365,97 +372,149 @@ namespace Isis { * Returns the input default value from the translation table corresponding * to the output name argument. * * @param nName The output name to be used to search the translation table. * @param translationGroupName The output name to be used to search the translation table. * * @return QString The input default value * * @throws iException::Programmer * @throws IException::Programmer */ QString PvlTranslationTable::InputDefault(const QString nName) const { QString PvlTranslationTable::InputDefault(const QString translationGroupName) const { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); PvlGroup tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("InputDefault")) return tgrp["InputDefault"]; if (translationGroup.hasKeyword("InputDefault")) return translationGroup["InputDefault"]; return ""; } bool PvlTranslationTable::hasInputDefault(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlGroup &tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("InputDefault")) return true; /** * Determines whether the given group has a default input value. * This method returns true if the translation group contains a * PvlKeyword with the name "InputDefault". Note: no value needs * to be assigned to this keyword. * * @param translationGroupName The name of the PVL translation group. * * @return bool Indicates whether the given group has an * InputDefault keyword. */ bool PvlTranslationTable::hasInputDefault(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); if (translationGroup.hasKeyword("InputDefault")) return true; return false; } bool PvlTranslationTable::IsAuto(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlGroup &tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("Auto")) return true; /** * Determines whether the given group should be automatically * translated. This method returns true if the translation * group contains a PvlKeyword with the name "Auto". Note: * no value is assigned to this keyword. * * @param translationGroupName The name of the PVL translation group. * * @return bool Indicates whether the given group has an Auto * keyword. */ bool PvlTranslationTable::IsAuto(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); if (translationGroup.hasKeyword("Auto")) return true; return false; } bool PvlTranslationTable::IsOptional(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlGroup &tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("Optional")) return true; /** * Determines whether the translation group is optional. This * method returns true if the translation group contains a * PvlKeyword with the name "Optional". Note: no value is * assigned to this keyword. * * @param translationGroupName The name of the PVL translation group. * * @return bool Indicates whether the given group has an * Optional keyword. */ bool PvlTranslationTable::IsOptional(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); if (translationGroup.hasKeyword("Optional")) return true; return false; } PvlKeyword &PvlTranslationTable::OutputPosition(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlGroup &tgrp = p_trnsTbl.findGroup(nName); if(!tgrp.hasKeyword("OutputPosition")) { /** * Retrieves the OutputPosition PvlKeyword for the translation * group with the given name. * * @param translationGroupName The name of the PVL translation group. * * @return PvlKeyword The OutputPosition keyword from the given * translation group. */ PvlKeyword PvlTranslationTable::OutputPosition(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); if (!translationGroup.hasKeyword("OutputPosition")) { QString msg = "Unable to find translation keyword [OutputPostion] in [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; translationGroupName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } return tgrp["OutputPosition"]; return translationGroup["OutputPosition"]; } QString PvlTranslationTable::OutputName(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } /** * Retrieves a string containing the value of the OutputName * keyword for the translation group with the given name. * * @param translationGroupName The name of the PVL translation group. * * @return @b QString The value of the OutputName keyword from * the given translation group. */ QString PvlTranslationTable::OutputName(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); PvlGroup tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("OutputName")) { return tgrp["OutputName"]; if (translationGroup.hasKeyword("OutputName")) { return translationGroup["OutputName"]; } return ""; } /** * Searches for translation group with the given name. * * @see PvlObject::findGroup() * * @param translationGroupName Name of the PVL group to search for. * * @return const PvlGroup& The first PVL group with the given name. * * @throws IException::Programmer - "Unable to find translation * group in file." */ const PvlGroup &PvlTranslationTable::findTranslationGroup(const QString translationGroupName) const { if (!p_trnsTbl.hasGroup(translationGroupName)) { QString msg = "Unable to find translation group [" + translationGroupName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } return p_trnsTbl.findGroup(translationGroupName); } } // end namespace isis isis/src/base/objs/PvlTranslationTable/PvlTranslationTable.h +12 −9 File changed.Preview size limit exceeded, changes collapsed. Show changes isis/src/base/objs/XmlToPvlTranslationManager/XmlToPvlTranslationManager.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -240,6 +240,7 @@ namespace Isis { cout << endl << "Finding input element:" << endl << endl; cout << inputParentElement.tagName() << endl; } // traverse the input position path for (int i = 0; i < inputPosition.size(); i++) { QString childName = inputPosition[i]; inputParentElement = inputParentElement.firstChildElement(childName); Loading @@ -265,6 +266,7 @@ namespace Isis { cout << indent << inputParentElement.tagName() << endl; } } // now get input value at given input position path QDomElement inputKeyElement = inputParentElement.firstChildElement(inputKey); if (isDebug) { indent += " "; Loading @@ -289,7 +291,6 @@ namespace Isis { inputKeyElement = inputParentElement.firstChildElement(inputKey); } } // If the parent element is NULL at this point then we traversed every // potential input element and none of them satisfied the dependencies. if ( inputParentElement.isNull() ) { Loading @@ -301,7 +302,8 @@ namespace Isis { return PvlTranslationTable::Translate( outputName ); } else { QString msg = "Could not find an input value or default value."; QString msg = "Could not find an input or default value that fits the given input " "keyword dependencies."; throw IException(IException::Unknown, msg, _FILEINFO_); } } Loading Loading @@ -347,7 +349,8 @@ namespace Isis { * dependencies are requirements on the values of attributes of the element * and/or the values of sibling elements. The dependencies are specified by * strings that are formatted as follows * <code>[tag/att]\@[tagName/attName]:[value]</code> * <code>[tag/att]\@[tagName/attName]|[value]</code> or * <code>[tagName/attName]|[value]</code> * * @param element The element to check dependencies on. * @param dependencies A multi-valued keyword were every entry specifies a Loading Loading
isis/src/base/objs/PvlToPvlTranslationManager/PvlToPvlTranslationManager.cpp +13 −7 Original line number Diff line number Diff line Loading @@ -104,10 +104,11 @@ namespace Isis { /** * Returns a translated value. The output name is used to find the input * group, keyword, default and tranlations in the translation table. If the * keyword does not exist in the input label, the input default if * available will be used as the input value. This input value * is then used to search all of the translations. If a match is * found the translated value is returned. * keyword does not exist in the input label and an input * default is available, then this default will be used as the * input value. This input value is then used to search all of * the translations. If a match is found the translated value is * returned. * * @param nName The output name used to identify the input keyword to be * translated. Loading Loading @@ -136,7 +137,12 @@ namespace Isis { /** * Translate the requested output name to output values using the input name * and values or default value * and values or default value. * * Note: This is a protected method used when automatically * translating * * @see Auto(). * * @param nName The output name used to identify the input keyword to be * translated. Loading
isis/src/base/objs/PvlToPvlTranslationManager/PvlToPvlTranslationManager.h +20 −26 Original line number Diff line number Diff line Loading @@ -44,42 +44,36 @@ namespace Isis { * @author 2003-05-29 Stuart Sides * * @internal * @history 2003-09-03 Stuart Sides - Modified to work with new isis label * format * @history 2003-09-25 Stuart Sides - Added the Translate member * @history 2005-02-15 Elizabeth Ribelin - Modified file to support Doxygen * documentation * @history 2006-08-09 Brendan George - Modified to support Optional keyword * translation * @history 2003-09-03 Stuart Sides - Modified to work with new isis label format. * @history 2003-09-25 Stuart Sides - Added the Translate member. * @history 2005-02-15 Elizabeth Ribelin - Modified file to support Doxygen documentation. * @history 2006-08-09 Brendan George - Modified to support Optional keyword translation. * @history 2006-10-01 Stuart Sides - Fixed bug with Optional keyword. * Non-optional keywords were being reported * instantly. * Non-optional keywords were being reported instantly. * @history 2006-11-16 Brendan George - Changed instances of "Foreign" to "Input" * and "Native" to "Output" * and "Native" to "Output". * @history 2007-06-22 Stuart Sides - Added ability to have more than one input location * keyword for a translation. The first one found * which contains the input keyword is used. * keyword for a translation. The first one found which contains * the input keyword is used. * @history 2008-05-09 Steven Lambright - Added ability to change input label without * re-reading the translation file. * @history 2008-07-10 Noah Hilt - Changed while loops to continue searching * other groups if a group has been found, but the keyword does not * exist in that group. * @history 2008-07-10 Steven Lambright - Changed to use new accessors * @history 2008-07-10 Noah Hilt - Changed while loops to continue searching other groups * if a group has been found, but the keyword does not exist in * that group. * @history 2008-07-10 Steven Lambright - Changed to use new accessors. * @history 2010-01-04 Steven Lambright - Added InputKeyword method and removed * InputSize, InputUnits, InputValue. * Renamed private Translate method to * DoTranslation to remove ambiguity * with a parent method, instead of * using a dummy parameter. * @history 2017-01-11 Jeannie Backer - Moved several methods to a generic * parent class, LabelTranslationManager. Fixes #4584. * InputSize, InputUnits, InputValue. Renamed private Translate() method * to DoTranslation() to remove ambiguity with a parent method, * instead of using a dummy parameter. * @history 2017-01-11 Jeannie Backer - Moved several methods to a generic parent class, * LabelTranslationManager. Fixes #4584. * @history 2017-06-13 Adam Paquette - Changed PvlTranslationManager file name to * PvlToPvlTranslationManager. Fixes #4901. * @history 2018-01-10 Christopher Combs - Changed ProcessDataFilePointer call to reflect * changes made to voy2isis. Fixes #4345, #4421. * @todo 2005-02-15 Stuart Sides - add coded example and implementation example * to class documentation, and finish * documentation * documentation. */ class PvlToPvlTranslationManager : public LabelTranslationManager { public: Loading
isis/src/base/objs/PvlTranslationTable/PvlTranslationTable.cpp +199 −140 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <fstream> #include <sstream> #include <QDebug> #include "IException.h" #include "IString.h" #include "Message.h" Loading @@ -37,7 +39,7 @@ namespace Isis { * * @param transFile The translation file to be used * * @throws iException::Io * @throws IException::Io */ PvlTranslationTable::PvlTranslationTable(FileName transFile) { AddTable(transFile.expanded()); Loading @@ -54,23 +56,39 @@ namespace Isis { } //! Construct an empty PvlTranslationTable /** * Construct an empty PvlTranslationTable */ PvlTranslationTable::PvlTranslationTable() { } //! Destroys the PvlTranslationTable object. /** * Destroys the PvlTranslationTable object. */ PvlTranslationTable::~PvlTranslationTable() { } //! Protected accessor for pvl translation table passed into class. /** * Protected accessor for pvl translation table passed into * class. This method returns a reference to the translation * table member. * * @return @b Pvl The translation table as a PVL object. */ Pvl &PvlTranslationTable::TranslationTable() { return p_trnsTbl; } //! Protected accessor for const pvl translation table passed into class. /** * Protected accessor for const pvl translation table passed * into class. This method returns a @b const reference to the * translation table member. * * @return @b Pvl The translation table as a PVL object. */ const Pvl &PvlTranslationTable::TranslationTable() const { return p_trnsTbl; } Loading Loading @@ -103,20 +121,20 @@ namespace Isis { vector< pair<QString, int> > validKeywordSizes = validKeywords(); for (int i = 0; i < p_trnsTbl.groups(); i++) { PvlGroup currGrp = p_trnsTbl.group(i); PvlGroup currGroup = p_trnsTbl.group(i); if(!currGrp.hasKeyword("InputKey")) { if (!currGroup.hasKeyword("InputKey")) { QString message = "Unable to find InputKey for group [" + currGrp.name() + "] in file [" + + currGroup.name() + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::User, message, _FILEINFO_); } for(int j = 0; j < currGrp.keywords(); j++) { for (int j = 0; j < currGroup.keywords(); j++) { bool validKeyword = false; bool keywordSizeMismatch = false; const PvlKeyword &currKey = currGrp[j]; const PvlKeyword &currKey = currGroup[j]; // Test this keyword for validity for (int key = 0; Loading Loading @@ -184,53 +202,53 @@ namespace Isis { validKeywords.push_back(pair<QString, int>("Optional", 0)); validKeywords.push_back(pair<QString, int>("InputKey", 1)); validKeywords.push_back(pair<QString, int>("InputDefault", -1)); validKeywords.push_back(pair<QString, int>("InputKeyDependencies", -1)); return validKeywords; } /** * Translates the output name and input value. * Translates a single output value from the given translation * group name and input value. * * @param nName The output name to be used to search the translation table. * @param fValue The input value to be translated * @param translationGroupName The name of the pvl translation * group. Often, this is the same * as the output keyword name. * @param inputKeyValue The value to be translated, from the * input keyword. * * @return QString The translated QString * @return QString The translated value, for the * output keyword. * * @throws iException::Programmer * @throws IException::Programmer */ QString PvlTranslationTable::Translate(const QString nName, const QString fValue) const { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } QString PvlTranslationTable::Translate(const QString translationGroupName, const QString inputKeyValue) const { const PvlGroup &tgrp = p_trnsTbl.findGroup(nName); const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); // If no input value was passed in search using the input default QString tmpFValue = fValue; QString tmpFValue = inputKeyValue; if (tmpFValue.isEmpty()) { if(tgrp.hasKeyword("InputDefault")) { tmpFValue = (QString) tgrp["InputDefault"]; if (translationGroup.hasKeyword("InputDefault")) { tmpFValue = (QString) translationGroup["InputDefault"]; } else { QString msg = "No value or default value to translate for "; msg += "translation group ["; msg += nName; msg += translationGroupName; msg += "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } } // Search the Translation keywords for a match to the input value Pvl::ConstPvlKeywordIterator it = tgrp.findKeyword("Translation", tgrp.begin(), tgrp.end()); Pvl::ConstPvlKeywordIterator it = translationGroup.findKeyword("Translation", translationGroup.begin(), translationGroup.end()); while(it != tgrp.end()) { while (it != translationGroup.end()) { const PvlKeyword &key = *it; // compare the value from the input file to the second value of each Translation in the trans file. // ignore cases for input values Loading @@ -246,11 +264,11 @@ namespace Isis { } } it = tgrp.findKeyword("Translation", it + 1, tgrp.end()); it = translationGroup.findKeyword("Translation", it + 1, translationGroup.end()); } QString msg = "Unable to find a translation value for [" + nName + ", " + fValue + "] in file [" + translationGroupName + ", " + inputKeyValue + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); Loading @@ -261,41 +279,35 @@ namespace Isis { * Returns the input group name from the translation table corresponding to * the output name argument. * * @param nName The output name to be used to search the translation table. * @param translationGroupName The output name to be used to search the translation table. * @param inst The occurence number of the "InputGroup" keyword * (first one is zero) * * @return QString The input group name * * @throws iException::Programmer * @throws IException::Programmer */ PvlKeyword PvlTranslationTable::InputGroup(const QString nName, PvlKeyword PvlTranslationTable::InputGroup(const QString translationGroupName, const int inst) const { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } const PvlGroup &transGrp = p_trnsTbl.findGroup(nName); const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); //bool foundLegalInputGroup = false; Pvl::ConstPvlKeywordIterator it = transGrp.findKeyword("InputPosition", transGrp.begin(), transGrp.end()); Pvl::ConstPvlKeywordIterator it = translationGroup.findKeyword("InputPosition", translationGroup.begin(), translationGroup.end()); int currentInstance = 0; // If no InputPosition keyword exists, the answer is root if(inst == 0 && it == transGrp.end()) { if (inst == 0 && it == translationGroup.end()) { PvlKeyword root("InputPosition"); root += "ROOT"; return root; } while(it != transGrp.end()) { while (it != translationGroup.end()) { const PvlKeyword &result = *it; // This check is to prevent backtracking to the old "value,value" way of Loading @@ -318,17 +330,17 @@ namespace Isis { currentInstance ++; } it = transGrp.findKeyword("InputPosition", it + 1, transGrp.end()); it = translationGroup.findKeyword("InputPosition", it + 1, translationGroup.end()); } /* Error if no containers were listed if (!foundLegalInputGroup) { QString msg = "No input position found for translation ["; msg += nName; msg += translationGroupName; msg += "] in translation file ["; msg += p_trnsTbl.FileName(); msg += "]"; throw iException::Message(iException::Programmer, msg, _FILEINFO_); throw IException::Message(IException::Programmer, msg, _FILEINFO_); }*/ PvlKeyword empty; Loading @@ -340,22 +352,17 @@ namespace Isis { * Returns the input keyword name from the translation table corresponding to * the output name argument. * * @param nName The output name to be used to search the translation table. * @param translationGroupName The output name to be used to search the translation table. * * @return QString The input keyword name * * @throws iException::Programmer * @throws IException::Programmer */ QString PvlTranslationTable::InputKeywordName(const QString nName) const { QString PvlTranslationTable::InputKeywordName(const QString translationGroupName) const { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); PvlGroup tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("InputKey")) return tgrp["InputKey"]; if (translationGroup.hasKeyword("InputKey")) return translationGroup["InputKey"]; return ""; } Loading @@ -365,97 +372,149 @@ namespace Isis { * Returns the input default value from the translation table corresponding * to the output name argument. * * @param nName The output name to be used to search the translation table. * @param translationGroupName The output name to be used to search the translation table. * * @return QString The input default value * * @throws iException::Programmer * @throws IException::Programmer */ QString PvlTranslationTable::InputDefault(const QString nName) const { QString PvlTranslationTable::InputDefault(const QString translationGroupName) const { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); PvlGroup tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("InputDefault")) return tgrp["InputDefault"]; if (translationGroup.hasKeyword("InputDefault")) return translationGroup["InputDefault"]; return ""; } bool PvlTranslationTable::hasInputDefault(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlGroup &tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("InputDefault")) return true; /** * Determines whether the given group has a default input value. * This method returns true if the translation group contains a * PvlKeyword with the name "InputDefault". Note: no value needs * to be assigned to this keyword. * * @param translationGroupName The name of the PVL translation group. * * @return bool Indicates whether the given group has an * InputDefault keyword. */ bool PvlTranslationTable::hasInputDefault(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); if (translationGroup.hasKeyword("InputDefault")) return true; return false; } bool PvlTranslationTable::IsAuto(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlGroup &tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("Auto")) return true; /** * Determines whether the given group should be automatically * translated. This method returns true if the translation * group contains a PvlKeyword with the name "Auto". Note: * no value is assigned to this keyword. * * @param translationGroupName The name of the PVL translation group. * * @return bool Indicates whether the given group has an Auto * keyword. */ bool PvlTranslationTable::IsAuto(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); if (translationGroup.hasKeyword("Auto")) return true; return false; } bool PvlTranslationTable::IsOptional(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlGroup &tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("Optional")) return true; /** * Determines whether the translation group is optional. This * method returns true if the translation group contains a * PvlKeyword with the name "Optional". Note: no value is * assigned to this keyword. * * @param translationGroupName The name of the PVL translation group. * * @return bool Indicates whether the given group has an * Optional keyword. */ bool PvlTranslationTable::IsOptional(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); if (translationGroup.hasKeyword("Optional")) return true; return false; } PvlKeyword &PvlTranslationTable::OutputPosition(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlGroup &tgrp = p_trnsTbl.findGroup(nName); if(!tgrp.hasKeyword("OutputPosition")) { /** * Retrieves the OutputPosition PvlKeyword for the translation * group with the given name. * * @param translationGroupName The name of the PVL translation group. * * @return PvlKeyword The OutputPosition keyword from the given * translation group. */ PvlKeyword PvlTranslationTable::OutputPosition(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); if (!translationGroup.hasKeyword("OutputPosition")) { QString msg = "Unable to find translation keyword [OutputPostion] in [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; translationGroupName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } return tgrp["OutputPosition"]; return translationGroup["OutputPosition"]; } QString PvlTranslationTable::OutputName(const QString nName) { if(!p_trnsTbl.hasGroup(nName)) { QString msg = "Unable to find translation group [" + nName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } /** * Retrieves a string containing the value of the OutputName * keyword for the translation group with the given name. * * @param translationGroupName The name of the PVL translation group. * * @return @b QString The value of the OutputName keyword from * the given translation group. */ QString PvlTranslationTable::OutputName(const QString translationGroupName) { const PvlGroup &translationGroup = findTranslationGroup(translationGroupName); PvlGroup tgrp = p_trnsTbl.findGroup(nName); if(tgrp.hasKeyword("OutputName")) { return tgrp["OutputName"]; if (translationGroup.hasKeyword("OutputName")) { return translationGroup["OutputName"]; } return ""; } /** * Searches for translation group with the given name. * * @see PvlObject::findGroup() * * @param translationGroupName Name of the PVL group to search for. * * @return const PvlGroup& The first PVL group with the given name. * * @throws IException::Programmer - "Unable to find translation * group in file." */ const PvlGroup &PvlTranslationTable::findTranslationGroup(const QString translationGroupName) const { if (!p_trnsTbl.hasGroup(translationGroupName)) { QString msg = "Unable to find translation group [" + translationGroupName + "] in file [" + p_trnsTbl.fileName() + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } return p_trnsTbl.findGroup(translationGroupName); } } // end namespace isis
isis/src/base/objs/PvlTranslationTable/PvlTranslationTable.h +12 −9 File changed.Preview size limit exceeded, changes collapsed. Show changes
isis/src/base/objs/XmlToPvlTranslationManager/XmlToPvlTranslationManager.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -240,6 +240,7 @@ namespace Isis { cout << endl << "Finding input element:" << endl << endl; cout << inputParentElement.tagName() << endl; } // traverse the input position path for (int i = 0; i < inputPosition.size(); i++) { QString childName = inputPosition[i]; inputParentElement = inputParentElement.firstChildElement(childName); Loading @@ -265,6 +266,7 @@ namespace Isis { cout << indent << inputParentElement.tagName() << endl; } } // now get input value at given input position path QDomElement inputKeyElement = inputParentElement.firstChildElement(inputKey); if (isDebug) { indent += " "; Loading @@ -289,7 +291,6 @@ namespace Isis { inputKeyElement = inputParentElement.firstChildElement(inputKey); } } // If the parent element is NULL at this point then we traversed every // potential input element and none of them satisfied the dependencies. if ( inputParentElement.isNull() ) { Loading @@ -301,7 +302,8 @@ namespace Isis { return PvlTranslationTable::Translate( outputName ); } else { QString msg = "Could not find an input value or default value."; QString msg = "Could not find an input or default value that fits the given input " "keyword dependencies."; throw IException(IException::Unknown, msg, _FILEINFO_); } } Loading Loading @@ -347,7 +349,8 @@ namespace Isis { * dependencies are requirements on the values of attributes of the element * and/or the values of sibling elements. The dependencies are specified by * strings that are formatted as follows * <code>[tag/att]\@[tagName/attName]:[value]</code> * <code>[tag/att]\@[tagName/attName]|[value]</code> or * <code>[tagName/attName]|[value]</code> * * @param element The element to check dependencies on. * @param dependencies A multi-valued keyword were every entry specifies a Loading