← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 3022: Omaga can contain more Scene instances

 

------------------------------------------------------------
revno: 3022
committer: Jan Stransky <_honzik@xxxxxxxxxx>
branch nick: yade
timestamp: Mon 2012-02-13 11:36:56 +0100
message:
  Omaga can contain more Scene instances
modified:
  core/Omega.cpp
  core/Omega.hpp
  py/wrapper/yadeWrapper.cpp


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

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription
=== modified file 'core/Omega.cpp'
--- core/Omega.cpp	2010-12-09 12:38:42 +0000
+++ core/Omega.cpp	2012-02-13 10:36:56 +0000
@@ -48,8 +48,28 @@
 
 const map<string,DynlibDescriptor>& Omega::getDynlibsDescriptor(){return dynlibs;}
 
-const shared_ptr<Scene>& Omega::getScene(){return scene;}
-void Omega::resetScene(){ RenderMutexLock lock; scene = shared_ptr<Scene>(new Scene);}
+const shared_ptr<Scene>& Omega::getScene(){return scenes.at(currentSceneNb);}
+void Omega::resetCurrentScene(){ RenderMutexLock lock; scenes.at(currentSceneNb) = shared_ptr<Scene>(new Scene);}
+void Omega::resetScene(){ resetCurrentScene(); }//RenderMutexLock lock; scene = shared_ptr<Scene>(new Scene);}
+void Omega::resetAllScenes(){
+	RenderMutexLock lock;
+	scenes.resize(1);
+	scenes[0] = shared_ptr<Scene>(new Scene);
+	currentSceneNb=0;
+}
+int Omega::addScene(){
+	scenes.push_back(shared_ptr<Scene>(new Scene));
+	return scenes.size()-1;
+}
+void Omega::switchToScene(unsigned int i) {
+	if (i<0 || i>=scenes.size()) {
+		LOG_ERROR("Scene "<<i<<" has not been created yet, no switch.");
+		return;
+	}
+	currentSceneNb=i;
+}
+
+
 
 Real Omega::getRealTime(){ return (microsec_clock::local_time()-startupLocalTime).total_milliseconds()/1e3; }
 time_duration Omega::getRealTime_duration(){return microsec_clock::local_time()-startupLocalTime;}
