-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcmdObliq.cpp
More file actions
149 lines (122 loc) · 4.67 KB
/
Copy pathcmdObliq.cpp
File metadata and controls
149 lines (122 loc) · 4.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
137
138
139
140
141
142
143
144
145
146
147
148
149
// cmdObliq.cpp : command file
//
#include "stdafx.h"
#include "ObliqPlugIn.h"
#include "ObliqueConduit.h"
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN Obliq command
//
#pragma region Obliq command
// Do NOT put the definition of class CCommandObliq in a header
// file. There is only ONE instance of a CCommandObliq class
// and that instance is the static theObliqCommand that appears
// immediately below the class definition.
class CCommandObliq : public CRhinoCommand
{
public:
// The one and only instance of CCommandObliq is created below.
// No copy constructor or operator= is required.
// Values of member variables persist for the duration of the application.
// CCommandObliq::CCommandObliq()
// is called exactly once when static theObliqCommand is created.
CCommandObliq() = default;
// CCommandObliq::~CCommandObliq()
// is called exactly once when static theObliqCommand is destroyed.
// The destructor should not make any calls to the Rhino SDK.
// If your command has persistent settings, then override
// CRhinoCommand::SaveProfile and CRhinoCommand::LoadProfile.
~CCommandObliq() = default;
// Returns a unique UUID for this command.
// If you try to use an id that is already being used, then
// your command will not work. Use GUIDGEN.EXE to make unique UUID.
UUID CommandUUID() override
{
// {538A3CCE-B912-474B-95DF-69BDE41AE976}
static const GUID ObliqCommand_UUID =
{0x538a3cce,0xb912,0x474b,{0x95,0xdf,0x69,0xbd,0xe4,0x1a,0xe9,0x76}};
return ObliqCommand_UUID;
}
// Returns the English command name.
// If you want to provide a localized command name, then override
// CRhinoCommand::LocalCommandName.
const wchar_t* EnglishCommandName() override { return L"Obliq"; }
// Rhino calls RunCommand to run the command.
CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
};
// The one and only CCommandObliq object
// Do NOT create any other instance of a CCommandObliq class.
static class CCommandObliq theObliqCommand;
CRhinoCommand::result CCommandObliq::RunCommand(const CRhinoCommandContext& context)
{
// CCommandObliq::RunCommand() is called when the user
// runs the "Obliq".
// TODO: Add command code here.
CRhinoDoc* doc = context.Document();
if (nullptr == doc)
return CRhinoCommand::failure;
// Record existing viewport IDs before creating a new one
ON_SimpleArray<ON_UUID> viewport_ids;
ON_SimpleArray<CRhinoView*> view_list;
CRhinoView* view = nullptr;
int i = 0;
doc->GetViewList(view_list, CRhinoView::ViewTypeFilter::Model);
for (i = 0; i < view_list.Count(); i++)
{
view = view_list[i];
if (view)
viewport_ids.Append(view->ActiveViewportID());
}
view_list.Empty();
// Create the new view
doc->NewView(ON_3dmView(), true);
// Find the newly created view by diffing against the old ID list
doc->GetViewList(view_list, CRhinoView::ViewTypeFilter::Model);
for (i = 0; i < view_list.Count(); i++)
{
view = view_list[i];
if (view)
{
int rc = viewport_ids.Search(view->ActiveViewportID());
if (rc < 0)
break;
else
view = nullptr;
}
}
if (view)
{
ON_Viewport onvp = view->ActiveViewport().VP();
onvp.SetProjection(ON::parallel_view);
onvp.SetCameraLocation(ON_3dPoint(0.0, 0.0, 100.0));
onvp.SetCameraDirection(ON_3dVector(0.0, 0.0, -1.0));
onvp.SetCameraUp(ON_3dVector(0.0, 1.0, 0.0));
double hw = 30.0, hh = 30.0;
onvp.SetFrustum(-hw, hw, -hh, hh, 0.1, 1000.0);
onvp.SetTargetPoint(ON_3dPoint(0.0, 0.0, 0.0));
view->ActiveViewport().SetVP(onvp, true);
ON_3dmView v = view->ActiveViewport().View();
v.m_name = L"Oblique";
view->ActiveViewport().SetView(v);
view->FloatRhinoView(true);
static CObliqueConduit s_conduit;
s_conduit.SetObliqueParams(90.0, 1.0);
s_conduit.SetViewportId(view->ActiveViewportID()); // track which viewport
s_conduit.Bind(view->ActiveViewport().VP()); // Bind takes const ON_Viewport&
s_conduit.Enable(doc->RuntimeSerialNumber());
view->Redraw();
}
else
{
RhinoApp().Print(L"Ptest: Failed to find new viewport.\n");
return CRhinoCommand::failure;
}
return CRhinoCommand::success;
}
#pragma endregion
//
// END Obliq command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////