SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
Vertex.cpp
1 //
2 // Vertex.cpp
3 //
4 // Sketchup C++ Wrapper for C API
5 // MIT License
6 //
7 // Copyright (c) 2017 Tom Kaneko
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 
16 // The above copyright notice and this permission notice shall be included in all
17 // copies or substantial portions of the Software.
18 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 // SOFTWARE.
26 //
27 
28 // Macro for getting rid of unused variables commonly for assert checking
29 #define _unused(x) ((void)(x))
30 
31 #include "SUAPI-CppWrapper/model/Vertex.hpp"
32 
33 #include <cassert>
34 #include <stdexcept>
35 
36 namespace CW {
37 /******************************
38 ** Private Static Methods *****
39 *******************************/
40 SUVertexRef Vertex::copy_reference(const Vertex& other) {
41  // As vertices cannot be "copied", we simply pass the existing reference.
42  return other.ref();
43 }
44 
45 /******************************
46 ** Constructors / Destructor **
47 *******************************/
49  Entity()
50 {}
51 
52 
53 Vertex::Vertex(SUVertexRef vertex):
54  Entity(SUVertexToEntity(vertex), true)
55 {}
56 
57 
58 Vertex::Vertex(const Vertex& other):
59  Entity(other, SUVertexToEntity(copy_reference(other)))
60 {}
61 
62 
64  // Vertices cannot be released, as they are elements that are attached to something else.
65 }
66 
67 
69  // Simply assign the other vertex to this object.
70  m_entity = other.m_entity;
71  Entity::operator=(other);
72  return (*this);
73 }
74 
75 
76 /*******************
77 ** Public Methods **
78 ********************/
80  if (!(*this)) {
81  throw std::logic_error("CW::Vertex::position(): Vertex is null");
82  }
83  SUPoint3D point;
84  SUResult res = SUVertexGetPosition(this->ref(), &point);
85  assert(res == SU_ERROR_NONE); _unused(res);
86  return Point3D(point);
87 }
88 
89 
90 Vertex::operator SUVertexRef() const {
91  return this->ref();
92 }
93 
94 SUVertexRef Vertex::ref() const {
95  return SUVertexFromEntity(m_entity);
96 }
97 
98 Vertex::operator SUPoint3D() const {
99  return position();
100 }
101 
102 Vertex::operator Point3D() const {
103  return position();
104 }
105 
106 } /* namespace CW */
Point3D position() const
Definition: Vertex.cpp:79
Entity()
Constructor representing a null objject.
Definition: Entity.cpp:48
SUEntityRef m_entity
The C SUEntityRef that this class wraps.
Definition: Entity.hpp:59
Definition: Color.hpp:34
Vertex & operator=(const Vertex &other)
Definition: Vertex.cpp:68
Entity & operator=(const Entity &other)
Copy assignment operator.
Definition: Entity.cpp:73