Commit a484c359 authored by T.J. Corona's avatar T.J. Corona

Mesh session: fix Read op to enable persistent model properties

parent 12158169
......@@ -19,10 +19,10 @@ namespace resource
{
void to_json(json& j, const Surrogate& surrogate)
{
// j["index"] = surrogate.index();
j["index"] = surrogate.index();
j["type"] = surrogate.typeName();
// j["id"] = surrogate.id();
// j["location"] = surrogate.location();
j["id"] = surrogate.id();
j["location"] = surrogate.location();
}
Surrogate from_json(const json& j)
......
......@@ -149,27 +149,48 @@ Import::Result Import::operateInternal()
session->facade()["neumann"] = "Side Set";
}
// Assign its model resource to the one associated with this session
// Assign the collection's model resource to the one associated with this
// session
collection->setModelResource(resource);
// Also assign the collection to be the model's tessellation
resource->setMeshTessellations(collection);
// Determine the model's dimension
int dimension = int(smtk::mesh::utility::highestDimension(collection->meshes()));
// If we are reading a mesh session resource (as opposed to a new import), we
// should access the existing model instead of creating a new one here. If
// this is the case, then the collection's associated model id will be related
// to a model entity that is already in the resource (as it was put there by
// the Read operation calling this one).
smtk::common::UUID associatedModelId = collection->associatedModel().toString();
// Create a model with the appropriate dimension
smtk::model::Model model = resource->addModel(dimension, dimension);
// Construct the topology
session->addTopology(Topology(model.entity(), newMeshes, constructHierarchy));
// By default, a model is invalid
smtk::model::Model model;
if (associatedModelId != smtk::common::UUID::null())
{
// Assign the model to one described already in the resource with the id of
// collection's associated model. If there is no such model, then this
// instance will also be invalid.
model = smtk::model::Model(resource, associatedModelId);
}
// Name the model according to the stem of the file
if (!name.empty())
if (model.isValid() == false)
{
model.setName(name);
// Determine the model's dimension
int dimension = int(smtk::mesh::utility::highestDimension(collection->meshes()));
// Create a model with the appropriate dimension
model = resource->addModel(dimension, dimension);
// Name the model according to the stem of the file
if (!name.empty())
{
model.setName(name);
}
}
// Construct the topology
session->addTopology(Topology(model.entity(), newMeshes, constructHierarchy));
// Set the url and type of the model
model.setStringProperty("url", filePath);
model.setStringProperty("type", format.Name);
......
......@@ -15,6 +15,9 @@
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/ResourceItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/attribute/VoidItem.h"
#include "smtk/model/json/jsonResource.h"
#include "smtk/session/mesh/Resource.h"
......@@ -69,6 +72,10 @@ Read::Result Read::operateInternal()
resource->setLocation(filename);
resource->setSession(session);
// Transcribe model data onto the resource
auto modelResource = std::static_pointer_cast<smtk::model::Resource>(resource);
smtk::model::from_json(j, modelResource);
std::string meshFilename = j.at("Mesh URL");
// Create an import operator
......@@ -77,6 +84,7 @@ Read::Result Read::operateInternal()
importOp->parameters()->findResource("resource")->setValue(resource);
importOp->parameters()->findString("session only")->setDiscreteIndex(0);
importOp->parameters()->findFile("filename")->setValue(meshFilename);
importOp->parameters()->findVoid("construct hierarchy")->setIsEnabled(false);
// Execute the operation
smtk::operation::Operation::Result importOpResult = importOp->operate();
......
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