25 #include <QDomDocument> 26 #include <QDomElement> 51 PvlToXmlTranslationManager::PvlToXmlTranslationManager(
const QString &transFile)
65 const QString &transFile)
97 validKeywords.push_back(pair<QString, int>(
"OutputAttributes", -1));
98 validKeywords.push_back(pair<QString, int>(
"OutputSiblings", -1));
125 while((grp =
InputGroup(transGroupName, inst++)).name() !=
"") {
149 QDomElement &parentElement) {
152 QString transGroupName = transGroup.
name();
155 while (grp.
name() !=
"") {
167 QString untranslatedValue = inputKeyword[0];
170 QString units = inputKeyword.
unit();
171 if (outputName.size() == 2 && outputName[0] ==
"att") {
172 parentElement.setAttribute(outputName[1], translatedValue);
173 if (transGroup.
hasKeyword(
"OutputAttributes")) {
178 QDomElement newElement = parentElement.ownerDocument().createElement(outputName[0]);
180 parentElement.appendChild(newElement);
181 if (transGroup.
hasKeyword(
"OutputAttributes")) {
186 if (transGroup.
hasKeyword(
"OutputSiblings")) {
198 QDomElement newElement = parentElement.ownerDocument().createElement(
OutputName(transGroupName));
200 parentElement.appendChild(newElement);
201 if (transGroup.
hasKeyword(
"OutputAttributes")) {
204 if (transGroup.
hasKeyword(
"OutputSiblings")) {
223 QDomDocument &outputLabel) {
243 QDomElement element = outputLabel.documentElement();
271 int instanceNumber = 0;
273 bool anInputGroupFound =
false;
275 while(inputGroupKeyword.
name() !=
"") {
277 if(containingGroup != NULL) {
278 anInputGroupFound =
true;
286 inputGroupKeyword =
InputGroup(transGroupName, instanceNumber);
289 if(anInputGroupFound) {
290 QString msg =
"Unable to find input keyword [" +
InputKeywordName(transGroupName) +
291 "] for output name [" + transGroupName +
"] in file [" +
296 QString container =
"";
299 if(i > 0) container +=
",";
304 QString msg =
"Unable to find input group [" + container +
"] for output name [" +
327 while((grp =
InputGroup(transGroupName, inst++)).name() !=
"") {
349 if(inputGroup.
size() == 1 &&
359 objectIndex < inputGroup.
size() - 1;
361 if(currentObject->
hasObject(inputGroup[objectIndex])) {
362 currentObject = ¤tObject->
findObject(inputGroup[objectIndex]);
370 if(currentObject->
hasObject(inputGroup[objectIndex])) {
371 return ¤tObject->
findObject(inputGroup[objectIndex]);
373 else if(currentObject->
hasGroup(inputGroup[objectIndex])) {
374 return ¤tObject->
findGroup(inputGroup[objectIndex]);
394 QDomElement &xmlRootElement) {
399 QDomElement *currentElement = &xmlRootElement;
404 if (containers.
size() > 0 && currentElement->tagName() == containers[0]) {
409 while (i < containers.
size()) {
415 bool addNewElement =
false;
417 if (specifications.size() == 2 && specifications[0] ==
"new") {
418 addNewElement =
true;
424 QDomElement childElement = xmlRootElement.ownerDocument().createElement(specifications[1]);
425 *currentElement = currentElement->appendChild(childElement).toElement();
429 else if (currentElement->namedItem(containers[i]).isNull()) {
430 QDomElement childElement = xmlRootElement.ownerDocument().createElement(specifications[0]);
431 *currentElement = currentElement->appendChild(childElement).toElement();
436 *currentElement = currentElement->firstChildElement(containers[i]);
440 return currentElement;
454 QDomElement &parent) {
456 for (
int i = 0; i < outputSiblings.
size(); i++) {
458 parsedSibling.reserve(5);
460 if (parsedSibling.size() != 2) {
462 QString msg =
"Malformed OutputSibling [" + outputSiblings[i] +
"]. OutputSiblings must" +
463 " be in the form of tag|value";
467 if (parent.namedItem(parsedSibling[0]).isNull()) {
469 QDomElement childElement = parent.ownerDocument().createElement(parsedSibling[0]);
471 parent.appendChild(childElement).toElement();;
487 QDomElement &element) {
490 for (
int i = 0; i < outputAttributes.
size(); i++) {
493 if (parsedAttribute.size() != 2) {
494 QString msg =
"Malformed output attribute [" + outputAttributes[i] +
495 "]. OutputAttributes must be in the form of att@attribute_name|value";
498 element.setAttribute(parsedAttribute[0], parsedAttribute[1]);
517 QDomElement newElement = parent.ownerDocument().createElement(name);
520 parent.appendChild(newElement).toElement();;
534 QDomText valueText = element.ownerDocument().createTextNode(value);
536 element.appendChild(valueText);
539 element.setAttribute(
"unit", units);
554 element.firstChild().setNodeValue(value);
556 element.setAttribute(
"unit", units);
virtual ~PvlToXmlTranslationManager()
Destroys the TranslationManager object.
virtual QString Translate(QString translationGroupName, int inputIndex=0)
Returns a translated value.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
QString unit(const int index=0) const
Returns the units of measurement of the element of the array of values for the object at the specifie...
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Contains more than one keyword-value pair.
static void addElement(QDomElement &parent, QString name, QString value, QString units="")
Add a QDomElement to the given parent with the indicated value and units.
virtual QStringList parseSpecification(QString specification) const
Parses and validates a dependency specification.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
PvlKeyword OutputPosition(const QString translationGroupName)
Retrieves the OutputPosition PvlKeyword for the translation group with the given name.
Namespace for the standard library.
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
void addAttributes(PvlKeyword something, QDomElement &parent)
Take in the outputAttributes PvlKeyword and add each attribute to the appropriate element given as an...
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
This error is for when a programmer made an API call that was illegal.
PvlToXmlTranslationManager(const QString &transFile)
Constructs and initializes a TranslationManager object from given the Pvl translation file...
QDomElement * createParentElements(const QString translationGroupName, QDomElement &xml)
Read the OutputPosition for the translation group name passed and create any parent elements specifie...
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not...
QString Translate(const QString translationGroupName, const QString inputKeyValue="") const
Translates a single output value from the given translation group name and input value.
QString name() const
Returns the container name.
static void resetElementValue(QDomElement &element, QString value, QString units="")
Reset the QDomElement's value, and units, if units != "".
virtual QString InputKeywordName(const QString translationGroupName) const
Returns the input keyword name from the translation table corresponding to the output name argument...
void doTranslation(PvlGroup transGroup, QDomElement &parent)
Translate the requested output name to output values using the input name and values or default value...
virtual const PvlContainer * GetContainer(const PvlKeyword &inputGroup) const
Return a container from the input label with the path given by the "InputPosition" keyword of the tra...
QString OutputName(const QString translationGroupName)
Retrieves a string containing the value of the OutputName keyword for the translation group with the ...
int size() const
Returns the number of values stored in this keyword.
Pvl & TranslationTable()
Protected accessor for pvl translation table passed into class.
virtual std::vector< std::pair< QString, int > > validKeywords() const
Returns a vector of valid keyword names and their sizes.
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
A single keyword-value pair.
virtual std::vector< std::pair< QString, int > > validKeywords() const
Returns a vector of valid keyword names and their sizes.
static void setElementValue(QDomElement &element, QString value, QString units="")
Set the QDomElement's value, and units, if units != "".
void SetLabel(Pvl &inputLabel)
Internalizes a Pvl formatted label for translation.
Container for cube-like labels.
virtual bool InputHasKeyword(const QString translationGroupName)
Indicates if the input keyword corresponding to the output name exists in the label.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
PvlGroup & group(const int index)
Return the group at the specified index.
void addSiblings(PvlKeyword outputSiblings, QDomElement &parent)
Take in outputSiblings PvlKeyword and turn each sibling into its corresponding QDomElement.
Pvl m_inputLabel
A Pvl object for the input label file.
QString fileName() const
Returns the filename used to initialise the Pvl object.
QString name() const
Returns the keyword name.
void Auto(QDomDocument &outputLabel)
Automatically translate all the output names found in the translation table.
Namespace for ISIS/Bullet specific routines.
bool IsOptional(const QString translationGroupName)
Determines whether the translation group is optional.
Allows applications to translate simple text files.
int groups() const
Returns the number of groups contained.
virtual const PvlKeyword & InputKeyword(const QString translationGroupName) const
Uses the translation file group name to find the input label's PvlKeyword that corresponds to the Inp...
Contains Pvl Groups and Pvl Objects.
virtual PvlKeyword InputGroup(const QString translationGroupName, const int inst=0) const
Returns the input group name from the translation table corresponding to the output name argument...
bool IsAuto(const QString translationGroupName)
Determines whether the given group should be automatically translated.