parametragemodele.cpp 15 KB
Newer Older
1
#include"parametragemodele.h"
Maxime Goret's avatar
Maxime Goret committed
2
#include <autocell.h>
3
#include <Automate.h>
4
5
6


NouveauModele::NouveauModele(QWidget* parent) : QWidget() {
7
8
9
10
11
12
13
14
15
16
	Automate::getInstance().reset();
	//create dumb ensembleetat
	Automate::getInstance().getEnsemble().ajouterEtat(0, "État 1", 0, 0, 0);
	Automate::getInstance().getEnsemble().ajouterEtat(1, "État 2", 10, 10, 30);
	Automate::getInstance().getEnsemble().ajouterEtat(2, "État 3", 10, 30, 10);
	Automate::getInstance().getEnsemble().ajouterEtat(3, "État 4", 30, 10, 10);
	Automate::getInstance().getEnsemble().ajouterEtat(4, "État 5", 100, 70, 70);
	Automate::getInstance().getEnsemble().ajouterEtat(5, "État 6", 70, 100, 70);
	Automate::getInstance().getEnsemble().ajouterEtat(6, "État 7", 70, 70, 100);
	Automate::getInstance().getEnsemble().ajouterEtat(7, "État 8", 200, 200, 200);
Maxime Goret's avatar
Maxime Goret committed
17
   // fonction.reset(new Fonction(Automate::getInstance().getEnsemble().getEtat(0)));
18
19
20
    this->setWindowTitle("Paramétrage d'un nouveau modèle");
    this->setMinimumSize(850, 550);

21
22
23
24
25
    general = new QGridLayout;
    this->setLayout(general);

    //définition de la frame paramétrage du modèle

26
    fenetre_init = new QWidget;
27
    fenetre_init->setStyleSheet("background-color: rgb(204, 209, 209)");
Maxime Goret's avatar
Maxime Goret committed
28
    fenetre_init->setFixedWidth(410);
29
    label_init = new QLabel("Configuration du modèle :");
30
31
32

    form_init = new QGridLayout(fenetre_init);

33
    form_choix = new QFormLayout;
34
35

    form_init->addWidget(label_init, 0, 0, 1, 2);
36
    form_init->addLayout(form_choix, 1, 0, 8, 2);
37

38
39
    // infos sur l'automate
    QString nomDefaut = "Nouvel automate";
Leon Do Castelo's avatar
Leon Do Castelo committed
40
    nom_automate = new QLineEdit(nomDefaut);
41
    QString auteurDefaut = "Anonym";
Leon Do Castelo's avatar
Leon Do Castelo committed
42
    auteur = new QLineEdit(auteurDefaut);
43
    QString anneeDefaut = "2000";
Leon Do Castelo's avatar
Leon Do Castelo committed
44
    annee = new QLineEdit(anneeDefaut);
45
    QString descDefaut = "Nouvel automate créé par l'utilisateur";
Leon Do Castelo's avatar
Leon Do Castelo committed
46
    description = new QLineEdit(descDefaut);
47
    // nb d'états
Leon Do Castelo's avatar
Leon Do Castelo committed
48
    nb_etats = new QSpinBox;
Leon Do Castelo's avatar
Leon Do Castelo committed
49
    nb_etats->setRange(2, 8);
Boris Cazic's avatar
Boris Cazic committed
50
51
    QSpinBox* etat_defaut = new QSpinBox;
    etat_defaut->setRange(0,nb_etats->value()-1);
52

53
    //choisir un voisinage
54
    liste_voisinage = new QComboBox;
55

56

Maxime Goret's avatar
Maxime Goret committed
57
58

    liste_voisinage->setPlaceholderText("--- select ---");
59
    liste_voisinage->setCurrentIndex(-1);
Maxime Goret's avatar
Maxime Goret committed
60

61

62
63
64
    connect(liste_voisinage, SIGNAL(currentTextChanged(const QString&)), this, SLOT(paramVoisinage(const QString&)));

    //choisir une règle de transition
65
    liste_regle_transition = new QComboBox;
Maxime Goret's avatar
Maxime Goret committed
66
67

    liste_regle_transition->setPlaceholderText("--- select ---");
68
69

    //liste_regle_transition->addItem("--- select ---");
70
    liste_regle_transition->addItem("Life Game");
71
    liste_regle_transition->addItem("Langston's Loop");
72
73
    liste_regle_transition->addItem("Brian's brain");
    liste_regle_transition->addItem("Circulaire de Griffeath");
Maxime Goret's avatar
Maxime Goret committed
74
75
    liste_regle_transition->addItem("Nouvelle fonction de transition");

76
77
78
79
    liste_regle_transition->setCurrentIndex(-1);

    //connect(liste_regle_transition, SIGNAL(currentIndexChanged(int)), liste_voisinage, SLOT(setCurrentIndex(int)));
    connect(liste_regle_transition, SIGNAL(currentTextChanged(const QString&)), this, SLOT(changerVoisinage(const QString&)));
Maxime Goret's avatar
Maxime Goret committed
80
    connect(liste_regle_transition, SIGNAL(currentTextChanged(const QString&)), this, SLOT(paramRegle(const QString)));
81
82

    bouton_valide = new QPushButton("Valider");
Maxime Goret's avatar
Maxime Goret committed
83

Maxime Goret's avatar
Maxime Goret committed
84
85
86
87
88
    layoutvalid = new QHBoxLayout;

    boutonEtat = new QPushButton("Etats");

    connect(boutonEtat, SIGNAL(clicked()), this, SLOT(parametrerEtats()));
Maxime Goret's avatar
Maxime Goret committed
89
    connect(bouton_valide, SIGNAL(clicked()), this, SLOT(validerParametrage()));
90

Maxime Goret's avatar
Maxime Goret committed
91
    //ajout regle :
92
93
94
95
    form_choix->addRow("Nom automate :", nom_automate);
    form_choix->addRow("Auteur :", auteur);
    form_choix->addRow("Année :", annee);
    form_choix->addRow("Description :", description);
Maxime Goret's avatar
Merge    
Maxime Goret committed
96
    //form_choix->addRow("Etat par défaut", etat_defaut);
97
98
    form_choix->addRow("Nombre d'états :", nb_etats);
    form_choix->addRow("Règle de transition :", liste_regle_transition);
Maxime Goret's avatar
Maxime Goret committed
99
100
101
    form_choix->addRow(layoutvalid);
    layoutvalid->addWidget(bouton_valide);
    layoutvalid->addWidget(boutonEtat);
Maxime Goret's avatar
Maxime Goret committed
102

103
    general->addWidget(fenetre_init, 0, 0, 9, 1);
104
105

    //définition de la frame contenant la grille de sélection du voisinage
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    fenetre_param = new QWidget;
    fenetre_param->setFixedWidth(500);
    label_param = new QLabel("Paramétrer votre choix :");

    form_param = new QGridLayout(fenetre_param);
    form_rayon = new QFormLayout;
    rayon = new QSpinBox;

    general->addWidget(label_param, 0, 1, 1, 1);
    general->addWidget(fenetre_param, 1, 1, 8, 1);

    /*
    form_param->addWidget(label_param, 0, 0, 1, 1);
    form_param->addLayout(form_rayon, 1, 0, 8, 1);

    general->addWidget(fenetre_param, 0, 1, 9, 1);
    */
123

Maxime Goret's avatar
Maxime Goret committed
124

125
126
}

