Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LO21_Pin_Noir_Boucher_Bouri_Detree
CellulutLO21
Commits
8b139896
Commit
8b139896
authored
Jun 07, 2021
by
Eugene Pin
Browse files
Grille de choix des voisins
#47
parent
f8208ee6
Pipeline
#79322
canceled with stage
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/neighborhoodDialog.hpp
View file @
8b139896
...
...
@@ -16,22 +16,24 @@ class NeighborhoodDialog : public QDialog
Coord
currentPoint
;
public:
explicit
NeighborhoodDialog
(
QWidget
*
parent
=
nullptr
);
explicit
NeighborhoodDialog
(
Neighborhood
&
n
,
QWidget
*
parent
=
nullptr
);
~
NeighborhoodDialog
();
//! \brief Retourne le voisinage
Neighborhood
*
getVoisinage
()
const
;
GridView
&
getGridView
()
const
;
void
ResizeCreateGrid
(
int
x
,
int
y
,
Neighborhood
&
n
);
public
slots
:
Neighborhood
&
getNeighborhood
()
const
;
Neighborhood
*
getNeighborhood
()
const
;
protected:
void
done
(
int
r
);
private
slots
:
void
on_validateGridDim_2_clicked
();
void
on_heightSpinBox_2_valueChanged
(
int
arg1
);
void
on_widthSpinBox_2_valueChanged
(
int
arg1
);
private:
Ui
::
NeighborhoodDialog
*
ui
;
};
...
...
include/propertyvisitors.hpp
View file @
8b139896
...
...
@@ -16,6 +16,7 @@ Fichier contenant diverses classes filles de PropertyVisitor permettant l'affich
#include <QVariant>
#include "property.hpp"
#include "neighborhoodDialog.hpp"
//! \brief Exception lancée lors d'une erreur liée aux visiteurs de propriétés.
class
PropertyVisitorException
:
public
std
::
exception
...
...
@@ -51,6 +52,7 @@ private:
QWidget
*
current_widget
();
void
push_array_widget
(
const
Property
&
prop
);
QWidget
*
pop_widget
();
NeighborhoodDialog
*
neighborhoodDialog
;
private:
void
visit
(
StringProperty
&
str
);
...
...
src/neighborhoodDialog.cpp
View file @
8b139896
...
...
@@ -4,7 +4,7 @@
#include <QDate>
#include <QMessageBox>
NeighborhoodDialog
::
NeighborhoodDialog
(
QWidget
*
parent
)
:
NeighborhoodDialog
::
NeighborhoodDialog
(
Neighborhood
&
n
,
QWidget
*
parent
)
:
QDialog
(
parent
),
ui
(
new
Ui
::
NeighborhoodDialog
)
{
ui
->
setupUi
(
this
);
...
...
@@ -23,44 +23,62 @@ NeighborhoodDialog::NeighborhoodDialog(QWidget *parent) :
gv
.
set_alphabet
(
a
);
// Initialisation taille de la grille
int
xMax
=
11
;
int
yMax
=
11
;
int
nbrVoisins
=
n
.
size
();
QSize
size
=
gv
.
grid_size
();
currentPoint
=
{
size
.
width
()
/
2
,
size
.
height
()
/
2
};
Grid
newGrid
(
gv
.
get_grid
());
newGrid
.
set_cell
(
currentPoint
,
2
);
gv
.
copy_grid
(
newGrid
);
gv
.
enable_toggle_mode
(
1
,
0
);
// TODO le clic sur la cellule centrale
}
for
(
int
i
=
0
;
i
<
nbrVoisins
;
i
++
)
{
int
currentX
=
n
.
neighbor_at_index
(
i
).
first
.
x
;
int
currentY
=
n
.
neighbor_at_index
(
i
).
first
.
y
;
if
(
abs
(
currentX
)
>=
xMax
/
2
)
xMax
=
(
abs
(
currentX
)
+
1
)
*
2
;
if
(
abs
(
currentY
)
>=
yMax
/
2
)
yMax
=
(
abs
(
currentY
)
+
1
)
*
2
;
}
NeighborhoodDialog
::~
NeighborhoodDialog
()
{
delete
ui
;
std
::
cout
<<
"xMax ="
<<
xMax
<<
" yMax="
<<
yMax
<<
endl
;
ui
->
widthSpinBox_2
->
setValue
(
xMax
);
ui
->
heightSpinBox_2
->
setValue
(
yMax
);
ResizeCreateGrid
(
xMax
,
yMax
,
n
);
gv
.
enable_toggle_mode
(
1
,
0
);
gv
.
add_toggle_rule
(
3
,
2
);
}
void
NeighborhoodDialog
::
done
(
int
r
)
void
NeighborhoodDialog
::
ResizeCreateGrid
(
int
x
,
int
y
,
Neighborhood
&
n
)
{
if
(
QDialog
::
Accepted
==
r
)
// ok was pressed
{
GridView
&
gv
=
*
(
*
ui
).
grid_view
;
int
nbrVoisins
=
n
.
size
();
Grid
newGrid
(
y
,
x
);
currentPoint
=
{
x
/
2
,
y
/
2
};
newGrid
.
set_cell
(
currentPoint
,
2
);
for
(
int
i
=
0
;
i
<
nbrVoisins
;
i
++
)
{
Coord
newNeighborRelative
=
n
.
neighbor_at_index
(
i
).
first
;
if
(
newNeighborRelative
==
Coord
{
0
,
0
})
{
newGrid
.
set_cell
(
currentPoint
,
3
);
}
else
{
Coord
newNeighborAbsolute
=
{
currentPoint
.
x
+
newNeighborRelative
.
x
,
currentPoint
.
y
+
newNeighborRelative
.
y
};
if
(
(
newNeighborAbsolute
.
x
<
x
&&
newNeighborAbsolute
.
y
<
y
))
{
newGrid
.
set_cell
(
newNeighborAbsolute
,
1
);
}
}
}
else
// cancel, close or exc was pressed
{
QDialog
::
done
(
r
);
return
;
}
gv
.
copy_grid
(
newGrid
);
}
Neighborhood
*
NeighborhoodDialog
::
getVoisinage
()
const
Neighborhood
Dialog
::~
NeighborhoodDialog
()
{
return
nullptr
;
delete
ui
;
}
GridView
&
NeighborhoodDialog
::
getGridView
()
const
{
return
*
(
ui
->
grid_view
);
void
NeighborhoodDialog
::
done
(
int
r
)
{
QDialog
::
done
(
r
);
return
;
}
Neighborhood
&
NeighborhoodDialog
::
getNeighborhood
()
const
Neighborhood
*
NeighborhoodDialog
::
getNeighborhood
()
const
{
Neighborhood
*
newNeighborhood
=
new
Neighborhood
;
Grid
currentGrid
=
ui
->
grid_view
->
get_grid
();
...
...
@@ -69,7 +87,7 @@ Neighborhood& NeighborhoodDialog::getNeighborhood() const
int
width
=
currentSizeGrid
.
width
();
for
(
int
j
=
0
;
j
<
height
;
j
++
)
{
for
(
int
i
=
0
;
i
<
width
;
i
++
)
{
if
(
currentGrid
.
get_state
({
i
,
j
})
==
1
)
{
if
(
currentGrid
.
get_state
({
i
,
j
})
==
1
||
currentGrid
.
get_state
({
i
,
j
})
==
3
)
{
Coord
newCoord
=
{
i
-
currentPoint
.
x
,
j
-
currentPoint
.
y
};
newNeighborhood
->
addNeighbor
(
newCoord
,
1
);
std
::
cout
<<
"Nouveau voisin : X="
<<
newCoord
.
x
<<
" Y="
<<
newCoord
.
y
<<
endl
;
...
...
@@ -77,5 +95,64 @@ Neighborhood& NeighborhoodDialog::getNeighborhood() const
}
}
}
return
*
newNeighborhood
;
return
newNeighborhood
;
}
void
NeighborhoodDialog
::
on_validateGridDim_2_clicked
()
{
Grid
oldGrid
=
ui
->
grid_view
->
get_grid
();
unsigned
int
nbrRow
=
ui
->
heightSpinBox_2
->
value
();
// nbr de lignes => axe y
unsigned
int
nbrCol
=
ui
->
widthSpinBox_2
->
value
();
// nbr de colonne => axe x
Grid
newGrid
(
nbrCol
,
nbrRow
);
Neighborhood
*
oldNeighborhood
=
this
->
getNeighborhood
();
ResizeCreateGrid
(
nbrCol
,
nbrRow
,
*
oldNeighborhood
);
ui
->
validateGridDim_2
->
setEnabled
(
false
);
delete
oldNeighborhood
;
/*
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 (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;
}
}
}
ui->grid_view->copy_grid(newGrid);
ui->validateGridDim_2->setEnabled(false);
*/
}
void
NeighborhoodDialog
::
on_heightSpinBox_2_valueChanged
(
int
)
{
ui
->
validateGridDim_2
->
setEnabled
(
true
);
}
void
NeighborhoodDialog
::
on_widthSpinBox_2_valueChanged
(
int
)
{
ui
->
validateGridDim_2
->
setEnabled
(
true
);
}
src/uibuildervisitor.cpp
View file @
8b139896
#include "propertyvisitors.hpp"
#include "neighborhoodDialog.hpp"
#include <QGroupBox>
#include <QPushButton>
...
...
@@ -185,19 +185,21 @@ void UIBuilderVisitor::visit(PropertyList &list)
add_button
->
setEnabled
(
true
);
}
});
QObject
::
connect
(
widgetGridNeighborhoodButton
,
&
QPushButton
::
pressed
,
[
&
list
]()
{
NeighborhoodDialog
*
nw
=
new
NeighborhoodDialog
;
nw
->
exec
();
/*
QObject::connect(validateButton, &QPushButton::pressed, [&list, &nw] () {
list.clear();
Neighborhood newNeighborhood = nw->getNeighborhood();
// TODO a finir
list.push_back();
});*/
// QObject::connect(validateButton, &QPushButton::pressed, nw, &QDialog::done );
QObject
::
connect
(
widgetGridNeighborhoodButton
,
&
QPushButton
::
pressed
,
[
this
,
&
list
,
list_widget
]()
{
Neighborhood
currentNeighborhood
=
list
.
to_neighborhood
();
neighborhoodDialog
=
new
NeighborhoodDialog
(
currentNeighborhood
);
if
(
neighborhoodDialog
->
exec
()
)
{
std
::
cout
<<
"sacreubleu"
<<
endl
;
fflush
(
stdout
);
list
.
clear
();
Neighborhood
*
newNeighborhood
=
neighborhoodDialog
->
getNeighborhood
();
list
.
load_from_neighborhood
(
*
newNeighborhood
);
delete
newNeighborhood
;
UIBuilderVisitor
visit
(
list_widget
);
for
(
const
auto
&
ptr
:
list
.
contents
)
ptr
->
accept
(
visit
);
}
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment