Commit 1415340a authored by David Thompson's avatar David Thompson
Browse files

Fix methods on Model to omit invalid entries.

Methods like `smtk::model::Model::cellsAs<T>()` and
`smtk::model::Model::groupsAs<T>()` would append cursors
that were invalid rather than omitting values not matching
the container type. For example, calling `model->cellsAs<Edges>()`
should only return cells owned by the model that are edges
(as opposed to vertices, faces, or volumes).
Without this patch, invalid `Edge` cursors were being inserted
for each vertex, face, or volume in the model's set of cells.
parent 09b1c15a
......@@ -93,6 +93,10 @@ CellEntities Model::cells() const
{
CellEntities result;
ManagerPtr mgr = this->manager();
if (!mgr)
{
return result;
}
EntityRefArrangementOps::appendAllRelations(*this, INCLUDES, result);
if (result.empty())
{ // We may have a "simple" model that has no arrangements but does have relations.
......
......@@ -72,7 +72,14 @@ template<typename T> T Model::cellsAs() const
{
// TODO: This could be done more efficiently without a copy.
CellEntities tmp = this->cells();
return T(tmp.begin(), tmp.end());
T result;
for (CellEntities::iterator it = tmp.begin(); it != tmp.end(); ++it)
{
typename T::value_type entry(*it);
if (entry.isValid())
result.insert(result.end(), *it);
}
return result;
}
/// Return the top-level (free) groups of this model in a container of the template type.
......@@ -80,7 +87,14 @@ template<typename T> T Model::groupsAs() const
{
// TODO: This could be done more efficiently without a copy.
Groups tmp = this->groups();
return T(tmp.begin(), tmp.end());
T result;
for (Groups::iterator it = tmp.begin(); it != tmp.end(); ++it)
{
typename T::value_type entry(*it);
if (entry.isValid())
result.insert(result.end(), *it);
}
return result;
}
/// Return the child models of this model in a container of the template type.
......@@ -88,7 +102,14 @@ template<typename T> T Model::submodelsAs() const
{
// TODO: This could be done more efficiently without a copy.
Models tmp = this->submodels();
return T(tmp.begin(), tmp.end());
T result;
for (Models::iterator it = tmp.begin(); it != tmp.end(); ++it)
{
typename T::value_type entry(*it);
if (entry.isValid())
result.insert(result.end(), *it);
}
return result;
}
/// Append free cells of this model to the given \a container. Only valid cells are inserted.
......@@ -96,7 +117,12 @@ template<typename T> void Model::appendCells(T& container) const
{
// TODO: This could be done more efficiently without a copy.
CellEntities tmp = this->cells();
container.insert(container.end(), tmp.begin(), tmp.end());
for (CellEntities::iterator it = tmp.begin(); it != tmp.end(); ++it)
{
typename T::value_type entry(*it);
if (entry.isValid())
container.insert(container.end(), *it);
}
}
/// Add all the free cells in \a container to this model.
......
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