Skip to content
Snippets Groups Projects
Commit d0e0efc0 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Fix re-loading

parent c18706c8
No related branches found
No related tags found
1 merge request!1Add Locations and Graph to Navigation Memory and Redesign Location Graph Editor
Showing
with 144 additions and 27 deletions
...@@ -50,6 +50,16 @@ ...@@ -50,6 +50,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="commitGraphButton">
<property name="toolTip">
<string>Draws the selected scene</string>
</property>
<property name="text">
<string>Commit</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
...@@ -161,8 +171,7 @@ ...@@ -161,8 +171,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QFrame" name="graphFrame">
<widget class="QFrame" name="graphFrame">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
...@@ -186,7 +195,7 @@ ...@@ -186,7 +195,7 @@
<layout class="QVBoxLayout" name="graphSceneLayout"/> <layout class="QVBoxLayout" name="graphSceneLayout"/>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
</item> </item>
<item> <item>
......
...@@ -127,6 +127,7 @@ namespace armarx::nav::locgrapheditor ...@@ -127,6 +127,7 @@ namespace armarx::nav::locgrapheditor
connect(widget.refreshGraphsButton, &QPushButton::pressed, this, &This::updateGraphList); connect(widget.refreshGraphsButton, &QPushButton::pressed, this, &This::updateGraphList);
connect(widget.loadGraphButton, &QPushButton::pressed, this, &This::loadGraph); connect(widget.loadGraphButton, &QPushButton::pressed, this, &This::loadGraph);
connect(widget.commitGraphButton, &QPushButton::pressed, this, &This::commitGraph);
// Update views // Update views
...@@ -286,12 +287,20 @@ namespace armarx::nav::locgrapheditor ...@@ -286,12 +287,20 @@ namespace armarx::nav::locgrapheditor
fromAron(dto, nav); fromAron(dto, nav);
} }
model.graphEntityID = entityID;
setGraph(nav); setGraph(nav);
} }
void LocationGraphEditorWidgetController::commitGraph()
{
}
void LocationGraphEditorWidgetController::setGraph(graph::Graph& nav) void LocationGraphEditorWidgetController::setGraph(graph::Graph& nav)
{ {
#if 0
// Store vertex highlighting. // Store vertex highlighting.
std::set<std::string> highlightedVertices; std::set<std::string> highlightedVertices;
for (auto vertex : model.graph.vertices()) for (auto vertex : model.graph.vertices())
...@@ -301,8 +310,12 @@ namespace armarx::nav::locgrapheditor ...@@ -301,8 +310,12 @@ namespace armarx::nav::locgrapheditor
highlightedVertices.insert(vertex.attrib().getName()); highlightedVertices.insert(vertex.attrib().getName());
} }
} }
#endif
// Build the gui graph (model).
const bool initialBlocked = this->signalsBlocked();
blockSignals(true);
// Build graph.
clearGraph(); clearGraph();
for (auto vertex : nav.vertices()) for (auto vertex : nav.vertices())
{ {
...@@ -313,6 +326,7 @@ namespace armarx::nav::locgrapheditor ...@@ -313,6 +326,7 @@ namespace armarx::nav::locgrapheditor
addEdge(edge); addEdge(edge);
} }
#if 0
// Restore vertex highlighting. // Restore vertex highlighting.
for (auto vertex : model.graph.vertices()) for (auto vertex : model.graph.vertices())
{ {
...@@ -321,7 +335,11 @@ namespace armarx::nav::locgrapheditor ...@@ -321,7 +335,11 @@ namespace armarx::nav::locgrapheditor
vertex.attrib().highlighted = true; vertex.attrib().highlighted = true;
} }
} }
#endif
blockSignals(initialBlocked);
// Trigger a view update.
emit graphChanged(); emit graphChanged();
} }
...@@ -464,43 +482,89 @@ namespace armarx::nav::locgrapheditor ...@@ -464,43 +482,89 @@ namespace armarx::nav::locgrapheditor
} }
void LocationGraphEditorWidgetController::clearGraph()
{
const bool initialBlocked = this->signalsBlocked();
blockSignals(true);
clearEdges();
clearVertices();
blockSignals(initialBlocked);
// Clear data structure
ARMARX_CHECK_EQUAL(model.graph.numEdges(), 0);
ARMARX_CHECK_EQUAL(model.graph.numVertices(), 0);
emit graphChanged();
}
void LocationGraphEditorWidgetController::clearEdges() void LocationGraphEditorWidgetController::clearEdges()
{ {
// Remove from graphics scene // Remove in reverse order to be more array-friendly.
for (auto edge : model.graph.edges()) std::vector<GuiGraph::Edge> edges { model.graph.edges().begin(), model.graph.edges().end() };
for (auto it = edges.rbegin(); it != edges.rend(); ++it)
{ {
view.graph->scene()->removeEdge(edge.attrib().graphicsItem); GuiGraph::Edge edge = *it;
removeEdge(edge);
} }
// Clear table widget ARMARX_CHECK_EQUAL(view.edgeTable->rowCount(), 0);
view.edgeTable->clearContents(); ARMARX_CHECK_EQUAL(model.graph.numEdges(), 0);
view.edgeTable->setRowCount(0);
// Clear data structure emit graphChanged();
while (model.graph.edges().begin() != model.graph.edges().end()) }
void LocationGraphEditorWidgetController::clearVertices()
{
ARMARX_CHECK_EQUAL(model.graph.numEdges(), 0)
<< "The graph may not have any edges when clearing the vertices.";
// Remove in reverse order to be more array-friendly.
std::vector<GuiGraph::Vertex> vertices { model.graph.vertices().begin(), model.graph.vertices().end() };
for (auto it = vertices.rbegin(); it != vertices.rend(); ++it)
{ {
model.graph.removeEdge(*model.graph.edges().begin()); GuiGraph::Vertex vertex = *it;
removeVertex(vertex);
} }
ARMARX_CHECK_EQUAL(view.vertexTable->rowCount(), 0);
ARMARX_CHECK_EQUAL(model.graph.numVertices(), 0);
emit graphChanged(); emit graphChanged();
} }
void LocationGraphEditorWidgetController::clearGraph() void LocationGraphEditorWidgetController::removeEdge(GuiGraph::Edge& edge)
{ {
// Clear scene // Remove view elements
view.graph->scene()->clear(); view.graph->scene()->removeEdge(edge.attrib().graphicsItem);
view.edgeTable->removeEdge(edge);
// Clear table widgets // Remove from model
view.edgeTable->clearContents(); model.graph.removeEdge(edge);
view.edgeTable->setRowCount(0); }
view.vertexTable->clearContents();
view.vertexTable->setRowCount(0);
// Clear data structure
model.graph.clear();
emit graphChanged(); void LocationGraphEditorWidgetController::removeVertex(GuiGraph::Vertex& vertex)
{
ARMARX_CHECK_EQUAL(vertex.inDegree(), 0)
<< "A vertex may not have any edges before being removed. " << vertex.attrib().getName();
ARMARX_CHECK_EQUAL(vertex.outDegree(), 0)
<< "A vertex may not have any edges before being removed. " << vertex.attrib().getName();
// Remove view elements
view.graph->scene()->removeVertex(vertex.attrib().graphicsItem);
view.vertexTable->removeVertex(vertex);
if (view.vertexData->vertex().has_value() and view.vertexData->vertex().value() == vertex)
{
view.vertexData->clearVertex();
}
// Remove from model
model.graph.removeVertex(vertex);
} }
...@@ -562,6 +626,10 @@ namespace armarx::nav::locgrapheditor ...@@ -562,6 +626,10 @@ namespace armarx::nav::locgrapheditor
void LocationGraphEditorWidgetController::selectVertex(QTableWidgetItem* vertexItem) void LocationGraphEditorWidgetController::selectVertex(QTableWidgetItem* vertexItem)
{ {
if (vertexItem == nullptr)
{
view.vertexData->clearVertex();
}
if (auto vertex = model.graph.getVertexFromTableItem(vertexItem)) if (auto vertex = model.graph.getVertexFromTableItem(vertexItem))
{ {
selectVertex(vertex.value()); selectVertex(vertex.value());
......
...@@ -138,6 +138,7 @@ namespace armarx::nav::locgrapheditor ...@@ -138,6 +138,7 @@ namespace armarx::nav::locgrapheditor
void queryGraphs(); void queryGraphs();
void updateGraphList(); void updateGraphList();
void loadGraph(); void loadGraph();
void commitGraph();
void setGraph(graph::Graph& nav); void setGraph(graph::Graph& nav);
GuiGraph::Vertex addVertex(graph::Graph::ConstVertex vertex); GuiGraph::Vertex addVertex(graph::Graph::ConstVertex vertex);
...@@ -145,8 +146,12 @@ namespace armarx::nav::locgrapheditor ...@@ -145,8 +146,12 @@ namespace armarx::nav::locgrapheditor
GuiGraph::Edge addEdge(GuiGraph::ConstVertex source, GuiGraph::ConstVertex target, GuiGraph::Edge addEdge(GuiGraph::ConstVertex source, GuiGraph::ConstVertex target,
const EdgeData& defaultAttribs); const EdgeData& defaultAttribs);
void clearEdges();
void clearGraph(); void clearGraph();
void clearEdges();
void clearVertices();
void removeEdge(GuiGraph::Edge& edge);
void removeVertex(GuiGraph::Vertex& vertex);
void addEdges(QList<QPair<QTableWidgetItem*, QTableWidgetItem*>> vertexItems); void addEdges(QList<QPair<QTableWidgetItem*, QTableWidgetItem*>> vertexItems);
...@@ -197,6 +202,7 @@ namespace armarx::nav::locgrapheditor ...@@ -197,6 +202,7 @@ namespace armarx::nav::locgrapheditor
struct Model struct Model
{ {
armem::wm::Memory memory; armem::wm::Memory memory;
armem::MemoryID graphEntityID;
GuiGraph graph; GuiGraph graph;
}; };
Model model; Model model;
......
...@@ -84,6 +84,13 @@ namespace armarx::nav::locgrapheditor ...@@ -84,6 +84,13 @@ namespace armarx::nav::locgrapheditor
} }
void EdgeTableWidget::removeEdge(GuiGraph::Edge& edge)
{
this->removeRow(row(edge.attrib().tableWidgetItem));
edge.attrib().tableWidgetItem = nullptr;
}
QList<QTableWidgetItem*> QList<QTableWidgetItem*>
EdgeTableWidget::selectedEdgeItems() EdgeTableWidget::selectedEdgeItems()
{ {
......
...@@ -55,7 +55,7 @@ namespace armarx::nav::locgrapheditor ...@@ -55,7 +55,7 @@ namespace armarx::nav::locgrapheditor
void updateEdge(GuiGraph::Edge edge); void updateEdge(GuiGraph::Edge edge);
void removeEdge(GuiGraph::Edge edge); void removeEdge(GuiGraph::Edge& edge);
void clearEdges(); void clearEdges();
......
...@@ -125,9 +125,20 @@ namespace armarx::nav::locgrapheditor ...@@ -125,9 +125,20 @@ namespace armarx::nav::locgrapheditor
void VertexDataWidget::setVertex(GuiGraph::Vertex vertex) void VertexDataWidget::setVertex(GuiGraph::Vertex vertex)
{ {
blockSignals(true);
_vertex = vertex; _vertex = vertex;
_setFromVertex(vertex); _setFromVertex(vertex);
setEnabled(true); setEnabled(true);
blockSignals(false);
}
void VertexDataWidget::clearVertex()
{
_vertex = std::nullopt;
setEnabled(false);
} }
......
...@@ -49,6 +49,7 @@ namespace armarx::nav::locgrapheditor ...@@ -49,6 +49,7 @@ namespace armarx::nav::locgrapheditor
std::optional<GuiGraph::Vertex> vertex(); std::optional<GuiGraph::Vertex> vertex();
void setVertex(GuiGraph::Vertex vertex); void setVertex(GuiGraph::Vertex vertex);
void clearVertex();
Eigen::Vector3d xyz() const; Eigen::Vector3d xyz() const;
Eigen::Vector3d rpyDeg() const; Eigen::Vector3d rpyDeg() const;
......
...@@ -103,6 +103,18 @@ namespace armarx::nav::locgrapheditor ...@@ -103,6 +103,18 @@ namespace armarx::nav::locgrapheditor
} }
void
VertexTableWidget::removeVertex(GuiGraph::Vertex& vertex)
{
if (currentItem() == vertex.attrib().tableWidgetItem)
{
setCurrentItem(nullptr);
}
this->removeRow(row(vertex.attrib().tableWidgetItem));
vertex.attrib().tableWidgetItem = nullptr;
}
QList<QTableWidgetItem*> QList<QTableWidgetItem*>
VertexTableWidget::selectedVertexItems() VertexTableWidget::selectedVertexItems()
{ {
......
...@@ -46,6 +46,8 @@ namespace armarx::nav::locgrapheditor ...@@ -46,6 +46,8 @@ namespace armarx::nav::locgrapheditor
void updateVertex(GuiGraph::Vertex vertex); void updateVertex(GuiGraph::Vertex vertex);
void removeVertex(GuiGraph::Vertex& vertex);
QList<QTableWidgetItem*> selectedVertexItems(); QList<QTableWidgetItem*> selectedVertexItems();
......
...@@ -79,7 +79,8 @@ namespace armarx::nav::locgrapheditor::graph_scene ...@@ -79,7 +79,8 @@ namespace armarx::nav::locgrapheditor::graph_scene
void Scene::updateEdge(GuiGraph::Edge& edge) void Scene::updateEdge(GuiGraph::Edge& edge)
{ {
QGraphicsLineItem* item = edge.attrib().graphicsItem; QGraphicsLineItem* item = edge.attrib().graphicsItem;
ARMARX_CHECK_NOT_NULL(item); ARMARX_CHECK_NOT_NULL(item)
<< edge.source().attrib().getName() << " -> " << edge.target().attrib().getName();
Eigen::Matrix4d sourcePose = edge.source().attrib().getPose().cast<qreal>(); Eigen::Matrix4d sourcePose = edge.source().attrib().getPose().cast<qreal>();
Eigen::Matrix4d targetPose = edge.target().attrib().getPose().cast<qreal>(); Eigen::Matrix4d targetPose = edge.target().attrib().getPose().cast<qreal>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment