Beispiel #1
0
        public static string[] AvailableFontFaceNames()
        {
            IntPtr pStringArray = UnsafeNativeMethods.ON_StringArray_New();
            int    count        = UnsafeNativeMethods.CRhinoFontTable_GetFontNames(pStringArray);

            string[] rc = new string[count];
            using (var sh = new StringHolder())
            {
                IntPtr pStringHolder = sh.NonConstPointer();
                for (int i = 0; i < count; i++)
                {
                    UnsafeNativeMethods.ON_StringArray_Get(pStringArray, i, pStringHolder);
                    rc[i] = sh.ToString();
                }
            }
            UnsafeNativeMethods.ON_StringArray_Delete(pStringArray);
            if (count < 1)
            {
                System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
                rc = new string[fonts.Families.Length];
                for (int i = 0; i < fonts.Families.Length; i++)
                {
                    rc[i] = fonts.Families[i].Name;
                }
            }
            Array.Sort(rc);
            return(rc);
        }
        /// <summary>
        /// Gets a copy of all (user key string, user value string) pairs attached to this geometry.
        /// </summary>
        /// <returns>A new collection.</returns>
        internal System.Collections.Specialized.NameValueCollection _GetUserStrings()
        {
            System.Collections.Specialized.NameValueCollection rc = new System.Collections.Specialized.NameValueCollection();
            IntPtr const_ptr_this  = ConstPointer();
            int    count           = 0;
            IntPtr ptr_userstrings = UnsafeNativeMethods.ON_Object_GetUserStrings(const_ptr_this, ref count);

            using (var keyHolder = new StringHolder())
                using (var valueHolder = new StringHolder())
                {
                    IntPtr pKeyHolder   = keyHolder.NonConstPointer();
                    IntPtr pValueHolder = valueHolder.NonConstPointer();

                    for (int i = 0; i < count; i++)
                    {
                        UnsafeNativeMethods.ON_UserStringList_KeyValue(ptr_userstrings, i, true, pKeyHolder);
                        UnsafeNativeMethods.ON_UserStringList_KeyValue(ptr_userstrings, i, false, pValueHolder);
                        string key   = keyHolder.ToString();
                        string value = valueHolder.ToString();
                        if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                        {
                            rc.Add(key, value);
                        }
                    }
                }

            if (IntPtr.Zero != ptr_userstrings)
            {
                UnsafeNativeMethods.ON_UserStringList_Delete(ptr_userstrings);
            }

            return(rc);
        }
Beispiel #3
0
        /// <summary>
        /// Override this function to provide information about which texture is used for
        /// the standard (ie - defined in ON_Texture) texture channels.
        /// </summary>
        /// <param name="slot">An valid slot.</param>
        /// <returns>The texture used for the channel.</returns>
        public virtual string TextureChildSlotName(StandardChildSlots slot)
        {
            if (IsNativeWrapper())
            {
                StringIds iString = StringIds.DiffuseChildSlotName;
                switch (slot)
                {
                case StandardChildSlots.Diffuse:
                    iString = StringIds.DiffuseChildSlotName;
                    break;

                case StandardChildSlots.Transparency:
                    iString = StringIds.TransparencyChildSlotName;
                    break;

                case StandardChildSlots.Bump:
                    iString = StringIds.BumpChildSlotName;
                    break;

                case StandardChildSlots.Environment:
                    iString = StringIds.EnvironmentChildSlotName;
                    break;
                }
                return(GetString(iString));
            }

            using (var sh = new StringHolder())
            {
                IntPtr pString = sh.NonConstPointer();
                UnsafeNativeMethods.Rdk_RenderMaterial_CallTextureChildSlotNameBase(ConstPointer(), pString, (int)slot);
                return(sh.ToString());
            }
        }
Beispiel #4
0
 public string ToString(IFormatProvider provider)
 {
     using (var sh = new StringHolder())
     {
         UnsafeNativeMethods.Rdk_Variant_GetStringValue(ConstPointer(), sh.NonConstPointer());
         return(sh.ToString());
     }
 }
 /// <summary>
 /// Gets localized unit system name.  Uses current application locale id.
 /// </summary>
 /// <param name="units">The unit system.</param>
 /// <param name="capitalize">true if the name should be capitalized.</param>
 /// <param name="singular">true if the name is expressed for a singular element.</param>
 /// <param name="abbreviate">true if name should be the abbreviation.</param>
 /// <returns>The unit system name.</returns>
 /// <since>5.0</since>
 public static string UnitSystemName(UnitSystem units, bool capitalize, bool singular, bool abbreviate)
 {
     using (var sh = new StringHolder())
     {
         IntPtr pString = sh.NonConstPointer();
         UnsafeNativeMethods.CRhinoApp_UnitSystemName((int)units, capitalize, singular, abbreviate, pString);
         return(sh.ToString());
     }
 }
 /// <summary>
 /// Get a string version of a number in a given unit system / display mode.
 /// </summary>
 /// <param name="x">The number to format into a string.</param>
 /// <param name="units">The unit system for the number.</param>
 /// <param name="mode">How the number should be formatted.</param>
 /// <param name="precision">The precision of the number.</param>
 /// <param name="appendUnitSystemName">Adds unit system name to the end of the number.</param>
 /// <returns>The formatted number.</returns>
 /// <since>5.0</since>
 public static string FormatNumber(double x, UnitSystem units, DistanceDisplayMode mode, int precision, bool appendUnitSystemName)
 {
     using (var sh = new StringHolder())
     {
         IntPtr pString = sh.NonConstPointer();
         UnsafeNativeMethods.RHC_RhinoFormatNumber(x, (int)units, (int)mode, precision, appendUnitSystemName, pString);
         return(sh.ToString());
     }
 }
Beispiel #7
0
 public string GetUnusedInstanceDefinitionName(string root, uint defaultSuffix)
 {
     using (var sh = new StringHolder())
     {
         IntPtr pString = sh.NonConstPointer();
         UnsafeNativeMethods.CRhinoInstanceDefinitionTable_GetUnusedName3(m_doc.m_docId, root, defaultSuffix, pString);
         return(sh.ToString());
     }
 }
 /// <summary>
 /// Gets unused linetype name used as default when creating new linetypes.
 /// </summary>
 /// <returns>The unused linetype name.</returns>
 /// <since>6.0</since>
 public string GetUnusedLinetypeName()
 {
     using (var sh = new StringHolder())
     {
         IntPtr pString = sh.NonConstPointer();
         UnsafeNativeMethods.CRhinoLinetypeTable_GetUnusedLinetypeName(m_doc.RuntimeSerialNumber, pString);
         return(sh.ToString());
     }
 }
 /// <summary>
 /// Gets unsed instance definition name used as default when creating
 /// new instance definitions.
 /// </summary>
 /// <returns>An unused instance definition name string.</returns>
 public string GetUnusedInstanceDefinitionName()
 {
     using (var sh = new StringHolder())
     {
         IntPtr ptr_string = sh.NonConstPointer();
         UnsafeNativeMethods.CRhinoInstanceDefinitionTable_GetUnusedName(m_doc.m_docId, ptr_string);
         return(sh.ToString());
     }
 }
 public static string StringFromProjection(BackgroundProjections projection)
 {
     using (var sh = new StringHolder())
     {
         IntPtr pString = sh.NonConstPointer();
         UnsafeNativeMethods.Rdk_SimulatedTexture_StringFromProjection(pString, (int)projection);
         return(sh.ToString());
     }
 }
 public string GetUnusedDimensionStyleName()
 {
     using (var sh = new StringHolder())
     {
         IntPtr pStringHolder = sh.NonConstPointer();
         UnsafeNativeMethods.CRhinoDimStyleTable_GetUnusedDimensionStyleName(m_doc.m_docId, pStringHolder);
         return(sh.ToString());
     }
 }
Beispiel #12
0
 /// <summary>
 /// Gets unused linetype name used as default when creating new linetypes.
 /// </summary>
 /// <param name="ignoreDeleted">
 /// If this is true then a name used by a deleted linetype is allowed.
 /// </param>
 /// <returns>The unused linetype name.</returns>
 public string GetUnusedLinetypeName(bool ignoreDeleted)
 {
     using (var sh = new StringHolder())
     {
         IntPtr pString = sh.NonConstPointer();
         UnsafeNativeMethods.CRhinoLinetypeTable_GetUnusedLinetypeName(m_doc.m_docId, ignoreDeleted, pString);
         return(sh.ToString());
     }
 }
        /*
         * /// <summary>
         * /// Shows the content chooser to allow the user to select a new or existing content.
         * /// </summary>
         * /// <param name="defaultType">The content type that will be initially selected in the 'New' tab.</param>
         * /// <param name="defaultInstanceId">The content instance that will be initially selected in the 'Existing' tab.</param>
         * /// <param name="kinds">Which content kinds will be displayed.</param>
         * /// <param name="instanceIdOut">The UUID of the chosen item. Depending on eRhRdkSccResult, this can be the type id of a content type or the instance id of an existing content.</param>
         * /// <param name="flags">Tabs specifications.</param>
         * /// <param name="doc">A Rhino document.</param>
         * /// <returns>The result.</returns>
         * public static ShowContentChooserResults ShowContentChooser(Guid defaultType, Guid defaultInstanceId, RenderContentKind kinds, ref Guid instanceIdOut, ShowContentChooserFlags flags, RhinoDoc doc)
         * {
         * return (ShowContentChooserResults)UnsafeNativeMethods.Rdk_Globals_ShowContentChooser(defaultType, defaultInstanceId, RenderContent.KindString(kinds), ref instanceIdOut, (int)flags, doc.m_docId);
         * }
         */

        /// <summary>
        /// Finds a file and also handles network shares.
        /// <remarks>This is a replacement for CRhinoFileUtilities::FindFile().</remarks>
        /// </summary>
        /// <param name="fullPathToFile">The file to be found.</param>
        /// <returns>The found file.</returns>
        public static string FindFile(string fullPathToFile)
        {
            using (var sh = new StringHolder())
            {
                IntPtr pString = sh.NonConstPointer();
                bool   found   = (1 == UnsafeNativeMethods.Rdk_Globals_FindFile(fullPathToFile, pString));

                return(found ? sh.ToString() : null);
            }
        }
Beispiel #14
0
 /// <summary>
 /// Returns a string that represents the pattern of the linetype, which can be used in user interface.
 /// Values greater than zero represent line segments,
 /// and values less than or equal to zero represent space segments.
 /// </summary>
 /// <param name="millimeters">
 /// If true, the string is formatted in millimeters.
 /// If false, the string is formatted in inches.
 /// </param>
 /// <returns>The pattern string.</returns>
 /// <since>7.4</since>
 public string PatternString(bool millimeters)
 {
     using (var sh = new StringHolder())
     {
         IntPtr ptr_string     = sh.NonConstPointer();
         IntPtr ptr_const_this = ConstPointer();
         UnsafeNativeMethods.RHC_RhPatternStringFromLinetype(ptr_const_this, millimeters, ptr_string);
         return(sh.ToString());
     }
 }
        /// <summary>
        /// Gets user string from this geometry.
        /// </summary>
        /// <param name="key">id used to retrieve the string.</param>
        /// <returns>string associated with the key if successful. null if no key was found.</returns>
        internal string _GetUserString(string key)
        {
            IntPtr pThis = ConstPointer();

            using (var sh = new StringHolder())
            {
                IntPtr pStringHolder = sh.NonConstPointer();
                UnsafeNativeMethods.ON_Object_GetUserString(pThis, key, pStringHolder);
                return(sh.ToString());
            }
        }
        string GetStringHelper(int which)
        {
            IntPtr pConstThis = ConstPointer();

            using (var sh = new StringHolder())
            {
                IntPtr pString = sh.NonConstPointer();
                UnsafeNativeMethods.CArgsRhinoGetLine_GetString(pConstThis, which, pString);
                return(sh.ToString());
            }
        }
Beispiel #17
0
        string GetStringHelper(UnsafeNativeMethods.ArgsGetPolylineStringConsts which)
        {
            IntPtr ptr_const_this = ConstPointer();

            using (var sh = new StringHolder())
            {
                IntPtr ptr_string = sh.NonConstPointer();
                UnsafeNativeMethods.CArgsRhinoGetPolyline_GetString(ptr_const_this, which, ptr_string);
                return(sh.ToString());
            }
        }
Beispiel #18
0
        string GetString(int which)
        {
            IntPtr ptr = ConstPointer();

            using (var sh = new StringHolder())
            {
                IntPtr ptr_string = sh.NonConstPointer();
                UnsafeNativeMethods.ON_3dmObjectAttributes_GetSetString(ptr, which, false, null, ptr_string);
                return(sh.ToString());
            }
        }
        /// <summary>
        /// Determines if an object is valid. Also provides a report on errors if this
        /// object happens not to be valid.
        /// </summary>
        /// <param name="log">A textual log. This out parameter is assigned during this call.</param>
        /// <returns>true if this object is valid; false otherwise.</returns>
        /// <since>5.0</since>
        public bool IsValidWithLog(out string log)
        {
            IntPtr const_ptr_this = ConstPointer();

            using (var sh = new StringHolder())
            {
                IntPtr ptr_string = sh.NonConstPointer();
                bool   rc         = UnsafeNativeMethods.ON_Object_IsValid(const_ptr_this, ptr_string);
                log = sh.ToString();
                return(rc);
            }
        }
 public string ModelPathFromSerialNumber(uint modelSerialNumber)
 {
     using (var sh = new StringHolder())
     {
         IntPtr ptr_string = sh.NonConstPointer();
         bool   result     = UnsafeNativeMethods.CRhinoWorksession_ModelPathFromSerialNumber(m_doc.RuntimeSerialNumber, modelSerialNumber, ptr_string);
         if (result)
         {
             return(sh.ToString());
         }
     }
     return(null);
 }
Beispiel #21
0
        private string GetPath(bool relative)
        {
            using (var holder = new StringHolder())
            {
                if (UnsafeNativeMethods.ON_FileReference_GetFullOrRelativePath(
                        m_const_ptr, holder.NonConstPointer(), relative))
                {
                    return(holder.ToString());
                }

                throw new ApplicationException("Error occurred while marshalling path.");
            }
        }
        /// <summary>
        /// Prompts the user for a save file name and the width, height and depth of an image to be saved.
        /// </summary>
        /// <param name="filename">The original file path.</param>
        /// <param name="width">A width.</param>
        /// <param name="height">An height.</param>
        /// <param name="colorDepth">A color depth.</param>
        /// <returns>The new file name.</returns>
        public static string PromptForSaveImageFileParameters(string filename, ref int width, ref int height, ref int colorDepth)
        {
            using (var sh = new StringHolder())
            {
                IntPtr pString = sh.NonConstPointer();
                bool   bRet    = 1 == UnsafeNativeMethods.Rdk_Globals_PromptForSaveImageFileParams(filename, ref width, ref height, ref colorDepth, pString);

                if (bRet)
                {
                    return(sh.ToString());
                }
            }
            return(null);
        }
Beispiel #23
0
 /// <summary>
 /// Returns the detail view object's scale as a formatted string.
 /// The detail view object's viewport must be to parallel projection.
 /// </summary>
 /// <param name="format">The scale format.</param>
 /// <param name="value">The formatted string</param>
 /// <returns>true if successful, false otherwise</returns>
 /// <since>7.0</since>
 public bool GetFormattedScale(ScaleFormat format, out string value)
 {
     value = null;
     using (var sh = new StringHolder())
     {
         IntPtr ptr_const_this = ConstPointer();
         IntPtr ptr_string     = sh.NonConstPointer();
         if (UnsafeNativeMethods.CRhinoDetailViewObject_GetFormattedScale(ptr_const_this, (uint)format, ptr_string))
         {
             value = sh.ToString();
             return(true);
         }
     }
     return(false);
 }
        public RenderPlugInList()
        {
            IntPtr pList = UnsafeNativeMethods.Rdk_RenderPlugInInfo_New();

            if (pList != IntPtr.Zero)
            {
                bool b = true;

                while (b)
                {
                    using (var sh = new StringHolder())
                    {
                        IntPtr pString = sh.NonConstPointer();
                        Guid   uuid    = new Guid();
                        b = 1 == UnsafeNativeMethods.Rdk_RenderPlugInInfo(pList, ref uuid, pString);

                        Add(new RenderPlugInInfo(uuid, pString.ToString()));
                    }
                }

                UnsafeNativeMethods.Rdk_RenderPlugInInfo_Delete(pList);
            }
        }
        internal static ConstructionPlane FromIntPtr(IntPtr pConstructionPlane)
        {
            if (IntPtr.Zero == pConstructionPlane)
            {
                return(null);
            }
            ConstructionPlane rc = new ConstructionPlane();

            using (var sh = new StringHolder())
            {
                IntPtr ptr_string = sh.NonConstPointer();
                UnsafeNativeMethods.ON_3dmConstructionPlane_Copy(pConstructionPlane,
                                                                 ref rc.m_plane,
                                                                 ref rc.m_grid_spacing,
                                                                 ref rc.m_snap_spacing,
                                                                 ref rc.m_grid_line_count,
                                                                 ref rc.m_grid_thick_frequency,
                                                                 ref rc.m_bDepthBuffered,
                                                                 ptr_string);
                rc.m_name = sh.ToString();
            }
            return(rc);
        }
Beispiel #26
0
 /// <summary>
 /// Gets a plug-in name for an installed plug-in given the path to that plug-in.
 /// </summary>
 /// <param name="pluginPath">The path of the plug-in.</param>
 /// <returns>The plug-in name.</returns>
 public static string NameFromPath(string pluginPath)
 {
   string rc;
   using (var sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.CRhinoPlugInManager_NameFromPath(pluginPath, pString);
     rc = sh.ToString();
   }
   if (string.IsNullOrEmpty(rc))
   {
     // 2-Nov-2011 Dale Fugier
     // Look in our local collection of plug-ins. We may be in "OnLoad"
     // and the plug-in hasn't officially been registered with Rhino.
     for (int i = 0; i < m_plugins.Count; i++)
     {
       if (string.Compare(m_plugins[i].Assembly.Location, pluginPath, StringComparison.OrdinalIgnoreCase) == 0)
       {
         rc = m_plugins[i].Name;
         break;
       }
     }
   }
   return rc;
 }
 /// <summary>
 /// Determines if an object is valid. Also provides a report on errors if this
 /// object happens not to be valid.
 /// </summary>
 /// <param name="log">A textual log. This out parameter is assigned during this call.</param>
 /// <returns>true if this object is valid; false otherwise.</returns>
 public bool IsValidWithLog(out string log)
 {
   IntPtr pConstThis = ConstPointer();
   using (var sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     bool rc = UnsafeNativeMethods.ON_Object_IsValid(pConstThis, pString);
     log = sh.ToString();
     return rc;
   }
 }
Beispiel #28
0
 /// <summary>
 /// Returns the name of a group.
 /// </summary>
 /// <param name="groupIndex">The index of the group.</param>
 /// <returns>The group name.</returns>
 /// <since>5.0</since>
 public string GroupName(int groupIndex)
 {
     using (var sh = new StringHolder())
     {
         bool worked = UnsafeNativeMethods.CRhinoGroupTable_GroupName(m_doc.RuntimeSerialNumber, groupIndex, sh.NonConstPointer());
         if (!worked)
         {
             throw new ArgumentOutOfRangeException("groupIndex");
         }
         return(sh.ToString());
     }
 }
 /// <summary>
 /// Gets the path to an installed plug-in given the id of that plug-in
 /// </summary>
 /// <param name="pluginId"></param>
 /// <returns></returns>
 public static string PathFromId(Guid pluginId)
 {
   using (var sh = new StringHolder())
   {
     IntPtr ptr_string = sh.NonConstPointer();
     UnsafeNativeMethods.CRhinoPlugInManager_PathFromId(pluginId, ptr_string);
     return sh.ToString();
   }
 }
Beispiel #30
0
 /// <summary>
 /// Gets the debug dumps. This is a text description of the geometric contents.
 /// DebugDump() is intended for debugging and is not suitable for creating high
 /// quality text descriptions of an object.
 /// </summary>
 /// <param name="geometry">Some geometry.</param>
 /// <returns>A debug dump text.</returns>
 public static string DebugDumpToString(Rhino.Geometry.GeometryBase geometry)
 {
   IntPtr pConstThis = geometry.ConstPointer();
   using (var sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.ON_Object_Dump(pConstThis, pString);
     return sh.ToString();
   }
 }
Beispiel #31
0
    internal static void WriteIntoSerializationInfo(IntPtr pRhCmnProfileContext, System.Runtime.Serialization.SerializationInfo info, string prefixStrip)
    {
      const int _string = 1;
      const int _multistring = 2;
      const int _uuid = 3;
      const int _color = 4;
      const int _int = 5;
      const int _double = 6;
      const int _rect = 7;
      const int _point = 8;
      const int _3dpoint = 9;
      const int _xform = 10;
      const int _3dvector = 11;
      const int _meshparams = 12;
      const int _buffer = 13;
      const int _bool = 14;
      int count = UnsafeNativeMethods.CRhCmnProfileContext_Count(pRhCmnProfileContext);
      using (StringHolder sectionholder = new StringHolder())
      using (StringHolder entryholder = new StringHolder())
      {
        IntPtr pStringSection = sectionholder.NonConstPointer();
        IntPtr pStringEntry = entryholder.NonConstPointer();
        for (int i = 0; i < count; i++)
        {
          int pctype = 0;
          UnsafeNativeMethods.CRhCmnProfileContext_Item(pRhCmnProfileContext, i, pStringSection, pStringEntry, ref pctype);
          string section = sectionholder.ToString();
          string entry = entryholder.ToString();
          if (string.IsNullOrEmpty(entry))
            continue;
          string name = string.IsNullOrEmpty(section) ? entry : section + "\\" + entry;
          if (name.StartsWith(prefixStrip + "\\"))
            name = name.Substring(prefixStrip.Length + 1);
          name = name.Replace("\\", "::");

          switch (pctype)
          {
            case _string:
              {
                UnsafeNativeMethods.CRhinoProfileContext_LoadString(pRhCmnProfileContext, section, entry, pStringEntry);
                string val = entryholder.ToString();
                info.AddValue(name, val);
              }
              break;
            case _multistring:
              {
                IntPtr pStrings = UnsafeNativeMethods.ON_StringArray_New();
                int array_count = UnsafeNativeMethods.CRhinoProfileContext_LoadStrings(pRhCmnProfileContext, section, entry, pStrings);
                string[] s = new string[array_count];
                for( int j=0; j<array_count; j++ )
                {
                  UnsafeNativeMethods.ON_StringArray_Get(pStrings, j, pStringEntry);
                  s[j] = entryholder.ToString();
                }
                info.AddValue(name, s);
              }
              break;
            case _uuid:
              {
                Guid id = Guid.Empty;
                UnsafeNativeMethods.CRhinoProfileContext_LoadGuid(pRhCmnProfileContext, section, entry, ref id);
                info.AddValue(name, id);
              }
              break;
            case _color:
              {
                int abgr = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadColor(pRhCmnProfileContext, section, entry, ref abgr);
                System.Drawing.Color c = Interop.ColorFromWin32(abgr);
                //string s = System.Drawing.ColorTranslator.ToHtml(c);
                info.AddValue(name, c);
              }
              break;
            case _int:
              {
                int ival = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadInt(pRhCmnProfileContext, section, entry, ref ival);
                info.AddValue(name, ival);
              }
              break;
            case _double:
              {
                double dval = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadDouble(pRhCmnProfileContext, section, entry, ref dval);
                info.AddValue(name, dval);
              }
              break;
            case _rect:
              {
                int left = 0, top = 0, right = 0, bottom = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadRect(pRhCmnProfileContext, section, entry, ref left, ref top, ref right, ref bottom);
                System.Drawing.Rectangle r = System.Drawing.Rectangle.FromLTRB(left, top, right, bottom);
                info.AddValue(name, r);
              }
              break;
            case _point:
              {
                int x = 0, y = 0;
                UnsafeNativeMethods.CRhinoProfileContext_LoadPoint(pRhCmnProfileContext, section, entry, ref x, ref y);
                System.Drawing.Point pt = new System.Drawing.Point(x, y);
                info.AddValue(name, pt);
              }
              break;
            case _3dpoint:
              {
                Rhino.Geometry.Point3d pt = new Geometry.Point3d();
                UnsafeNativeMethods.CRhinoProfileContext_LoadPoint3d(pRhCmnProfileContext, section, entry, ref pt);
                info.AddValue(name, pt);
              }
              break;
            case _xform:
              {
                Rhino.Geometry.Transform xf = new Geometry.Transform();
                UnsafeNativeMethods.CRhinoProfileContext_LoadXform(pRhCmnProfileContext, section, entry, ref xf);
                info.AddValue(name, xf);
              }
              break;
            case _3dvector:
              {
                Rhino.Geometry.Vector3d vec = new Geometry.Vector3d();
                UnsafeNativeMethods.CRhinoProfileContext_LoadVector3d(pRhCmnProfileContext, section, entry, ref vec);
                info.AddValue(name, vec);
              }
              break;
            case _meshparams:
              {
                Rhino.Geometry.MeshingParameters mp = new Geometry.MeshingParameters();
                UnsafeNativeMethods.CRhinoProfileContext_LoadMeshParameters(pRhCmnProfileContext, section, entry, mp.NonConstPointer());
                info.AddValue(name, mp);
                mp.Dispose();
              }
              break;
            case _buffer:
              {
                //not supported yet
                //int buffer_length = UnsafeNativeMethods.CRhinoProfileContext_BufferLength(pRhCmnProfileContext, section, entry);
                //byte[] buffer = new byte[buffer_length];
                //UnsafeNativeMethods.CRhinoProfileContext_LoadBuffer(pRhCmnProfileContext, section, entry, buffer_length, buffer);
                //info.AddValue(name, buffer);
              }
              break;
            case _bool:
              {
                bool b = false;
                UnsafeNativeMethods.CRhinoProfileContext_LoadBool(pRhCmnProfileContext, section, entry, ref b);
                info.AddValue(name, b);
              }
              break;
          }
        }
      }
    }
 /// <summary>
 /// Gets user string from this geometry.
 /// </summary>
 /// <param name="key">id used to retrieve the string.</param>
 /// <returns>string associated with the key if successful. null if no key was found.</returns>
 internal string _GetUserString(string key)
 {
   IntPtr pThis = ConstPointer();
   using (var sh = new StringHolder())
   {
     IntPtr pStringHolder = sh.NonConstPointer();
     UnsafeNativeMethods.ON_Object_GetUserString(pThis, key, pStringHolder);
     return sh.ToString();
   }
 }
    /// <summary>
    /// Gets a copy of all (user key string, user value string) pairs attached to this geometry.
    /// </summary>
    /// <returns>A new collection.</returns>
    internal System.Collections.Specialized.NameValueCollection _GetUserStrings()
    {
      System.Collections.Specialized.NameValueCollection rc = new System.Collections.Specialized.NameValueCollection();
      IntPtr pThis = ConstPointer();
      int count = 0;
      IntPtr pUserStrings = UnsafeNativeMethods.ON_Object_GetUserStrings(pThis, ref count);

      using( var keyHolder = new StringHolder() )
      using( var valueHolder = new StringHolder() )
      {
        IntPtr pKeyHolder = keyHolder.NonConstPointer();
        IntPtr pValueHolder = valueHolder.NonConstPointer();

        for (int i = 0; i < count; i++)
        {
          UnsafeNativeMethods.ON_UserStringList_KeyValue(pUserStrings, i, true, pKeyHolder);
          UnsafeNativeMethods.ON_UserStringList_KeyValue(pUserStrings, i, false, pValueHolder);
          string key = keyHolder.ToString();
          string value = valueHolder.ToString();
          if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
            rc.Add(key, value);
        }
      }

      if (IntPtr.Zero != pUserStrings)
        UnsafeNativeMethods.ON_UserStringList_Delete(pUserStrings);

      return rc;
    }
      /// <summary>
      /// Passed as a delegate to LicenseUtils.GetLicense(), will call the C++
      /// ValidateProductKey() method then and copy CRhinoLicenseValidator C++
      /// data to the LicenseData output object.
      /// </summary>
      /// <param name="productKey"></param>
      /// <param name="licenseData">
      /// Key information is coppied to this object
      /// </param>
      /// <returns></returns>
      public ValidateResult ValidateProductKey(string productKey, out LicenseData licenseData)
      {
        // Create an empty LicenseData
        licenseData = new LicenseData();
        var rc = 0;
        // Call back into the C++ unmanaged function pointer
        if (IntPtr.Zero != _validator)
          rc = UnsafeNativeMethods.RHC_ValidateProductKey(productKey, _validator);
        if (rc != 1)
          return (-1 == rc ? ValidateResult.ErrorHideMessage : ValidateResult.ErrorShowMessage);
        // Copy unmanaged C++ validate data to the managed LicenseData
        var year = 0;
        var month = 0;
        var day = 0;
        var hour = 0;
        var minute = 0;
        var second = 0;
        var licenseCount = 0;
        var buildType = 0;
        IntPtr hIcon;
        // String placeholders
        using (var shSerailNumber = new StringHolder())
        using (var shLicenseTitle = new StringHolder())
        using (var shProductLicense = new StringHolder())
        {
          // Get ON_wString pointers
          var pSerialNumber = shSerailNumber.NonConstPointer();
          var pLicenseTitle = shLicenseTitle.NonConstPointer();
          var pProductLicense = shProductLicense.NonConstPointer();
          hIcon = UnsafeNativeMethods.RHC_ExtractLicenseData(_validator,
                                                             ref year,
                                                             ref month,
                                                             ref day,
                                                             ref hour,
                                                             ref minute,
                                                             ref second,
                                                             pSerialNumber,
                                                             ref licenseCount,
                                                             pLicenseTitle,
                                                             pProductLicense,
                                                             ref buildType);
          // Copy ON_wString values to C# strings
          licenseData.SerialNumber = shSerailNumber.ToString();
          licenseData.LicenseTitle = shLicenseTitle.ToString();
          licenseData.ProductLicense = shProductLicense.ToString();
        }
        // Set the expiration date using the C++ date data
        if (year >= 2010)
          licenseData.DateToExpire = new DateTime(year, month, day, hour, minute, second);
        licenseData.LicenseCount = licenseCount;
        licenseData.BuildType = (LicenseBuildType)buildType;
        // Icon associated with the specified license type
        if (hIcon != IntPtr.Zero)
        {
          // 19 May 214 - John Morse
          // Added try catch to the icon copy code, an exception here should not cause
          // license validation to fail.
          try
          {
            // Create a new icon from the handle.
            var newIcon = System.Drawing.Icon.FromHandle(hIcon);

            // Set the LicenseData icon. Note, LicenseData creates it's own copy of the icon.
            licenseData.ProductIcon = newIcon;

            // When using Icon::FromHandle, you must dispose of the original icon by using the
            // DestroyIcon method in the Win32 API to ensure that the resources are released.
            if (newIcon != null)
              DestroyIcon(newIcon.Handle);
          }
          catch { }
        }

        return ValidateResult.Success;
      }
Beispiel #35
0
 /// <summary>
 /// Gets names of all "non-test" commands for a given plug-in.
 /// </summary>
 /// <param name="pluginId">The plug-in ID.</param>
 /// <returns>An array with all plug-in names. This can be empty, but not null.</returns>
 public static string[] GetEnglishCommandNames(Guid pluginId)
 {
   IntPtr pStrings = UnsafeNativeMethods.ON_StringArray_New();
   int count = UnsafeNativeMethods.CRhinoPluginManager_GetCommandNames(pluginId, pStrings);
   string[] rc = new string[count];
   using (var sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     for (int i = 0; i < count; i++)
     {
       UnsafeNativeMethods.ON_StringArray_Get(pStrings, i, pString);
       rc[i] = sh.ToString();
     }
   }
   UnsafeNativeMethods.ON_StringArray_Delete(pStrings);
   return rc;
 }
Beispiel #36
0
 /// <summary>
 /// Returns a list of output types which your renderer can write.
 /// <para>The default implementation returns bmp, jpg, png, tif, tga.</para>
 /// </summary>
 /// <returns>A list of file types.</returns>
 protected virtual List<Rhino.FileIO.FileType> SupportedOutputTypes()
 {
   using (var shExt = new StringHolder())
   using (var shDesc = new StringHolder())
   {
     var rc = new List<Rhino.FileIO.FileType>();
     int iIndex = 0;
     while (1 == UnsafeNativeMethods.Rdk_RenderPlugIn_BaseOutputTypeAtIndex(NonConstPointer(), iIndex++, shExt.NonConstPointer(), shDesc.NonConstPointer()))
     {
       rc.Add(new Rhino.FileIO.FileType(shExt.ToString(), shDesc.ToString()));
     }
     return rc;
   }
 }
Beispiel #37
0
 /// <summary>
 /// Gets the debug dumps. This is a text description of the geometric contents.
 /// DebugDump() is intended for debugging and is not suitable for creating high
 /// quality text descriptions of an object.
 /// </summary>
 /// <param name="bezierCurve">curve to evaluate</param>
 /// <returns>A debug dump text.</returns>
 public static string DebugDumpToString(Rhino.Geometry.BezierCurve bezierCurve)
 {
   IntPtr pConstThis = bezierCurve.ConstPointer();
   using (var sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.ON_BezierCurve_Dump(pConstThis, pString);
     return sh.ToString();
   }
 }