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

Implement+test model-bridge-operator associations.

parent d4fd5579
......@@ -180,6 +180,7 @@ namespace smtk
typedef smtk::weak_ptr< smtk::model::Model > WeakModelPtr;
typedef smtk::shared_ptr< smtk::model::Operator > OperatorPtr;
typedef smtk::weak_ptr< smtk::model::Operator > WeakOperatorPtr;
typedef std::set< smtk::model::OperatorPtr > Operators;
typedef smtk::shared_ptr< smtk::model::Storage > StoragePtr;
typedef smtk::weak_ptr< smtk::model::Storage > WeakStoragePtr;
typedef smtk::shared_ptr< smtk::model::Item > ItemPtr;
......
......@@ -252,10 +252,10 @@ std::string BRepModel::name(const UUID& ofEntity) const
*
* \sa HigherDimensionalBoundaries
*/
UUIDs BRepModel::bordantEntities(const smtk::util::UUID& ofEntity, int ofDimension)
UUIDs BRepModel::bordantEntities(const smtk::util::UUID& ofEntity, int ofDimension) const
{
UUIDs result;
UUIDsToEntities::iterator it = this->m_topology->find(ofEntity);
UUIDsToEntities::const_iterator it = this->m_topology->find(ofEntity);
if (it == this->m_topology->end())
{
return result;
......@@ -265,8 +265,8 @@ UUIDs BRepModel::bordantEntities(const smtk::util::UUID& ofEntity, int ofDimensi
// can't ask for "higher" dimensional boundaries that are lower than the dimension of this cell.
return result;
}
UUIDsToEntities::iterator other;
for (UUIDArray::iterator ai = it->second.relations().begin(); ai != it->second.relations().end(); ++ai)
UUIDsToEntities::const_iterator other;
for (UUIDArray::const_iterator ai = it->second.relations().begin(); ai != it->second.relations().end(); ++ai)
{
other = this->m_topology->find(*ai);
if (other == this->m_topology->end())
......@@ -287,7 +287,7 @@ UUIDs BRepModel::bordantEntities(const smtk::util::UUID& ofEntity, int ofDimensi
*
* \sa HigherDimensionalBoundaries
*/
UUIDs BRepModel::bordantEntities(const smtk::util::UUIDs& ofEntities, int ofDimension)
UUIDs BRepModel::bordantEntities(const smtk::util::UUIDs& ofEntities, int ofDimension) const
{
UUIDs result;
std::insert_iterator<UUIDs> inserter(result, result.begin());
......@@ -303,10 +303,10 @@ UUIDs BRepModel::bordantEntities(const smtk::util::UUIDs& ofEntities, int ofDime
*
* \sa LowerDimensionalBoundaries
*/
UUIDs BRepModel::boundaryEntities(const smtk::util::UUID& ofEntity, int ofDimension)
UUIDs BRepModel::boundaryEntities(const smtk::util::UUID& ofEntity, int ofDimension) const
{
UUIDs result;
UUIDsToEntities::iterator it = this->m_topology->find(ofEntity);
UUIDsToEntities::const_iterator it = this->m_topology->find(ofEntity);
if (it == this->m_topology->end())
{
return result;
......@@ -317,7 +317,7 @@ UUIDs BRepModel::boundaryEntities(const smtk::util::UUID& ofEntity, int ofDimens
return result;
}
UUIDsToEntities::iterator other;
for (UUIDArray::iterator ai = it->second.relations().begin(); ai != it->second.relations().end(); ++ai)
for (UUIDArray::const_iterator ai = it->second.relations().begin(); ai != it->second.relations().end(); ++ai)
{
other = this->m_topology->find(*ai);
if (other == this->m_topology->end())
......@@ -338,7 +338,7 @@ UUIDs BRepModel::boundaryEntities(const smtk::util::UUID& ofEntity, int ofDimens
*
* \sa LowerDimensionalBoundaries
*/
UUIDs BRepModel::boundaryEntities(const smtk::util::UUIDs& ofEntities, int ofDimension)
UUIDs BRepModel::boundaryEntities(const smtk::util::UUIDs& ofEntities, int ofDimension) const
{
UUIDs result;
std::insert_iterator<UUIDs> inserter(result, result.begin());
......@@ -883,10 +883,10 @@ UUIDWithIntegerProperties BRepModel::integerPropertiesForEntity(const smtk::util
///@}
/// Attempt to find a model owning the given entity.
smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent)
smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent) const
{
smtk::util::UUID uid(ent);
UUIDWithEntity it = this->m_topology->find(uid);
UUIDsToEntities::const_iterator it = this->m_topology->find(uid);
if (it != this->m_topology->end())
{
// If we have a use or a shell, get the associated cell, if any
......@@ -897,11 +897,11 @@ smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent)
// Assume the first relationship that is a group or model is our owner.
// Keep going up parent groups until we hit the top.
for (
smtk::model::UUIDArray::iterator sit = it->second.relations().begin();
smtk::model::UUIDArray::const_iterator sit = it->second.relations().begin();
sit != it->second.relations().end();
++sit)
{
UUIDWithEntity subentity = this->topology().find(*sit);
UUIDsToEntities::const_iterator subentity = this->topology().find(*sit);
if (subentity != this->topology().end() && subentity->first != uid)
{
if (subentity->second.entityFlags() & MODEL_ENTITY)
......@@ -918,11 +918,11 @@ smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent)
case INSTANCE_ENTITY:
// Look for any relationship. We assume the first one is our prototype.
for (
smtk::model::UUIDArray::iterator sit = it->second.relations().begin();
smtk::model::UUIDArray::const_iterator sit = it->second.relations().begin();
sit != it->second.relations().end();
++sit)
{
UUIDWithEntity subentity = this->topology().find(*sit);
UUIDsToEntities::const_iterator subentity = this->topology().find(*sit);
if (subentity != this->topology().end() && subentity->first != uid)
{
if (subentity->second.entityFlags() & MODEL_ENTITY)
......@@ -935,11 +935,11 @@ smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent)
case SHELL_ENTITY:
// Loop for a relationship to a use.
for (
smtk::model::UUIDArray::iterator sit = it->second.relations().begin();
smtk::model::UUIDArray::const_iterator sit = it->second.relations().begin();
sit != it->second.relations().end();
++sit)
{
UUIDWithEntity subentity = this->topology().find(*sit);
UUIDsToEntities::const_iterator subentity = this->topology().find(*sit);
if (
subentity != this->topology().end() &&
smtk::model::isUseEntity(subentity->second.entityFlags()))
......@@ -952,11 +952,11 @@ smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent)
case USE_ENTITY:
// Look for a relationship to a cell
for (
smtk::model::UUIDArray::iterator sit = it->second.relations().begin();
smtk::model::UUIDArray::const_iterator sit = it->second.relations().begin();
sit != it->second.relations().end();
++sit)
{
UUIDWithEntity subentity = this->topology().find(*sit);
UUIDsToEntities::const_iterator subentity = this->topology().find(*sit);
if (
subentity != this->topology().end() &&
smtk::model::isCellEntity(subentity->second.entityFlags()))
......@@ -972,7 +972,12 @@ smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent)
// point to each other, which could throw us into an infinite loop. So,
// we attempt to cast ourselves to Storage and identify a parent model.
{
StoragePtr store = smtk::dynamic_pointer_cast<Storage>(shared_from_this());
// Although const_pointer_cast is evil, changing the cursor classes
// to accept any type of shared_ptr<X/X const>
StoragePtr store =
smtk::dynamic_pointer_cast<Storage>(
smtk::const_pointer_cast<BRepModel>(
shared_from_this()));
if (store)
{
ModelEntities parents;
......@@ -997,11 +1002,11 @@ smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent)
{
for (smtk::util::UUIDs::iterator uit = uids.begin(); uit != uids.end(); ++uit)
{
Entity* bordEnt = this->findEntity(*uit);
const Entity* bordEnt = this->findEntity(*uit);
if (!bordEnt) continue;
for (smtk::util::UUIDArray::iterator rit = bordEnt->relations().begin(); rit != bordEnt->relations().end(); ++rit)
for (smtk::util::UUIDArray::const_iterator rit = bordEnt->relations().begin(); rit != bordEnt->relations().end(); ++rit)
{
Entity* relEnt = this->findEntity(*rit);
const Entity* relEnt = this->findEntity(*rit);
if (relEnt && (relEnt->entityFlags() & MODEL_ENTITY))
{
return *rit;
......@@ -1023,10 +1028,10 @@ smtk::util::UUID BRepModel::modelOwningEntity(const smtk::util::UUID& ent)
*
* \sa BridgeBase
*/
BridgeBasePtr BRepModel::bridgeForModel(const smtk::util::UUID& uid)
BridgeBasePtr BRepModel::bridgeForModel(const smtk::util::UUID& uid) const
{
// See if the passed entity has a bridge.
UUIDsToBridges::iterator it = this->m_modelBridges.find(uid);
UUIDsToBridges::const_iterator it = this->m_modelBridges.find(uid);
if (it != this->m_modelBridges.end())
return it->second;
......
......@@ -67,10 +67,10 @@ public:
virtual bool erase(const smtk::util::UUID& uid);
smtk::util::UUIDs bordantEntities(const smtk::util::UUID& ofEntity, int ofDimension = -2);
smtk::util::UUIDs bordantEntities(const smtk::util::UUIDs& ofEntities, int ofDimension = -2);
smtk::util::UUIDs boundaryEntities(const smtk::util::UUID& ofEntity, int ofDimension = -2);
smtk::util::UUIDs boundaryEntities(const smtk::util::UUIDs& ofEntities, int ofDimension = -2);
smtk::util::UUIDs bordantEntities(const smtk::util::UUID& ofEntity, int ofDimension = -2) const;
smtk::util::UUIDs bordantEntities(const smtk::util::UUIDs& ofEntities, int ofDimension = -2) const;
smtk::util::UUIDs boundaryEntities(const smtk::util::UUID& ofEntity, int ofDimension = -2) const;
smtk::util::UUIDs boundaryEntities(const smtk::util::UUIDs& ofEntities, int ofDimension = -2) const;
smtk::util::UUIDs lowerDimensionalBoundaries(const smtk::util::UUID& ofEntity, int lowerDimension);
smtk::util::UUIDs higherDimensionalBordants(const smtk::util::UUID& ofEntity, int higherDimension);
......@@ -134,8 +134,8 @@ public:
UUIDsToIntegerData& integerProperties() { return *this->m_integerData; }
UUIDsToIntegerData const& integerProperties() const { return *this->m_integerData; }
smtk::util::UUID modelOwningEntity(const smtk::util::UUID& uid);
BridgeBasePtr bridgeForModel(const smtk::util::UUID& uid);
smtk::util::UUID modelOwningEntity(const smtk::util::UUID& uid) const;
BridgeBasePtr bridgeForModel(const smtk::util::UUID& uid) const;
void setBridgeForModel(BridgeBasePtr bridge, const smtk::util::UUID& uid);
void assignDefaultNames();
......
......@@ -70,6 +70,17 @@ Operators BridgeBase::operators()
return this->m_operators;
}
OperatorPtr BridgeBase::op(const std::string& opName) const
{
Operators::const_iterator it;
for (it = this->m_operators.begin(); it != this->m_operators.end(); ++it)
{
if ((*it)->name() == opName)
return *it;
}
return OperatorPtr();
}
/**\brief Add a solid-model operator to this bridge.
*
* Subclasses of BridgeBase should call this method in their
......
......@@ -92,6 +92,7 @@ public:
const Operators& operators() const;
Operators operators();
OperatorPtr op(const std::string& opName) const;
virtual void addOperator(OperatorPtr op);
protected:
......
#include "smtk/model/ModelEntity.h"
#include "smtk/model/BridgeBase.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/GroupEntity.h"
#include "smtk/model/Storage.h"
......@@ -97,5 +98,20 @@ ModelEntity& ModelEntity::removeSubmodel(const ModelEntity& m)
return *this;
}
OperatorPtr ModelEntity::op(const std::string& operatorName) const
{
return this->bridge()->op(operatorName);
}
Operators ModelEntity::operators() const
{
return this->bridge()->operators();
}
BridgeBasePtr ModelEntity::bridge() const
{
return this->m_storage->bridgeForModel(this->m_entity);
}
} // namespace model
} // namespace smtk
......@@ -41,6 +41,11 @@ public:
ModelEntity& removeSubmodel(const ModelEntity& m);
template<typename T> ModelEntity& addSubmodels(const T& container);
template<typename T> ModelEntity& removeSubmodels(const T& container);
OperatorPtr op(const std::string& operatorName) const;
Operators operators() const;
BridgeBasePtr bridge() const;
};
/// Add all the free cells in \a container to this model.
......
#include "smtk/model/BridgeBase.h"
#include "smtk/model/ModelEntity.h"
#include "smtk/model/Operator.h"
#include "smtk/model/OperatorResult.h"
#include "smtk/model/Parameter.h"
#include "smtk/model/Storage.h"
#include "smtk/util/Testing/helpers.h"
#include "smtk/model/testing/helpers.h"
......@@ -89,11 +92,14 @@ protected:
}
};
int testOperatorOutcomes()
int testOperatorOutcomes(Storage::Ptr storage)
{
int status = 0;
TestOutcomeOperator::Ptr op = TestOutcomeOperator::create();
// Add the operator to the default bridge of our storage.
storage->bridgeForModel(smtk::util::UUID::null())->addOperator(op);
int shouldCancel = 1;
int parameterWasModified = 0;
int numberOfFailedOperations = 0;
......@@ -171,11 +177,14 @@ protected:
}
};
int testParameterChecks()
int testParameterChecks(Storage::Ptr storage)
{
int status = 0;
TestParameterOperator::Ptr op = TestParameterOperator::create();
// Add the operator to the default bridge of our storage.
storage->bridgeForModel(smtk::util::UUID::null())->addOperator(op);
int parameterModifiedCount = 0;
op->observe(PARAMETER_CHANGE, ParameterWatcher, &parameterModifiedCount);
......@@ -205,11 +214,31 @@ int testParameterChecks()
return status;
}
int testBridgeAssociation(Storage::Ptr storage)
{
ModelEntity model = storage->addModel(3, 3, "Model Airplane");
test(model.operators().size() == 2, "Expected 2 operators defined for the test model.");
Operator::Ptr op = model.op("ParameterTest");
test(op, "ModelEntity::op(\"ParameterTest\") returned a \"null\" shared pointer.");
return 0;
}
int main()
{
int status = 0;
status |= testOperatorOutcomes();
status |= testParameterChecks();
Storage::Ptr storage = Storage::create();
try {
status |= testOperatorOutcomes(storage);
status |= testParameterChecks(storage);
status |= testBridgeAssociation(storage);
} catch (const std::string& msg) {
std::cerr << "Exiting...\n";
status = -1;
}
return status;
}
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