For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

keeping pointers to shapes outside of occ

Ugo Capeto's picture
Forums: 

Hi:
I need to keep pointers to shapes outside of occ as void * ... when i come back, i need to cast back to the shape type and then do stuff with the shape.

For example:
for ( Ex.Init(aCompound,TopAbs_SOLID);Ex.more;Ex.next) {
cast Ex.current as a void *;
store pointer to solid shape outside of occ;
}

do things outside of occ.

When i need to go back to occ, i want to cast back the void * to a pointer to a Solid shape and then do things with it in occ.

i've tried that but it doesn't work. when i cast back and dereference the pointer, it crashes.
What am I doing wrong ? what's the proper way to store a pointer/handle to a shape outside of occ so that when you come back, you can still access it.

Note: i am not too versed in C++.
thanks in advance for your help.

Ugo Capeto's picture

i have the feeling it cannot be done.

what is the proper way to reference occ shapes from outside occ ? so that you can go in and out of occ without too much pain.

do you have to assign a unique identifier to each shape and maintain your own ID table ?

i just need a few clues.

Stephane Routelous's picture

you can create a class to include a shape like :
class ShapeContainer
{
public:
ShapeContainer(const TopoDS_Shape& shape):_shape(shape){}
TopoDS_Shape _shape;
};

and in your code :
//external api
void ExternalFct(void* shapecontainer);
void* ReturnShapeContainer();

//occ code
TopoDS_Shape s = Exp.Current();
ShapeContainer* sc = new ShapeContainer(s);
ExternalFct(sc);
void* ptr = ReturnShapeContainer();
ShapeContainer* sc2 = (ShapeContainer*)ptr;
TopoDS_Shape s2 = sc2->_shape;

//cleanup
sc2 = NULL;
delete sc; sc = NULL;

it should work

HTH,

Stephane

Roman Lygin's picture

Stephane is correct.
TopoDS_HShape can do the work for you.

TopoDS_HShape* aHShape = new TopoDS_HShape (aShape);

Note that in this case you must take care of memory deallocation yourself. In the case of using Open CASCADE handles (Handle_TopoDS_HShape), which are smart pointers you do not have to care about that.
Roman

Ugo Capeto's picture

thanks a lot.

so the pointer that I store is this aHShape?
void *ptr=aHShape;

Now, assuming the aShape was a Solid to begin with.

when I cast it back to a Solid, do I use:
Solid=*(static_cast(ptr)); ???
i've tried that but i don't think it works.

Roman Lygin's picture

No, you always cast to TopoDS_HShape*.

TopoDS_HShape* aHShape = static_cast (ptr);

const TopoDS_Shape& aShape = aHShape->Shape();

then you deal with aShape as usual. For instance:
const TopoDS_Solid& aSolid = TopoDS::Solid (aShape) if you are sure it's a solid.

Ugo Capeto's picture

merci bien.

is it the same as using TopoDS_HShape ?

Ugo Capeto's picture

above was directed to Stéphane and his solution.

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.