Update TPrsStd_AISPresentation on shape modification

Jojain

CAD practitioner
Hello,

After reading and cross reading of the docs on TPrsStd_AISPresentation and associated class, I come to ask for help since I couldn't find an answer to my problem.

So currently I have this code that display a Shape (It's python but should be understandable from C++ pov, the "_s" suffix indicates that it's a C++ static method) :
Python:
    def display(self, shape: TopoDS_Shape):
        """
        Builds the display object and attach it to the OCAF tree
        """
        self.bldr = TNaming_Builder(self._label) #_label is  TDF_Label
        self.bldr.Generated(shape)

        named_shape = self.bldr.NamedShape()
        self._label.FindAttribute(TNaming_NamedShape.GetID_s(), named_shape)

        self.ais_shape = TPrsStd_AISPresentation.Set_s(named_shape)
        self.ais_shape.Display(update=True)

When I first create a Shape I pass it to this function and the shape is displayed correctly, no problem.
The problem arise when I want to edit the shape and update the view.

The only solution I got right now is to pass the modified shape to the same function but I feel that OCAF/OCCT can handle that and that I don't have to do that (which feels quite wrong)

Does someone know a better way ? OCAF visualisation and shape rebuilding seems quite linked to TFunctions but it looks quite heavy to implement and I'm trying to avoid using it yet, there's already so much to know/learn, it's a bit overwhelming

Thanks !
 

Quaoar

Administrator
Staff member
The only solution I got right now is to pass the modified shape to the same function but I feel that OCAF/OCCT can handle that and that I don't have to do that (which feels quite wrong)

Does someone know a better way ? OCAF visualisation and shape rebuilding seems quite linked to TFunctions but it looks quite heavy to implement and I'm trying to avoid using it yet, there's already so much to know/learn, it's a bit overwhelming
I'd say, keep redisplaying your shape. Whatever OCAF provides does not change the simple fact that updating a shape requires rebuilding its presentation meshes. There are no local or "incremental" updates supported at the level of the B-rep data structure, so you will gain nothing even with some very intelligent architectural connections, including TFunctions, whatsoever. Keep it simple and it will pay off.
 

Jojain

CAD practitioner
No I don't think so.
I was thinking that the viewer would somehow be notified when a shape is updated (by looking if the shapes attributes in the OCAF tree are modified or something) and would redraw accordingly.

But with more searching I don't think it's possible and that recreating a new NamedShape and Ais_Presentation for the updated shape is the way to go.
I've implemented it like that and it's working fine for now.

My questions might appear dumb/random but it's really not easy to understand how to do something when you only have the docs (that is sometimes very thin ... ) So sorry for that
 
Last edited:

Quaoar

Administrator
Staff member
No I don't think so.
I was thinking that the viewer would somehow be notified when a shape is updated (by looking if the shapes attributes in the OCAF tree are modified or something) and would redraw accordingly.

But with more searching I don't think it's possible and that recreating a new NamedShape and Ais_Presentation for the updated shape is the way to go.
I've implemented it like that and it's working fine for now.

My questions might appear dumb/random but it's really not easy to understand how to do something when you only have the doc (that is sometimes very thin ... ) So sorry for that
That's absolutely fine, no need to be sorry. I remember spending several horrible days on trivial things (also in AIS) simply because there was no reference or someone to ask. That's why this forum should help, I hope.
 
Top