json_conversions.cpp
Go to the documentation of this file.
1
/**
2
* This file is part of ArmarX.
3
*
4
* ArmarX is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation.
7
*
8
* ArmarX is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*
16
* @package VisionX::components::MemoryGrapher
17
* @author [Author Name] ( [Author Email] )
18
* @date 2021
19
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20
* GNU General Public License
21
*/
22
23
#include "
json_conversions.h
"
24
25
#include <SimoxUtility/algorithm/string/string_tools.h>
26
#include <SimoxUtility/json.h>
27
28
#include <
RobotAPI/libraries/armem/core/json_conversions.h
>
29
30
31
namespace
armarx::armem
32
{
33
34
static
const
char
* nowhereText =
"[Nowhere]"
;
35
36
37
void
38
id_graph::to_json
(nlohmann::json& json,
const
MemoryVertex
& vertex)
39
{
40
json[
"memoryID"
] = vertex.
memoryID
;
41
json[
"memoryID.str()"
] = vertex.
memoryID
.
str
();
42
json[
"depth"
] = vertex.
depth
;
43
44
if
(not vertex.
memoryID
.
hasMemoryName
())
45
{
46
json[
"style"
][
"label"
] = nowhereText;
47
json[
"style"
][
"fill-color"
] = simox::Color::gray().to_vector4i();
48
}
49
else
50
{
51
std::vector<std::string> items = vertex.
memoryID
.
getItems
();
52
std::string del =
"/"
;
53
if
(items.size() > 3)
54
{
55
del =
static_cast<
std::string
>
(
"/\n"
);
56
}
57
json[
"style"
][
"label"
] = simox::alg::join(items, del);
58
json[
"style"
][
"fill-color"
] = vertex.
fillColor
.to_vector4i();
59
}
60
}
61
62
63
void
64
id_graph::from_json
(
const
nlohmann::json& json,
MemoryVertex
& vertex)
65
{
66
json.at(
"memoryID"
).get_to(vertex.
memoryID
);
67
json.at(
"depth"
).get_to(vertex.
depth
);
68
}
69
70
71
void
72
id_graph::to_json
(nlohmann::json& json,
const
MemoryEdge
& edge)
73
{
74
json[
"key"
] = edge.
referenceKey
;
75
json[
"isNowhereLink"
] = edge.
isNowhereLink
;
76
77
json[
"style"
][
"label"
] = edge.
referenceKey
;
78
79
if
(edge.
isNowhereLink
)
80
{
81
json[
"style"
][
"color"
] = simox::Color::kit_red().to_vector4i();
82
}
83
}
84
85
86
void
87
id_graph::from_json
(
const
nlohmann::json& json,
MemoryEdge
& edge)
88
{
89
json.at(
"key"
).get_to(edge.
referenceKey
);
90
json.at(
"isNowhereLink"
).get_to(edge.
isNowhereLink
);
91
}
92
93
94
void
95
id_graph::to_json
(nlohmann::json& json,
const
MemoryGraphAttributes
& graph)
96
{
97
json[
"initialMemoryID"
] = graph.
initialMemoryID
;
98
}
99
100
101
void
102
id_graph::from_json
(
const
nlohmann::json& json,
MemoryGraphAttributes
& graph)
103
{
104
json.at(
"initialMemoryID"
).get_to(graph.
initialMemoryID
);
105
}
106
}
// namespace armarx::armem::id_graph
armarx::armem::id_graph::MemoryVertex::memoryID
MemoryID memoryID
Definition:
MemoryGraph.h:36
armarx::armem::id_graph::MemoryVertex::fillColor
simox::Color fillColor
Definition:
MemoryGraph.h:38
armarx::armem::MemoryID::str
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
Definition:
MemoryID.cpp:102
armarx::armem
Definition:
LegacyRobotStateMemoryAdapter.cpp:31
json_conversions.h
armarx::armem::id_graph::MemoryGraphAttributes
Definition:
MemoryGraph.h:47
armarx::armem::id_graph::MemoryGraphAttributes::initialMemoryID
MemoryID initialMemoryID
Definition:
MemoryGraph.h:49
armarx::armem::id_graph::MemoryVertex
Definition:
MemoryGraph.h:34
armarx::armem::id_graph::from_json
void from_json(const nlohmann::json &j, MemoryVertex &vertex)
Definition:
json_conversions.cpp:64
armarx::armem::id_graph::MemoryEdge
Definition:
MemoryGraph.h:41
armarx::armem::MemoryID::hasMemoryName
bool hasMemoryName() const
Definition:
MemoryID.h:103
armarx::armem::MemoryID::getItems
std::vector< std::string > getItems(bool escapeDelimiters=false) const
Get the levels from root to first not defined level (excluding).
Definition:
MemoryID.cpp:228
armarx::armem::id_graph::to_json
void to_json(nlohmann::json &j, const MemoryVertex &vertex)
Definition:
json_conversions.cpp:38
armarx::armem::id_graph::MemoryEdge::referenceKey
std::string referenceKey
Definition:
MemoryGraph.h:43
armarx::armem::id_graph::MemoryEdge::isNowhereLink
bool isNowhereLink
Definition:
MemoryGraph.h:44
armarx::armem::id_graph::MemoryVertex::depth
int depth
Definition:
MemoryGraph.h:37
VisionX
libraries
armem_idgraph
json_conversions.cpp
Generated on Sat Oct 12 2024 09:14:02 for armarx_documentation by
1.8.17