← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3548: fix save/load QGL camera state via text files

 

------------------------------------------------------------
revno: 3548
committer: Bruno Chareyre <bruno.chareyre@xxxxxxxxxxx>
timestamp: Thu 2014-11-27 10:28:36 +0100
message:
  fix save/load QGL camera state via text files
modified:
  gui/qt4/GLViewer.cpp
  gui/qt4/_GLViewer.cpp


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'gui/qt4/GLViewer.cpp'
--- gui/qt4/GLViewer.cpp	2014-10-15 06:44:01 +0000
+++ gui/qt4/GLViewer.cpp	2014-11-27 09:28:36 +0000
@@ -83,7 +83,7 @@
 	setKeyDescription(Qt::Key_Y,"Show the yx [shift: yz] (up-right) plane (clip plane: align normal with +y)");
 	setKeyDescription(Qt::Key_Z,"Show the zy [shift: zx] (up-right) plane (clip plane: align normal with +z)");
 	setKeyDescription(Qt::Key_Period,"Toggle grid subdivision by 10");
-	setKeyDescription(Qt::Key_S & Qt::AltModifier,"Save QGLViewer state to /tmp/qglviewerState.xml");
+	setKeyDescription(Qt::Key_S,"Save QGLViewer state to /tmp/qglviewerState.xml");
 	setKeyDescription(Qt::Key_T,"Switch orthographic / perspective camera");
 	setKeyDescription(Qt::Key_O,"Set narrower field of view");
 	setKeyDescription(Qt::Key_P,"Set wider field of view");
@@ -136,7 +136,7 @@
 	QString origStateFileName=stateFileName();
 	string tmpFile=Omega::instance().tmpFilename();
 	setStateFileName(QString(tmpFile.c_str())); saveStateToFile(); setStateFileName(origStateFileName);
-	LOG_DEBUG("State saved to temp file "<<tmpFile);
+	LOG_WARN("State saved to temp file "<<tmpFile);
 	// read tmp file contents and return it as string
 	// this will replace all whitespace by space (nowlines will disappear, which is what we want)
 	ifstream in(tmpFile.c_str()); string ret; while(!in.eof()){string ss; in>>ss; ret+=" "+ss;}; in.close();
@@ -149,7 +149,7 @@
 	std::ofstream out(tmpFile.c_str());
 	if(!out.good()){ LOG_ERROR("Error opening temp file `"<<tmpFile<<"', loading aborted."); return; }
 	out<<state; out.close();
-	LOG_DEBUG("Will load state from temp file "<<tmpFile);
+	LOG_WARN("Will load state from temp file "<<tmpFile);
 	QString origStateFileName=stateFileName(); setStateFileName(QString(tmpFile.c_str())); restoreStateFromFile(); setStateFileName(origStateFileName);
 	boost::filesystem::remove(boost::filesystem::path(tmpFile));
 }
@@ -239,6 +239,10 @@
 		LOG_INFO("Saving QGLViewer state to /tmp/qglviewerState.xml");
 		setStateFileName("/tmp/qglviewerState.xml"); saveStateToFile(); setStateFileName(QString::null);
 	}