Romain De Laage De Bellefaye's avatar
Romain De Laage De Bellefaye committed
127
128
129
130
131
void NouveauModele::parametrerEtats() {
	paramAlpha.reset(new ParamAlpha(nb_etats->value()));
	paramAlpha->show();
}

132
133
void NouveauModele::paramVoisinage(const QString& choix_voisinage){
    if(choix_voisinage == "Voisinage de von Neumann" || choix_voisinage == "Voisinage de Moore"){
Maxime Goret's avatar
Maxime Goret committed
134
        if (form_rayon != nullptr) delete form_rayon;
Maxime Goret's avatar
Maxime Goret committed
135
136
        if (grid != nullptr) delete grid;

Maxime Goret's avatar
Maxime Goret committed
137
138
139
        grid = new QTableWidget;
        grid = nullptr;

140
141
142
143
144
145
146
147
148
149
        form_rayon = new QFormLayout;
        rayon = new QSpinBox;

        form_rayon->addRow("Rayon du voisinage :", rayon);
        form_param->addLayout(form_rayon, 0, 0, 1, 1);
        //form_param->addLayout(form_rayon, 1, 0, 8, 1);
    }
    else if(choix_voisinage == "Voisinage arbitraire") {
        this->affGrille();
    }
150
    //else if(choix_voisinage == "--- select ---"){
151
152
        //delete form_rayon;
        //delete grid;
153
    //}
154
155

}
Maxime Goret's avatar
Maxime Goret committed
156

Maxime Goret's avatar
Maxime Goret committed
157
158


