Commit 1c7fd3f8 authored by Eugene Pin's avatar Eugene Pin
Browse files

#47 #49 Implementation grille aléatoire de départ et amélioaration du...

#47 #49 Implementation grille aléatoire de départ et amélioaration du redimensionnement (conservation des états des cellules)
parent 6a4ad98a
Pipeline #78232 passed with stages
in 17 seconds
......@@ -51,6 +51,9 @@ private slots:
void on_nbrStateComboBox_currentTextChanged(const QString &arg1);
//! \brief Créer une nouvelle grille ayant des états aléatoire
void on_randomPatternButton_clicked();
private:
Ui::MainWindow *ui;
};
......
......@@ -64,12 +64,12 @@ void MainWindow::on_neighborhoodComboBox_currentTextChanged(const QString &arg1)
}
}
void MainWindow::on_widthSpinBox_valueChanged(int arg1)
void MainWindow::on_widthSpinBox_valueChanged(int)
{
ui->validateGridDim->setEnabled(true);
}
void MainWindow::on_heightSpinBox_valueChanged(int arg1)
void MainWindow::on_heightSpinBox_valueChanged(int)
{
ui->validateGridDim->setEnabled(true);
}
......@@ -121,17 +121,31 @@ void MainWindow::on_validateGridDim_clicked()
Grid oldGrid = ui->grid_view->get_grid();
delete ui->grid_view;
unsigned int height = ui->heightSpinBox->value();
unsigned int width = ui->widthSpinBox->value();
Grid newGrid(height, width);
unsigned int nbrRow = ui->heightSpinBox->value(); // nbr de lignes => axe y
unsigned int nbrCol = ui->widthSpinBox->value(); // nbr de colonne => axe x
Grid newGrid(nbrRow, nbrCol);
fflush(stdout);
if(oldGrid.get_rows() < height && oldGrid.get_col() < width) {
unsigned oldNbrRow = oldGrid.get_rows(); // rows = nbr de lignes => axe y
unsigned oldNbrCol = oldGrid.get_col(); // col = nbr de colonne => axe x
if(oldNbrRow <= nbrRow && oldNbrCol <= nbrCol) {
//std::cout << "superieur\n";
fflush(stdout);
for (unsigned y = 0; y < oldNbrRow ; y++) {
for (unsigned x = 0; x < oldNbrCol ; x++) {
Coord pos = {static_cast<int>(x), static_cast<int>(y)};
newGrid.set_cell(pos, oldGrid.get_state(pos));
//std::cout << "oldState : " << oldGrid.get_state(pos) << endl;
}
}
}
else
{
//std::cout << "superieur\n";
fflush(stdout);
for (int i = 0; i < static_cast<int>(oldGrid.get_rows()) ; i++) {
for (int j = 0; j < static_cast<int>(oldGrid.get_col()) ; j++) {
Coord pos = {i, j};
for (unsigned y = 0; y < nbrRow ; y++) {
for (unsigned x = 0; x < nbrCol ; x++) {
Coord pos = {static_cast<int>(x), static_cast<int>(y)};
newGrid.set_cell(pos, oldGrid.get_state(pos));
//std::cout << "oldState : " << oldGrid.get_state(pos) << endl;
}
......@@ -143,7 +157,6 @@ void MainWindow::on_validateGridDim_clicked()
ui->grid_view->setObjectName(QString::fromUtf8("grid_view"));
ui->grid_view->setFrameShape(QFrame::StyledPanel);
ui->grid_view->setFrameShadow(QFrame::Raised);
ui->gridLayout_2->addWidget(ui->grid_view, 0, 0, 1, 1);
......@@ -156,3 +169,35 @@ void MainWindow::on_nbrStateComboBox_currentTextChanged(const QString &arg1)
ui->grid_view->set_current_pen(val);
}
void MainWindow::on_randomPatternButton_clicked()
{
// TODO Prendre en compte l'alphabet !
// int nbr = rand() % nbr de states différents;
Grid oldGrid = ui->grid_view->get_grid();
unsigned nbrRow = oldGrid.get_rows(); // rows = nbr de lignes => axe y
unsigned nbrCol = oldGrid.get_col(); // col = nbr de colonne => axe x
Grid newGrid(nbrRow, nbrCol);
for (unsigned y = 0; y < nbrRow; ++y)
{
for (unsigned x = 0; x < nbrCol; ++x)
{
// TODO Remplacer 2 par le nbr d'états différents
// TODO comprendre pourquoi il faut inverser x et y (???)
unsigned state = rand() % 2;
Coord pos = {static_cast<int>(x), static_cast<int>(y)};
std::cout << "position x= "<< pos.x << " y= "<< pos.y << endl;
newGrid.set_cell(pos, state);
}
}
delete ui->grid_view;
ui->grid_view = new GridView(ui->grid, &newGrid);
ui->grid_view->setObjectName(QString::fromUtf8("grid_view"));
ui->grid_view->setFrameShape(QFrame::StyledPanel);
ui->grid_view->setFrameShadow(QFrame::Raised);
ui->gridLayout_2->addWidget(ui->grid_view, 0, 0, 1, 1);
}
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