diff --git a/LICENSE b/LICENSE index b566f24..3e4d16d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Victor Lin +Copyright (c) 2024 Victor Lin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index 3701b27..0000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("RobotsExtended")] -[assembly: AssemblyDescription("Extended capabilities for Robots plugin")] -#if (DEBUG) -[assembly: AssemblyConfiguration("Debug")] -#else -[assembly: AssemblyConfiguration("Release")] -#endif -[assembly: AssemblyCompany("Yu Chieh (Victor) Lin")] -[assembly: AssemblyProduct("RobotsExtended")] -[assembly: AssemblyCopyright("Copyright © 2024")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("d69e8d8d-f0a3-40d6-b858-59d009798be4")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.7")] -[assembly: AssemblyFileVersion("1.6.7.0")] diff --git a/RobotsExtended.csproj b/RobotsExtended.csproj deleted file mode 100644 index 5be23c6..0000000 --- a/RobotsExtended.csproj +++ /dev/null @@ -1,166 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {D69E8D8D-F0A3-40D6-B858-59D009798BE4} - Library - Properties - RobotsExtended - RobotsExtended - v4.8 - 9.0 - 512 - false - - - - - - true - full - false - bin\ - DEBUG;TRACE - prompt - false - - - pdbonly - true - bin\ - TRACE - prompt - 4 - - - - - - - - - True - True - Resources.resx - - - - - - - - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - packages\RhinoCommon.7.0.20314.3001\lib\net45\Eto.dll - False - - - packages\Grasshopper.7.0.20314.3001\lib\net45\GH_IO.dll - False - - - packages\Grasshopper.7.0.20314.3001\lib\net45\Grasshopper.dll - False - - - - packages\RhinoCommon.7.0.20314.3001\lib\net45\Rhino.UI.dll - False - - - packages\RhinoCommon.7.0.20314.3001\lib\net45\RhinoCommon.dll - False - - - packages\Robots.Rhino.1.6.7\lib\net48\Robots.dll - False - - - packages\Robots.Rhino.1.6.7\lib\net48\Robots.Grasshopper.dll - False - - - - - - - - - - - - Copy "$(TargetPath)" "$(TargetDir)$(ProjectName).gha" -Erase "$(TargetPath)" -if $(ConfigurationName) == Release ( - del /Q "$(TargetDir)*.config" - del /Q "$(TargetDir)*.pdb" - rmdir /S /Q "$(TargetDir)\..\obj" -) - - - en-US - - - C:\Program Files\Rhino 6\System\Rhino.exe - - - Program - x64 - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file diff --git a/packages.config b/packages.config deleted file mode 100644 index 59eb9e8..0000000 --- a/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/Kuka/CVEL.cs b/src/Kuka/CVEL.cs index be120cb..88b6652 100644 --- a/src/Kuka/CVEL.cs +++ b/src/Kuka/CVEL.cs @@ -1,12 +1,4 @@ -using Grasshopper.Kernel; -using Robots; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RobotsExtended.Kuka +namespace RobotsExtended.Kuka { public class CVEL : GH_Component { @@ -43,7 +35,7 @@ protected override void SolveInstance(IGH_DataAccess DA) DA.SetData(0, command); } protected override System.Drawing.Bitmap Icon => Properties.Resources.Speed_Approximation; - public override Guid ComponentGuid => new Guid("79B3841F-6BCE-4D80-B665-B6DF637C1797"); + public override Guid ComponentGuid => new("79B3841F-6BCE-4D80-B665-B6DF637C1797"); } } diff --git a/src/Kuka/MergeKRL.cs b/src/Kuka/MergeKRL.cs index d98819e..96bb9d1 100644 --- a/src/Kuka/MergeKRL.cs +++ b/src/Kuka/MergeKRL.cs @@ -1,17 +1,4 @@ -using GH_IO.Serialization; -using Grasshopper.Kernel.Data; -using Grasshopper.Kernel.Parameters; -using Grasshopper.Kernel.Types; -using Grasshopper.Kernel; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace RobotsExtended.Kuka +namespace RobotsExtended.Kuka { public class MergeKRL : GH_Component, IGH_VariableParameterComponent { @@ -51,8 +38,8 @@ protected override void SolveInstance(IGH_DataAccess DA) List header = code.Branches[0][0].Value .Split(new string[] { "\r\n", "\r", "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); - Dictionary declare = new Dictionary(); - List prog = new List(); + Dictionary declare = []; + List prog = []; List declOrg = string.Join(Environment.NewLine, code.Branches[1].Select(x => x.Value)).Split(new string[] { "\r\n", "\r", "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); ; for (int i = 1; i < declOrg.Count - 1; i++)// Skip RVP+REL and ENDDAT { @@ -69,8 +56,7 @@ protected override void SolveInstance(IGH_DataAccess DA) prog.Add(code.Branches[2][i].Value); } - List main = new List(); - main.AddRange(prog); + List main = [.. prog]; if (fold) main.Insert(2, "\r\n;FOLD"); else @@ -175,8 +161,8 @@ protected override void SolveInstance(IGH_DataAccess DA) void IGH_VariableParameterComponent.VariableParameterMaintenance() {} bool save = false; bool fold = false; - readonly Param_String param = new Param_String { Name = "Directory", NickName = "P", Description = "Specify Path where file will be saved\nIf not specified, will try to save to Desktop", Optional = true }; - readonly Param_Boolean param2 = new Param_Boolean { Name = "Save", NickName = "S", Description = "Button or toggle to specify saving", Optional = false }; + readonly Param_String param = new() { Name = "Directory", NickName = "P", Description = "Specify Path where file will be saved\nIf not specified, will try to save to Desktop", Optional = true }; + readonly Param_Boolean param2 = new() { Name = "Save", NickName = "S", Description = "Button or toggle to specify saving", Optional = false }; private void SaveInputs(object sender, EventArgs e) { RecordUndoEvent("Enable/disable Save param"); @@ -207,7 +193,7 @@ public override bool Read(GH_IReader reader) return base.Read(reader); } protected override System.Drawing.Bitmap Icon => Properties.Resources.KRL; - public override Guid ComponentGuid => new Guid("309454cf-ea5e-470f-80a8-fc19e3729dfc"); + public override Guid ComponentGuid => new("309454cf-ea5e-470f-80a8-fc19e3729dfc"); } } diff --git a/src/Kuka/MxAutomation.cs b/src/Kuka/MxAutomation.cs index eef33a5..1ff2094 100644 --- a/src/Kuka/MxAutomation.cs +++ b/src/Kuka/MxAutomation.cs @@ -1,12 +1,4 @@ -using Grasshopper.Kernel; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RobotsExtended.Kuka +namespace RobotsExtended.Kuka { //public class MxAutomation : GH_Component //{ diff --git a/src/Kuka/VarClient.cs b/src/Kuka/VarClient.cs index 1bbb31b..263fb5e 100644 --- a/src/Kuka/VarClient.cs +++ b/src/Kuka/VarClient.cs @@ -1,21 +1,10 @@ -using Grasshopper.Kernel; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Net.Sockets; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace RobotsExtended.Kuka +namespace RobotsExtended.Kuka { public class KukaVarClient : GH_Component { public KukaVarClient() : base("Remote KUKA", "Remote", "KukaVarProxy Client. [Requires KukaVarProxy]", "Robots", "Components") { } public override GH_Exposure Exposure => GH_Exposure.senary; //| GH_Exposure.obscure; - public override Guid ComponentGuid => new Guid("D746BC1B-CA90-401D-ACDC-9320D2AD0844"); + public override Guid ComponentGuid => new("D746BC1B-CA90-401D-ACDC-9320D2AD0844"); protected override System.Drawing.Bitmap Icon => Properties.Resources.KukaVarProxyConnect; public override void AddedToDocument(GH_Document document) { @@ -76,7 +65,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) TcpClient client; NetworkStream stream = null; - NumericUpDown rTO = new NumericUpDown + readonly NumericUpDown rTO = new() { Minimum = 250, Maximum = 10000, @@ -87,14 +76,14 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) BackgroundWorker worker; string ip = string.Empty; bool bgKeepAlive = true; - List log = new List(); + List log = []; bool logNewestOnly = true; #if(DEBUG) bool debug = false; #endif protected override void SolveInstance(IGH_DataAccess DA) { - List usercmd = new List(); + List usercmd = []; bool run = false; int port = 7000; DA.GetData("IP Address", ref ip); @@ -104,12 +93,10 @@ protected override void SolveInstance(IGH_DataAccess DA) #if (DEBUG) if (ip == "0.0.0.0") { - using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0)) - { - socket.Connect("8.8.8.8", 65530); - IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint; - ip = endPoint.Address.ToString(); - } + using Socket socket = new(AddressFamily.InterNetwork, SocketType.Dgram, 0); + socket.Connect("8.8.8.8", 65530); + IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint; + ip = endPoint.Address.ToString(); } #endif if (run) @@ -163,7 +150,7 @@ protected override void SolveInstance(IGH_DataAccess DA) try { tcpmsg = Array.ConvertAll(usercmd[0].Split(' '), s => (byte)int.Parse(s)); } catch - { tcpmsg = new byte[] { 0, 0, 0, 2, 0, 0 }; } + { tcpmsg = [0, 0, 0, 2, 0, 0]; } } #else byte[] tcpmsg = EncodeMsg(usercmd); @@ -186,14 +173,14 @@ void BackgroundTask() void KeepAlive(object sender, DoWorkEventArgs e) { //(ASCII)"$AXIS_ACT"=="0004000C00000924415849535F414354"(HEX) == "0 0 0 12 0 0 9 36 65 88 73 83 95 65 67 84 "(byte) - byte[] poke = new byte[] { 100, 100, 0, 2, 0, 0 }; + byte[] poke = [100, 100, 0, 2, 0, 0]; while (bgKeepAlive) { try { /*if (rKA.Value > rKA.Maximum) rKA.Value = rKA.Maximum; else if (rKA.Value < rKA.Minimum) rKA.Value = rKA.Minimum;*/ - System.Threading.Thread.Sleep(10000);//(int)rKA.Value); + Thread.Sleep(10000);//(int)rKA.Value); if (stream == null) break; SendMsg(poke); } @@ -211,7 +198,7 @@ void KeepAlive(object sender, DoWorkEventArgs e) } byte[] EncodeMsg(List message) { - List msg = new List(); + List msg = []; // LittleEndian - no need to shift list to add header (ID and Req Length) for (int i = message.Count - 1; i >= 0; i--) { @@ -220,7 +207,7 @@ byte[] EncodeMsg(List message) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"[{i}] is not a variable command, skipped"); continue; // Skip if not a variable }*/ - List temp = new List(); + List temp = []; for (int c = message[i].Length - 1; c >= -1; c--) { if (c == -1 || message[i][c] == '=') @@ -228,7 +215,7 @@ byte[] EncodeMsg(List message) int length = temp.Count; msg.AddRange(temp); msg.AddRange(new byte[] { (byte)(length % 256), (byte)(length / 256) }); - temp = new List(); + temp = []; continue; } //if (message[i][c] == ' ') continue; // Spaces needed to formate msg correctly @@ -250,12 +237,12 @@ byte[] EncodeMsg(List message) msg.AddRange(new byte[] { (byte)DateTime.Now.Second, (byte)DateTime.Now.Minute }); msg.Reverse(); - return msg.ToArray(); + return [.. msg]; } void SendMsg(byte[] tcpmsg) { if (tcpmsg == null) return; - if (logNewestOnly) log = new List(); + if (logNewestOnly) log = []; #if (DEBUG) log.Add("_Send (Byte):\r\n" + string.Join(" ", tcpmsg)); #endif @@ -275,7 +262,7 @@ void SendMsg(byte[] tcpmsg) { //rLength = 11; error = true; - response = new byte[] { 78, 111, 32, 82, 101, 115, 112, 111, 110, 115, 101 }; + response = [78, 111, 32, 82, 101, 115, 112, 111, 110, 115, 101]; } string respString = string.Join(" ", new ArraySegment(response, 0, rLength).ToArray()); responseData = (error ? "_Error " : "") + respString; diff --git a/src/Util/Obsolete_RenderColour.cs b/src/Obsolete/RenderColour.cs similarity index 95% rename from src/Util/Obsolete_RenderColour.cs rename to src/Obsolete/RenderColour.cs index a65a2bf..56feed1 100644 --- a/src/Util/Obsolete_RenderColour.cs +++ b/src/Obsolete/RenderColour.cs @@ -6,21 +6,22 @@ using System.Text; using System.Threading.Tasks; -namespace RobotsExtended.Util +namespace RobotsExtended.Obsolete { - public class Obsolete_RenderColour : GH_Component + [Obsolete("Replace with proper C# instaed of snippet")] + public class RenderColour : GH_Component { - public Obsolete_RenderColour() + public RenderColour() : base("Render Colour", "Colour", "Adds render colour to robot mesh", "Robots", "Utility") { } - public override GH_Exposure Exposure => GH_Exposure.secondary | GH_Exposure.obscure |GH_Exposure.hidden; + public override GH_Exposure Exposure => GH_Exposure.secondary | GH_Exposure.obscure | GH_Exposure.hidden; - protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) + protected override void RegisterInputParams(GH_InputParamManager pManager) { } - protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) + protected override void RegisterOutputParams(GH_OutputParamManager pManager) { } protected override void SolveInstance(IGH_DataAccess DA) @@ -29,8 +30,8 @@ protected override void SolveInstance(IGH_DataAccess DA) byte[] binaryRep = Convert.FromBase64String(snip); archive.Deserialize_Binary(binaryRep); string xmlSnippet = archive.Serialize_Xml(); - System.Windows.Forms.Clipboard.Clear(); - System.Windows.Forms.Clipboard.SetText(xmlSnippet); + Clipboard.Clear(); + Clipboard.SetText(xmlSnippet); Paste(); Grasshopper.Instances.ActiveCanvas.Document.ScheduleSolution(10, DeleteThis); } @@ -45,10 +46,10 @@ void Paste() { GH_DocumentIO documentIO = new GH_DocumentIO(); documentIO.Paste(GH_ClipboardType.System); - var thispivot = this.Attributes.Pivot; + var thispivot = Attributes.Pivot; - int smallestX = Int32.MaxValue; - int smallestY = Int32.MaxValue; + int smallestX = int.MaxValue; + int smallestY = int.MaxValue; foreach (IGH_DocumentObject obj in documentIO.Document.Objects) { var pivot = obj.Attributes.Pivot; @@ -56,7 +57,7 @@ void Paste() if (pivot.Y < smallestY) smallestY = (int)pivot.Y; } - System.Drawing.Size offset = new System.Drawing.Size((int)thispivot.X - smallestX, (int)thispivot.Y - smallestY); + Size offset = new Size((int)thispivot.X - smallestX, (int)thispivot.Y - smallestY); documentIO.Document.TranslateObjects(offset, false); documentIO.Document.SelectAll(); @@ -68,7 +69,7 @@ void Paste() Grasshopper.Instances.ActiveCanvas.Document.UndoUtil.RecordAddObjectEvent("Paste", objs); Grasshopper.Instances.ActiveCanvas.Document.ScheduleSolution(10); } - protected override System.Drawing.Bitmap Icon => Properties.Resources.Colourful; + protected override Bitmap Icon => Properties.Resources.Colourful; public override Guid ComponentGuid => new Guid("5AE1E121-11B3-499A-AB30-82B02FAD533A"); } diff --git a/Properties/Resources.Designer.cs b/src/Properties/Resources.Designer.cs similarity index 94% rename from Properties/Resources.Designer.cs rename to src/Properties/Resources.Designer.cs index 3ecd5c8..9a79f77 100644 --- a/Properties/Resources.Designer.cs +++ b/src/Properties/Resources.Designer.cs @@ -1,163 +1,173 @@ -//------------------------------------------------------------------------------ -// -// 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 RobotsExtended.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", "17.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("RobotsExtended.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 Colourful { - get { - object obj = ResourceManager.GetObject("Colourful", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap Define_Joints { - get { - object obj = ResourceManager.GetObject("Define_Joints", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap DeTool { - get { - object obj = ResourceManager.GetObject("DeTool", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconRobot { - get { - object obj = ResourceManager.GetObject("iconRobot", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap KRL { - get { - object obj = ResourceManager.GetObject("KRL", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap KukaVarProxyConnect { - get { - object obj = ResourceManager.GetObject("KukaVarProxyConnect", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap Rotate_Euler { - get { - object obj = ResourceManager.GetObject("Rotate_Euler", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap Speed_Approximation { - get { - object obj = ResourceManager.GetObject("Speed_Approximation", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap UpdateFrame { - get { - object obj = ResourceManager.GetObject("UpdateFrame", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap UpdateTool { - get { - object obj = ResourceManager.GetObject("UpdateTool", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - } -} +//------------------------------------------------------------------------------ +// +// 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 RobotsExtended.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", "17.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("RobotsExtended.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 Colourful { + get { + object obj = ResourceManager.GetObject("Colourful", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Define_Joints { + get { + object obj = ResourceManager.GetObject("Define_Joints", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap DeTool { + get { + object obj = ResourceManager.GetObject("DeTool", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap iconRobot { + get { + object obj = ResourceManager.GetObject("iconRobot", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap KRL { + get { + object obj = ResourceManager.GetObject("KRL", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap KukaVarProxyConnect { + get { + object obj = ResourceManager.GetObject("KukaVarProxyConnect", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Library { + get { + object obj = ResourceManager.GetObject("Library", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Rotate_Euler { + get { + object obj = ResourceManager.GetObject("Rotate_Euler", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Speed_Approximation { + get { + object obj = ResourceManager.GetObject("Speed_Approximation", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap UpdateFrame { + get { + object obj = ResourceManager.GetObject("UpdateFrame", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap UpdateTool { + get { + object obj = ResourceManager.GetObject("UpdateTool", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Properties/Resources.resx b/src/Properties/Resources.resx similarity index 97% rename from Properties/Resources.resx rename to src/Properties/Resources.resx index b5f94a1..20176a6 100644 --- a/Properties/Resources.resx +++ b/src/Properties/Resources.resx @@ -1,151 +1,154 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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\Colourful.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Define_Joints.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\DeTool.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\iconRobot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\KRL.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\KukaVarProxyConnect.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Rotate_Euler.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Speed_Approximation.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\UpdateFrame.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\UpdateTool.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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\Colourful.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Define_Joints.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\DeTool.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\iconRobot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\KRL.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\KukaVarProxyConnect.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Library.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Rotate_Euler.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Speed_Approximation.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\UpdateFrame.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\UpdateTool.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/src/Properties/launchSettings.json b/src/Properties/launchSettings.json new file mode 100644 index 0000000..b52f699 --- /dev/null +++ b/src/Properties/launchSettings.json @@ -0,0 +1,19 @@ +{ + "profiles": { + "Rhino 8": { + "commandName": "Executable", + "executablePath": "C:\\Program Files\\Rhino 8\\System\\Rhino.exe", + "commandLineArgs": "/netfx /nosplash /notemplate /runscript=\"_-grasshopper Banner Disable Windows Load Window Show _enter\"", + "environmentVariables": { + "RHINO_PACKAGE_DIRS": "$(ProjectDir)$(OutputPath)" + } + }, + "Rhino 7": { + "commandName": "Executable", + "executablePath": "C:\\Program Files\\Rhino 7\\System\\Rhino.exe", + "environmentVariables": { + "RHINO_PACKAGE_DIRS": "$(ProjectDir)$(OutputPath)" + } + } + } +} \ No newline at end of file diff --git a/Resources/Colourful.png b/src/Resources/Colourful.png similarity index 100% rename from Resources/Colourful.png rename to src/Resources/Colourful.png diff --git a/Resources/DeTool.png b/src/Resources/DeTool.png similarity index 100% rename from Resources/DeTool.png rename to src/Resources/DeTool.png diff --git a/Resources/Define_Joints.png b/src/Resources/Define_Joints.png similarity index 100% rename from Resources/Define_Joints.png rename to src/Resources/Define_Joints.png diff --git a/Resources/KRL.png b/src/Resources/KRL.png similarity index 100% rename from Resources/KRL.png rename to src/Resources/KRL.png diff --git a/Resources/KukaVarProxyConnect.png b/src/Resources/KukaVarProxyConnect.png similarity index 100% rename from Resources/KukaVarProxyConnect.png rename to src/Resources/KukaVarProxyConnect.png diff --git a/src/Resources/Library.png b/src/Resources/Library.png new file mode 100644 index 0000000..3e31a8f Binary files /dev/null and b/src/Resources/Library.png differ diff --git a/Resources/Rotate_Euler.png b/src/Resources/Rotate_Euler.png similarity index 100% rename from Resources/Rotate_Euler.png rename to src/Resources/Rotate_Euler.png diff --git a/Resources/Speed_Approximation.png b/src/Resources/Speed_Approximation.png similarity index 100% rename from Resources/Speed_Approximation.png rename to src/Resources/Speed_Approximation.png diff --git a/Resources/UpdateFrame.png b/src/Resources/UpdateFrame.png similarity index 100% rename from Resources/UpdateFrame.png rename to src/Resources/UpdateFrame.png diff --git a/Resources/UpdateTool.png b/src/Resources/UpdateTool.png similarity index 100% rename from Resources/UpdateTool.png rename to src/Resources/UpdateTool.png diff --git a/Resources/iconRobot.png b/src/Resources/iconRobot.png similarity index 100% rename from Resources/iconRobot.png rename to src/Resources/iconRobot.png diff --git a/src/RobotsExtended.csproj b/src/RobotsExtended.csproj new file mode 100644 index 0000000..346b1b9 --- /dev/null +++ b/src/RobotsExtended.csproj @@ -0,0 +1,49 @@ + + + net48 + 12 + .gha + enable + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/RobotsExtended.csproj.user b/src/RobotsExtended.csproj.user similarity index 80% rename from RobotsExtended.csproj.user rename to src/RobotsExtended.csproj.user index b2b0257..89efda6 100644 --- a/RobotsExtended.csproj.user +++ b/src/RobotsExtended.csproj.user @@ -1,12 +1,17 @@ - - - - C:\Program Files\Rhino 8\System\Rhino.exe - /netfx /nosplash /notemplate /runscript="_-Grasshopper Banner Disable Window Load Window Show _Enter" - - - Program - C:\Program Files\Rhino 7\System\Rhino.exe - -nosplash -notemplate /runscript="_-Grasshopper Banner Disable Window Load Window Show _Enter" - + + + + C:\Program Files\Rhino 8\System\Rhino.exe + /netfx /nosplash /notemplate /runscript="_-Grasshopper Banner Disable Window Load Window Show _Enter" + ProjectDebugger + + + Program + C:\Program Files\Rhino 7\System\Rhino.exe + -nosplash -notemplate /runscript="_-Grasshopper Banner Disable Window Load Window Show _Enter" + + + net48 + Rhino 8 + \ No newline at end of file diff --git a/RobotsExtended.sln b/src/RobotsExtended.sln similarity index 93% rename from RobotsExtended.sln rename to src/RobotsExtended.sln index 271e3a0..a196fb0 100644 --- a/RobotsExtended.sln +++ b/src/RobotsExtended.sln @@ -1,9 +1,9 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32811.315 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RobotsExtended", "RobotsExtended.csproj", "{D69E8D8D-F0A3-40D6-B858-59D009798BE4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RobotsExtended", "RobotsExtended.csproj", "{D69E8D8D-F0A3-40D6-B858-59D009798BE4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/RobotsExtendedInfo.cs b/src/RobotsExtendedInfo.cs similarity index 86% rename from RobotsExtendedInfo.cs rename to src/RobotsExtendedInfo.cs index 6ad9ff0..b7c5e41 100644 --- a/RobotsExtendedInfo.cs +++ b/src/RobotsExtendedInfo.cs @@ -1,63 +1,61 @@ -using Grasshopper.Kernel; -using System; -using System.Drawing; - -namespace RobotsExtended -{ - public class RobotsExtendedInfo : GH_AssemblyInfo - { - public override string Name - { - get - { - return "RobotsExtended"; - } - } - public override Bitmap Icon - { - get - { - return Properties.Resources.iconRobot; - } - } - public override string Description - { - get - { - //Return a short string describing the purpose of this GHA library. - return "Extension for Robots plugin"; - } - } - public override Guid Id - { - get - { - return new Guid("1144ad19-a43a-4b2b-870f-19ab431ca98f"); - } - } - - public override string AuthorName - { - get - { - return "Victor (Yu Chieh) Lin"; - } - } - public override string AuthorContact - { - get - { - return "https://github.com/lin-ycv/RobotsExtended"; - } - } - - static readonly Version Ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; - public override string Version - { - get - { - return Ver.ToString(); - } - } - } -} +using Grasshopper.Kernel; +using System; +using System.Drawing; + +namespace RobotsExtended +{ + public class RobotsExtendedInfo : GH_AssemblyInfo + { + public override string Name + { + get + { + return "RobotsExtended"; + } + } + public override Bitmap Icon + { + get + { + return Properties.Resources.iconRobot; + } + } + public override string Description + { + get + { + //Return a short string describing the purpose of this GHA library. + return "Extension for Robots plugin"; + } + } + public override Guid Id + { + get + { + return new Guid("1144ad19-a43a-4b2b-870f-19ab431ca98f"); + } + } + + public override string AuthorName + { + get + { + return "Victor (Yu Chieh) Lin"; + } + } + public override string AuthorContact + { + get + { + return "https://github.com/lin-ycv/RobotsExtended"; + } + } + public override string Version + { + get + { + return "1.6.7.1"; + } + } + } +} diff --git a/src/Util/DeconstructTool.cs b/src/Util/DeconstructTool.cs index 0138a31..93a8814 100644 --- a/src/Util/DeconstructTool.cs +++ b/src/Util/DeconstructTool.cs @@ -1,18 +1,10 @@ -using Grasshopper.Kernel; -using Robots.Grasshopper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RobotsExtended.Util +namespace RobotsExtended.Util { public class DeconstructTool : GH_Component { public DeconstructTool() : base("Deconstruct Tool", "DeTool", "Retrieves properties of an exsisting tool", "Robots", "Utility") { } - protected override System.Drawing.Bitmap Icon => Properties.Resources.DeTool; - public override Guid ComponentGuid => new Guid("753CDC90-7278-45C4-91D4-B476BA34D396"); + protected override Bitmap Icon => Properties.Resources.DeTool; + public override Guid ComponentGuid => new("753CDC90-7278-45C4-91D4-B476BA34D396"); readonly string tName = nameof(tName); readonly string TCP = nameof(TCP); readonly string Weight = nameof(Weight); diff --git a/src/Util/DefineJoints.cs b/src/Util/DefineJoints.cs index c5464ed..3065c4c 100644 --- a/src/Util/DefineJoints.cs +++ b/src/Util/DefineJoints.cs @@ -1,18 +1,4 @@ -using GH_IO.Serialization; -using Grasshopper.Kernel.Parameters; -using Grasshopper.Kernel.Special; -using Grasshopper.Kernel; -using Rhino; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using Grasshopper.Kernel.Geometry; -using Robots; - -namespace RobotsExtended.Util +namespace RobotsExtended.Util { public class DefJoints : GH_Component, IGH_VariableParameterComponent { @@ -145,13 +131,13 @@ public override bool Read(GH_IReader reader) void IGH_VariableParameterComponent.VariableParameterMaintenance() { } bool external = false; - readonly IGH_Param[] parameters = new IGH_Param[4] - { + readonly IGH_Param[] parameters = + [ new Param_String { Name = "Axis 3", NickName = "A3", Description = "Degree of rotation for Axis 3", Optional = false }, new Param_String { Name = "Axis 4", NickName = "A4", Description = "Degree of rotation for Axis 4", Optional = false }, new Param_String { Name = "Axis 5", NickName = "A5", Description = "Degree of rotation for Axis 5", Optional = false }, new Param_String { Name = "Axis 6", NickName = "A6", Description = "Degree of rotation for Axis 6", Optional = false } - }; + ]; readonly int[,] limits = new int[3, 6] { {-185,-190,-120,-350,-119,-350}, diff --git a/src/Util/LoadCommand.cs b/src/Util/LoadCommand.cs new file mode 100644 index 0000000..0729df0 --- /dev/null +++ b/src/Util/LoadCommand.cs @@ -0,0 +1,134 @@ +using RC = Robots.Commands; +using System.Xml.Linq; + +namespace RobotsExtended.Util +{ + public class LoadCommand : GH_Component + { + public LoadCommand() : base("Load Command", "Com", "Load predefined commands on the xml config", "Robots", "Utility") { } + public override Guid ComponentGuid => new("{56C786AD-B863-4D81-87FE-6B7F233295A1}"); + protected override Bitmap Icon => Properties.Resources.Colourful; //base.Icon; // Properties.Resources.LoadCommand; + private static readonly int _Type = 3; + + protected override void RegisterInputParams(GH_InputParamManager pManager) + { + pManager.AddTextParameter("Name", "N", "Name of the Command", GH_ParamAccess.item); + pManager.AddTextParameter("Value", "V", "Value for commands that takes input", GH_ParamAccess.item); + pManager[1].Optional = true; + } + + protected override void RegisterOutputParams(GH_OutputParamManager pManager) + { + pManager.AddGenericParameter("Command", "C", "", GH_ParamAccess.item); + } + + protected override void BeforeSolveInstance() + { + CommandList(); + base.BeforeSolveInstance(); + } + + protected override void SolveInstance(IGH_DataAccess DA) + { + string name = null, val = null; + if (!DA.GetData(0, ref name) || string.IsNullOrEmpty(name)) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No command selected"); + return; + } + try + { + DA.GetData(1, ref val); + var command = Load(name, val); + DA.SetData(0, command); + } + catch(Exception e) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message); + } + } + + internal void CommandList() + { + if (Params.Input[0].SourceCount > 0) return; + var doc = OnPingDocument(); + GH_ValueList list = new(); + list.CreateAttributes(); + list.Attributes.Pivot = new PointF( + Attributes.Pivot.X - list.Attributes.Bounds.Width - Attributes.Bounds.Width / 2, + Attributes.Pivot.Y - list.Attributes.Bounds.Height); + list.ListItems.Clear(); + list.ListItems.AddRange(List().Select(i => new GH_ValueListItem(i, $"\"{i}\""))); + if (list.ListItems.Count > 0) + list.ListItems[0].Selected = true; + doc.AddObject(list, false); + Params.Input[0].AddSource(list); + Params.Input[0].CollectData(); + } + + static IEnumerable GetLibraries() + { + var previous = new HashSet(StringComparer.OrdinalIgnoreCase); + + foreach (var path in RobotLibrary.LibPath()) + { + if (!Directory.Exists(path)) + continue; + + var files = Directory.EnumerateFiles(path, "*.xml"); + + foreach (var file in files) + { + var name = Path.GetFileNameWithoutExtension(file); + + if (!previous.Add(name)) + continue; + + yield return file; + } + } + } + static List List() + { + List names = []; + + foreach (var file in GetLibraries()) + { + var root = XElement.Load(file); + var elements = root.Elements(XName.Get("Custom")); + + foreach (var element in elements) + names.Add(element.Attribute("name").Value); + } + + return names; + } + + static RC.Custom Load(string name, string val) + { + foreach (var file in GetLibraries()) + { + var root = XElement.Load(file); + var elements = root.Elements(XName.Get("Custom")); + + var element = elements.FirstOrDefault(e => e.Attribute("name").Value.Equals(name,StringComparison.InvariantCultureIgnoreCase)); + + if (element == null) break; + + var command = element.Element(XName.Get("Command")); + var code = command.Attribute(XName.Get("Code")).Value; + var input = command.Attribute(XName.Get("input"))?.Value; + var manu = command.Attribute(XName.Get("manufacturer"))?.Value; + if (input == "true") + { + name += val; + code = code.Replace("?", val); + } + + return new RC.Custom(name, Enum.TryParse(manu, out var manufacturer)?manufacturer:Manufacturers.All, code,null); + } + + throw new Exception($"Command \"{name}\" not found"); + } + } +} diff --git a/src/Util/RenderColour.cs b/src/Util/RenderColour.cs index 1d7c2ff..30b5780 100644 --- a/src/Util/RenderColour.cs +++ b/src/Util/RenderColour.cs @@ -1,20 +1,6 @@ -using Grasshopper.Kernel.Types; -using Grasshopper.Kernel; -using System; -using System.Collections.Generic; -using System.Drawing; -using Rhino.DocObjects; -using Rhino; -using Grasshopper.Kernel.Components; -using Rhino.Display; -using Rhino.Render; -using Rhino.Geometry; -using GH_IO.Types; -using Rhino.Render.ChangeQueue; - -namespace RobotsExtended.Util +namespace RobotsExtended.Util { - public class RenderColour : GH_CustomPreviewComponent/*GH_Component*/ /*, IGH_CustomPreviewObject //Rhino8*/ + public class RenderColour : GH_CustomPreviewComponent { public RenderColour() //: base("Render Colour", "Colour", @@ -34,7 +20,7 @@ public RenderColour() protected override Bitmap Icon => Properties.Resources.Colourful; private readonly static Color lightBlack = Color.FromArgb(92, 92, 92); - private readonly static string[] robotLabels = new string[8] { "Base", "A1", "A2", "A3", "A4", "A5", "A6", "Tool" }; + private readonly static string[] robotLabels = ["Base", "A1", "A2", "A3", "A4", "A5", "A6", "Tool"]; private BoundingBox _boundingBox; public override BoundingBox ClippingBox => _boundingBox; @@ -65,7 +51,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) protected override void BeforeSolveInstance() { - _items = new List(); + _items = []; _boundingBox = BoundingBox.Empty; //meshes.Clear(); //base.BeforeSolveInstance(); @@ -73,8 +59,8 @@ protected override void BeforeSolveInstance() override protected void AfterSolveInstance() { } protected override void SolveInstance(IGH_DataAccess DA) - { - List meshes = new(); + { + List meshes = []; DA.GetDataList(1, meshes); if (meshes.Count < 8) return; Color[] colors = new Color[meshes.Count]; @@ -148,7 +134,7 @@ protected override void SolveInstance(IGH_DataAccess DA) layer.ParentLayerId = mainId; } ObjectAttributes att = new() { LayerIndex = index }; - doc.Objects.AddMesh(meshes[i].Value,att); + doc.Objects.AddMesh(meshes[i].Value, att); } void Append(GH_Mesh m, Color c) @@ -166,9 +152,9 @@ void Append(GH_Mesh m, Color c) } public override void DrawViewportMeshes(IGH_PreviewArgs args) { - if (this.Locked || _items.Count==0 || args.Document.IsRenderMeshPipelineViewport(args.Display)) + if (this.Locked || _items.Count == 0 || args.Document.IsRenderMeshPipelineViewport(args.Display)) return; - if(this.Attributes.Selected) + if (this.Attributes.Selected) { GH_PreviewMeshArgs args2 = new(args.Viewport, args.Display, args.ShadeMaterial_Selected, args.MeshingParameters); foreach (GH_CustomPreviewItem item in _items) @@ -191,6 +177,20 @@ public override void DrawViewportMeshes(IGH_PreviewArgs args) // args.Display.DrawMeshShaded(meshes[i].Value, new DisplayMaterial(colors[i])); //base.DrawViewportMeshes(args); } + //public void AppendCustomGeometry(GH_RenderArgs args) + //{ + // if (_items == null || _items.Count == 0) + // { + // return; + // } + + // GH_Document gH_Document = OnPingDocument(); + // if (gH_Document != null && (gH_Document.PreviewMode == GH_PreviewMode.Disabled || _items.Count == 0 || gH_Document.PreviewMode == GH_PreviewMode.Wireframe)) + // return; + + // foreach (var item in _items) + // item.PushToRenderPipeline(args); + //} [Obsolete] // For Rhino 7 public override void AppendRenderGeometry(GH_RenderArgs args) @@ -204,22 +204,5 @@ public override void AppendRenderGeometry(GH_RenderArgs args) //base.AppendRenderGeometry(args); } - //void IGH_CustomPreviewObject.AppendCustomGeometry(GH_RenderArgs args) // For Rhino 8 (Robots targets R7, unable to use R8) - //{ - // if (_items == null || _items.Count == 0) - // { - // return; - // } - - // DisplayPipelineAttributes pipelineAttributes = args.PipelineAttributes; - // if ((!IncludeInRender && (pipelineAttributes == null || pipelineAttributes.RealtimeDisplayId != Guid.Empty))) - // { - // return; - // } - - // foreach (var item in _items) - // item.PushToRenderPipeline(args); - //} } - } diff --git a/src/Util/RobotLibrary.cs b/src/Util/RobotLibrary.cs new file mode 100644 index 0000000..9f9f8f3 --- /dev/null +++ b/src/Util/RobotLibrary.cs @@ -0,0 +1,84 @@ +namespace RobotsExtended.Util +{ + public class RobotLibrary : GH_Component + { + public override Guid ComponentGuid => new("{73D053CD-4013-40D2-BE10-C62F999AB60C}"); + override public GH_Exposure Exposure => GH_Exposure.secondary; + protected override Bitmap Icon => Properties.Resources.Library; + public RobotLibrary() : base("Robot Library", "Library", "Double click to open Robot Library directory", "Robots", "Utility") { } + bool Open = false; + private static readonly string localPath = FileIO.LocalLibraryPath, downloadPath = FileIO.OnlineLibraryPath; + + protected override void RegisterInputParams(GH_InputParamManager pManager) + { } + + protected override void RegisterOutputParams(GH_OutputParamManager pManager) + { + pManager.AddTextParameter("Path", "P", "Path to Local Robot Library", GH_ParamAccess.item); + pManager.AddTextParameter("Path", "P", "Path to Downloaded Robot Library", GH_ParamAccess.item); + } + + protected override void SolveInstance(IGH_DataAccess DA) + { + DA.SetData(0, localPath); + DA.SetData(1, downloadPath); + + if (!Open) return; + + bool l, d; + l = Directory.Exists(localPath); + d = Directory.Exists(downloadPath); + if (l) + OpenDir(localPath); + if (d) + OpenDir(downloadPath); + if (!l && !d) + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No Library Found"); + Open = false; + } + public override void CreateAttributes() + { + m_attributes = new LibAttributes(this); + } + public class LibAttributes(IGH_Component component) : GH_ComponentAttributes(component) + { + public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e) + { + if (base.Owner is RobotLibrary comp) + { + comp.Open = true; + comp.ExpireSolution(true); + return GH_ObjectResponse.Handled; + } + return base.RespondToMouseDoubleClick(sender, e); + } + } + public override void AppendAdditionalMenuItems(ToolStripDropDown menu) + { + Menu_AppendItem(menu, "Create Local Directory", CreateDir, !Directory.Exists(localPath)); + base.AppendAdditionalMenuItems(menu); + } + + private void CreateDir(object sender, EventArgs e) + { + Directory.CreateDirectory(localPath); + OpenDir(localPath); + } + + private void OpenDir(string path) + { + if (Directory.Exists(path)) + Process.Start(new ProcessStartInfo() + { + FileName = path, + UseShellExecute = true, + Verb = "open" + }); + } + internal static IEnumerable LibPath() + { + yield return localPath; + yield return downloadPath; + } + } +} diff --git a/src/Util/RotateEuler.cs b/src/Util/RotateEuler.cs index a0b5390..f35a388 100644 --- a/src/Util/RotateEuler.cs +++ b/src/Util/RotateEuler.cs @@ -1,19 +1,9 @@ -using Grasshopper.Kernel.Types; -using Grasshopper.Kernel; -using Rhino.Geometry; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static Rhino.Render.Dithering; - -namespace RobotsExtended.Util +namespace RobotsExtended.Util { public class RotateEuler : GH_Component { public RotateEuler() : base("Rotate Euler", "RotEuler", "Rotate an object with (KUKA) Euler notation", "Transform", "Euclidean") { } - public override Guid ComponentGuid => new Guid("F838B4F6-42FA-4D77-9615-F6B2D142BA68"); + public override Guid ComponentGuid => new("F838B4F6-42FA-4D77-9615-F6B2D142BA68"); protected override System.Drawing.Bitmap Icon => Properties.Resources.Rotate_Euler; protected override void RegisterInputParams(GH_InputParamManager pManager) @@ -38,9 +28,9 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) protected override void SolveInstance(IGH_DataAccess DA) { - List geo = new List(); - List pln = new List(); - List[] ro = new List[3] { new List(), new List(), new List() }; + List geo = []; + List pln = []; + List[] ro = [[], [], []]; DA.GetDataList(0, geo); DA.GetDataList(1, pln); @@ -51,19 +41,19 @@ protected override void SolveInstance(IGH_DataAccess DA) for (int i = 0; i < geo.Count; i++) geo[i] = geo[i].DuplicateGeometry(); if (geo.Count == 0 && pln.Count > 0) - geo.AddRange(pln.Select(p=> GH_Convert.ToGeometricGoo(p))); - for(int i = 0; i < ro.Length; i++) + geo.AddRange(pln.Select(p=> GH_Convert.ToGeometricGoo(p).DuplicateGeometry())); + for (int i = 0; i < ro.Length; i++) if (!ro[i].Any()) - ro[i].Add(0); + ro[i].Add(new GH_Number(0)); - List transforms = new List(); + List transforms = []; double r = Math.PI / 180; for (int i = 0; i < pln.Count; i++) { if (i > geo.Count) break; - Transform x = Transform.Rotation(ro[0][Math.Min(i, ro[0].Count-1)] * r, pln[i].ZAxis, pln[i].Origin); - x *= Transform.Rotation(ro[1][Math.Min(i, ro[1].Count - 1)] * r, pln[i].YAxis, pln[i].Origin); - x *= Transform.Rotation(ro[2][Math.Min(i, ro[2].Count - 1)] * r, pln[i].XAxis, pln[i].Origin); + Transform x = Transform.Rotation(ro[0][Math.Min(i, ro[0].Count-1)].Value * r, pln[i].Value.ZAxis, pln[i].Value.Origin); + x *= Transform.Rotation(ro[1][Math.Min(i, ro[1].Count - 1)].Value * r, pln[i].Value.YAxis, pln[i].Value.Origin); + x *= Transform.Rotation(ro[2][Math.Min(i, ro[2].Count - 1)].Value * r, pln[i].Value.XAxis, pln[i].Value.Origin); transforms.Add(x); geo[i].Transform(x); } diff --git a/src/Util/UpdateFrame.cs b/src/Util/UpdateFrame.cs index 33a3cfa..60dc6e9 100644 --- a/src/Util/UpdateFrame.cs +++ b/src/Util/UpdateFrame.cs @@ -1,18 +1,9 @@ -using Grasshopper.Kernel; -using Rhino.Geometry; -using Robots; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RobotsExtended.Util +namespace RobotsExtended.Util { public class UpdateFrame : GH_Component { public UpdateFrame() : base("Update Frame", "newBase", "Update frame info", "Robots", "Utility") { } - public override Guid ComponentGuid => new Guid("{3BAA462A-7D1B-401A-B789-2E12B878B6AD}"); + public override Guid ComponentGuid => new("{3BAA462A-7D1B-401A-B789-2E12B878B6AD}"); protected override System.Drawing.Bitmap Icon => Properties.Resources.UpdateFrame; protected override void RegisterInputParams(GH_InputParamManager pManager) @@ -35,7 +26,7 @@ protected override void SolveInstance(IGH_DataAccess DA) DA.GetData(1, ref plane); DA.GetData(2, ref number); if (number < 0) number = null; - Frame uFrame = new Frame(plane == Plane.Unset ? frame.Plane : plane, frame.CoupledMechanism, frame.CoupledMechanicalGroup, frame.HasName ? frame.Name : null, number.HasValue, number); + Frame uFrame = new(plane == Plane.Unset ? frame.Plane : plane, frame.CoupledMechanism, frame.CoupledMechanicalGroup, frame.HasName ? frame.Name : null, number.HasValue, number); DA.SetData(0, uFrame); } } diff --git a/src/Util/UpdateTool.cs b/src/Util/UpdateTool.cs index abc5939..b804fda 100644 --- a/src/Util/UpdateTool.cs +++ b/src/Util/UpdateTool.cs @@ -1,24 +1,11 @@ -using GH_IO.Serialization; -using Grasshopper.Kernel.Parameters; -using Grasshopper.Kernel; -using Robots.Grasshopper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using Rhino.Geometry; -using Robots; - -namespace RobotsExtended.Util +namespace RobotsExtended.Util { public class UpdateTool : GH_Component, IGH_VariableParameterComponent { public UpdateTool() : base("Update Tool", "newTCP", "Update the TCP of an exsisting tool", "Robots", "Utility") { } //public override GH_Exposure Exposure => GH_Exposure.hidden; protected override System.Drawing.Bitmap Icon => Properties.Resources.UpdateTool; - public override Guid ComponentGuid => new Guid("92915A29-8636-4670-B21C-756D681789E4"); + public override Guid ComponentGuid => new("92915A29-8636-4670-B21C-756D681789E4"); protected override void RegisterInputParams(GH_InputParamManager pManager) { @@ -40,13 +27,13 @@ protected override void SolveInstance(IGH_DataAccess DA) { GH_Tool input = null; DA.GetData(0, ref input); - Plane tcp = new Plane(); + Plane tcp = new(); DA.GetData(1, ref tcp); int? no = null; if (controller) DA.GetData(2, ref no); - GH_Tool tool = new GH_Tool( + GH_Tool tool = new( new Tool( tcp, input.Value.Name, diff --git a/app.config b/src/app.config similarity index 98% rename from app.config rename to src/app.config index 8b90ad9..b50d3a1 100644 --- a/app.config +++ b/src/app.config @@ -1,27 +1,27 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file