From 34e116151d4f7e2bba3f619125ff6acc85d81fda Mon Sep 17 00:00:00 2001
From: Florent Lamiraux <florent@laas.fr>
Date: Thu, 5 Jun 2014 20:44:36 +0200
Subject: [PATCH] Replace class Grasp by Gripper.

---
 CMakeLists.txt                                |  2 +-
 include/hpp/manipulation/axial-handle.hh      |  2 +-
 include/hpp/manipulation/fwd.hh               |  6 +-
 .../hpp/manipulation/{grasp.hh => gripper.hh} | 56 +++++++++++--------
 include/hpp/manipulation/handle.hh            |  5 +-
 src/axial-handle.cc                           | 10 ++--
 src/handle.cc                                 |  9 ++-
 src/robot.cc                                  |  2 +-
 8 files changed, 50 insertions(+), 42 deletions(-)
 rename include/hpp/manipulation/{grasp.hh => gripper.hh} (65%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ebdf43..bef800f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ ADD_REQUIRED_DEPENDENCY(hpp-constraints >= 3.0.0)
 
 SET (${PROJECT_NAME}_HEADERS
   include/hpp/manipulation/fwd.hh
-  include/hpp/manipulation/grasp.hh
+  include/hpp/manipulation/gripper.hh
   include/hpp/manipulation/axial-handle.hh
   include/hpp/manipulation/handle.hh
   include/hpp/manipulation/object.hh
diff --git a/include/hpp/manipulation/axial-handle.hh b/include/hpp/manipulation/axial-handle.hh
index 889eaee..b7de07c 100644
--- a/include/hpp/manipulation/axial-handle.hh
+++ b/include/hpp/manipulation/axial-handle.hh
@@ -51,7 +51,7 @@ namespace hpp {
       /// \return the constraint of relative position between the handle and
       ///         the gripper. The rotation around x is not constrained.
       virtual DifferentiableFunctionPtr_t createGrasp
-      (const RobotPtr_t& robot, const GraspPtr_t& grasp) const;
+      (const GripperPtr_t& gripper) const;
 
       virtual std::ostream& print (std::ostream& os) const;
     protected:
diff --git a/include/hpp/manipulation/fwd.hh b/include/hpp/manipulation/fwd.hh
index d3f576f..71f291f 100644
--- a/include/hpp/manipulation/fwd.hh
+++ b/include/hpp/manipulation/fwd.hh
@@ -38,8 +38,8 @@ namespace hpp {
     typedef boost::shared_ptr <AxialHandle> AxialHandlePtr_t;
     typedef core::DifferentiableFunction DifferentiableFunction;
     typedef core::DifferentiableFunctionPtr_t DifferentiableFunctionPtr_t;
-    HPP_PREDEF_CLASS (Grasp);
-    typedef boost::shared_ptr <Grasp> GraspPtr_t;
+    HPP_PREDEF_CLASS (Gripper);
+    typedef boost::shared_ptr <Gripper> GripperPtr_t;
     HPP_PREDEF_CLASS (Handle);
     typedef boost::shared_ptr <Handle> HandlePtr_t;
     HPP_PREDEF_CLASS (Object);
@@ -63,7 +63,7 @@ namespace hpp {
     typedef model::vectorOut_t vectorOut_t;
 
     typedef std::vector <DevicePtr_t> Devices_t;
-    typedef std::vector <GraspPtr_t> Grasps_t;
+    typedef std::vector <GripperPtr_t> Grippers_t;
     typedef std::vector <ObjectPtr_t> Objects_t;
     typedef std::map <JointConstPtr_t, JointPtr_t> JointMap_t;
     typedef core::ConstraintPtr_t ConstraintPtr_t;
diff --git a/include/hpp/manipulation/grasp.hh b/include/hpp/manipulation/gripper.hh
similarity index 65%
rename from include/hpp/manipulation/grasp.hh
rename to include/hpp/manipulation/gripper.hh
index 5df35bb..862b022 100644
--- a/include/hpp/manipulation/grasp.hh
+++ b/include/hpp/manipulation/gripper.hh
@@ -17,62 +17,72 @@
 // hpp-manipulation. If not, see
 // <http://www.gnu.org/licenses/>.
 
-#ifndef HPP_MANIPULATION_GRASP_HH
-# define HPP_MANIPULATION_GRASP_HH
+#ifndef HPP_MANIPULATION_GRIPPER_HH
+# define HPP_MANIPULATION_GRIPPER_HH
 
 # include <hpp/manipulation/handle.hh>
 
 namespace hpp {
   namespace manipulation {
     /// Constraint between the position of a robot joint and of an object handle
-    class HPP_MANIPULATION_DLLAPI Grasp
+    class HPP_MANIPULATION_DLLAPI Gripper
     {
     public:
       /// Return a shared pointer to new instance
-      /// \param joint joint of the robot that holds the handle,
-      /// \param handle handle that is grasped,
+      /// \param joint joint of the robot that will hold handles,
       /// \param handlePositionInJoint handle position in the the grasping
       ///        joint.
-      static GraspPtr_t create (const JointPtr_t& joint,
-				const HandlePtr_t& handle,
+      static GripperPtr_t create (const std::string& name, const JointPtr_t& joint,
 				const Transform3f& handlePositionInJoint)
       {
-	Grasp* ptr = new Grasp (joint, handle, handlePositionInJoint);
-	return GraspPtr_t (ptr);
-      }
-      /// Get handle that is grasped
-      const HandlePtr_t& handle () const
-      {
-	return handle_;
+	Gripper* ptr = new Gripper (name, joint, handlePositionInJoint);
+	return GripperPtr_t (ptr);
       }
-      /// Get joint that grasps
+
+      /// Get joint that Grippers
       const JointPtr_t& joint () const
       {
 	return joint_;
       }
-      /// Get handle position in the the grasping joint
+      /// Get handle position in the the Grippering joint
       const Transform3f& handlePositionInJoint () const
       {
 	return handlePositionInJoint_;
       }
+      ///get name
+      const std::string& name () const
+      {
+	return name_;
+      }
+      /// Set name
+      void name (const std::string& n)
+      {
+	name_ = n;
+      }
+
+      
+      DifferentiableFunctionPtr_t createGrasp(HandlePtr_t& handle)
+      {
+        return handle->createGrasp(GripperPtr_t(this));
+      }
+
     protected:
       /// Constructor
       /// \param joint joint of the robot that holds the handle,
-      /// \param handle handle that is grasped,
       /// \param handlePositionInJoint handle position in the the grasping
       ///        joint.
-      Grasp (const JointPtr_t& joint, const HandlePtr_t& handle,
+      Gripper (const std::string& name, const JointPtr_t& joint,
 	     const Transform3f& handlePositionInJoint) :
-	joint_ (joint), handle_ (handle),
+	joint_ (joint),
 	handlePositionInJoint_ (handlePositionInJoint)
       {
       }
     private:
-      /// Joint of the robot that holds the handle.
+      /// Joint of the robot that holds handles.
+      std::string name_;
       JointPtr_t joint_;
-      HandlePtr_t handle_;
       Transform3f handlePositionInJoint_;
-    }; // class Grasp
+    }; // class Gripper
   } // namespace manipulation
 } // namespace hpp
-#endif // HPP_MANIPULATION_GRASP_HH
+#endif // HPP_MANIPULATION_GRIPPER_HH
diff --git a/include/hpp/manipulation/handle.hh b/include/hpp/manipulation/handle.hh
index 204832c..4afd217 100644
--- a/include/hpp/manipulation/handle.hh
+++ b/include/hpp/manipulation/handle.hh
@@ -84,8 +84,7 @@ namespace hpp {
       }
 
       /// Create constraint corresponding to a gripper grasping this object
-      /// \param robot the robot that grasps the handle,
-      /// \param grasp object containing the grasp information
+      /// \param gripper object containing the gripper information
       /// \return the constraint of relative position between the handle and
       ///         the gripper.
       /// \note the constraint may constrain less than 6 degrees of freedom
@@ -93,7 +92,7 @@ namespace hpp {
       ///       a handle symmetric with respect to its x-axis for instance, the
       ///       rotation around x is not constrained.
       virtual DifferentiableFunctionPtr_t createGrasp
-      (const RobotPtr_t& robot, const GraspPtr_t& grasp) const;
+      (const GripperPtr_t& gripper) const;
       virtual std::ostream& print (std::ostream& os) const;
 
     protected:
diff --git a/src/axial-handle.cc b/src/axial-handle.cc
index c5484fb..7f57d2f 100644
--- a/src/axial-handle.cc
+++ b/src/axial-handle.cc
@@ -22,21 +22,21 @@
 #include <hpp/model/joint.hh>
 #include <hpp/constraints/relative-transformation.hh>
 #include <hpp/manipulation/axial-handle.hh>
-#include <hpp/manipulation/grasp.hh>
+#include <hpp/manipulation/gripper.hh>
 #include <hpp/manipulation/robot.hh>
 
 namespace hpp {
   namespace manipulation {
 
     DifferentiableFunctionPtr_t AxialHandle::createGrasp
-    (const RobotPtr_t& robot, const GraspPtr_t& grasp) const
+    (const GripperPtr_t& gripper) const
     {
       using boost::assign::list_of;
       std::vector <bool> mask = list_of (true)(true)(true)(false)(true)(true);
       return RelativeTransformation::create
-	(robot, grasp->joint (), grasp->handle ()->joint (),
-	 inverse (grasp->handle ()->localPosition ()) *
-	 grasp->handlePositionInJoint (), mask);
+	(gripper->joint()->robot(), gripper->joint (), joint(),
+	 inverse (localPosition()) *
+	 gripper->handlePositionInJoint (), mask);
     }
     HandlePtr_t AxialHandle::clone () const
     {
diff --git a/src/handle.cc b/src/handle.cc
index 793477e..c66e2e7 100644
--- a/src/handle.cc
+++ b/src/handle.cc
@@ -22,21 +22,20 @@
 #include <hpp/model/joint.hh>
 #include <hpp/constraints/relative-transformation.hh>
 #include <hpp/manipulation/handle.hh>
-#include <hpp/manipulation/grasp.hh>
+#include <hpp/manipulation/gripper.hh>
 #include <hpp/manipulation/robot.hh>
 
 namespace hpp {
   namespace manipulation {
 
     DifferentiableFunctionPtr_t Handle::createGrasp
-    (const RobotPtr_t& robot, const GraspPtr_t& grasp) const
+    (const GripperPtr_t& gripper) const
     {
       using boost::assign::list_of;
       std::vector <bool> mask = list_of (true)(true)(true)(true)(true)(true);
       return RelativeTransformation::create
-	(robot, grasp->joint (), grasp->handle ()->joint (),
-	 inverse (grasp->handle ()->localPosition ()) *
-	 grasp->handlePositionInJoint (), mask);
+	(gripper->joint()->robot(), gripper->joint (), joint(), inverse (localPosition()) *
+	 gripper->handlePositionInJoint (), mask);
     }
 
     HandlePtr_t Handle::clone () const
diff --git a/src/robot.cc b/src/robot.cc
index e784285..410d963 100644
--- a/src/robot.cc
+++ b/src/robot.cc
@@ -20,7 +20,7 @@
 #include <hpp/util/debug.hh>
 #include <hpp/model/object-factory.hh>
 #include <hpp/manipulation/robot.hh>
-#include <hpp/manipulation/grasp.hh>
+#include <hpp/manipulation/gripper.hh>
 
 namespace hpp {
   namespace manipulation {
-- 
GitLab