File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
LabelTranslationManager.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "PvlTranslationTable.h"
8 
9 #include "IException.h"
10 #include "IString.h"
11 #include "LabelTranslationManager.h"
12 #include "Message.h"
13 #include "Pvl.h"
14 #include "PvlContainer.h"
15 #include "PvlGroup.h"
16 #include "PvlKeyword.h"
17 #include "PvlObject.h"
18 
19 using namespace std;
20 namespace Isis {
21 
25  LabelTranslationManager::LabelTranslationManager()
27  }
28 
29 
37  AddTable(transFile);
38  }
39 
40 
49  AddTable(transStrm);
50  }
51 
52 
57  }
58 
59 
70  void LabelTranslationManager::Auto(Pvl &outputLabel) {
71  // Attempt to translate every group in the translation table
72  for(int i = 0; i < TranslationTable().groups(); i++) {
74  if(IsAuto(g.name())) {
75  try {
76  PvlContainer *con = CreateContainer(g.name(), outputLabel);
77  (*con) += DoTranslation(g.name());
78  }
79  catch(IException &e) {
80  if(!IsOptional(g.name())) {
81  throw e;//??? is this needed???
82  }
83  }
84  }
85  }
86  }
87 
88 
100  PvlContainer *LabelTranslationManager::CreateContainer(const QString translationGroupName,
101  Pvl &pvl) {
102 
103  // Get the array of Objects/Groups from the OutputName keyword
104  PvlKeyword np = OutputPosition(translationGroupName);
105 
106  PvlObject *obj = &pvl;
107 
108  // Look at every pair in the output position
109  for(int c = 0; c < np.size(); c += 2) {
110  // If this pair is an object
111  if(np[c].toUpper() == "OBJECT") {
112  // If the object doesn't exist create it
113  if(!obj->hasObject(np[c+1])) {
114  obj->addObject(np[c+1]);
115  }
116  obj = &(obj->findObject(np[c+1]));
117  }
118  // If this pair is a group
119  else if(np[c].toUpper() == "GROUP") {
120  // If the group doesn't exist create it
121  if(!obj->hasGroup(np[c+1])) {
122  obj->addGroup(np[c+1]);
123  }
124  return (PvlContainer *) & (obj->findGroup(np[c+1]));
125 
126  }
127  }
128 
129  return (PvlContainer *) obj;
130  }
131 
132 
145  PvlKeyword outputKeyword( outputName, Translate(outputName) );
146  return outputKeyword;
147  }
148 
149 
173 
174  QStringList parsedSpecification;
175 
176  try {
177  QStringList typeSplit = specification.split("@", QString::SkipEmptyParts);
178  QStringList barSplit = specification.split("|", QString::SkipEmptyParts);
179 
180  if (typeSplit.size() == 2) { //handle tag@elementname|value
181  if (typeSplit[0].toLower() != "att" &&
182  typeSplit[0].toLower() != "tag" &&
183  typeSplit[0].toLower() != "new") {
184  QString msg = "Dependency type specification [" + typeSplit[0] +
185  "] is invalid. Valid types are [att], [tag] and [new]";
186  throw IException(IException::Programmer, msg, _FILEINFO_);
187  }
188  parsedSpecification.append(typeSplit[0].toLower());
189 
190  QStringList nameValueSplit = typeSplit[1].split("|", QString::SkipEmptyParts);
191  if (nameValueSplit.size() == 2) {
192  parsedSpecification.append(nameValueSplit);
193  }
194  else if (nameValueSplit.size() == 1) {
195  parsedSpecification.append(nameValueSplit);
196  }
197  else { //nameValueSplit is an unexpected value
198  QString msg = "Malformed dependency specification [" + specification + "].";
199  throw IException(IException::Programmer, msg, _FILEINFO_);
200  }
201  }
202  else if (barSplit.size() == 2) { //handle elementname|value
203  parsedSpecification = barSplit;
204  }
205  else if (barSplit.size() == 1 && typeSplit.size() == 1) { //handle value with no "@" or "|" characters
206  parsedSpecification = barSplit;
207  }
208  else { //nameValueSplit is an unexpected value
209  QString msg = " [" + specification + "] has unexpected number of '@' or '|' delimiters";
210  throw IException(IException::Programmer,msg, _FILEINFO_);
211  }
212  }
213 
214  catch (IException &e) {
215  QString msg = "Malformed dependency specification [" + specification + "].";
216  throw IException(e, IException::Programmer, msg, _FILEINFO_);
217  }
218 
219  return parsedSpecification;
220 }
221 
222 } // end namespace isis
Isis::LabelTranslationManager::parseSpecification
virtual QStringList parseSpecification(QString specification) const
Parses and validates a dependency specification.
Definition: LabelTranslationManager.cpp:172
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::PvlObject::group
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:452
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::LabelTranslationManager::DoTranslation
virtual PvlKeyword DoTranslation(const QString translationGroupName)
Translate the requested output name to output values using the input name and values or default value...
Definition: LabelTranslationManager.cpp:144
Isis::PvlObject::groups
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:75
Isis::PvlTranslationTable
Internalizes a translation table.
Definition: PvlTranslationTable.h:106
Isis::PvlTranslationTable::AddTable
void AddTable(std::istream &transStm)
Adds the contents of a translation table to the searchable groups/keys Also performs a verification,...
Definition: PvlTranslationTable.cpp:102
Isis::PvlObject::hasGroup
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
Definition: PvlObject.h:210
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::PvlObject::addObject
void addObject(const PvlObject &object)
Add a PvlObject.
Definition: PvlObject.h:307
QStringList
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::LabelTranslationManager::LabelTranslationManager
LabelTranslationManager()
Constructs a default LabelTranslationManager.
Definition: LabelTranslationManager.cpp:25
Isis::LabelTranslationManager::CreateContainer
virtual PvlContainer * CreateContainer(const QString translationGroupName, Pvl &pvl)
Creates all parent PVL containers for an output keyword.
Definition: LabelTranslationManager.cpp:100
Isis::PvlTranslationTable::OutputPosition
PvlKeyword OutputPosition(const QString translationGroupName)
Retrieves the OutputPosition PvlKeyword for the translation group with the given name.
Definition: PvlTranslationTable.cpp:483
Isis::PvlObject::findObject
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:274
Isis::LabelTranslationManager::Auto
virtual void Auto(Pvl &outputLabel)
Automatically translate all the output names tagged as Auto in the translation table If a output name...
Definition: LabelTranslationManager.cpp:70
Isis::PvlContainer::name
QString name() const
Returns the container name.
Definition: PvlContainer.h:63
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::PvlObject::hasObject
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not.
Definition: PvlObject.h:323
Isis::PvlObject::addGroup
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:186
Isis::PvlTranslationTable::IsAuto
bool IsAuto(const QString translationGroupName)
Determines whether the given group should be automatically translated.
Definition: PvlTranslationTable.cpp:432
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::PvlKeyword::size
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:125
Isis::PvlTranslationTable::IsOptional
bool IsOptional(const QString translationGroupName)
Determines whether the translation group is optional.
Definition: PvlTranslationTable.cpp:457
Isis::PvlContainer
Contains more than one keyword-value pair.
Definition: PvlContainer.h:49
Isis::LabelTranslationManager::~LabelTranslationManager
virtual ~LabelTranslationManager()
Destroys the LabelTranslationManager object.
Definition: LabelTranslationManager.cpp:56
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::PvlTranslationTable::TranslationTable
Pvl & TranslationTable()
Protected accessor for pvl translation table passed into class.
Definition: PvlTranslationTable.cpp:62

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:46