-
Notifications
You must be signed in to change notification settings - Fork 3
/
SelArcCommand.cs
65 lines (57 loc) · 2.02 KB
/
SelArcCommand.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
using Rhino;
using Rhino.Commands;
namespace SelCommands
{
[System.Runtime.InteropServices.Guid("84fc40e8-8b0d-4923-a639-bf7c60e4cd3c")]
public class SelArcCommand : SelCommand
{
public override string EnglishName { get { return "SelArc"; } }
protected bool m_bUseDocTol = true;
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var use_doc_tol = new Rhino.Input.Custom.OptionToggle(m_bUseDocTol, "No", "Yes");
var go = new Rhino.Input.Custom.GetOption();
go.AddOptionToggle("UseDocumentTolerance", ref use_doc_tol);
go.AcceptNothing(true);
go.SetCommandPrompt("Tolerance");
while (go.Get() == Rhino.Input.GetResult.Option) { }
if (go.CommandResult() != Result.Success && go.CommandResult()!= Result.Nothing)
return go.CommandResult();
m_bUseDocTol = use_doc_tol.CurrentValue;
return Result.Success;
}
protected double GetTolerance(Rhino.RhinoDoc doc)
{
if (m_bUseDocTol && doc != null)
return doc.ModelAbsoluteTolerance;
return 0;
}
protected override bool SelFilter(Rhino.DocObjects.RhinoObject rhObj)
{
Rhino.Geometry.Curve crv = rhObj.Geometry as Rhino.Geometry.Curve;
if (crv != null)
{
double tolerance = GetTolerance(rhObj.Document);
// let's say that circles are not arcs in this function
// since we can combine it with SelCircle
return crv.IsArc(tolerance) && !crv.IsCircle(tolerance);
}
return false;
}
}
[System.Runtime.InteropServices.Guid("6EACCAD6-DA41-48A5-8A29-3DCCF5B46DD6")]
public class SelCircleCommand : SelArcCommand
{
public override string EnglishName { get { return "SelCircle"; } }
protected override bool SelFilter(Rhino.DocObjects.RhinoObject rhObj)
{
Rhino.Geometry.Curve crv = rhObj.Geometry as Rhino.Geometry.Curve;
if (crv != null)
{
double tolerance = GetTolerance(rhObj.Document);
return crv.IsCircle(tolerance);
}
return false;
}
}
}