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