00001 #include "PostureEditor.h"
00002 #include "Motion/MMAccessor.h"
00003 #include "ValueEditControl.h"
00004 #include "NullControl.h"
00005
00006 PostureEditor::PostureEditor()
00007 : ControlBase("Posture Editor","Allows you to load, save, and numerically edit the posture"),
00008 poseMC(), poseID(MotionManager::invalid_MC_ID), lastSlot(NULL), loadPose(NULL), savePose(NULL)
00009 {
00010
00011 pushSlot(loadPose=new FileInputControl("Load Posture","Select a posture to open",config->motion.root));
00012 loadPose->setFilter("*.pos");
00013 pushSlot(savePose=new StringInputControl("Save Posture","Please enter the filename to save to (in "+config->motion.root+")"));
00014
00015
00016 ControlBase * weights;
00017 pushSlot(weights=new ControlBase("Weights","Set the weights for outputs"));
00018 for(unsigned int i=0; i<NumOutputs; i++) {
00019 std::string tmp(outputNames[i]);
00020 weights->pushSlot(new ValueEditControl<float>(tmp,&poseMC->getOutputCmd(i).weight));
00021 }
00022
00023 pushSlot(NULL);
00024
00025
00026 for(unsigned int i=0; i<NumOutputs; i++) {
00027 std::string tmp(outputNames[i]);
00028 pushSlot(new ValueEditControl<float>(tmp,&poseMC->getOutputCmd(i).value));
00029 }
00030 }
00031
00032 ControlBase *
00033 PostureEditor::activate(MotionManager::MC_ID disp_id, Socket * gui) {
00034
00035 poseMC->takeSnapshot();
00036
00037 for(unsigned int i=LEDOffset; i<LEDOffset+NumLEDs; i++)
00038 poseMC->setOutputCmd(i,0);
00039
00040 poseID=motman->addMotion(poseMC,MotionManager::kEmergencyPriority+1,false);
00041
00042 return ControlBase::activate(disp_id,gui);
00043 }
00044
00045 void
00046 PostureEditor::refresh() {
00047 if(lastSlot==loadPose) {
00048
00049 MMAccessor<PostureMC>(poseID)->LoadFile(loadPose->getLastInput().c_str());
00050 } else if(lastSlot==savePose || savePose->getLastInput().size()>0) {
00051
00052 MMAccessor<PostureMC>(poseID)->SaveFile(config->motion.makePath(savePose->getLastInput()).c_str());
00053 savePose->takeInput("");
00054 }
00055 lastSlot=NULL;
00056 ControlBase::refresh();
00057 }
00058
00059 void
00060 PostureEditor::deactivate() {
00061 motman->removeMotion(poseID);
00062 poseID=MotionManager::invalid_MC_ID;
00063 ControlBase::deactivate();
00064 }
00065
00066 ControlBase*
00067 PostureEditor::doSelect() {
00068
00069 lastSlot=options[hilights.front()];
00070
00071 return ControlBase::doSelect();
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084