-
Notifications
You must be signed in to change notification settings - Fork 330
/
pick-points.cs
95 lines (81 loc) · 2.39 KB
/
pick-points.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
partial class Examples
{
private static readonly List<ConduitPoint> m_conduit_points = new List<ConduitPoint>();
public static Rhino.Commands.Result PickPoints(RhinoDoc doc)
{
var conduit = new PointsConduit(m_conduit_points);
conduit.Enabled = true;
var gp = new Rhino.Input.Custom.GetPoint();
while (true)
{
gp.SetCommandPrompt("click location to create point. (<ESC> exit)");
gp.AcceptNothing(true);
gp.Get();
if (gp.CommandResult() != Rhino.Commands.Result.Success)
break;
m_conduit_points.Add(new ConduitPoint(gp.Point()));
doc.Views.Redraw();
}
var gcp = new GetConduitPoint(m_conduit_points);
while (true)
{
gcp.SetCommandPrompt("select conduit point. (<ESC> to exit)");
gcp.AcceptNothing(true);
gcp.Get(true);
doc.Views.Redraw();
if (gcp.CommandResult() != Rhino.Commands.Result.Success)
break;
}
return Rhino.Commands.Result.Success;
}
}
public class ConduitPoint
{
public ConduitPoint(Point3d point)
{
Color = System.Drawing.Color.White;
Point = point;
}
public System.Drawing.Color Color { get; set; }
public Point3d Point { get; set; }
}
public class GetConduitPoint : GetPoint
{
private readonly List<ConduitPoint> m_conduit_points;
public GetConduitPoint(List<ConduitPoint> conduitPoints )
{
m_conduit_points = conduitPoints;
}
protected override void OnMouseDown(GetPointMouseEventArgs e)
{
base.OnMouseDown(e);
var picker = new PickContext();
picker.View = e.Viewport.ParentView;
picker.PickStyle = PickStyle.PointPick;
var xform = e.Viewport.GetPickTransform(e.WindowPoint);
picker.SetPickTransform(xform);
foreach (var cp in m_conduit_points)
{
double depth;
double distance;
if (picker.PickFrustumTest(cp.Point, out depth, out distance))
cp.Color = System.Drawing.Color.Red;
else
cp.Color = System.Drawing.Color.White;
}
}
}
class PointsConduit : Rhino.Display.DisplayConduit
{
private readonly List<ConduitPoint> m_conduit_points;
public PointsConduit(List<ConduitPoint> conduitPoints )
{
m_conduit_points = conduitPoints;
}
protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
{
if (m_conduit_points != null)
foreach (var cp in m_conduit_points)
e.Display.DrawPoint(cp.Point, PointStyle.Simple, 3, cp.Color);
}
}