test-ModelManagerQt.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "Component/ModelManager.H"
00007 #include "Qt/ui/ModelManagerControl.h"
00008 #include "Neuro/StdBrain.H"
00009 #include "Neuro/VisualCortexConfigurator.H"
00010 #include "QtUtil/Util.H"
00011 #include "Simulation/SimEventQueueConfigurator.H"
00012 #include "Component/JobServerConfigurator.H"
00013 #include "Media/SimFrameSeries.H"
00014 #include "Neuro/NeuroOpts.H"
00015
00016 #include <qapplication.h>
00017 #include <qthread.h>
00018 #include <unistd.h>
00019
00020 class ModelRun : public QThread {
00021 public:
00022 ModelRun(ModelManager *mgr_, nub::ref<SimEventQueueConfigurator> seqc_, bool *dorun_) :
00023 QThread(), mgr(mgr_), seqc(seqc_), dorun(dorun_)
00024 { }
00025
00026 virtual void run() {
00027 while(true) {
00028
00029 if (*dorun == false) { usleep(50000); continue; }
00030
00031
00032 mgr->start();
00033 nub::ref<SimEventQueue> q = seqc->getQ();
00034
00035
00036 SimStatus status = SIM_CONTINUE;
00037 while (status == SIM_CONTINUE && *dorun == true) status = q->evolve();
00038
00039
00040 LINFO("Simulation terminated.");
00041
00042
00043 mgr->stop();
00044 }
00045 }
00046
00047 private:
00048 ModelManager *mgr;
00049 nub::ref<SimEventQueueConfigurator> seqc;
00050 bool *dorun;
00051 };
00052
00053 int main( int argc, const char ** argv )
00054 {
00055
00056 ModelManager mgr( "model manager" );
00057
00058
00059 nub::ref<JobServerConfigurator> jsc(new JobServerConfigurator(mgr));
00060 mgr.addSubComponent(jsc);
00061
00062 nub::ref<SimEventQueueConfigurator> seqc(new SimEventQueueConfigurator(mgr));
00063 mgr.addSubComponent(seqc);
00064
00065
00066
00067
00068
00069 nub::ref<SimOutputFrameSeries> ofs(new SimOutputFrameSeries(mgr));
00070 mgr.addSubComponent(ofs);
00071
00072 nub::ref<SimInputFrameSeries> ifs(new SimInputFrameSeries(mgr));
00073 mgr.addSubComponent(ifs);
00074
00075 nub::ref<StdBrain> brain(new StdBrain(mgr));
00076 mgr.addSubComponent(brain);
00077
00078
00079 REQUEST_OPTIONALIAS_NEURO(mgr);
00080
00081
00082 if (mgr.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00083
00084
00085
00086 bool dorun = false;
00087 ModelRun mr(&mgr, seqc, &dorun);
00088 mr.start();
00089
00090
00091 QApplication a( argc, argv2qt( argc, argv ) );
00092 ModelManagerControl mmc;
00093 mmc.init( mgr, &dorun );
00094 mmc.show();
00095 a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
00096 a.exec();
00097
00098 return 0;
00099 }