@@ -79,7 +99,8 @@
 
 void Omega::init(){
 	sceneFile="";
-	resetScene();
+	//resetScene();
+	resetAllScenes();
 	sceneAnother=shared_ptr<Scene>(new Scene);
 	timeInit();
 	createSimulationLoop();
@@ -220,6 +241,9 @@
 	if(isMem && memSavedSimulations.count(f)==0) throw runtime_error("Cannot load nonexistent memory-saved simulation "+f);
 	
 	if(!quiet) LOG_INFO("Loading file "+f);
+	//shared_ptr<Scene> scene = getScene();
+	shared_ptr<Scene>& scene = scenes[currentSceneNb];
+	//shared_ptr<Scene>& scene = getScene();
 	{
 		stop(); // stop current simulation if running
 		resetScene();
@@ -242,6 +266,9 @@
 void Omega::saveSimulation(const string& f, bool quiet){
 	if(f.size()==0) throw runtime_error("f of file to save has zero length.");
 	if(!quiet) LOG_INFO("Saving file " << f);
+	//shared_ptr<Scene> scene = getScene();
+	shared_ptr<Scene>& scene = scenes[currentSceneNb];
+	//shared_ptr<Scene>& scene = getScene();
 	if(algorithm::starts_with(f,":memory:")){
 		if(memSavedSimulations.count(f)>0 && !quiet) LOG_INFO("Overwriting in-memory saved simulation "<<f);
 		ostringstream oss;

=== modified file 'core/Omega.hpp'
--- core/Omega.hpp	2010-12-09 12:38:42 +0000
+++ core/Omega.hpp	2012-02-13 10:36:56 +0000
@@ -63,7 +63,8 @@
 	map<string,DynlibDescriptor> dynlibs; // FIXME : should store that in ClassFactory ?
 	void buildDynlibDatabase(const vector<string>& dynlibsList); // FIXME - maybe in ClassFactory ?
 	
-	shared_ptr<Scene> scene;
+	vector<shared_ptr<Scene> > scenes;
+	unsigned int currentSceneNb;
 	shared_ptr<Scene> sceneAnother; // used for temporarily running different simulation, in Omega().switchscene()
 
 	ptime startupLocalTime;
@@ -109,7 +110,11 @@
 		void saveSimulation(const string& name, bool quiet=false);
 
 		void resetScene();
+		void resetCurrentScene();
+		void resetAllScenes();
 		const shared_ptr<Scene>& getScene();
+		int addScene();
+		void switchToScene(int i);
 		//! Return unique temporary filename. May be deleted by the user; if not, will be deleted at shutdown.
 		string tmpFilename();
 		Real getRealTime();

=== modified file 'py/wrapper/yadeWrapper.cpp'
--- py/wrapper/yadeWrapper.cpp	2011-12-19 17:02:15 +0000
+++ py/wrapper/yadeWrapper.cpp	2012-02-13 10:36:56 +0000
@@ -397,10 +397,14 @@
 	}
 
 	void reset(){Py_BEGIN_ALLOW_THREADS; OMEGA.reset(); Py_END_ALLOW_THREADS; }
-	void resetThisScene(){Py_BEGIN_ALLOW_THREADS; OMEGA.stop(); Py_END_ALLOW_THREADS; OMEGA.resetScene(); OMEGA.createSimulationLoop();}
+	void resetThisScene(){Py_BEGIN_ALLOW_THREADS; OMEGA.stop(); Py_END_ALLOW_THREADS; OMEGA.resetCurrentScene(); OMEGA.createSimulationLoop();}
+	void resetCurrentScene(){Py_BEGIN_ALLOW_THREADS; OMEGA.stop(); Py_END_ALLOW_THREADS; OMEGA.resetCurrentScene(); OMEGA.createSimulationLoop();}
 	void resetTime(){ OMEGA.getScene()->iter=0; OMEGA.getScene()->time=0; OMEGA.timeInit(); }
-	void switchScene(){ std::swap(OMEGA.scene,OMEGA.sceneAnother); }
+	void switchScene(){ std::swap(OMEGA.scenes[OMEGA.currentSceneNb],OMEGA.sceneAnother); }
+	void resetAllScenes(){Py_BEGIN_ALLOW_THREADS; OMEGA.stop(); Py_END_ALLOW_THREADS; OMEGA.resetAllScenes(); OMEGA.createSimulationLoop();}
 	shared_ptr<Scene> scene_get(){ return OMEGA.getScene(); }
+	int addScene(){return OMEGA.addScene();}
+	void switchToScene(int i){OMEGA.switchToScene(i);}
 
 	void save(std::string fileName,bool quiet=false){
 		assertScene();
@@ -548,8 +552,12 @@
 		.def("wait",&pyOmega::wait,"Don't return until the simulation will have been paused. (Returns immediately if not running).")
 		.add_property("running",&pyOmega::isRunning,"Whether background thread is currently running a simulation.")
 		.add_property("filename",&pyOmega::get_filename,"Filename under which the current simulation was saved (None if never saved).")
-		.def("reset",&pyOmega::reset,"Reset simulations completely (including another scene!).")
+		.def("reset",&pyOmega::reset,"Reset simulations completely (including another scenes!).")
 		.def("resetThisScene",&pyOmega::resetThisScene,"Reset current scene.")
+		.def("resetCurrentScene",&pyOmega::resetCurrentScene,"Reset current scene.")
+		.def("resetAllScenes",&pyOmega::resetAllScenes,"Reset all scenes.")
+		.def("addScene",&pyOmega::addScene,"Add new scene to Omega, returns its number")
+		.def("switchToScene",&pyOmega::switchToScene,"Switch to defined scene. Default scene has number 0, other scenes have to be created by addScene method.")
 		.def("switchScene",&pyOmega::switchScene,"Switch to alternative simulation (while keeping the old one). Calling the function again switches back to the first one. Note that most variables from the first simulation will still refer to the first simulation even after the switch\n(e.g. b=O.bodies[4]; O.switchScene(); [b still refers to the body in the first simulation here])")
 		.def("labeledEngine",&pyOmega::labeled_engine_get,"Return instance of engine/functor with the given label. This function shouldn't be called by the user directly; every ehange in O.engines will assign respective global python variables according to labels.\n\nFor example::\n\tO.engines=[InsertionSortCollider(label='collider')]\n\tcollider.nBins=5 ## collider has become a variable after assignment to O.engines automatically)")
 		.def("resetTime",&pyOmega::resetTime,"Reset simulation time: step number, virtual and real time. (Doesn't touch anything else, including timings).")