forked from mcneel/rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LBPRhObjectSelection.cpp
301 lines (233 loc) · 6.85 KB
/
LBPRhObjectSelection.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// GAWK-MARKER
#include "stdafx.h"
#ifdef LBPRHLIB
#include "LBPRhObjectSelection.h"
#include "LBPLibUtilities.h"
static IRhinoPropertiesPanelPageEventArgs* Args(const IRhinoPropertiesPanelPage* page)
{
return IRhinoPropertiesPanelPageEventArgs::FromPage(page);
}
int LBPRhCountMeshableObjects(const IRhinoPropertiesPanelPage* pDialogPage)
{
IRhinoPropertiesPanelPageEventArgs* args = IRhinoPropertiesPanelPageEventArgs::FromPage(pDialogPage);
if (args == nullptr)
return 0;
const int iCount = args->ObjectCount();
int iMeshableCount = 0;
for (int i = 0; i < iCount; i++)
{
const CRhinoObject* pObject = args->ObjectAt(i);
if(pObject && pObject->IsMeshable(ON::render_mesh))
{
iMeshableCount++;
}
}
return iMeshableCount;
}
bool LBPRhContainsMeshableObjects(const IRhinoPropertiesPanelPage* pDialogPage)
{
IRhinoPropertiesPanelPageEventArgs* args = IRhinoPropertiesPanelPageEventArgs::FromPage(pDialogPage);
if (args == nullptr)
return 0;
const int iCount = args->ObjectCount();
for (int i = 0; i < iCount; i++)
{
const CRhinoObject* pObject = args->ObjectAt(i);
if(pObject && pObject->IsMeshable(ON::render_mesh))
{
return true;
}
}
return false;
}
CLBPRhObjectSelection::CLBPRhObjectSelection(const CRhinoDoc& doc)
: m_runtime_document_serial_number(doc.RuntimeSerialNumber())
{
m_iIterationIndex = -1;
}
CLBPRhObjectSelection::CLBPRhObjectSelection(const IRhinoPropertiesPanelPage* pDialogPage, bool bMeshableOnly)
: m_aObjects(Args(pDialogPage) ? Args(pDialogPage)->ObjectCount() : 1),
m_runtime_document_serial_number(Args(pDialogPage) ? Args(pDialogPage)->DocumentRuntimeSerialNumber() : CRhinoDoc::NullRuntimeSerialNumber)
{
m_iIterationIndex = -1;
IRhinoPropertiesPanelPageEventArgs* args = IRhinoPropertiesPanelPageEventArgs::FromPage(pDialogPage);
const int iCount = args == nullptr ? 0 : args->ObjectCount();
m_aObjects.SetCapacity(iCount);
for (int i = 0; i < iCount; i++)
{
const CRhinoObject* pObject = args->ObjectAt(i);
if(pObject)
{
if(!bMeshableOnly || pObject->IsMeshable(ON::render_mesh))
{
m_aObjects.Append(pObject->Attributes().m_uuid);
}
}
}
}
CLBPRhObjectSelection::CLBPRhObjectSelection(const CRhinoDoc& doc, bool bMeshableOnly)
: m_aObjects(CountSelectedObjects(doc)),
m_runtime_document_serial_number(doc.RuntimeSerialNumber())
{
CRhinoObjectIterator it(doc, CRhinoObjectIterator::normal_or_locked_objects, CRhinoObjectIterator::active_and_reference_objects);
const CRhinoObject* pObject = it.First();
while(pObject != NULL)
{
if(pObject->IsSelected() && (!bMeshableOnly || pObject->IsMeshable(ON::render_mesh)))
{
m_aObjects.Append(pObject->Attributes().m_uuid);
}
pObject = it.Next();
}
}
CLBPRhObjectSelection::CLBPRhObjectSelection(const IRhinoPropertiesPanelPage* pDialogPage, ON::object_type ot)
: m_aObjects(Args(pDialogPage) ? Args(pDialogPage)->ObjectCount() : 1),
m_runtime_document_serial_number(Args(pDialogPage) ? Args(pDialogPage)->DocumentRuntimeSerialNumber() : CRhinoDoc::NullRuntimeSerialNumber)
{
m_iIterationIndex = -1;
auto* args = Args(pDialogPage);
const int iCount = args == nullptr ? 0 : args->ObjectCount();
m_aObjects.SetCapacity(iCount);
for (int i = 0; i < iCount; i++)
{
const CRhinoObject* pObject = args->ObjectAt(i);
if(pObject)
{
if(ot & pObject->ObjectType())
{
m_aObjects.Append(pObject->Attributes().m_uuid);
}
}
}
}
CLBPRhObjectSelection::CLBPRhObjectSelection(const CLBPRhObjectSelection& sel)
: m_aObjects(sel.Count()),
m_runtime_document_serial_number(sel.m_runtime_document_serial_number)
{
m_iIterationIndex = -1;
const int iCount = sel.m_aObjects.Count();
m_aObjects.SetCapacity(iCount);
for (int i = 0; i < iCount; i++)
{
m_aObjects.Append(sel.m_aObjects[i]);
}
}
CLBPRhObjectSelection::CLBPRhObjectSelection(const CRhinoDoc& doc, const ON_SimpleArray<UUID>& aObjects)
: m_aObjects(aObjects.Count()),
m_runtime_document_serial_number(doc.RuntimeSerialNumber())
{
m_iIterationIndex = -1;
const int iCount = aObjects.Count();
m_aObjects.SetCapacity(iCount);
for (int i=0; i<iCount; i++)
{
m_aObjects.Append(aObjects[i]);
}
}
int CLBPRhObjectSelection::Count(void) const
{
return m_aObjects.Count();
}
const CRhinoObject * CLBPRhObjectSelection::First(void) const
{
m_iIterationIndex = -1;
return Next();
}
const CRhinoObject * CLBPRhObjectSelection::Next(void) const
{
if (++m_iIterationIndex >= m_aObjects.Count())
return NULL;
const CRhinoDoc* pDoc = LBPRhDocFromRuntimeSerialNumber(m_runtime_document_serial_number);
if (pDoc != NULL)
{
return pDoc->LookupObject(m_aObjects[m_iIterationIndex]);
}
return NULL;
}
DWORD CLBPRhObjectSelection::CRC(void) const
{
//May not work if the objects are in a different order
const int iCount = m_aObjects.Count();
if(0==iCount) return 0;
UUID* pBuffer = new UUID[iCount];
int i;
for (i = 0; i < iCount; i++)
{
const UUID uuid = m_aObjects[i];
memcpy((void*)(&pBuffer[i]), &uuid, sizeof(m_aObjects[i]));
}
DWORD dw = 123456;
dw = ON_CRC32(dw, sizeof(m_aObjects[i]) * iCount, (void*)pBuffer);
delete [] pBuffer;
return dw;
}
void CLBPRhObjectSelection::BoundingBox(ON_BoundingBox& boxOut) const
{
for (int i = 0; i < m_aObjects.Count(); i++)
{
auto* pDoc = CRhinoDoc::FromRuntimeSerialNumber(DocumentSerialNumber());
if (pDoc)
{
const CRhinoObject* pObject = pDoc->LookupObject(m_aObjects[i]);
if (NULL != pObject)
{
if (0 == i)
{
boxOut = pObject->BoundingBox();
}
else
{
boxOut.Union(pObject->BoundingBox());
}
}
}
}
}
bool CLBPRhObjectSelection::operator==(const CLBPRhObjectSelection& selection)
{
return CRC() == selection.CRC();
}
CLBPRhObjectList::CLBPRhObjectList(const CRhinoDoc& doc)
: m_runtime_document_serial_number(doc.RuntimeSerialNumber())
{
}
int CLBPRhObjectList::Count(void) const
{
ASSERT(m_aObjects.Count() == (int)m_mapObjects.Count());
return m_aObjects.Count();
}
void CLBPRhObjectList::AddObjects(const CLBPRhObjectSelection& sel)
{
const CRhinoObject* pObject = sel.First();
while (NULL != pObject)
{
Add(pObject);
pObject = sel.Next();
}
}
void CLBPRhObjectList::Add(const CRhinoObject* pObject)
{
const UUID& uuid = pObject->Attributes().m_uuid;
int i;
if (m_mapObjects.Lookup(uuid, i))
return;
m_aObjects.Append(uuid);
m_mapObjects.SetAt(uuid, 0);
}
void CLBPRhObjectList::Clear(void)
{
m_aObjects.Destroy();
m_mapObjects.Destroy();
}
const CRhinoObject* CLBPRhObjectList::Object(int iIndex) const
{
if ((iIndex < 0) || (iIndex >= m_aObjects.Count()))
return NULL;
const CRhinoDoc* pDoc = LBPRhDocFromRuntimeSerialNumber(m_runtime_document_serial_number);
if (pDoc != NULL)
{
return pDoc->LookupObject(m_aObjects[iIndex]);
}
return NULL;
}
#endif