29 #define _unused(x) ((void)(x)) 31 #include "SUAPI-CppWrapper/model/Edge.hpp" 36 #include "SUAPI-CppWrapper/Color.hpp" 37 #include "SUAPI-CppWrapper/model/Vertex.hpp" 38 #include "SUAPI-CppWrapper/model/Face.hpp" 44 SUEdgeRef Edge::create_edge(
const Point3D& start,
const Point3D& end) {
46 throw std::invalid_argument(
"CW::Edge::create_edge(): given Point3D is null");
49 throw std::invalid_argument(
"CW::Edge::create_edge(): start and end points are equal - cannot create edge of zero length");
51 SUEdgeRef edge = SU_INVALID;
52 SUPoint3D start_ref = start;
53 SUPoint3D end_ref = end;
54 SUResult res = SUEdgeCreate(&edge, &start_ref, &end_ref);
55 assert(res == SU_ERROR_NONE); _unused(res);
60 SUEdgeRef Edge::copy_reference(
const Edge& other) {
61 if (other.m_attached) {
64 SUEdgeRef new_edge = create_edge(other.start().position(), other.end().position());
76 Edge::Edge(
const std::vector<Point3D>& points):
77 Edge(create_edge(points[0], points[1]),
false)
82 Edge(create_edge(start, end),
false)
87 Edge(start.position(), end.position())
97 DrawingElement(other, SUEdgeToDrawingElement(copy_reference(other)))
100 this->color(other.color());
101 this->smooth(other.smooth());
102 this->soft(other.soft());
109 SUEdgeRef edge = this->
ref();
110 SUResult res = SUEdgeRelease(&edge);
111 assert(res == SU_ERROR_NONE); _unused(res);
118 Edge& Edge::operator=(
const Edge& other) {
120 SUEdgeRef edge = this->
ref();
121 SUResult res = SUEdgeRelease(&edge);
122 assert(res == SU_ERROR_NONE); _unused(res);
124 m_entity = SUEdgeToEntity(copy_reference(other));
126 this->color(other.color());
127 this->smooth(other.smooth());
128 this->soft(other.soft());
139 Edge::operator SUEdgeRef()
const {
152 Color Edge::color()
const {
154 throw std::logic_error(
"CW::Edge::color(): Edge is null");
156 SUColor color = SU_INVALID;
157 SUEdgeGetColor(this->
ref(), &color);
162 bool Edge::color(
const Color& input_color) {
164 throw std::logic_error(
"CW::Edge::color(): Edge is null");
166 SUColor color = input_color.ref();
167 SUResult result = SUEdgeSetColor(this->
ref(), &color);
168 if (result == SU_ERROR_NONE) {
175 Vertex Edge::end()
const {
177 throw std::logic_error(
"CW::Edge::end(): Edge is null");
179 SUVertexRef vertex = SU_INVALID;
180 SUEdgeGetEndVertex(this->
ref(), &vertex);
185 std::vector<Face> Edge::faces()
const {
187 throw std::logic_error(
"CW::Edge::faces(): Edge is null");
190 SUResult res = SUEdgeGetNumFaces(this->
ref(), &count);
191 assert(res == SU_ERROR_NONE);
193 return std::vector<Face>();
195 std::vector<SUFaceRef> face_refs(count, SU_INVALID);
196 res = SUEdgeGetFaces(this->
ref(), count, face_refs.data(), &count);
197 assert(res == SU_ERROR_NONE); _unused(res);
198 std::vector<Face> faces(count);
199 std::transform(face_refs.begin(), face_refs.end(), faces.begin(),
200 [](
const SUFaceRef& value) {
208 throw std::logic_error(
"CW::Edge::vector(): Edge is null");
210 return end().position() - start().position();
214 bool Edge::smooth()
const {
216 throw std::logic_error(
"CW::Edge::smooth(): Edge is null");
219 SUEdgeGetSmooth(this->
ref(), &smooth_flag);
224 bool Edge::smooth(
bool smooth) {
226 throw std::logic_error(
"CW::Edge::smooth(): Edge is null");
228 SUResult result = SUEdgeSetSmooth(this->
ref(), smooth);
229 if (result == SU_ERROR_NONE) {
236 bool Edge::soft()
const {
238 throw std::logic_error(
"CW::Edge::soft(): Edge is null");
241 SUEdgeGetSoft(this->
ref(), &soft_flag);
246 bool Edge::soft(
bool soft) {
248 throw std::logic_error(
"CW::Edge::soft(): Edge is null");
250 SUResult result = SUEdgeSetSoft(this->
ref(), soft);
251 if (result == SU_ERROR_NONE) {
258 Vertex Edge::start()
const {
260 throw std::logic_error(
"CW::Edge::start(): Edge is null");
262 SUVertexRef vertex = SU_INVALID;
263 SUEdgeGetStartVertex(this->
ref(), &vertex);
bool m_attached
Indicates whether the Entity has been attached to a model.
bool attached() const
Returns true if the entity is attached to another object.
DrawingElement & operator=(const DrawingElement &other)
SUEntityRef m_entity
The C SUEntityRef that this class wraps.