WidgetController.h
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 Navigation::gui-plugins::WidgetController
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 #pragma once
23 
24 #include <memory>
25 #include <string>
26 
27 #include <qhashfunctions.h>
28 #include <qicon.h>
29 #include <qlist.h>
30 #include <qobjectdefs.h>
31 #include <qpair.h>
32 #include <qpointer.h>
33 #include <qsettings.h>
34 #include <qwidget.h>
35 
38 
41 
49 
51 #include <armarx/navigation/gui-plugins/LocationGraphEditor/ui_LocationGraphEditorWidget.h>
52 
53 #include "GuiGraph.h"
54 #include "Visu.h"
55 #include <SemanticObjectRelations/Shapes/Shape.h>
56 
57 
58 class QDialog;
59 
60 namespace armarx::viz
61 {
62  class Client;
63 }
64 
66 {
67  enum class EdgeDirection;
68 }
69 
71 {
72  class EdgeTableWidget;
73  class RobotVisuWidget;
75  class VertexDataWidget;
76  class VertexTableWidget;
77 
78  /**
79  \page armarx_navigation-GuiPlugins-LocationGraphEditor LocationGraphEditor
80  \brief The LocationGraphEditor allows visualizing ...
81 
82  \image html LocationGraphEditor.png
83  The user can
84 
85  API Documentation \ref WidgetController
86 
87  \see LocationGraphEditorGuiPlugin
88  */
89 
90 
91  /**
92  * \class LocationGraphEditorGuiPlugin
93  * \ingroup ArmarXGuiPlugins
94  * \brief LocationGraphEditorGuiPlugin brief description
95  *
96  * Detailed description
97  */
98 
99  /**
100  * \class WidgetController
101  * \brief WidgetController brief one line description
102  *
103  * Detailed description
104  */
106  public armarx::ArmarXComponentWidgetControllerTemplate<WidgetController>
107  {
108  Q_OBJECT
109 
110  using This = WidgetController;
111 
112 
113  public:
114  static QString GetWidgetName();
115  static QIcon GetWidgetIcon();
116 
117 
118  explicit WidgetController();
119  virtual ~WidgetController() override;
120 
121 
122  //// @see ArmarXWidgetController::loadSettings()
123  void loadSettings(QSettings* settings) override;
124  /// @see ArmarXWidgetController::saveSettings()
125  void saveSettings(QSettings* settings) override;
126 
127 
128  QPointer<QDialog> getConfigDialog(QWidget* parent = nullptr) override;
129  void configured() override;
130 
131 
132  void onInitComponent() override;
133  void onConnectComponent() override;
134 
135 
136  //because the above load/save functions are *obviously* for "Save/Load Gui Config." :/
137  virtual void loadAutomaticSettings();
138  virtual void saveAutomaticSettings();
139 
140 
141  signals:
142 
143  void connected();
144 
145  void locationMemoryChanged();
146  void graphMemoryChanged();
147  void memoryChanged();
148 
149  void graphChanged();
150 
151 
152  private slots:
153 
154  // Load
155  void queryMemory();
156  armem::client::QueryResult queryLocations();
157  armem::client::QueryResult queryGraphs();
158 
159  void loadGraph();
160  bool loadGraphDialog();
161 
162  // Commit
163  void commit();
164  armem::CommitResult commitLocations();
165  armem::EntityUpdateResult commitGraph();
166 
167 
168  // View & Tables
169  void updateGraphList();
170  void updateGraphView();
171  void updateVertexView(GuiGraph::Vertex vertex);
172  void updateEdgeView(GuiGraph::Edge edge);
173  void updateArViz();
174 
175 
176  // Selection & Highlighting
177  void selectVertex(QTableWidgetItem* vertexItem);
178  void selectVertex(GuiGraph::Vertex vertex);
179  void updateVertexHighlighting();
180  void updateEdgeHighlighting();
181 
182 
183  // Graph modification triggered by user interaction
184  void createVertexDialog();
185 
186  void addEdges(QList<QPair<QTableWidgetItem*, QTableWidgetItem*>> vertexItems);
187  void removeEdges(QList<QTableWidgetItem*> edgeItems);
188  void removeEdgesOfVertex(QList<QTableWidgetItem*> vertexItems,
189  utils::EdgeDirection direction);
190 
191  void createGraphDialog();
192 
193 
194  private:
195  void setGraph(const armem::MemoryID& entityID, const core::Graph& nav);
196  void setEmptyGraph(const armem::MemoryID& entityID);
197 
198  GuiGraph::Vertex addVertex(semrel::ShapeID vertexID, const VertexData& defaultAttribs);
199  GuiGraph::Vertex addVertex(semrel::ShapeID vertexID,
200  const armem::wm::EntityInstance& locationInstance);
201 
202  GuiGraph::Edge addEdge(GuiGraph::ConstVertex source,
203  GuiGraph::ConstVertex target,
204  const EdgeData& defaultAttribs);
205 
206  void removeVertex(GuiGraph::Vertex& vertex);
207  void removeEdge(GuiGraph::Edge& edge);
208 
209  void clearGraph();
210  void clearEdges();
211  void clearVertices();
212 
213 
214  QString getGraphDisplayName(const armem::MemoryID& entityID, bool changed = false) const;
215 
216  void exportLocationGraph();
217 
218  private:
219  /// Widget Form
220  Ui::LocationGraphEditorWidget widget;
221  QPointer<SimpleConfigDialog> configDialog;
222 
223  struct Remote
224  {
225  std::string memoryNameSystemName = "MemoryNameSystem";
226  armem::client::MemoryNameSystem memoryNameSystem;
227 
228  armem::client::Reader locationReader;
229  armem::client::Writer locationWriter;
230 
231  armem::client::Reader graphReader;
232  armem::client::Writer graphWriter;
233 
234  std::unique_ptr<viz::Client> arviz;
235 
236  void connect(Component& parent);
237  };
238 
239  Remote remote;
240 
241  struct Model
242  {
243  armem::wm::Memory locationsMemory;
244 
245  armem::wm::Memory graphMemory;
246  armem::MemoryID graphEntityID;
247  GuiGraph graph;
248 
249  GraphVisu visu;
250  };
251 
252  Model model;
253 
254  struct View
255  {
256  VertexTableWidget* vertexTable = nullptr;
257  EdgeTableWidget* edgeTable = nullptr;
258  VertexDataWidget* vertexData = nullptr;
259 
260  RobotVisuWidget* robotVisu = nullptr;
261  ObjectPoseClientWidget* objectPoses = nullptr;
262  };
263 
264  View view;
265 
266 
267  private:
268  QSettings settings;
269  QString lastSelectedSceneName;
270  };
271 
272 } // namespace armarx::navigation::qt_plugins::location_graph_editor
273 
274 namespace armarx
275 {
277 }
armarx::armem::client::Reader
Reads data from a memory server.
Definition: Reader.h:23
Reader.h
armarx::navigation::qt_plugins::location_graph_editor::WidgetController
WidgetController brief one line description.
Definition: WidgetController.h:105
Writer.h
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::EntityUpdateResult
Result of an EntityUpdate.
Definition: Commit.h:69
MemoryID.h
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:668
armarx::navigation::qt_plugins::location_graph_editor::EdgeData
The EdgeData struct holds data required for the edge.
Definition: GuiGraph.h:60
armarx::armem::client::QueryResult
Result of a QueryInput.
Definition: Query.h:50
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
SimpleConfigDialog.h
armarx::navigation::qt_plugins::location_graph_editor::utils::EdgeDirection
EdgeDirection
Definition: utils.h:43
armarx::navigation::qt_plugins::location_graph_editor::VertexData
The NodeData struct holds data required for the node.
Definition: GuiGraph.h:44
forward_declarations.h
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::navigation::core::Graph
Definition: Graph.h:89
armarx::navigation::qt_plugins::location_graph_editor::RobotVisuWidget
Definition: RobotVisuWidget.h:131
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::armem::CommitResult
Result of a Commit.
Definition: Commit.h:105
armarx::armem::client::Writer
Helps a memory client sending data to a memory.
Definition: Writer.h:22
armarx::navigation::qt_plugins::location_graph_editor
Definition: GuiGraph.cpp:34
armarx::navigation::qt_plugins::location_graph_editor::ObjectPoseClientWidget
Definition: ObjectPoseClientWidget.h:88
Visu.h
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
Component.h
memory_definitions.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
Commit.h
Graph.h
armarx::navigation::qt_plugins::location_graph_editor::GraphVisu
Definition: Visu.h:93
GuiGraph.h
armarx::navigation::qt_plugins::location_graph_editor::EdgeTableWidget
Definition: EdgeTableWidget.h:39
armarx::navigation::qt_plugins::location_graph_editor::utils
Definition: WidgetController.h:65
armarx::navigation::qt_plugins::location_graph_editor::GuiGraph
Definition: GuiGraph.h:78
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:68
armarx::navigation::qt_plugins::location_graph_editor::VertexDataWidget
Definition: VertexDataWidget.h:56
Client
Definition: Admin.cpp:26
MemoryNameSystem.h
armarx::navigation::qt_plugins::location_graph_editor::VertexTableWidget
Definition: VertexTableWidget.h:45
armarx::viz
This file is part of ArmarX.
Definition: ArVizStorage.cpp:418
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ImportExportComponent.h