yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #05362
[Branch ~yade-dev/yade/trunk] Rev 2366: 1. Make static attributes documented (xrefs still not working, though)
------------------------------------------------------------
revno: 2366
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Wed 2010-07-14 21:13:18 +0200
message:
1. Make static attributes documented (xrefs still not working, though)
2. Add section on the Material-State association to the Programmer's manual
3. Fix syntax error in qt4-attributes.py
modified:
core/main/main.py.in
doc/sphinx/conf.py
doc/sphinx/prog.rst
doc/sphinx/yadeSphinx.py
lib/serialization/Serializable.hpp
scripts/test/qt4-attributes.py
--
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/main/main.py.in'
--- core/main/main.py.in 2010-07-13 19:58:14 +0000
+++ core/main/main.py.in 2010-07-14 19:13:18 +0000
@@ -77,9 +77,9 @@
# run servers
yade.system.runServers()
+qtEnabled=False
if not 'noqt3' in features:
# open GUI if possible
- qtEnabled=False
if not opts.nogui:
try:
import yade.qt
=== modified file 'doc/sphinx/conf.py'
--- doc/sphinx/conf.py 2010-07-13 19:58:14 +0000
+++ doc/sphinx/conf.py 2010-07-14 19:13:18 +0000
@@ -42,6 +42,7 @@
else: raise RuntimeError("Must have either 'latex' or 'html' on the command line (hack for reference styles)")
+
def yaderef_role(role,rawtext,text,lineno,inliner,options={},content=[]):
"Handle the :yref:`` role, by making hyperlink to yade.wrapper.*. It supports :yref:`Link text<link target>` syntax, like usual hyperlinking roles."
id=rawtext.split(':',2)[2][1:-1]
@@ -287,6 +288,21 @@
#return None,None
+from sphinx import addnodes
+def parse_ystaticattr(env,attr,attrnode):
+ m=re.match(r'([a-zA-Z0-9_]+)\.(.*)\(=(.*)\)',attr)
+ if not m:
+ print 100*'@'+' Static attribute %s not matched'%attr
+ attrnode+=addnodes.desc_name(attr,attr)
+ klass,name,default=m.groups()
+ #attrnode+=addnodes.desc_type('static','static')
+ attrnode+=addnodes.desc_name(name,name)
+ plist=addnodes.desc_parameterlist()
+ if default=='': default='unspecified'
+ plist+=addnodes.desc_parameter('='+default,'='+default)
+ attrnode+=plist
+ attrnode+=addnodes.desc_annotation(' [static]',' [static]')
+ return klass+'.'+name
#############################
## set tab size
@@ -305,6 +321,7 @@
app.connect('autodoc-skip-member',customExclude)
app.connect('autodoc-process-signature',fixSignature)
app.connect('autodoc-process-docstring',fixDocstring)
+ app.add_description_unit('ystaticattr',None,objname='static attribute',indextemplate='pair: %s; static method',parse_node=parse_ystaticattr)
import sys, os
=== modified file 'doc/sphinx/prog.rst'
--- doc/sphinx/prog.rst 2010-07-12 09:11:16 +0000
+++ doc/sphinx/prog.rst 2010-07-14 19:13:18 +0000
@@ -1632,6 +1632,29 @@
Interactions may still be created explicitly with :yref:`yade.utils.createInteraction`, without any spatial requirements. This function searches current engines for dispatchers and uses them. :yref:`InteractionGeometryFunctor` is called with the ``force`` parameter, obliging it to return ``true`` even if there is no spatial overlap.
+Associating Material and State types
+------------------------------------
+
+Some models keep extra :yref:`state<State>` information in the :yref:`Body.state` object, therefore requiring strict association of a :yref:`Material` with a certain :yref:`State` (for instance, :yref:`CpmMat` is associated to :yref:`CpmState` and this combination is supposed by engines such as :yref:`CpmStateUpdater`).
+
+If a :yref:`Material` has such a requirement, it must override 2 virtual methods:
+
+#. :yref:`Material.newAssocState`, which returns a new :yref:`State` object of the corresponding type. The default implementation returns :yref:`State` itself.
+#. :yref:`Material.stateTypeOk`, which checks whether a given :yref:`State` object is of the corresponding type (this check is run at the beginning of the simulation for all particles).
+
+In c++, the code looks like this (for :yref:`CpmMat`):
+
+.. code-block:: c++
+
+ class CpmMat: public FrictMat {
+ public:
+ virtual shared_ptr<State> newAssocState() const { return shared_ptr<State>(new CpmState); }
+ virtual bool stateTypeOk(State* s) const { return (bool)dynamic_cast<CpmState*>(s); }
+ /* ... */
+ };
+
+This allows to construct :yref:`Body` objects from functions such as :yref:`yade.utils.sphere` only by knowing the requires :yref:`Material` type, enforcing the expectation of the model implementor.
+
Runtime structure
==================
=== modified file 'doc/sphinx/yadeSphinx.py'
--- doc/sphinx/yadeSphinx.py 2010-07-13 19:58:14 +0000
+++ doc/sphinx/yadeSphinx.py 2010-07-14 19:13:18 +0000
@@ -131,7 +131,7 @@
sect('Constitutive laws','',['LawFunctor','LawDispatcher'])+
sect('Callbacks','',['BodyCallback','IntrCallback'])+
sect('Preprocessors','',['FileGenerator'])+
- sect('Rendering','',['OpenGLRenderingEngine','GlShapeFunctor','GlStateFunctor','GlBoundFunctor','GlInteractionGeometryFunctor','GlInteractionPhysicsFunctor']), # ,'GlShapeDispatcher','GlStateDispatcher','GlBoundDispatcher','GlInteractionGeometryDispatcher','GlInteractionPhysicsDispatcher'])+
+ sect('Rendering','',['OpenGLRenderingEngine','GlShapeFunctor','GlStateFunctor','GlBoundFunctor','GlInteractionGeometryFunctor','GlInteractionPhysicsFunctor'])+ # ,'GlShapeDispatcher','GlStateDispatcher','GlBoundDispatcher','GlInteractionGeometryDispatcher','GlInteractionPhysicsDispatcher'])+
sect('Simulation data','',['Omega','BodyContainer','InteractionContainer','ForceContainer','MaterialContainer'])
+"""
Other classes
=== modified file 'lib/serialization/Serializable.hpp'
--- lib/serialization/Serializable.hpp 2010-07-13 19:58:14 +0000
+++ lib/serialization/Serializable.hpp 2010-07-14 19:13:18 +0000
@@ -196,11 +196,12 @@
thisClass() BOOST_PP_IF(BOOST_PP_SEQ_SIZE(inits attrDecls),:,) BOOST_PP_SEQ_FOR_EACH_I(_ATTR_INI,BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(inits attrDecls)), inits BOOST_PP_SEQ_FOR_EACH(_DECLINI4,~,attrDecls)) { ctor ; } /* ctor, with initialization of defaults */ \
_YADE_CLASS_BASE_DOC_ATTRS_DEPREC_PY(thisClass,baseClass,docString,BOOST_PP_SEQ_FOR_EACH(_STRIPDECL4,~,attrDecls),deprec,extras)
-#define _STAT_NONSTAT_ATTR_PY(thisClass,attr,doc) /* _DEF_READWRITE_CUSTOM_STATIC(thisClass,attr,doc) */ _DEF_READWRITE_CUSTOM(thisClass,attr,doc) /* duplicate static and non-static attributes do not work (they apparently trigger to-python converter being added; for now, make then non-static, that's it. */
+#define _STAT_NONSTAT_ATTR_PY(thisClass,attr,doc) _DEF_READWRITE_CUSTOM_STATIC(thisClass,attr,doc) /* _DEF_READWRITE_CUSTOM(thisClass,attr,doc) */ /* duplicate static and non-static attributes do not work (they apparently trigger to-python converter being added; for now, make then non-static, that's it. */
#define _STATATTR_PY(x,thisClass,z) _STAT_NONSTAT_ATTR_PY(thisClass,BOOST_PP_TUPLE_ELEM(4,1,z),/*docstring*/ "|ystatic| :ydefault:`" BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(4,2,z)) "` :yattrtype:`" BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(4,0,z)) "` " BOOST_PP_TUPLE_ELEM(4,3,z))
#define _STATATTR_DECL(x,y,z) static BOOST_PP_TUPLE_ELEM(4,0,z) BOOST_PP_TUPLE_ELEM(4,1,z);
#define _STRIP_TYPE_DEFAULT_DOC(x,y,z) (BOOST_PP_TUPLE_ELEM(4,1,z))
#define _STATATTR_SET(x,thisClass,z) thisClass::BOOST_PP_TUPLE_ELEM(4,1,z)=BOOST_PP_TUPLE_ELEM(4,2,z);
+#define _STATATTR_DOC(x,thisClass,z) ".. ystaticattr:: " BOOST_PP_STRINGIZE(thisClass) "." BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(4,1,z)) "(=" BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(4,2,z)) ")" "\n\n\t" BOOST_PP_TUPLE_ELEM(4,3,z) "\n\n"
#define YADE_CLASS_BASE_DOC_STATICATTRS(thisClass,baseClass,docString,attrs)\
public: BOOST_PP_SEQ_FOR_EACH(_STATATTR_DECL,~,attrs) /* attribute declarations */ \
@@ -210,7 +211,7 @@
/* called only at class registration, to set initial values; storage still has to be alocated in the cpp file! */ \
void initSetStaticAttributesValue(void){ BOOST_PP_SEQ_FOR_EACH(_STATATTR_SET,thisClass,attrs); } \
virtual void pyRegisterClass(python::object _scope) { if(!checkPyClassRegistersItself(#thisClass)) return; initSetStaticAttributesValue(); boost::python::scope thisScope(_scope); YADE_SET_DOCSTRING_OPTS; \
- boost::python::class_<thisClass,shared_ptr<thisClass>,boost::python::bases<baseClass>,boost::noncopyable> _classObj(#thisClass,docString); _classObj.def("__init__",python::raw_constructor(Serializable_ctor_kwAttrs<thisClass>)); \
+ boost::python::class_<thisClass,shared_ptr<thisClass>,boost::python::bases<baseClass>,boost::noncopyable> _classObj(#thisClass,docString "\n\n" BOOST_PP_SEQ_FOR_EACH(_STATATTR_DOC,thisClass,attrs) ); _classObj.def("__init__",python::raw_constructor(Serializable_ctor_kwAttrs<thisClass>)); \
BOOST_PP_SEQ_FOR_EACH(_STATATTR_PY,thisClass,attrs); \
}
=== modified file 'scripts/test/qt4-attributes.py'
--- scripts/test/qt4-attributes.py 2010-07-13 19:58:14 +0000
+++ scripts/test/qt4-attributes.py 2010-07-14 19:13:18 +0000
@@ -4,7 +4,7 @@
import re
import logging
-logging.basicConfig(level=logging.DEBUG)
+logging.basicConfig(level=logging.INFO)
from logging import debug,info,warning,error
class SerializableData(QWidget):
@@ -20,7 +20,6 @@
QWidget.__init__(self,parent)
self.ser=ser
self.entries=[]
- print self.ser
debug('New Serializable of type %s'%ser.__class__.__name__)
self.setWindowTitle(str(ser))
self.mkWidgets()
@@ -89,7 +88,7 @@
for i in range(3):
subw=QLineEdit('')
subw.setText(str(vec[i]))
- subw.setSizePolicy(QSizePolicy().setHorizontalPolicy(
+ #subw.setSizePolicy(QSizePolicy().setHorizontalPolicy(
class updateVec:
"bind local args... ugly"
def __init__(self,i,ser,name,subw): self.i,self.ser,self.name,self.subw=i,ser,name,subw