-
-
Notifications
You must be signed in to change notification settings - Fork 365
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: Implemented transparent handles #581
WIP: Implemented transparent handles #581
Conversation
BTW: Obviously, I made most of the changes with an adapted pythonocc-generator. I still have an issue with the PCDM_Document class, which mistakenly is detected as type of Standard_Transient. If this is fixed, I will send you the PR of the generator as well. |
The OCCT handle smart pointer API is a C++ specific detail and should not be exposed to Python. Instead it should be completely invisible. I used the std::shared_ptr swig library as a basis for the implementation. To be compatible with most of the "old" code, GetHandle() and GetObject() methods still exist but do nothing except from a deprecation warning. In general, I tried to make sure that the code is backwards compatible as possible. Closes tpaviot#539
5592697
to
0ac6173
Compare
There still seems to be an issue with python 2.7 and the automatic upcasting of handles. Concretely what currently does not work is: Somehow, swig does not see, that the handle_geom2d_trimmed curve IS A handle_geom2d_curve. |
@rainman110 Thank you for this contribution, it's a huge achievement. I remember working on removing handles some time ago, but without success ... This really makes things more pythonic, those f**** handles constantly reminds the python user he works with something coming from C/C++. GetHandle()/GetObject() was only an ugly hack to makes things working. I would like the generator to keep consistent with the pythonocc-core SWIG files, is it possible that you also submit a PR on pythonocc-generator ? |
Sure... as I said I have to fix one issue in the generator regarding the class PCDM_Document. Then I'll send you a PR as well. |
Yes, I read your note regarding the PCDM_Document class. Don't spend to much time on this issue. My solution : after 15mn working on a class that I don't manage to get wrapped, I remove it from the wrapper ! |
I sent you the PR for the generator. The issue with the one class (and obviously others where also affected) is fixed. |
Lets summarize the current status:
|
@tpaviot How do I add SMESH support? Which version of SMESH do I have to use? |
@rainman110 SMESH wrappers are generated the same way that other modules, using pythonocc-generator. You have to use smesh-676 (https://github.com/tpaviot/smesh/releases/tag/6.7.6). Running the pythonocc-gnererator, just set i the .conf file the path where are located the smesh headers. |
730bdca
to
75cb5c9
Compare
@rainman110 The |
ok, the |
@rainman110 which os/python version did you use to generate the SWIG files ? I'm running a Linux Ubuntu 18.04 machine, and running the generator creates a huge diff compared to your result. |
@rainman110 There's a trailing
|
I created my own branch, cherry-picked from yours, to test on my own see review/tp-transparent-handles Your contribution results in much smaller and readable SWIG files, that's really how things should have been done from the beginning |
Examples have been ported to this new feature tpaviot/pythonocc-demos#9 |
@tpaviot Great that you take care of it!
I created it on windows. I regularly have seen, that the order of includes can be pretty arbitrary. It could also depend on the python version used to run the generator! |
@tpaviot Is there anything, I still have to do? We could also use your new branch now and I will create PRs into this branch, when I have to change anything. |
@rainman110 In my branch, I re-generated the swig files using the same machine, you can see that the diffs are more readable. I also noticed a different output from Windows and Linux, I think this comes from the Currently I've been waiting the travis and appveyor builds to complete, then I'll check if the refactored examples run. I think the next step is to check if the docstrings have to be modified in the generator as well. I do think that method docstrings refer to Handle_*, and this should be removed to be consistent with the API. |
Superseeded by PR #583 |
The OCCT handle smart pointer API is a C++ specific detail and should not be exposed to Python. Instead it should be completely invisible. This PR almost completely removes Handles_ from pythonOCC.
This makes the use of pythonOCC much cleaner and less verbose!
I used the std::shared_ptr swig library as a basis for the implementation.
To be compatible with most of the "old" code, GetHandle() and GetObject() methods still exist but do nothing except from a deprecation warning. In general, I tried to make sure that the code is backwards compatible as possible.
I adapted already the unit tests to not include the legacy code. The demos are working unmodified but should be adapted to avoid deprecation warnings.
The only thing that is not backwards compatible is, when previously an Null-Handle was returned - e.g. a non successful computation. Before, the object was a handle but .IsNull() was true. Now, it is a None type, which is more Pythonic.
The "magic" is implemeted in new swig typemaps in OccHandle.i.
Closes #539