-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial set up * Remove implementation of assembly priority
- Loading branch information
1 parent
dabc2ff
commit 8dc3b68
Showing
5 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"profiles": { | ||
"WireEventImplementor": { | ||
"commandName": "Executable", | ||
"executablePath": "C:\\Program Files\\Rhino 7\\System\\Rhino.exe", | ||
"commandLineArgs": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net48</TargetFramework> | ||
<Version>1.0</Version> | ||
<Title>WireEventImplementor</Title> | ||
<Description>Description of WireEventImplementor</Description> | ||
<TargetExt>.dll</TargetExt> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Grasshopper" Version="7.13.21348.13001" IncludeAssets="compile;build" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Windows.Forms" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Grasshopper.GUI.Canvas; | ||
using Grasshopper.GUI.Canvas.Interaction; | ||
using Grasshopper.Kernel; | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace WireEventImplementor | ||
{ | ||
public static class WireInstances | ||
{ | ||
|
||
public delegate void PreWiredEventHandler(WireStatus wireStatus); | ||
|
||
public delegate void WiringEventHandler(WireStatus wireStatus); | ||
|
||
public delegate void PostWiredEventHandler(WireStatus wireStatus); | ||
|
||
/// <summary> | ||
/// Invoked when your wiring cursor is floating. | ||
/// </summary> | ||
public static event WiringEventHandler Wiring; | ||
|
||
/// <summary> | ||
/// Invoked when your wiring cursor is on the grip. | ||
/// </summary> | ||
public static event PreWiredEventHandler PreWired; | ||
|
||
/// <summary> | ||
/// Invoked when your wire connects grips. | ||
/// </summary> | ||
public static event PostWiredEventHandler PostWired; | ||
|
||
private static TaskCompletionSource<WireStatus> m_source = new TaskCompletionSource<WireStatus>(); | ||
|
||
/// <summary> | ||
/// Call when canvas created. | ||
/// </summary> | ||
/// <param name="canvas">Applied canvas.</param> | ||
public static void SetUp(GH_Canvas canvas) | ||
{ | ||
canvas.MouseMove += Canvas_MouseMove; | ||
canvas.MouseUp += Canvas_MouseUp; | ||
} | ||
|
||
private static void Canvas_MouseMove(object sender, MouseEventArgs e) | ||
{ | ||
if (sender is GH_Canvas canvas && canvas.ActiveInteraction is GH_WireInteraction wireInteraction) | ||
{ | ||
wireInteraction.GetWireParameters(out WireStatus status); | ||
|
||
if (e.Button == MouseButtons.Left) | ||
{ | ||
m_source = new TaskCompletionSource<WireStatus>(); | ||
|
||
if (status.WireTarget == null) | ||
Wiring?.Invoke(status); | ||
else | ||
{ | ||
PreWired?.Invoke(status); | ||
m_source.SetResult(status); | ||
} | ||
} | ||
|
||
canvas.Refresh(); | ||
} | ||
} | ||
|
||
private static async void Canvas_MouseUp(object sender, MouseEventArgs e) | ||
{ | ||
WireStatus status = await m_source.Task; | ||
m_source = new TaskCompletionSource<WireStatus>(); | ||
|
||
PostWired?.Invoke(status); | ||
|
||
(sender as GH_Canvas).Refresh(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Grasshopper.Kernel; | ||
|
||
namespace WireEventImplementor | ||
{ | ||
public class WireStatus | ||
{ | ||
public IGH_Param WireSource { get; } | ||
|
||
public IGH_Param WireTarget { get; } | ||
|
||
public LinkMode? LinkMode { get; } | ||
|
||
public bool? IsDragFromInput { get; } | ||
|
||
public IGH_Param PreviousSideParam => (bool)IsDragFromInput ? WireTarget : WireSource; | ||
|
||
public IGH_Param SubsequentSideParam => (bool)IsDragFromInput ? WireSource : WireTarget; | ||
|
||
private WireStatus() | ||
{ | ||
} | ||
|
||
internal WireStatus(IGH_Param wireSource, IGH_Param wireTarget, LinkMode? linkMode, bool? isDragFromInput) | ||
{ | ||
WireSource = wireSource; | ||
WireTarget = wireTarget; | ||
LinkMode = linkMode; | ||
IsDragFromInput = isDragFromInput; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Grasshopper.GUI.Canvas.Interaction; | ||
using Grasshopper.Kernel; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace WireEventImplementor | ||
{ | ||
public enum LinkMode | ||
{ | ||
Replace, | ||
Add, | ||
Remove | ||
} | ||
|
||
public static class WireUtil | ||
{ | ||
internal static void GetWireParameters(this GH_WireInteraction self, out WireStatus wireStatus) | ||
{ | ||
Func<string, object> getPrivateParam = (name) => typeof(GH_WireInteraction).GetField(name, BindingFlags.NonPublic | BindingFlags.Instance).GetValue(self); | ||
|
||
IGH_Param source = getPrivateParam("m_source") as IGH_Param; | ||
IGH_Param target = getPrivateParam("m_target") as IGH_Param; | ||
LinkMode mode = (LinkMode)Enum.Parse(typeof(LinkMode), getPrivateParam("m_mode").ToString()); | ||
bool dragFromInput = (bool)getPrivateParam("m_dragfrominput"); | ||
|
||
wireStatus = new WireStatus(source, target, mode, dragFromInput); | ||
} | ||
} | ||
} |