WPF panel issue in newest WIP


#1

Hi All,
Trying to catch up on my WIP debugging. Not getting very far!

In Rhino 5, I do something like this, as per Dale’s WPF example:

public partial class SMTWpfPanelHost : RhinoWindows.Controls.WpfElementHost
{
    public SMTWpfPanelHost(): base(new SMTWpfPanelUserControl(), null) 
    {
        
    }
    public static System.Guid PanelId
    {
        get
        {
            return typeof(SMTWpfPanelHost).GUID;
        }
    }

}

And then later
{
Guid panelId = SMTWpfPanelHost.PanelId;
Rhino.UI.Panels.OpenPanelAsSibling(panelId, Rhino.UI.PanelIds.Layers);
SMTWpfPanelHost SMTPanel = (Rhino.UI.Panels.GetPanel(panelId) as SMTWpfPanelHost);
}

And this works fine. But now in WIP , .GetPanel() has been changed, to take a uint?

Error CS0411 The type arguments for method ‘Panels.GetPanel(uint)’ cannot be inferred from the usage. Try specifying the type arguments explicitly

I did some digging and this seems to fix it:

RhinoDoc doc = RhinoDoc.ActiveDoc

SMTWpfPanelHost SMTPanel = (Rhino.UI.Panels.GetPanel(panelId, doc.RuntimeSerialNumber) as SMTWpfPanelHost);

thoughts? Its working fine for now.


(Steve Baer) #2

I think this should be changed.

@JohnM, I see that you authored this 11 days ago by looking at the source. We should modify the input parameter to a RhinoDoc instead of a simple uint and bring back the older function that doesn’t require a document. This function should be deprecated and call the newer version of the function with ActiveDoc. Sound like a good plan or am I missing something?


(John Morse) #3

@stevebaer Several months ago I changed the Windows panel code to make it operate in the same fashion as the Mac panel code. Windows Rhino now creates a instance of the registered panel class for each new document. The Panels manager will also look for a public constructor which includes a uint parameter and call it before calling the default constructor so the panel object can tell which document it belongs to.

Under the hood the old version was using the RhinoDoc.ActiveDoc.RuntimeSerialNumber which caused a problem in some of the commands in the Commands plug-in. I added the document serial number so that a command could request the panel associated with the document specified by run command because in Mac Rhino there will be an instance of a panel class for each open document.

I can overload the Panels.GetPanel() to include a version with no arguments but I need the form that takes a serial number.


(Steve Baer) #4

I don’t exactly like having a uint as an argument when a RhinoDoc argument could be used instead since it is more informative of what needs to be passed. You can always internally use the serial number for storage. Changing the GetPanel function breaks the SDK and makes it so some V5 plug-ins won’t load into V6. I think we should have two functions; one with a RhinoDoc argument and an [Obsolete] version that does not take a RhinoDoc argument. This obsolete version can call the new version with ActiveDoc as the passed arg.


(John Morse) #5

I added the old versions back and marked them obsolete, in addition I added new versions that take a RhinoDoc argument.