159
void NouveauModele::affGrille() {
Maxime Goret's avatar
Maxime Goret committed
160
    if (grid != nullptr) delete grid;
Maxime Goret's avatar
Maxime Goret committed
161
    grid = new QTableWidget(5,5);
Maxime Goret's avatar
Maxime Goret committed
162
    form_param->addWidget(grid, 0, 0, 7, 3);
163
164
165
166
167
168
169
170
171

    grid->horizontalHeader()->setVisible(false); //Pas de nom pour les colonnes.
    grid->verticalHeader()->setVisible(false);
    grid->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //Pas de barre pour scroller.
    grid->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    for(unsigned int i=0; i<5; i++){
        for(unsigned int j=0; j<5; j++)
        {
Maxime Goret's avatar
Maxime Goret committed
172
173
            grid->setRowHeight(j,80);
            grid->setColumnWidth(j,80);
174
175
176
177
178
179
180
181
182
183
184
185
186

            /*
            int x = i-3;
            int y = -1*(j-2);
            std::string co = "(";
            co += x;
            co += ",";
            co += y;
            co += ")";
            QString coordonnees = co;
            */

            grid->setItem(i, j, new QTableWidgetItem);
Maxime Goret's avatar
Maxime Goret committed
187
188
                grid->item(i, j)->setFlags(Qt::ItemIsEnabled);
                grid->item(i,j)->setBackground(Qt::white);
189

Maxime Goret's avatar
Maxime Goret committed
190
            }
191
        }
Maxime Goret's avatar
Maxime Goret committed
192
193
    QColor noir = Qt::black;
    grid->item(2,2)->setBackground(noir);
Maxime Goret's avatar
Maxime Goret committed
194

195
196
197
    connect(grid, SIGNAL(clicked(const QModelIndex&)), this, SLOT(modifGrille(const QModelIndex&)));
}

Maxime Goret's avatar
Maxime Goret committed
198
199


200
201
202
void NouveauModele::modifGrille(const QModelIndex& index){
    unsigned int i = index.row();
    unsigned int j = index.column();
203

204
    QColor rouge = Qt::red;
Maxime Goret's avatar
Maxime Goret committed
205
206
    QColor blanc = Qt::white;

Maxime Goret's avatar
Maxime Goret committed
207
    if (i == 2 && j == 2){
Maxime Goret's avatar
Maxime Goret committed
208
209
210
211
212
213
       return;
    }else if (grid->item(i,j)->background() == blanc){
         grid->item(i,j)->setBackground(rouge);
    }else if(grid->item(i,j)->background() == rouge){
         grid->item(i,j)->setBackground(blanc);
    }
Maxime Goret's avatar
Maxime Goret committed
214

215
216
}

217
218
void NouveauModele::changerVoisinage(const QString& choix_regle){

Maxime Goret's avatar
Maxime Goret committed
219
    //delete liste_voisinage;
220
221
    form_choix->removeRow(2);
    liste_voisinage = new QComboBox();
222

Maxime Goret's avatar
Maxime Goret committed
223
224


225
226
227
228
229
230
231
232
233
234
235
    if(choix_regle == "Life Game"){
        //liste_voisinage->addItem("--- select ---");
        liste_voisinage->addItem("Voisinage de von Neumann");
        liste_voisinage->addItem("Voisinage arbitraire");
        liste_voisinage->setCurrentIndex(-1);
    }
    else if(choix_regle == "Langston's Loop"){
        liste_voisinage->addItem("Voisinage de Moore");
        liste_voisinage->addItem("Voisinage arbitraire");
        liste_voisinage->setCurrentIndex(-1);
    }
Maxime Goret's avatar
Maxime Goret committed
236
    else if(choix_regle == "Brian's brain" || choix_regle == "Circulaire de Griffeath" || choix_regle == "Nouvelle fonction de transition"){
237
238
239
240
241
242
243
244
245
        //liste_voisinage->addItem("--- select ---");
        liste_voisinage->addItem("Voisinage de Moore");
        liste_voisinage->addItem("Voisinage de von Neumann");
        liste_voisinage->addItem("Voisinage arbitraire");
        liste_voisinage->setCurrentIndex(-1);
    }
    form_choix->insertRow(2, "Voisinage :", liste_voisinage);
    connect(liste_voisinage, SIGNAL(currentTextChanged(const QString&)), this, SLOT(paramVoisinage(const QString&)));
}
Maxime Goret's avatar
Maxime Goret committed
246

Maxime Goret's avatar
Maxime Goret committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

