← Back to team overview

yade-dev team mailing list archive

simulation file option and debugging macros

 

Patch for passing simulation filename from command-line directly (-S filename option), that works with QtGUI only ATM; and handy debugging macros. It is all temporary, so no overly strict criteria, please ;-)

Vaclav
Index: yade-guis/yade-gui-qt/src/QtGUI/SimulationController.cpp
===================================================================
--- yade-guis/yade-gui-qt/src/QtGUI/SimulationController.cpp	(revision 1016)
+++ yade-guis/yade-gui-qt/src/QtGUI/SimulationController.cpp	(working copy)
@@ -81,6 +81,20 @@
 	addNewView();
 
 	updater = shared_ptr<SimulationControllerUpdater>(new SimulationControllerUpdater(this));
+
+	// HACK: this should be passed through the bazillion of abstract interfaces to the the most abstract idea,
+	// of which Plato speaks in the Republic and elsewhere, then descending from this perfectly one beyond being
+	// though the cascades of emanations here, where it incarnates. Unfortunately, there is no heaven in c++, because
+	// c++ itself is hell.
+	//
+	// Actually, it is quite useful, since it allows me to pass simulation to yade from command line,
+	// thus saving at least 4 mouse-clicks
+	//
+	// there is file existence assertion in lodSimulationFromFilename, so yade will abort cleanly...
+	cerr<<"Omega::instance().getSimulationFileName()="<<Omega::instance().getSimulationFileName()<<endl;
+	if (Omega::instance().getSimulationFileName()!=""){
+		loadSimulationFromFileName(Omega::instance().getSimulationFileName());
+	}
 }
 
 
@@ -135,6 +149,14 @@
 		&& filesystem::exists(fileName) 
 		&& (filesystem::extension(fileName)==".xml" || filesystem::extension(fileName)==".yade"))
 	{
+		this->loadSimulationFromFileName(fileName);
+	}
+}
+
+
+void SimulationController::loadSimulationFromFileName(const std::string& fileName){
+	assert(filesystem::exists(fileName));
+
 //		updater->stop();
 		Omega::instance().finishSimulationLoop();
 		Omega::instance().joinSimulationLoop();
@@ -188,8 +210,7 @@
 		}
 
 		pbCenterSceneClicked();
-        }
-} 
+}
 
 void SimulationController::pbSaveClicked()
 {
Index: yade-guis/yade-gui-qt/src/QtGUI/SimulationController.hpp
===================================================================
--- yade-guis/yade-gui-qt/src/QtGUI/SimulationController.hpp	(revision 1016)
+++ yade-guis/yade-gui-qt/src/QtGUI/SimulationController.hpp	(working copy)
@@ -38,6 +38,7 @@
 		QFrame * scrollViewFrame;
 		QVBoxLayout* scrollViewLayout;
 		void addNewView();
+		void loadSimulationFromFileName(const std::string& fileName);
 	
 	public : 
 		bool	 changeSkipTimeStepper
Index: yade-guis/yade-gui-qt/src/QtGUI/YadeQtMainWindow.cpp
===================================================================
--- yade-guis/yade-gui-qt/src/QtGUI/YadeQtMainWindow.cpp	(revision 1016)
+++ yade-guis/yade-gui-qt/src/QtGUI/YadeQtMainWindow.cpp	(working copy)
@@ -86,6 +86,9 @@
 	setCentralWidget( vbox );
 	
 	simulationController = 0;
+	
+	// HACK
+	if(Omega::instance().getSimulationFileName()!="") fileNewSimulation();
 }
 
 
Index: yade-core/src/yade/Omega.hpp
===================================================================
--- yade-core/src/yade/Omega.hpp	(revision 1016)
+++ yade-core/src/yade/Omega.hpp	(working copy)
@@ -25,6 +25,28 @@
 
 #include "SimulationFlow.hpp"
 
