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

Clean up session relationships.

Make the documentation match reality as far as model ownership
goes (it did not show Model→Group relations and incorrectly had
submodels related by `INCLUDES/EMBEDDED_IN` instead of
`SUPERSET_OF/SUBSET_OF`).

Add methods to EntityRef for managing superset/subset arrangements
and use those (instead of raw relations) for parent-child of Model
and Session.

Rename ModelEntities and GroupEntities typedefs to Models and Groups.

Clean up Read operator in all bridges to use new session storage
style (where `Entity::relations()` holds session children) instead
of having Session instance track top-level models.

Get rid of `smtk::model::Manager::m_modelSessions`; this information
is now stored in the sessions's `Entity::relations()`.
parent 201f2938
......@@ -105,7 +105,7 @@ UUIDs and assigning it to the vtkInformation object on the dataset
or filter.
Although not required by this technique, you should be aware that you
may store information about a particular session session instance in
may store information about a particular session instance in
an SMTK JSON file by subclassing the :smtk:`SessionIOJSON` class.
.. _session-by-sequence:
......
......@@ -84,8 +84,7 @@ smtkImplementsModelOperator(
void testOperator(Model model)
{
// Get the default session for our model manager:
smtk::model::SessionPtr session =
model.manager()->sessionForModel(UUID::null());
smtk::model::SessionPtr session = model.session().session();
// Ask the session to create an operator:
ex::CounterOperator::Ptr op =
......@@ -113,10 +112,12 @@ int main()
int status = 0;
Manager::Ptr manager = Manager::create();
SessionRef session = manager->createSession("native");
UUIDArray uids = smtk::model::testing::createTet(manager);
Model model = manager->addModel(3, 3, "TestModel");
Volume tet = Volume(manager, uids[21]);
model.setSession(session);
model.addCell(tet);
try {
......
......@@ -17,7 +17,7 @@ also accessible in Python, whose instances perform the following functions:
You can think of the entities in a model Manager as being "backed" by
a solid modeling kernel; the session provides a way to synchronize
the representations in the Manager and the modeling kernel.
A manager may contain entity records from multiple Session sessions
A manager may contain entity records from multiple sessions
(e.g., a single Manager may contain some models back by an ACIS
modeling kernel session and some backed by an OpenCascade session).
......
......@@ -12,8 +12,9 @@
#include "smtk/bridge/cgm/TDUUID.h"
#include "smtk/model/EntityRef.h"
#include "smtk/model/Group.h"
#include "smtk/model/SessionRef.h"
#include "smtk/model/Model.h"
#include "smtk/model/Group.h"
#include "smtk/model/VolumeUse.h"
#include "smtk/model/FaceUse.h"
#include "smtk/model/EdgeUse.h"
......@@ -334,6 +335,9 @@ smtk::model::SessionInfoBits Session::addBodyToManager(
if (requestedInfo & (smtk::model::SESSION_ENTITY_RELATIONS | smtk::model::SESSION_ARRANGEMENTS))
{
// Tell the model its owning session is this instance:
mutableEntityRef.as<smtk::model::Model>().setSession(
smtk::model::SessionRef(this->manager(), this->sessionId()));
// Add free cells, submodels, and groups.
// Since CGM does not allow submodels, there's nothing to do for that.
// However, we can see what groups *contain* this body.
......
......@@ -54,7 +54,7 @@ bool BooleanIntersection::ableToOperate()
{
this->ensureSpecification();
bool result = true;
std::size_t numWorkpieces = this->associatedEntitiesAs<ModelEntities>().size();
std::size_t numWorkpieces = this->associatedEntitiesAs<Models>().size();
std::size_t numTools = this->findModelEntity("tool")->numberOfValues();
if (numWorkpieces + numTools < 2)
{
......@@ -71,11 +71,11 @@ bool BooleanIntersection::ableToOperate()
smtk::model::OperatorResult BooleanIntersection::operateInternal()
{
int keepInputs = this->findInt("keep inputs")->value();
ModelEntities bodiesIn = this->associatedEntitiesAs<ModelEntities>();
Models bodiesIn = this->associatedEntitiesAs<Models>();
ModelEntityItemPtr toolIn = this->findModelEntity("tool");
Body* cgmToolBody = NULL;
ModelEntities::iterator it;
Models::iterator it;
DLIList<Body*> cgmBodiesIn;
DLIList<Body*> cgmBodiesOut;
Body* cgmBody;
......
......@@ -54,9 +54,9 @@ smtk::model::OperatorResult BooleanSubtraction::operateInternal()
int keepInputs = this->findInt("keep inputs")->value();
int imprint = this->findInt("imprint workpieces")->value();
ModelEntityItemPtr toolsIn = this->findModelEntity("tools");
ModelEntities bodiesIn = this->associatedEntitiesAs<ModelEntities>();
Models bodiesIn = this->associatedEntitiesAs<Models>();
ModelEntities::iterator it;
Models::iterator it;
DLIList<Body*> cgmBodiesIn;
DLIList<Body*> cgmBodiesOut;
DLIList<Body*> cgmToolsIn;
......
......@@ -51,9 +51,9 @@ namespace smtk {
smtk::model::OperatorResult BooleanUnion::operateInternal()
{
int keepInputs = this->findInt("keep inputs")->value();
ModelEntities bodiesIn = this->associatedEntitiesAs<ModelEntities>();
Models bodiesIn = this->associatedEntitiesAs<Models>();
ModelEntities::iterator it;
Models::iterator it;
DLIList<Body*> cgmBodiesIn;
DLIList<Body*> cgmBodiesOut;
Body* cgmBody;
......
......@@ -127,10 +127,7 @@ smtk::model::OperatorResult Read::operateInternal()
smtk::common::UUID entId = refId->entityId();
smtk::model::EntityRef smtkEntry(this->manager(), entId);
if (session->transcribe(smtkEntry, smtk::model::SESSION_EVERYTHING, false))
{
resultModels->setValue(i, smtkEntry);
this->manager()->setSessionForModel(session->shared_from_this(), entId);
}
}
imported.reset();
......
......@@ -52,9 +52,9 @@ smtk::model::OperatorResult Reflect::operateInternal()
smtk::attribute::DoubleItemPtr basepointItem = this->findDouble("base point");
smtk::attribute::DoubleItemPtr directionItem = this->findDouble("direction");
ModelEntities bodiesIn = this->associatedEntitiesAs<ModelEntities>();
Models bodiesIn = this->associatedEntitiesAs<Models>();
ModelEntities::iterator it;
Models::iterator it;
DLIList<RefEntity*> cgmEntitiesIn;
DLIList<RefEntity*> cgmEntitiesOut;
RefEntity* refEntity;
......
......@@ -53,9 +53,9 @@ smtk::model::OperatorResult Rotate::operateInternal()
smtk::attribute::DoubleItemPtr axisItem = this->findDouble("axis");
smtk::attribute::DoubleItemPtr angleItem = this->findDouble("angle");
ModelEntities bodiesIn = this->associatedEntitiesAs<ModelEntities>();
Models bodiesIn = this->associatedEntitiesAs<Models>();
ModelEntities::iterator it;
Models::iterator it;
DLIList<RefEntity*> cgmEntitiesIn;
DLIList<RefEntity*> cgmEntitiesOut;
RefEntity* refEntity;
......
......@@ -54,9 +54,9 @@ smtk::model::OperatorResult Scale::operateInternal()
smtk::attribute::DoubleItemPtr factorItem = this->findDouble("scale factor");
smtk::attribute::DoubleItemPtr factorsItem = this->findDouble("scale factors");
ModelEntities bodiesIn = this->associatedEntitiesAs<ModelEntities>();
Models bodiesIn = this->associatedEntitiesAs<Models>();
ModelEntities::iterator it;
Models::iterator it;
DLIList<RefEntity*> cgmEntitiesIn;
DLIList<RefEntity*> cgmEntitiesOut;
RefEntity* refEntity;
......
......@@ -51,9 +51,9 @@ smtk::model::OperatorResult Translate::operateInternal()
{
smtk::attribute::DoubleItemPtr offset = this->findDouble("offset");
ModelEntities bodiesIn = this->associatedEntitiesAs<ModelEntities>();
Models bodiesIn = this->associatedEntitiesAs<Models>();
ModelEntities::iterator it;
Models::iterator it;
DLIList<RefEntity*> cgmEntitiesIn;
DLIList<RefEntity*> cgmEntitiesOut;
RefEntity* refEntity;
......
......@@ -181,7 +181,7 @@ int main (int argc, char* argv[])
}
Model prism = result->findModelEntity("entities")->value();
ModelEntities operands;
Models operands;
operands.push_back(sphere);
operands.push_back(prism);
SessionRef bs(mgr, brg->sessionId());
......
......@@ -17,9 +17,10 @@
#include "smtk/attribute/StringItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/model/Operator.h"
#include "smtk/model/Model.h"
#include "smtk/model/Manager.h"
#include "smtk/model/Model.h"
#include "smtk/model/Operator.h"
#include "smtk/model/SessionRef.h"
#include "vtkDiscreteModelWrapper.h"
#include "vtkModelItem.h"
......@@ -174,9 +175,10 @@ std::string json = smtk::io::ExportJSON::fromModelManager(this->manager());
file.close();
*/
this->manager()->setSessionForModel(
this->session()->shared_from_this(),
modelId);
modelEntity.as<smtk::model::Model>().setSession(
smtk::model::SessionRef(
modelEntity.manager(),
this->session()->sessionId()));
return result;
}
......
......@@ -91,14 +91,14 @@ OperatorResult ReadOperator::operateInternal()
#if defined(SMTK_DISCRETE_SESSION_DEBUG)
std::string json = smtk::io::ExportJSON::fromModelManager(this->manager());
std::ofstream file("/tmp/read_op_out.json");
file << json;
file.close();
std::ofstream file("/tmp/read_op_out.json");
file << json;
file.close();
#endif
this->manager()->setSessionForModel(
this->session()->shared_from_this(),
modelId);
modelEntity.as<smtk::model::Model>().setSession(
smtk::model::SessionRef(
this->manager(), this->session()->sessionId()));
return result;
}
......
......@@ -278,32 +278,6 @@ vtkUnsignedIntArray* Session::retrieveUUIDs(
return vuid;
}
smtk::common::UUID Session::ImportEntitiesFromFileNameIntoManager(
const std::string& filename,
const std::string& filetype,
smtk::model::ManagerPtr mgr)
{
// Make sure that the session has a list of operators it can provide.
// TODO: Register an attribute type for UUID on CMB's models?
if (filetype != "cmb")
{
std::cerr << "Unsupported file type \"" << filetype << "\" (not \"cmb\").\n";
return smtk::common::UUID::null();
}
vtkNew<vtkDiscreteModelWrapper> mod;
vtkNew<vtkCMBModelReadOperator> rdr;
rdr->SetFileName(filename.c_str());
rdr->Operate(mod.GetPointer());
if (!rdr->GetOperateSucceeded())
{
std::cerr << "Could not read file \"" << filename << "\".\n";
return smtk::common::UUID::null();
}
return this->trackModel(mod.GetPointer(), filename, mgr);
}
int Session::ExportEntitiesToFileOfNameAndType(
const std::vector<smtk::model::EntityRef>& entities,
const std::string& filename,
......@@ -381,7 +355,10 @@ smtk::common::UUID Session::trackModel(
Session::s_modelRefsToIds[mod] = mid;
this->m_itemsToRefs[mid] = dmod;
Session::s_modelsToSessions[dmod] = shared_from_this();
mgr->setSessionForModel(shared_from_this(), mid);
smtk::model::Model smtkModel(mgr, mid);
smtkModel.setSession(
smtk::model::SessionRef(
mgr, this->sessionId()));
// Now add the record to manager and assign the URL to
// the model as a string property.
......
......@@ -65,22 +65,22 @@ class vtkItemWatcherCommand;
/**\brief A class that handles translation between CMB and SMTK instances.
*
* How it works:
* (1) A session entity is created and ImportEntitiesFromFileNameIntoManager
* is called to load a CMB model. A CMBModelReadOperator is used to load
* (1) A Session entity and ReadOperator are created. The read operator is called
* to load a CMB model. Internally, a CMBModelReadOperator is used to load
* a vtkDiscreteModel (placed inside a vtkDiscreteModelWrapper by the
* CMB operator). The session instance is associated to the model wrapper
* CMB operator). The Session instance is associated to the model wrapper
* in the s_modelsToSessions variable.
* (2) ImportEntitiesFromFileNameIntoManager calls trackModel with the
* vtkDiscreteModelWrapper obtained using CMB's "read" model
* operator. Since vtkDiscreteModelWrapper is a subclass of vtkObject,
* (2) The ReadOperator calls trackModel with the vtkDiscreteModelWrapper
* obtained using CMB's (not SMTK's) "read" operator. Since
* vtkDiscreteModelWrapper is a subclass of vtkObject,
* we can keep it from being destroyed by holding a smart-pointer to
* it (in s_modelIdsToRefs and s_modelRefsToIds).
* (2) The model and, upon demand, entities contained in the model
* are assigned UUIDs if not present already. The UUIDs are kept
* in the vtkInformation object every vtkModelItem owns (Properties).
* (3) ExportSolid accepts a list of UUIDs for vtkModel instances.
* For each top-level vtkDiscreteModelWrapper in the list, it calls
* CMB's "write" operator on the model.
* (3) An SMTK WriteOperator will accept a list of UUIDs for vtkModel
* instances. For each top-level vtkDiscreteModelWrapper in the list,
* it calls CMB's "write" operator on the model.
*/
class SMTKDISCRETESESSION_EXPORT Session : public smtk::model::Session
{
......@@ -104,11 +104,6 @@ public:
static vtkUnsignedIntArray* retrieveUUIDs(
vtkDiscreteModel* model, const std::vector<vtkModelItem*>& ents);
smtk::common::UUID ImportEntitiesFromFileNameIntoManager(
const std::string& filename,
const std::string& filetype,
smtk::model::ManagerPtr storage);
int ExportEntitiesToFileOfNameAndType(
const std::vector<smtk::model::EntityRef>& entities,
const std::string& filename,
......
......@@ -135,7 +135,7 @@ int main(int argc, char* argv[])
smtk::model::OperatorPtr splitFace = model.op("split face");
splitFace->specification()->findModelEntity("face to split")->setValue(f);
splitFace->specification()->findModelEntity("model")->setValue(
*manager->entitiesMatchingFlagsAs<ModelEntities>(smtk::model::MODEL_ENTITY).begin());
*manager->entitiesMatchingFlagsAs<Models>(smtk::model::MODEL_ENTITY).begin());
splitFace->specification()->findDouble("feature angle")->setValue(15.0);
OperatorResult result = splitFace->operate();
std::cout << " Face is " << f.name() << " (" << f.entity() << ")\n";
......
......@@ -82,8 +82,8 @@ smtk::model::OperatorResult ReadOperator::operateInternal()
// The side and node sets now exist; go through
// and use the Exodus reader's private information
// to correct the property information.
GroupEntities groups = smtkModelOut.groups();
for (GroupEntities::iterator git = groups.begin(); git != groups.end(); ++git)
Groups groups = smtkModelOut.groups();
for (Groups::iterator git = groups.begin(); git != groups.end(); ++git)
{
int oid;
EntityHandle handle = this->exodusHandle(*git);
......
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