29 #define _unused(x) ((void)(x)) 33 #include "SUAPI-CppWrapper/model/ComponentDefinition.hpp" 34 #include "SUAPI-CppWrapper/model/Entities.hpp" 35 #include "SUAPI-CppWrapper/model/ComponentInstance.hpp" 36 #include "SUAPI-CppWrapper/model/Group.hpp" 37 #include "SUAPI-CppWrapper/model/Model.hpp" 38 #include "SUAPI-CppWrapper/model/Opening.hpp" 45 SUComponentDefinitionRef ComponentDefinition::create_definition() {
46 SUComponentDefinitionRef definition = SU_INVALID;
47 SUResult res = SUComponentDefinitionCreate(&definition);
48 assert(res == SU_ERROR_NONE); _unused(res);
52 SUComponentDefinitionRef ComponentDefinition::copy_reference(
const ComponentDefinition& other) {
53 if (other.m_attached && SUIsValid(other.m_entity)) {
57 SUComponentDefinitionRef new_definition = create_definition();
58 if (SUIsValid(other.m_entity)) {
60 SUEntitiesRef new_entities_ref = SU_INVALID;
61 SUResult res = SUComponentDefinitionGetEntities(new_definition, &new_entities_ref);
62 assert(res == SU_ERROR_NONE); _unused(res);
63 Entities new_entities(new_entities_ref, other.model().ref());
64 new_entities.add(other.entities());
66 return new_definition;
80 DrawingElement(SUComponentDefinitionToDrawingElement(definition), attached)
88 DrawingElement(SUComponentDefinitionToDrawingElement(copy_reference(other)))
94 SUComponentDefinitionRef definition = this->
ref();
95 SUComponentDefinitionRelease(&definition);
105 SUComponentDefinitionRef definition = this->
ref();
106 SUResult res = SUComponentDefinitionRelease(&definition);
107 assert(res == SU_ERROR_NONE); _unused(res);
109 m_entity = SUComponentDefinitionToEntity(copy_reference(other));
119 return SUComponentDefinitionFromEntity(
m_entity);
123 ComponentDefinition::operator SUComponentDefinitionRef()
const {
130 throw std::logic_error(
"CW::ComponentDefinition::create_instance(): ComponentDefinition is null");
132 SUComponentInstanceRef instance = SU_INVALID;
133 SUResult res = SUComponentDefinitionCreateInstance(this->
ref(), &instance);
134 assert(res == SU_ERROR_NONE); _unused(res);
152 throw std::logic_error(
"CW::ComponentDefinition::entities(): ComponentDefinition is null");
154 SUEntitiesRef
entities = SU_INVALID;
155 SUResult res = SUComponentDefinitionGetEntities(this->
ref(), &entities);
156 assert(res == SU_ERROR_NONE); _unused(res);
163 throw std::logic_error(
"CW::ComponentDefinition::name(): ComponentDefinition is null");
165 SUStringRef name_string = SU_INVALID;
166 SUResult res = SUStringCreate(&name_string);
167 assert(res == SU_ERROR_NONE);
168 res = SUComponentDefinitionGetName(this->
ref(), &name_string);
169 assert(res == SU_ERROR_NONE); _unused(res);
170 return String(name_string);
176 throw std::logic_error(
"CW::ComponentDefinition::name(): ComponentDefinition is null");
178 SUResult res = SUComponentDefinitionSetName(this->
ref(), std::string(name).c_str());
179 if (res == SU_ERROR_NONE) {
188 throw std::logic_error(
"CW::ComponentDefinition::is_group(): ComponentDefinition is null");
190 SUComponentType type;
191 SUResult res = SUComponentDefinitionGetType(this->
ref(), &type);
192 assert(res == SU_ERROR_NONE); _unused(res);
193 if (type == SUComponentType_Group) {
204 throw std::logic_error(
"CW::ComponentDefinition::behavior(): ComponentDefinition is null");
207 SUResult res = SUComponentDefinitionGetBehavior(this->
ref(), &behavior);
208 assert(res == SU_ERROR_NONE); _unused(res);
214 throw std::logic_error(
"CW::ComponentDefinition::behavior(): ComponentDefinition is null");
216 SUComponentBehavior behavior_ref = behavior.ref();
217 SUResult res = SUComponentDefinitionSetBehavior(this->
ref(), &behavior_ref);
218 assert(res == SU_ERROR_NONE); _unused(res);
224 SUResult res = SUComponentDefinitionGetNumUsedInstances(this->
ref(), &num);
225 assert(res == SU_ERROR_NONE); _unused(res);
232 SUResult res = SUComponentDefinitionGetNumInstances(this->
ref(), &num);
233 assert(res == SU_ERROR_NONE); _unused(res);
239 if (!SUIsValid(this->
ref())) {
240 throw std::logic_error(
"CW::ComponentDefinition::instances(): definition is null");
244 return std::vector<ComponentInstance>{};
246 std::vector<SUComponentInstanceRef> instance_refs(count, SU_INVALID);
247 SUResult res = SUComponentDefinitionGetInstances(this->
ref(), count, instance_refs.data(), &count);
248 assert(res == SU_ERROR_NONE); _unused(res);
249 std::vector<ComponentInstance>
instances(count);
250 std::transform(instance_refs.begin(), instance_refs.end(), instances.begin(),
251 [](
const SUComponentInstanceRef& value) {
260 throw std::logic_error(
"CW::ComponentDefinition::num_openings(): ComponentDefinition is null");
263 SU_RESULT res = SUComponentDefinitionGetNumOpenings(this->
ref(), &count);
264 assert(res == SU_ERROR_NONE); _unused(res);
271 throw std::logic_error(
"CW::ComponentDefinition::num_openings(): ComponentDefinition is null");
274 std::vector<SUOpeningRef> opening_refs(count, SU_INVALID);
275 size_t return_count = 0;
276 SU_RESULT res = SUComponentDefinitionGetOpenings(this->
ref(), count, opening_refs.data(), &return_count);
277 assert(return_count == count);
278 assert(res == SU_ERROR_NONE); _unused(res);
280 openings.reserve(return_count);
281 for (SUOpeningRef p : opening_refs) {
282 openings.push_back(
Opening(p));
292 Behavior::Behavior(SUComponentBehavior behavior):
297 SUComponentBehavior Behavior::ref()
const {
bool m_attached
Indicates whether the Entity has been attached to a model.
ComponentInstance create_instance() const
SUComponentDefinitionRef ref() const
std::vector< Opening > openings() const
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.
size_t num_instances() const
Entities entities() const
size_t num_openings() const
Behavior behavior() const
ComponentDefinition & operator=(const ComponentDefinition &other)
size_t num_used_instances() const
std::vector< ComponentInstance > instances() const