Ejemplo n.º 1
0
        /// <summary>
        /// Register custom render user interface with Rhino.  This should only be
        /// done in <see cref="RenderPlugIn.RegisterRenderPanels"/>.  Panels
        /// registered after <see cref="RenderPlugIn.RegisterRenderPanels"/> is called
        /// will be ignored.
        /// </summary>
        /// <param name="plugin">
        /// The plug-in providing the custom user interface
        /// </param>
        /// <param name="tabType">
        /// The type of object to be created and added to the render container.
        /// </param>
        /// <param name="caption">
        /// The caption for the custom user interface.
        /// </param>
        /// <param name="icon">
        /// </param>
        public void RegisterTab(PlugIn plugin, Type tabType, string caption, Icon icon)
        {
            if (!typeof(IWin32Window).IsAssignableFrom(tabType))
            {
                throw new ArgumentException("tabType must implement IWin32Window interface", "tabType");
            }
            var constructor = tabType.GetConstructor(Type.EmptyTypes);

            if (!tabType.IsPublic || constructor == null)
            {
                throw new ArgumentException("tabType must be a public class and have a parameterless constructor", "tabType");
            }
            var attr = tabType.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);

            if (attr.Length != 1)
            {
                throw new ArgumentException("tabType must have a GuidAttribute", "tabType");
            }

            if (g_existing_dockbar_tabs == null)
            {
                g_existing_dockbar_tabs = new List <RenderTabData>();
            }
            // make sure the type is not already registered
            for (var i = 0; i < g_existing_dockbar_tabs.Count; i++)
            {
                var pd = g_existing_dockbar_tabs[i];
                if (pd != null && pd.PlugInId == plugin.Id && pd.PanelType == tabType)
                {
                    return;
                }
            }

            var panel_data = new RenderTabData()
            {
                PlugInId = plugin.Id, PanelType = tabType, Icon = icon
            };

            g_existing_dockbar_tabs.Add(panel_data);

            var render_panel_type = RenderPanelTypeToRhRdkCustomUiType(panel_data.RenderPanelType);

            g_create_dockbar_tab_callback  = OnCreateDockBarTabCallback;
            g_visible_dockbar_tab_callback = OnVisibleDockBarTabCallback;
            g_destroy_dockbar_tab_callback = OnDestroyDockBarTabCallback;

            UnsafeNativeMethods.CRhCmnRdkRenderPlugIn_RegisterCustomDockBarTab(
                render_panel_type,
                caption,
                tabType.GUID,
                plugin.Id,
                icon == null ? IntPtr.Zero : icon.Handle,
                g_create_dockbar_tab_callback,
                g_visible_dockbar_tab_callback,
                g_destroy_dockbar_tab_callback
                );
        }
Ejemplo n.º 2
0
    /// <summary>
    /// Register custom render user interface with Rhino.  This should only be
    /// done in <see cref="RenderPlugIn.RegisterRenderPanels"/>.  Panels
    /// registered after <see cref="RenderPlugIn.RegisterRenderPanels"/> is called
    /// will be ignored.
    /// </summary>
    /// <param name="plugin">
    /// The plug-in providing the custom user interface
    /// </param>
    /// <param name="tabType">
    /// The type of object to be created and added to the render container.
    /// </param>
    /// <param name="caption">
    /// The caption for the custom user interface.
    /// </param>
    /// <param name="icon">
    /// </param>
    public void RegisterTab(PlugIn plugin, Type tabType, string caption, Icon icon)
    {
      if (!typeof(IWin32Window).IsAssignableFrom(tabType))
        throw new ArgumentException("tabType must implement IWin32Window interface", "tabType");
      var constructor = tabType.GetConstructor(Type.EmptyTypes);
      if (!tabType.IsPublic || constructor == null)
        throw new ArgumentException("tabType must be a public class and have a parameterless constructor", "tabType");
      var attr = tabType.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
      if (attr.Length != 1)
        throw new ArgumentException("tabType must have a GuidAttribute", "tabType");

      if (g_existing_dockbar_tabs == null)
        g_existing_dockbar_tabs = new List<RenderTabData>();
      // make sure the type is not already registered
      for (var i = 0; i < g_existing_dockbar_tabs.Count; i++)
      {
        var pd = g_existing_dockbar_tabs[i];
        if (pd != null && pd.PlugInId == plugin.Id && pd.PanelType == tabType)
          return;
      }

      var panel_data = new RenderTabData() { PlugInId = plugin.Id, PanelType = tabType, Icon = icon };
      g_existing_dockbar_tabs.Add(panel_data);

      var render_panel_type = RenderPanelTypeToRhRdkCustomUiType(panel_data.RenderPanelType);

      g_create_dockbar_tab_callback = OnCreateDockBarTabCallback;
      g_visible_dockbar_tab_callback = OnVisibleDockBarTabCallback;
      g_destroy_dockbar_tab_callback = OnDestroyDockBarTabCallback;

      UnsafeNativeMethods.CRhCmnRdkRenderPlugIn_RegisterCustomDockBarTab(
        render_panel_type,
        caption,
        tabType.GUID,
        plugin.Id,
        icon == null ? IntPtr.Zero : icon.Handle,
        g_create_dockbar_tab_callback,
        g_visible_dockbar_tab_callback,
        g_destroy_dockbar_tab_callback
        );
    }