Commit 90577892 authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'mesh-session-import-fixes' into release

58502f84 Fix mesh session import into exiting resource
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: David Thompson's avatarDavid Thompson <david.thompson@kitware.com>
Merge-request: !1559
parents 2ea4b3fc 58502f84
Pipeline #137467 running with stage
...@@ -75,6 +75,7 @@ Import::Result Import::operateInternal() ...@@ -75,6 +75,7 @@ Import::Result Import::operateInternal()
// Modes 2 and 3 requre an existing resource for input // Modes 2 and 3 requre an existing resource for input
smtk::attribute::ReferenceItem::Ptr existingResourceItem = this->parameters()->associations(); smtk::attribute::ReferenceItem::Ptr existingResourceItem = this->parameters()->associations();
bool newResource = true;
if (existingResourceItem->numberOfValues() > 0) if (existingResourceItem->numberOfValues() > 0)
{ {
smtk::session::mesh::Resource::Ptr existingResource = smtk::session::mesh::Resource::Ptr existingResource =
...@@ -88,6 +89,7 @@ Import::Result Import::operateInternal() ...@@ -88,6 +89,7 @@ Import::Result Import::operateInternal()
{ {
// If the "session only" value is set to "this file", then we use the // If the "session only" value is set to "this file", then we use the
// existing resource // existing resource
newResource = false;
resource = existingResource; resource = existingResource;
meshResource = existingResource->resource(); meshResource = existingResource->resource();
...@@ -134,7 +136,7 @@ Import::Result Import::operateInternal() ...@@ -134,7 +136,7 @@ Import::Result Import::operateInternal()
// Name the mesh according to the stem of the file // Name the mesh according to the stem of the file
std::string name = smtk::common::Paths::stem(filePath); std::string name = smtk::common::Paths::stem(filePath);
if (!name.empty()) if (!name.empty() && newResource == true)
{ {
meshResource->setName(name); meshResource->setName(name);
resource->setName(name); resource->setName(name);
...@@ -164,7 +166,7 @@ Import::Result Import::operateInternal() ...@@ -164,7 +166,7 @@ Import::Result Import::operateInternal()
// By default, a model is invalid // By default, a model is invalid
smtk::model::Model model; 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 // 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 // mesh resource's associated model. If there is no such model, then this
......
...@@ -155,6 +155,8 @@ int UnitTestImportIntoResource(int argc, char* argv[]) ...@@ -155,6 +155,8 @@ int UnitTestImportIntoResource(int argc, char* argv[])
test(count[0] == 0, "There should be no vertex groups"); test(count[0] == 0, "There should be no vertex groups");
} }
smtk::model::Entity::Ptr secondModel;
{ {
smtk::session::mesh::Import::Ptr importOp = smtk::session::mesh::Import::Ptr importOp =
operationManager->create<smtk::session::mesh::Import>(); operationManager->create<smtk::session::mesh::Import>();
...@@ -172,11 +174,20 @@ int UnitTestImportIntoResource(int argc, char* argv[]) ...@@ -172,11 +174,20 @@ int UnitTestImportIntoResource(int argc, char* argv[])
std::cerr << "Import operator failed\n"; std::cerr << "Import operator failed\n";
return 1; 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 }; std::size_t count[4] = { 0, 0, 0, 0 };
ParseModelTopology(model->referenceAs<smtk::model::Model>(), count); ParseModelTopology(model->referenceAs<smtk::model::Model>(), count);
ParseModelTopology(secondModel->referenceAs<smtk::model::Model>(), count);
std::cout << count[3] << " volumes" << std::endl; std::cout << count[3] << " volumes" << std::endl;
test(count[3] == 2, "There should be two volumes"); 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