Commit 63f6cce6 authored by Anthony Noir's avatar Anthony Noir
Browse files

IT'S ALAIVE ! IT'S ALIVE !

parent dd944119
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1056</width> <width>1068</width>
<height>771</height> <height>771</height>
</rect> </rect>
</property> </property>
...@@ -212,7 +212,7 @@ pattern recorded :</string> ...@@ -212,7 +212,7 @@ pattern recorded :</string>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>50</string> <string>10</string>
</property> </property>
<property name="maxLength"> <property name="maxLength">
<number>10</number> <number>10</number>
...@@ -605,8 +605,8 @@ pattern recorded :</string> ...@@ -605,8 +605,8 @@ pattern recorded :</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1056</width> <width>1068</width>
<height>25</height> <height>26</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFichier"> <widget class="QMenu" name="menuFichier">
......
...@@ -73,6 +73,12 @@ private slots: ...@@ -73,6 +73,12 @@ private slots:
void on_savePatternButton_clicked(); void on_savePatternButton_clicked();
void on_nextButton_clicked();
void on_prevButton_clicked();
void on_playPauseButton_clicked();
private: private:
//! \brief Initialiser la liste des transitions et voisinages disponibles //! \brief Initialiser la liste des transitions et voisinages disponibles
void init_transition_neighborhood_list(); void init_transition_neighborhood_list();
...@@ -114,6 +120,7 @@ private: ...@@ -114,6 +120,7 @@ private:
TransitionRule* m_transition_rule; TransitionRule* m_transition_rule;
NeighborhoodRule* m_neighborhood_rule; NeighborhoodRule* m_neighborhood_rule;
QJsonObject m_loaded_model; QJsonObject m_loaded_model;
QTimer* timer;
bool m_customizing; bool m_customizing;
}; };
#endif // MAINWINDOW_HPP #endif // MAINWINDOW_HPP
...@@ -67,6 +67,12 @@ public: ...@@ -67,6 +67,12 @@ public:
//! \brief Indique si la simulation peut tourner
//! \return vrai si la simulation peut tourner
bool runnable() {return canRun;}
//! \brief Remet la simulation dans son état de départ //! \brief Remet la simulation dans son état de départ
void reset(); void reset();
...@@ -74,7 +80,8 @@ public: ...@@ -74,7 +80,8 @@ public:
void step(); void step();
//! \brief Fais reculer la simulation d'un pas si possible //! \brief Fais reculer la simulation d'un pas si possible
void back(); //! \return vrai si la simulation a reculé
bool back();
}; };
#endif // SIMULATION_HPP #endif // SIMULATION_HPP
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
#include <QDate> #include <QDate>
#include <QTextStream> #include <QTextStream>
#include <QInputDialog> #include <QInputDialog>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, simulation(), , simulation()
m_customizing(false) , timer(new QTimer(this))
, m_customizing(false)
{ {
ui->setupUi(this); ui->setupUi(this);
...@@ -55,6 +57,12 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -55,6 +57,12 @@ MainWindow::MainWindow(QWidget *parent)
ui->struct_library->update_cell_pixel_size(ui->grid_view->cell_screen_size()); ui->struct_library->update_cell_pixel_size(ui->grid_view->cell_screen_size());
load_model(default_model()); load_model(default_model());
connect(timer, &QTimer::timeout, this, [this](){
on_nextButton_clicked();
std::cout << "a\n";
timer->start();
});
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
...@@ -605,3 +613,37 @@ void MainWindow::on_savePatternButton_clicked() ...@@ -605,3 +613,37 @@ void MainWindow::on_savePatternButton_clicked()
{ {
save_grid_configuration(); save_grid_configuration();
} }
void MainWindow::on_nextButton_clicked()
{
simulation.setGrid(ui->grid_view->get_grid());
simulation.step();
ui->grid_view->copy_grid(simulation.getGrid());
}
void MainWindow::on_prevButton_clicked()
{
if(!simulation.back()) {
QMessageBox::critical(this, "Retour arrière impossible", "L'historique est vide : impossible de revenir en arrière.");
}
ui->grid_view->copy_grid(simulation.getGrid());
}
void MainWindow::on_playPauseButton_clicked()
{
if(timer->isActive()) {
//Pause
timer->stop();
} else {
//Play
int frequence = ui->simSpeedSpinbox->value();
if(frequence == 0) {
QMessageBox::critical(this, "Impossible de démarrer", "Impossible de lancer la simulation à une vitesse nulle.");
} else if(!simulation.runnable()) {
QMessageBox::critical(this, "Impossible de démarrer", "Impossible de lancer la simulation : les règles ne sont pas définies ou incompatibles.");
} else {
timer->setInterval(1000/frequence);
timer->start();
}
}
}
...@@ -15,7 +15,9 @@ mooreNeighborhoodRule::mooreNeighborhoodRule(int _radius) ...@@ -15,7 +15,9 @@ mooreNeighborhoodRule::mooreNeighborhoodRule(int _radius)
for(int j = -_radius; j <= _radius; j++){ for(int j = -_radius; j <= _radius; j++){
newCord.x = i; newCord.x = i;
newCord.y = j; newCord.y = j;
format.positions.push_back(newCord); if(!(newCord.x == 0 && newCord.y == 0)) {
format.positions.push_back(newCord);
}
} }
} }
} }
......
...@@ -5,13 +5,13 @@ Simulation::Simulation() : canRun(false), time(0), automaton(), startGrid(0,0), ...@@ -5,13 +5,13 @@ Simulation::Simulation() : canRun(false), time(0), automaton(), startGrid(0,0),
Simulation::~Simulation() {} Simulation::~Simulation() {}
void Simulation::setNeighborhoodRule(NeighborhoodRule* NR) { void Simulation::setNeighborhoodRule(NeighborhoodRule* NR) {
canRun = false;
automaton.setNeighborhoodRule(NR); automaton.setNeighborhoodRule(NR);
canRun = automaton.getNeighborhoodRule()&&automaton.getTransitionRule()&&automaton.getTransitionRule()->acceptFormat(automaton.getNeighborhoodRule()->getFormats());
} }
void Simulation::setTransitionRule(TransitionRule* TR) { void Simulation::setTransitionRule(TransitionRule* TR) {
canRun = false;
automaton.setTransitionRule(TR); automaton.setTransitionRule(TR);
canRun = automaton.getNeighborhoodRule()&&automaton.getTransitionRule()&&automaton.getTransitionRule()->acceptFormat(automaton.getNeighborhoodRule()->getFormats());
} }
void Simulation::setAlphabet(const Alphabet& A) { void Simulation::setAlphabet(const Alphabet& A) {
...@@ -71,11 +71,14 @@ void Simulation::step() { ...@@ -71,11 +71,14 @@ void Simulation::step() {
++time; ++time;
} }
void Simulation::back() { bool Simulation::back() {
bool r=false;
if(!hist.isEmpty()) { if(!hist.isEmpty()) {
automaton.setGrid(hist.topGrid()); automaton.setGrid(hist.topGrid());
//automaton.getNeighborhoodRule()->back(); //automaton.getNeighborhoodRule()->back();
hist.popGrid(); hist.popGrid();
--time; --time;
r=true;
} }
return r;
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment