29 #define _unused(x) ((void)(x)) 34 #include "SUAPI-CppWrapper/model/GeometryInput.hpp" 36 #include <SketchupAPI/sketchup_info.h> 38 #include "SUAPI-CppWrapper/Initialize.hpp" 39 #include "SUAPI-CppWrapper/model/Model.hpp" 40 #include "SUAPI-CppWrapper/model/Entities.hpp" 41 #include "SUAPI-CppWrapper/model/Vertex.hpp" 42 #include "SUAPI-CppWrapper/model/Loop.hpp" 43 #include "SUAPI-CppWrapper/model/LoopInput.hpp" 44 #include "SUAPI-CppWrapper/model/Layer.hpp" 45 #include "SUAPI-CppWrapper/model/Material.hpp" 46 #include "SUAPI-CppWrapper/model/Face.hpp" 47 #include "SUAPI-CppWrapper/model/Edge.hpp" 48 #include "SUAPI-CppWrapper/model/MaterialInput.hpp" 52 std::unordered_map<SUGeometryInputRef, size_t> GeometryInput::num_objects_ = {};
57 SUGeometryInputRef GeometryInput::create_geometry_input() {
58 SUGeometryInputRef geom_input = SU_INVALID;
59 SUResult res = SUGeometryInputCreate(&geom_input);
60 assert(res == SU_ERROR_NONE); _unused(res);
84 m_geometry_input(create_geometry_input()),
86 m_target_model(target_model)
88 num_objects_[m_geometry_input] = 1;
93 if (SUIsValid(m_geometry_input) && !m_attached && num_objects_[m_geometry_input] == 1) {
94 num_objects_.erase(m_geometry_input);
95 SUResult res = SUGeometryInputRelease(&m_geometry_input);
96 assert(res == SU_ERROR_NONE); _unused(res);
99 --num_objects_[m_geometry_input];
105 m_target_model(other.m_target_model)
107 if (SUIsValid(m_geometry_input) && !m_attached && num_objects_[m_geometry_input] == 1) {
108 num_objects_.erase(m_geometry_input);
109 SUResult res = SUGeometryInputRelease(&m_geometry_input);
110 assert(res == SU_ERROR_NONE); _unused(res);
113 --num_objects_[m_geometry_input];
115 m_geometry_input = other.m_geometry_input;
116 m_attached = other.m_attached;
117 ++num_objects_[m_geometry_input];
122 if (SUIsValid(m_geometry_input) && !m_attached && num_objects_[m_geometry_input] == 1) {
123 num_objects_.erase(m_geometry_input);
124 SUResult res = SUGeometryInputRelease(&m_geometry_input);
125 assert(res == SU_ERROR_NONE); _unused(res);
128 --num_objects_[m_geometry_input];
130 m_geometry_input = other.m_geometry_input;
131 m_attached = other.m_attached;
132 m_target_model = other.m_target_model;
133 ++num_objects_[m_geometry_input];
140 return m_geometry_input;
145 return SUIsInvalid(m_geometry_input);
151 throw std::logic_error(
"CW::GeometryInput::num_faces(): GeometryInput is null");
159 throw std::logic_error(
"CW::GeometryInput::add_face(): GeometryInput is null");
162 throw std::invalid_argument(
"CW::GeometryInput::add_face(): Face argument is null");
166 std::vector<Point3D> outer_points = face.outer_loop().
points();
167 std::vector<Edge> outer_edges = face.outer_loop().
edges();
168 for (
size_t i=0; i < outer_points.size(); ++i) {
169 size_t v_index = this->
add_vertex(outer_points[i]);
171 if (outer_edges[i].hidden()) {
172 outer_loop_input.set_edge_hidden(v_index,
true);
174 if (outer_edges[i].smooth()) {
175 outer_loop_input.set_edge_smooth(v_index,
true);
177 if (outer_edges[i].soft()) {
178 outer_loop_input.set_edge_soft(v_index,
true);
182 size_t added_face_index = this->
add_face(outer_loop_input);
184 std::vector<Loop> inner_loops = face.
inner_loops();
185 for (
size_t i=0; i < inner_loops.size(); ++i) {
187 std::vector<Point3D> inner_points = inner_loops[i].points();
188 std::vector<Edge> inner_edges = inner_loops[i].edges();
189 for (
size_t j=0; j < inner_points.size(); ++j) {
190 size_t v_index = this->
add_vertex(inner_points[i]);
192 if (inner_edges[i].hidden()) {
193 inner_loop_input.set_edge_hidden(v_index,
true);
195 if (inner_edges[i].smooth()) {
196 inner_loop_input.set_edge_smooth(v_index,
true);
198 if (inner_edges[i].soft()) {
199 inner_loop_input.set_edge_soft(v_index,
true);
205 if (copy_material_layer) {
209 assert(
Model(m_target_model,
false).layer_exists(face_layer));
210 this->
face_layer(added_face_index, face_layer);
214 Material front_mat = face.material();
217 assert(
Model(m_target_model,
false).material_exists(front_material_input.material()));
220 Material back_mat = face.back_material();
223 assert(
Model(m_target_model,
false).material_exists(back_material_input.material()));
228 return added_face_index;
232 size_t GeometryInput::add_faces(
const std::vector<Face>& faces,
bool copy_material_layer) {
234 throw std::logic_error(
"CW::GeometryInput::add_faces(): GeometryInput is null");
237 for (
size_t i=0; i < faces.size(); ++i) {
246 throw std::invalid_argument(
"CW::GeometryInput::add_edge(): Edge argument is null");
248 if (SU_API_VERSION_MAJOR < 5) {
253 size_t start_index = this->
add_vertex(start_point);
255 size_t end_index = this->
add_vertex(end_point);
256 size_t added_edge_index = this->
add_edge(start_index, end_index);
269 return added_edge_index;
273 size_t GeometryInput::add_edges(
const std::vector<Edge>& edges) {
275 throw std::logic_error(
"CW::GeometryInput::add_edges(): GeometryInput is null");
278 for (
size_t i=0; i < edges.size(); ++i) {
287 throw std::logic_error(
"CW::GeometryInput::empty(): GeometryInput is null");
290 if (counts[1] == 0 && counts[2] == 0) {
298 SUResult res = SUGeometryInputAddVertex(m_geometry_input, point);
299 assert(res == SU_ERROR_NONE); _unused(res);
301 return m_vertex_index-1;
306 assert(this->
counts()[1] == 0);
307 assert(this->
counts()[2] == 0);
308 SUResult res = SUGeometryInputSetVertices(m_geometry_input, points.size(), points.data());
309 assert(res == SU_ERROR_NONE); _unused(res);
311 m_vertex_index = points.size();
316 std::vector<SUPoint3D> point_refs(points.size());
317 std::transform(points.begin(), points.end(), point_refs.begin(),
326 size_t added_edge_index;
327 SUResult res = SUGeometryInputAddEdge(m_geometry_input, vertex0_index, vertex1_index, &added_edge_index);
328 assert(res == SU_ERROR_NONE); _unused(res);
329 return added_edge_index;
334 SUResult res = SUGeometryInputEdgeSetHidden(m_geometry_input, edge_index, hidden);
335 assert(res == SU_ERROR_NONE); _unused(res);
340 SUResult res = SUGeometryInputEdgeSetSoft(m_geometry_input, edge_index, soft);
341 assert(res == SU_ERROR_NONE); _unused(res);
346 SUResult res = SUGeometryInputEdgeSetSmooth(m_geometry_input, edge_index, smooth);
347 assert(res == SU_ERROR_NONE); _unused(res);
352 SUResult res = SUGeometryInputEdgeSetMaterial(m_geometry_input, edge_index, material.ref());
353 assert(res == SU_ERROR_NONE); _unused(res);
359 SUResult res = SUGeometryInputEdgeSetLayer(m_geometry_input, edge_index, layer.
ref());
360 assert(res == SU_ERROR_NONE); _unused(res);
366 size_t added_curve_index;
367 SUResult res = SUGeometryInputAddCurve(m_geometry_input, edge_indices.size(), edge_indices.data(), &added_curve_index);
368 assert(res == SU_ERROR_NONE); _unused(res);
369 return added_curve_index;
374 size_t added_curve_index;
375 size_t control_edge_index;
376 SUResult res = SUGeometryInputAddArcCurve(m_geometry_input, start_point, end_point, center, normal, num_segments, &added_curve_index, &control_edge_index);
377 assert(res == SU_ERROR_NONE); _unused(res);
378 return std::pair<size_t, size_t> {added_curve_index, control_edge_index};
383 size_t added_face_index;
384 SULoopInputRef loop_ref = loop_input.ref();
385 SUResult res = SUGeometryInputAddFace(m_geometry_input, &loop_ref, &added_face_index);
386 assert(res == SU_ERROR_NONE); _unused(res);
387 loop_input.m_attached =
true;
388 return added_face_index;
393 SUResult res = SUGeometryInputFaceSetReverse(m_geometry_input, face_index, reverse);
394 assert(res == SU_ERROR_NONE); _unused(res);
399 SUResult res = SUGeometryInputFaceSetLayer(m_geometry_input, face_index, layer.
ref());
400 assert(res == SU_ERROR_NONE); _unused(res);
405 SULoopInputRef loop_ref = inner_loop.ref();
406 SUResult res = SUGeometryInputFaceAddInnerLoop(m_geometry_input, face_index, &loop_ref);
407 assert(res == SU_ERROR_NONE); _unused(res);
408 inner_loop.m_attached =
true;
413 SUMaterialInput material_ref = material_input.ref();
414 SUResult res = SUGeometryInputFaceSetFrontMaterial(m_geometry_input, face_index, &material_ref);
415 assert(res == SU_ERROR_NONE); _unused(res);
421 SUMaterialInput material_ref = material_input.ref();
422 SUResult res = SUGeometryInputFaceSetBackMaterial (m_geometry_input, face_index, &material_ref);
423 assert(res == SU_ERROR_NONE); _unused(res);
429 SUResult res = SUGeometryInputFaceSetHidden(m_geometry_input, face_index, hidden);
430 assert(res == SU_ERROR_NONE); _unused(res);
435 std::array<size_t, 5> count_arr;
436 SUResult res = SUGeometryInputGetCounts(m_geometry_input, &count_arr[0], &count_arr[1], &count_arr[2], &count_arr[3], &count_arr[4]);
437 assert(res == SU_ERROR_NONE); _unused(res);
443 bool operator==(
const SUGeometryInputRef& lhs,
const SUGeometryInputRef& rhs) {
444 return lhs.ptr == rhs.ptr;
std::vector< Edge > edges() const
bool attached() const
Returns true if the entity is attached to another object.
std::vector< Loop > inner_loops() const
std::vector< Point3D > points() const