Hi all,
In the context of a RhinoInside app, with a ViewportControl hosted in a WPF view, I need to be able to redraw when any call to ActiveDoc.Views.Redraw() is made (by Grasshopper, by the various Rhino commands refreshing viewports, etc.).
From what I understand, I am missing something such as:
a way to add the ViewportControl to the document ViewTable
or an event I could use to manually redraw the hosted viewport instance(s). I already subscribed to Grasshopper solution ends and Rhino command ends, but this is really too limiting, I am missing many redraw events such as the one triggered during picking or when the state of a GH component is updated.
I’m not aware of any OnRedraw event. Why do you need to redraw i
My only thought is you could try using the SampleCsEventWatcher to see if any of the RhinoView events that exist are fired in the scenarios you’re hoping to capture.
Well, I need to redraw so I can have my viewport working as expected (drawing information like any other viewport in Rhino). So far, it only half works because of the fact hosted viewports are not behaving as other viewports so you have to do some glue code to replicate expected behaviour. My understanding is that for now these viewports are a bit of a temporary hack provided by McNeel, but not 100% usable as is.
My only thought is you could try using the SampleCsEventWatcher to see if any of the RhinoView events that exist are fired in the scenarios you’re hoping to capture.
The event watcher just subscribes to all available events in Rhino, none of them doing what I need, hence my request to have an event corresponding to the display phase start or end or whatever, where I could maybe tell the display pipeline to also deal with this viewport. The best solution would be to have any instance of ViewportControl added in the document ViewTable by default, so this would not be a problem to just set the active view and have the viewports redraw as they should, but this is a feature only McNeel can add.
Another path I am exploring with limited success so far is to use a CustomMeshProvider or something else already participating in the display pipeline to propagate calls, then filter duplicate calls. But this is a hack.
Ahh I see, you’ve put your own custom Rhino Viewport in a UI and you want it to refresh when the main view does. Are you drawing something in there using the Display Conduit?
I was going to suggest the below,
RhinoView.Modify is called when the view moves, you could use that to update when a user is panning. For everything else you could just chuck a redraw call into Idle. It’s not the most efficient method, but it might be a bit less hacky at least.
But you can add views to the ViewTable. Is it possible to add one and then switch your custom viewport to that new view?
I tried to handle the Modified and Idle events already, but they do not trigger when needed, probably because the regular rhino views are not refreshed as they are not on screen.
Panning and mouse events are handled directly by the viewport so that’s alright.
Again, the issue is to have Views.Redraw() triggering redraw of ALL viewports, not only standard rhino document viewports.
Also, I just realised that GetPoint and the snaps do not work in hosted viewports either, so I spent the day reprogramming them from scratch… I can now have selection in these hosted viewports, but any call to get commands (for example, via a Grasshopper parameter → set point) will fail as mouse events are not propagated from the hosted viewports below (so no mouse move and no mouse click triggering the end of command). I tried to force this to happen by propagating GetPointMouseEventArgs that I instantiated via reflection using the hosted viewport handle, but it does not do anything. As there is no parent View, I guess this is yet again the issue: no view container to be refreshed / referenced or something.
But you can add views to the ViewTable. Is it possible to add one and then switch your custom viewport to that new view?