void NouveauModele::choisirEtatCourant(const QString& validEtat){

    if (validEtat == "Oui"){

        if (fin != nullptr) delete fin;
        if (next != nullptr) delete next;
        if (layouth5 != nullptr) delete layouth5;
        if (layouth6 != nullptr) delete layouth6;
        if (layoutv2 != nullptr) delete layoutv2;
        if (etatCourant2 != nullptr) delete etatCourant2;
        if (numEtatCourant != nullptr) delete numEtatCourant;

        layouth6 = new QHBoxLayout;
        layouth5 = new QHBoxLayout;
        layoutv2 = new QVBoxLayout;


        fin = new QPushButton("Terminer");
        next = new QPushButton("Règle suivante");

        form_choix->addRow(layoutv2);
        layoutv2->addLayout(layouth5);
        layoutv2->addLayout(layouth6);


        etatCourant2 = new QLabel("Etat Courant : ");

        numEtatCourant = new QSpinBox;
        numEtatCourant->setRange(1,8);

        layouth5->addWidget(etatCourant2);
        layouth5->addWidget(numEtatCourant);

        layouth6->addWidget(fin);
        layouth6->addWidget(next);
        connect(next, SIGNAL(clicked()), this, SLOT(addRegle()));

    }else{


       if (fin != nullptr) delete fin;
       if (next != nullptr) delete next;
       if (layouth5 != nullptr) delete layouth5;
       if (layouth6 != nullptr) delete layouth6;
       if (layoutv2 != nullptr) delete layoutv2;
       if (etatCourant2 != nullptr) delete etatCourant2;
       if (numEtatCourant != nullptr) delete numEtatCourant;

       numEtatCourant = new QSpinBox;
       numEtatCourant = nullptr;

       layouth6 = new QHBoxLayout;
       layouth5 = new QHBoxLayout;
       layoutv2 = new QVBoxLayout;


       etatCourant2 = new QLabel("Etat Courant non pris en compte ");

       fin = new QPushButton("Terminer");
       next = new QPushButton("Règle suivante");

       form_choix->addRow(layoutv2);
       layoutv2->addLayout(layouth5);
       layoutv2->addLayout(layouth6);
       layouth5->addWidget(etatCourant2);
       layouth6->addWidget(fin);
       layouth6->addWidget(next);

       connect(next, SIGNAL(clicked()), this, SLOT(addRegle()));

    }


}

