Commit 8e5a6d96 authored by John Tourtellott's avatar John Tourtellott

Implement option to use vtk session to import models as the default

This is a temporary workaround, because the current mesh session code
does not import names assigned to side sets and element blocks
in exodus files. Also changed option to copy model file from advanced to
parent 2bb1b65b
......@@ -18,7 +18,7 @@
<Directory Name="workspace-path" Label="Workspace Directory" NumberOfRequiredValues="1" ShouldExist="true">
<BriefDescription>Root directory for projects.</BriefDescription>
<String Name="project-folder" Label="Name" NumberOfRequiredValues="1">
<String Name="project-folder" Label="Name (Subdirectory)" NumberOfRequiredValues="1">
<BriefDescription>Project files will be stored in a workspace folder with this name.</BriefDescription>
......@@ -27,26 +27,36 @@
FileFilters="CMB Template Files (*.sbt);;All Files (*)">
<BriefDescription>The CMB template file (*.sbt) specifying the simulation</BriefDescription>
<File Name="model-file" Label="Model File" NumberOfRequiredValues="1" ShouldExist="true"
<File Name="model-file" Label="Input Geometry" NumberOfRequiredValues="1" ShouldExist="true"
Optional="true" IsEnabledByDefault="true"
FileFilters="Exodus Files (*.ex? *.gen);;All Files (*)">
<BriefDescription>The model file to import into the project.</BriefDescription>
<BriefDescription>The model or mesh file to import into the project.</BriefDescription>
<DetailedDescription>The current implementation only supports Exodus file.</DetailedDescription>
<Void Name="copy-model-file" Label="Copy Input Geometry"
Optional="true" IsEnabledByDefault="true">
<BriefDescription>If enabled, store a copy of the input geometry file in the project directory.</BriefDescription>
<String Name="model-file-identifier" Label="Model File Label" NumberOfRequiredValues="1" AdvanceLevel="1">
<BriefDescription>A text label that can be used to identify this model</BriefDescription>
<Void Name="copy-model-file" Label="Copy Model File Into Project" AdvanceLevel="1"
The "use-vtk-session" option is set TRUE by default, as a temporary workaround for
loading exodus files, which otherwise would use the mesh session. The vtk session is
used because it copies the side set and element block names to the smtk model.
Once the mesh session code is updated to do the same thing, recommend that the
default for this item be changed to FALSE.
<Void Name="use-vtk-session" Label="Use VTK Session" AdvanceLevel="1"
Optional="true" IsEnabledByDefault="true">
<BriefDescription>Use VTK session for importing model files</BriefDescription>
Use this option to load models with smtk::session::vtk in place of the default
smtk logic.
<String Name="session-type" Label="Modeling Session" AdvanceLevel="1">
<DiscreteInfo DefaultIndex="0">
<Value Enum="Mesh">mesh</Value>
......@@ -69,7 +69,7 @@ std::vector<smtk::resource::ResourcePtr> Project::resources() const
return resourceList;
for (auto& rd : m_resourceDescriptors)
for (const auto& rd : m_resourceDescriptors)
if (rd.m_uuid.isNull())
......@@ -90,7 +90,7 @@ std::vector<smtk::resource::ResourcePtr> Project::resources() const
std::string Project::importLocation(smtk::resource::ResourcePtr res) const
auto resId = res->id();
for (auto& descriptor : m_resourceDescriptors)
for (const auto& descriptor : m_resourceDescriptors)
if (descriptor.m_uuid == resId)
......@@ -184,9 +184,11 @@ bool Project::build(smtk::attribute::AttributePtr specification, smtk::io::Logge
auto modelFileItem = specification->findFile("model-file");
if (modelFileItem->isEnabled())
// Check use-vtk-session option
std::string modelPath = modelFileItem->value(0);
bool copyNativeModel = specification->findVoid("copy-model-file")->isEnabled();
if (!this->importModel(modelPath, copyNativeModel, modelDescriptor, logger))
bool useVTKSession = specification->findVoid("use-vtk-session")->isEnabled();
if (!this->importModel(modelPath, copyNativeModel, modelDescriptor, useVTKSession, logger))
return false;
......@@ -246,7 +248,7 @@ bool Project::save(smtk::io::Logger& logger) const
boost::filesystem::path boostDirectory(m_directory);
// Save project resources
for (auto& rd : m_resourceDescriptors)
for (const auto& rd : m_resourceDescriptors)
auto resource = resManager->get(rd.m_uuid);
auto writer = opManager->create<smtk::operation::WriteResource>();
......@@ -275,7 +277,7 @@ bool Project::close()
// Release resources
for (auto& rd : m_resourceDescriptors)
for (const auto& rd : m_resourceDescriptors)
auto resourcePtr = resManager->get(rd.m_uuid);
if (resourcePtr)
......@@ -361,7 +363,7 @@ bool Project::open(const std::string& location, smtk::io::Logger& logger)
} // open()
bool Project::importModel(const std::string& importPath, bool copyNativeModel,
ResourceDescriptor& descriptor, smtk::io::Logger& logger)
ResourceDescriptor& descriptor, bool useVTKSession, smtk::io::Logger& logger)
auto opManager = m_operationManager.lock();
if (!opManager)
......@@ -386,7 +388,16 @@ bool Project::importModel(const std::string& importPath, bool copyNativeModel,
// Create the import operator
auto importOp = opManager->create<smtk::operation::ImportResource>();
smtk::operation::OperationPtr importOp;
if (useVTKSession)
importOp = opManager->create("smtk::session::vtk::Import");
importOp = opManager->create<smtk::operation::ImportResource>();
if (!importOp)
smtkErrorMacro(logger, "Import operator not found");
......@@ -500,7 +511,7 @@ bool Project::loadResources(const std::string& path, smtk::io::Logger& logger)
// Part of opening project from disk
boost::filesystem::path directoryPath(path);
for (auto& descriptor : m_resourceDescriptors)
for (const auto& descriptor : m_resourceDescriptors)
// Create a read operator
auto readOp = opManager->create<smtk::operation::ReadResource>();
......@@ -559,7 +570,7 @@ smtk::operation::OperationPtr Project::getExportOperator(smtk::io::Logger& logge
// Find the simulation attribute resource.
ResourceDescriptor simAttDescriptor;
for (auto& descriptor : m_resourceDescriptors)
for (const auto& descriptor : m_resourceDescriptors)
if (descriptor.m_typeName == smtk::common::typeName<smtk::attribute::Resource>())
......@@ -651,7 +662,7 @@ bool Project::populateExportOperator(
std::vector<smtk::resource::ResourcePtr> attResourceList;
std::vector<smtk::resource::ComponentPtr> modelList;
auto resourceList = this->resources();
for (auto resource : resourceList)
for (const auto resource : resourceList)
if (resource->isOfType(smtk::common::typeName<smtk::attribute::Resource>()))
......@@ -661,7 +672,7 @@ bool Project::populateExportOperator(
auto modelResource = smtk::dynamic_pointer_cast<smtk::model::Resource>(resource);
auto uuids = modelResource->entitiesMatchingFlags(smtk::model::MODEL_ENTITY, true);
for (auto uuid : uuids)
for (const auto& uuid : uuids)
auto model = modelResource->find(uuid);
if (model)
......@@ -81,7 +81,7 @@ protected:
// Remaining calls are for internal use
bool importModel(const std::string& location, bool copyNativeFile, ResourceDescriptor& descriptor,
smtk::io::Logger& logger = smtk::io::Logger::instance());
bool useVtkSession, smtk::io::Logger& logger = smtk::io::Logger::instance());
bool importAttributeTemplate(const std::string& location, ResourceDescriptor& descriptor,
smtk::io::Logger& logger = smtk::io::Logger::instance());
......@@ -88,6 +88,9 @@ class TestProjectManager(unittest.TestCase):
smtk.testing.DATA_DIR, 'model', '3d', 'genesis', 'gun-1fourth.gen')
spec.findFile('model-file').setValue(0, model_file)
# Make sure vtk-session option is off
self.assertTrue(spec.isValid(), msg="project spec not valid")
# Create project
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