3
#include"SnapshotEngine.hpp"
5
YADE_PLUGIN((SnapshotEngine));
6
CREATE_LOGGER(SnapshotEngine);
8
void SnapshotEngine::action(){
9
if(!OpenGLManager::self) throw logic_error("No OpenGLManager instance?!");
10
if(OpenGLManager::self->views.size()==0){
11
int viewNo=OpenGLManager::self->waitForNewView(deadTimeout);
13
if(!ignoreErrors) throw runtime_error("SnapshotEngine: Timeout waiting for new 3d view.");
15
LOG_WARN("Making myself Engine::dead, as I can not live without a 3d view (timeout)."); dead=true; return;
19
const shared_ptr<GLViewer>& glv=OpenGLManager::self->views[0];
20
ostringstream fss; fss<<fileBase<<setw(5)<<setfill('0')<<counter++<<"."<<boost::algorithm::to_lower_copy(format);
21
LOG_DEBUG("GL view → "<<fss.str())
22
glv->setSnapshotFormat(QString(format.c_str()));
23
glv->nextFrameSnapshotFilename=fss.str();
24
// wait for the renderer to save the frame (will happen at next postDraw)
25
timespec t1,t2; t1.tv_sec=0; t1.tv_nsec=10000000; /* 10 ms */
27
while(!glv->nextFrameSnapshotFilename.empty()){
28
nanosleep(&t1,&t2); waiting++;
29
if(((waiting) % 1000)==0) LOG_WARN("Already waiting "<<waiting/100<<"s for snapshot to be saved. Something went wrong?");
30
if(waiting/100.>deadTimeout){
31
if(ignoreErrors){ LOG_WARN("Timeout waiting for snapshot to be saved, making byself Engine::dead"); dead=true; return; }
32
else throw runtime_error("SnapshotEngine: Timeout waiting for snapshot to be saved.");
35
snapshots.push_back(fss.str());
36
usleep((long)(msecSleep*1000));
37
//if(!plot.empty()){ pyRunString("import yade.plot; yade.plot.addImgData("+plot+"='"+fss.str()+"')"); }
41
#endif /* YADE_OPENGL */