00001
00002 #ifndef INCLUDED_LoadPostureControl_h_
00003 #define INCLUDED_LoadPostureControl_h_
00004
00005 #include "FileBrowserControl.h"
00006 #include "Motion/PostureMC.h"
00007 #include "Motion/MMAccessor.h"
00008 #include "Motion/EmergencyStopMC.h"
00009 #include "Events/EventRouter.h"
00010 #include <string>
00011
00012
00013
00014 class LoadPostureControl : public FileBrowserControl, public EventListener {
00015 public:
00016
00017 LoadPostureControl(const std::string& n, MotionManager::MC_ID estop_id)
00018 : FileBrowserControl(n,"Loads a posture from user-selected file",config->motion.root), estopid(estop_id), file()
00019 {
00020 setFilter("*.pos");
00021 }
00022
00023 virtual ~LoadPostureControl() {}
00024
00025
00026 virtual void processEvent(const EventBase& event) {
00027
00028
00029 erouter->removeListener(this,event);
00030 MMAccessor<EmergencyStopMC> estop(estopid);
00031
00032
00033
00034 estop->LoadFile(file.c_str());
00035 estop->setActive(true);
00036 }
00037
00038 virtual void deactivate() {
00039 erouter->forgetListener(this);
00040 }
00041
00042 protected:
00043
00044 virtual ControlBase* selectedFile(const std::string& f) {
00045 file=f;
00046 SharedObject<PostureMC> post;
00047 post->LoadFile(file.c_str());
00048 MMAccessor<EmergencyStopMC>(estopid)->setActive(false);
00049 MotionManager::MC_ID id=motman->addMotion(post,MotionManager::kEmergencyPriority+1,true);
00050 erouter->addListener(this,EventBase::motmanEGID,id,EventBase::deactivateETID);
00051 return this;
00052 }
00053
00054 MotionManager::MC_ID estopid;
00055 std::string file;
00056 };
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #endif