@@ -112,9 +112,13 @@ std::unique_ptr<DataContainerContext> writeableArray(BaseData* self)
112112 return nullptr ;
113113}
114114
115- void __setattr__ (py::object self, const std::string& s, py::object value)
115+ py::object getValue (py::object self)
116+ {
117+ return PythonFactory::valueToPython_ro (py::cast<BaseData*>(self));
118+ }
119+
120+ void setValue (py::object self, py::object value)
116121{
117- SOFA_UNUSED (s);
118122 BaseData* selfdata = py::cast<BaseData*>(self);
119123
120124 if (py::isinstance<DataContainer>(value))
@@ -132,14 +136,20 @@ void __setattr__(py::object self, const std::string& s, py::object value)
132136 BindingBase::SetAttr (py::cast (selfdata->getOwner ()),selfdata->getName (),value);
133137}
134138
139+ void __setattr__ (py::object self, const std::string& s, py::object value)
140+ {
141+ SOFA_UNUSED (s);
142+ setValue (self, value);
143+ }
144+
135145py::object __getattr__ (py::object self, const std::string& s)
136146{
137147 // / If this is data.value we returns the content value of the data field converted into
138148 // / a python object that is easy to manipulate. The conversion is done with the toPython
139149 // / function.
140150 if (s == " value" )
141151 {
142- return PythonFactory::valueToPython_ro (py::cast<BaseData*>( self) );
152+ return getValue ( self);
143153 }
144154
145155 if (s == " linkpath" )
@@ -150,6 +160,8 @@ py::object __getattr__(py::object self, const std::string& s)
150160 throw py::attribute_error (" There is no attribute '" +s+" '" );
151161}
152162
163+
164+
153165void setParent (BaseData* self, BaseData* parent)
154166{
155167 self->setParent (parent);
@@ -211,6 +223,8 @@ void moduleAddBaseData(py::module& m)
211223 data.def (" getName" , [](BaseData& b){ return b.getName (); }, sofapython3::doc::baseData::getName);
212224 data.def (" setName" , [](BaseData& b, const std::string& s){ b.setName (s); }, sofapython3::doc::baseData::setName);
213225 data.def (" getCounter" , [](BaseData& self) { return self.getCounter (); }, sofapython3::doc::baseData::getCounter);
226+ data.def (" setValue" , setValue);
227+ data.def (" getValue" , getValue);
214228 data.def (" getHelp" , &BaseData::getHelp, sofapython3::doc::baseData::getHelp);
215229 data.def (" unset" , [](BaseData& b){ b.unset (); }, sofapython3::doc::baseData::unset);
216230 data.def (" getOwner" , &getOwner, sofapython3::doc::baseData::getOwner);
0 commit comments