Skip to content
GitLab
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
b337e8cc
Commit
b337e8cc
authored
May 29, 2021
by
Yann Boucher
Browse files
Improved the Property class by separating the visual name and the identifier name
parent
fbda5448
Changes
10
Hide whitespace changes
Inline
Side-by-side
include/property.hpp
View file @
b337e8cc
...
...
@@ -73,12 +73,17 @@ public:
//! \brief Accepte un visiteur. Cette fonction est automatiquement redéfinie correctement en héritant de PropertyImpl<Classe>?
virtual
void
accept
(
PropertyVisitor
&
v
)
=
0
;
//! \brief Retourne le nom de la propriété.
std
::
string
name
()
const
{
return
prop_name
;
}
//! \brief Retourne le nom identifiant propriété.
std
::
string
identifier
()
const
{
return
m_identifier
;
}
//! \brief Retourne le nom d'affichage de la propriété, qui est purement cosmétique.
std
::
string
display_name
()
const
{
return
m_display_name
;
}
private:
std
::
string
prop_name
;
std
::
string
m_identifier
;
std
::
string
m_display_name
;
};
/**
...
...
@@ -118,10 +123,11 @@ public:
protected:
//! \brief Appelée internalement par les macros DEFINE_CONFIGURABLE_*.
template
<
typename
PropertyType
,
typename
...
Args
>
PropertyType
&
register_property
(
const
std
::
string
&
name
,
Args
&&
...
args
)
PropertyType
&
register_property
(
const
std
::
string
&
prop_name
,
const
std
::
string
&
display_
name
,
Args
&&
...
args
)
{
m_properties
.
emplace_back
(
std
::
make_unique
<
PropertyType
>
(
std
::
forward
<
Args
>
(
args
)...));
m_properties
.
back
()
->
prop_name
=
name
;
m_properties
.
back
()
->
m_identifier
=
prop_name
;
m_properties
.
back
()
->
m_display_name
=
display_name
;
return
static_cast
<
PropertyType
&>
(
*
m_properties
.
back
());
}
...
...
@@ -266,8 +272,8 @@ private:
\param name Nom affichable de la propriété.
\param ... Arguments supplémentaires à passer au constructeur de 'prop_type'
**/
#define DEFINE_CONFIGURABLE_PROPERTY(prop_type, identifier, name, ...) \
prop_type& identifier = register_property<prop_type>(name, ##__VA_ARGS__)
#define DEFINE_CONFIGURABLE_PROPERTY(prop_type, identifier,
display_
name, ...) \
prop_type& identifier = register_property<prop_type>(
#identifier, display_
name, ##__VA_ARGS__)
/** Permet de déclarer une liste fixée de propriétés 'identifier' de type 'prop_type', avec comme nom affichable 'name'.
\param prop_type Type des propriétés.
...
...
@@ -275,8 +281,8 @@ prop_type& identifier = register_property<prop_type>(name, ##__VA_ARGS__)
\param name Nom affichable de la liste de propriétés.
\param ... Arguments supplémentaires à passer au constructeur de 'prop_type' lors de la créatin d'une propriété dans la liste
**/
#define DEFINE_CONFIGURABLE_LIST(prop_type, identifier, name, ...) \
PropertyList& identifier = register_property<PropertyList>(name, []()->std::unique_ptr<Property>{ return std::make_unique<prop_type>(__VA_ARGS__); false, ##__VA_ARGS__ })
#define DEFINE_CONFIGURABLE_LIST(prop_type, identifier,
display_
name, ...) \
PropertyList& identifier = register_property<PropertyList>(
#identifier, display_
name, []()->std::unique_ptr<Property>{ return std::make_unique<prop_type>(__VA_ARGS__); false, ##__VA_ARGS__ })
/** Permet de déclarer une liste dynamique de propriétés 'identifier' de type 'prop_type', avec comme nom affichable 'name'.
\param prop_type Type des propriétés.
\param identifier Nom de la variable dans le code.
...
...
@@ -284,7 +290,7 @@ PropertyList& identifier = register_property<PropertyList>(name, []()->std::uniq
\param inner_args Arguments supplémentaires à passer au constructeur de 'prop_type' lors de la créatin d'une propriété dans la liste
\param ... Arguments supplémentaires à passer au constructeur de PropertyList.
**/
#define DEFINE_CONFIGURABLE_DYNLIST(prop_type, identifier, name, inner_args, ...) \
PropertyList& identifier = register_property<PropertyList>(name, []()->std::unique_ptr<Property>{ return std::make_unique<prop_type> inner_args; }, true, ##__VA_ARGS__ )
#define DEFINE_CONFIGURABLE_DYNLIST(prop_type, identifier,
display_
name, inner_args, ...) \
PropertyList& identifier = register_property<PropertyList>(
#identifier, display_
name, []()->std::unique_ptr<Property>{ return std::make_unique<prop_type> inner_args; }, true, ##__VA_ARGS__ )
#endif // PROPERTY_HPP
include/transition_rules/circulartransition.hpp
View file @
b337e8cc
...
...
@@ -15,7 +15,7 @@ public:
private:
DEFINE_CONFIGURABLE_PROPERTY
(
IntegerProperty
,
states
,
"State count"
,
1
);
DEFINE_CONFIGURABLE_PROPERTY
(
IntegerProperty
,
thresold
,
"Threshold"
);
DEFINE_CONFIGURABLE_PROPERTY
(
IntegerProperty
,
thres
h
old
,
"Threshold"
);
};
REGISTER_FACTORY_ENTRY
(
TransitionRule
,
CircularTransition
,
"Circular"
);
...
...
models/test3.json
View file @
b337e8cc
...
...
@@ -5,13 +5,13 @@
"date"
:
"lun. mai 24 2021"
,
"desc"
:
"aaa"
,
"neighborhood_data"
:
{
"
R
adius"
:
4
"
r
adius"
:
4
},
"neighborhood_name"
:
"Von Neumann"
,
"title"
:
"test3"
,
"transition_data"
:
{
"
S
tate
count
"
:
4
,
"
T
hreshold"
:
3
"
s
tate
s
"
:
4
,
"
t
hreshold"
:
3
},
"transition_name"
:
"Circular"
}
models/test_modele3.json
0 → 100644
View file @
b337e8cc
{
"alphabet"
:
[
],
"author"
:
"JM"
,
"date"
:
"ven. mai 28 2021"
,
"desc"
:
""
,
"neighborhood_data"
:
{
"radius"
:
5
},
"neighborhood_name"
:
"Von Neumann"
,
"title"
:
"test_modele3"
,
"transition_data"
:
{
"states"
:
3
,
"threshold"
:
6
},
"transition_name"
:
"Circular"
}
src/propertyvisitors.cpp
View file @
b337e8cc
...
...
@@ -65,7 +65,7 @@ QWidget *UIBuilderVisitor::current_widget()
void
UIBuilderVisitor
::
push_array_widget
(
const
Property
&
prop
)
{
QGroupBox
*
box
=
new
QGroupBox
(
QString
::
fromStdString
(
prop
.
name
()),
current_widget
());
QGroupBox
*
box
=
new
QGroupBox
(
QString
::
fromStdString
(
prop
.
identifier
()),
current_widget
());
box
->
setLayout
(
new
QVBoxLayout
);
add_widget
(
""
,
box
);
m_widget_hierarchy
.
push
(
box
);
...
...
@@ -82,7 +82,7 @@ QWidget* UIBuilderVisitor::pop_widget()
void
UIBuilderVisitor
::
visit
(
StringProperty
&
str
)
{
QLineEdit
*
line
=
new
QLineEdit
(
QString
::
fromStdString
(
str
.
str
),
current_widget
());
add_widget
(
str
.
name
(),
line
);
add_widget
(
str
.
identifier
(),
line
);
QObject
::
connect
(
line
,
&
QLineEdit
::
textEdited
,
[
&
str
](
const
QString
&
qstr
)
{
str
.
str
=
qstr
.
toStdString
();
});
...
...
@@ -91,7 +91,7 @@ void UIBuilderVisitor::visit(StringProperty &str)
void
UIBuilderVisitor
::
visit
(
IntegerProperty
&
prop
)
{
QSpinBox
*
spin
=
new
QSpinBox
(
current_widget
());
add_widget
(
prop
.
name
(),
spin
);
add_widget
(
prop
.
identifier
(),
spin
);
spin
->
setValue
(
prop
.
val
);
spin
->
setMinimum
(
prop
.
prop_min
);
...
...
@@ -112,7 +112,7 @@ void UIBuilderVisitor::visit(CoordinateProperty &prop)
frame
->
layout
()
->
addWidget
(
new
QLabel
(
"y :"
,
frame
));
frame
->
layout
()
->
addWidget
(
spin_y
);
frame
->
layout
()
->
addItem
(
new
QSpacerItem
(
40
,
20
,
QSizePolicy
::
Expanding
,
QSizePolicy
::
Minimum
));
add_widget
(
prop
.
name
(),
frame
);
add_widget
(
prop
.
identifier
(),
frame
);
spin_x
->
setValue
(
prop
.
c
.
x
);
spin_y
->
setValue
(
prop
.
c
.
y
);
QObject
::
connect
(
spin_x
,
QOverload
<
int
>::
of
(
&
QSpinBox
::
valueChanged
),
...
...
@@ -205,7 +205,7 @@ void PropertySaverVisitor::save_value(Property &prop, const QJsonValue &val)
else
{
QJsonObject
obj
=
current
().
toJsonObject
();
obj
[
QString
::
fromStdString
(
prop
.
name
())]
=
val
;
obj
[
QString
::
fromStdString
(
prop
.
identifier
())]
=
val
;
current
()
=
obj
;
}
}
...
...
@@ -295,7 +295,7 @@ QJsonValue PropertyLoaderVisitor::fetch_value(Property &prop)
return
val
;
}
else
return
current
()[
prop
.
name
().
c_str
()];
return
current
()[
prop
.
identifier
().
c_str
()];
}
void
PropertyLoaderVisitor
::
visit
(
StringProperty
&
prop
)
...
...
src/transition_rules/circulartransition.cpp
View file @
b337e8cc
...
...
@@ -4,7 +4,7 @@ unsigned CircularTransition::getState(unsigned cell, const Neighborhood &neighbo
{
unsigned
next_state
=
(
cell
+
1
)
%
states
.
val
;
unsigned
next_state_neighbors
=
neighborhood
.
getNb
(
next_state
);
if
((
int
)
next_state_neighbors
>=
thresold
.
val
)
if
((
int
)
next_state_neighbors
>=
thres
h
old
.
val
)
return
next_state
;
else
return
cell
;
...
...
tests/arbitraryneighborhoodrule_test.cpp
View file @
b337e8cc
...
...
@@ -22,7 +22,7 @@ void CellulutTests::test_arbitrary_neighborhood_rule()
entry
.
push_back
(
coord
.
y
);
json_array
.
push_back
(
entry
);
}
obj
[
"
N
eighbors"
]
=
json_array
;
obj
[
"
n
eighbors"
]
=
json_array
;
ArbitraryNeighborhoodRule
rule
;
{
...
...
tests/circulartransition_test.cpp
View file @
b337e8cc
...
...
@@ -6,8 +6,8 @@
void
CellulutTests
::
test_circulartransition
()
{
QJsonObject
obj
;
obj
[
"
Nombre d'é
tats"
]
=
4
;
obj
[
"
Seuil
"
]
=
3
;
obj
[
"
s
tat
e
s"
]
=
4
;
obj
[
"
threshold
"
]
=
3
;
CircularTransition
rule
;
// load
{
...
...
tests/property_test.cpp
View file @
b337e8cc
...
...
@@ -15,7 +15,8 @@ void CellulutTests::test_property()
PropertyClass
test
;
QVERIFY
(
test
.
test_str
.
str
==
"hello world"
);
QVERIFY
(
test
.
test_str
.
name
()
==
"Test String"
);
QVERIFY
(
test
.
test_str
.
identifier
()
==
"test_str"
);
QVERIFY
(
test
.
test_str
.
display_name
()
==
"Test String"
);
QVERIFY
(
test
.
get_properties
().
size
()
==
1
);
QVERIFY
(
test
.
get_properties
()[
0
].
get
()
==
&
test
.
test_str
);
}
...
...
tests/totalistictransition_test.cpp
View file @
b337e8cc
...
...
@@ -90,7 +90,7 @@ void CellulutTests::test_totalistictransition()
TotalisticTransition
rule
;
QJsonObject
obj
;
obj
[
"
R
ule
S
tring"
]
=
"1->2
\n
"
obj
[
"
r
ule
_s
tring"
]
=
"1->2
\n
"
"2->3
\n
"
"3,1:[1..2]->1
\n
"
;
PropertyLoaderVisitor
visit
(
obj
);
...
...
@@ -134,7 +134,7 @@ void CellulutTests::test_totalistictransition()
TotalisticTransition
rule
;
QJsonObject
obj
;
obj
[
"
R
ule
S
tring"
]
=
"0,1:[3]->1
\n
"
obj
[
"
r
ule
_s
tring"
]
=
"0,1:[3]->1
\n
"
"1,1:[0..1]->0
\n
"
"1,1:[4..*]->0
\n
"
;
PropertyLoaderVisitor
visit
(
obj
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment