forked from mdjcad/SampleCsCommands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleCsSubCurve.cs
84 lines (69 loc) · 2.12 KB
/
SampleCsSubCurve.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
using System;
using Rhino;
using Rhino.Commands;
namespace SampleCsCommands
{
[System.Runtime.InteropServices.Guid("06f18176-ac87-45c3-a058-419f20a6908e")]
public class SampleCsSubCurve : Command
{
public SampleCsSubCurve()
{
}
public override string EnglishName
{
get { return "SampleCsSubCurve"; }
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
Rhino.DocObjects.ObjRef obj_ref;
Result rc = Rhino.Input.RhinoGet.GetOneObject("Select curve", false, Rhino.DocObjects.ObjectType.Curve, out obj_ref);
if (rc != Result.Success)
return rc;
Rhino.DocObjects.RhinoObject obj = obj_ref.Object();
if (null == obj)
return Result.Failure;
obj_ref.Object().Select(false);
doc.Views.Redraw();
Rhino.Geometry.Curve crv = obj_ref.Curve();
if (null == crv)
return Result.Failure;
Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
gp.SetCommandPrompt("First point on curve");
gp.Constrain(crv, false);
gp.Get();
rc = gp.CommandResult();
if (rc != Result.Success)
return rc;
double t0 = Rhino.RhinoMath.UnsetValue;
if (null == gp.PointOnCurve(out t0))
return Result.Failure;
gp.SetCommandPrompt("Second point on curve");
gp.Get();
rc = gp.CommandResult();
if (rc != Result.Success)
return rc;
double t1 = Rhino.RhinoMath.UnsetValue;
if (null == gp.PointOnCurve(out t1))
return Result.Failure;
if (System.Math.Abs(t1-t0) < Rhino.RhinoMath.ZeroTolerance)
return Result.Failure;
if (crv.IsClosed || (!crv.IsClosed && t0 > t1))
{
double t = t0;
t0 = t1;
t1 = t;
}
Rhino.Geometry.Interval range = new Rhino.Geometry.Interval(t0, t1);
Rhino.Geometry.Curve subcrv = crv.Trim(range);
if (null != subcrv)
{
System.Guid id = doc.Objects.Add(subcrv);
obj = doc.Objects.Find(id);
if (null != obj)
obj.Select(true);
}
doc.Views.Redraw();
return Result.Success;
}
}
}