tclpkg-expt.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 1999-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Mon Mar  8 03:18:40 1999
00010 // commit: $Id: tclpkg-expt.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/visx/tclpkg-expt.cc $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_VISX_TCLPKG_EXPT_CC_UTC20050628171008_DEFINED
00035 #define GROOVX_VISX_TCLPKG_EXPT_CC_UTC20050628171008_DEFINED
00036 
00037 #include "visx/tclpkg-expt.h"
00038 
00039 #include "nub/ref.h"
00040 
00041 #include "tcl/itertcl.h"
00042 #include "tcl/objpkg.h"
00043 #include "tcl/pkg.h"
00044 #include "tcl/tracertcl.h"
00045 
00046 #include "tcl-gfx/toglet.h"
00047 
00048 #include "rutz/fstring.h"
00049 #include "rutz/sfmt.h"
00050 
00051 #include "visx/exptdriver.h"
00052 
00053 #include "rutz/trace.h"
00054 
00055 using rutz::fstring;
00056 
00057 namespace
00058 {
00059   // Creates the necessary screen bindings for start, pause, and quit,
00060   // then begins the current trial (probably the first trial) of the
00061   // current Expt. Record the time when the experiment
00062   // began. edBeginExpt is called, which displays a trial, and
00063   // generates the timer callbacks associated with a trial.
00064   void beginExpt(nub::ref<ExptDriver> xp)
00065   {
00066     nub::soft_ref<Toglet> w = xp->getWidget();
00067 
00068     // Create the begin key binding
00069     w->bind("<Control-KeyPress-b>",
00070             rutz::sfmt("-> %lu takeFocus; -> %lu begin",
00071                        w.id(), xp.id()));
00072 
00073     // Create the quit key binding
00074     w->bind("<Control-KeyPress-q>",
00075             rutz::sfmt("-> %lu halt; -> %lu storeData; exit",
00076                        xp.id(), xp.id()));
00077 
00078     // Create the quit-without-save key binding
00079     w->bind("<Control-Alt-KeyPress-x>", "exit");
00080 
00081     // Create the save key binding
00082     w->bind("<Control-KeyPress-s>", rutz::sfmt("-> %lu storeData", xp.id()));
00083 
00084     // Create the stop key binding
00085     w->bind("<Control-KeyPress-c>", rutz::sfmt("-> %lu stop", xp.id()));
00086 
00087     // Create the reset key binding
00088     w->bind("<Control-KeyPress-r>", rutz::sfmt("-> %lu reset", xp.id()));
00089 
00090 #if 0
00091     // Create the pause key binding
00092     w->bind("<KeyPress-p>", rutz::sfmt("-> %lu pause", xp.id()));
00093 #endif
00094 
00095     // Force the focus to the widget
00096     w->takeFocus();
00097 
00098     xp->edBeginExpt();
00099   }
00100 
00101   void waitStartKey(nub::ref<ExptDriver> xp, const char* event)
00102   {
00103     nub::soft_ref<Toglet> w = xp->getWidget();
00104 
00105     // This script does two things:
00106 
00107     // (1) destroy the binding that generated this callback (so that we
00108     // don't accidentally "start" the experiment twice due to a double
00109     // keypress)
00110     // (2) actually start the experimeent
00111     const fstring script =
00112       rutz::sfmt("-> %lu bind %s {}; -> %lu begin",
00113                  w.id(), event, xp.id());
00114 
00115     w->bind(event, script);
00116     w->takeFocus();
00117   }
00118 
00119   void fakePause(nub::ref<ExptDriver>) {}
00120 }
00121 
00122 extern "C"
00123 int Exptdriver_Init(Tcl_Interp* interp)
00124 {
00125 GVX_TRACE("Exptdriver_Init");
00126 
00127   GVX_PKG_CREATE(pkg, interp, "ExptDriver", "4.$Revision: 10065 $");
00128   pkg->inherit_pkg("ElementContainer");
00129   tcl::def_creator<ExptDriver>(pkg);
00130   tcl::def_basic_type_cmds<ExptDriver>(pkg, SRC_POS);
00131 
00132   tcl::def_tracing(pkg, ExptDriver::tracer);
00133 
00134   pkg->def( "begin", "expt_id", &beginExpt, SRC_POS );
00135   pkg->def( "waitStartKey", "expt_id <event>", &waitStartKey, SRC_POS );
00136 
00137   pkg->def_get_set("autosaveFile",
00138                    &ExptDriver::getAutosaveFile,
00139                    &ExptDriver::setAutosaveFile,
00140                    SRC_POS);
00141   pkg->def_get_set("autosavePeriod",
00142                    &ExptDriver::getAutosavePeriod,
00143                    &ExptDriver::setAutosavePeriod,
00144                    SRC_POS);
00145   pkg->def_action("claimLogFile", &ExptDriver::claimLogFile, SRC_POS);
00146   pkg->def_get_set("filePrefix",
00147                    &ExptDriver::getFilePrefix,
00148                    &ExptDriver::setFilePrefix,
00149                    SRC_POS);
00150   pkg->def_getter("infoLog", &ExptDriver::getInfoLog, SRC_POS);
00151   pkg->def("pause", "expt_id", &fakePause, SRC_POS);
00152   pkg->def_action("storeData", &ExptDriver::storeData, SRC_POS);
00153   // FIXME this conflicts with Element::widget
00154   pkg->def_get_set("widget", &ExptDriver::getWidget, &ExptDriver::setWidget, SRC_POS);
00155   pkg->def_getter("doWhenComplete", &ExptDriver::getDoWhenComplete, SRC_POS);
00156   pkg->def_setter("doWhenComplete", &ExptDriver::setDoWhenComplete, SRC_POS);
00157 
00158   GVX_PKG_RETURN(pkg);
00159 }
00160 
00161 static const char __attribute__((used)) vcid_groovx_visx_tclpkg_expt_cc_utc20050628171008[] = "$Id: tclpkg-expt.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00162 #endif // !GROOVX_VISX_TCLPKG_EXPT_CC_UTC20050628171008_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:42 2008 by Doxygen version 1.5.5.