Commit 7f72f487 authored by T.J. Corona's avatar T.J. Corona
Browse files

smtk::Attribute: associations now use the association role

parent c6716dee
......@@ -183,6 +183,7 @@ ReferenceItemDefinitionPtr Definition::createLocalAssociationRule()
m_acceptsRules = ReferenceItemDefinition::New(assocName.str());
m_acceptsRules->setIsExtensible(false);
m_acceptsRules->setNumberOfRequiredValues(0);
m_acceptsRules->setRole(smtk::attribute::Resource::AssociationRole);
}
return m_acceptsRules;
}
......
......@@ -173,15 +173,17 @@ bool ReferenceItem::setObjectValue(PersistentObjectPtr val)
ReferenceItem::Key ReferenceItem::linkTo(PersistentObjectPtr val)
{
auto def = static_cast<const ReferenceItemDefinition*>(this->definition().get());
// If the object is a component...
if (auto component = std::dynamic_pointer_cast<smtk::resource::Component>(val))
{
return this->attribute()->links().addLinkTo(component, Resource::ReferenceRole);
return this->attribute()->links().addLinkTo(component, def->role());
}
// If the object is a resource...
else if (auto resource = std::dynamic_pointer_cast<smtk::resource::Resource>(val))
{
return this->attribute()->links().addLinkTo(resource, Resource::ReferenceRole);
return this->attribute()->links().addLinkTo(resource, def->role());
}
// If the object cannot be cast to a resource or component, there's not much
......
......@@ -14,6 +14,7 @@
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/ReferenceItem.h"
#include "smtk/attribute/Resource.h"
#include "smtk/resource/Container.h"
#include "smtk/resource/Manager.h"
......@@ -34,6 +35,7 @@ ReferenceItemDefinition::ReferenceItemDefinition(const std::string& sname)
m_isExtensible = false;
m_maxNumberOfValues = 0;
m_lockType = smtk::resource::LockType::DoNotLock;
m_role = smtk::attribute::Resource::ReferenceRole;
}
ReferenceItemDefinition::~ReferenceItemDefinition()
......
......@@ -87,6 +87,12 @@ public:
void setLockType(smtk::resource::LockType val) { m_lockType = val; }
smtk::resource::LockType lockType() const { return m_lockType; }
/// Set/Get the reference's role when generating links between the containing
/// attribute and the reference item. By default, this value is set to
/// smtk::attribute::Resource::ReferenceRole.
void setRole(const smtk::resource::Links::RoleType& role) { m_role = role; }
smtk::resource::Links::RoleType role() const { return m_role; }
smtk::attribute::ItemPtr buildItem(Attribute* owningAttribute, int itemPosition) const override;
smtk::attribute::ItemPtr buildItem(Item* owner, int itemPos, int subGroupPosition) const override;
......@@ -111,6 +117,7 @@ protected:
std::size_t m_maxNumberOfValues;
std::multimap<std::string, std::string> m_acceptable;
smtk::resource::LockType m_lockType;
smtk::resource::Links::RoleType m_role;
};
} // namespace attribute
......
......@@ -34,12 +34,14 @@ PySharedPtrClass< smtk::attribute::ReferenceItemDefinition, smtk::attribute::Ite
.def("lockType", &smtk::attribute::ReferenceItemDefinition::lockType)
.def("maxNumberOfValues", &smtk::attribute::ReferenceItemDefinition::maxNumberOfValues)
.def("numberOfRequiredValues", &smtk::attribute::ReferenceItemDefinition::numberOfRequiredValues)
.def("role", &smtk::attribute::ReferenceItemDefinition::role)
.def("setAcceptsEntries", &smtk::attribute::ReferenceItemDefinition::setAcceptsEntries, py::arg("typeName"), py::arg("queryString"), py::arg("accept"))
.def("setCommonValueLabel", &smtk::attribute::ReferenceItemDefinition::setCommonValueLabel, py::arg("elabel"))
.def("setIsExtensible", &smtk::attribute::ReferenceItemDefinition::setIsExtensible, py::arg("extensible"))
.def("setLockType", &smtk::attribute::ReferenceItemDefinition::setLockType, py::arg("val"))
.def("setMaxNumberOfValues", &smtk::attribute::ReferenceItemDefinition::setMaxNumberOfValues, py::arg("maxNum"))
.def("setNumberOfRequiredValues", &smtk::attribute::ReferenceItemDefinition::setNumberOfRequiredValues, py::arg("esize"))
.def("setRole", &smtk::attribute::ReferenceItemDefinition::setRole)
.def("setValueLabel", &smtk::attribute::ReferenceItemDefinition::setValueLabel, py::arg("element"), py::arg("elabel"))
.def("type", &smtk::attribute::ReferenceItemDefinition::type)
.def("typeName", &smtk::attribute::ReferenceItemDefinition::typeName)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment