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

                if (this is UserDictionary)
                {
                    Guid id = RhinoApp.Rhino5Id;
                    m_native_pointer = UnsafeNativeMethods.CRhCmnUserData_New(m_serial_number, managed_type_id, id, description);
                }
                else
                {
                    PlugIns.PlugIn plugin    = PlugIns.PlugIn.Find(t.Assembly);
                    Guid           plugin_id = plugin.Id;
                    m_native_pointer = UnsafeNativeMethods.CRhCmnUserData_New(m_serial_number, managed_type_id, plugin_id, description);
                }
            }
#endif
            return(m_native_pointer);
        }
示例#2
0
 /// <summary>
 /// Call once to register a panel type which will get dynamically created
 /// and embedded in a Rhino docking/floating location.
 /// </summary>
 /// <param name="plugIn">
 /// Plug-in restringing the panel
 /// </param>
 /// <param name="type">
 /// Type of the control object to be displayed in the panel
 /// </param>
 /// <param name="caption">
 /// Panel caption also used as a tool-tip.  On Windows the panel may be
 /// displayed using the icon, caption or both.  On Mac the icon will be
 /// used and the caption will be the tool-tip.
 /// </param>
 /// <param name="icon">
 /// The panel icon.  On Windows the panel may be displayed using the icon,
 /// caption or both.  On Mac the icon will be used and the caption will be
 /// the tool-tip.
 /// </param>
 /// <param name="panelType">
 /// See <see cref="PanelType"/>
 /// </param>
 public static void Register(PlugIns.PlugIn plugIn, Type type, string caption, Icon icon, PanelType panelType)
 {
     // Plug-in that owns the panel, currently required.  Investigate changing to
     // System.Reflection.Assembly to allow Pixel.Rhino.UI to register panels directly
     if (plugIn == null)
     {
         throw new ArgumentNullException(nameof(plugIn));
     }
     Register(GetPlugInId(plugIn), type, caption, icon, panelType);
 }
示例#3
0
    /// <summary>
    /// Search the plug-in's dictionary for the specified plug-in and if it is
    /// not found then add it to the dictionary.
    /// </summary>
    /// <param name="plugIn"></param>
    /// <returns></returns>
    internal static RdkPlugIn GetRdkPlugIn(PlugIns.PlugIn plugIn)
    {
        var found = FromRhinoPlugIn(plugIn);

        if (null != found)
        {
            return(found);
        }
        var plugin_pointer = plugIn.NonConstPointer();

        return(AddPlugInToDictionary(plugin_pointer, plugIn.Id, plugIn.m_runtime_serial_number));
    }
示例#4
0
 private static Guid GetPlugInId(PlugIns.PlugIn plugIn)
 {
     try
     {
         var id = plugIn.Id;
         if (id != Guid.Empty)
         {
             return(id);
         }
         // Probabbly called by the plug-in constructor and the plug-in has not
         // been initialized by the plug-in loader yet so get the Id from the assembly
         var attribute = plugIn.GetType().Assembly.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true)[0] as System.Runtime.InteropServices.GuidAttribute;
         return(new Guid(attribute.Value));
     }
     catch
     {
         return(Guid.Empty);
     }
 }
示例#5
0
        /// <summary>
        /// Gets the object that is returned by PlugIn.GetPlugInObject for a given
        /// plug-in. This function attempts to find and load a plug-in with a given Id.
        /// When a plug-in is found, it's GetPlugInObject function is called and the
        /// result is returned here.
        /// Note the plug-in must have already been installed in Rhino or the plug-in manager
        /// will not know where to look for a plug-in with a matching id.
        /// </summary>
        /// <param name="pluginId">Guid for a given plug-in.</param>
        /// <returns>
        /// Result of PlugIn.GetPlugInObject for a given plug-in on success.
        /// </returns>
        public static object GetPlugInObject(Guid pluginId)
        {
            if (pluginId == Guid.Empty)
            {
                return(null);
            }

            // see if the plug-in is already loaded before doing any heavy lifting
            PlugIns.PlugIn p = Rhino.PlugIns.PlugIn.GetLoadedPlugIn(pluginId);
            if (p != null)
            {
                return(p.GetPlugInObject());
            }


            // load plug-in
            UnsafeNativeMethods.CRhinoPlugInManager_LoadPlugIn(pluginId);
            p = Rhino.PlugIns.PlugIn.GetLoadedPlugIn(pluginId);
            if (p != null)
            {
                return(p.GetPlugInObject());
            }

            IntPtr iunknown = UnsafeNativeMethods.CRhinoApp_GetPlugInObject(pluginId);

            if (IntPtr.Zero == iunknown)
            {
                return(null);
            }

            object rc;

            try
            {
                rc = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(iunknown);
            }
            catch (Exception)
            {
                rc = null;
            }
            return(rc);
        }
