Skip to content

Commit

Permalink
Few more components
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-ycv committed Apr 14, 2023
1 parent 3c335d9 commit ca8d861
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 8 deletions.
28 changes: 27 additions & 1 deletion AssemblyPriority.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
using System.Windows.Forms;
using Melanoplus.Widget;
using Melanoplus.Util;

using Melanoplus.DevTools;
using System.Reflection;

namespace Melanoplus
{
Expand All @@ -28,6 +29,7 @@ public override GH_LoadingInstruction PriorityLoad()
GH_Canvas.WidgetListCreated += AddWindowsWidget;
Instances.CanvasCreated += LoadQuickButtons;
Instances.CanvasCreated += LoadMenuOptions;
Instances.CanvasCreated += LoadDevMenuOptions;
GH_DocumentEditor.AggregateShortcutMenuItems += AggregateShortcutMenuItems;
/*var server = Instances.ComponentServer;
server.AddCategoryShortName("Melanoplus", "Plus");
Expand Down Expand Up @@ -96,6 +98,30 @@ private void LoadMenuOptions(GH_Canvas canvas)
mnu.DropDownOpening += (s, e) => mnu.DropDownItems["mnuUnlockCluster"].Visible = canvas.IsDocument && canvas.Document.SelectedObjects().Any(o => o is GH_Cluster);
}
}
private void LoadDevMenuOptions(GH_Canvas canvas)
{
Instances.CanvasCreated -= LoadDevMenuOptions;
var editor = Instances.DocumentEditor;
if (editor != null)
{
editor.SuspendLayout();

var mnu = (ToolStripMenuItem)editor.MainMenuStrip.Items["mnuEdit"];
var index = mnu.DropDownItems.IndexOfKey("mnuFind");
var getIcon = new ToolStripMenuItem("Extract Icon", Properties.Resources.image, (s, e) => GetIcon.Save(canvas.Document), "mnuGetIcon");
mnu.DropDownItems.Insert(index, getIcon);
MenuEntryAllowShortcut.Add(getIcon);

mnu = (ToolStripMenuItem)editor.MainMenuStrip.Items["mnuFile"];
index = mnu.DropDownItems.Count;
var unload = new ToolStripMenuItem("Unload GH", null, (s, e) => UnloadGH.Unload(), "mnuUnloadGH");
mnu.DropDownItems.Insert(index, unload);
MenuEntryAllowShortcut.Add(unload);

editor.ResumeLayout();

}
}
private static void AggregateShortcutMenuItems(object sender, GH_MenuShortcutEventArgs e)
{
GH_DocumentEditor.AggregateShortcutMenuItems -= AggregateShortcutMenuItems;
Expand Down
40 changes: 40 additions & 0 deletions DevTools/GetIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Eto.Drawing;
using Eto.Forms;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Special;
using Rhino;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Melanoplus.DevTools
{
public class GetIcon
{
public static void Save(GH_Document document)
{
if (document == null || document.SelectedCount == 0) return;
try
{
var selected = document.SelectedObjects();
var path = document.FilePath == null ? Environment.GetFolderPath(Environment.SpecialFolder.Desktop): "";
foreach (var obj in selected)
{
if (obj is GH_DocumentObject comp)
{
comp.Icon_24x24.Save(Path.Combine(path, comp.NickName + ".png"), System.Drawing.Imaging.ImageFormat.Png);
RhinoApp.WriteLine("Saved {0}.png to {1}", comp.NickName, path==""? Directory.GetCurrentDirectory():path);
}
}
}
catch (Exception er)
{
RhinoApp.WriteLine(er.Message);
}
}

}
}
85 changes: 85 additions & 0 deletions DevTools/Melanoplus.DevTools.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F820841E-54ED-49B2-B21A-BBA8110A4413}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Melanoplus.DevTools</RootNamespace>
<AssemblyName>Melanoplus.DevTools</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Eto, Version=2.5.0.0, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL">
<HintPath>..\packages\RhinoCommon.7.0.20314.3001\lib\net45\Eto.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="GH_IO, Version=7.0.20314.3000, Culture=neutral, PublicKeyToken=6a29997d2e6b4f97, processorArchitecture=MSIL">
<HintPath>..\packages\Grasshopper.7.0.20314.3001\lib\net45\GH_IO.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Grasshopper, Version=7.0.20314.3000, Culture=neutral, PublicKeyToken=dda4f5ec2cd80803, processorArchitecture=MSIL">
<HintPath>..\packages\Grasshopper.7.0.20314.3001\lib\net45\Grasshopper.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rhino.UI, Version=7.0.20314.3000, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL">
<HintPath>..\packages\RhinoCommon.7.0.20314.3001\lib\net45\Rhino.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RhinoCommon, Version=7.0.20314.3000, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL">
<HintPath>..\packages\RhinoCommon.7.0.20314.3001\lib\net45\RhinoCommon.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GetIcon.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnloadGH.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\RhinoCommon.7.0.20314.3001\build\RhinoCommon.targets" Condition="Exists('..\packages\RhinoCommon.7.0.20314.3001\build\RhinoCommon.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\RhinoCommon.7.0.20314.3001\build\RhinoCommon.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\RhinoCommon.7.0.20314.3001\build\RhinoCommon.targets'))" />
<Error Condition="!Exists('..\packages\Grasshopper.7.0.20314.3001\build\Grasshopper.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Grasshopper.7.0.20314.3001\build\Grasshopper.targets'))" />
</Target>
<Import Project="..\packages\Grasshopper.7.0.20314.3001\build\Grasshopper.targets" Condition="Exists('..\packages\Grasshopper.7.0.20314.3001\build\Grasshopper.targets')" />
</Project>
36 changes: 36 additions & 0 deletions DevTools/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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("DevTools")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DevTools")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[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("f820841e-54ed-49b2-b21a-bba8110a4413")]

// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
26 changes: 26 additions & 0 deletions DevTools/UnloadGH.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Grasshopper.Kernel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Melanoplus.DevTools
{
public class UnloadGH
{
public static void Unload()
{
//// UI items don't get loaded on relaunch
//Grasshopper.Instances.DocumentServer.RemoveAllDocuments();
//Grasshopper.Instances.DocumentEditor.CloseForReal();

// Viewport widgets prevent proper reload if enabled when unloaded
var widgets = Grasshopper.Instances.ActiveCanvas.Widgets.Where(w => (w.Name == "Rhino Viewport" || w.Name == "Peek Viewport"));//.Select(w=>w.Visible = false);
foreach(var w in widgets)
w.Visible = false;
Grasshopper.Instances.UnloadAllObjects();
}
}
}
5 changes: 5 additions & 0 deletions DevTools/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Grasshopper" version="7.0.20314.3001" targetFramework="net48" />
<package id="RhinoCommon" version="7.0.20314.3001" targetFramework="net48" />
</packages>
13 changes: 13 additions & 0 deletions Melanoplus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="src\LabelWidget.cs" />
<Compile Include="src\LoopBegin.cs" />
<Compile Include="src\LoopEnd.cs" />
<Compile Include="src\RoundToDecimal.cs" />
<Compile Include="src\TextOutline.cs" />
<Compile Include="src\ViewportBGWidget.cs" />
<Compile Include="src\TaskMassAdd.cs" />
Expand Down Expand Up @@ -155,9 +156,15 @@
<None Include="Resources\LoopEnd.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="DevTools\Melanoplus.DevTools.csproj">
<Project>{f820841e-54ed-49b2-b21a-bba8110a4413}</Project>
<Name>Melanoplus.DevTools</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="WindowsOnly\Melanoplus.WindowsOnly.csproj">
<Project>{9e324a28-260c-4d1a-80c2-c16f8a1ab92c}</Project>
<Name>Melanoplus.WindowsOnly</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand All @@ -166,6 +173,12 @@
<ItemGroup>
<None Include="Resources\TextOutline.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\image.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\decimalDecrease.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>Copy "$(TargetPath)" "$(TargetDir)$(ProjectName).gha"
Expand Down
6 changes: 6 additions & 0 deletions Melanoplus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanoplus", "Melanoplus.cs
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanoplus.WindowsOnly", "WindowsOnly\Melanoplus.WindowsOnly.csproj", "{9E324A28-260C-4D1A-80C2-C16F8A1AB92C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanoplus.DevTools", "DevTools\Melanoplus.DevTools.csproj", "{F820841E-54ED-49B2-B21A-BBA8110A4413}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{9E324A28-260C-4D1A-80C2-C16F8A1AB92C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E324A28-260C-4D1A-80C2-C16F8A1AB92C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E324A28-260C-4D1A-80C2-C16F8A1AB92C}.Release|Any CPU.Build.0 = Release|Any CPU
{F820841E-54ED-49B2-B21A-BBA8110A4413}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F820841E-54ED-49B2-B21A-BBA8110A4413}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F820841E-54ED-49B2-B21A-BBA8110A4413}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F820841E-54ED-49B2-B21A-BBA8110A4413}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
20 changes: 20 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<data name="DataHUD" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\DataHUD.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="decimalDecrease" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\decimalDecrease.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="GetCamera" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\GetCamera.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand All @@ -136,6 +139,9 @@
<data name="idempotent3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\idempotent3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="image" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\image.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Label" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Label.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
Binary file added Resources/decimalDecrease.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions WindowsOnly/ViewportWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using RhinoWindows.WindowsLocalization;

//REF: https://github.com/mcneel/GhCanvasViewport
//Seperate project because this requires libraries that's available only on windows, when loading on macos, this library will error out, but allows for the main library to continue.

namespace Melanoplus.WindowsOnly.Widget
{
Expand Down
Loading

0 comments on commit ca8d861

Please sign in to comment.