← Back to team overview

yade-users team mailing list archive

Re: [Question #265275]: Inheritance of State Class - add variables

 

Question #265275 on Yade changed:
https://answers.launchpad.net/yade/+question/265275

    Status: Answered => Open

Pawel is still having a problem:
Hi
Thank you for your answers.
I created a class named MyState as:

class MyState: public State{
public:

YADE_CLASS_BASE_DOC_ATTRS(MyState,State,"MyState of a body.",
((bool,isSet,false,,"my isSet"))
        );
REGISTER_CLASS_INDEX(MYState,State);
};
REGISTER_SERIALIZABLE(MyState);

Next i made changes to utils.py by add a new MySphere


def
MYsphere(center,radius,dynamic=None,fixed=False,wire=False,color=None,highlight=False,material=-1,mask=1):
b=Body()
b.state = MYState()
b.shape=Sphere(radius=radius,color=color if color else
randomColor(),wire=wire,highlight=highlight)
V=(4./3)*math.pi*radius**3
geomInert=(2./5.)*V*radius**2
_commonBodySetup(b,V,Vector3(geomInert,geomInert,geomInert),material,pos=center,dynamic=dynamic,fixed=fixed)
b.aspherical=False
b.mask=mask
return b

And there is an error ;(
Traceback (most recent call last):
  File "./install/bin/yade-1.09.0", line 178, in runScript
    execfile(script,globals())
  File "myscript.py", line 87, in <module>

O.bodies.append([utils.MYsphere(k*Vz,r,material=green[0],color=green[1])])
......

NameError: global name 'MYState' is not defined

All c++ code compiles without errors.


2015-04-15 23:16 GMT+02:00 Bruno Chareyre <
question265275@xxxxxxxxxxxxxxxxxxxxx>:

> Your question #265275 on Yade changed:
> https://answers.launchpad.net/yade/+question/265275
>
> Bruno Chareyre proposed the following answer:
> Hi,
> You can use conventional C++ inheritance and add the new variables with
> the YADE_CLASS macro:
>
> class MyState: State
> {
>    YADE_CLASS(...
>       ((int, myNewVariable,...))
> }
>
> A python code generating a body with this new State  would read:
>
> b=Body()
> b.state=MyState()
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/yade/+question/265275/+confirm?answer_id=1
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/yade/+question/265275
>
> You received this question notification because you asked the question.
>


-- 
*Paweł Chodkiewicz*


*Instytut Podstaw Budowy Maszyn*
*Wydział Samochodów i Maszyn Roboczych*

Politechnika Warszawska
ul. Narbutta 84
02-524 Warszawa


*tel. 603 303 134*
*pawel@xxxxxxxxxxxxxxxxxx <pawel@xxxxxxxxxxxxxxxxxx>*

You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.


Follow ups