diff --git a/rhinocommon/cs/SampleCsCommands/Properties/Resources.Designer.cs b/rhinocommon/cs/SampleCsCommands/Properties/Resources.Designer.cs deleted file mode 100644 index 3974bdb9..00000000 --- a/rhinocommon/cs/SampleCsCommands/Properties/Resources.Designer.cs +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace SampleCsCommands.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SampleCsCommands.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap Logo { - get { - object obj = ResourceManager.GetObject("Logo", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - } -} diff --git a/rhinocommon/cs/SampleCsCommands/Properties/Resources.resx b/rhinocommon/cs/SampleCsCommands/Properties/Resources.resx deleted file mode 100644 index 61e26f0d..00000000 --- a/rhinocommon/cs/SampleCsCommands/Properties/Resources.resx +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - ..\Resources\Logo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - \ No newline at end of file diff --git a/rhinocommon/cs/SampleCsCommands/Resources/Logo.png b/rhinocommon/cs/SampleCsCommands/Resources/Logo.png deleted file mode 100644 index 70c77b57..00000000 Binary files a/rhinocommon/cs/SampleCsCommands/Resources/Logo.png and /dev/null differ diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsClipboard.cs b/rhinocommon/cs/SampleCsCommands/SampleCsClipboard.cs deleted file mode 100644 index c2f271ce..00000000 --- a/rhinocommon/cs/SampleCsCommands/SampleCsClipboard.cs +++ /dev/null @@ -1,208 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; -using System.Windows.Forms; -using Rhino; -using Rhino.Commands; -using Rhino.Geometry; - -namespace SampleCsCommands -{ - /// - /// SampleCsCopyToClipboard command - /// - public class SampleCsCopyToClipboard : Command - { - public override string EnglishName => "SampleCsCopyToClipboard"; - - protected override Result RunCommand(RhinoDoc doc, RunMode mode) - { - var sphere = new Sphere(Plane.WorldXY, 5.0); - var brep = sphere.ToBrep(); - - var rc = SampleCsGeometryBaseClipboardHelper.Write(brep); - if (rc) - { - //Console.WriteLine("{0} copied to the Windows Clipboard", brep.ObjectType); - RhinoApp.WriteLine("{0} copied to the Windows Clipboard", brep.ObjectType); - } - - return Result.Success; - } - } - - /// - /// SampleCsPasteFromClipboard command - /// - public class SampleCsPasteFromClipboard : Command - { - public override string EnglishName => "SampleCsPasteFromClipboard"; - - protected override Result RunCommand(RhinoDoc doc, RunMode mode) - { - var geometry = SampleCsGeometryBaseClipboardHelper.Read(); - if (null == geometry) - { - RhinoApp.WriteLine("Nothing to paste."); - return Result.Nothing; - } - - doc.Objects.Add(geometry); - doc.Views.Redraw(); - - return Result.Success; - } - } - - public static class SampleCsGeometryBaseClipboardHelper - { - private const string CLIPBOARD_FORMAT = "Rhino.Geometry.GeometryBase"; - - /// - /// Writes an object, that inherits from Rhino.Geometry.GeometryBase to the Windows Clipboard. - /// - /// The geometry to write. - /// True if successful, false otherwise. - public static bool Write(GeometryBase geometry) - { - if (null == geometry) - return false; - - var bytes = GeometryBaseToBytes(geometry); - if (null == bytes || 0 == bytes.Length) - return false; - - return WriteClipboardBytes(bytes); - } - - /// - /// Reads an object, that inherits from Rhino.Geometry.GeometryBase from the Windows Clipboard. - /// - /// The object if successful, null otherwise. - public static GeometryBase Read() - { - var bytes = ReadClipboardBytes(); - if (null == bytes || 0 == bytes.Length) - return null; - - return BytesToGeometryBase(bytes); - } - - /// - /// Converts an object that inherits from Rhino.Geometry.GeometryBase to an array of bytes. - /// - private static byte[] GeometryBaseToBytes(GeometryBase src) - { - if (null == src) - return null; - - var rc = Array.Empty(); - try - { - var formatter = new BinaryFormatter(); - using (var stream = new MemoryStream()) - { - formatter.Serialize(stream, src); - rc = stream.ToArray(); - } - } - catch (Exception e) - { - Debug.WriteLine(e.Message); - } - - return rc; - } - - /// - /// Converts an array of bytes to an object that inherits from Rhino.Geometry.GeometryBase. - /// - private static GeometryBase BytesToGeometryBase(byte[] bytes) - { - if (null == bytes || 0 == bytes.Length) - return null; - - GeometryBase rc = null; - try - { - using (var stream = new MemoryStream()) - { - var formatter = new BinaryFormatter {Binder = new GeometryBaseBinder()}; - stream.Write(bytes, 0, bytes.Length); - stream.Seek(0, SeekOrigin.Begin); - if (formatter.Deserialize(stream) is GeometryBase geometry && geometry.IsValid) - rc = geometry; - } - } - catch (Exception e) - { - Debug.WriteLine(e.Message); - } - - return rc; - } - - /// - /// Writes an array of bytes to the Window Clipboard in our format. - /// - private static bool WriteClipboardBytes(byte[] bytes) - { - if (null == bytes || 0 == bytes.Length) - return false; - - var rc = false; - try - { - var data = new DataObject(); - using (var stream = new MemoryStream()) - { - stream.Write(bytes, 0, bytes.Length); - data.SetData(CLIPBOARD_FORMAT, false, stream); - Clipboard.SetDataObject(data, true); - rc = true; - } - } - catch (Exception e) - { - Debug.WriteLine(e.Message); - } - - return rc; - } - - /// - /// Reads an array of bytes from the Window Clipboard in our format. - /// - private static byte[] ReadClipboardBytes() - { - if (!(Clipboard.GetDataObject() is DataObject data) || !data.GetDataPresent(CLIPBOARD_FORMAT)) - return null; - - var stream = data.GetData(CLIPBOARD_FORMAT) as MemoryStream; - return stream?.ToArray(); - } - - /// - /// Both RhinoCommon and Rhino3dmIO have a Rhino.Geometry.GeometryBase - /// class. This serialization binder helps deserialize the equivalent - /// objects across the different assemblies. - /// - private class GeometryBaseBinder : SerializationBinder - { - public override Type BindToType(string assemblyName, string typeName) - { - if (assemblyName == null) - throw new ArgumentNullException(nameof(assemblyName)); - - var assembly = typeof(GeometryBase).Assembly; - assemblyName = assembly.ToString(); - var type_to_deserialize = Type.GetType($"{typeName}, {assemblyName}"); - - return type_to_deserialize; - } - } - - } -} \ No newline at end of file diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsDrawViewportLogo.cs b/rhinocommon/cs/SampleCsCommands/SampleCsDrawViewportLogo.cs deleted file mode 100644 index 05752ad9..00000000 --- a/rhinocommon/cs/SampleCsCommands/SampleCsDrawViewportLogo.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using Rhino; -using Rhino.Commands; -using Rhino.Geometry; -using Rhino.Input.Custom; - -namespace SampleCsCommands -{ - /// - /// SampleCsDrawViewportLogo command - /// - public class SampleCsDrawViewportLogo : Command - { - public override string EnglishName => "SampleCsDrawViewportLogo"; - - protected override Result RunCommand(RhinoDoc doc, RunMode mode) - { - SampleCsDrawViewportLogoConduit conduit = new SampleCsDrawViewportLogoConduit(); - conduit.Enabled = true; - doc.Views.Redraw(); - - GetString gs = new GetString(); - gs.SetCommandPrompt("Press to continue"); - gs.AcceptNothing(true); - gs.Get(); - - conduit.Enabled = false; - doc.Views.Redraw(); - - return Result.Success; - } - } - - /// - /// SampleCsDrawViewportLogoConduit display conduit - /// - public class SampleCsDrawViewportLogoConduit : Rhino.Display.DisplayConduit - { - private float m_sprite_size = 64; - private System.Drawing.Bitmap m_logo; - private readonly Rhino.Display.DisplayBitmap m_bitmap; - - public SampleCsDrawViewportLogoConduit() - { - m_logo = SampleCsCommands.Properties.Resources.Logo; - m_bitmap = new Rhino.Display.DisplayBitmap(m_logo); - } - - protected override void DrawForeground(Rhino.Display.DrawEventArgs e) - { - System.Drawing.Rectangle rect = e.Viewport.Bounds; - Point2d point = new Point2d(rect.Right - (0.5 * m_sprite_size), rect.Bottom - (0.5 * m_sprite_size)); - e.Display.DrawSprite(m_bitmap, point, m_sprite_size); - } - } - -} diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsRestoreLayerState.cs b/rhinocommon/cs/SampleCsCommands/SampleCsRestoreLayerState.cs deleted file mode 100644 index c555e68a..00000000 --- a/rhinocommon/cs/SampleCsCommands/SampleCsRestoreLayerState.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using Rhino; -using Rhino.Commands; - -namespace SampleCsCommands -{ - public class SampleCsRestoreLayerState : Command - { - public override string EnglishName => "SampleCsRestoreLayerState"; - - protected override Result RunCommand(RhinoDoc doc, RunMode mode) - { - Guid plugin_id = Rhino.PlugIns.PlugIn.IdFromName("Rhino Bonus Tools"); - if (plugin_id == Guid.Empty) - return Result.Failure; - - // The object returned by Rhino.RhinoApp.GetPlugInObject is a COM object, not a .NET object. - // C# 4 introduced the new dynamic keyword, which was designed with COM Interop in mind. - // The intent was to make calling properties and methods in C# as easy as it was in VBScript, etc. - - dynamic plugin_obj = Rhino.RhinoApp.GetPlugInObject(plugin_id); - if (null == plugin_obj) - return Result.Failure; - - object[] layer_states = plugin_obj.LayerStateNames(); - foreach (object layer_state in layer_states) - { - string state_name = layer_state.ToString(); - if (state_name.Equals("MyLayerState", StringComparison.OrdinalIgnoreCase)) - plugin_obj.RestoreLayerState(layer_state, 0); - } - - return Result.Success; - } - } -} diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsSerializeClass.cs b/rhinocommon/cs/SampleCsCommands/SampleCsSerializeClass.cs deleted file mode 100644 index 353bceab..00000000 --- a/rhinocommon/cs/SampleCsCommands/SampleCsSerializeClass.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; -using Rhino; -using Rhino.Commands; -using Rhino.DocObjects; -using Rhino.DocObjects.Custom; -using Rhino.FileIO; -using Rhino.Input; - -namespace SampleCsCommands -{ - public class SampleCsSerializeClass : Command - { - public override string EnglishName => "SampleCsSerializeClass"; - - protected override Result RunCommand(RhinoDoc doc, RunMode mode) - { - var rc = RhinoGet.GetOneObject("Select object", false, ObjectType.AnyObject, out var objref); - if (rc != Result.Success) - return rc; - - var obj = objref.Object(); - if (null == obj) - return Result.Failure; - - if (!(obj.Attributes.UserData.Find(typeof(SampleCsCustomUserData)) is SampleCsCustomUserData ud)) - { - var rand = new Random(); - ud = new SampleCsCustomUserData - { - Data = - { - X = rand.NextDouble(), - Y = rand.NextDouble(), - Z = rand.NextDouble() - } - }; - obj.Attributes.UserData.Add(ud); - } - - RhinoApp.WriteLine("{0} = {1}", ud.Description, ud.Data); - - return Result.Success; - } - } - - /// - /// SampleCsCustomUserData - /// - [System.Runtime.InteropServices.Guid("23A7FA3D-74F6-4578-9059-B5E3611CD406")] - public class SampleCsCustomUserData : UserData - { - public SampleCsCustomClass Data { get; } - - public SampleCsCustomUserData() - { - Data = new SampleCsCustomClass(); - } - - public bool IsValid => Data.IsValid; - - public override string Description => "SampleCsCustomClass"; - - public override string ToString() - { - return Description; - } - - protected override void OnDuplicate(UserData source) - { - if (source is SampleCsCustomUserData src) - { - Data.Create(src.Data); - } - } - - public override bool ShouldWrite => IsValid; - - protected override bool Read(BinaryArchiveReader archive) - { - archive.Read3dmChunkVersion(out var major, out var minor); - if (1 == major && 0 == minor) - { - Data.Read(archive); - } - return !archive.ReadErrorOccured; - } - - protected override bool Write(BinaryArchiveWriter archive) - { - archive.Write3dmChunkVersion(1, 0); - Data.Write(archive); - return !archive.WriteErrorOccured; - } - } - - /// - /// SampleCsCustomClass - /// - [Serializable] - public class SampleCsCustomClass - { - public double X { get; set; } - public double Y { get; set; } - public double Z { get; set; } - - public SampleCsCustomClass() - { - X = Y = Z = 0.0; - } - - public SampleCsCustomClass(SampleCsCustomClass src) - { - X = src.X; - Y = src.Y; - Z = src.Z; - } - - public void Create(SampleCsCustomClass src) - { - X = src.X; - Y = src.Y; - Z = src.Z; - } - - public bool IsValid => RhinoMath.IsValidDouble(X) && - RhinoMath.IsValidDouble(Y) && - RhinoMath.IsValidDouble(Z); - - public bool Write(BinaryArchiveWriter archive) - { - var rc = false; - if (null != archive) - { - try - { - // Write chunk version - archive.Write3dmChunkVersion(1, 0); - - // Write 'this' object - var formatter = new BinaryFormatter(); - var stream = new MemoryStream(); - formatter.Serialize(stream, this); - stream.Seek(0, 0); - var bytes = stream.ToArray(); - archive.WriteByteArray(bytes); - stream.Close(); - - // Verify writing - rc = archive.WriteErrorOccured; - } - catch - { - // TODO - } - } - return rc; - } - - public bool Read(BinaryArchiveReader archive) - { - var rc = false; - if (null != archive) - { - // Read and verify chunk version - archive.Read3dmChunkVersion(out var major, out var minor); - if (1 == major && 0 == minor) - { - try - { - // Read this object - var bytes = archive.ReadByteArray(); - var stream = new MemoryStream(bytes); - var formatter = new BinaryFormatter(); - var data = formatter.Deserialize(stream) as SampleCsCustomClass; - Create(data); - - // Verify reading - rc = archive.ReadErrorOccured; - } - catch - { - // TODO - } - } - } - return rc; - } - - public override string ToString() - { - var culture = System.Globalization.CultureInfo.InvariantCulture; - return $"{X.ToString(culture)},{Y.ToString(culture)},{Z.ToString(culture)}"; - } - } - -} diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsWritePdf.cs b/rhinocommon/cs/SampleCsCommands/SampleCsWritePdf.cs deleted file mode 100644 index 049682d8..00000000 --- a/rhinocommon/cs/SampleCsCommands/SampleCsWritePdf.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using Rhino; -using Rhino.Commands; -using Rhino.FileIO; - -namespace SampleCsCommands -{ - public class SampleCsWritePdf : Command - { - public override string EnglishName => "SampleCsWritePdf"; - - protected override Result RunCommand(RhinoDoc doc, RunMode mode) - { - var pdf = FilePdf.Create(); - - var pdf_doc = pdf.PdfDocumentImplementation() as Xfinium.Pdf.PdfFixedDocument; - if (null == pdf_doc) - return Result.Failure; - - var cover_page = pdf_doc.Pages.Add(); - - using (var font = new System.Drawing.Font("Arial", 30)) - { - var pdf_font = new Xfinium.Pdf.Graphics.PdfUnicodeTrueTypeFont(font, false) { Underline = true }; - var color = new Xfinium.Pdf.Graphics.PdfRgbColor(0, 0, 0); - var appearance = new Xfinium.Pdf.Graphics.PdfStringAppearanceOptions(pdf_font, null, new Xfinium.Pdf.Graphics.PdfBrush(color)); - var layout = new Xfinium.Pdf.Graphics.PdfStringLayoutOptions - { - HorizontalAlign = Xfinium.Pdf.Graphics.PdfStringHorizontalAlign.Center, - X = cover_page.Width / 2, - Y = cover_page.Height / 2 - }; - cover_page.Graphics.DrawString(EnglishName, appearance, layout); - } - - const int w = (int)(8.5 * 300); - const int h = 11 * 300; - - var views = doc.Views.GetViewList(true, false); - for (var i = 0; i < views.Length; i++) - { - var view = views[i]; - var viewcapture = new Rhino.Display.ViewCaptureSettings(view, new System.Drawing.Size(w, h), 300); - var page_index = pdf.AddPage(viewcapture) - 1; - using (var font = new System.Drawing.Font("Arial", 80)) - { - var pdf_font = new Xfinium.Pdf.Graphics.PdfUnicodeTrueTypeFont(font, false); - var color = new Xfinium.Pdf.Graphics.PdfRgbColor(40, 40, 40); - var pen = new Xfinium.Pdf.Graphics.PdfPen(color, 3); - var appearance = new Xfinium.Pdf.Graphics.PdfStringAppearanceOptions(pdf_font, pen, null); - var layout = new Xfinium.Pdf.Graphics.PdfStringLayoutOptions - { - HorizontalAlign = Xfinium.Pdf.Graphics.PdfStringHorizontalAlign.Center, - Rotation = 45, - X = cover_page.Width / 2, - Y = cover_page.Height / 2 - }; - pdf_doc.Pages[page_index].Graphics.DrawString("Top Secret", appearance, layout); - } - - using (var font = new System.Drawing.Font("Arial", 20)) - { - var pdf_font = new Xfinium.Pdf.Graphics.PdfUnicodeTrueTypeFont(font, false); - var color = new Xfinium.Pdf.Graphics.PdfRgbColor(0, 0, 0); - var appearance = new Xfinium.Pdf.Graphics.PdfStringAppearanceOptions(pdf_font, null, new Xfinium.Pdf.Graphics.PdfBrush(color)); - var layout = new Xfinium.Pdf.Graphics.PdfStringLayoutOptions - { - HorizontalAlign = Xfinium.Pdf.Graphics.PdfStringHorizontalAlign.Right, - X = cover_page.Width * 0.9, - Y = cover_page.Height * 0.9 - }; - pdf_doc.Pages[page_index].Graphics.DrawString($"Page {i + 1} of {views.Length}", appearance, layout); - } - } - - var path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); - path = System.IO.Path.Combine(path, EnglishName + ".pdf"); - pdf.Write(path); - - return Result.Success; - } - } -} \ No newline at end of file