Skip to content
Snippets Groups Projects
Commit d9d43eae authored by Jake Drahos's avatar Jake Drahos
Browse files

Replaced stupidity with simplicity

parent aeb8c0c8
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,7 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -34,7 +34,7 @@ MainWindow::MainWindow(QWidget *parent) :
topScene->addItem(quad); topScene->addItem(quad);
/* Set up environment variables */ /* Set up environment variables */
findChild<QLineEdit *>("socketPath")->setText(QProcessEnvironment::systemEnvironment().value("UCART_SOCKET")); ui->socketPath->setText(QProcessEnvironment::systemEnvironment().value("UCART_SOCKET"));
/* Create a thread for workers */ /* Create a thread for workers */
QThread* workerThread = new QThread(this); QThread* workerThread = new QThread(this);
...@@ -67,8 +67,8 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -67,8 +67,8 @@ MainWindow::MainWindow(QWidget *parent) :
connect(controlWorker, SIGNAL (paramSet(QString, QString)), controlWorker, SLOT (getParamValue(QString, QString))); connect(controlWorker, SIGNAL (paramSet(QString, QString)), controlWorker, SLOT (getParamValue(QString, QString)));
/* Signals to control worker */ /* Signals to control worker */
connect(findChild<QPushButton *>("pbControlRefresh"), SIGNAL (clicked()), controlWorker, SLOT (getNodes())); connect(ui->pbControlRefresh, SIGNAL (clicked()), controlWorker, SLOT (getNodes()));
connect(findChild<QComboBox *>("nodeSelect"), SIGNAL (currentIndexChanged(QString)), controlWorker, SLOT (getParams(QString))); connect(ui->nodeSelect, SIGNAL (currentIndexChanged(QString)), controlWorker, SLOT (getParams(QString)));
connect(this, SIGNAL (getParamValue(QString, QString)), controlWorker, SLOT (getParamValue(QString, QString))); connect(this, SIGNAL (getParamValue(QString, QString)), controlWorker, SLOT (getParamValue(QString, QString)));
connect(this, SIGNAL (setParamValue(QString, QString, float)), controlWorker, SLOT (setParamValue(QString, QString, float))); connect(this, SIGNAL (setParamValue(QString, QString, float)), controlWorker, SLOT (setParamValue(QString, QString, float)));
...@@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *parent) :
/* Connect refresh button and refresh timer to tracker worker */ /* Connect refresh button and refresh timer to tracker worker */
QTimer * trackerTimer = new QTimer(this); QTimer * trackerTimer = new QTimer(this);
connect(trackerTimer, SIGNAL(timeout()), trackerWorker, SLOT(process())); connect(trackerTimer, SIGNAL(timeout()), trackerWorker, SLOT(process()));
connect(findChild<QPushButton *>("pbRefresh"), SIGNAL (clicked()), trackerWorker, SLOT (process())); connect(ui->pbRefresh, SIGNAL (clicked()), trackerWorker, SLOT (process()));
/* Timer used for next setpoint */ /* Timer used for next setpoint */
nextSpTimer->setSingleShot(true); nextSpTimer->setSingleShot(true);
...@@ -93,15 +93,15 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -93,15 +93,15 @@ MainWindow::MainWindow(QWidget *parent) :
cwThread->start(); cwThread->start();
/* Connect the setpointlist to the model */ /* Connect the setpointlist to the model */
findChild<QListView *>("setpointList")->setModel(setpointList); ui->setpointList->setModel(setpointList);
/* Connect various things that can result in sending setpoints */ /* Connect various things that can result in sending setpoints */
connect(findChild<QPushButton *>("pbSendSetpoint"), SIGNAL (clicked()), this, SLOT (sendSetpoints())); connect(ui->pbSendSetpoint, SIGNAL (clicked()), this, SLOT (sendSetpoints()));
connect(findChild<QLineEdit *>("xSetpoint"), SIGNAL (returnPressed()), this, SLOT (sendSetpoints())); connect(ui->xSetpoint, SIGNAL (returnPressed()), this, SLOT (sendSetpoints()));
connect(findChild<QLineEdit *>("ySetpoint"), SIGNAL (returnPressed()), this, SLOT (sendSetpoints())); connect(ui->ySetpoint, SIGNAL (returnPressed()), this, SLOT (sendSetpoints()));
connect(findChild<QLineEdit *>("zSetpoint"), SIGNAL (returnPressed()), this, SLOT (sendSetpoints())); connect(ui->zSetpoint, SIGNAL (returnPressed()), this, SLOT (sendSetpoints()));
connect(findChild<QListView *>("setpointList"), SIGNAL (doubleClicked(QModelIndex)), this, SLOT (sendSelectedSetpoint())); connect(ui->setpointList, SIGNAL (doubleClicked(QModelIndex)), this, SLOT (sendSelectedSetpoint()));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
...@@ -116,7 +116,7 @@ void MainWindow::updateConsole() ...@@ -116,7 +116,7 @@ void MainWindow::updateConsole()
size_t len = 0; size_t len = 0;
len = readBackend(backendPipe, buf, len); len = readBackend(backendPipe, buf, len);
if (len > 0) { if (len > 0) {
QLineEdit * con = findChild<QLineEdit *>("vConsole"); QLineEdit * con = ui->vConsole;
con->setText(con->text().append(buf)); con->setText(con->text().append(buf));
} }
} }
...@@ -124,38 +124,38 @@ void MainWindow::updateConsole() ...@@ -124,38 +124,38 @@ void MainWindow::updateConsole()
void MainWindow::updateTracker(float x, float y, float z, float p, float r, float yaw) void MainWindow::updateTracker(float x, float y, float z, float p, float r, float yaw)
{ {
findChild<QLineEdit *>("xActual")->setText(QString::number(x)); ui->xActual->setText(QString::number(x));
findChild<QLineEdit *>("yActual")->setText(QString::number(y)); ui->yActual->setText(QString::number(y));
findChild<QLineEdit *>("zActual")->setText(QString::number(z)); ui->zActual->setText(QString::number(z));
findChild<QLineEdit *>("pitchActual")->setText(QString::number(p)); ui->pitchActual->setText(QString::number(p));
findChild<QLineEdit *>("rollActual")->setText(QString::number(r)); ui->rollActual->setText(QString::number(r));
findChild<QLineEdit *>("yawActual")->setText(QString::number(yaw)); ui->yawActual->setText(QString::number(yaw));
float dist = sqrt(pow(x - sp_x, 2.0) + pow(y - sp_y, 2.0) + pow(z - sp_z, 2.0)); float dist = sqrt(pow(x - sp_x, 2.0) + pow(y - sp_y, 2.0) + pow(z - sp_z, 2.0));
findChild<QLineEdit *>("dist")->setText(QString::number(dist)); ui->dist->setText(QString::number(dist));
if (!nextSpTimer->isActive() && findChild<QCheckBox *>("autonavEnabled")->isChecked() && if (!nextSpTimer->isActive() && ui->autonavEnabled->isChecked() &&
(dist < findChild<QLineEdit *>("autonavThreshold")->text().toFloat())) { (dist < ui->autonavThreshold->text().toFloat())) {
nextSpTimer->start(findChild<QLineEdit *>("autonavDelay")->text().toInt()); nextSpTimer->start(ui->autonavDelay->text().toInt());
} }
} }
void MainWindow::on_pbStart_clicked() void MainWindow::on_pbStart_clicked()
{ {
QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", findChild<QLineEdit *>("socketPath")->text()); QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", ui->socketPath->text());
this->backendPid = startBackend(findChild<QLineEdit *>("backendPath")->text().toStdString().c_str(), &backendPipe); this->backendPid = startBackend(ui->backendPath->text().toStdString().c_str(), &backendPipe);
findChild<QPushButton *>("pbStart")->setEnabled(false); ui->pbStart->setEnabled(false);
findChild<QPushButton *>("pbStop")->setEnabled(true); ui->pbStop->setEnabled(true);
backendState = 1; backendState = 1;
} }
void MainWindow::on_pbConnect_clicked() void MainWindow::on_pbConnect_clicked()
{ {
QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", findChild<QLineEdit *>("socketPath")->text()); QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", ui->socketPath->text());
findChild<QPushButton *>("pbStart")->setEnabled(false); ui->pbStart->setEnabled(false);
findChild<QPushButton *>("pbConnect")->setEnabled(false); ui->pbConnect->setEnabled(false);
findChild<QPushButton *>("pbStop")->setEnabled(true); ui->pbStop->setEnabled(true);
emit(connectWorkers()); emit(connectWorkers());
backendState = 1; backendState = 1;
} }
...@@ -168,9 +168,9 @@ void MainWindow::on_pbStop_clicked() ...@@ -168,9 +168,9 @@ void MainWindow::on_pbStop_clicked()
backendPipe = -1; backendPipe = -1;
backendPid = 0; backendPid = 0;
} }
findChild<QPushButton *>("pbStart")->setEnabled(true); ui->pbStart->setEnabled(true);
findChild<QPushButton *>("pbConnect")->setEnabled(true); ui->pbConnect->setEnabled(true);
findChild<QPushButton *>("pbStop")->setEnabled(false); ui->pbStop->setEnabled(false);
backendState = 0; backendState = 0;
} }
...@@ -178,33 +178,33 @@ void MainWindow::on_chooseBackend_clicked() ...@@ -178,33 +178,33 @@ void MainWindow::on_chooseBackend_clicked()
{ {
QString backendPath = QFileDialog::getOpenFileName(this, QString backendPath = QFileDialog::getOpenFileName(this,
tr("Path to Backend Executable")); tr("Path to Backend Executable"));
findChild<QLineEdit *>("backendPath")->setText(backendPath); ui->backendPath->setText(backendPath);
} }
void MainWindow::newNodes(QStringList blocks) void MainWindow::newNodes(QStringList blocks)
{ {
QComboBox * select = findChild<QComboBox *>("nodeSelect"); QComboBox * select = ui->nodeSelect;
select->clear(); select->clear();
select->addItems(blocks); select->addItems(blocks);
this->findChild<QLabel *>("noGraphWarning1")->setVisible(false); this->ui->noGraphWarning1->setVisible(false);
this->findChild<QLabel *>("noGraphWarning2")->setVisible(false); this->ui->noGraphWarning2->setVisible(false);
this->findChild<QWidget *>("noGraphWarningLine")->setVisible(false); this->ui->noGraphWarningLine->setVisible(false);
} }
void MainWindow::newConstantBlocks(QStringList blocks) void MainWindow::newConstantBlocks(QStringList blocks)
{ {
QComboBox * xSelect = findChild<QComboBox *>("xSetpointSelect"); QComboBox * xSelect = ui->xSetpointSelect;
xSelect->clear(); xSelect->clear();
xSelect->addItems(blocks); xSelect->addItems(blocks);
QComboBox * ySelect = findChild<QComboBox *>("ySetpointSelect"); QComboBox * ySelect = ui->ySetpointSelect;
ySelect->clear(); ySelect->clear();
ySelect->addItems(blocks); ySelect->addItems(blocks);
QComboBox * zSelect = findChild<QComboBox *>("zSetpointSelect"); QComboBox * zSelect = ui->zSetpointSelect;
zSelect->clear(); zSelect->clear();
zSelect->addItems(blocks); zSelect->addItems(blocks);
...@@ -225,64 +225,64 @@ void MainWindow::newConstantBlocks(QStringList blocks) ...@@ -225,64 +225,64 @@ void MainWindow::newConstantBlocks(QStringList blocks)
void MainWindow::newParams(QStringList params) void MainWindow::newParams(QStringList params)
{ {
QComboBox * select = findChild<QComboBox *>("paramSelect"); QComboBox * select = ui->paramSelect;
select->clear(); select->clear();
select->addItems(params); select->addItems(params);
} }
void MainWindow::newParamValue(QString node, QString param, float val) void MainWindow::newParamValue(QString node, QString param, float val)
{ {
findChild<QLineEdit *>("paramValue")->setText(QString::number(val)); ui->paramValue->setText(QString::number(val));
/* Update the nav page setpoints if it's a setpoint paramvalue */ /* Update the nav page setpoints if it's a setpoint paramvalue */
if (node == findChild<QComboBox *>("xSetpointSelect")->currentText()) { if (node == ui->xSetpointSelect->currentText()) {
findChild<QLineEdit *>("xSetpoint")->setText(QString::number(val)); ui->xSetpoint->setText(QString::number(val));
} else if (node == findChild<QComboBox *>("ySetpointSelect")->currentText()) { } else if (node == ui->ySetpointSelect->currentText()) {
findChild<QLineEdit *>("ySetpoint")->setText(QString::number(val)); ui->ySetpoint->setText(QString::number(val));
} else if (node == findChild<QComboBox *>("zSetpointSelect")->currentText()) { } else if (node == ui->zSetpointSelect->currentText()) {
findChild<QLineEdit *>("zSetpoint")->setText(QString::number(val)); ui->zSetpoint->setText(QString::number(val));
} }
} }
void MainWindow::on_paramSelect_currentIndexChanged(const QString &arg1) void MainWindow::on_paramSelect_currentIndexChanged(const QString &arg1)
{ {
emit(getParamValue(findChild<QComboBox *>("nodeSelect")->currentText(), arg1)); emit(getParamValue(ui->nodeSelect->currentText(), arg1));
} }
void MainWindow::on_paramValue_returnPressed() void MainWindow::on_paramValue_returnPressed()
{ {
emit (setParamValue(findChild<QComboBox *>("nodeSelect")->currentText(), emit (setParamValue(ui->nodeSelect->currentText(),
findChild<QComboBox *>("paramSelect")->currentText(), ui->paramSelect->currentText(),
findChild<QLineEdit *>("paramValue")->text().toFloat())); ui->paramValue->text().toFloat()));
} }
void MainWindow::sendSetpoints() void MainWindow::sendSetpoints()
{ {
sp_x = findChild<QLineEdit *>("xSetpoint")->text().toFloat(); sp_x = ui->xSetpoint->text().toFloat();
emit (setParamValue(findChild<QComboBox *>("xSetpointSelect")->currentText(), emit (setParamValue(ui->xSetpointSelect->currentText(),
blockDefs[BLOCK_CONSTANT]->param_names[0], sp_x)); blockDefs[BLOCK_CONSTANT]->param_names[0], sp_x));
sp_y = findChild<QLineEdit *>("ySetpoint")->text().toFloat(); sp_y = ui->ySetpoint->text().toFloat();
emit (setParamValue(findChild<QComboBox *>("ySetpointSelect")->currentText(), emit (setParamValue(ui->ySetpointSelect->currentText(),
blockDefs[BLOCK_CONSTANT]->param_names[0], sp_y)); blockDefs[BLOCK_CONSTANT]->param_names[0], sp_y));
sp_z = findChild<QLineEdit *>("zSetpoint")->text().toFloat(); sp_z = ui->zSetpoint->text().toFloat();
emit (setParamValue(findChild<QComboBox *>("zSetpointSelect")->currentText(), emit (setParamValue(ui->zSetpointSelect->currentText(),
blockDefs[BLOCK_CONSTANT]->param_names[0], sp_z)); blockDefs[BLOCK_CONSTANT]->param_names[0], sp_z));
} }
void MainWindow::on_pbAppendSetpoint_clicked() void MainWindow::on_pbAppendSetpoint_clicked()
{ {
QString str("[" + findChild<QLineEdit *>("xSetpoint")->text() + ", "+ QString str("[" + ui->xSetpoint->text() + ", "+
findChild<QLineEdit *>("ySetpoint")->text() + ", " + ui->ySetpoint->text() + ", " +
findChild<QLineEdit *>("zSetpoint")->text() + "]"); ui->zSetpoint->text() + "]");
setpointList->appendRow(new QStandardItem(str)); setpointList->appendRow(new QStandardItem(str));
} }
void MainWindow::on_pbNextSetpoint_clicked() void MainWindow::on_pbNextSetpoint_clicked()
{ {
QListView * listView = findChild<QListView *>("setpointList"); QListView * listView = ui->setpointList;
if (listView->currentIndex().isValid() && setpointList->index(listView->currentIndex().row() + 1, 0).isValid()) { if (listView->currentIndex().isValid() && setpointList->index(listView->currentIndex().row() + 1, 0).isValid()) {
listView->setCurrentIndex(setpointList->index(listView->currentIndex().row() + 1, 0)); listView->setCurrentIndex(setpointList->index(listView->currentIndex().row() + 1, 0));
} else { } else {
...@@ -294,14 +294,14 @@ void MainWindow::on_pbNextSetpoint_clicked() ...@@ -294,14 +294,14 @@ void MainWindow::on_pbNextSetpoint_clicked()
void MainWindow::sendSelectedSetpoint() void MainWindow::sendSelectedSetpoint()
{ {
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) { if (ui->setpointList->currentIndex().isValid()) {
QRegExp regex("\\[(.*), (.*), (.*)\\]"); QRegExp regex("\\[(.*), (.*), (.*)\\]");
int row = findChild<QListView *>("setpointList")->currentIndex().row(); int row = ui->setpointList->currentIndex().row();
regex.indexIn(setpointList->item(row)->text()); regex.indexIn(setpointList->item(row)->text());
findChild<QLineEdit *>("xSetpoint")->setText(regex.cap(1)); ui->xSetpoint->setText(regex.cap(1));
findChild<QLineEdit *>("ySetpoint")->setText(regex.cap(2)); ui->ySetpoint->setText(regex.cap(2));
findChild<QLineEdit *>("zSetpoint")->setText(regex.cap(3)); ui->zSetpoint->setText(regex.cap(3));
sendSetpoints(); sendSetpoints();
} }
...@@ -309,36 +309,36 @@ void MainWindow::sendSelectedSetpoint() ...@@ -309,36 +309,36 @@ void MainWindow::sendSelectedSetpoint()
void MainWindow::on_pbActualToSetpoint_clicked() void MainWindow::on_pbActualToSetpoint_clicked()
{ {
findChild<QLineEdit *>("xSetpoint")->setText(findChild<QLineEdit *>("xActual")->text()); ui->xSetpoint->setText(ui->xActual->text());
findChild<QLineEdit *>("ySetpoint")->setText(findChild<QLineEdit *>("yActual")->text()); ui->ySetpoint->setText(ui->yActual->text());
findChild<QLineEdit *>("zSetpoint")->setText(findChild<QLineEdit *>("zActual")->text()); ui->zSetpoint->setText(ui->zActual->text());
} }
void MainWindow::on_pbDeleteSetpoint_clicked() void MainWindow::on_pbDeleteSetpoint_clicked()
{ {
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) { if (ui->setpointList->currentIndex().isValid()) {
setpointList->removeRow(findChild<QListView *>("setpointList")->currentIndex().row()); setpointList->removeRow(ui->setpointList->currentIndex().row());
} }
} }
void MainWindow::newControlGraph(QString graph) void MainWindow::newControlGraph(QString graph)
{ {
findChild<QLabel *>("graphImage")->setPixmap(QPixmap(graph)); ui->graphImage->setPixmap(QPixmap(graph));
} }
void MainWindow::on_pbActualToWaypoint_clicked() void MainWindow::on_pbActualToWaypoint_clicked()
{ {
QString str("[" + findChild<QLineEdit *>("xActual")->text() + ", "+ QString str("[" + ui->xActual->text() + ", "+
findChild<QLineEdit *>("yActual")->text() + ", " + ui->yActual->text() + ", " +
findChild<QLineEdit *>("zActual")->text() + "]"); ui->zActual->text() + "]");
setpointList->appendRow(new QStandardItem(str)); setpointList->appendRow(new QStandardItem(str));
} }
void MainWindow::on_pbMoveUp_clicked() void MainWindow::on_pbMoveUp_clicked()
{ {
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) { if (ui->setpointList->currentIndex().isValid()) {
int current = findChild<QListView *>("setpointList")->currentIndex().row(); int current = ui->setpointList->currentIndex().row();
if (current > 0) { if (current > 0) {
setpointList->insertRow(current - 1, setpointList->takeItem(current)); setpointList->insertRow(current - 1, setpointList->takeItem(current));
setpointList->removeRow(current + 1); setpointList->removeRow(current + 1);
...@@ -348,8 +348,8 @@ void MainWindow::on_pbMoveUp_clicked() ...@@ -348,8 +348,8 @@ void MainWindow::on_pbMoveUp_clicked()
void MainWindow::on_pbMoveDown_clicked() void MainWindow::on_pbMoveDown_clicked()
{ {
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) { if (ui->setpointList->currentIndex().isValid()) {
int current = findChild<QListView *>("setpointList")->currentIndex().row(); int current = ui->setpointList->currentIndex().row();
if (current < (setpointList->rowCount() - 1)) { if (current < (setpointList->rowCount() - 1)) {
setpointList->insertRow(current + 2, setpointList->takeItem(current)); setpointList->insertRow(current + 2, setpointList->takeItem(current));
setpointList->removeRow(current); setpointList->removeRow(current);
...@@ -360,13 +360,13 @@ void MainWindow::on_pbMoveDown_clicked() ...@@ -360,13 +360,13 @@ void MainWindow::on_pbMoveDown_clicked()
void MainWindow::on_pbInsertSetpoint_clicked() void MainWindow::on_pbInsertSetpoint_clicked()
{ {
int current = 0; int current = 0;
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) { if (ui->setpointList->currentIndex().isValid()) {
current = findChild<QListView *>("setpointList")->currentIndex().row(); current = ui->setpointList->currentIndex().row();
} }
QString str("[" + findChild<QLineEdit *>("xSetpoint")->text() + ", "+ QString str("[" + ui->xSetpoint->text() + ", "+
findChild<QLineEdit *>("ySetpoint")->text() + ", " + ui->ySetpoint->text() + ", " +
findChild<QLineEdit *>("zSetpoint")->text() + "]"); ui->zSetpoint->text() + "]");
setpointList->insertRow(current, new QStandardItem(str)); setpointList->insertRow(current, new QStandardItem(str));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment