Homepage Demos Overview Downloads Tutorials Reference
Credits

PostureEditor.cc

Go to the documentation of this file.
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   // add load and save menus
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   // add submenu for weight editors
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); // a separator for clarity
00024 
00025   // add actual value editors
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   // start off with current pose
00035   poseMC->takeSnapshot();
00036   // clear the LEDs though
00037   for(unsigned int i=LEDOffset; i<LEDOffset+NumLEDs; i++)
00038     poseMC->setOutputCmd(i,0);
00039   // add it to motion manager above estop
00040   poseID=motman->addMotion(poseMC,MotionManager::kEmergencyPriority+1,false);
00041   // call super class
00042   return ControlBase::activate(disp_id,gui);
00043 }
00044 
00045 void
00046 PostureEditor::refresh() {
00047   if(lastSlot==loadPose) {
00048     // we just got back from the load menu
00049     MMAccessor<PostureMC>(poseID)->LoadFile(loadPose->getLastInput().c_str());
00050   } else if(lastSlot==savePose || savePose->getLastInput().size()>0) {
00051     // we just got back from the save menu
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   // record the option that is being selected, in case it's the load or save
00069   lastSlot=options[hilights.front()];
00070   // but do what we'd normally do (select that option)
00071   return ControlBase::doSelect();
00072 }
00073 
00074 
00075 /*! @file
00076  * @brief Describes PostureEditor, which allows numeric control of joints and LEDs
00077  * @author ejt (Creator)
00078  *
00079  * $Author: ejt $
00080  * $Name: tekkotsu-2_1 $
00081  * $Revision: 1.3 $
00082  * $State: Exp $
00083  * $Date: 2004/01/30 01:48:02 $
00084  */

Tekkotsu v2.1
Generated Tue Mar 16 23:19:14 2004 by Doxygen 1.3.5