+
+
+// these macros are temporary
+#define TRACE cerr<<__FILE__<<":"<<__LINE__<<":"<<__FUNCTION__<<"\n"
+#define _TRVHEAD cerr<<__FILE__<<":"<<__LINE__<<":"<<__FUNCTION__<<": "
+#define _TRV(x) <<#x"="<<x<<"; "
+#define _TRVTAIL "\n"
+#define TRVAR1(a) _TRVHEAD _TRV(a) _TRVTAIL
+#define TRVAR2(a,b) _TRVHEAD _TRV(a) _TRV(b) _TRVTAIL
+#define TRVAR3(a,b,c) _TRVHEAD _TRV(a) _TRV(b) _TRV(c) _TRVTAIL
+#define TRVAR4(a,b,c,d) _TRVHEAD _TRV(a) _TRV(b) _TRV(c) _TRV(d) _TRVTAIL
+#define TRVAR5(a,b,c,d,e) _TRVHEAD _TRV(a) _TRV(b) _TRV(c) _TRV(d) _TRV(e) _TRVTAIL
+// prints boost matrix
+#define TRMAT(MAT) _TRVHEAD<< #MAT "=(";for(unsigned i=0; i<MAT.size1(); i++){cerr<<"(";for(unsigned j=0; j<MAT.size2(); j++){ cerr<<MAT(i,j)<<" "; } cerr<<")"; } cerr<<")"; cerr<<_TRVTAIL
+// dtto, but for matrix of vectors; maybe the previos macro could handle that also.
+#define TRMATVEC(MAT) _TRVHEAD<< #MAT "=(";for(unsigned i=0; i<MAT.size1(); i++){cerr<<"(";for(unsigned j=0; j<MAT.size2(); j++){ cerr<<"["<<static_cast<Vector3r>(MAT(i,j))<<"]"; } cerr<<")"; } cerr<<")"; cerr<<_TRVTAIL
+// show Matrix3 from the wm3 library
+#define TRWM3MAT(_M)	_TRVHEAD<< #_M "=(("<<_M(0,0)<<" "<<_M(0,1)<<" "<<_M(0,2)<<")("<<_M(1,0)<<" "<<_M(1,1)<<" "<<_M(1,2)<<")("<<_M(2,0)<<" "<<_M(2,1)<<" "<<_M(2,2)<<"))"<<_TRVTAIL
+
+
+
+
 class MetaBody;
 class ThreadRunner;
 class Preferences;
Index: yade-core/src/yade/yade.cpp
===================================================================
--- yade-core/src/yade/yade.cpp	(revision 1016)
+++ yade-core/src/yade/yade.cpp	(working copy)
@@ -92,6 +92,7 @@
 	-w	: launch the 'first run configuration'\n\
 	-c	: use local directory ./ as configuration directory\n\
 	-C path : configuration directory different than default ~/.yade/\n\
+	-S file : load simulation from file (works with QtGUI only)\n\
 \n\
 Only one option can be passed to yade, all other options are passed to the selected GUI\n\
 ";
@@ -106,9 +107,10 @@
 	int ch;
 	string  gui             = "";
 	string 	configPath 	= string(getenv("HOME")) + string("/.yade");
+	string simulationFileName="";
 	
 	bool 	setup 		= false;
-	if( ( ch = getopt(argc,argv,"hnN:wC:c") ) != -1)
+	if( ( ch = getopt(argc,argv,"hnN:wC:cS:") ) != -1)
 		switch(ch)
 		{
 			case 'h' :	printHelp();		return 1;
@@ -117,6 +119,7 @@
 			case 'w' :	setup = true;		break;
 			case 'C' :	configPath = optarg; 	break;
 			case 'c' :	configPath = "."; 	break;
+			case 'S' : simulationFileName=optarg; break;
 			default	 :	printHelp();		return 1;
 		}
 	
@@ -140,6 +143,8 @@
 	Omega::instance().scanPlugins();
 	cout << "Plugins loaded.\n";
 	Omega::instance().init();
+
+	Omega::instance().setSimulationFileName(simulationFileName); //init() resets to "";
 	
 	if( gui.size()==0)
 		gui = Omega::instance().preferences->defaultGUILibName;
Index: yade-core/src/yade/Omega.cpp
===================================================================
--- yade-core/src/yade/Omega.cpp	(revision 1016)
+++ yade-core/src/yade/Omega.cpp	(working copy)
@@ -25,7 +25,7 @@
 
 Omega::Omega()
 {
-	std::cerr << "Constructing Omega  (if multiple times - check '-rdynamic' flag!)";
+	std::cerr << "Constructing Omega  (if multiple times - check '-rdynamic' flag!)\n";
 }
 
 
Index: Makefile
===================================================================
--- Makefile	(revision 1016)
+++ Makefile	(working copy)
@@ -37,5 +37,5 @@
 	$(MAKE) -C yade-extra uninstall
 
 tags:
-	ctags -R --language-force=c++ --extra=+q --exclude=.svn
+	ctags -R --language-force=c++ --extra=+q --exclude=.svn --exclude=yade-flat
 
_______________________________________________
yade-dev mailing list
yade-dev@xxxxxxxxxxxxxxxx
https://lists.berlios.de/mailman/listinfo/yade-dev