mirror of
https://github.com/nasa/trick.git
synced 2024-12-19 13:17:55 +00:00
Refactoring in trkConvert (#649)
* refactoring: DocWindow constructor to take datalog rather than filename. * Neatening DocWindow.cpp
This commit is contained in:
parent
951aae4be4
commit
6f82d11122
@ -14,72 +14,68 @@
|
|||||||
#include "CSV_Formatter.hh"
|
#include "CSV_Formatter.hh"
|
||||||
#include "Varlist_Formatter.hh"
|
#include "Varlist_Formatter.hh"
|
||||||
|
|
||||||
// Notes:
|
DocWindow::DocWindow(TRK_DataLog* data_log )
|
||||||
// Need to be able to search for a variable by pattern.
|
|
||||||
// Use a QLineEdit widget for the text box.
|
|
||||||
|
|
||||||
DocWindow::DocWindow(const QString &name)
|
|
||||||
: QMainWindow( 0, 0) {
|
: QMainWindow( 0, 0) {
|
||||||
|
|
||||||
QTextStream out(stdout);
|
QTextStream out(stdout);
|
||||||
|
|
||||||
foundItemIndex = 0;
|
foundItemIndex = 0;
|
||||||
|
datalog = data_log;
|
||||||
|
|
||||||
trkFileName = name;
|
// Build the FILE menu
|
||||||
|
|
||||||
// Build the Menus
|
|
||||||
QAction * fileLoadAction = new QAction( "&Open File...", this );
|
|
||||||
fileLoadAction->setShortcut(tr("CTRL+O"));
|
|
||||||
connect( fileLoadAction, &QAction::triggered , this, &DocWindow::load );
|
|
||||||
|
|
||||||
QAction * csvSaveAction = new QAction( "&Export as CSV...", this );
|
|
||||||
connect( csvSaveAction, &QAction::triggered, this, &DocWindow::saveAsCSV );
|
|
||||||
|
|
||||||
QAction * varListSaveAction = new QAction( "&Export as Variable List...", this );
|
|
||||||
connect( varListSaveAction, &QAction::triggered, this, &DocWindow::saveAsVarList );
|
|
||||||
|
|
||||||
QMenu *fileMenu = menuBar()->addMenu("&File");
|
QMenu *fileMenu = menuBar()->addMenu("&File");
|
||||||
|
|
||||||
|
QAction * fileLoadAction = new QAction( "&Open File...", this );
|
||||||
|
fileLoadAction->setShortcut(tr("CTRL+O"));
|
||||||
fileMenu->addAction(fileLoadAction);
|
fileMenu->addAction(fileLoadAction);
|
||||||
|
connect( fileLoadAction, &QAction::triggered , this, &DocWindow::load );
|
||||||
|
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
|
|
||||||
|
QAction * csvSaveAction = new QAction( "&Export as CSV...", this );
|
||||||
fileMenu->addAction(csvSaveAction);
|
fileMenu->addAction(csvSaveAction);
|
||||||
|
connect( csvSaveAction, &QAction::triggered, this, &DocWindow::saveAsCSV );
|
||||||
|
|
||||||
|
QAction * varListSaveAction = new QAction( "&Export as Variable List...", this );
|
||||||
fileMenu->addAction(varListSaveAction);
|
fileMenu->addAction(varListSaveAction);
|
||||||
|
connect( varListSaveAction, &QAction::triggered, this, &DocWindow::saveAsVarList );
|
||||||
|
|
||||||
|
// Build the EDIT menu
|
||||||
QAction * editSelectAction = new QAction( "&Select All", this );
|
|
||||||
editSelectAction->setShortcut(tr("CTRL+A"));
|
|
||||||
connect( editSelectAction, &QAction::triggered, this, &DocWindow::checkAll );
|
|
||||||
|
|
||||||
QAction * editClearAction = new QAction( "&Clear All", this );
|
|
||||||
connect( editClearAction, &QAction::triggered, this, &DocWindow::unCheckAll );
|
|
||||||
|
|
||||||
QMenu *editMenu = menuBar()->addMenu("&Edit");
|
QMenu *editMenu = menuBar()->addMenu("&Edit");
|
||||||
|
|
||||||
|
QAction * editSelectAction = new QAction( "&Select All", this );
|
||||||
|
editSelectAction->setShortcut(tr("CTRL+A"));
|
||||||
editMenu->addAction(editSelectAction);
|
editMenu->addAction(editSelectAction);
|
||||||
|
connect( editSelectAction, &QAction::triggered, this, &DocWindow::checkAll );
|
||||||
|
|
||||||
|
QAction * editClearAction = new QAction( "&Clear All", this );
|
||||||
editMenu->addAction(editClearAction);
|
editMenu->addAction(editClearAction);
|
||||||
|
connect( editClearAction, &QAction::triggered, this, &DocWindow::unCheckAll );
|
||||||
|
|
||||||
|
// Build the search interface.
|
||||||
|
|
||||||
QHBoxLayout *hbox = new QHBoxLayout();
|
QHBoxLayout *hbox = new QHBoxLayout();
|
||||||
|
|
||||||
QPushButton *backward = new QPushButton(QChar(0x25C0), this);
|
QPushButton *backward = new QPushButton(QChar(0x25C0), this);
|
||||||
|
hbox->addWidget(backward);
|
||||||
connect( backward, &QPushButton::released, this, &DocWindow::findAgainBackward);
|
connect( backward, &QPushButton::released, this, &DocWindow::findAgainBackward);
|
||||||
|
|
||||||
QPushButton *forward = new QPushButton(QChar(0x25B6), this);
|
QPushButton *forward = new QPushButton(QChar(0x25B6), this);
|
||||||
|
hbox->addWidget(forward);
|
||||||
connect( forward, &QPushButton::released, this, &DocWindow::findAgainForward);
|
connect( forward, &QPushButton::released, this, &DocWindow::findAgainForward);
|
||||||
|
|
||||||
searchLineEdit = new QLineEdit;
|
searchLineEdit = new QLineEdit;
|
||||||
searchLineEdit->setPlaceholderText("Search Pattern");
|
searchLineEdit->setPlaceholderText("Search Pattern");
|
||||||
connect(searchLineEdit, SIGNAL(returnPressed()), this, SLOT(find()));
|
|
||||||
|
|
||||||
hbox->addWidget(backward);
|
|
||||||
hbox->addWidget(forward);
|
|
||||||
hbox->addWidget(searchLineEdit);
|
hbox->addWidget(searchLineEdit);
|
||||||
|
connect(searchLineEdit, SIGNAL(returnPressed()), this, SLOT(find()));
|
||||||
|
|
||||||
QVBoxLayout *vbox = new QVBoxLayout();
|
QVBoxLayout *vbox = new QVBoxLayout();
|
||||||
|
|
||||||
// Build the Table Widget that displays the variable names, types, and units.
|
// Build the Table Widget that displays the variable names, types, and units.
|
||||||
varTable = new VarTableWidget(this);
|
varTable = new VarTableWidget(this);
|
||||||
|
|
||||||
datalog = new TRK_DataLog( trkFileName.toStdString().c_str() );
|
|
||||||
int recordCount = datalog->parameterCount();
|
int recordCount = datalog->parameterCount();
|
||||||
for (int ii = 0; ii < recordCount; ii++) {
|
for (int ii = 0; ii < recordCount; ii++) {
|
||||||
varTable->addRecord( Qt::Checked,
|
varTable->addRecord( Qt::Checked,
|
||||||
@ -104,8 +100,11 @@ void DocWindow::load() {
|
|||||||
newFileName = QFileDialog::getOpenFileName(this,
|
newFileName = QFileDialog::getOpenFileName(this,
|
||||||
tr("Open Data File"), ".", tr("Data Files (*.trk)"));
|
tr("Open Data File"), ".", tr("Data Files (*.trk)"));
|
||||||
|
|
||||||
|
QFileInfo trkFileInfo( newFileName);
|
||||||
|
TRK_DataLog* newdatalog = new TRK_DataLog( trkFileInfo.absoluteFilePath().toStdString());
|
||||||
|
|
||||||
if (!newFileName.isEmpty()) {
|
if (!newFileName.isEmpty()) {
|
||||||
DocWindow* w = new DocWindow(newFileName);
|
DocWindow* w = new DocWindow(newdatalog);
|
||||||
w->setWindowTitle(newFileName);
|
w->setWindowTitle(newFileName);
|
||||||
w->resize(800, 500);
|
w->resize(800, 500);
|
||||||
w->show();
|
w->show();
|
||||||
@ -114,7 +113,7 @@ void DocWindow::load() {
|
|||||||
|
|
||||||
void DocWindow::formattedSave(LogFormatter &formatter) {
|
void DocWindow::formattedSave(LogFormatter &formatter) {
|
||||||
|
|
||||||
QFileInfo trkFileInfo( trkFileName);
|
QFileInfo trkFileInfo( datalog->getFileName().c_str());
|
||||||
|
|
||||||
QString outFileName = trkFileInfo.canonicalPath();
|
QString outFileName = trkFileInfo.canonicalPath();
|
||||||
outFileName += "/";
|
outFileName += "/";
|
||||||
|
@ -10,7 +10,7 @@ class DocWindow : public QMainWindow {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DocWindow(const QString &name);
|
DocWindow(TRK_DataLog* data_log );
|
||||||
~DocWindow(){};
|
~DocWindow(){};
|
||||||
|
|
||||||
void formattedSave(LogFormatter &formatter);
|
void formattedSave(LogFormatter &formatter);
|
||||||
@ -30,9 +30,8 @@ class DocWindow : public QMainWindow {
|
|||||||
void findAgainBackward();
|
void findAgainBackward();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString searchPattern;
|
|
||||||
int foundItemIndex;
|
int foundItemIndex;
|
||||||
QString trkFileName;
|
QString searchPattern;
|
||||||
QLineEdit* searchLineEdit;
|
QLineEdit* searchLineEdit;
|
||||||
VarTableWidget* varTable;
|
VarTableWidget* varTable;
|
||||||
TRK_DataLog* datalog;
|
TRK_DataLog* datalog;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "TRK_DataLog.hh"
|
#include "TRK_DataLog.hh"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
@ -63,10 +64,10 @@ const char* TypeName[] = {
|
|||||||
const int TRK_DataLog::LittleEndian = 1;
|
const int TRK_DataLog::LittleEndian = 1;
|
||||||
const int TRK_DataLog::BigEndian = 2;
|
const int TRK_DataLog::BigEndian = 2;
|
||||||
|
|
||||||
TRK_DataLog::TRK_DataLog(const char* file_name) {
|
TRK_DataLog::TRK_DataLog(std::string file_name) {
|
||||||
|
|
||||||
fileName = file_name;
|
fileName = file_name;
|
||||||
in_fp = fopen(fileName, "rb");
|
in_fp = fopen(fileName.c_str(), "rb");
|
||||||
|
|
||||||
if (in_fp != NULL) {
|
if (in_fp != NULL) {
|
||||||
|
|
||||||
@ -122,25 +123,29 @@ TRK_DataLog::TRK_DataLog(const char* file_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string TRK_DataLog::getFileName() const {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
int TRK_DataLog::parameterCount() const {
|
int TRK_DataLog::parameterCount() const {
|
||||||
return (int)N_params;
|
return (int)N_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* TRK_DataLog::parameterName(unsigned int n) {
|
const char* TRK_DataLog::parameterName(unsigned int n) const {
|
||||||
if (n < N_params)
|
if (n < N_params)
|
||||||
return paramDescriptions[n]->parameterName;
|
return paramDescriptions[n]->parameterName;
|
||||||
else
|
else
|
||||||
return "BadIndex";
|
return "BadIndex";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* TRK_DataLog::parameterUnits(unsigned int n) {
|
const char* TRK_DataLog::parameterUnits(unsigned int n) const {
|
||||||
if (n < N_params)
|
if (n < N_params)
|
||||||
return paramDescriptions[n]->unitsName;
|
return paramDescriptions[n]->unitsName;
|
||||||
else
|
else
|
||||||
return "BadIndex";
|
return "BadIndex";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* TRK_DataLog::parameterType(unsigned int n) {
|
const char* TRK_DataLog::parameterType(unsigned int n) const {
|
||||||
if (n < N_params)
|
if (n < N_params)
|
||||||
return TypeName[ paramDescriptions[n]->dataType ];
|
return TypeName[ paramDescriptions[n]->dataType ];
|
||||||
else
|
else
|
||||||
|
@ -12,16 +12,7 @@
|
|||||||
|
|
||||||
class TRK_DataLog {
|
class TRK_DataLog {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const char* fileName;
|
|
||||||
FILE* in_fp;
|
|
||||||
int version;
|
|
||||||
int endianness;
|
|
||||||
uint32_t N_params;
|
|
||||||
fpos_t dataPosition;
|
|
||||||
int dataRecordSize;
|
|
||||||
char* dataRecord;
|
|
||||||
|
|
||||||
static const int LittleEndian;
|
static const int LittleEndian;
|
||||||
static const int BigEndian;
|
static const int BigEndian;
|
||||||
|
|
||||||
@ -31,17 +22,28 @@ class TRK_DataLog {
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
TRK_DataLog(){}
|
TRK_DataLog(){}
|
||||||
TRK_DataLog(const char* fileName);
|
TRK_DataLog(std::string fileName);
|
||||||
|
|
||||||
|
std::string getFileName() const;
|
||||||
int parameterCount() const;
|
int parameterCount() const;
|
||||||
const char* parameterName(unsigned int n);
|
const char* parameterName(unsigned int n) const;
|
||||||
const char* parameterUnits(unsigned int n);
|
const char* parameterUnits(unsigned int n) const;
|
||||||
const char* parameterType(unsigned int n);
|
const char* parameterType(unsigned int n) const;
|
||||||
|
|
||||||
void selectAllParameters();
|
void selectAllParameters();
|
||||||
void selectParameter(unsigned int index);
|
void selectParameter(unsigned int index);
|
||||||
void selectParameter(const char * paramName);
|
void selectParameter(const char * paramName);
|
||||||
void deselectParameter(unsigned int index);
|
void deselectParameter(unsigned int index);
|
||||||
void formattedWrite(FILE* out_fp, LogFormatter* formatter);
|
void formattedWrite(FILE* out_fp, LogFormatter* formatter);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string fileName;
|
||||||
|
FILE* in_fp;
|
||||||
|
int version;
|
||||||
|
int endianness;
|
||||||
|
uint32_t N_params;
|
||||||
|
fpos_t dataPosition;
|
||||||
|
int dataRecordSize;
|
||||||
|
char* dataRecord;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,7 +68,10 @@ int main(int argc, char *argv[]) {
|
|||||||
if (!trkFilePath.isEmpty()) {
|
if (!trkFilePath.isEmpty()) {
|
||||||
QFileInfo trkFileInfo( trkFilePath);
|
QFileInfo trkFileInfo( trkFilePath);
|
||||||
|
|
||||||
DocWindow* w1 = new DocWindow( trkFileInfo.absoluteFilePath());
|
TRK_DataLog* datalog =
|
||||||
|
new TRK_DataLog( trkFileInfo.absoluteFilePath().toStdString().c_str() );
|
||||||
|
|
||||||
|
DocWindow* w1 = new DocWindow(datalog);
|
||||||
w1->setWindowTitle( trkFileInfo.fileName());
|
w1->setWindowTitle( trkFileInfo.fileName());
|
||||||
w1->resize(800, 500);
|
w1->resize(800, 500);
|
||||||
w1->show();
|
w1->show();
|
||||||
|
Loading…
Reference in New Issue
Block a user