From 334a52942e0963ef5b43568df909b22b84f519a8 Mon Sep 17 00:00:00 2001 From: Christopher Stawarz Date: Fri, 25 Mar 2011 14:29:19 -0400 Subject: [PATCH] Removed some unused code from StandardStimuli. Tweaked some exception message formatting. --- Core/Exceptions/Exceptions.h | 6 +- Core/Stimuli/StandardStimuli.cpp | 394 ++----------------------------- Core/Stimuli/StandardStimuli.h | 78 +++--- 3 files changed, 54 insertions(+), 424 deletions(-) diff --git a/Core/Exceptions/Exceptions.h b/Core/Exceptions/Exceptions.h index 3330319..0281fc9 100644 --- a/Core/Exceptions/Exceptions.h +++ b/Core/Exceptions/Exceptions.h @@ -163,12 +163,12 @@ class FatalParserException : public SimpleException { class UnknownExpressionException : public SimpleException { public: - UnknownExpressionException(string _subject) : SimpleException(M_PARSER_MESSAGE_DOMAIN, "Invalid expression: ", _subject){ } + UnknownExpressionException(string _subject) : SimpleException(M_PARSER_MESSAGE_DOMAIN, "Invalid expression", _subject){ } }; class UnknownVariableException : public SimpleException { public: - UnknownVariableException(string _subject) : SimpleException(M_PARSER_MESSAGE_DOMAIN, "Invalid variable definition: ", _subject){ } + UnknownVariableException(string _subject) : SimpleException(M_PARSER_MESSAGE_DOMAIN, "Invalid variable definition", _subject){ } }; @@ -179,7 +179,7 @@ class ComponentFactoryConflictException : public SimpleException{ public: ComponentFactoryConflictException(string _subject) : - SimpleException(M_PLUGIN_MESSAGE_DOMAIN, "A plugin has attempted to redefine the behavior of an existing component signature.", _subject){ + SimpleException(M_PLUGIN_MESSAGE_DOMAIN, "A plugin has attempted to redefine the behavior of an existing component signature", _subject){ } virtual ~ComponentFactoryConflictException() throw() {} diff --git a/Core/Stimuli/StandardStimuli.cpp b/Core/Stimuli/StandardStimuli.cpp index 9069e27..437e03d 100644 --- a/Core/Stimuli/StandardStimuli.cpp +++ b/Core/Stimuli/StandardStimuli.cpp @@ -33,277 +33,11 @@ #import -using namespace mw; +BEGIN_NAMESPACE_MW -#define VERBOSE_STANDARD_STIMULI 0 - -/*StimulusGroupReference::StimulusGroupReference(char *_tag, StimulusGroup *_group, - Variable *_index) : Stimulus(_tag){ - group = _group; - index = _index; -} - - - -void StimulusGroupReference::load(shared_ptr display){ - - //(stimulus_nodes->getElement((int)(*index)))->load(); - if(index != NULL){ - mprintf("loading stimulus (%d)", GlobalCurrentExperiment->getInt(index)); - Stimulus *stim = group->getElement(GlobalCurrentExperiment->getInt(index)); - if(stim != NULL){ - //stim->load(display); - } else { - mprintf("Invalid referenced stimulus"); - } - } else { - mprintf("Invalid variable indexing stimulus group reference"); - } -} - - -void StimulusGroupReference::draw(shared_ptr display, float x, float y){ - - //(stimulus_nodes->getElement((int)(*index)))->draw(display, x, y); - if(index != NULL){ - mprintf("drawing stimulus (%d)", GlobalCurrentExperiment->getInt(index)); - Stimulus *stim = group->getElement(GlobalCurrentExperiment->getInt(index)); - if(stim != NULL){ - stim->draw(display,x,y); - } else { - mprintf("Invalid referenced stimulus"); - } - } else { - mprintf("Invalid variable indexing stimulus group reference"); - } -} - - -void StimulusGroupReference::draw(shared_ptr display, float x, float y, - float sizex, float sizey){ - - //(stimulus_nodes->getElement((int)(*index)))->draw(display,x,y,sizex,sizey); - mprintf("drawing stimulus (%d)", GlobalCurrentExperiment->getInt(index)); - if(index != NULL){ - Stimulus *stim = group->getElement(GlobalCurrentExperiment->getInt(index)); - if(stim != NULL){ - stim->draw(display,x,y,sizex,sizey); - } else { - mprintf("Invalid referenced stimulus"); - } - } else { - mprintf("Invalid variable indexing stimulus group reference"); - } -} - - -void StimulusGroupReference::draw(shared_ptr display){ - - //(stimulus_nodes->getElement((int)(*index)))->draw(display); - if(index != NULL){ - if (VERBOSE_STANDARD_STIMULI>0) mprintf("mStimulusGroupReference: drawing stimulus (%d)", - GlobalCurrentExperiment->getInt(index)); - Stimulus *stim = - group->getElement(GlobalCurrentExperiment->getInt(index)); - if(stim != NULL){ - stim->draw(display); - } else { - mprintf("Invalid referenced stimulus"); - } - } else { - mprintf("Invalid variable indexing stimulus group reference"); - } -} - -// JJD new method -// override of methods in base stimulus class -- announce each sub-element (using the standard base method) -void StimulusGroupReference::announceStimulusDraw() { - - //(stimulus_nodes->getElement((int)(*index)))->announceStimulusDraw(); - if(index != NULL){ - int groupIndex = GlobalCurrentExperiment->getInt(index); - if (VERBOSE_STANDARD_STIMULI>0) { - mprintf("mStimulusGroupReference: announcing stimulus draw, group index = %d", groupIndex); - } - Stimulus *stim = group->getElement(groupIndex); - char *groupName = group->getGroupTagName(); - if(stim != NULL){ - stim->announceStimulusDraw(groupName,groupIndex); // new polymophic method to give user back their group info - } else { - mprintf("Invalid referenced stimulus"); - } - } - -} - -void StimulusGroupReference::announceStimulusErase() { - - //(stimulus_nodes->getElement((int)(*index)))->announceStimulusErase(); - if(index != NULL){ - int groupIndex = GlobalCurrentExperiment->getInt(index); - if (VERBOSE_STANDARD_STIMULI>0) { - mprintf("mStimulusGroupReference: announcing stimulus erase, group index = %d", groupIndex); - } - Stimulus *stim = group->getElement(groupIndex); - char *groupName = group->getGroupTagName(); - if(stim != NULL){ - stim->announceStimulusErase(groupName, groupIndex); // new polymophic method to give user back their group info - } else { - mprintf("Invalid referenced stimulus"); - } - } -} - - */ - -/* -CompoundStimulus::CompoundStimulus(std::string _tag):Stimulus(_tag) { - stimList = new ExpandableList(); - makeSubTag(); // setup first tag just to have something -} - -CompoundStimulus::~CompoundStimulus() { - delete stimList; -} - - -// TODO: need to take into account case where stimulus in compound is -// somehow shared with other objects... (a strange, possibly impossible -// case currently, but needs to be considered down the road). - -void CompoundStimulus::freeze(bool should_freeze){ - for(int i = 0; i < stimList->getNElements(); i++){ - (*stimList)[i]->freeze(should_freeze); - } - Stimulus::freeze(should_freeze); -} -//Stimulus * CompoundStimulus::frozenClone(){ -// CompoundStimulus *clone = new CompoundStimulus(tag); -// for(int i = 0; i < stimList->getNElements(); i++){ -// shared_ptr p((*stimList)[i]->frozenClone()); -// clone->addStimulus(p); -// } -// -// clone->setIsFrozen(true); -// return clone; -//} - -void CompoundStimulus::addStimulus(shared_ptr stim) { - makeSubTag(); - shared_ptr p(new OffsetStimulusContainer(currentSubTag, stim)); - stimList->addReference(p); -} - -void CompoundStimulus::addStimulus(shared_ptr stim, shared_ptr _xloc, shared_ptr _yloc) { - makeSubTag(); - shared_ptr p(new OffsetStimulusContainer(currentSubTag, stim, _xloc, _yloc)); - stimList->addReference(p); -} - - -// override of methods in base stimulus class -- announce each sub-element (using the standard base method) -void CompoundStimulus::announceStimulusDraw(MWTime now) { - for(int i = 0; i < stimList->getNElements(); i++) { - (stimList->getElement(i))->announceStimulusDraw(now); - } -} - -void CompoundStimulus::makeSubTag() { - - // delete any previously used memory - - // make subTag - std::string baseTag= this->gettag(); // get base tag - int n = stimList->getNElements(); - char *sub = new char [5]; // make subtag - sprintf(sub, "_%d", n ); - - - currentSubTag = baseTag + sub; - - delete [] sub; - -} - -void CompoundStimulus::draw(shared_ptr display, - float xdeg, float ydeg) { - for(int i = 0; i < stimList->getNElements(); i++) { - (stimList->getElement(i))->draw(display, xdeg, ydeg); - } -} -*/ - - - - -OffsetStimulusContainer::OffsetStimulusContainer(std::string _tag, - shared_ptr _stim):Stimulus(_tag) { - stim = _stim; - - xoffset = shared_ptr(new ConstantVariable(Datum(0.0))); - yoffset = shared_ptr(new ConstantVariable(Datum(0.0))); -} - -OffsetStimulusContainer::OffsetStimulusContainer(std::string _tag, - shared_ptr _stim, - shared_ptr _xdeg, - shared_ptr _ydeg): - Stimulus(_tag) { - stim = _stim; - - xoffset = registerVariable(_xdeg); - yoffset = registerVariable(_ydeg); -} - -OffsetStimulusContainer::OffsetStimulusContainer(OffsetStimulusContainer& copy):Stimulus((Stimulus&) copy) { -// mdebug("Offset copy constructor is %x", this); -// mdebug("Offset copy object is %x", ©); -// mdebug("Offset copy stim is %x", copy.stim); - //mdebug("More information %x", *(copy.stim)); - stim = copy.stim; -// mdebug("Stim of offset in copy is %x", stim); - xoffset = copy.xoffset; - yoffset = copy.yoffset; -} - -OffsetStimulusContainer::~OffsetStimulusContainer() { } - -// TODO: need to write better custom "freeze" handling for the -// contained stimulus -void OffsetStimulusContainer::freeze(bool should_freeze){ - - stim->freeze(should_freeze); - Stimulus::freeze(should_freeze); -} - -//Stimulus * OffsetStimulusContainer::frozenClone(){ -// shared_ptr stim_clone(stim->frozenClone()); -// shared_ptr x_clone(xoffset->frozenClone()); -// shared_ptr y_clone(yoffset->frozenClone()); -// -// OffsetStimulusContainer *clone = new OffsetStimulusContainer(tag, -// stim_clone, -// x_clone, -// y_clone); -// clone->setIsFrozen(true); -// return clone; -//} - -void OffsetStimulusContainer::draw(shared_ptr display, - float x, float y){ } - -void OffsetStimulusContainer::draw(shared_ptr display, float x, - float y, float sizex, float sizey) { - if(stim == NULL) { - mwarning(M_DISPLAY_MESSAGE_DOMAIN, - "Attempt to draw on a NULL stimulus"); - mwarning(M_DISPLAY_MESSAGE_DOMAIN, - "%s:%d", __FILE__, __LINE__); - } - stim->draw(display, (float)*xoffset+x, (float)*yoffset+y, sizex, sizey); -} +#define VERBOSE_STANDARD_STIMULI 0 BasicTransformStimulus::BasicTransformStimulus(std::string _tag, shared_ptr _xoffset, @@ -1081,111 +815,27 @@ Datum PointStimulus::getCurrentAnnounceDrawData() { } -/* -void * forceDisplayUpdate(void *arg) { - //mprintf("displaying..."); - shared_ptr display = *((shared_ptr *)arg); - //mprintf("Called force display..."); - if(display) { - display->updateDisplay(); - } - // just return NULL because noone is probably checking this anyway - return NULL; -} +END_NAMESPACE_MW + + + + + + + + + + + + + + + + + + + -FreeRunningMovieStimulus::FreeRunningMovieStimulus(char *_tag, long _nframes, - long _frame_interval, float _xoffset, float _yoffset, - float _xscale, float _yscale, float _rot) - : BasicTransformStimulus(_tag, - new ConstantVariable(_xoffset), - new ConstantVariable(_yoffset), - new ConstantVariable(_xscale), - new ConstantVariable(_yscale), - new ConstantVariable(_rot)) { - // TODO: this is a leak for sure - nframes = _nframes; - frame_interval_ms = _frame_interval; - start_time = clock->getSystemTime(); - running = false; -} -void FreeRunningMovieStimulus::setCurrentFrame() { }; - -void FreeRunningMovieStimulus::draw(shared_ptr display) { - if(!running && GlobalCurrentExperiment->getInt(state_system_mode) != IDLE) { - if(display) { - if(0 && nframes) { - schedule_node = GlobalScheduler->schedule(0, frame_interval_ms, - abs(nframes), &forceDisplayUpdate, - (void *)display, - M_DEFAULT_STIMULUS_PRIORITY, - M_DEFAULT_WARN_SLOP_MS, - M_DEFAULT_FAIL_SLOP_MS); - } else { - schedule_node = GlobalScheduler->schedule(0, frame_interval_ms, - M_REPEAT_INDEFINITELY, - &forceDisplayUpdate, - (void *)display, - M_DEFAULT_STIMULUS_PRIORITY, - M_DEFAULT_WARN_SLOP_MS, - M_DEFAULT_FAIL_SLOP_MS); - } - } - running = true; - } - if(GlobalCurrentExperiment->getInt(state_system_mode) == IDLE && running) { - if(schedule_node) { - running = false; - schedule_node->cancel(); - schedule_node = NULL; - } - return; - } - - int current_time = clock->getSystemTime(); - int elapsed = current_time - start_time; - current_frame = (int)((double)elapsed / (double)frame_interval_ms); - - if(current_frame > abs(nframes)) { - if(nframes > 0) { - running = false; - return; // do something more interesting here... - } else { - //running = true; - current_frame = current_frame % abs(nframes); - } - } - //mprintf("current_frame: %d", current_frame); - draw(display, *xoffset, *yoffset, *xscale, *yscale); -} - -void FreeRunningMovieStimulus::draw(shared_ptr display,float x, - float y, float sizex, float sizey) { - BasicTransformStimulus::draw(display,x,y,sizex,sizey); -} - -void FreeRunningMovieStimulus::drawInUnitSquare(shared_ptr display) { } - -void FreeRunningMovieStimulus::setVisible(bool vis) { - BasicTransformStimulus::setVisible(vis); - if(!vis && running && schedule_node) { - schedule_node->cancel(); - running = false; - // kludge/needs addition: someone must clean this up - schedule_node = NULL; - } -} -void VideoRequest::service() { - //E->drawStimulusID(stimtodraw, xloc, yloc); -} -void videoInterruptService(void) { - //ITC_DigitalBitsOn(0x02); - //VRtime = currentTime; - //if (E->getBool(IS_RUNNING)) - //putEvent5("VR", NULL, NULL); - - //E->drawPendingStimuli(); -}*/ - diff --git a/Core/Stimuli/StandardStimuli.h b/Core/Stimuli/StandardStimuli.h index 34be0cd..bf0c188 100644 --- a/Core/Stimuli/StandardStimuli.h +++ b/Core/Stimuli/StandardStimuli.h @@ -22,39 +22,10 @@ #include "Stimulus.h" #include "Experiment.h" #include "ComponentFactory.h" -namespace mw { -// a stimulus object with a position stored -// may still be an error here TODO because no destructor and copy -// constructor does nothing -class OffsetStimulusContainer : public Stimulus { - protected: - shared_ptr stim; - shared_ptr xoffset; - shared_ptr yoffset; - public: - /** - * Constructor - */ - OffsetStimulusContainer(std::string _tag, shared_ptr _stim); - OffsetStimulusContainer(std::string _tag, shared_ptr _stim, - shared_ptr _xdeg, - shared_ptr _ydeg); - - OffsetStimulusContainer(OffsetStimulusContainer& copy); - ~OffsetStimulusContainer(); - //virtual Stimulus * frozenClone(); - void freeze(bool should_freeze = true); - - virtual void draw(shared_ptr display, float x, float y); - virtual void draw(shared_ptr display, float x, float y, - float sizex, float sizey); - private: - // do not use the assignment operator, it does nothing - // useful. I made it private to hide it from users and to - // prevent a default version from being used. - void operator=(const OffsetStimulusContainer& l) { } -}; + +BEGIN_NAMESPACE_MW + // a stimulus object with a position stored // this is the base object from which many others should derive @@ -275,22 +246,31 @@ class BlankScreenFactory : public ComponentFactory { ComponentRegistry *reg); }; -/*class VideoRequest { - protected: - StimID stimtodraw; - Datum xloc; - Datum yloc; - - public: - VideoRequest(StimID _stim, Datum _x, Datum _y) { - stimtodraw = _stim; - xloc = _x; - yloc = _y; - } - virtual ~VideoRequest() { } - virtual void service(); -}; -void videoInterruptService();*/ -} +END_NAMESPACE_MW + + #endif + + + + + + + + + + + + + + + + + + + + + + +