-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Subclassing OpenSim classes in Python #710
base: main
Are you sure you want to change the base?
Conversation
@chrisdembia Nice job indeed, I was planning to add a "Controller" instead but the same process holds. We'll have to decide what classes we should allow extending since there's a cost in code bloat due to SWIG directors. I don't think RegisterType is necessary (although possible) since that only plays into registration and XML serialization which shouldn't be needed for development/prototyping purposes. What symptoms of memory problems did you run into? I saw nothing on AppVeyor, testComponents fails for an unrelated reason AFAIK. |
Segfaults. I didn't try too hard to understand what was happening. It'd be good to discuss in person. I also tried making a custom ModelComponent. I was able to implement a protected method but I was unable to call protected methods from it! This could present serious problems! I agree that serialization/deserialization is not necessary; it would be nice icing on the cake though if we could get it to work. It'd be neat if we could give python users an equivalent of OpenSim_DECLARE_PROPERTY. I think it may be possible. |
@chrisdembia Thanks, why don't you add the code that causes the segfault as a test case so I can reproduce and we can discuss and make sure it stays fixed. |
done |
Awesome, thanks a million @chrisdembia |
@chrisdembia Thought I'd document my findings and status of this PR since I spent some time on the investigation:
I can think of solutions around these issues (e.g. create non abstract class in the interface file that we can wrap/expose and have that as base classes e.g. PythonAnalysis etc. but that may complicate documentation etc. and will need to scale to other Components) Considering how we're handicapped by using Macros for Properties it probably make sense to stop here until there's a specific use-case/need, but let me know if you think otherwise. |
I don't think we should support users calling I think we could find a workaround for properties using python decorators, so long as the |
@aymanhab , I updated this. |
…loning/registration.
@chrisdembia Aside from the implementation of clone, this seems working now. Haven't touched the ModelComponent issues/tests but maybe similar fix (where base class methods that are used need to be declared as director methods). Please take a look when you have a chance. An example in Java with a pure implementation of clone in Jva is working perfectly as well. |
I reproduced something that @aymanhab did a few months ago: subclassing an OpenSim class in Python and using it with a tool. OpenSim can recognize the new class, etc. I think @aseth1 and @klshrinidhi have expressed interest in this.
If we want to be able to do this, there is still a lot to iron out. It'd be nice if we could register this type (
OpenSim::registerType()
), but I'm running into memory ownership issues there; perhaps @aymanhab would know how to address such memory issues.This change is