How to erase message, which is display by OCC.Display.OCCViewer Viewer3d.DisplayMessage()

natalia

Moderator
Staff member
Hi @jrzou

To hide displayed message, use 'Erase' for the result of this command.

The sample code:
Code:
from OCC.Display.SimpleGui import init_display
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.gp import gp_Pnt

display, start_display, add_menu, add_function_to_menu = init_display()
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()

display.DisplayShape(my_box, update=True)

var = display.DisplayMessage(gp_Pnt(10, 20, 30), "(10, 20, 30)", 32)

var.Erase()
start_display()
The result of it (without Erase called on the left and with it's called on the right:
pythonOCC.png
Some words about why:
In pythonOCC we have created instance of 'Graphic3d_Structure':
Code:
    def DisplayMessage(
        self,
        point,
        text_to_write,
        height=14.0,
        message_color=(0.0, 0.0, 0.0),
        update=False,
    ):
        """
        :point: a gp_Pnt or gp_Pnt2d instance
        :text_to_write: a string
        :height: font height, 12 by defaults
        :message_color: triple with the range 0-1, default to black
        """
        aStructure = Graphic3d_Structure(self._struc_mgr)

        text_aspect = Prs3d_TextAspect()
        text_aspect.SetColor(rgb_color(*message_color))
        text_aspect.SetHeight(height)
        if isinstance(point, gp_Pnt2d):
            point = gp_Pnt(point.X(), point.Y(), 0)

        Prs3d_Text.Draw(
            aStructure.CurrentGroup(), text_aspect, to_string(text_to_write), point
        )
        aStructure.Display()
        # @TODO: it would be more coherent if a AIS_InteractiveObject
        # is be returned
        if update:
            self.Repaint()
        return aStructure

If we open this class definition in OCC we find the 'Display' inside, which is called in attached code above. Additionally this class has the 'Erase' declaration.

This is a good topic question becase it's not the usual way of managing OCCT visualization approach. That is also given in comments inside the DisplayMessage implementation : "@TODO: it would be more coherent if a AIS_InteractiveObject is be returned". May be later there will be impelemented using of AIS_TextLabel instead)

Best regards, Natalia
 
Top