+	else if(e->key()==Qt::Key_L){
+		LOG_INFO("Loading QGLViewer state from /tmp/qglviewerState.xml");
+		setStateFileName("/tmp/qglviewerState.xml"); restoreStateFromFile(); setStateFileName(QString::null);
+	}
 	else if(e->key()==Qt::Key_X || e->key()==Qt::Key_Y || e->key()==Qt::Key_Z){
 		int axisIdx=(e->key()==Qt::Key_X?0:(e->key()==Qt::Key_Y?1:2));
 		if(manipulatedClipPlane<0){

=== modified file 'gui/qt4/_GLViewer.cpp'
--- gui/qt4/_GLViewer.cpp	2014-10-15 06:44:01 +0000
+++ gui/qt4/_GLViewer.cpp	2014-11-27 09:28:36 +0000
@@ -42,9 +42,12 @@
 		string pyStr(){return string("<GLViewer for view #")+boost::lexical_cast<string>(viewNo)+">";}
 		void saveDisplayParameters(size_t n){GLV;  glv->saveDisplayParameters(n);}
 		void useDisplayParameters(size_t n){GLV;  glv->useDisplayParameters(n);}
+		void loadState(string filename){GLV; QString origStateFileName=glv->stateFileName(); glv->setStateFileName(QString(filename.c_str())); glv->restoreStateFromFile(); glv->saveStateToFile(); glv->setStateFileName(origStateFileName);}
+		void saveState(string filename){GLV;  QString origStateFileName=glv->stateFileName(); glv->setStateFileName(QString(filename.c_str())); glv->saveStateToFile(); glv->setStateFileName(origStateFileName);}
 		string get_timeDisp(){GLV;  const int& m(glv->timeDispMask); string ret; if(m&GLViewer::TIME_REAL) ret+='r'; if(m&GLViewer::TIME_VIRT) ret+="v"; if(m&GLViewer::TIME_ITER) ret+="i"; return ret;}
 		void set_timeDisp(string s){GLV;  int& m(glv->timeDispMask); m=0; FOREACH(char c, s){switch(c){case 'r': m|=GLViewer::TIME_REAL; break; case 'v': m|=GLViewer::TIME_VIRT; break; case 'i': m|=GLViewer::TIME_ITER; break; default: throw invalid_argument(string("Invalid flag for timeDisp: `")+c+"'");}}}
 		void set_bgColor(const Vector3r& c){ QColor cc(255*c[0],255*c[1],255*c[2]); GLV;  glv->setBackgroundColor(cc);} Vector3r get_bgColor(){ GLV;  QColor c(glv->backgroundColor()); return Vector3r(c.red()/255.,c.green()/255.,c.blue()/255.);}
+		void saveSnapshot(string filename) {GLV; glv->nextFrameSnapshotFilename = filename;}
 		#undef GLV
 		#undef VEC_GET_SET
 		#undef BOOL_GET_SET
@@ -93,10 +96,11 @@
 		.def("fitSphere",&pyGLViewer::fitSphere,(py::arg("center"),py::arg("radius")),"Adjust scene bounds so that sphere given by *center* and *radius* fits in.")
 		.def("showEntireScene",&pyGLViewer::showEntireScene)
 		.def("center",&pyGLViewer::center,(py::arg("median")=true),"Center view. View is centered either so that all bodies fit inside (*median* = False), or so that 75\% of bodies fit inside (*median* = True).")
-		.def("saveState",&pyGLViewer::saveDisplayParameters,(py::arg("slot")),"Save display parameters into numbered memory slot. Saves state for both :yref:`GLViewer<yade._qt.GLViewer>` and associated :yref:`OpenGLRenderer`.")
-		.def("loadState",&pyGLViewer::useDisplayParameters,(py::arg("slot")),"Load display parameters from slot saved previously into, identified by its number.")
+		.def("saveState",&pyGLViewer::saveState,(py::arg("stateFilename")=".qglviewer.xml"),"Save display parameters into a file. Saves state for both :yref:`GLViewer<yade._qt.GLViewer>` and associated :yref:`OpenGLRenderer`.")
+		.def("loadState",&pyGLViewer::loadState,(py::arg("stateFilename")=".qglviewer.xml"),"Load display parameters from file saved previously into.")
 		.def("__repr__",&pyGLViewer::pyStr).def("__str__",&pyGLViewer::pyStr)
 		.def("close",&pyGLViewer::close)
+		.def("saveSnapshot",&pyGLViewer::saveSnapshot,(py::arg("filename")),"Save the current view to image file")
 		.add_property("selection",&pyGLViewer::get_selection,&pyGLViewer::set_selection)
 		;
 }