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