Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CellulutLO21
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LO21_Pin_Noir_Boucher_Bouri_Detree
CellulutLO21
Commits
32b13873
Commit
32b13873
authored
3 years ago
by
Yann Boucher
Browse files
Options
Downloads
Patches
Plain Diff
Added support for saving and loading the alphabet associated with a model
parent
fcfda1bb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#78943
passed
3 years ago
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/gridview.cpp
+5
-1
5 additions, 1 deletion
src/gridview.cpp
src/interface.cpp
+58
-8
58 additions, 8 deletions
src/interface.cpp
with
63 additions
and
9 deletions
src/gridview.cpp
+
5
−
1
View file @
32b13873
...
...
@@ -175,6 +175,7 @@ void GridGraphicsView::mousePressEvent(QMouseEvent *event)
if
(
QGuiApplication
::
keyboardModifiers
()
==
Qt
::
NoModifier
&&
event
->
button
()
==
Qt
::
LeftButton
)
{
m_gridview
.
push_history
();
m_gridview
.
click_on
(
coord
);
m_gridview
.
update_gridview
();
}
...
...
@@ -191,7 +192,6 @@ void GridGraphicsView::mousePressEvent(QMouseEvent *event)
void
GridGraphicsView
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
QPointF
item_pos
=
mapToScene
(
event
->
pos
());
if
(
!
sceneRect
().
contains
(
item_pos
)
||
!
sceneRect
().
contains
(
mapToScene
(
m_last_mouse_pos
)))
return
;
...
...
@@ -330,6 +330,8 @@ void GridView::set_alphabet(const Alphabet &alph)
m_undo_history
.
popGrid
();
m_alph
=
alph
;
// Default to using the first non-null state as the current pen
set_current_pen
(
1
);
}
const
Alphabet
&
GridView
::
alphabet
()
const
...
...
@@ -339,6 +341,7 @@ const Alphabet &GridView::alphabet() const
void
GridView
::
set_current_pen
(
unsigned
state
)
{
state
%=
m_alph
.
taille
();
m_pen
=
state
;
}
...
...
@@ -423,6 +426,7 @@ void GridView::undo()
{
load_grid
(
m_undo_history
.
popGrid
());
}
update_gridview
();
}
void
GridView
::
load_grid
(
const
Grid
&
grid
)
...
...
This diff is collapsed.
Click to expand it.
src/interface.cpp
+
58
−
8
View file @
32b13873
...
...
@@ -327,10 +327,39 @@ void MainWindow::disable_rule_customization()
void
MainWindow
::
load_model
(
const
QJsonObject
&
obj
)
{
ui
->
rule_name
->
setText
(
obj
.
value
(
"title"
).
toString
());
// TODO : load alphabet
ui
->
transition_list
->
setCurrentText
(
obj
.
value
(
"transition_name"
).
toString
());
ui
->
neighborhood_list
->
setCurrentText
(
obj
.
value
(
"neighborhood_name"
).
toString
());
bool
alpha_initialise
=
false
;
Alphabet
alpha
;
if
(
obj
.
value
(
"alphabet"
).
isArray
())
{
for
(
auto
entry
:
obj
.
value
(
"alphabet"
).
toArray
())
{
if
(
!
entry
.
isObject
())
continue
;
auto
entry_obj
=
entry
.
toObject
();
std
::
string
name
=
entry_obj
.
value
(
"name"
).
toString
().
toStdString
();
if
(
!
entry_obj
.
value
(
"color"
).
isArray
())
continue
;
auto
color_array
=
entry_obj
.
value
(
"color"
).
toArray
();
stateColor
color
(
color_array
[
0
].
toInt
(),
color_array
[
1
].
toInt
(),
color_array
[
2
].
toInt
());
// Initialisation avec le premier élement
if
(
!
alpha_initialise
)
{
alpha
=
Alphabet
(
state
(
color
,
name
));
alpha_initialise
=
true
;
}
else
alpha
.
newEtat
(
state
(
color
,
name
));
}
}
update_transition_settings
();
update_neighborhood_settings
();
disable_rule_customization
();
...
...
@@ -353,10 +382,12 @@ void MainWindow::load_model(const QJsonObject &obj)
prop
->
accept
(
visit
);
}
ui
->
grid_view
->
set_alphabet
(
alpha
);
// 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
);
simulation
.
setTransitionRule
(
m_transition_rule
);
simulation
.
setAlphabet
(
ui
->
grid_view
->
alphabet
()
);
simulation
.
setAlphabet
(
alpha
);
}
void
MainWindow
::
save_model
()
...
...
@@ -387,8 +418,19 @@ void MainWindow::save_model()
root
[
"neighborhood_name"
]
=
ui
->
neighborhood_list
->
currentText
();
root
[
"neighborhood_data"
]
=
neighborhood_saver
.
save
();
// TODO : sauvegarder l'alphabet quand on pourra y accéder avec Simulation
QJsonArray
alphabet
;
for
(
unsigned
i
=
0
;
i
<
simulation
.
getAlphabet
().
taille
();
++
i
)
{
auto
state
=
simulation
.
getAlphabet
().
getState
(
i
);
QJsonArray
color
;
QJsonObject
entry
;
entry
[
"name"
]
=
QString
::
fromStdString
(
state
.
getStateLabel
());
color
.
push_back
(
state
.
getColor
().
getRed
());
color
.
push_back
(
state
.
getColor
().
getGreen
());
color
.
push_back
(
state
.
getColor
().
getBlue
());
entry
[
"color"
]
=
color
;
alphabet
.
push_back
(
entry
);
}
root
[
"alphabet"
]
=
alphabet
;
...
...
@@ -448,12 +490,20 @@ void MainWindow::load_from_image()
QJsonObject
MainWindow
::
default_model
()
const
{
QJsonObject
obj
;
obj
[
"title"
]
=
"Game of Life"
;
obj
[
"transition_name"
]
=
"Game of Life"
;
obj
[
"transition_data"
]
=
QJsonObject
();
const
char
*
json
=
R"(
{
"title" : "Game of Life",
"transition_name" : "Game of Life",
"transition_data" : {},
"alphabet" : [
{"name" : "Dead", "color" : [255, 255, 255]},
{"name" : "Alive", "color" : [0, 0, 255]}]
}
)"
;
QJsonDocument
doc
=
QJsonDocument
::
fromJson
(
QByteArray
(
json
));
return
obj
;
return
doc
.
object
()
;
}
void
MainWindow
::
on_saveRuleButton_clicked
()
...
...
This diff is collapsed.
Click to expand it.
Yann Boucher
@yboucher
mentioned in issue
#59 (closed)
·
3 years ago
mentioned in issue
#59 (closed)
mentioned in issue #59
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment