forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdSampleCircle.cpp
More file actions
136 lines (108 loc) · 3.67 KB
/
Copy pathcmdSampleCircle.cpp
File metadata and controls
136 lines (108 loc) · 3.67 KB
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
135
136
#include "stdafx.h"
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN SampleCircle command
//
class CGetCircleRadiusPoint : public CRhinoGetPoint
{
public:
CGetCircleRadiusPoint();
void SetCenterPoint(const ON_3dPoint center_point);
bool CalculateCircle(CRhinoViewport& vp, const ON_3dPoint& pt);
void OnMouseMove(CRhinoViewport& vp, UINT flags, const ON_3dPoint& pt, const ON_2iPoint* pt2d);
void DynamicDraw(CRhinoDisplayPipeline& dp, const ON_3dPoint& pt);
const ON_Circle& Circle() const;
private:
ON_Circle m_circle;
ON_3dPoint m_center_point;
bool m_draw_circle;
};
CGetCircleRadiusPoint::CGetCircleRadiusPoint()
{
m_draw_circle = false;
}
void CGetCircleRadiusPoint::SetCenterPoint(const ON_3dPoint center_point)
{
m_center_point = center_point;
}
bool CGetCircleRadiusPoint::CalculateCircle(CRhinoViewport& vp, const ON_3dPoint& pt)
{
double radius = m_center_point.DistanceTo(pt);
if (radius < ON_SQRT_EPSILON)
return false;
ON_Plane plane = vp.ConstructionPlane().m_plane;
plane.SetOrigin(m_center_point);
m_circle.Create(plane, radius);
return m_circle.IsValid() ? true : false;
}
void CGetCircleRadiusPoint::OnMouseMove(CRhinoViewport& vp, UINT flags, const ON_3dPoint& pt, const ON_2iPoint* pt2d)
{
m_draw_circle = CalculateCircle(vp, pt);
CRhinoGetPoint::OnMouseMove(vp, flags, pt, pt2d);
}
void CGetCircleRadiusPoint::DynamicDraw(CRhinoDisplayPipeline& dp, const ON_3dPoint& pt)
{
if (m_draw_circle)
dp.DrawCircle(m_circle, RhinoApp().AppSettings().ActiveLayerColor());
CRhinoGetPoint::DynamicDraw(dp, pt);
}
const ON_Circle& CGetCircleRadiusPoint::Circle() const
{
return m_circle;
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
class CCommandSampleCircle : public CRhinoCommand
{
public:
CCommandSampleCircle() = default;
~CCommandSampleCircle() = default;
UUID CommandUUID() override
{
// {4018B527-BC6E-49EA-B729-4043628802CD}
static const GUID SampleCircleCommand_UUID =
{ 0x4018B527, 0xBC6E, 0x49EA, { 0xB7, 0x29, 0x40, 0x43, 0x62, 0x88, 0x02, 0xCD } };
return SampleCircleCommand_UUID;
}
const wchar_t* EnglishCommandName() override { return L"SampleCircle"; }
CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
void DoHelp() override;
};
// The one and only CCommandSampleCircle object
static class CCommandSampleCircle theSampleCircleCommand;
void CCommandSampleCircle::DoHelp()
{
RhinoApp().Print(L"TODO: Add %s command help here\n", EnglishCommandName());
}
CRhinoCommand::result CCommandSampleCircle::RunCommand(const CRhinoCommandContext& context)
{
CRhinoGetPoint gp;
gp.SetCommandPrompt(L"Center point");
gp.ConstrainToConstructionPlane(FALSE);
gp.GetPoint();
if (gp.CommandResult() != CRhinoCommand::success)
return gp.CommandResult();
ON_3dPoint center_point = gp.Point();
CGetCircleRadiusPoint gc;
gc.SetCommandPrompt(L"Radius");
gc.ConstrainToConstructionPlane(FALSE);
gc.SetBasePoint(center_point);
gc.DrawLineFromPoint(center_point, TRUE);
gc.SetCenterPoint(center_point);
gc.GetPoint();
if (gc.CommandResult() != CRhinoCommand::success)
return gc.CommandResult();
if (gc.CalculateCircle(gc.View()->Viewport(), gc.Point()))
{
ON_Circle circle = gc.Circle();
context.m_doc.AddCurveObject(circle);
context.m_doc.Redraw();
}
return CRhinoCommand::success;
}
//
// END SampleCircle command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////