hppwidgetsplugin.hh 7.51 KB
Newer Older
1
2
3
4
5
//
// Copyright (c) CNRS
// Author: Joseph Mirabel and Heidy Dallard
//

Joseph Mirabel's avatar
Joseph Mirabel committed
6
7
#ifndef HPP_GUI_HPPWIDGETSPLUGIN_HH
#define HPP_GUI_HPPWIDGETSPLUGIN_HH
8

9
#include <gepetto/gui/plugin-interface.hh>
10
#include <gepetto/gui/windows-manager.hh>
11
12
#include <hpp/corbaserver/client.hh>

13
14
class QDockWidget;

Joseph Mirabel's avatar
Joseph Mirabel committed
15
16
17
18
19
20
21
22
namespace hpp {
  namespace gui {
    class SolverWidget;
    class PathPlayer;
    class JointTreeWidget;
    class ConfigurationListWidget;
    class JointTreeItem;
    class Roadmap;
23
    class ConstraintWidget;
Joseph Mirabel's avatar
Joseph Mirabel committed
24

Joseph Mirabel's avatar
Joseph Mirabel committed
25
26
27
    inline CORBA::String_var to_corba(const QString& s)
    { return (const char*)s.toLocal8Bit().data(); }

hdallard's avatar
hdallard committed
28
    /// Plugin that add a lot of features to work with hpp.
29
30
    class HppWidgetsPlugin : public QObject, public gepetto::gui::PluginInterface,
    public gepetto::gui::ModelInterface, public gepetto::gui::CorbaInterface
Joseph Mirabel's avatar
Joseph Mirabel committed
31
32
    {
      Q_OBJECT
33
34
35
        Q_INTERFACES (gepetto::gui::PluginInterface
            gepetto::gui::ModelInterface
            gepetto::gui::CorbaInterface)
Joseph Mirabel's avatar
Joseph Mirabel committed
36

37
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
Joseph Mirabel's avatar
Joseph Mirabel committed
38
    Q_PLUGIN_METADATA (IID "hpp-gui.hppwidgetsplugin")
39
#endif
Joseph Mirabel's avatar
Joseph Mirabel committed
40

Joseph Mirabel's avatar
Joseph Mirabel committed
41
42
      public:
        struct JointElement {
43
          std::string name, prefix;
44
45
          // FIXME sort this vector.
          std::vector<std::string> bodyNames;
Joseph Mirabel's avatar
Joseph Mirabel committed
46
          JointTreeItem* item;
47
          std::vector<bool> updateViewer;
Joseph Mirabel's avatar
Joseph Mirabel committed
48
49

          JointElement ()
50
            : name (), bodyNames (), item (NULL), updateViewer (0, false) {}
51
52
53
54
55
56
57
58
59
          JointElement (const std::string& n,
              const std::string& prefix,
              const std::vector<std::string>& bns,
              JointTreeItem* i,
              bool updateV = true)
            : name (n), prefix (prefix), bodyNames (bns), item (i),
            updateViewer (bns.size(), updateV) {}
          JointElement (const std::string& n, const std::string& prefix,
              const hpp::Names_t& bns, JointTreeItem* i, bool updateV = true);
Joseph Mirabel's avatar
Joseph Mirabel committed
60
61
62
63
64
65
66
67
68
69
        };
        typedef QMap <std::string, JointElement> JointMap;
        typedef hpp::corbaServer::Client HppClient;

        explicit HppWidgetsPlugin ();

        virtual ~HppWidgetsPlugin ();

        // PluginInterface interface
      public:
hdallard's avatar
hdallard committed
70
        /// Initialize the plugin.
Joseph Mirabel's avatar
Joseph Mirabel committed
71
        void init();
hdallard's avatar
hdallard committed
72
73

        /// Returns the plugin's name.
Joseph Mirabel's avatar
Joseph Mirabel committed
74
75
76
77
        QString name() const;

        // ModelInterface interface
      public:
hdallard's avatar
hdallard committed
78
79
        /// Load a robot in the corba server.
        /// \param rd robot definition
80
        void loadRobotModel (gepetto::gui::DialogLoadRobot::RobotDefinition rd);
hdallard's avatar
hdallard committed
81
82
83

        /// Load an environment in the corba server.
        /// \param ed environment definition
84
        void loadEnvironmentModel (gepetto::gui::DialogLoadEnvironment::EnvironmentDefinition ed);
hdallard's avatar
hdallard committed
85
86
87

        /// Get the name of a joint's body.
        /// \param jointName joint name
88
89
        /// \todo this should be changed because there can be several body per
        /// joints now.
Joseph Mirabel's avatar
Joseph Mirabel committed
90
        std::string getBodyFromJoint (const std::string& jointName) const;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

        const hpp::floatSeq& currentConfig () const
        {
          return config_;
        }

        hpp::floatSeq& currentConfig ()
        {
          return config_;
        }

        const hpp::floatSeq& currentVelocity () const
        {
          return velocity_;
        }

        hpp::floatSeq& currentVelocity ()
        {
          return velocity_;
        }

112
signals:
Joseph Mirabel's avatar
Joseph Mirabel committed
113
114
        void configurationValidationStatus (bool valid);
        void configurationValidationStatus (QStringList collision);
115

Joseph Mirabel's avatar
Joseph Mirabel committed
116
117
118
        // CorbaInterface interface
      public:
        virtual bool corbaException (int jobId, const CORBA::Exception &excep) const;
119

hdallard's avatar
hdallard committed
120
        /// Open a connection to a corba server.
Joseph Mirabel's avatar
Joseph Mirabel committed
121
        virtual void openConnection ();
hdallard's avatar
hdallard committed
122
123

        /// Close connection to corbaserver.
Joseph Mirabel's avatar
Joseph Mirabel committed
124
        virtual void closeConnection ();
125
signals:
hdallard's avatar
hdallard committed
126
        /// Log the failure of a job in the MainWindow.
Joseph Mirabel's avatar
Joseph Mirabel committed
127
        void logJobFailed  (int id, const QString& text) const;
128

Joseph Mirabel's avatar
Joseph Mirabel committed
129
        public slots:
hdallard's avatar
hdallard committed
130
        /// Apply the current configuration of the robot.
Joseph Mirabel's avatar
Joseph Mirabel committed
131
          void applyCurrentConfiguration ();
hdallard's avatar
hdallard committed
132

Joseph Mirabel's avatar
Joseph Mirabel committed
133
134
135
136
        void setCurrentConfig (const hpp::floatSeq& q);

        hpp::floatSeq const* getCurrentConfig () const;

137
138
139
140
        void setCurrentQtConfig (const QVector<double>& q);

        QVector<double> getCurrentQtConfig () const;

141
142
143
144
145
146
        /// Set internal configuration from HPP current config.
        void fetchConfiguration ();

        /// Set HPP configuration to internal current configuration
        void sendConfiguration ();

hdallard's avatar
hdallard committed
147
        /// Build a list of bodies in collision.
Joseph Mirabel's avatar
Joseph Mirabel committed
148
        void configurationValidation ();
hdallard's avatar
hdallard committed
149
150
151

        /// Select a joint in the joint tree from a body's name.
        /// \param bodyName name of the body
Joseph Mirabel's avatar
Joseph Mirabel committed
152
        void selectJointFromBodyName (const QString bodyName);
153

Joseph Mirabel's avatar
Joseph Mirabel committed
154
155
        void update();

156
157
158
        /// See createJointGroup
        QString requestCreateJointGroup(const QString jn);

Joseph Mirabel's avatar
Joseph Mirabel committed
159
160
161
        /// See createComGroup
        QString requestCreateComGroup(const QString com);

162
        QString getHppIIOPurl () const;
163

Joseph Mirabel's avatar
Joseph Mirabel committed
164
165
        QString getHppContext () const;

Joseph Mirabel's avatar
Joseph Mirabel committed
166
      public:
hdallard's avatar
hdallard committed
167
        /// Get the corbaserver client.
Joseph Mirabel's avatar
Joseph Mirabel committed
168
        HppClient* client () const;
hdallard's avatar
hdallard committed
169
170

        /// Get the jointMap.
Joseph Mirabel's avatar
Joseph Mirabel committed
171
        JointMap& jointMap ();
hdallard's avatar
hdallard committed
172
173

        /// Get the pathPlayer widget.
174
        PathPlayer* pathPlayer() const;
175

Joseph Mirabel's avatar
Joseph Mirabel committed
176
177
178
        /// Get the pathPlayer widget.
        JointTreeWidget* jointTreeWidget() const;

hdallard's avatar
hdallard committed
179
180
        /// Get the list of joints from corbaserver and update internal joint map.
        /// \param robotName name of the robot
Joseph Mirabel's avatar
Joseph Mirabel committed
181
        virtual void updateRobotJoints (const QString robotName);
hdallard's avatar
hdallard committed
182
183

        /// Get the currently selected joint name.
184
        std::string getSelectedJoint () const;
hdallard's avatar
hdallard committed
185
186
187

        /// Create the roadmap of a given joint.
        /// \param jointName name of the joint
Joseph Mirabel's avatar
Joseph Mirabel committed
188
        virtual Roadmap* createRoadmap (const std::string& jointName);
189

190
191
192
193
      signals:
        void logSuccess (const QString& text);
        void logFailure (const QString& text);

Joseph Mirabel's avatar
Joseph Mirabel committed
194
        protected slots:
hdallard's avatar
hdallard committed
195
196
        /// Display the roadMap of a given joint.
        /// \param jointName name of the joint
Joseph Mirabel's avatar
Joseph Mirabel committed
197
          virtual void displayRoadmap (const std::string& jointName);
hdallard's avatar
hdallard committed
198
199
200

        /// Add XYZ axis at the joint's position
        /// \param jointName name of the joint
Joseph Mirabel's avatar
Joseph Mirabel committed
201
        void addJointFrame (const std::string& jointName);
202

Joseph Mirabel's avatar
Joseph Mirabel committed
203
      private:
204
        void prepareApplyConfiguration ();
205

Joseph Mirabel's avatar
Joseph Mirabel committed
206
207
208
        PathPlayer* pathPlayer_;
        SolverWidget* solverWidget_;
        ConfigurationListWidget* configListWidget_;
209

Joseph Mirabel's avatar
Joseph Mirabel committed
210
        HppClient* hpp_;
211

Joseph Mirabel's avatar
Joseph Mirabel committed
212
      protected:
hdallard's avatar
hdallard committed
213
214
        /// Change all "/" in jn to "__"
        /// \param jn string to escape
Joseph Mirabel's avatar
Joseph Mirabel committed
215
        static std::string escapeJointName (const std::string jn);
hdallard's avatar
hdallard committed
216
217
218

        /// Create a group from the given joint.
        /// \param jn joint name
Joseph Mirabel's avatar
Joseph Mirabel committed
219
        std::string createJointGroup (const std::string jn);
hdallard's avatar
hdallard committed
220

Joseph Mirabel's avatar
Joseph Mirabel committed
221
222
223
224
        /// Create a group from the given COM.
        /// \param com COM name
        std::string createComGroup (const std::string com);

hdallard's avatar
hdallard committed
225
        /// Replace all the bodies according to their position in hpp.
hdallard's avatar
hdallard committed
226
        void computeObjectPosition();
227

228
229
        virtual void loadConstraintWidget();

230
        QList <QDockWidget*> dockWidgets_;
hdallard's avatar
hdallard committed
231
        JointTreeWidget* jointTreeWidget_;
232
        ConstraintWidget* constraintWidget_;
Joseph Mirabel's avatar
Joseph Mirabel committed
233
        JointMap jointMap_;
234
        hpp::Names_t jointFrames_;
Joseph Mirabel's avatar
Joseph Mirabel committed
235
        std::list <std::string> comFrames_;
236

237
238
        hpp::floatSeq config_, velocity_;

239
240
241
242
        // Cache variables
        hpp::Names_t             linkNames_;
        std::vector<std::string> bodyNames_;
        std::vector<graphics::Configuration> bodyConfs_;
243
        std::vector<std::string> jointGroupNames_;
Joseph Mirabel's avatar
Joseph Mirabel committed
244
245
246
    };
  } // namespace gui
} // namespace hpp
247

Joseph Mirabel's avatar
Joseph Mirabel committed
248
#endif // HPP_GUI_HPPWIDGETSPLUGIN_HH