forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopennurbs_model_geometry.cpp
354 lines (313 loc) · 10.5 KB
/
opennurbs_model_geometry.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
//
// Copyright (c) 1993-2022 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
#include "opennurbs.h"
#if !defined(ON_COMPILING_OPENNURBS)
// This check is included in all opennurbs source .c and .cpp files to insure
// ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled.
// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined
// and the opennurbs .h files alter what is declared and how it is declared.
#error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs
#endif
ON_OBJECT_IMPLEMENT(ON_ModelGeometryComponent,ON_ModelComponent,"29D1B827-41CE-45C1-B265-0686AA391DAE");
const ON_ModelGeometryComponent* ON_ModelGeometryComponent::FromModelComponentRef(
const class ON_ModelComponentReference& model_component_reference,
const ON_ModelGeometryComponent* none_return_value
)
{
const ON_ModelGeometryComponent* p = ON_ModelGeometryComponent::Cast(model_component_reference.ModelComponent());
return (nullptr != p) ? p : none_return_value;
}
bool ON_ModelGeometryComponent::UpdateReferencedComponents(
const class ON_ComponentManifest& source_manifest,
const class ON_ComponentManifest& destination_manifest,
const class ON_ManifestMap& manifest_map
)
{
bool bGeometryUpdated = false;
for (;;)
{
ON_Object* geometry = m_geometry_sp.get();
if (nullptr == geometry)
{
bGeometryUpdated = true;
break;
}
bGeometryUpdated = geometry->UpdateReferencedComponents(source_manifest,destination_manifest,manifest_map);
break;
}
bool bAttributesUpdated = false;
for (;;)
{
ON_3dmObjectAttributes* attributes = m_attributes_sp.get();
if (nullptr == attributes)
{
bAttributesUpdated = true;
break;
}
if (&ON_3dmObjectAttributes::Unset == attributes)
return false;
if (&ON_3dmObjectAttributes::DefaultAttributes == attributes)
return false;
bAttributesUpdated = attributes->UpdateReferencedComponents(source_manifest,destination_manifest,manifest_map);
break;
}
return bGeometryUpdated && bAttributesUpdated;
}
static ON_ModelComponent::Type Internal_ON_ModelGeometry_TypeFilter(ON_ModelComponent::Type type)
{
switch (type)
{
case ON_ModelComponent::Type::Unset:
return type;
break;
case ON_ModelComponent::Type::Image:
break;
case ON_ModelComponent::Type::TextureMapping:
break;
case ON_ModelComponent::Type::RenderMaterial:
break;
case ON_ModelComponent::Type::LinePattern:
break;
case ON_ModelComponent::Type::Layer:
break;
case ON_ModelComponent::Type::Group:
break;
case ON_ModelComponent::Type::TextStyle:
break;
case ON_ModelComponent::Type::DimStyle:
break;
case ON_ModelComponent::Type::RenderLight:
return type;
break;
case ON_ModelComponent::Type::HatchPattern:
break;
case ON_ModelComponent::Type::InstanceDefinition:
break;
case ON_ModelComponent::Type::ModelGeometry:
return type;
break;
case ON_ModelComponent::Type::HistoryRecord:
break;
case ON_ModelComponent::Type::Mixed:
break;
default:
break;
}
ON_ERROR("Invalid ON_ModelComponent::Type for ON_ModelGeometryComponent.");
return ON_ModelComponent::Type::Unset;
}
ON_ModelGeometryComponent::ON_ModelGeometryComponent() ON_NOEXCEPT
: ON_ModelComponent(Internal_ON_ModelGeometry_TypeFilter(ON_ModelComponent::Type::Unset))
{}
ON_ModelGeometryComponent::ON_ModelGeometryComponent( ON_ModelComponent::Type type ) ON_NOEXCEPT
: ON_ModelComponent(Internal_ON_ModelGeometry_TypeFilter(type))
{}
ON_ModelGeometryComponent::~ON_ModelGeometryComponent()
{
// This destructor is explicitly implemented to insure m_geometry_sp
// and m_attributes_sp are destroyed by the same c-runtime
// that creates them.
}
ON_ModelGeometryComponent::ON_ModelGeometryComponent(const ON_ModelGeometryComponent& src)
: ON_ModelComponent(Internal_ON_ModelGeometry_TypeFilter(src.ComponentType()), src)
, m_geometry_sp(src.m_geometry_sp)
, m_attributes_sp(src.m_attributes_sp)
{}
ON_ModelGeometryComponent& ON_ModelGeometryComponent::operator=(const ON_ModelGeometryComponent& src)
{
if ( this != &src )
{
ON_ModelComponent::operator=(src);
m_geometry_sp.reset();
m_geometry_sp = src.m_geometry_sp;
m_attributes_sp.reset();
m_attributes_sp = src.m_attributes_sp;
SetComponentType(Internal_ON_ModelGeometry_TypeFilter(src.ComponentType()));
}
return *this;
}
ON_ModelGeometryComponent* ON_ModelGeometryComponent::CreateForExperts(
bool bManageGeometry,
ON_Object* geometry_object,
bool bManageAttributes,
ON_3dmObjectAttributes* attributes,
ON_ModelGeometryComponent* model_geometry_component
)
{
ON_ModelComponent::Type component_type;
ON_Geometry* geometry = ON_Geometry::Cast(geometry_object);
ON_Light* light = ON_Light::Cast(geometry);
if (nullptr != light)
component_type = ON_ModelComponent::Type::RenderLight;
else if (nullptr != geometry)
component_type = ON_ModelComponent::Type::ModelGeometry;
else
component_type = ON_ModelComponent::Type::Unset;
if (nullptr == attributes)
{
bManageAttributes = true;
attributes = new ON_3dmObjectAttributes();
if (nullptr != light)
{
attributes->m_uuid = light->m_light_id;
attributes->m_name = light->m_light_name;
}
}
if ( ON_nil_uuid == attributes->m_uuid )
attributes->m_uuid = ON_CreateId();
if (nullptr != light)
{
light->m_light_id = attributes->m_uuid;
light->m_light_name = attributes->m_name;
}
if ( nullptr == model_geometry_component)
model_geometry_component = new ON_ModelGeometryComponent(component_type);
model_geometry_component->m_geometry_sp
= bManageGeometry
? ON_MANAGED_SHARED_PTR(ON_Geometry,geometry)
: ON_UNMANAGED_SHARED_PTR(ON_Geometry,geometry);
model_geometry_component->m_attributes_sp
= bManageAttributes
? ON_MANAGED_SHARED_PTR(ON_3dmObjectAttributes,attributes)
: ON_UNMANAGED_SHARED_PTR(ON_3dmObjectAttributes,attributes);
model_geometry_component->SetId(attributes->m_uuid);
if ( attributes->m_name.IsNotEmpty() )
model_geometry_component->SetName(attributes->m_name);
return model_geometry_component;
}
ON_ModelGeometryComponent* ON_ModelGeometryComponent::Create(
const class ON_Object& geometry_object,
const class ON_3dmObjectAttributes* attributes,
ON_ModelGeometryComponent* model_geometry_component
)
{
const bool bManageGeometry = true;
ON_Object* managed_geometry_object = geometry_object.Duplicate();
const bool bManageAttributes = (nullptr != attributes);
ON_3dmObjectAttributes* managed_attributes = (nullptr != attributes) ? attributes->Duplicate() : nullptr;
return ON_ModelGeometryComponent::CreateForExperts(bManageGeometry,managed_geometry_object,bManageAttributes,managed_attributes,model_geometry_component);
}
ON_ModelGeometryComponent* ON_ModelGeometryComponent::CreateManaged(
ON_Object* geometry_object,
ON_3dmObjectAttributes* object_attributes,
ON_ModelGeometryComponent* model_geometry_component
)
{
bool bManageGeometry = true;
bool bManageAttributes = true;
return ON_ModelGeometryComponent::CreateForExperts(bManageGeometry,geometry_object,bManageAttributes,object_attributes,model_geometry_component);
}
#if defined(ON_HAS_RVALUEREF)
ON_ModelGeometryComponent::ON_ModelGeometryComponent( ON_ModelGeometryComponent&& src) ON_NOEXCEPT
: ON_ModelComponent(std::move(src))
, m_geometry_sp(std::move(src.m_geometry_sp))
, m_attributes_sp(std::move(src.m_attributes_sp))
{}
ON_ModelGeometryComponent& ON_ModelGeometryComponent::operator=(ON_ModelGeometryComponent&& src)
{
if ( this != &src )
{
m_geometry_sp.reset();
m_attributes_sp.reset();
ON_ModelComponent::operator=(std::move(src));
m_geometry_sp = std::move(src.m_geometry_sp);
m_attributes_sp = std::move(src.m_attributes_sp);
}
return *this;
}
#endif
bool ON_ModelGeometryComponent::IsEmpty() const
{
return (nullptr == m_geometry_sp.get());
}
bool ON_ModelGeometryComponent::IsInstanceDefinitionGeometry() const
{
if (nullptr != m_geometry_sp.get())
{
const ON_3dmObjectAttributes* attributes = m_attributes_sp.get();
return (nullptr != attributes && attributes->IsInstanceDefinitionObject() );
}
return false;
}
const ON_Geometry* ON_ModelGeometryComponent::Geometry(
const ON_Geometry* no_geometry_return_value
) const
{
const ON_Geometry* ptr = m_geometry_sp.get();
return (nullptr != ptr) ? ptr : no_geometry_return_value;
}
const ON_3dmObjectAttributes* ON_ModelGeometryComponent::Attributes(
const ON_3dmObjectAttributes* no_attributes_return_value
) const
{
const ON_3dmObjectAttributes* ptr = m_attributes_sp.get();
return (nullptr != ptr) ? ptr : no_attributes_return_value;
}
ON_Geometry* ON_ModelGeometryComponent::ExclusiveGeometry() const
{
return
(1 == m_geometry_sp.use_count())
? m_geometry_sp.get()
: nullptr;
}
ON_3dmObjectAttributes* ON_ModelGeometryComponent::ExclusiveAttributes() const
{
return
(1 == m_attributes_sp.use_count())
? m_attributes_sp.get()
: nullptr;
}
void ON_ModelGeometryComponent::Dump( ON_TextLog& text_log ) const
{
ON_ModelComponent::Dump(text_log);
text_log.Print("Attributes:\n");
text_log.PushIndent();
const ON_3dmObjectAttributes* attributes = Attributes(nullptr);
if (nullptr == attributes)
text_log.Print("Unset\n");
else
{
attributes->Dump(text_log);
// attributes user data
const ON_UserData* ud = attributes->FirstUserData();
while (0 != ud)
{
text_log.Print("Attributes user data:\n");
text_log.PushIndent();
ud->Dump(text_log);
text_log.PopIndent();
ud = ud->Next();
}
}
text_log.PopIndent();
text_log.Print("Geometry:\n");
text_log.PushIndent();
const ON_Object* geometry = Geometry(nullptr);
if (nullptr == geometry)
text_log.Print("Unset\n");
else
{
geometry->Dump(text_log);
// geometry user data
const ON_UserData* ud = geometry->FirstUserData();
while (0 != ud)
{
text_log.Print("Geometry user data:\n");
text_log.PushIndent();
ud->Dump(text_log);
text_log.PopIndent();
ud = ud->Next();
}
}
text_log.PopIndent();
}