-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRpcAddCmd.cpp
107 lines (81 loc) · 2.32 KB
/
RpcAddCmd.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
#include "StdAfx.h"
#include "RpcAddCmd.h"
#include "RpcObject.h"
#include "RpcInstance.h"
#include "RpcMains.h"
#include "RpcSelectDlg.h"
#include "RpcFileDlg.h"
#include "RpcUtilities.h"
#include "RpcEditDlg.h"
const wchar_t * CRpcAddCmd::EnglishCommandName()
{
return L"RPC";
}
UUID CRpcAddCmd::CommandUUID()
{
static const UUID uuid =
{
// {49DABEB1-A89E-41a7-9020-D52526CB3AB7}
0x49dabeb1, 0xa89e, 0x41a7, { 0x90, 0x20, 0xd5, 0x25, 0x26, 0xcb, 0x3a, 0xb7 }
};
return uuid;
}
CRhinoCommand::result CRpcAddCmd::RunRpcCommand(const CRhinoCommandContext& context)
{
CRhinoDoc* pDoc = context.Document();
if (!pDoc)
return failure;
pDoc->UnselectAll();
CLBPString sRpc;
if (!GetRpcFileName(*pDoc, sRpc))
return cancel;
CRpcInstance* rpc = new CRpcInstance(*pDoc, sRpc);
if (!rpc->IsValid())
{
delete rpc;
return failure;
}
CRhinoGetPoint gp;
gp.SetCommandPrompt(_RhLocalizeString( L"RPC base point", 36075));
if (CRhinoGet::point != gp.GetPoint())
return cancel;
const ON_3dPoint ptInsertion = gp.Point();
CRhinoInstanceObject* pBlock = rpc->AddToDocument(*pDoc, ptInsertion);
if (!pBlock)
return cancel;
pBlock->Select();
const ON_Xform xfromBlock = pBlock->InstanceXform();
ON_3dPoint ptOfRotation;
ptOfRotation.Zero();
ptOfRotation.Transform(xfromBlock);
const double dScale = pBlock->BoundingBox().Diagonal().Length() / 2.0;
ON_3dPoint ptFirstRef;
ptFirstRef = ON_3dVector::UnitVector(1);
ptFirstRef *= dScale;
ptFirstRef.Transform(xfromBlock);
CLBPString sRotateCmd;
sRotateCmd.Format(L"_Rotate %g,%g,%g %g,%g,%g", ptOfRotation.x, ptOfRotation.y, ptOfRotation.z,
ptFirstRef.x, ptFirstRef.y, ptFirstRef.z);
RhinoApp().RunScript( context.m_rhino_doc_sn, sRotateCmd.Wide());
IRhRdkCustomRenderMeshManager& crmm = ::RhRdkCustomRenderMeshManager();
crmm.OnRhinoDocumentChanged(*pDoc);
pDoc->Redraw();
return success;
}
bool CRpcAddCmd::GetRpcFileName(CRhinoDoc& doc, CLBPString& sRpc)
{
CWnd* pParentWnd = CWnd::FromHandle(RhinoApp().MainWnd());
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CRpcAdvancedFileDialog dlg(pParentWnd);
CRpcSelectDlg dlgRpcSelect(doc, (const wchar_t*)dlg.GetPathName());
if (dlgRpcSelect.DoModal() != IDOK)
{
return false;
}
CLBPString sSel = dlgRpcSelect.Selection();
if (sSel.IsEmpty())
return false;
sRpc = sSel;
return true;
}