Ejemplo n.º 1
0
 protected virtual void Dispose(bool isDisposing)
 {
     UnsafeNativeMethods.Rdk_SdkRender_Delete(m_pSdkRender);
     m_pSdkRender = IntPtr.Zero;
     m_plugin     = null;
     m_all_render_pipelines.Remove(m_serial_number);
     m_serial_number = -1;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Get the instance of a render tab associated with a specific render
 /// session, this is useful when it is necessary to update a control from a
 /// <see cref="RenderPipeline"/>
 /// </summary>
 /// <param name="plugIn">
 /// The plug-in that registered the custom user interface
 /// </param>
 /// <param name="tabType">
 /// The type of tab to return
 /// </param>
 /// <param name="renderSessionId">
 /// The <see cref="RenderPipeline.RenderSessionId"/> of a specific render
 /// session.
 /// </param>
 /// <returns>
 /// Returns the custom tab object if found; otherwise null is returned.
 /// </returns>
 public static object FromRenderSessionId(PlugIn plugIn, Type tabType, Guid renderSessionId)
 {
   if (plugIn == null) throw new ArgumentNullException("plugIn");
   if (tabType == null) throw new ArgumentNullException("tabType");
   var attr = tabType.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
   if (attr.Length != 1)
     return null;
   var data = FindExistingTabData(plugIn.Id, tabType.GUID);
   if (data == null)
     return null;
   IWin32Window tab;
   data.Tabs.TryGetValue(renderSessionId, out tab);
   return tab;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a subclass of this object on the stack in your Rhino plug-in's Render() or RenderWindow() implementation.
        /// </summary>
        /// <param name="doc">A Rhino document.</param>
        /// <param name="mode">A command running mode, such as scripted or interactive.</param>
        /// <param name="plugin">A plug-in.</param>
        /// <param name="sizeRendering">The width and height of the rendering.</param>
        /// <param name="caption">The caption to display in the frame window.</param>
        /// <param name="channels">The color channel or channels.</param>
        /// <param name="reuseRenderWindow">true if the rendering window should be reused; otherwise, a new one will be instanciated.</param>
        /// <param name="clearLastRendering">true if the last rendering should be removed.</param>
        protected RenderPipeline(RhinoDoc doc,
                                 Rhino.Commands.RunMode mode,
                                 Rhino.PlugIns.PlugIn plugin,
                                 System.Drawing.Size sizeRendering,
                                 string caption,
                                 Rhino.Render.RenderWindow.StandardChannels channels,
                                 bool reuseRenderWindow,
                                 bool clearLastRendering
                                 )
        {
            Debug.Assert(Rhino.PlugIns.RenderPlugIn.RenderCommandContextPointer != IntPtr.Zero);

            m_serial_number = m_current_serial_number++;
            m_all_render_pipelines.Add(m_serial_number, this);
            m_size     = sizeRendering;
            m_channels = channels;

            m_pSdkRender = UnsafeNativeMethods.Rdk_SdkRender_New(m_serial_number, Rhino.PlugIns.RenderPlugIn.RenderCommandContextPointer, plugin.NonConstPointer(), caption, reuseRenderWindow, clearLastRendering);
            m_session_id = UnsafeNativeMethods.CRhRdkSdkRender_RenderSessionId(m_pSdkRender);
            m_plugin     = plugin;

            UnsafeNativeMethods.Rdk_RenderWindow_Initialize(m_pSdkRender, (int)channels, m_size.Width, m_size.Height);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Adds a new dynamic command to Rhino.
    /// </summary>
    /// <param name="plugin">Plugin that owns the command.</param>
    /// <param name="cmd">Command to add.</param>
    /// <returns>true on success, false on failure.</returns>
    public static bool RegisterDynamicCommand(PlugIn plugin, Commands.Command cmd)
    {
      // every command must have a RhinoId and Name attribute
      bool rc = false;
      if (plugin != null)
      {
        try
        {
          plugin.m_commands.Add(cmd);
          int sn = cmd.m_runtime_serial_number;
          IntPtr pPlugIn = plugin.NonConstPointer();
          string englishName = cmd.EnglishName;
          string localName = cmd.LocalName;
          const int commandStyle = 2; //scripted
          Guid id = cmd.Id;
          UnsafeNativeMethods.CRhinoCommand_Create(pPlugIn, id, englishName, localName, sn, commandStyle, 0);

          rc = true;
        }
        catch (Exception ex)
        {
          ExceptionReport(ex);
        }
      }
      return rc;
    }
Ejemplo n.º 5
0
 /// <summary>
 /// Parses a plugin and create all the commands defined therein.
 /// </summary>
 /// <param name="plugin">Plugin to harvest for commands.</param>
 public static void CreateCommands(PlugIn plugin)
 {
   if (plugin!=null)
     plugin.InternalCreateCommands();
 }
Ejemplo n.º 6
0
    internal static bool CreateCommandsHelper(PlugIn plugin, IntPtr pPlugIn, Type command_type, Commands.Command new_command)
    {
      bool rc = false;
      try
      {
        // added in case the command tries to access it's plug-in in the constructor
        m_active_plugin_at_command_creation = plugin;
        if( new_command==null )
          new_command = (Commands.Command)System.Activator.CreateInstance(command_type);
        new_command.PlugIn = plugin;
        m_active_plugin_at_command_creation = null;

        if (null != plugin)
          plugin.m_commands.Add(new_command);

        int commandStyle = 0;
        object[] styleattr = command_type.GetCustomAttributes(typeof(Commands.CommandStyleAttribute), true);
        if (styleattr != null && styleattr.Length > 0)
        {
          Commands.CommandStyleAttribute a = (Commands.CommandStyleAttribute)styleattr[0];
          new_command.m_style_flags = a.Styles;
          commandStyle = (int)new_command.m_style_flags;
        }

        int sn = new_command.m_runtime_serial_number;
        Guid id = new_command.Id;
        string englishName = new_command.EnglishName;
        string localName = new_command.LocalName;

        int ct = 0;
        if (command_type.IsSubclassOf(typeof(Commands.TransformCommand)))
          ct = 1;
        if (command_type.IsSubclassOf(typeof(Commands.SelCommand)))
          ct = 2;

        UnsafeNativeMethods.CRhinoCommand_Create(pPlugIn, id, englishName, localName, sn, commandStyle, ct);

        rc = true;
      }
      catch (Exception ex)
      {
        Rhino.Runtime.HostUtils.ExceptionReport(ex);
      }

      return rc;
    }
Ejemplo n.º 7
0
 protected virtual void Dispose(bool isDisposing)
 {
   UnsafeNativeMethods.Rdk_SdkRender_Delete(m_pSdkRender);
   m_pSdkRender = IntPtr.Zero;
   m_plugin = null;
   m_all_render_pipelines.Remove(m_serial_number);
   m_serial_number = -1;
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Constructs a subclass of this object on the stack in your Rhino plug-in's Render() or RenderWindow() implementation.
    /// </summary>
    /// <param name="doc">A Rhino document.</param>
    /// <param name="mode">A command running mode, such as scripted or interactive.</param>
    /// <param name="plugin">A plug-in.</param>
    /// <param name="sizeRendering">The width and height of the rendering.</param>
    /// <param name="caption">The caption to display in the frame window.</param>
    /// <param name="channels">The color channel or channels.</param>
    /// <param name="reuseRenderWindow">true if the rendering window should be reused; otherwise, a new one will be instanciated.</param>
    /// <param name="clearLastRendering">true if the last rendering should be removed.</param>
    protected RenderPipeline(RhinoDoc doc,
                          Rhino.Commands.RunMode mode,
                          Rhino.PlugIns.PlugIn plugin,
                          System.Drawing.Size sizeRendering,
                          string caption,
                          Rhino.Render.RenderWindow.StandardChannels channels,
                          bool reuseRenderWindow,
                          bool clearLastRendering
                          )
    {
      Debug.Assert(Rhino.PlugIns.RenderPlugIn.RenderCommandContextPointer != IntPtr.Zero);

      m_serial_number = m_current_serial_number++;
      m_all_render_pipelines.Add(m_serial_number, this);
      m_size = sizeRendering;
      m_channels = channels;

      m_pSdkRender = UnsafeNativeMethods.Rdk_SdkRender_New(m_serial_number, Rhino.PlugIns.RenderPlugIn.RenderCommandContextPointer, plugin.NonConstPointer(), caption, reuseRenderWindow, clearLastRendering);
      m_session_id = UnsafeNativeMethods.CRhRdkSdkRender_RenderSessionId(m_pSdkRender);
      m_plugin = plugin;

      UnsafeNativeMethods.Rdk_RenderWindow_Initialize(m_pSdkRender, (int)channels, m_size.Width, m_size.Height);
    }
Ejemplo n.º 9
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="renderPanelType">
    /// See <see cref="RenderPanelType"/> for supported user interface types.
    /// </param>
    /// <param name="panelType">
    /// 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="alwaysShow">
    /// If true the custom user interface will always be visible, if false then
    /// it may be hidden or shown as requested by the user.
    /// </param>
    /// <param name="initialShow">
    /// Initial visibility state of the custom user interface control.
    /// </param>
    public void RegisterPanel(PlugIn plugin, RenderPanelType renderPanelType, Type panelType, string caption, bool alwaysShow, bool initialShow)
    {
      if (!typeof(IWin32Window).IsAssignableFrom(panelType))
        throw new ArgumentException("panelType must implement IWin32Window interface", "panelType");
      var constructor = panelType.GetConstructor(System.Type.EmptyTypes);
      if (!panelType.IsPublic || constructor == null)
        throw new ArgumentException("panelType must be a public class and have a parameterless constructor", "panelType");
      var attr = panelType.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
      if (attr.Length != 1)
        throw new ArgumentException("panelType must have a GuidAttribute", "panelType");

      if (g_existing_panels == null)
        g_existing_panels = new List<RenderPanelData>();
      // make sure the type is not already registered
      for (var i = 0; i < g_existing_panels.Count; i++)
      {
        var pd = g_existing_panels[i];
        if (pd != null && pd.PlugInId == plugin.Id && pd.PanelType == panelType)
          return;
      }
      var panel_data = new RenderPanelData { PlugInId = plugin.Id, PanelType = panelType, RenderPanelType = renderPanelType };
      g_existing_panels.Add(panel_data);


      g_create_panel_callback = OnCreatePanelCallback;
      g_visible_panel_callback = OnVisiblePanelCallback;
      g_destroy_panel_callback = OnDestroyPanelCallback;

      var render_panel_type = RenderPanelTypeToRhRdkCustomUiType(renderPanelType);

      UnsafeNativeMethods.CRhCmnRdkRenderPlugIn_RegisterCustomPlugInUi(
        render_panel_type,
        caption,
        panelType.GUID, 
        plugin.Id,
        alwaysShow,
        initialShow,
        g_create_panel_callback,
        g_visible_panel_callback,
        g_destroy_panel_callback);
    }
Ejemplo n.º 10
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
        );
    }