Commit 58502f84 authored by T.J. Corona's avatar T.J. Corona

Fix mesh session import into exiting resource

Originally, importing into an existing mesh session resource would
change the name of the resource and assign the first model's UUIDs to
the second resource. This MR follows the use-case for importing into
an existing resource to prevent these issues.
parent 2ea4b3fc
......@@ -75,6 +75,7 @@ Import::Result Import::operateInternal()
// Modes 2 and 3 requre an existing resource for input
smtk::attribute::ReferenceItem::Ptr existingResourceItem = this->parameters()->associations();
bool newResource = true;
if (existingResourceItem->numberOfValues() > 0)
{
smtk::session::mesh::Resource::Ptr existingResource =
......@@ -88,6 +89,7 @@ Import::Result Import::operateInternal()
{
// If the "session only" value is set to "this file", then we use the
// existing resource
newResource = false;
resource = existingResource;
meshResource = existingResource->resource();
......@@ -134,7 +136,7 @@ Import::Result Import::operateInternal()
// Name the mesh according to the stem of the file
std::string name = smtk::common::Paths::stem(filePath);
if (!name.empty())
if (!name.empty() && newResource == true)
{
meshResource->setName(name);
resource->setName(name);
......@@ -164,7 +166,7 @@ Import::Result Import::operateInternal()
// By default, a model is invalid
smtk::model::Model model;
if (associatedModelId != smtk::common::UUID::null())
if (associatedModelId != smtk::common::UUID::null() && newResource == true)
{
// Assign the model to one described already in the resource with the id of
// mesh resource's associated model. If there is no such model, then this
......
......@@ -155,6 +155,8 @@ int UnitTestImportIntoResource(int argc, char* argv[])
test(count[0] == 0, "There should be no vertex groups");
}
smtk::model::Entity::Ptr secondModel;
{
smtk::session::mesh::Import::Ptr importOp =
operationManager->create<smtk::session::mesh::Import>();
......@@ -172,11 +174,20 @@ int UnitTestImportIntoResource(int argc, char* argv[])
std::cerr << "Import operator failed\n";
return 1;
}
// Retrieve the resulting model
smtk::attribute::ComponentItemPtr componentItem =
std::dynamic_pointer_cast<smtk::attribute::ComponentItem>(
importOpResult->findComponent("model"));
// Access the generated model
secondModel = std::dynamic_pointer_cast<smtk::model::Entity>(componentItem->value());
}
{
std::size_t count[4] = { 0, 0, 0, 0 };
ParseModelTopology(model->referenceAs<smtk::model::Model>(), count);
ParseModelTopology(secondModel->referenceAs<smtk::model::Model>(), count);
std::cout << count[3] << " volumes" << std::endl;
test(count[3] == 2, "There should be two volumes");
......
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