|
|
@ -14,9 +14,15 @@ |
|
|
|
#include <QCoreApplication> |
|
|
|
#include <QCoreApplication> |
|
|
|
#include "Pendulum.h" |
|
|
|
#include "Pendulum.h" |
|
|
|
#include "Button.h" |
|
|
|
#include "Button.h" |
|
|
|
|
|
|
|
#include <QThread> |
|
|
|
|
|
|
|
#include <QCloseEvent> |
|
|
|
|
|
|
|
#include <QTimer> |
|
|
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow() { |
|
|
|
MainWindow::MainWindow() { |
|
|
|
|
|
|
|
simulationThread = new QThread(this); |
|
|
|
simulation = new Simulation; |
|
|
|
simulation = new Simulation; |
|
|
|
|
|
|
|
simulation->moveToThread(simulationThread); |
|
|
|
|
|
|
|
simulationThread->start(); |
|
|
|
|
|
|
|
|
|
|
|
masses = std::vector<double>(MaxSegments); |
|
|
|
masses = std::vector<double>(MaxSegments); |
|
|
|
lengths = std::vector<double>(MaxSegments); |
|
|
|
lengths = std::vector<double>(MaxSegments); |
|
|
@ -291,7 +297,7 @@ QWidget * MainWindow::buildAddUI() { |
|
|
|
removeBtn->setStyleSheet("background-color: #ffaaaa"); |
|
|
|
removeBtn->setStyleSheet("background-color: #ffaaaa"); |
|
|
|
|
|
|
|
|
|
|
|
connect(addBtn, &QPushButton::clicked, this, &MainWindow::add); |
|
|
|
connect(addBtn, &QPushButton::clicked, this, &MainWindow::add); |
|
|
|
connect(removeBtn, &QPushButton::clicked, this, &MainWindow::remove); |
|
|
|
connect(removeBtn, &QPushButton::clicked, simulation, &Simulation::clearPendula); |
|
|
|
|
|
|
|
|
|
|
|
btnLyt->addWidget(addBtn); |
|
|
|
btnLyt->addWidget(addBtn); |
|
|
|
btnLyt->addWidget(removeBtn); |
|
|
|
btnLyt->addWidget(removeBtn); |
|
|
@ -420,10 +426,6 @@ void MainWindow::add() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::remove() { |
|
|
|
|
|
|
|
simulation->clearPendula(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::resetSimulationControl() { |
|
|
|
void MainWindow::resetSimulationControl() { |
|
|
|
gravitySlider->setValue(981); |
|
|
|
gravitySlider->setValue(981); |
|
|
|
timescaleSlider->setValue(100); |
|
|
|
timescaleSlider->setValue(100); |
|
|
@ -433,3 +435,9 @@ void MainWindow::resetSimulationControl() { |
|
|
|
void MainWindow::toggleSimulation() { |
|
|
|
void MainWindow::toggleSimulation() { |
|
|
|
simulation->isPlaying = !simulation->isPlaying; |
|
|
|
simulation->isPlaying = !simulation->isPlaying; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *e) { |
|
|
|
|
|
|
|
simulationThread->quit(); |
|
|
|
|
|
|
|
simulationThread->wait(); |
|
|
|
|
|
|
|
e->accept(); |
|
|
|
|
|
|
|
} |
|
|
|