Doubts about the Geom Pac and the Handle class

Example

in the source code , using such as example:
Geom_Geometry < ---- Geom_Surface < ---- Geom_SweptSurface < ---- Geom_SurfaceOfRevolution

Detail

Geom_Geometry & Geom_Surfaces are abstract classes , have no data members.

Geom_SweptSurface has 3 data members:

// handle whose template T is abstract
Handle(Geom_Curve) basisCurve;

// as name says
gp_Dir direction;
// not concerned
GeomAbs_Shape smooth;

Geom_SurfaceOfRevolution has 3 data members

// handle whose template T is abstract
Handle(Geom_Curve) myBaseCurve;
// handle whose template T is abstract
Handle(Adaptor3d_HCurve) myBaseAdaptor; // not concerned
gp_Ax1 myRotAxis;

Questions

1.how can abstract handle be used?

For I know , when creating a ptr pointing to a object , it will be initialized first .
But as an abstract class , it can't be initialized .
So how does this worked?s

2.where is the points?

Mentioned abstract classes have no data members .
Or have no data members to store the points data.
Meanwhile , the curves need the points to constitute themselves , don't they?
So where is the points data ?

Kirill Gavrilov's picture

Maybe you can reformulate the question or share a code snippet to clarify where your doubts come from?

Lewis Alexander's picture

Thanks for your reply , dear K·G!

I am sorry that my English is not good enough .
Also I am kinda new to the OCC developing , if something is pretty wrong , please let me know , gracias!

So simplifying my question:

1.

In the source code files , I've seen many code that using Class Handle , whose base type is a abstract class(means they have pure virtual functions , right?)

For example , in the file : Geom_RectangularTrimmedSurface.hxx

the class Geom_RectangularTrimmedSurface has a data member named Handle(GeomSurface) basisSurf

however the class Geom_Surface is abstract class , so if I define a Geom_RectangularTrimmedSurface object named a directly

Then a will have a handle data member whose basic type is abstract class .

Won't this raise a exception?

2

The Surfaces are made of curves which made of points , but I don't know how does the system transfer the valid points data?

If I want to define some kind of Surfaces , does the descriptions below correct?

a)define a handle test pointing to a derived class object which has valid data
b)upcast the handle test ,and make it pointing to a common base type class which has no valid data members
c)using the handle test to construct another derived class object which shared the common base type class with the class mentioned in the No.a step

Again , most appreciation for your reply !

Kirill Gavrilov's picture

Handle() is just an OCCT-specific implementation of smart pointer. Nowadays C++ implements standard smart pointers like std::shared_ptr, but OCCT's Handle() is still useful as it has a couple of nice properties that std::shared_ptr doesn't have. In any case, you may consider replacing Handle() with a raw pointer, e.g. Handle(GeomSurface) -> GeomSurface* to see how to work with it - the "smart" part is just intended to call delete when pointer is no more used.

In this context an empty constructor of Handle(GeomSurface) as a class field becomes:

GeomSurface* basisSurf = NULL; // OK - just a NULL pointer

Initialization of abstract class will lead to a compiler error:

GeomSurface* basisSurf = new GeomSurface(); // error

but construction of classes inherited from pure interface and implementing all methods is perfectly fine:

GeomSurface* basisSurf = new Geom_CylindricalSurface (gp_Cylinder()); // OK
Lewis Alexander's picture

Thanks for your reply , and it helps a lot !
Wish you a good day!
^_^,谢谢~