hpp-plot: include/hpp/plot/hpp-native-graph.hh Source File

hpp-plot 9.0.2 Plotting tools for HPP

Loading...
Searching...
No Matches
hpp-native-graph.hh
Go to the documentation of this file.
1// BSD 2-Clause License
2
3// Copyright (c) 2025, hpp-plot
4// Authors: Paul Sardin
5// All rights reserved.
6
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10
11// * Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13
14// * Redistributions in binary form must reproduce the above copyright
15// notice, this list of conditions and the following disclaimer in
16// the documentation and/or other materials provided with the
17// distribution.
18
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30// OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#ifndef HPP_PLOT_HPP_NATIVE_GRAPH_HH
33#define HPP_PLOT_HPP_NATIVE_GRAPH_HH
34
35#include <QMenu>
36#include <QPushButton>
37#include <hpp/manipulation/graph/graph.hh>
38#include <hpp/plot/graph-widget.hh>
39
40namespace hpp {
41namespace plot {
42
48 class HppNativeGraphWidget : public GraphWidget {
49 Q_OBJECT
50
51 public:
55 HppNativeGraphWidget(hpp::manipulation::graph::GraphPtr_t graph = nullptr,
56 QWidget* parent = nullptr);
57
59 ~HppNativeGraphWidget();
60
63 void setGraph(hpp::manipulation::graph::GraphPtr_t graph);
64
66 const std::string& graphName() const { return graphName_; }
67
71 bool selectionID(std::size_t& id);
72
75 void highlightNode(long nodeId);
76
79 void highlightEdge(long edgeId);
80
81 public Q_SLOTS:
83 void displayStateConstraints(std::size_t id);
84
86 void displayEdgeConstraints(std::size_t id);
87
89 void displayEdgeTargetConstraints(std::size_t id);
90
91 Q_SIGNALS:
98 void nodeContextMenuAboutToShow(std::size_t nodeId, QString nodeName,
99 QMenu* menu);
100
107 void edgeContextMenuAboutToShow(std::size_t edgeId, QString edgeName,
108 QMenu* menu);
109
110 protected:
113 void fillScene() override;
114
115 protected Q_SLOTS:
116 void nodeContextMenu(QGVNode* node) override;
117 void nodeDoubleClick(QGVNode* node) override;
118 void edgeContextMenu(QGVEdge* edge) override;
119 void edgeDoubleClick(QGVEdge* edge) override;
120 void selectionChanged();
121
122 private:
124 QString getConstraints(
125 const hpp::manipulation::graph::GraphComponentPtr_t& component);
126
128 QString getDetailedStateConstraints(std::size_t stateId);
129
131 QString getDetailedEdgeConstraints(std::size_t edgeId);
132
134 QString getDetailedEdgeTargetConstraints(std::size_t edgeId);
135
137 void updateEdgeStyle(QGVEdge* edge, long weight);
138
139 hpp::manipulation::graph::GraphPtr_t graph_;
140 std::string graphName_;
141
143 struct GraphInfo {
144 std::size_t id;
145 QString constraintStr;
146 } graphInfo_;
147
149 struct NodeInfo {
150 std::size_t id;
151 QString name;
152 QString constraintStr;
153 QGVNode* node;
154 bool isWaypoint;
155 };
156
158 struct EdgeInfo {
159 std::size_t id;
160 QString name;
161 QString constraintStr;
162 QString containingStateName;
163 long weight;
164 bool isShort;
165 std::size_t nbWaypoints; // Number of waypoints (0 for regular edges)
166 QGVEdge* edge;
167 };
168
169 QMap<QGVNode*, NodeInfo> nodeInfos_;
170 QMap<QGVEdge*, EdgeInfo> edgeInfos_;
171 QMap<std::size_t, QGVNode*> nodes_;
172 QMap<std::size_t, QGVEdge*> edges_;
173
175 QPushButton* showWaypoints_;
176
178 long currentId_;
179
181 long highlightedNodeId_;
182 long highlightedEdgeId_;
183};
184
185} // namespace plot
186} // namespace hpp
187
188#endif // HPP_PLOT_HPP_NATIVE_GRAPH_HH
QGVEdge
QGVNode
hpp::plot::GraphWidget
Definition graph-widget.hh:54
hpp::plot::HppNativeGraphWidget
Constraint graph viewer using native C++ API.
Definition hpp-native-graph.hh:48
hpp::plot::HppNativeGraphWidget::nodeContextMenu
void nodeContextMenu(QGVNode *node) override
Definition hpp-native-graph.cc:414
hpp::plot::HppNativeGraphWidget::displayEdgeConstraints
void displayEdgeConstraints(std::size_t id)
Display detailed edge constraints in the constraint panel.
Definition hpp-native-graph.cc:163
hpp::plot::HppNativeGraphWidget::~HppNativeGraphWidget
~HppNativeGraphWidget()
Destructor.
Definition hpp-native-graph.cc:96
hpp::plot::HppNativeGraphWidget::edgeDoubleClick
void edgeDoubleClick(QGVEdge *edge) override
Definition hpp-native-graph.cc:492
hpp::plot::HppNativeGraphWidget::displayEdgeTargetConstraints
void displayEdgeTargetConstraints(std::size_t id)
Display edge target constraints in the constraint panel.
Definition hpp-native-graph.cc:168
hpp::plot::HppNativeGraphWidget::fillScene
void fillScene() override
Fill scene from Graph object Reads nodes and edges directly from the C++ graph structure.
Definition hpp-native-graph.cc:173
hpp::plot::HppNativeGraphWidget::graphName
const std::string & graphName() const
Get the graph name.
Definition hpp-native-graph.hh:66
hpp::plot::HppNativeGraphWidget::selectionID
bool selectionID(std::size_t &id)
Get currently selected element ID.
Definition hpp-native-graph.cc:112
hpp::plot::HppNativeGraphWidget::nodeContextMenuAboutToShow
void nodeContextMenuAboutToShow(std::size_t nodeId, QString nodeName, QMenu *menu)
Emitted before showing node context menu, allows external code to add actions.
Definition moc_hpp-native-graph.cpp:197
hpp::plot::HppNativeGraphWidget::highlightEdge
void highlightEdge(long edgeId)
Highlight a specific edge.
Definition hpp-native-graph.cc:138
hpp::plot::HppNativeGraphWidget::edgeContextMenu
void edgeContextMenu(QGVEdge *edge) override
Definition hpp-native-graph.cc:453
hpp::plot::HppNativeGraphWidget::setGraph
void setGraph(hpp::manipulation::graph::GraphPtr_t graph)
Set graph object and refresh display.
Definition hpp-native-graph.cc:98
hpp::plot::HppNativeGraphWidget::highlightNode
void highlightNode(long nodeId)
Highlight a specific node (e.g., for current configuration)
Definition hpp-native-graph.cc:118
hpp::plot::HppNativeGraphWidget::nodeDoubleClick
void nodeDoubleClick(QGVNode *node) override
Definition hpp-native-graph.cc:444
hpp::plot::HppNativeGraphWidget::displayStateConstraints
void displayStateConstraints(std::size_t id)
Display detailed state constraints in the constraint panel.
Definition hpp-native-graph.cc:158
hpp::plot::HppNativeGraphWidget::selectionChanged
void selectionChanged()
Definition hpp-native-graph.cc:646
hpp::plot::HppNativeGraphWidget::edgeContextMenuAboutToShow
void edgeContextMenuAboutToShow(std::size_t edgeId, QString edgeName, QMenu *menu)
Emitted before showing edge context menu, allows external code to add actions.
Definition moc_hpp-native-graph.cpp:204
graph-widget.hh
graph.hh
hpp
hpp::manipulation::graph::GraphComponentPtr_t
shared_ptr< GraphComponent > GraphComponentPtr_t
hpp::manipulation::graph::GraphPtr_t
shared_ptr< Graph > GraphPtr_t