00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef SCRIPT_MODELSCRIPT_C_DEFINED
00039 #define SCRIPT_MODELSCRIPT_C_DEFINED
00040
00041 #include "Script/ModelScript.H"
00042
00043 #include "tcl/stdconversions.h"
00044
00045 #include "Component/ModelManager.H"
00046 #include "Neuro/StdBrain.H"
00047 #include "Util/log.H"
00048 #include "tcl/list.h"
00049 #include "tcl/objpkg.h"
00050 #include "tcl/pkg.h"
00051
00052 #include <sstream>
00053 #include <string>
00054 #include <tcl.h>
00055
00056 namespace
00057 {
00058 nub::soft_ref<ModelManager> theManager;
00059
00060 nub::soft_ref<StdBrain> makeStdBrain()
00061 {
00062 return nub::soft_ref<StdBrain>(new StdBrain(*theManager));
00063 }
00064
00065 void setMPString(nub::soft_ref<ModelComponent> comp,
00066 const std::string& name,
00067 const std::string& value)
00068 {
00069 comp->setModelParamString(name, value);
00070 }
00071
00072 std::string getMPString(nub::soft_ref<ModelComponent> comp,
00073 const std::string& name)
00074 {
00075 return comp->getModelParamString(name);
00076 }
00077
00078 std::string printout(nub::soft_ref<ModelComponent> comp)
00079 {
00080 std::ostringstream strm;
00081 comp->printout(strm);
00082 return strm.str();
00083 }
00084
00085 bool mmParse(nub::soft_ref<ModelManager> mm,
00086 tcl::list argv, const char* usage,
00087 int minarg, int maxarg)
00088 {
00089 const char* args[argv.length()];
00090
00091 for (uint i = 0; i < argv.length(); ++i)
00092 args[i] = argv.get<const char*>(i);
00093
00094 return mm->parseCommandLine(argv.length(), args, usage,
00095 minarg, maxarg);
00096 }
00097
00098 tcl::list mmExtraArgs(nub::soft_ref<ModelManager> mm)
00099 {
00100 tcl::list result;
00101 for (uint i = 0; i < mm->numExtraArgs(); ++i)
00102 result.append(mm->getExtraArg(i));
00103 return result;
00104 }
00105
00106 int evolveMaster(nub::ref<SimEventQueue> seq)
00107 {
00108 const SimStatus status = seq->evolve();
00109 return status == SIM_BREAK;
00110 }
00111 }
00112
00113 OptionManager& getManager()
00114 {
00115 return *theManager;
00116 }
00117
00118 extern "C"
00119 int Modelcomponent_Init(Tcl_Interp* interp)
00120 {
00121 GVX_PKG_CREATE(pkg, interp, "Modelcomponent", "4.$Revision: 1$");
00122 pkg->inherit_pkg("Obj");
00123 tcl::def_basic_type_cmds<ModelComponent>(pkg, SRC_POS);
00124
00125 pkg->def("start", "objref",
00126 &ModelComponent::start, SRC_POS);
00127 pkg->def("stop", "objref",
00128 &ModelComponent::stop, SRC_POS);
00129 pkg->def("started", "objref",
00130 &ModelComponent::started, SRC_POS);
00131 pkg->def("descriptiveName", "objref",
00132 &ModelComponent::descriptiveName, SRC_POS);
00133 pkg->def("tagName", "objref",
00134 &ModelComponent::tagName, SRC_POS);
00135 pkg->def("tagName", "objref newname",
00136 &ModelComponent::setTagName, SRC_POS);
00137 pkg->def("addSubComponent", "objref subcomp propgrealm",
00138 &ModelComponent::addSubComponent, SRC_POS);
00139 pkg->def("removeSubComponentByIndex", "objref index",
00140 (void (ModelComponent::*)(uint))
00141 &ModelComponent::setTagName, SRC_POS);
00142 pkg->def("removeSubComponentByName", "objref tagname ",
00143 (void (ModelComponent::*)(const std::string&))
00144 &ModelComponent::setTagName, SRC_POS);
00145 pkg->def("removeAllSubComponents", "objref",
00146 &ModelComponent::removeAllSubComponents, SRC_POS);
00147 pkg->def("numSubComp", "objref",
00148 &ModelComponent::numSubComp, SRC_POS);
00149 pkg->def("subCompByIndex", "objref index",
00150 (nub::ref<ModelComponent> (ModelComponent::*)(uint) const)
00151 &ModelComponent::subComponent, SRC_POS);
00152 pkg->def("subCompByName", "objref tagname flags",
00153 (nub::ref<ModelComponent> (ModelComponent::*)(const std::string&, int) const)
00154 &ModelComponent::subComponent, SRC_POS);
00155 pkg->def("hasSubComponent", "objref tagname flags",
00156 (bool (ModelComponent::*)(const std::string&, int) const)
00157 &ModelComponent::hasSubComponent, SRC_POS);
00158 pkg->def("printout", "objref",
00159 &printout, SRC_POS);
00160 pkg->def("reset", "objref do_recurse",
00161 &ModelComponent::reset, SRC_POS);
00162
00163 pkg->def("param", "objref paramname",
00164 &getMPString, SRC_POS);
00165
00166 pkg->def("param", "objref paramname paramvalue",
00167 &setMPString, SRC_POS);
00168
00169 GVX_PKG_RETURN(pkg);
00170 }
00171
00172 extern "C"
00173 int Modelmanager_Init(Tcl_Interp* interp)
00174 {
00175 GVX_PKG_CREATE(pkg, interp, "ModelManager", "4.$Revision: 1$");
00176 pkg->inherit_pkg("Modelcomponent");
00177 tcl::def_basic_type_cmds<ModelManager>(pkg, SRC_POS);
00178
00179 theManager.reset(new ModelManager("iLab Neuromorphic Vision Toolkit"));
00180
00181 registerComponentCreator<StdBrain>();
00182
00183 pkg->def("parseCommandLine", "objref argv usage minarg maxarg",
00184 &mmParse, SRC_POS);
00185
00186 pkg->def("extraArgs", "objref", &mmExtraArgs, SRC_POS);
00187
00188 GVX_PKG_RETURN(pkg);
00189 }
00190
00191 extern "C"
00192 int Simmodule_Init(Tcl_Interp* interp)
00193 {
00194 GVX_PKG_CREATE(pkg, interp, "SimModule", "4.$Revision: 1$");
00195 pkg->inherit_pkg("Modelcomponent");
00196 tcl::def_basic_type_cmds<SimModule>(pkg, SRC_POS);
00197
00198 GVX_PKG_RETURN(pkg);
00199 }
00200
00201 extern "C"
00202 int Simeventqueue_Init(Tcl_Interp* interp)
00203 {
00204 GVX_PKG_CREATE(pkg, interp, "SimEventQueue", "4.$Revision: 1$");
00205 pkg->inherit_pkg("Modelcomponent");
00206 tcl::def_basic_type_cmds<SimEventQueue>(pkg, SRC_POS);
00207
00208 registerComponentCreator<SimEventQueue>();
00209
00210 pkg->def("evolveMaster", "objref", &evolveMaster, SRC_POS);
00211
00212
00213
00214 GVX_PKG_RETURN(pkg);
00215 }
00216
00217
00218
00219
00220
00221
00222
00223 #endif // SCRIPT_MODELSCRIPT_C_DEFINED