Developing a property set

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
yorik
Site Admin
Posts: 8563
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Developing a property set

Postby yorik » Wed Mar 08, 2017 10:13 pm

Hi all,

this is a question for the C++ gurus out there i think *hust* Werner *hust*

I'm developing a new property type called PropertySet ( https://github.com/yorikvanhavre/FreeCA ... t?expand=1 ). It's basically a property that can contain any number of other properties. It would be pretty useful for dealing with IFC files, where objects can have any number of custom properties grouped under property sets. This would allow us to recreate that structure without clogging the property editor with an enormous amount of properties...

So I basically created a new class called PropertySet, derived from Property. And, since we need tools to add/remove additional properties from these property sets, I also created a special python object with add/remove methods.

Problem: When adding an App::PropertySet to a python feature, then trying to access that property from python:

Code: Select all

o = App.ActiveDocument.addObject("App::FeaturePython","test")
o.addProperty("App::PropertyTest","testprop")
o.

I immediately get a crash with: virtual PyObject* Base::BaseClass::getPyObject(): Assertion `0' failed.

That is, I suppose, because the base Property class has a virtual getPyObject() that must be reimplemented in the derived classes. Which I didn't do, because I thought that the .xml + .PyImp.cpp system took care of doing all that automatically. Do I need to explicitly implement this function? How does it work with the .xml+.PyImp.cpp duo then?

Any clue?

Thanks!
DeepSOIC
Posts: 4504
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Developing a property set

Postby DeepSOIC » Wed Mar 08, 2017 11:28 pm

yorik wrote:Which I didn't do, because I thought that the .xml + .PyImp.cpp system took care of doing all that automatically. Do I need to explicitly implement this function?
Yes, at least as far as I know. I think this method is actually introduced much deeper, somewhere around BaseClass.
cwstirk
Posts: 15
Joined: Thu Dec 05, 2013 7:07 pm

Re: Developing a property set

Postby cwstirk » Thu Mar 09, 2017 1:47 am

@yorik it would be useful if the FreeCAD way to handle IFC property sets also could handle STEP user defined attributes, which serve a similar purpose.
https://www.cax-if.org/documents/rec_pr ... es_v15.pdf