void NouveauModele::paramRegle(const QString& choix_regle) {
    seuilMax = new QLabel("Seuil Max : ");
    seuilMin = new QLabel("Seuil Min : ");
    destination = new QLabel("Destination : ");
    etatCourant = new QLabel("Etat Courant : ");
Maxime Goret's avatar
Merge    
Maxime Goret committed
328
329
330
331
    etat_d = new QLabel("Etat défault : ");

    etat_default = new QSpinBox;
    etat_default->setRange(0,(nb_etats->value())-1);
Maxime Goret's avatar
Maxime Goret committed
332

Leon Do Castelo's avatar
Leon Do Castelo committed
333
334
335
336
337
    /*QLabel* etat_d = new QLabel("Etat Defaut : ");
    QSpinBox* etat_defaut = new QSpinBox;
    etat_defaut->setRange(0,nb_etats->value()-1);
    form_choix->addRow("Etat par défaut", etat_defaut);*/

Boris Cazic's avatar
Boris Cazic committed
338
    QSpinBox* etatDest = new QSpinBox;
Leon Do Castelo's avatar
Leon Do Castelo committed
339
    etatDest->setRange(0, nb_etats->value()-1);
Maxime Goret's avatar
Maxime Goret committed
340
341
342
343
344
345
346
347
348

    valid_Etat = new QComboBox;
    valid_Etat->addItem("Oui");
    valid_Etat->addItem("Non");
    valid_Etat->setCurrentIndex(-1);

    if (choix_regle == "Nouvelle fonction de transition") {
        seuilValidator=new QIntValidator;

Maxime Goret's avatar
Merge    
Maxime Goret committed
349
        //if(layouth != nullptr) delete layouth;
Maxime Goret's avatar
Maxime Goret committed
350
351
352
353
354
355
356
357
358
        if(layouth1 != nullptr) delete layouth1;
        if(layouth2 != nullptr) delete layouth2;
        if(layouth3 != nullptr) delete layouth3;
        if(layouth4 != nullptr) delete layouth4;
        if(layoutv != nullptr) delete layoutv;
        if(layouth5 != nullptr) delete layouth5;
        if(layouth6 != nullptr) delete layouth6;
        if(layoutv2 != nullptr) delete layoutv2;

Maxime Goret's avatar
Merge    
Maxime Goret committed
359
360
        layoutv = new QVBoxLayout;
        layouth = new QHBoxLayout;
Maxime Goret's avatar
Maxime Goret committed
361
362
363
364
365
        layouth1 = new QHBoxLayout;
        layouth2 = new QHBoxLayout;
        layouth3 = new QHBoxLayout;
        layouth4 = new QHBoxLayout;

Maxime Goret's avatar
Merge    
Maxime Goret committed
366
367
368
369

        //layouth6 = new QHBoxLayout;
        //layouth5 = new QHBoxLayout;
        //layoutv2 = new QVBoxLayout;
Maxime Goret's avatar
Maxime Goret committed
370
371
372
373
374
375

        form_choix->addRow(layoutv);
        layoutv->addLayout(layouth1);
        layoutv->addLayout(layouth2);
        layoutv->addLayout(layouth3);
        layoutv->addLayout(layouth4);
Maxime Goret's avatar
Merge    
Maxime Goret committed
376
        layoutv->addLayout(layouth);
Maxime Goret's avatar
Maxime Goret committed
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410



        seuilValidator->setRange(0,1);

        layouth1->addWidget(seuilMin);
        for(unsigned int i=0; i<8; i++) {
            numSeuilMin[i]=new QLineEdit;
            numSeuilMin[i]->setFixedWidth(22);
            numSeuilMin[i]->setMaxLength(2);
            numSeuilMin[i]->setText("-1");
            numSeuilMin[i]->setValidator(seuilValidator);
            if (i<nb_etats->value()){
            layouth1->addWidget(numSeuilMin[i]);
            }
         }


         layouth2->addWidget(seuilMax);
         for(unsigned int i=0; i<8; i++) {
             numSeuilMax[i]=new QLineEdit;
             numSeuilMax[i]->setFixedWidth(22);
             numSeuilMax[i]->setMaxLength(2);
             numSeuilMax[i]->setText("-1");
             numSeuilMax[i]->setValidator(seuilValidator);
             if (i<nb_etats->value()){
             layouth2->addWidget(numSeuilMax[i]);
             }
         }
         layouth3->addWidget(destination);
         layouth3->addWidget(etatDest);

         layouth4->addWidget(etatCourant);
         layouth4->addWidget(valid_Etat);
Maxime Goret's avatar
Merge    
Maxime Goret committed
411
412
413

         layouth->addWidget(etat_d);
         layouth->addWidget(etat_default);
Maxime Goret's avatar
Maxime Goret committed
414
415
416
417
418
419
420
421
422
423
         connect(valid_Etat, SIGNAL(currentTextChanged(const QString&)), this, SLOT(choisirEtatCourant(const QString&)));
    }
}



void NouveauModele::addRegle(){
    paramRegle("Nouvelle fonction de transition");
}

Leon Do Castelo's avatar
Leon Do Castelo committed
424
425
426
427
428
429
430
431
void NouveauModele::validerParametrage(){

    Automate::getInstance().setTitle(nom_automate->text().toStdString());
    Automate::getInstance().setAuthor(auteur->text().toStdString());
    Automate::getInstance().setDesc(description->text().toStdString());
    Automate::getInstance().setYear(annee->text().toInt());

    /*
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
	Automate::getInstance().setTitle(nom_automate->value().toStdString());
	Automate::getInstance().setAuthor(auteur->value().toStdString());
	Automate::getInstance().setYear(anneee->value().toInt());
	Automate::getInstance().setDescription(description->value().toStdString());
	Automate::getInstance().setFonction(fonction.get());
	if (liste_voisinage->currentText().toStdString() == "Voisinage de von Neumann") {
		RegleVoisinageNeumann *regle_voisins = new RegleVoisinageNeumann;
		regle_voisins->setr(rayon.value());
		Automate::getInstance().setRegleVoisinage(rayon_voisins);
	}
	else if (liste_voisinage->currentText().toStdString() == "Voisinage de Moore") {
		RegleVoisinageMoore *regle_voisins = new RegleVoisinageMoore;
		regle_voisins->setr(rayon.value());
		Automate::getInstance().setRegleVoisinage(rayon_voisins);
	}
	else if (liste_voisinage->currentText().toStdString() == "Voisinage arbitraire") {
		//todo
	}
	Database::saveAutomaton(Automate::getInstance());
Maxime Goret's avatar
Maxime Goret committed
451
452
453
454
    if(nvAutocell != nullptr) delete nvAutocell;

    nvAutocell = new AutoCell;

Leon Do Castelo's avatar
Leon Do Castelo committed
455
456
    nvAutocell->show();*/
}
Maxime Goret's avatar
Maxime Goret committed
457