hppmanipulationwidgetsplugin.hh 4.81 KB
Newer Older
1 2 3 4 5
//
// Copyright (c) CNRS
// Authors: Joseph Mirabel and Heidy Dallard
//

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

9 10
#include <QToolBar>

11
#include <gepetto/gui/plugin-interface.hh>
12 13 14 15 16
#include <hpp/corbaserver/manipulation/client.hh>
#undef __robot_hh__
#undef __problem_hh__
#include <hppwidgetsplugin/hppwidgetsplugin.hh>

17 18
class QListWidgetItem;

Joseph Mirabel's avatar
Joseph Mirabel committed
19 20
namespace hpp {
  namespace gui {
hdallard's avatar
hdallard committed
21
    /// HppManipulationWidgetsPlugin add functionalities to interact with hpp-manipulation-corba
Joseph Mirabel's avatar
Joseph Mirabel committed
22 23 24 25
    class HppManipulationWidgetsPlugin : public HppWidgetsPlugin
                                         // , public PluginInterface, public ModelInterface, public CorbaErrorInterface
    {
      Q_OBJECT
26 27 28
        Q_INTERFACES (gepetto::gui::PluginInterface
            gepetto::gui::ModelInterface
            gepetto::gui::CorbaInterface)
Joseph Mirabel's avatar
Joseph Mirabel committed
29

30
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
Joseph Mirabel's avatar
Joseph Mirabel committed
31
    Q_PLUGIN_METADATA (IID "hpp-gui.hppmanipulationwidgetsplugin")
32
#endif
Joseph Mirabel's avatar
Joseph Mirabel committed
33

Joseph Mirabel's avatar
Joseph Mirabel committed
34 35 36 37 38 39 40 41 42
      public:
        typedef hpp::corbaServer::manipulation::Client HppManipClient;

        explicit HppManipulationWidgetsPlugin ();

        virtual ~HppManipulationWidgetsPlugin ();

        // PluginInterface interface
      public:
hdallard's avatar
hdallard committed
43
        /// Initialize the plugin
Joseph Mirabel's avatar
Joseph Mirabel committed
44
        void init();
hdallard's avatar
hdallard committed
45 46

        /// Return the name of the plugin
Joseph Mirabel's avatar
Joseph Mirabel committed
47 48 49 50
        QString name() const;

        // ModelInterface interface
      public:
hdallard's avatar
hdallard committed
51 52
        /// Load a robot in the manipulation server.
        /// \param rd definition of the robot (Name, package path, URDF filename, suffix)
53
        void loadRobotModel (gepetto::gui::DialogLoadRobot::RobotDefinition rd);
hdallard's avatar
hdallard committed
54 55 56

        /// Load an environment in the manipulation server.
        /// \param ed definition of the environment (Name, package path, URDF filename, suffix)
57
        void loadEnvironmentModel (gepetto::gui::DialogLoadEnvironment::EnvironmentDefinition ed);
hdallard's avatar
hdallard committed
58 59 60

        /// Get the name of a joint's body.
        /// \param jointName joint name
Joseph Mirabel's avatar
Joseph Mirabel committed
61
        std::string getBodyFromJoint (const std::string& jointName) const;
62

Joseph Mirabel's avatar
Joseph Mirabel committed
63 64
        // CorbaInterface
      public:
hdallard's avatar
hdallard committed
65
        /// Open a connection to a corba manipulation server.
Joseph Mirabel's avatar
Joseph Mirabel committed
66
        virtual void openConnection ();
hdallard's avatar
hdallard committed
67 68

        /// Close connection from corba manipulation server.
Joseph Mirabel's avatar
Joseph Mirabel committed
69
        virtual void closeConnection();
70

Joseph Mirabel's avatar
Joseph Mirabel committed
71
      public:
hdallard's avatar
hdallard committed
72
        /// Get the instance of corba manipulation client.
Joseph Mirabel's avatar
Joseph Mirabel committed
73
        HppManipClient* manipClient () const;
74

hdallard's avatar
hdallard committed
75 76
        /// Get the list of joints from corbaserver and update internal joint map.
        /// \param robotName name of the robot (unused)
Joseph Mirabel's avatar
Joseph Mirabel committed
77
        void updateRobotJoints (const QString robotName);
78

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

Joseph Mirabel's avatar
Joseph Mirabel committed
83
        public slots:
hdallard's avatar
hdallard committed
84
          /// Draw robot's contacts in the viewer.
85
          void drawRobotContacts ();
hdallard's avatar
hdallard committed
86 87

          /// Draw environment's contacts in the viewer.
88
          void drawEnvironmentContacts ();
hdallard's avatar
hdallard committed
89 90

          /// Draw handles frame in the viewer.
91
          void drawHandlesFrame ();
hdallard's avatar
hdallard committed
92 93

          /// Draw grippers frame in the viewer.
94
          void drawGrippersFrame ();
hdallard's avatar
hdallard committed
95 96

          /// Create the widget to select what to include in constraint's graph autobuild.
hdallard's avatar
hdallard committed
97
          void autoBuildGraph();
98

99
        private slots:
hdallard's avatar
hdallard committed
100
          /// Construct all the corba vars and create the graph.
101 102
          void buildGraph();

103 104 105
      protected:
        virtual void loadConstraintWidget();

Joseph Mirabel's avatar
Joseph Mirabel committed
106
      private:
hdallard's avatar
hdallard committed
107 108 109
        // Type used to make one function to build datas needed for autoBuild
        typedef std::pair<hpp::Names_t, hpp::corbaserver::manipulation::Namess_t> NamesPair;
      typedef std::map<std::string, std::list<std::string> > MapNames;
hdallard's avatar
hdallard committed
110 111

        /// Convert a MapNames to a pair of corba types.
hdallard's avatar
hdallard committed
112
        NamesPair convertMap(MapNames& mapNames);
hdallard's avatar
hdallard committed
113 114

        /// Transform a list of QListWidgetItem to corba sequence of strings.
115
        hpp::Names_t_var convertToNames(const QList<QListWidgetItem *>& l);
116

117 118
      MapNames getObjects();
      void fillMap(MapNames& map, const QList<QListWidgetItem *>& l);
119 120
        void mergeShapes(MapNames& handles, MapNames& shapes);

121 122 123 124 125 126 127 128 129
      /// Draw the surface name describe by the points at index indexes[j] in points.
      /// The surface will be moved of epsilon along its normal so that it does not overlap
      /// others bodies.
      /// \param name surface name
      /// \param indexes table of indexes
      /// \param points table of points
      /// \param j index in table indexes
      /// \param epsilon offset
      void drawContactSurface(const std::string& name, hpp::intSeq_var& indexes,
130
			      hpp::floatSeqSeq_var& points, CORBA::ULong j, float epsilon = 0.0001f);
131

Joseph Mirabel's avatar
Joseph Mirabel committed
132
        HppManipClient* hpp_;
133

Joseph Mirabel's avatar
Joseph Mirabel committed
134
        QToolBar *toolBar_;
135
        QTabWidget *tw_;
136
        QDialog* graphBuilder_;
Joseph Mirabel's avatar
Joseph Mirabel committed
137 138 139
    };
  } // namespace gui
} // namespace hpp
140

Joseph Mirabel's avatar
Joseph Mirabel committed
141
#endif // HPP_GUI_HPPMANIPULATIONWIDGETSPLUGIN_HH