示例#6
0
 /// <summary>
 /// Search the Render Development Kit(RDK) plug-in dictionary for a render
 /// plug-in with the matching Rhino plug-in Id.
 /// </summary>
 /// <param name="plugIn">Rhino plug-in to search for.</param>
 /// <returns>
 /// If the plug-in is in the RDK dictionary then the dictionary plug-in
 /// object is returned, if not then null is returned.
 /// </returns>
 public static RdkPlugIn FromRhinoPlugIn(PlugIns.PlugIn plugIn)
 {
     return((null == plugIn) ? null : FromPlugInId(plugIn.Id));
 }
示例#7
0
        /*
         *  public static Pixel.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);
         *          Pixel.Rhino.Geometry.Curve crv = Pixel.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 Pixel.Rhino.Display.DisplayPipeline ConvertFromMRhinoDisplayPipeline(object source)
         *  {
         *    if (source != null)
         *    {
         *      try
         *      {
         *        Type base_type = Type.GetType("RMA.Pixel.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 Pixel.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>
        /// <since>5.0</since>
        public static IntPtr PlugInPointer(PlugIns.PlugIn plugin)
        {
            return(null == plugin ? IntPtr.Zero : plugin.NonConstPointer());
        }
示例#8
0
 /// <summary>
 /// You typically register your panel class in your plug-in's OnLoad
 /// function.  This will register your custom call with Rhino, Rhino will
 /// create an instance of your class the first time your panel is created
 /// and embed this instance of your class in a panel container.
 /// </summary>
 /// <param name="plugin">Plug-in this panel is associated with</param>
 /// <param name="panelType">
 /// Class type to construct when a panel is shown.  If your class is
 /// derived from Eto.Forms.Control it will work on both the Mac and
 /// Windows version of Rhino.  In addition Windows Rhino will support any
 /// class types that implement the IWin32Window interface or that are
 /// derived from System.Windows.FrameworkElement.  Mac Rhino will also
 /// support classes that are derived from NsView.  In addition to the
 /// type requirements the class must have a public constructor with no
 /// parameters or a constructor with a single uint that represents the
 /// document serial number and have a GuidAttribute applied with a
 /// unique Id.  n Windows there is only one panel created which gets
 /// recycled for each new document.  On the Mac a panel will be created
 /// for each open document and destroyed when the document closes.  In
 /// certain situations in Mac Rhino a a panel may get created and
 /// destroyed multiple times when opening/closing a panel while editing a
 /// document.
 /// </param>
 /// <param name="caption">
 /// Displays in the panel tab on Windows or at the top of the modeless
 /// window on Mac.
 /// </param>
 /// <param name="icon">
 /// Currently only used in Windows, use a 32bit depth icon in order to
 /// get proper transparency.
 /// </param>
 /// <since>5.0</since>
 public static void RegisterPanel(PlugIns.PlugIn plugin, Type panelType, string caption, System.Drawing.Icon icon)
 {
     RegisterPanel(plugin, panelType, caption, icon, PanelType.PerDoc);
 }
示例#9
0
 /// <summary>
 /// Call once to register a panel type which will get dynamically created
 /// and embedded in a Rhino docking/floating location.
 /// </summary>
 /// <param name="plugIn">
 /// Plug-in restringing the panel
 /// </param>
 /// <param name="type">
 /// Type of the control object to be displayed in the panel
 /// </param>
 /// <param name="caption">
 /// Panel caption also used as a tool-tip.  On Windows the panel may be
 /// displayed using the icon, caption or both.  On Mac the icon will be
 /// used and the caption will be the tool-tip.
 /// </param>
 /// <param name="icon">
 /// The panel icon.  On Windows the panel may be displayed using the icon,
 /// caption or both.  On Mac the icon will be used and the caption will be
 /// the tool-tip.
 /// </param>
 /// <param name="panelType">
 /// See <see cref="PanelType"/>
 /// </param>
 /// <since>6.1</since>
 public static void RegisterPanel(PlugIns.PlugIn plugIn, Type type, string caption, System.Drawing.Icon icon, PanelType panelType)
 {
     PanelSystem.Register(plugIn, type, caption, icon, panelType);
 }