Exemple #1
0
        internal virtual IntPtr NonConstPointer(bool createIfMissing)
        {
#if RHINO_SDK
            if (createIfMissing && IntPtr.Zero == m_pNativePointer)
            {
                m_serial_number = m_next_serial_number++;
                Type   t = GetType();
                Guid   managed_type_id = t.GUID;
                string description     = Description;

                if (this is UserDictionary)
                {
                    Guid id = Rhino.RhinoApp.Rhino5Id;
                    m_pNativePointer = UnsafeNativeMethods.CRhCmnUserData_New(m_serial_number, managed_type_id, id, description);
                }
                else
                {
                    Rhino.PlugIns.PlugIn plugin = PlugIns.PlugIn.Find(t.Assembly);
                    Guid plugin_id = plugin.Id;
                    m_pNativePointer = UnsafeNativeMethods.CRhCmnUserData_New(m_serial_number, managed_type_id, plugin_id, description);
                }
            }
#endif
            return(m_pNativePointer);
        }
 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;
 }
Exemple #3
0
        /// <summary>
        /// Register Salamander's UI Panel with Rhino for later use
        /// </summary>
        protected void RegisterPanelClasses()
        {
            Guid pluginId = new Guid("31ef1c91-653d-406d-a253-f39547c8f45a");

            R.PlugIns.PlugIn plugin = R.PlugIns.PlugIn.Find(pluginId);
            if (plugin == null)
            {
                R.PlugIns.PlugIn.LoadPlugIn(pluginId);
                plugin = R.PlugIns.PlugIn.Find(pluginId);
            }
            R.UI.Panels.RegisterPanel(plugin, typeof(SideBarUIHost), "Salamander 3", Salamander.Rhino.Properties.Resources.SalamanderIcon);
        }
        public static void RegisterProviders(System.Reflection.Assembly assembly, System.Guid pluginId)
        {
            Rhino.PlugIns.PlugIn plugin = Rhino.PlugIns.PlugIn.GetLoadedPlugIn(pluginId);
            if (plugin == null)
            {
                return;
            }

            Type[] exported_types = assembly.GetExportedTypes();

            if (exported_types != null)
            {
                List <Type> provider_types = new List <Type>();
                for (int i = 0; i < exported_types.Length; i++)
                {
                    Type t = exported_types[i];
                    if (!t.IsAbstract && t.IsSubclassOf(typeof(Rhino.Render.CustomRenderMesh.Provider)) && t.GetConstructor(new Type[] { }) != null)
                    {
                        provider_types.Add(t);
                    }
                }

                if (provider_types.Count == 0)
                {
                    return;
                }

                RdkPlugIn rdk_plugin = RdkPlugIn.GetRdkPlugIn(plugin);
                if (rdk_plugin == null)
                {
                    return;
                }

                foreach (Type t in provider_types)
                {
                    Provider p = System.Activator.CreateInstance(t) as Provider;
                    if (p == null)
                    {
                        continue;
                    }
                    IntPtr pCppObject = p.CreateCppObject(pluginId);
                    if (pCppObject != IntPtr.Zero)
                    {
                        //rdk_plugin.AddRegisteredCRMProvider(p);
                        m_all_providers.Add(p.m_runtime_serial_number, p);
                        UnsafeNativeMethods.Rdk_RegisterCRMProvider(pCppObject);
                    }
                }
            }
        }
            /// <summary>
            /// You typically register your panel class in your plug-in's OnLoad function.
            /// This informs Rhino of the existence of your panel class
            /// </summary>
            /// <param name="plugin">Plug-in this panel is associated with</param>
            /// <param name="panelType">
            /// Class type to construct when a panel is shown.  Currently only types
            /// that implement the IWin32Window interface are supported. The requirements
            /// for the class are that it has a parameterless constructor and have a
            /// GuidAttribute applied with a unique Guid
            /// </param>
            /// <param name="caption"></param>
            /// <param name="icon">Use a 32bit depth icon in order to get proper transparency</param>
            public static void RegisterPanel(Rhino.PlugIns.PlugIn plugin, Type panelType, string caption, System.Drawing.Icon icon)
            {
                if (!typeof(IWin32Window).IsAssignableFrom(panelType))
                {
                    throw new ArgumentException("panelType must implement IWin32Window interface", "panelType");
                }
                System.Reflection.ConstructorInfo 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");
                }
                object[] attr = panelType.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
                if (attr.Length != 1)
                {
                    throw new ArgumentException("panelType must have a GuidAttribute", "panelType");
                }

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

                panel_data.PlugInId  = plugin.Id;
                panel_data.PanelType = panelType;
                m_existing_panels.Add(panel_data);


                m_create_panel_callback  = OnCreatePanelCallback;
                m_visible_panel_callback = OnVisiblePanelCallback;
                UnsafeNativeMethods.RHC_RegisterTabbedDockBar(caption, panelType.GUID, plugin.Id, icon.Handle, m_create_panel_callback, m_visible_panel_callback);
            }
