Commit 32790424 authored by David Thompson's avatar David Thompson
Browse files

Add "assign names" property to model Operator.

When set (it is optional and its default value is OFF),
entity names will be assigned after each operation is
performed.

Names will only be assigned to models listed explicitly
by UUID in the operator result's "entities" item.

This is an efficient way for user interfaces to control
"prettification" of names.
parent 7c0f05ef
......@@ -16,6 +16,7 @@
#include "smtk/model/SessionRef.h"
#include "smtk/model/Chain.h"
#include "smtk/model/DefaultSession.h"
#include "smtk/model/EntityIterator.h"
#include "smtk/model/EntityRefArrangementOps.h"
#include "smtk/model/Edge.h"
#include "smtk/model/EdgeUse.h"
......@@ -1341,6 +1342,46 @@ void Manager::assignDefaultNames()
}
}
/**\brief Assign a string property named "name" to every entity of a model without one.
*
* This descends models rather than blindly iterating over UUIDs;
* it is thus much faster than calling assignDefaultName() on each entity UUID.
*/
void Manager::assignDefaultNamesToModelChildren(const smtk::common::UUID& modelId)
{
bool oops = true;
UUIDWithEntity it = this->m_topology->find(modelId);
if (it != this->m_topology->end())
{
Model model(shared_from_this(), modelId);
if (model.isValid())
{
oops = false;
EntityIterator it;
it.traverse(model, ITERATE_MODELS);
model.assignDefaultName();
std::string modelName = model.name();
UUIDs dummy;
for (it.begin(); !it.isAtEnd(); ++it)
{
if (it->isSessionRef())
(*it).assignDefaultName();
else
this->assignDefaultNamesWithOwner(
this->m_topology->find(it->entity()),
model.entity(),
modelName, dummy, true);
}
}
}
if (oops)
{
smtkWarningMacro(this->m_log,
"Tried to assign default names to a non-model entity: "
<< EntityRef(shared_from_this(), modelId).name() << ".");
}
}
/**\brief Assign a string property named "name" to the given entity.
*
* If a model can be identified as owning an entity, the default name
......
......@@ -183,6 +183,7 @@ public:
smtk::common::UUID modelOwningEntity(const smtk::common::UUID& uid) const;
void assignDefaultNames();
void assignDefaultNamesToModelChildren(const smtk::common::UUID& modelId);
std::string assignDefaultName(const smtk::common::UUID& uid);
static std::string shortUUIDName(const smtk::common::UUID& uid, BitFlags entityFlags);
......
......@@ -210,5 +210,11 @@ StringList Model::operatorNames() const
return this->session().operatorNames();
}
/// An efficient method for assigning default names to all of the model's entities.
void Model::assignDefaultNames()
{
this->manager()->assignDefaultNamesToModelChildren(this->entity());
}
} // namespace model
} // namespace smtk
......@@ -57,6 +57,8 @@ public:
OperatorPtr op(const std::string& operatorName) const;
StringList operatorNames() const;
void assignDefaultNames();
};
/// Add all the free cells in \a container to this model.
......
......@@ -94,6 +94,22 @@ OperatorResult Operator::operate()
result = this->operateInternal();
else
result = this->createResult(OPERATION_CANCELED);
smtk::attribute::IntItem::Ptr assignNamesItem;
if (
result->findInt("outcome")->value() == OPERATION_SUCCEEDED &&
(assignNamesItem = this->specification()->findInt("assign names")) &&
assignNamesItem->isEnabled() &&
assignNamesItem->value() != 0)
{
ModelEntityItem::Ptr thingsToName = result->findModelEntity("entities");
EntityRefArray::const_iterator it;
for (it = thingsToName->begin(); it != thingsToName->end(); ++it)
{
Model model(*it);
if (model.isValid())
model.assignDefaultNames();
}
}
std::size_t logEnd = this->log().numberOfRecords();
if (logEnd > logStart)
{ // Serialize relevant log records to JSON.
......
......@@ -284,9 +284,17 @@ void Session::initializeOperatorSystem(const OperatorConstructors* opList)
this->m_operatorSys = new smtk::attribute::System;
// Create the "base" definitions that all operators and results will inherit.
this->m_operatorSys->createDefinition("operator");
Definition::Ptr opdefn = this->m_operatorSys->createDefinition("operator");
Definition::Ptr defn = this->m_operatorSys->createDefinition("result");
IntItemDefinition::Ptr assignNamesDefn = IntItemDefinition::New("assign names");
// Do not assign names to entities after the operation by default:
assignNamesDefn->setDefaultValue(0);
assignNamesDefn->setIsOptional(true);
assignNamesDefn->setAdvanceLevel(11);
opdefn->addItemDefinition(assignNamesDefn);
Definition::Ptr resultdefn = this->m_operatorSys->createDefinition("result");
IntItemDefinition::Ptr outcomeDefn = IntItemDefinition::New("outcome");
ModelEntityItemDefinition::Ptr entoutDefn = ModelEntityItemDefinition::New("entities");
ModelEntityItemDefinition::Ptr entremDefn = ModelEntityItemDefinition::New("expunged");
......@@ -305,10 +313,10 @@ void Session::initializeOperatorSystem(const OperatorConstructors* opList)
logDefn->setIsExtensible(1);
logDefn->setIsOptional(true);
defn->addItemDefinition(outcomeDefn);
defn->addItemDefinition(entoutDefn);
defn->addItemDefinition(entremDefn);
defn->addItemDefinition(logDefn);
resultdefn->addItemDefinition(outcomeDefn);
resultdefn->addItemDefinition(entoutDefn);
resultdefn->addItemDefinition(entremDefn);
resultdefn->addItemDefinition(logDefn);
if (!opList && this->inheritsOperators())
{
......
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