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

Replaced stupidity with simplicity

parent 4e2bceed
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ MainWindow::MainWindow(QWidget *parent) :
topScene->addItem(quad);
/* 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 */
QThread* workerThread = new QThread(this);
......@@ -67,8 +67,8 @@ MainWindow::MainWindow(QWidget *parent) :
connect(controlWorker, SIGNAL (paramSet(QString, QString)), controlWorker, SLOT (getParamValue(QString, QString)));
/* Signals to control worker */
connect(findChild<QPushButton *>("pbControlRefresh"), SIGNAL (clicked()), controlWorker, SLOT (getNodes()));
connect(findChild<QComboBox *>("nodeSelect"), SIGNAL (currentIndexChanged(QString)), controlWorker, SLOT (getParams(QString)));
connect(ui->pbControlRefresh, SIGNAL (clicked()), controlWorker, SLOT (getNodes()));
connect(ui->nodeSelect, SIGNAL (currentIndexChanged(QString)), controlWorker, SLOT (getParams(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)));
......@@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *parent) :
/* Connect refresh button and refresh timer to tracker worker */
QTimer * trackerTimer = new QTimer(this);
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 */
nextSpTimer->setSingleShot(true);
......@@ -93,15 +93,15 @@ MainWindow::MainWindow(QWidget *parent) :
cwThread->start();
/* 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(findChild<QPushButton *>("pbSendSetpoint"), SIGNAL (clicked()), this, SLOT (sendSetpoints()));
connect(findChild<QLineEdit *>("xSetpoint"), SIGNAL (returnPressed()), this, SLOT (sendSetpoints()));
connect(findChild<QLineEdit *>("ySetpoint"), SIGNAL (returnPressed()), this, SLOT (sendSetpoints()));
connect(findChild<QLineEdit *>("zSetpoint"), SIGNAL (returnPressed()), this, SLOT (sendSetpoints()));
connect(ui->pbSendSetpoint, SIGNAL (clicked()), this, SLOT (sendSetpoints()));
connect(ui->xSetpoint, SIGNAL (returnPressed()), this, SLOT (sendSetpoints()));
connect(ui->ySetpoint, 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()
......@@ -116,7 +116,7 @@ void MainWindow::updateConsole()
size_t len = 0;
len = readBackend(backendPipe, buf, len);
if (len > 0) {
QLineEdit * con = findChild<QLineEdit *>("vConsole");
QLineEdit * con = ui->vConsole;
con->setText(con->text().append(buf));
}
}
......@@ -124,38 +124,38 @@ void MainWindow::updateConsole()
void MainWindow::updateTracker(float x, float y, float z, float p, float r, float yaw)
{
findChild<QLineEdit *>("xActual")->setText(QString::number(x));
findChild<QLineEdit *>("yActual")->setText(QString::number(y));
findChild<QLineEdit *>("zActual")->setText(QString::number(z));
findChild<QLineEdit *>("pitchActual")->setText(QString::number(p));
findChild<QLineEdit *>("rollActual")->setText(QString::number(r));
findChild<QLineEdit *>("yawActual")->setText(QString::number(yaw));
ui->xActual->setText(QString::number(x));
ui->yActual->setText(QString::number(y));
ui->zActual->setText(QString::number(z));
ui->pitchActual->setText(QString::number(p));
ui->rollActual->setText(QString::number(r));
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));
findChild<QLineEdit *>("dist")->setText(QString::number(dist));
ui->dist->setText(QString::number(dist));
if (!nextSpTimer->isActive() && findChild<QCheckBox *>("autonavEnabled")->isChecked() &&
(dist < findChild<QLineEdit *>("autonavThreshold")->text().toFloat())) {
nextSpTimer->start(findChild<QLineEdit *>("autonavDelay")->text().toInt());
if (!nextSpTimer->isActive() && ui->autonavEnabled->isChecked() &&
(dist < ui->autonavThreshold->text().toFloat())) {
nextSpTimer->start(ui->autonavDelay->text().toInt());
}
}
void MainWindow::on_pbStart_clicked()
{
QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", findChild<QLineEdit *>("socketPath")->text());
this->backendPid = startBackend(findChild<QLineEdit *>("backendPath")->text().toStdString().c_str(), &backendPipe);
findChild<QPushButton *>("pbStart")->setEnabled(false);
findChild<QPushButton *>("pbStop")->setEnabled(true);
QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", ui->socketPath->text());
this->backendPid = startBackend(ui->backendPath->text().toStdString().c_str(), &backendPipe);
ui->pbStart->setEnabled(false);
ui->pbStop->setEnabled(true);
backendState = 1;
}
void MainWindow::on_pbConnect_clicked()
{
QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", findChild<QLineEdit *>("socketPath")->text());
findChild<QPushButton *>("pbStart")->setEnabled(false);
findChild<QPushButton *>("pbConnect")->setEnabled(false);
findChild<QPushButton *>("pbStop")->setEnabled(true);
QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", ui->socketPath->text());
ui->pbStart->setEnabled(false);
ui->pbConnect->setEnabled(false);
ui->pbStop->setEnabled(true);
emit(connectWorkers());
backendState = 1;
}
......@@ -168,9 +168,9 @@ void MainWindow::on_pbStop_clicked()
backendPipe = -1;
backendPid = 0;
}
findChild<QPushButton *>("pbStart")->setEnabled(true);
findChild<QPushButton *>("pbConnect")->setEnabled(true);
findChild<QPushButton *>("pbStop")->setEnabled(false);
ui->pbStart->setEnabled(true);
ui->pbConnect->setEnabled(true);
ui->pbStop->setEnabled(false);
backendState = 0;
}
......@@ -178,33 +178,33 @@ void MainWindow::on_chooseBackend_clicked()
{
QString backendPath = QFileDialog::getOpenFileName(this,
tr("Path to Backend Executable"));
findChild<QLineEdit *>("backendPath")->setText(backendPath);
ui->backendPath->setText(backendPath);
}
void MainWindow::newNodes(QStringList blocks)
{
QComboBox * select = findChild<QComboBox *>("nodeSelect");
QComboBox * select = ui->nodeSelect;
select->clear();
select->addItems(blocks);
this->findChild<QLabel *>("noGraphWarning1")->setVisible(false);
this->findChild<QLabel *>("noGraphWarning2")->setVisible(false);
this->findChild<QWidget *>("noGraphWarningLine")->setVisible(false);
this->ui->noGraphWarning1->setVisible(false);
this->ui->noGraphWarning2->setVisible(false);
this->ui->noGraphWarningLine->setVisible(false);
}
void MainWindow::newConstantBlocks(QStringList blocks)
{
QComboBox * xSelect = findChild<QComboBox *>("xSetpointSelect");
QComboBox * xSelect = ui->xSetpointSelect;
xSelect->clear();
xSelect->addItems(blocks);
QComboBox * ySelect = findChild<QComboBox *>("ySetpointSelect");
QComboBox * ySelect = ui->ySetpointSelect;
ySelect->clear();
ySelect->addItems(blocks);
QComboBox * zSelect = findChild<QComboBox *>("zSetpointSelect");
QComboBox * zSelect = ui->zSetpointSelect;
zSelect->clear();
zSelect->addItems(blocks);
......@@ -225,64 +225,64 @@ void MainWindow::newConstantBlocks(QStringList blocks)
void MainWindow::newParams(QStringList params)
{
QComboBox * select = findChild<QComboBox *>("paramSelect");
QComboBox * select = ui->paramSelect;
select->clear();
select->addItems(params);
}
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 */
if (node == findChild<QComboBox *>("xSetpointSelect")->currentText()) {
findChild<QLineEdit *>("xSetpoint")->setText(QString::number(val));
} else if (node == findChild<QComboBox *>("ySetpointSelect")->currentText()) {
findChild<QLineEdit *>("ySetpoint")->setText(QString::number(val));
} else if (node == findChild<QComboBox *>("zSetpointSelect")->currentText()) {
findChild<QLineEdit *>("zSetpoint")->setText(QString::number(val));
if (node == ui->xSetpointSelect->currentText()) {
ui->xSetpoint->setText(QString::number(val));
} else if (node == ui->ySetpointSelect->currentText()) {
ui->ySetpoint->setText(QString::number(val));
} else if (node == ui->zSetpointSelect->currentText()) {
ui->zSetpoint->setText(QString::number(val));
}
}
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()
{
emit (setParamValue(findChild<QComboBox *>("nodeSelect")->currentText(),
findChild<QComboBox *>("paramSelect")->currentText(),
findChild<QLineEdit *>("paramValue")->text().toFloat()));
emit (setParamValue(ui->nodeSelect->currentText(),
ui->paramSelect->currentText(),
ui->paramValue->text().toFloat()));
}
void MainWindow::sendSetpoints()
{
sp_x = findChild<QLineEdit *>("xSetpoint")->text().toFloat();
emit (setParamValue(findChild<QComboBox *>("xSetpointSelect")->currentText(),
sp_x = ui->xSetpoint->text().toFloat();
emit (setParamValue(ui->xSetpointSelect->currentText(),
blockDefs[BLOCK_CONSTANT]->param_names[0], sp_x));
sp_y = findChild<QLineEdit *>("ySetpoint")->text().toFloat();
emit (setParamValue(findChild<QComboBox *>("ySetpointSelect")->currentText(),
sp_y = ui->ySetpoint->text().toFloat();
emit (setParamValue(ui->ySetpointSelect->currentText(),
blockDefs[BLOCK_CONSTANT]->param_names[0], sp_y));
sp_z = findChild<QLineEdit *>("zSetpoint")->text().toFloat();
emit (setParamValue(findChild<QComboBox *>("zSetpointSelect")->currentText(),
sp_z = ui->zSetpoint->text().toFloat();
emit (setParamValue(ui->zSetpointSelect->currentText(),
blockDefs[BLOCK_CONSTANT]->param_names[0], sp_z));
}
void MainWindow::on_pbAppendSetpoint_clicked()
{
QString str("[" + findChild<QLineEdit *>("xSetpoint")->text() + ", "+
findChild<QLineEdit *>("ySetpoint")->text() + ", " +
findChild<QLineEdit *>("zSetpoint")->text() + "]");
QString str("[" + ui->xSetpoint->text() + ", "+
ui->ySetpoint->text() + ", " +
ui->zSetpoint->text() + "]");
setpointList->appendRow(new QStandardItem(str));
}
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()) {
listView->setCurrentIndex(setpointList->index(listView->currentIndex().row() + 1, 0));
} else {
......@@ -294,14 +294,14 @@ void MainWindow::on_pbNextSetpoint_clicked()
void MainWindow::sendSelectedSetpoint()
{
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) {
if (ui->setpointList->currentIndex().isValid()) {
QRegExp regex("\\[(.*), (.*), (.*)\\]");
int row = findChild<QListView *>("setpointList")->currentIndex().row();
int row = ui->setpointList->currentIndex().row();
regex.indexIn(setpointList->item(row)->text());
findChild<QLineEdit *>("xSetpoint")->setText(regex.cap(1));
findChild<QLineEdit *>("ySetpoint")->setText(regex.cap(2));
findChild<QLineEdit *>("zSetpoint")->setText(regex.cap(3));
ui->xSetpoint->setText(regex.cap(1));
ui->ySetpoint->setText(regex.cap(2));
ui->zSetpoint->setText(regex.cap(3));
sendSetpoints();
}
......@@ -309,36 +309,36 @@ void MainWindow::sendSelectedSetpoint()
void MainWindow::on_pbActualToSetpoint_clicked()
{
findChild<QLineEdit *>("xSetpoint")->setText(findChild<QLineEdit *>("xActual")->text());
findChild<QLineEdit *>("ySetpoint")->setText(findChild<QLineEdit *>("yActual")->text());
findChild<QLineEdit *>("zSetpoint")->setText(findChild<QLineEdit *>("zActual")->text());
ui->xSetpoint->setText(ui->xActual->text());
ui->ySetpoint->setText(ui->yActual->text());
ui->zSetpoint->setText(ui->zActual->text());
}
void MainWindow::on_pbDeleteSetpoint_clicked()
{
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) {
setpointList->removeRow(findChild<QListView *>("setpointList")->currentIndex().row());
if (ui->setpointList->currentIndex().isValid()) {
setpointList->removeRow(ui->setpointList->currentIndex().row());
}
}
void MainWindow::newControlGraph(QString graph)
{
findChild<QLabel *>("graphImage")->setPixmap(QPixmap(graph));
ui->graphImage->setPixmap(QPixmap(graph));
}
void MainWindow::on_pbActualToWaypoint_clicked()
{
QString str("[" + findChild<QLineEdit *>("xActual")->text() + ", "+
findChild<QLineEdit *>("yActual")->text() + ", " +
findChild<QLineEdit *>("zActual")->text() + "]");
QString str("[" + ui->xActual->text() + ", "+
ui->yActual->text() + ", " +
ui->zActual->text() + "]");
setpointList->appendRow(new QStandardItem(str));
}
void MainWindow::on_pbMoveUp_clicked()
{
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) {
int current = findChild<QListView *>("setpointList")->currentIndex().row();
if (ui->setpointList->currentIndex().isValid()) {
int current = ui->setpointList->currentIndex().row();
if (current > 0) {
setpointList->insertRow(current - 1, setpointList->takeItem(current));
setpointList->removeRow(current + 1);
......@@ -348,8 +348,8 @@ void MainWindow::on_pbMoveUp_clicked()
void MainWindow::on_pbMoveDown_clicked()
{
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) {
int current = findChild<QListView *>("setpointList")->currentIndex().row();
if (ui->setpointList->currentIndex().isValid()) {
int current = ui->setpointList->currentIndex().row();
if (current < (setpointList->rowCount() - 1)) {
setpointList->insertRow(current + 2, setpointList->takeItem(current));
setpointList->removeRow(current);
......@@ -360,13 +360,13 @@ void MainWindow::on_pbMoveDown_clicked()
void MainWindow::on_pbInsertSetpoint_clicked()
{
int current = 0;
if (findChild<QListView *>("setpointList")->currentIndex().isValid()) {
current = findChild<QListView *>("setpointList")->currentIndex().row();
if (ui->setpointList->currentIndex().isValid()) {
current = ui->setpointList->currentIndex().row();
}
QString str("[" + findChild<QLineEdit *>("xSetpoint")->text() + ", "+
findChild<QLineEdit *>("ySetpoint")->text() + ", " +
findChild<QLineEdit *>("zSetpoint")->text() + "]");
QString str("[" + ui->xSetpoint->text() + ", "+
ui->ySetpoint->text() + ", " +
ui->zSetpoint->text() + "]");
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