Commit 931929f1 authored by Yumin Yuan's avatar Yumin Yuan
Browse files

Removed the non const accessor of AttributeAssignment map.

In Manager and EntityRef classes, there were non-const accessor to the entity-attributes assignment map, which could potenitally cause inconsistency of the map records in the manager and attribute if developers get hold of the map and modify it directly without going through Manager. By removing these non-const accessors, the developers have to go through the public api in manager to update the map so that we can ensure the map is consistent in the system.
parent 84c400da
......@@ -280,18 +280,18 @@ smtk::attribute::AttributePtr Attribute::pointer() const
*/
void Attribute::removeAllAssociations()
{
if (this->m_associations)
this->m_associations->reset();
smtk::model::ManagerPtr modelMgr = this->modelManager();
if (!modelMgr)
return;
smtk::model::UUIDsToAttributeAssignments::iterator it;
for(it = modelMgr->attributeAssignments().begin();
it != modelMgr->attributeAssignments().end() ; ++it)
if (modelMgr)
{
it->second.disassociateAttribute(this->id());
smtk::model::EntityRefArray::const_iterator it;
for (it = this->m_associations->begin(); it != this->m_associations->end(); ++it)
{
modelMgr->disassociateAttribute(this->system(), this->m_id, it->entity(), false);
}
}
if (this->m_associations)
this->m_associations->reset();
}
/**\brief Is the model \a entity associated with this attribute?
......
......@@ -749,15 +749,13 @@ void qtAssociationWidget::onDomainAssociationChanged()
return;
}
smtk::model::AttributeAssignments atts = domainItem.attributes();
atts.attributes().clear(); //detach all attributes
domainItem.disassociateAllAttributes(attSystem, uid); //detach all attributes
if(combo->currentText().isEmpty())
{
return;
}
QString attName = combo->currentText();
AttributePtr attPtr = attSystem->findAttribute(attName.toStdString());
if(attPtr)
......
......@@ -42,7 +42,7 @@ std::string AttributeListPhrase::title()
{
std::ostringstream message;
DescriptivePhrases::size_type sz =
this->m_attributes.empty() ? this->m_entity.attributes().attributes().size() : this->m_attributes.size();
this->m_attributes.empty() ? this->m_entity.attributes().size() : this->m_attributes.size();
message << sz << " " << (sz == 1 ? "attribute" : "attributes");
return message.str();
}
......
......@@ -678,19 +678,28 @@ bool EntityRef::disassociateAttribute(smtk::attribute::System* sys,
return mgr->disassociateAttribute(sys, attribId, this->m_entity, reverse);
}
/**\brief Does the entityref have any attributes associated with it?
/**\brief Remove all attribute association form this entityref
*/
AttributeAssignments& EntityRef::attributes()
bool EntityRef::disassociateAllAttributes(smtk::attribute::System* sys,
const smtk::common::UUID& fromEntity, bool reverse)
{
ManagerPtr mgr = this->m_manager.lock();
return mgr->attributeAssignments()[this->m_entity];
AttributeSet atts = this->attributes();
AttributeSet::const_iterator it;
bool res = true;
for(it = atts.begin(); it != atts.end(); ++it)
{
if(!this->disassociateAttribute(sys, *it, reverse))
res = false;
}
return res;
}
/**\brief Does the entityref have any attributes associated with it?
*/
AttributeSet EntityRef::attributes() const
{
ManagerPtr mgr = this->m_manager.lock();
return mgr->attributeAssignments()[this->m_entity].attributes();
return mgr->attributeAssignments().find(this->m_entity)->second.attributes();
}
///@}
......
......@@ -178,7 +178,9 @@ public:
bool associateAttribute(smtk::attribute::System* sys, const smtk::common::UUID &attribId);
bool disassociateAttribute(smtk::attribute::System* sys,
const smtk::common::UUID &attribId, bool reverse = true);
AttributeAssignments& attributes();
bool disassociateAllAttributes(smtk::attribute::System* sys,
const smtk::common::UUID& fromEntity, bool reverse = true);
AttributeSet attributes() const;
#ifndef SHIBOKEN_SKIP
......
......@@ -149,11 +149,6 @@ const UUIDsToTessellations& Manager::analysisMesh() const
return *this->m_analysisMesh.get();
}
UUIDsToAttributeAssignments& Manager::attributeAssignments()
{
return *this->m_attributeAssignments;
}
const UUIDsToAttributeAssignments& Manager::attributeAssignments() const
{
return *this->m_attributeAssignments;
......@@ -231,7 +226,7 @@ SessionInfoBits Manager::erase(const UUID& uid, SessionInfoBits flags)
this->tessellations().erase(uid);
if (actual & SESSION_ATTRIBUTE_ASSOCIATIONS)
this->attributeAssignments().erase(uid);
this->m_attributeAssignments->erase(uid);
// TODO: If this entity is a model and has parents, we should make
// the parent own the child models? Erase the children? Leave
......@@ -2865,7 +2860,7 @@ bool Manager::associateAttribute(
allowed = false;
}
if (allowed)
this->attributeAssignments()[toEntity].associateAttribute(attribId);
(*this->m_attributeAssignments)[toEntity].associateAttribute(attribId);
return allowed;
}
......
......@@ -120,7 +120,6 @@ public:
UUIDsToTessellations& analysisMesh();
const UUIDsToTessellations& analysisMesh() const;
UUIDsToAttributeAssignments& attributeAssignments();
const UUIDsToAttributeAssignments& attributeAssignments() const;
BitFlags type(const smtk::common::UUID& ofEntity) const;
......
Supports Markdown
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