← Back to team overview

yade-dev team mailing list archive

[svn] r1918 - in trunk: gui/py lib/serialization py/yadeWrapper scripts

 

Author: eudoxos
Date: 2009-08-04 19:25:28 +0200 (Tue, 04 Aug 2009)
New Revision: 1918

Modified:
   trunk/gui/py/PythonUI_rc.py
   trunk/lib/serialization/MultiTypeHandler.tpp
   trunk/lib/serialization/Serializable.hpp
   trunk/py/yadeWrapper/yadeWrapper.cpp
   trunk/scripts/default-test.py
Log:
1. Rename Preprocessor in python to FileGenerator, to be consistent with c++. Preprocessor is never used directly, anyway. The old deprecated name put in the deprecation table.
2. Manage crash at exit in defaut-test gracefully
3. Fix serialization of pairs (overlooked replace)



Modified: trunk/gui/py/PythonUI_rc.py
===================================================================
--- trunk/gui/py/PythonUI_rc.py	2009-08-04 13:03:37 UTC (rev 1917)
+++ trunk/gui/py/PythonUI_rc.py	2009-08-04 17:25:28 UTC (rev 1918)
@@ -28,8 +28,6 @@
 _allSerializables=set(listChildClassesRecursive('Serializable'))
 # classes that cannot be instantiated in python directly, and will have no properties generated for them
 _noPropsClasses=set(['InteractionContainer','BodyContainer','EngineUnit','Engine','MetaEngine'])
-# We call some classes differently in python than in c++
-_classTranslations={'FileGenerator':'Preprocessor'}
 # classes that have special wrappers; only the most-bottom ones, with their names as it is in c++
 _pyRootClasses=set([
 	'StandAloneEngine','DeusExMachina','GeometricalModel','InteractingGeometry','PhysicalParameters','BoundingVolume','InteractingGeometry','InteractionPhysics','FileGenerator',
@@ -40,10 +38,9 @@
 
 if 1:
 	# create types for all classes that yade defines: first those deriving from some root classes
-	for root0 in _pyRootClasses:
-		root=root0 if (root0 not in _classTranslations.keys()) else _classTranslations[root0]
+	for root in _pyRootClasses:
 		rootType=yade.wrapper.__dict__[root]
-		for p in listChildClassesRecursive(root0):
+		for p in listChildClassesRecursive(root):
 			_proxyNamespace[p]=type(p,(rootType,),{'__init__': lambda self,__subType_=p,*args,**kw: super(type(self),self).__init__(__subType_,*args,**kw)})
 			_proxiedClasses.add(p)
 	# create types for classes that derive just from Serializable
@@ -52,17 +49,14 @@
 	## NOTE: this will not work if the object is returned from c++; seems to be more confusing than doing any good; disabling for now.
 	if 0:
 		# create class properties for yade serializable attributes, i.e. access object['attribute'] as object.attribute
-		for c0 in _allSerializables-_noPropsClasses:
-			c=c0 if (c0 not in _classTranslations.keys()) else _classTranslations[c0]
+		for c in _allSerializables-_noPropsClasses:
 			cls=eval(c) # ugly: create instance; better lookup some namespace (builtins? globals?)
 			for k in cls().keys(): # must be instantiated so that attributes can be retrieved
 				setattr(cls,k,property(lambda self,__k_=k:self.__getitem__(__k_),lambda self,val,__k_=k:self.__setitem__(__k_,val)))
 else:
 	# old code, can be removed at some point
-	for root0 in _pyRootClasses:
-		root=root0 if (root0 not in _classTranslations.keys()) else _classTranslations[root0]
-		for p in listChildClassesRecursive(root0):
-			if root=='Preprocessor': print root,p
+	for root in _pyRootClasses:
+		for p in listChildClassesRecursive(root):
 			_proxyNamespace[p]=lambda __r_=root,__p_=p,**kw : yade.wrapper.__dict__[__r_](__p_,**kw)
 			_proxiedClasses.add(p)
 	# wrap classes that don't derive from any specific root class, have no proxy and need it
@@ -81,6 +75,8 @@
 	'GLDrawBrefcomContact':'GLDrawCpmPhys',
 	'BrefcomDamageColorizer':'CpmPhysDamageColorizer',
 	'BrefcomGlobalCharacteristics':'CpmGlobalCharacteristics',
+	# renamed back to comply with the c++ name, 4.8.2009
+	'Preprocessor':'FileGenerator'
 }
 
 for oldName in renamed:

Modified: trunk/lib/serialization/MultiTypeHandler.tpp
===================================================================
--- trunk/lib/serialization/MultiTypeHandler.tpp	2009-08-04 13:03:37 UTC (rev 1917)
+++ trunk/lib/serialization/MultiTypeHandler.tpp	2009-08-04 17:25:28 UTC (rev 1918)
@@ -55,7 +55,7 @@
 		REGISTER_ATTRIBUTE_(first);
 		REGISTER_ATTRIBUTE_(second);
 	};
