forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdSampleBend.cpp
More file actions
105 lines (87 loc) · 2.85 KB
/
Copy pathcmdSampleBend.cpp
File metadata and controls
105 lines (87 loc) · 2.85 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
#include "stdafx.h"
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN SampleBend command
//
#pragma region SampleBend command
static CRhinoObject* RhinoBendObject(
const CRhinoObject* obj,
const ON_3dPoint& start_pt,
const ON_3dPoint& end_pt,
const ON_3dPoint& arc_pt,
double angle = ON_UNSET_VALUE,
bool bStraight = false,
bool bSymmetric = false,
bool bCopy = false
)
{
if (0 == obj)
return 0;
CRhinoDoc* doc = obj->Document();
if (0 == doc)
return 0;
ON_Line spine(start_pt, end_pt);
if (spine.Length() < ON_ZERO_TOLERANCE)
return 0;
if (ON_IsValid(angle) && fabs(angle) < ON_ZERO_TOLERANCE)
angle = ON_UNSET_VALUE;
CRhinoBendSpaceMorph morph;
morph.SetSpine(spine);
bool bUseAngle = ON_IsValid(angle);
morph.m_bStraightEnd = bStraight || bUseAngle;
morph.m_bSymmetric = bSymmetric;
morph.SetArc(arc_pt, bUseAngle ? angle : ON_UNSET_VALUE);
CRhinoKeepKinkySurfaces keep_creases;
return doc->MorphObject(obj, morph, true, !bCopy);
}
class CCommandSampleBend : public CRhinoCommand
{
public:
CCommandSampleBend() = default;
~CCommandSampleBend() = default;
UUID CommandUUID() override
{
// {F02D2876-34A4-4522-A34A-E96A6FDE412E}
static const GUID SampleBendCommand_UUID =
{ 0xF02D2876, 0x34A4, 0x4522, { 0xA3, 0x4A, 0xE9, 0x6A, 0x6F, 0xDE, 0x41, 0x2E } };
return SampleBendCommand_UUID;
}
const wchar_t* EnglishCommandName() override { return L"SampleBend"; }
CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override ;
};
// The one and only CCommandSampleBend object
static class CCommandSampleBend theSampleBendCommand;
CRhinoCommand::result CCommandSampleBend::RunCommand(const CRhinoCommandContext& context)
{
CRhinoGetObject go;
go.SetCommandPrompt(L"Select surface or polysurface to bend");
go.SetGeometryFilter(CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object);
go.GetObjects(1, 1);
CRhinoCommand::result rc = go.CommandResult();
if (rc != CRhinoCommand::success)
return go.CommandResult();
CArgsRhinoGetLine args;
args.SetFirstPointPrompt(L"Start of spine");
args.SetSecondPointPrompt(L"End of spine");
ON_Line line;
rc = RhinoGetLine(args, line);
if (rc != CRhinoCommand::success)
return go.CommandResult();
CRhinoGetPoint gp;
gp.SetCommandPrompt(L"Point to bend through");
gp.GetPoint();
rc = gp.CommandResult();
if (rc != CRhinoCommand::success)
return go.CommandResult();
CRhinoObject* obj = RhinoBendObject(go.Object(0).Object(), line.from, line.to, gp.Point());
if (obj)
context.m_doc.Redraw();
return CRhinoCommand::success;
}
#pragma endregion
//
// END SampleBend command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////