MotionSequenceNode.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_MotionSequenceNode_h_
00003 #define INCLUDED_MotionSequenceNode_h_
00004
00005 #include "MCNode.h"
00006 #include "Motion/MotionManager.h"
00007 #include "Motion/MotionSequenceMC.h"
00008 #include "Shared/debuget.h"
00009 #include "Shared/MarkScope.h"
00010
00011
00012
00013 extern const char defMotionSequenceNodeName[];
00014
00015
00016 extern const char defMotionSequenceNodeDesc[];
00017
00018
00019
00020
00021 template<unsigned int SIZE>
00022 class MotionSequenceNode : public MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true> {
00023 public:
00024
00025 MotionSequenceNode()
00026 : MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>(),
00027 looping(false), filename() {}
00028
00029
00030 MotionSequenceNode(const std::string& name, const std::string& file="", bool loop=false)
00031 : MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>(name),
00032 looping(loop), filename(file) {}
00033
00034 virtual void preStart() {
00035 MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::preStart();
00036 if(const DataEvent<std::string>* ev = dynamic_cast<const DataEvent<std::string>*>(this->event))
00037 filename = ev->getData();
00038 update(filename);
00039 }
00040
00041 virtual void postStart() {
00042 MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::postStart();
00043 MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::getMC()->play();
00044 }
00045
00046
00047 virtual void setFile(const std::string& file) {
00048 if ( StateNode::isActive() )
00049 update(file);
00050 else
00051 filename=file;
00052 }
00053
00054
00055 virtual void setLooping(bool loop) { looping=loop; }
00056
00057 virtual void doEvent() {
00058 ASSERTRET(this->event->getGeneratorID()==EventBase::motmanEGID,"Unknown event");
00059 if ( this->event->getSourceID() == MCNodeBase::getMC_ID() ) {
00060 if(looping)
00061 MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::getMC()->setTime(1);
00062 StateNode::postStateCompletion();
00063 }
00064 }
00065
00066
00067 virtual bool getLooping() { return looping; }
00068
00069 protected:
00070
00071
00072 void update(const std::string& file) {
00073 if ( file.size() > 0 ) {
00074 filename=file;
00075 MMAccessor<MotionSequenceMC<SIZE> > mma = MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::getMC();
00076 mma->clear();
00077 mma->loadFile(filename.c_str());
00078 mma->setTime(1);
00079 }
00080 }
00081
00082 bool looping;
00083 std::string filename;
00084 };
00085
00086 typedef MotionSequenceNode<TinyMotionSequenceMC::CAPACITY> TinyMotionSequenceNode;
00087 typedef MotionSequenceNode<SmallMotionSequenceMC::CAPACITY> SmallMotionSequenceNode;
00088 typedef MotionSequenceNode<MediumMotionSequenceMC::CAPACITY> MediumMotionSequenceNode;
00089 typedef MotionSequenceNode<LargeMotionSequenceMC::CAPACITY> LargeMotionSequenceNode;
00090 typedef MotionSequenceNode<XLargeMotionSequenceMC::CAPACITY> XLargeMotionSequenceNode;
00091
00092
00093
00094
00095
00096
00097 #endif