GCC Code Coverage Report


Directory: plugins/
File: plugins/hppwidgetsplugin/hppwidgetsplugin.hh
Date: 2024-12-13 15:51:58
Exec Total Coverage
Lines: 0 6 0.0%
Branches: 0 6 0.0%

Line Branch Exec Source
1 //
2 // Copyright (c) CNRS
3 // Author: Joseph Mirabel and Heidy Dallard
4 //
5
6 #ifndef HPP_GUI_HPPWIDGETSPLUGIN_HH
7 #define HPP_GUI_HPPWIDGETSPLUGIN_HH
8
9 #include <gepetto/gui/plugin-interface.hh>
10 #include <gepetto/gui/windows-manager.hh>
11 #include <hpp/corbaserver/client.hh>
12
13 class QDockWidget;
14
15 namespace hpp {
16 namespace gui {
17 class SolverWidget;
18 class PathPlayer;
19 class JointTreeWidget;
20 class ConfigurationListWidget;
21 class JointTreeItem;
22 class Roadmap;
23 class ConstraintWidget;
24
25 inline CORBA::String_var to_corba(const QString& s) {
26 return (const char*)s.toLocal8Bit().data();
27 }
28
29 /// Plugin that add a lot of features to work with hpp.
30 class HppWidgetsPlugin : public QObject,
31 public gepetto::gui::PluginInterface,
32 public gepetto::gui::ModelInterface,
33 public gepetto::gui::ConnectionInterface {
34 Q_OBJECT
35 Q_INTERFACES(gepetto::gui::PluginInterface gepetto::gui::ModelInterface
36 gepetto::gui::ConnectionInterface)
37
38 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
39 Q_PLUGIN_METADATA(IID "hpp-gui.hppwidgetsplugin")
40 #endif
41
42 public:
43 struct JointElement {
44 std::string name, prefix;
45 // FIXME sort this vector.
46 std::vector<std::string> bodyNames;
47 JointTreeItem* item;
48 std::vector<bool> updateViewer;
49
50 JointElement() : name(), bodyNames(), item(NULL), updateViewer(0, false) {}
51 JointElement(const std::string& n, const std::string& prefix,
52 const std::vector<std::string>& bns, JointTreeItem* i,
53 bool updateV = true)
54 : name(n),
55 prefix(prefix),
56 bodyNames(bns),
57 item(i),
58 updateViewer(bns.size(), updateV) {}
59 JointElement(const std::string& n, const std::string& prefix,
60 const hpp::Names_t& bns, JointTreeItem* i,
61 bool updateV = true);
62 };
63 typedef QMap<std::string, JointElement> JointMap;
64 typedef hpp::corbaServer::Client HppClient;
65
66 explicit HppWidgetsPlugin();
67
68 virtual ~HppWidgetsPlugin();
69
70 // PluginInterface interface
71 public:
72 /// Initialize the plugin.
73 void init();
74
75 /// Returns the plugin's name.
76 QString name() const;
77
78 // ModelInterface interface
79 public:
80 /// Load a robot in the corba server.
81 /// \param rd robot definition
82 void loadRobotModel(gepetto::gui::DialogLoadRobot::RobotDefinition rd);
83
84 /// Load an environment in the corba server.
85 /// \param ed environment definition
86 void loadEnvironmentModel(
87 gepetto::gui::DialogLoadEnvironment::EnvironmentDefinition ed);
88
89 /// Get the name of a joint's body.
90 /// \param jointName joint name
91 /// \todo this should be changed because there can be several body per
92 /// joints now.
93 std::string getBodyFromJoint(const std::string& jointName) const;
94
95 const hpp::floatSeq& currentConfig() const { return config_; }
96
97 hpp::floatSeq& currentConfig() { return config_; }
98
99 const hpp::floatSeq& currentVelocity() const { return velocity_; }
100
101 hpp::floatSeq& currentVelocity() { return velocity_; }
102
103 signals:
104 void configurationValidationStatus(bool valid);
105 void configurationValidationStatus(QStringList collision);
106
107 // ConnectionInterface interface
108 public:
109 /// Open a connection to a corba server.
110 virtual void openConnection();
111
112 /// Close connection to corbaserver.
113 virtual void closeConnection();
114 signals:
115 /// Log the failure of a job in the MainWindow.
116 void logJobFailed(int id, const QString& text) const;
117
118 public slots:
119 /// Apply the current configuration of the robot.
120 void applyCurrentConfiguration();
121
122 void setCurrentConfig(const hpp::floatSeq& q);
123
124 hpp::floatSeq const* getCurrentConfig() const;
125
126 void setCurrentQtConfig(const QVector<double>& q);
127
128 QVector<double> getCurrentQtConfig() const;
129
130 /// Set internal configuration from HPP current config.
131 void fetchConfiguration();
132
133 /// Set HPP configuration to internal current configuration
134 void sendConfiguration();
135
136 /// Build a list of bodies in collision.
137 void configurationValidation();
138
139 /// Select a joint in the joint tree from a body's name.
140 /// \param bodyName name of the body
141 void selectJointFromBodyName(const QString bodyName);
142
143 void update();
144
145 /// See createJointGroup
146 QString requestCreateJointGroup(const QString jn);
147
148 /// See createComGroup
149 QString requestCreateComGroup(const QString com);
150
151 QString getHppIIOPurl() const;
152
153 QString getHppContext() const;
154
155 public:
156 /// Get the corbaserver client.
157 HppClient* client() const;
158
159 /// Get the jointMap.
160 JointMap& jointMap();
161
162 /// Get the pathPlayer widget.
163 PathPlayer* pathPlayer() const;
164
165 /// Get the pathPlayer widget.
166 JointTreeWidget* jointTreeWidget() const;
167
168 /// Get the list of joints from corbaserver and update internal joint map.
169 /// \param robotName name of the robot
170 virtual void updateRobotJoints(const QString robotName);
171
172 /// Get the currently selected joint name.
173 std::string getSelectedJoint() const;
174
175 /// Create the roadmap of a given joint.
176 /// \param jointName name of the joint
177 virtual Roadmap* createRoadmap(const std::string& jointName);
178
179 signals:
180 void logSuccess(const QString& text);
181 void logFailure(const QString& text);
182
183 protected slots:
184 /// Display the roadMap of a given joint.
185 /// \param jointName name of the joint
186 virtual void displayRoadmap(const std::string& jointName);
187
188 /// Add XYZ axis at the joint's position
189 /// \param jointName name of the joint
190 void addJointFrame(const std::string& jointName);
191
192 private:
193 void prepareApplyConfiguration();
194
195 PathPlayer* pathPlayer_;
196 SolverWidget* solverWidget_;
197 ConfigurationListWidget* configListWidget_;
198
199 HppClient* hpp_;
200
201 protected:
202 /// Change all "/" in jn to "__"
203 /// \param jn string to escape
204 static std::string escapeJointName(const std::string jn);
205
206 /// Create a group from the given joint.
207 /// \param jn joint name
208 std::string createJointGroup(const std::string jn);
209
210 /// Create a group from the given COM.
211 /// \param com COM name
212 std::string createComGroup(const std::string com);
213
214 /// Replace all the bodies according to their position in hpp.
215 void computeObjectPosition();
216
217 virtual void loadConstraintWidget();
218
219 QList<QDockWidget*> dockWidgets_;
220 JointTreeWidget* jointTreeWidget_;
221 ConstraintWidget* constraintWidget_;
222 JointMap jointMap_;
223 hpp::Names_t jointFrames_;
224 std::list<std::string> comFrames_;
225
226 hpp::floatSeq config_, velocity_;
227
228 // Cache variables
229 hpp::Names_t linkNames_;
230 std::vector<std::string> bodyNames_;
231 std::vector<gepetto::viewer::Configuration> bodyConfs_;
232 std::vector<std::string> jointGroupNames_;
233 };
234 } // namespace gui
235 } // namespace hpp
236
237 #endif // HPP_GUI_HPPWIDGETSPLUGIN_HH
238