Exemple #6
0
        public static Type[] RegisterContentIo(System.Reflection.Assembly assembly, System.Guid pluginId)
        {
            Rhino.PlugIns.PlugIn plugin = Rhino.PlugIns.PlugIn.GetLoadedPlugIn(pluginId);
            if (plugin == null)
            {
                return(null);
            }

            //Find all public types exported in the plug-in that we're dealing with
            Type[] exported_types = assembly.GetExportedTypes();
            if (exported_types != null)
            {
                List <Type> contentio_types = new List <Type>();
                for (int i = 0; i < exported_types.Length; i++)
                {
                    //If the type is a Render.IOPlugIn, add it to the "to register" list.
                    Type t = exported_types[i];
                    if (!t.IsAbstract && t.IsSubclassOf(typeof(Rhino.Render.IOPlugIn)) && t.GetConstructor(new Type[] { }) != null)
                    {
                        contentio_types.Add(t);
                    }
                }

                // make sure that content types have not already been registered
                for (int i = 0; i < contentio_types.Count; i++)
                {
                    Type t = contentio_types[i];

                    if (!RdkPlugIn.RenderContentIoTypeIsRegistered(t))
                    {
                        //The object registers itself in a static array
                        IOPlugIn pi = System.Activator.CreateInstance(t) as IOPlugIn;
                        pi.Construct(pluginId);
                    }
                }

                return(contentio_types.ToArray());
            }
            return(null);
        }
        /// <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_plugin     = plugin;

            UnsafeNativeMethods.Rdk_RenderWindow_Initialize(m_pSdkRender, (int)channels, m_size.Width, m_size.Height);
        }
    /// <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_plugin = plugin;

      UnsafeNativeMethods.Rdk_RenderWindow_Initialize(m_pSdkRender, (int)channels, m_size.Width, m_size.Height);
    }
 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;
 }
Exemple #10
0
        /*
         *  public static Rhino.Geometry.Curve TryCopyFromOnCurve(object source)
         *  {
         *    if (source != null)
         *    {
         *      try
         *      {
         *        Type base_type = Type.GetType("RMA.OpenNURBS.OnCurve");
         *        System.Type t = source.GetType();
         *        if (t.IsAssignableFrom(base_type))
         *        {
         *          System.Reflection.PropertyInfo pi = t.GetProperty("InternalPointer");
         *          IntPtr ptr = (IntPtr)pi.GetValue(source, null);
         *          Rhino.Geometry.Curve crv = Rhino.Geometry.Curve.CreateCurveHelper(ptr, null);
         *          crv.NonConstPointer();
         *          return crv;
         *        }
         *      }
         *      catch (Exception)
         *      {
         *      }
         *    }
         *    return null;
         *  }
         *
         *  /// <summary>
         *  /// Do not hold on to the returned class outside the scope of your current function.
         *  /// </summary>
         *  /// <param name="source">-</param>
         *  /// <returns>-</returns>
         *  public static Rhino.Display.DisplayPipeline ConvertFromMRhinoDisplayPipeline(object source)
         *  {
         *    if (source != null)
         *    {
         *      try
         *      {
         *        Type base_type = Type.GetType("RMA.Rhino.MRhinoDisplayPipeline");
         *        System.Type t = source.GetType();
         *        if (t.IsAssignableFrom(base_type))
         *        {
         *          System.Reflection.PropertyInfo pi = t.GetProperty("InternalPointer");
         *          IntPtr ptr = (IntPtr)pi.GetValue(source, null);
         *          return new Rhino.Display.DisplayPipeline(ptr);
         *        }
         *      }
         *      catch (Exception)
         *      {
         *      }
         *    }
         *    return null;
         *  }
         */
#if RHINO_SDK
        /// <summary>
        /// Gets a C++ plug-in pointer for a given RhinoCommon plug-in.
        /// <para>This is a Rhino SDK function.</para>
        /// </summary>
        /// <param name="plugin">A plug-in.</param>
        /// <returns>A pointer.</returns>
        public static IntPtr PlugInPointer(Rhino.PlugIns.PlugIn plugin)
        {
            return(null == plugin ? IntPtr.Zero : plugin.NonConstPointer());
        }