Commit be586086 authored by Yann Boucher's avatar Yann Boucher
Browse files

Linked the UI with the Simulation object of MainWindow

parent 707a30ce
Pipeline #78769 passed with stages
in 17 seconds
......@@ -97,5 +97,7 @@ private:
private:
Ui::MainWindow *ui;
Simulation simulation;
TransitionRule* m_transition_rule;
NeighborhoodRule* m_neighborhood_rule;
};
#endif // MAINWINDOW_HPP
......@@ -18,6 +18,9 @@ MainWindow::MainWindow(QWidget *parent)
{
ui->setupUi(this);
m_transition_rule = nullptr;
m_neighborhood_rule = nullptr;
init_transition_neighborhood_list();
update_transition_settings();
update_neighborhood_settings();
......@@ -36,6 +39,10 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
delete ui;
if (m_transition_rule)
delete m_transition_rule;
if (m_neighborhood_rule)
delete m_neighborhood_rule;
}
/// Connections
......@@ -250,42 +257,39 @@ void MainWindow::init_transition_neighborhood_list()
}
}
// TODO FIXME quand on aura une classe simulation commune
static std::unique_ptr<TransitionRule> transition_rule;
static std::unique_ptr<NeighborhoodRule> neighborhood_rule;
void MainWindow::update_transition_settings()
{
std::string selected = ui->transition_list->currentText().toStdString();
transition_rule = Factory<TransitionRule>::make(selected);
if (!transition_rule)
m_transition_rule = Factory<TransitionRule>::make(selected).release();
if (!m_transition_rule)
return;
if (transition_rule->get_properties().size() == 0)
if (m_transition_rule->get_properties().size() == 0)
ui->rule_settings_area->hide();
else
{
ui->rule_settings_area->show();
UIBuilderVisitor visit(ui->rule_settings_area);
for (auto& prop : transition_rule->get_properties())
for (auto& prop : m_transition_rule->get_properties())
prop->accept(visit);
}
}
void MainWindow::update_neighborhood_settings()
{
std::string selected = ui->neighborhood_list->currentText().toStdString();
neighborhood_rule = Factory<NeighborhoodRule>::make(selected);
if (!neighborhood_rule)
m_neighborhood_rule = Factory<NeighborhoodRule>::make(selected).release();
if (!m_neighborhood_rule)
return;
if (neighborhood_rule->get_properties().size() == 0)
if (m_neighborhood_rule->get_properties().size() == 0)
ui->neighborhood_settings_area->hide();
else
{
ui->neighborhood_settings_area->show();
UIBuilderVisitor visit(ui->neighborhood_settings_area);
for (auto& prop : neighborhood_rule->get_properties())
for (auto& prop : m_neighborhood_rule->get_properties())
prop->accept(visit);
}
}
......@@ -295,6 +299,9 @@ void MainWindow::enable_rule_customization()
ui->simulation_tab->setEnabled(false);
ui->customize_button->setEnabled(false);
ui->rule_settings->setEnabled(true);
update_neighborhood_settings();
update_transition_settings();
}
void MainWindow::disable_rule_customization()
......@@ -317,21 +324,25 @@ void MainWindow::load_model(const QJsonObject &obj)
{
PropertyLoaderVisitor loader(obj.value("transition_data").toObject());
for (auto& prop : transition_rule->get_properties())
for (auto& prop : m_transition_rule->get_properties())
prop->accept(loader);
UIBuilderVisitor visit(ui->rule_settings_area);
for (auto& prop : transition_rule->get_properties())
for (auto& prop : m_transition_rule->get_properties())
prop->accept(visit);
}
{
PropertyLoaderVisitor loader(obj.value("neighborhood_data").toObject());
for (auto& prop : neighborhood_rule->get_properties())
for (auto& prop : m_neighborhood_rule->get_properties())
prop->accept(loader);
UIBuilderVisitor visit(ui->neighborhood_settings_area);
for (auto& prop : neighborhood_rule->get_properties())
for (auto& prop : m_neighborhood_rule->get_properties())
prop->accept(visit);
}
// On transfère la propriété de ces pointeurs vers Simulation, qui en est désormais propriétaire pour l'exécution de l'automate
simulation.setNeighborhoodRule(m_neighborhood_rule); m_neighborhood_rule = nullptr;
simulation.setTransitionRule(m_transition_rule); m_transition_rule = nullptr;
}
void MainWindow::save_model()
......@@ -343,11 +354,11 @@ void MainWindow::save_model()
QString filename = QFileDialog::getSaveFileName(this, "Choisir un nom de fichier", QString(), "Modèle d'automate (*.json)");
PropertySaverVisitor trans_saver;
for (auto& prop : transition_rule->get_properties())
for (auto& prop : m_transition_rule->get_properties())
prop->accept(trans_saver);
PropertySaverVisitor neighborhood_saver;
for (auto& prop : neighborhood_rule->get_properties())
for (auto& prop : m_neighborhood_rule->get_properties())
prop->accept(neighborhood_saver);
QJsonObject root;
......@@ -375,6 +386,8 @@ void MainWindow::save_model()
ui->rule_name->setText(dialog.titre());
disable_rule_customization();
load_model(root);
}
QJsonObject MainWindow::default_model() const
......
Markdown is supported
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