Finally a managed to do it with the following:
    
    
    aPnt1 = newHandle( cast[ptr Geom_Point](aPnt2.get) )
    
    
    Run

where:

  * `aPnt2.get`: `get` is wrapped from the library I am working on. It gives 
you the pointer from the given handle. So its type is: `ptr 
Geom_CartesianPoint`.
  * `cast[ptr Geom_Point](aPnt2.get) `: then I get the conversion from `ptr 
Geom_CartesianPoint` to `ptr Geom_Point`.
  * `newHandle( ... )`: this creates new handles. It can do it from a pointer 
as it is being done in this case.



The downcasting can be done in a similar way.

So the following works for me:
    
    
    import occt
    
    # Geom_CartesianPoint a sub-class of Geom_Point;
    var aPnt1: Handle[Geom_Point]
    var aPnt2, aPnt3: Handle[Geom_CartesianPoint]
    
    assert(`*`(aPnt2) of Geom_Point)
    assert(`*`(aPnt2) of Geom_CartesianPoint)
    aPnt2 = newHandle( cnew newGeomCartesianPoint(1.0,2.0,3.0) )
    aPnt1 = newHandle( cast[ptr Geom_Point](aPnt2.get) )
    
    assert (`*`(aPnt1).x) == (`*`(aPnt2).x)
    
    aPnt3 = newHandle( cast[ptr Geom_CartesianPoint](aPnt1.get) )
    assert (`*`(aPnt1).x) == (`*`(aPnt3).x)
    
    
    Run

I am not sure if there is any better way of doing so.

Reply via email to