GuiGraph.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 MemoryX::ArmarXObjects::GraphImportExport
17 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18 * @date 2021
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "GuiGraph.h"
24
25#include <map>
26#include <optional>
27
28#include <SimoxUtility/math/convert/mat4f_to_rpy.h>
29#include <SimoxUtility/math/convert/rad_to_deg.h>
30
33
35{
36
37 bool
39 {
40 if (attrib().edgesChanged)
41 {
42 return true;
43 }
44 for (auto vertex : vertices())
45 {
46 if (vertex.attrib().changed)
47 {
48 return true;
49 }
50 }
51 return false;
52 }
53
54 std::optional<GuiGraph::Vertex>
55 GuiGraph::getVertexFromTableItem(QTableWidgetItem* item)
56 {
57 for (auto vertex : vertices())
58 {
59 if (vertex.attrib().tableWidgetItem == item)
60 {
61 return vertex;
62 }
63 }
64 return std::nullopt;
65 }
66
67 std::map<QTableWidgetItem*, GuiGraph::Vertex>
69 {
70 std::map<QTableWidgetItem*, GuiGraph::Vertex> map;
71
72 for (auto vertex : vertices())
73 {
74 if (vertex.attrib().tableWidgetItem != nullptr)
75 {
76 map[vertex.attrib().tableWidgetItem] = vertex;
77 }
78 }
79
80 return map;
81 }
82
83 std::map<QTableWidgetItem*, GuiGraph::Edge>
85 {
86 std::map<QTableWidgetItem*, GuiGraph::Edge> map;
87
88 for (auto edge : edges())
89 {
90 if (edge.attrib().tableWidgetItem != nullptr)
91 {
92 map[edge.attrib().tableWidgetItem] = edge;
93 }
94 }
95
96 return map;
97 }
98
99 float
101 {
102 return simox::math::rad_to_deg(simox::math::mat4f_to_rpy(pose.matrix())(2));
103 }
104
105 double
107 {
108 return simox::math::rad_to_deg(simox::math::mat4f_to_rpy(pose.matrix())(2));
109 }
110
111 auto
113 {
115 for (auto v : nav.vertices())
116 {
117 gui.addVertex(v.objectID(), {v.attrib()});
118 }
119 for (auto e : nav.edges())
120 {
121 gui.addEdge(e.sourceObjectID(), e.targetObjectID(), {e.attrib()});
122 }
123 return gui;
124 }
125
128 {
130 for (auto v : gui.vertices())
131 {
132 nav.addVertex(v.objectID(), {v.attrib()});
133 }
134 for (auto e : gui.edges())
135 {
136 nav.addEdge(e.sourceObjectID(), e.targetObjectID(), {e.attrib()});
137 }
138 return nav;
139 }
140
141} // namespace armarx::navigation::qt_plugins::location_graph_editor
std::map< QTableWidgetItem *, Edge > getTableItemToEdgeMap()
Definition GuiGraph.cpp:84
std::optional< Vertex > getVertexFromTableItem(QTableWidgetItem *item)
Definition GuiGraph.cpp:55
std::map< QTableWidgetItem *, Vertex > getTableItemToVertexMap()
Definition GuiGraph.cpp:68
Eigen::Isometry3f Pose
Definition basic_types.h:31
Eigen::Isometry3d Pose_d
Definition basic_types.h:32
auto toGuiGraph(const core::Graph &nav) -> GuiGraph
Definition GuiGraph.cpp:112
navigation::core::Graph fromGuiGraph(const GuiGraph &gui)
Definition GuiGraph.cpp:127