TShape modification (and general ownership and lifetime questions)

We require a mutable type of "path" (both 3d and 2d) where i can split or add and modify segments. These operations should be very lightweight.

It seems that the BRep internal TShape types are immutable after creation and not the correct facility?

What is the best way to archive this, or should we build our own facilities on top of Geom_Curve?

 

In addition I have some questions that remain open after reading the docs:

In most cases this concerns lifetime questions as OCC mostly passes handles vs current modern c++ rules that move/pass unique_ptr/shared_ptr only for ownership/lifetime transfer and pass (const) references for local usage.

E.g for the BRep_Tool Class:

static const HandleGeom_Curve > &  Curve (const TopoDS_Edge &E, TopLoc_Location &L, Standard_Real &First, Standard_Real &Last)
static HandleGeom_Curve >  Curve (const TopoDS_Edge &E, Standard_Real &First, Standard_Real &Last)

- Why does the TopLoc_Location version returns an const Handle Reference. What is the lifetime of this object? Can I store it?

- Can I modify the Geom_Curve? It is not const.

- In General who is the owner of an Geom_Curve? When I pass a Geom_Curve to an Edge I also pass the ownership? After this operation any manual change to the curve might horribly break the BRep and I should always use the BRep_Falcilities instead?

-  Are multiple shapes allowed to share the same curve?

Thomas Hafemann's picture

Have you found an answer for your question? I have the same question...

If you could modify a curve, how would you pass this change to all the objects associated with it?

Mikhail Sazonov's picture

OCCT paradigm of modeling algorithms is not to alter already built shapes. Rather one should create a new shape along with any new version of the shape.

For example, if you want to modify the geometry of some face of a solid object, you should make a new copy of that face (probably saving the same boundary edges to preserve connectivity), and then rebuild the solid from scratch leaving the non-modified faces as is, and rebuilding the shell containing the modified face. For that you can use the special tool class BRepTools_ReShape that rebuilds a shape by making pre-defined substitutions on some
of its components.

As for the question of Andreas Fleischner about the overload methods BRep_Tool::Curve(), the first one returns the (probably) the deep copy of the original curve of the edge (depending on the "identity" property of the edge's location; if it is not then the result curve is a copy, otherwise it is the shared curve). BTW, if one had read the description of the methods carefully then one could understand this idea from the phrase of the description of the second method - "It can be a copy if there is a Location".

>Can I modify the Geom_Curve? It is not const.
The simple answer is "No", because it may be the handle to the same curve stored in the edge. This method was introduced just for simplicity if you need always the curve considering the location of the edge.

>In General who is the owner of an Geom_Curve?
There is no dedicated owner of OCCT handle. The last remaining handle will destroy the entity along with self destruction.