forked from mdjcad/SampleCsCommands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleCsSetPoint.cs
134 lines (115 loc) · 3.21 KB
/
SampleCsSetPoint.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using Rhino;
using Rhino.Collections;
using Rhino.Commands;
using Rhino.Display;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;
namespace SampleCsCommands
{
#region GetSetPointTransform class
/// <summary>
/// GetSetPointTransform
/// </summary>
internal class GetSetPointTransform : GetTransform
{
public GetSetPointTransform(bool bSetX, bool bSetY, bool bSetZ)
{
SetX = bSetX;
SetY = bSetY;
SetZ = bSetZ;
}
public bool SetX { get; set; }
public bool SetY { get; set; }
public bool SetZ { get; set; }
public override Transform CalculateTransform(RhinoViewport viewport, Point3d point)
{
Transform xform = new Transform(0);
if (SetX)
xform[0, 3] = point.X;
else
xform[0, 0] = 1.0;
if (SetY)
xform[1, 3] = point.Y;
else
xform[1, 1] = 1.0;
if (SetZ)
xform[2, 3] = point.Z;
else
xform[2, 2] = 1.0;
xform[3, 3] = 1.0;
return xform;
}
}
#endregion
#region SampleCsSetPoint command
/// <summary>
/// SampleCsSetPoint
/// </summary>
[System.Runtime.InteropServices.Guid("ece11f77-6a51-49cd-a737-d31072967f27")]
public class SampleCsSetPoint : TransformCommand
{
public SampleCsSetPoint()
{
}
public override string EnglishName
{
get { return "SampleCsSetPoint"; }
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
Result rc = Result.Nothing;
GetResult res = GetResult.Nothing;
// Select objects to rotate
TransformObjectList list = new TransformObjectList();
rc = SelectObjects("Select objects to transform", list);
if (rc != Result.Success)
return rc;
OptionToggle opt_xset = new OptionToggle(true, "No", "Yes");
OptionToggle opt_yset = new OptionToggle(true, "No", "Yes");
OptionToggle opt_zset = new OptionToggle(true, "No", "Yes");
// Second reference point
GetSetPointTransform gx = new GetSetPointTransform(true, true, true);
gx.SetCommandPrompt("Location for points");
gx.AddTransformObjects(list);
for (;;)
{
gx.ClearCommandOptions();
gx.AddOptionToggle("XSet", ref opt_xset);
gx.AddOptionToggle("YSet", ref opt_yset);
gx.AddOptionToggle("ZSet", ref opt_zset);
res = gx.GetXform();
if (res == GetResult.Point)
{
RhinoView view = gx.View();
rc = (null != view) ? Result.Success : Result.Failure;
if (rc == Result.Success)
{
Transform xform = gx.CalculateTransform(view.ActiveViewport, gx.Point());
rc = (xform.IsValid) ? Result.Success : Result.Failure;
if (rc == Result.Success)
{
TransformObjects(list, xform, false, false);
doc.Views.Redraw();
}
}
}
else if (res == GetResult.Option)
{
gx.SetX = opt_xset.CurrentValue;
gx.SetY = opt_yset.CurrentValue;
gx.SetZ = opt_zset.CurrentValue;
continue;
}
else
{
rc = Result.Cancel;
}
break;
}
return rc;
}
}
#endregion
}