-	public : void deserialize(any& a)
+	public : void yadeDeserialize(any& a)
 	{
 		std::pair< ContainedType1 , ContainedType2 > * multiType
 			= any_cast< std::pair< ContainedType1 , ContainedType2 > * >(a);
@@ -64,7 +64,7 @@
 		multiType->second	= second;
 	};
 
-	public : void serialize(any& a)
+	public : void yadeSerialize(any& a)
 	{
 		std::pair< ContainedType1 , ContainedType2 > * multiType
 			= any_cast< std::pair< ContainedType1 , ContainedType2 > * >(a);
@@ -157,14 +157,14 @@
 	{
 		REGISTER_ATTRIBUTE_(first);
 	};
-	public : void deserialize(any& a)
+	public : void yadeDeserialize(any& a)
 	{
 		boost::tuple< ContainedType1 > * multiType
 			= any_cast< boost::tuple< ContainedType1 > * >(a);
 
 		multiType->get<0>()	= first;
 	};
-	public : void serialize(any& a)
+	public : void yadeSerialize(any& a)
 	{
 		boost::tuple< ContainedType1 > * multiType
 			= any_cast< boost::tuple< ContainedType1 > * >(a);
@@ -252,7 +252,7 @@
 		REGISTER_ATTRIBUTE_(first);
 		REGISTER_ATTRIBUTE_(second);
 	};
-	public : void deserialize(any& a)
+	public : void yadeDeserialize(any& a)
 	{
 		boost::tuple< ContainedType1 , ContainedType2 > * multiType
 			= any_cast< boost::tuple< ContainedType1 , ContainedType2 > * >(a);
@@ -260,7 +260,7 @@
 		multiType->get<0>()	= first;
 		multiType->get<1>()	= second;
 	};
-	public : void serialize(any& a)
+	public : void yadeSerialize(any& a)
 	{
 		boost::tuple< ContainedType1 , ContainedType2 > * multiType
 			= any_cast< boost::tuple< ContainedType1 , ContainedType2 > * >(a);
@@ -355,7 +355,7 @@
 		REGISTER_ATTRIBUTE_(second);
 		REGISTER_ATTRIBUTE_(third);
 	};
-	public : void deserialize(any& a)
+	public : void yadeDeserialize(any& a)
 	{
 		boost::tuple< ContainedType1 , ContainedType2 , ContainedType3 > * multiType
 			= any_cast< boost::tuple< ContainedType1 , ContainedType2 , ContainedType3 > * >(a);
@@ -364,7 +364,7 @@
 		multiType->get<1>()	= second;
 		multiType->get<2>()	= third;
 	};
-	public : void serialize(any& a)
+	public : void yadeSerialize(any& a)
 	{
 		boost::tuple< ContainedType1 , ContainedType2 , ContainedType3 > * multiType
 			= any_cast< boost::tuple< ContainedType1 , ContainedType2 , ContainedType3 > * >(a);
@@ -465,7 +465,7 @@
 		REGISTER_ATTRIBUTE_(third);
 		REGISTER_ATTRIBUTE_(fourth);
 	};								//
-	public : void deserialize(any& a)				//
+	public : void yadeDeserialize(any& a)				//
 	{								//
 		boost::tuple			< ContainedType1 , ContainedType2 , ContainedType3 , ContainedType4 > * multiType
 		= any_cast< boost::tuple	< ContainedType1 , ContainedType2 , ContainedType3 , ContainedType4 > * >(a);
@@ -475,7 +475,7 @@
 		multiType->get<2>()	= third;
 		multiType->get<3>()	= fourth;
 	};								//
-	public : void serialize(any& a)					//
+	public : void yadeSerialize(any& a)					//
 	{								//
 		boost::tuple			< ContainedType1 , ContainedType2 , ContainedType3 , ContainedType4 > * multiType
 		= any_cast< boost::tuple	< ContainedType1 , ContainedType2 , ContainedType3 , ContainedType4 > * >(a);
@@ -583,7 +583,7 @@
 		REGISTER_ATTRIBUTE_(fourth);
 		REGISTER_ATTRIBUTE_(fifth);
 	};								//
-	public : void deserialize(any& a)				//
+	public : void yadeDeserialize(any& a)				//
 	{								//
 		boost::tuple			< ContainedType1 , ContainedType2 , ContainedType3 , ContainedType4 , ContainedType5 > * multiType
 		= any_cast< boost::tuple	< ContainedType1 , ContainedType2 , ContainedType3 , ContainedType4 , ContainedType5 > * >(a);
@@ -594,7 +594,7 @@
 		multiType->get<3>()	= fourth;
 		multiType->get<4>()	= fifth;
 	};								//
-	public : void serialize(any& a)					//
+	public : void yadeSerialize(any& a)					//
 	{								//
 		boost::tuple			< ContainedType1 , ContainedType2 , ContainedType3 , ContainedType4 , ContainedType5 > * multiType
 		= any_cast< boost::tuple	< ContainedType1 , ContainedType2 , ContainedType3 , ContainedType4 , ContainedType5 > * >(a);

Modified: trunk/lib/serialization/Serializable.hpp
===================================================================
--- trunk/lib/serialization/Serializable.hpp	2009-08-04 13:03:37 UTC (rev 1917)
+++ trunk/lib/serialization/Serializable.hpp	2009-08-04 17:25:28 UTC (rev 1918)
@@ -123,8 +123,8 @@
 		bool containsOnlyFundamentals();
 		Archives& getArchives() 	{ return archives; };
 		
-		virtual void yadeSerialize(any& )	{ throw SerializableError(SerializationExceptions::SetFunctionNotDeclared); };
-		virtual void yadeDeserialize(any& ) { throw SerializableError(SerializationExceptions::GetFunctionNotDeclared); };
+		virtual void yadeSerialize(any& a)	{ throw SerializableError((SerializationExceptions::SetFunctionNotDeclared+string(" for type ")+a.type().name()).c_str()); };
+		virtual void yadeDeserialize(any& a) { throw SerializableError((SerializationExceptions::GetFunctionNotDeclared+string(" for type ")+a.type().name()).c_str()); };
 
 		virtual void postProcessAttributes(bool /*deserializing*/) {};
 

Modified: trunk/py/yadeWrapper/yadeWrapper.cpp
===================================================================
--- trunk/py/yadeWrapper/yadeWrapper.cpp	2009-08-04 13:03:37 UTC (rev 1917)
+++ trunk/py/yadeWrapper/yadeWrapper.cpp	2009-08-04 17:25:28 UTC (rev 1918)
@@ -764,7 +764,7 @@
 		.add_property("isReal",&Interaction::isReal);
 	EXPOSE_CXX_CLASS(InteractionPhysics);
 	EXPOSE_CXX_CLASS(InteractionGeometry);
-	EXPOSE_CXX_CLASS_RENAMED(FileGenerator,Preprocessor)
+	EXPOSE_CXX_CLASS(FileGenerator)
 		.def("generate",&FileGenerator_generate)
 		.def("load",&FileGenerator_load);
 }

Modified: trunk/scripts/default-test.py
===================================================================
--- trunk/scripts/default-test.py	2009-08-04 13:03:37 UTC (rev 1917)
+++ trunk/scripts/default-test.py	2009-08-04 17:25:28 UTC (rev 1918)
@@ -28,7 +28,7 @@
 
 runGenerator="""
 #generated file
-Preprocessor('%%s'%%s).generate('%s')
+FileGenerator('%%s'%%s).generate('%s')
 quit()
 """%(simulFile)
 
@@ -44,7 +44,10 @@
 	msg=''
 	if os.path.exists(msgFile): msg=open(msgFile,'r').readlines()[0]
 	if retval==0: return True,msg,pout
-	else: return False,msg,pout
+	else:
+		# handle crash at exit :-(
+		if 'main: Yade: normal exit.' in pout: return True,msg,pout
+		return False,msg,pout
 
 reports=[]
 summary=[]
@@ -58,7 +61,7 @@
 for pp in o.childClasses('FileGenerator'):
 	if pp in broken:
 		summary.append(pp,'skipped (broken)','');
-	params='' if pp not in genParams else (",{"+",".join(["'%s':%s"%(k,repr(genParams[pp][k])) for k in genParams[pp]])+"}")
+	params='' if pp not in genParams else (","+",".join(["%s=%s"%(k,repr(genParams[pp][k])) for k in genParams[pp]]))
 	ok1,msg1,out1=crashProofRun(runGenerator%(pp,params))
 	if not ok1:
 		reports.append([pp,'generator CRASH',out1]); summary.append([pp,'generator CRASH'])