Commit 4cf717fb authored by chrisryancombs's avatar chrisryancombs Committed by Makayla Shepherd
Browse files

Changed spiceserver's packageKernels to write Json instead of Xml. Added tableToJson method.

parent cb1e6d8f
Loading
Loading
Loading
Loading
+65 −26
Original line number Diff line number Diff line
@@ -7,8 +7,11 @@
#include <QDomElement>
#include <QDomNode>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <QStringList>
#include <QTextStream>

#include "Camera.h"
#include "CameraFactory.h"
@@ -523,6 +526,15 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
  return true;
}

QJsonValue tableToJson(QString file) {
  QFile tableFile(file);
  tableFile.open(QIODevice::ReadOnly);
  QByteArray data = tableFile.readAll();
  tableFile.close();

  return QJsonValue::fromVariant(data.toHex().constData());
}


QString tableToXml(QString tableName, QString file) {
  QString xml;
@@ -606,40 +618,67 @@ void parseParameters(QDomElement parametersElement) {


void packageKernels(QString toFile) {
  QString xml;
  xml += "<spice_data>\n";

  xml += "  <application_log>\n";
  QJsonObject spiceData;

  QString logFile(toFile + ".print");
  Pvl logMessage(logFile);
  QFile::remove(logFile);
  stringstream logStream;
  logStream << logMessage;
  xml += QString( QByteArray( logStream.str().c_str() ).toHex().constData() ) + "\n";
  xml += "  </application_log>\n";

  xml += "  <kernels_label>\n";
  QString logText = QString( QByteArray( logStream.str().c_str() ).toHex().constData() );
  spiceData.insert("Application Log", QJsonValue::fromVariant(logText));

  QString kernLabelsFile(toFile + ".lab");
  Pvl kernLabels(kernLabelsFile);
  QFile::remove(kernLabelsFile);
  stringstream labelStream;
  labelStream << kernLabels;

  xml += QString( QByteArray( labelStream.str().c_str() ).toHex().constData() ) + "\n";

  xml += "  </kernels_label>\n";

  xml += "  <tables>\n";
  xml += tableToXml("instrument_pointing", toFile + ".pointing");
  xml += tableToXml("instrument_position", toFile + ".position");
  xml += tableToXml("body_rotation", toFile + ".bodyrot");
  xml += tableToXml("sun_position", toFile + ".sun");

  xml += "  </tables>\n";
  xml += "</spice_data>\n";
  QString encodedXml( QByteArray( xml.toLatin1() ).toHex().constData() );
  QString labelText = QString( QByteArray( labelStream.str().c_str() ).toHex().constData() );
  spiceData.insert("Kernels Label", QJsonValue::fromVariant(labelText));

  QJsonObject tables;
  tables.insert("Instrument Pointing", tableToJson(toFile + ".pointing"));
  tables.insert("Instrument Position", tableToJson(toFile + ".position"));
  tables.insert("Body Rotation", tableToJson(toFile + ".bodyrot"));
  tables.insert("Sun Position", tableToJson(toFile + ".sun"));
  spiceData.insert("Tables", tables);

  QJsonDocument doc(spiceData);

  // QString xml;
  // xml += "<spice_data>\n";
  //
  // xml += "  <application_log>\n";
  //
  // QString logFile(toFile + ".print");
  // Pvl logMessage(logFile);
  // QFile::remove(logFile);
  // stringstream logStream;
  // logStream << logMessage;
  // xml += QString( QByteArray( logStream.str().c_str() ).toHex().constData() ) + "\n";
  // xml += "  </application_log>\n";
  //
  // xml += "  <kernels_label>\n";
  //
  // QString kernLabelsFile(toFile + ".lab");
  // Pvl kernLabels(kernLabelsFile);
  // QFile::remove(kernLabelsFile);
  // stringstream labelStream;
  // labelStream << kernLabels;
  //
  // xml += QString( QByteArray( labelStream.str().c_str() ).toHex().constData() ) + "\n";
  //
  // xml += "  </kernels_label>\n";
  //
  // xml += "  <tables>\n";
  // xml += tableToXml("instrument_pointing", toFile + ".pointing");
  // xml += tableToXml("instrument_position", toFile + ".position");
  // xml += tableToXml("body_rotation", toFile + ".bodyrot");
  // xml += tableToXml("sun_position", toFile + ".sun");
  //
  // xml += "  </tables>\n";
  // xml += "</spice_data>\n";
  QString encodedXml( QByteArray( doc.toJson().toLatin1() ).toHex().constData() );

  QFile finalOutput(toFile);
  finalOutput.open(QIODevice::WriteOnly);