Studierstube 4 Documentation Project

   Main Page       Modules       Class Hierarchy       Alphabetical List       Compound List       File List       Compound Members       Related Pages   

SoTimeOutSwitch.cpp

Go to the documentation of this file.
00001 //
00002 // C++ Implementation: %{MODULE}
00003 //
00004 // Description:
00005 //
00006 //
00007 // Author: sareika
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 
00013 #include <iostream>
00014 
00015 #include <stb/components/starlight/SoTimeOutSwitch.h>
00016 
00017 using namespace std;
00018 
00019 // #define TIMEOUTDEBUG
00020 
00021 SO_NODEENGINE_SOURCE(SoTimeOutSwitch);
00022 
00023 SoTimeOutSwitch::SoTimeOutSwitch()
00024 {
00025     SO_NODEENGINE_CONSTRUCTOR(SoTimeOutSwitch);
00026     SO_NODE_ADD_FIELD(trigger, ());
00027     SO_NODE_ADD_FIELD(on, ("TRUE"));
00028     SO_NODE_ADD_FIELD(off, ("FALSE"));
00029     SO_NODE_ADD_FIELD(timeout, (1.0));
00030 
00031     SO_NODEENGINE_ADD_OUTPUT(out, SoSFString);
00032 
00033     timeOutSensor.setFunction(SoTimeOutSwitch::timeOutFired);
00034     timeOutSensor.setData(this);
00035     inputChanged(&trigger);
00036     switchOn=false;
00037 }
00038 
00039 void SoTimeOutSwitch::initClass(void)
00040 {
00041     if( SoType::fromName("SoTimeOutSwitch").isBad())
00042     {
00043         SO_NODEENGINE_INIT_CLASS(SoTimeOutSwitch, SoNodeEngine, "NodeEngine");
00044     }
00045 }
00046 
00047 void SoTimeOutSwitch::inputChanged( SoField * which )
00048 {
00049     if( which == &trigger )
00050     {
00051         trigger.getValue();
00052         if(timeOutSensor.isScheduled())
00053             timeOutSensor.unschedule();
00054         
00055         timeOutSensor.setTimeFromNow(timeout.getValue());
00056         timeOutSensor.schedule();
00057          
00058 #ifdef TIMEOUTDEBUG
00059         logPrintD("trigger fired %i \n", switchOn);
00060 #endif
00061     }
00062 }
00063 
00064 void SoTimeOutSwitch::evaluate(void)
00065 {
00066 #ifdef TIMEOUTDEBUG
00067     logPrintD("evaluate with %i and %i\n", timeOutSensor.isScheduled(),  switchOn);
00068 #endif
00069     
00070     SbString temp;
00071     if( timeOutSensor.isScheduled())
00072         temp = on.getValue();
00073     else
00074         temp = off.getValue();
00075     SO_ENGINE_OUTPUT(out, SoSFString, setValue(temp));
00076 }
00077 
00078 void SoTimeOutSwitch::timeOutFired( void * data, SoSensor * sensor )
00079 {
00080     assert( data != NULL );
00081     SoTimeOutSwitch * self = (SoTimeOutSwitch *) data;
00082 
00083     self->touch();
00084 
00085 #ifdef TIMEOUTDEBUG
00086     logPrintD("timer fired\n");
00087 #endif
00088 }
 This page was generated at Wed Oct 27 13:00:12 2010 for Studierstube 4 by Doxygen.
 If you have any comments, please send a message to schmalstieg#icg.tu-graz.ac.at.
www.studierstube.org