RhinoCommon event when viewport display mode changes?


(Menno Deij - van Rijswijk) #1

Is there an event somewhere that is fired when the user changes display mode, e.g. from wireframe to ghosted? I’ve searched the RhinoCommon SDK docs, but could not find anything…


(Dale Fugier) #2

I don’t see anything in RhinoCommon. But the Rhino C++ SDK does contain a CRhinoDisplayModeChanged event class. I’ll put this on the to-do for @stevebaer. Hopefully we can add something for a future service release.

Just curious, why do you need to be notified with the display mode changes?


(Menno Deij - van Rijswijk) #3

I noticed that a display conduit I use does not get redrawn immediately when the user changes display mode, so I was hoping that it could be notified of the change and tell the document to redraw its views. It gets redrawn if the user changes the camera though.

So, another way to solve this is to issue a RhinoDoc.ActiveDoc.Views.Redraw() after the display mode has changed.


(Steve Baer) #4

This sounds like a bug we need to fix. I couldn’t repeat this in Rhino. I hooked up to the PostDrawObjects event and it got called when switching display modes back and forth between wireframe and shaded. This is essentially the exact same as having a conduit with that specific virtual function overridden. Do you have a small sample that shows Rhino not calling the conduit when the display mode changes.


(Menno Deij - van Rijswijk) #5

I think the display conduit only uses the DrawOverlay override, not the PostDrawObjects. I’ll check tomorrow to be sure.


(Menno Deij - van Rijswijk) #6

This seems to be a bug. To reproduce it use the DisplayConduit and Command as below.

The display conduit will draw a red point in the center of the bounding box of the selected surface.

Now, change the display mode without changing the camera and the red point disappears. The DrawOverlay method gets called (there is output on the commandline after the change of display mode), but the red point is not drawn! A change in the camera will trigger a new DrawOverlay and then the point gets drawn.

public class MyDisplayConduit : DisplayConduit
{
    private BoundingBox _b;
    public MyDisplayConduit(GeometryBase g)
    {
        _b = g.GetBoundingBox(true);
    }

    protected override void DrawOverlay(DrawEventArgs e)
    {
        e.Display.DrawPoint(_b.Center, PointStyle.Simple, 4, Color.Red);
        RhinoApp.WriteLine("draw overlay");
        base.DrawOverlay(e);
    }
}

And activate it in a command like so:

private MyDisplayConduit _conduit;
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    ObjRef sRef;
    Result r = RhinoGet.GetOneObject("Select a geometry", false, ObjectType.Surface, out sRef);
    if (r != Result.Success) return r;

    Surface s = sRef.Surface();
    _conduit = new MyDisplayConduit(s) {Enabled = true};

    return Result.Success;
}

(Steve Baer) #7

The DrawOverlay conduit is only called when Rhino is in a “feedback” mode (the dynamic drawing of things while you are in a GetPoint or some other “Get” operation).

Here’s a description of the process
http://4.rhino3d.com/5/rhinocommon/html/T_Rhino_Display_DisplayPipeline.htm


(Menno Deij - van Rijswijk) #8

Ah, that explains it. I will probably have to use another channel for my purposes then. Thanks for your help, I would not have found this :smile:


(Menno Deij - van Rijswijk) #9

I’ve changed it to DrawForeground and now it works.