Hello,

OpenCascade smart pointers mechanism has to be supported in pythonOCC in 
order to enable efficient access to all classes/methods in a safe way. 
Roman Lygin wrote on his blog (http://opencascade.blogspot.com/) a set 
of excellent articles related to Handle_*. A recent topic on OCC forum 
also recently dealt with this issue when considering C# OCC wrapper 
(http://www.opencascade.org/org/forum/thread_14766/).

After a few days of work, a simple solution was found to overcome the 
Handle_* management issue in pythonOCC:

- each class managed by a smart pointer (ie, all classes that inhertis 
from Standard_Transient) are extended with a GetHandle() method that 
returns a pointer to the object. This was achived by adding the 
following set of lines in the SWIG wrapper. This is an example for 
gp_VectorWithNullMagnitude:

%extend gp_VectorWithNullMagnitude {
    Handle_gp_VectorWithNullMagnitude GetHandle() {
    return *(Handle_gp_VectorWithNullMagnitude*) &$self;
    }
};

- each Handle_* class is extended with a GetObject() method that returns 
the 'pointed' object (indeed a pointer to this object).

%extend Handle_gp_VectorWithNullMagnitude {
    gp_VectorWithNullMagnitude* GetObject() {
    return (gp_VectorWithNullMagnitude*)$self->Access();
    }
};

Here is now an example of the smart pointer handle in pythonOCC:

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> from OCC import *
 >>> V = gp_VectorWithNullMagnitude()
 >>> print V
<OCC.gp_VectorWithNullMagnitude; proxy of <Swig Object of type 
'gp_VectorWithNullMagnitude *' at 0x5786660> >
 >>> h = V.GetHandle()
 >>> print h
<OCC.Handle_gp_VectorWithNullMagnitude; proxy of <Swig Object of type 
'Handle_gp_VectorWithNullMagnitude *' at
 0x5786674> >
 >>> V2 = h.GetObject()
 >>> print V2
<OCC.gp_VectorWithNullMagnitude; proxy of <Swig Object of type 
'gp_VectorWithNullMagnitude *' at 0x5786660> >
 >>>

OCC pointers are not smart anymore in pythonOCC but it's a first step. 
Jelle and I successfully tested this new feature with a few sample 
scripts. The next step is to have a complete handle of smart pointers, 
that means a complete support of the -> C++ operator defined in OCC 
headers. Anyway, you can download a daily release added a couple of days 
ago (http://www.pythonocc.org/Releases/daily) and test that by yourself.

Best regards,

Thomas Paviot

_______________________________________________
Minerva-pythonocc mailing list
Minerva-pythonocc@gna.org
https://mail.gna.org/listinfo/minerva-pythonocc

Reply via email to