-
Notifications
You must be signed in to change notification settings - Fork 5
/
RPCPlugIn.cpp
263 lines (211 loc) · 7.55 KB
/
RPCPlugIn.cpp
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// RPCPlugIn.cpp : defines the initialization routines for the plug-in.
//
#include "StdAfx.h"
#if defined INSITU
#include "../../../SDK/inc/rhinoSdkPlugInDeclare.h"
#else
#include "rhinoSdkPlugInDeclare.h"
#endif
#include "RPCPlugIn.h"
#include "Resource.h"
#include "RpcMains.h"
#include "RpcPropertiesDlg.h"
#include "RpcSelectionDialog.h"
#include "RpcEventWatcher.h"
#include "RpcDocument.h"
#include "LBPFileMgr2.h"
// The plug-in object must be constructed before any plug-in classes derived
// from CRhinoCommand. The #pragma init_seg(lib) ensures that this happens.
#pragma warning(push)
#pragma warning(disable : 4073)
#pragma init_seg(lib)
#pragma warning(pop)
// Rhino plug-in declaration
RHINO_PLUG_IN_DECLARE
// Rhino plug-in name
// Provide a short, friendly name for this plug-in.
RHINO_PLUG_IN_NAME(L"RPC");
// Rhino plug-in id
// Provide a unique uuid for this plug-in.
// {1F908FF5-4984-45A6-95F0-A81CE979A4D7}
RHINO_PLUG_IN_ID(L"1F908FF5-4984-45A6-95F0-A81CE979A4D7");
// Rhino plug-in version
// Provide a version number string for this plug-in.
RHINO_PLUG_IN_VERSION(__DATE__ " " __TIME__)
// Rhino plug-in description
// Provide a description of this plug-in.
RHINO_PLUG_IN_DESCRIPTION(L"RPC plug-in for Rhinoceros");
// Rhino plug-in icon resource id
// Provide an icon resource this plug-in.
// Icon resource should contain 16, 24, 32, 48, and 256-pixel image sizes.
//RHINO_PLUG_IN_ICON_RESOURCE_ID(IDI_ICON);
// Rhino plug-in developer declarations
// TODO: fill in the following developer declarations with
// your company information. Note, all of these declarations
// must be present or your plug-in will not load.
//
// When completed, delete the following #error directive.
RHINO_PLUG_IN_DEVELOPER_ORGANIZATION(L"Robert McNeel & Associates");
RHINO_PLUG_IN_DEVELOPER_ADDRESS (L"3670 Woodland Park Avenue North\r\nSeattle WA 98103");
RHINO_PLUG_IN_DEVELOPER_COUNTRY (L"United States");
RHINO_PLUG_IN_DEVELOPER_PHONE (L"206-545-7000");
RHINO_PLUG_IN_DEVELOPER_FAX (L"206-545-7321");
RHINO_PLUG_IN_DEVELOPER_EMAIL (L"tech@mcneel.com");
RHINO_PLUG_IN_DEVELOPER_WEBSITE (L"http://www.mcneel.com");
RHINO_PLUG_IN_UPDATE_URL (L"http://www.mcneel.com");
// The one and only CRPCPlugIn object
static class CRPCPlugIn thePlugIn;
/////////////////////////////////////////////////////////////////////////////
// CRPCPlugIn definition
CRPCPlugIn& PlugIn()
{
// Return a reference to the one and only CRPCPlugIn object
return thePlugIn;
}
CRPCPlugIn::CRPCPlugIn()
{
// Description:
// CRPCPlugIn constructor. The constructor is called when the
// plug-in is loaded and "thePlugIn" is constructed. Once the plug-in
// is loaded, CRPCPlugIn::OnLoadPlugIn() is called. The
// constructor should be simple and solid. Do anything that might fail in
// CRPCPlugIn::OnLoadPlugIn().
// TODO: Add construction code here
m_plugin_version = RhinoPlugInVersion();
m_pMains = nullptr;
}
/////////////////////////////////////////////////////////////////////////////
// Required overrides
const wchar_t* CRPCPlugIn::PlugInName() const
{
// Description:
// Plug-in name display string. This name is displayed by Rhino when
// loading the plug-in, in the plug-in help menu, and in the Rhino
// interface for managing plug-ins.
// TODO: Return a short, friendly name for the plug-in.
return RhinoPlugInName();
}
const wchar_t* CRPCPlugIn::PlugInVersion() const
{
// Description:
// Plug-in version display string. This name is displayed by Rhino
// when loading the plug-in and in the Rhino interface for managing
// plug-ins.
// TODO: Return the version number of the plug-in.
return m_plugin_version;
}
GUID CRPCPlugIn::PlugInID() const
{
// Description:
// Plug-in unique identifier. The identifier is used by Rhino to
// manage the plug-ins.
// TODO: Return a unique identifier for the plug-in.
// {7F806339-3300-4992-B349-AFC72474696C}
return ON_UuidFromString(RhinoPlugInId());
}
/////////////////////////////////////////////////////////////////////////////
// Additional overrides
BOOL CRPCPlugIn::OnLoadPlugIn()
{
// Description:
// Called after the plug-in is loaded and the constructor has been
// run. This is a good place to perform any significant initialization,
// license checking, and so on. This function must return TRUE for
// the plug-in to continue to load.
// Remarks:
// Plug-ins are not loaded until after Rhino is started and a default document
// is created. Because the default document already exists
// CRhinoEventWatcher::On????Document() functions are not called for the default
// document. If you need to do any document initialization/synchronization then
// override this function and do it here. It is not necessary to call
// CPlugIn::OnLoadPlugIn() from your derived class.
// TODO: Add plug-in initialization code here.
RefreshToolbar();
m_pMains = new CRpcMains(*this);
if (!m_pMains->Initialize())
{
delete m_pMains;
m_pMains = nullptr;
return FALSE;
}
CRpcSelectionDialog::CRhinoTabbedDockBarDialog::Register(
RUNTIME_CLASS(CRpcSelectionDialog),
CRpcSelectionDialog::IDD,
IDI_PROP_RPC,
AfxGetStaticModuleState()
);
CRpcSelectionDialog::OpenPanelInDockBarWithOtherPanel(*RhinoApp().ActiveDoc(), CRpcSelectionDialog::Id(), uuidPanelObjectProps, false);
return TRUE;
}
void CRPCPlugIn::OnUnloadPlugIn()
{
// Description:
// Called one time when plug-in is about to be unloaded. By this time,
// Rhino's mainframe window has been destroyed, and some of the SDK
// managers have been deleted. There is also no active document or active
// view at this time. Thus, you should only be manipulating your own objects.
// or tools here.
// TODO: Add plug-in cleanup code here.
if (nullptr != m_pMains)
{
m_pMains->Uninitialize();
delete m_pMains;
m_pMains = nullptr;
}
}
CRpcMains& CRPCPlugIn::Mains(void)
{
return *m_pMains;
}
void CRPCPlugIn::RefreshToolbar()
{
ON_wString path;
CRhinoFileUtilities::GetRhinoRoamingProfileDataFolder(path);
path += L"UI\\Plug-ins\\";
ON_wString plugin;
GetPlugInFileName(plugin);
ON_wString fname;
ON_wString::SplitPath(plugin, nullptr, nullptr, &fname, nullptr);
fname += L".rui";
path += fname;
if (CRhinoFileUtilities::FileExists(path))
CRhinoFileUtilities::DeleteFile(path);
}
ON_UUID CRPCPlugIn::PropertiesPlugInId() const
{
return ON_UuidFromString(L"334b4fce-860c-415b-89ff-3beaf65ebf52");
}
void CRPCPlugIn::GetPropertiesPages(CRhinoPropertiesPanelPageCollection& collection)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
auto page = &Mains().PropertiesDlg();
if (page)
collection.Add(page);
}
BOOL CRPCPlugIn::CallWriteDocument(const CRhinoFileWriteOptions& options)
{
return TRUE;
}
BOOL CRPCPlugIn::ReadDocument(CRhinoDoc& doc, ON_BinaryArchive& archive, const CRhinoFileReadOptions& options)
{
if (Mains().EventWatcher().IsReferenceDocument() || Mains().EventWatcher().IsMergingDocument())
return TRUE;
if (!Mains().RpcDocument().ReadFromArchive(doc, archive, options))
return FALSE;
Mains().EventWatcher().SetReadingRpcData();
return TRUE;
}
BOOL CRPCPlugIn::WriteDocument(CRhinoDoc& doc, ON_BinaryArchive& archive, const CRhinoFileWriteOptions& options)
{
if (!Mains().RpcDocument().WriteToArchive(doc, archive, options))
return FALSE;
return TRUE;
}
const CLBPString CRPCPlugIn::getRpcApiFilename()
{
const CLBPString sFullPathToPlugIn = PlugIn().PlugInFileName();
CLBPString sPathOnly = CLBPFileMgr2::GetPathOnly(sFullPathToPlugIn);
CLBPFileMgr2::RemoveTrailingSlash(sPathOnly);
const CLBPString sRpcApiDll = sPathOnly + L"\\RPCapi.dll";
return sRpcApiDll;
}