00001 #ifndef GRASP_PLANNING_GRASPIT_GRASPITACCESSOR_H 00002 #define GRASP_PLANNING_GRASPIT_GRASPITACCESSOR_H 00003 00025 // #include <grasp_planning_graspit/LogBinding.h> 00026 #include <grasp_planning_graspit/SharedPtr.h> 00027 #include <grasp_planning_graspit/GraspItSceneManager.h> 00028 #include <grasp_planning_graspit/GraspItTypes.h> 00029 #include <string> 00030 00031 namespace GraspIt 00032 { 00033 00034 class GraspItSceneManager; 00035 00082 class GraspItAccessor 00083 { 00084 friend class GraspItSceneManager; 00085 public: 00092 GraspItAccessor(const std::string& objectName, const SHARED_PTR<GraspItSceneManager>& interface); 00093 virtual ~GraspItAccessor(); 00094 00095 std::string getName() const; 00096 00097 protected: 00115 virtual void idleEventFromSceneManager() = 0; 00116 00122 virtual void onSceneManagerShutdown() = 0; 00123 00124 00143 bool addAsIdleListener(); 00144 00148 bool removeFromIdleListeners(); 00149 00157 void scheduleForIdleEventUpdate(); 00158 00162 void unschedule(); 00163 00167 bool isScheduledForIdleEvent() const; 00168 00175 const SHARED_PTR<GraspItSceneManager>& getGraspItSceneManager(); 00176 00177 const SHARED_PTR<const GraspItSceneManager> readGraspItSceneManager() const; 00178 00182 bool eventThreadRunsQt() const; 00183 00187 bool tryLockWorld(); 00188 00192 void lockWorld(); 00193 00197 void unlockWorld(); 00198 00202 UNIQUE_RECURSIVE_LOCK getUniqueWorldLock(); 00203 00207 Hand * getCurrentHand(); 00208 00212 const Hand * readCurrentHand() const; 00213 00217 GraspableBody * getCurrentGraspableBody(); 00218 00222 const GraspableBody * readCurrentGraspableBody() const; 00223 00227 Robot * getRobot(const std::string& name); 00228 00232 Robot * getRobot(const unsigned int i); 00233 00237 GraspableBody * getGraspableBody(const std::string& name); 00238 00242 GraspableBody * getGraspableBody(const unsigned int i); 00243 00247 Body * getBody(const std::string& name); 00248 00252 Body * getBody(const unsigned int i); 00253 00257 bool isRobotLoaded(const Robot * robot) const; 00258 00262 bool isObjectLoaded(const Body * object) const; 00263 00271 bool removeElement(WorldElement* elem, const bool deleteInstance); 00272 00276 int addRobot(Robot* robot, const EigenTransform& worldTransform); 00277 00281 int addBody(Body* body, const EigenTransform& worldTransform); 00282 00283 private: 00287 GraspItAccessor(const GraspItAccessor& o) {} 00288 00292 GraspItAccessor() {} 00293 00294 // pointer to the GraspItSceneManager object. GraspItSceneManager is supposed to 00295 // be threadsafe, though at beta stage, no guarantees are given yet. 00296 const SHARED_PTR<GraspItSceneManager> graspItInterface; 00297 00298 const std::string name; 00299 00300 bool registered; 00301 00302 bool scheduled; 00303 MUTEX scheduledMtx; 00304 }; 00305 } // namespace GraspIt 00306 #endif // GRASP_PLANNING_GRASPIT_GRASPITACCESSOR_H