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

Progress on "force create face".

Now loops and uses should be set up properly.
Also, the model has references to any edges involved in the face
removed (as free cells) and the face added (as a free cell) so that
the subphrase generator displays the model hierarchy correctly.
parent d2fa9547
......@@ -158,25 +158,43 @@ smtk::model::OperatorResult ForceCreateFace::operateInternal()
smtkErrorMacro(this->log(), "Could not create model edge(s) of face.");
return this->createResult(smtk::model::OPERATION_FAILED);
}
// TODO
smtk::attribute::ModelEntityItem::Ptr created = edgeResult->findModelEntity("created");
// IV. Transcribe face (uses, loops, face) to smtk
//
// Make up some UUIDs for the new entities.
std::vector<std::pair<smtk::model::Edge, bool> > orientedLoopEdges;
orientedLoopEdges.push_back(
std::make_pair(edgeResult->findModelEntity("created")->value(0).as<smtk::model::Edge>(), true));
smtk::model::Edge outerEdge = created->value(0).as<smtk::model::Edge>();
orientedLoopEdges.push_back(std::make_pair(outerEdge, true));
smtk::common::UUID modelFaceId = mgr->unusedUUID();
smtk::common::UUID modelFaceUseId = mgr->unusedUUID();
smtk::common::UUID modelLoopId = mgr->unusedUUID();
if (!mgr->insertModelFaceWithOrientedOuterLoop(modelFaceId, modelFaceUseId, modelLoopId, orientedLoopEdges))
smtk::common::UUID outerLoopId = mgr->unusedUUID();
if (!mgr->insertModelFaceWithOrientedOuterLoop(modelFaceId, modelFaceUseId, outerLoopId, orientedLoopEdges))
{
smtkErrorMacro(this->log(), "Could not create SMTK outer loop of face.");
return this->createResult(smtk::model::OPERATION_FAILED);
}
smtk::model::Face modelFace(mgr, modelFaceId);
model.removeCell(outerEdge);
model.addCell(modelFace);
modelFace.assignDefaultName();
// Now transcribe inner-loop edges:
int numInner = static_cast<int>(created->numberOfValues());
for (int inner = 1; inner < numInner; ++inner)
{
orientedLoopEdges.clear();
smtk::model::Edge innerEdge = created->value(inner).as<smtk::model::Edge>();
orientedLoopEdges.push_back(std::make_pair(innerEdge, true));
smtk::common::UUID innerLoopId = mgr->unusedUUID();
if (!mgr->insertModelFaceOrientedInnerLoop(innerLoopId, outerLoopId, orientedLoopEdges))
{
smtkErrorMacro(this->log(), "Could not create SMTK inner loop of face.");
return this->createResult(smtk::model::OPERATION_FAILED);
}
model.removeCell(innerEdge);
}
// V. Add tessellation
poly::polygon_set_data<internal::Coord> polys;
std::vector<poly::polygon_data<internal::Coord> > tess;
......
......@@ -79,6 +79,7 @@ class TestPolygonCreation(smtk.testing.TestCase):
res = fop.operate()
PrintResultLog(res)
self.mgr.assignDefaultNames()
smtk.io.ExportJSON.fromModelManagerToFile(self.mgr, '/tmp/forcepoly.json')
def testCreation(self):
......
......@@ -70,5 +70,17 @@ FaceUse Face::positiveUse() const
relationFromArrangement(HAS_USE, *arr.begin(), 0).as<FaceUse>();
}
/**\brief Add or replace any existing face use with the given use-record \a u.
*
*/
void Face::setFaceUse(Orientation orientation, const FaceUse& u)
{
smtk::model::Manager::Ptr mgr = this->manager();
if (this->isValid())
{
mgr->findCreateOrReplaceCellUseOfSenseAndOrientation(this->m_entity, 0, orientation, u.entity());
}
}
} // namespace model
} // namespace smtk
......@@ -38,6 +38,8 @@ public:
Volumes volumes() const;
FaceUse negativeUse() const;
FaceUse positiveUse() const;
void setFaceUse(Orientation o, const FaceUse& u);
};
} // namespace model
......
......@@ -845,6 +845,20 @@ void Manager::insertEntityReferences(const UUIDWithEntity& c)
}
}
/**\brief Given an entity \a c and the ID of one of its related entities \a r,
* overwrite the occurrence of \a r in \a c's array of relations with an
* invalid UUID.
*
* Use this method to avoid the need to rewrite indices into \a c's
* array of relations held by \a c and potentially other entities related
* to \a c.
*/
bool Manager::elideOneEntityReference(const UUIDWithEntity& c, const UUID& r)
{
UUIDArray::const_iterator bit;
return c->second.invalidateRelation(r) < 0 ? false : true;
}
/**\brief Given an entity \a c, ensure that all of its references
* contain <b>no</b> reference to it.
*
......
......@@ -165,6 +165,7 @@ public:
smtk::common::UUID addCellOfDimensionWithUUID(const smtk::common::UUID& uid, int dim);
void insertEntityReferences(const UUIDWithEntity& c);
bool elideOneEntityReference(const UUIDWithEntity& c, const smtk::common::UUID& r);
void elideEntityReferences(const UUIDWithEntity& c);
void removeEntityReferences(const UUIDWithEntity& c);
......
......@@ -40,9 +40,10 @@ bool Manager::insertModelFaceWithOrientedOuterLoop(
for (typename T::const_iterator oeit = orderedEdgesWithOrientation.begin(); oeit != orderedEdgesWithOrientation.end(); ++oeit)
{
smtk::model::Edge mutableEdge(oeit->first);
EdgeUse eu = mutableEdge.findOrAddEdgeUse(oeit->second ? smtk::model::POSITIVE : smtk::model::NEGATIVE, 0);
EdgeUse eu = mutableEdge.findOrAddEdgeUse(oeit->second ? POSITIVE : NEGATIVE, 0);
l.addUse(eu);
}
f.setFaceUse(POSITIVE, fu);
return true;
}
......@@ -74,7 +75,8 @@ bool Manager::insertModelFaceOrientedInnerLoop(
// adding edge uses for each edge to the loop.
for (typename T::const_iterator oeit = orderedEdgesWithOrientation.begin(); oeit != orderedEdgesWithOrientation.end(); ++oeit)
{
EdgeUse eu = oeit->first.findOrAddEdgeUse(oeit->second, 0);
smtk::model::Edge mutableEdge(oeit->first);
EdgeUse eu = mutableEdge.findOrAddEdgeUse(oeit->second ? POSITIVE : NEGATIVE, 0);
inner.addUse(eu);
}
return true;
......
......@@ -139,7 +139,19 @@ Model& Model::addCell(const CellEntity& c)
Model& Model::removeCell(const CellEntity& c)
{
ManagerPtr mgr = this->manager();
this->unembedEntity(c);
UUIDWithEntity ent;
ent = mgr->topology().find(this->m_entity);
if (ent != mgr->topology().end())
{
mgr->elideOneEntityReference(ent, c.entity());
}
ent = mgr->topology().find(c.entity());
if (ent != mgr->topology().end())
{
mgr->elideOneEntityReference(ent, this->m_entity);
}
return *this;
}
......
......@@ -158,6 +158,7 @@
<suppress-warning text="skipping function 'smtk::model::Manager::insertEntityReferences', unmatched parameter type 'smtk::model::UUIDWithEntity const&amp;'"/>
<suppress-warning text="skipping function 'smtk::model::Manager::removeEntityReferences', unmatched parameter type 'smtk::model::UUIDWithEntity const&amp;'"/>
<suppress-warning text="skipping function 'smtk::model::Manager::elideEntityReferences', unmatched parameter type 'smtk::model::UUIDWithEntity const&amp;'"/>
<suppress-warning text="skipping function 'smtk::model::Manager::elideOneEntityReference', unmatched parameter type 'smtk::model::UUIDWithEntity const&amp;'"/>
<suppress-warning text="skipping field 'Manager::m_topology' with unmatched type 'smtk::shared_ptr&lt;UUIDsToEntities&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::Manager::Manager', unmatched parameter type 'shared_ptr&lt;UUIDsToEntities&gt;'"/>
<suppress-warning text="skipping field 'Manager::m_tessellations' with unmatched type 'smtk::shared_ptr&lt;UUIDsToTessellations&gt;'"/>
......
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