Commit c52e461a authored by John Tourtellott's avatar John Tourtellott Committed by Kitware Robot

Merge topic 'project-import-location'

8e5a6d96 Implement option to use vtk session to import models as the default
2bb1b65b Add method to get the import location for a project resource
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Haocheng LIU's avatarHaocheng LIU <haocheng.liu@kitware.com>
Merge-request: !1466
parents 1b88899b 8e5a6d96
Pipeline #129217 running with stage
......@@ -18,7 +18,7 @@
<Directory Name="workspace-path" Label="Workspace Directory" NumberOfRequiredValues="1" ShouldExist="true">
<BriefDescription>Root directory for projects.</BriefDescription>
</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>
<DefaultValue>NewProject</DefaultValue>
</String>
......@@ -27,26 +27,36 @@
FileFilters="CMB Template Files (*.sbt);;All Files (*)">
<BriefDescription>The CMB template file (*.sbt) specifying the simulation</BriefDescription>
</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"
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>
</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">
<BriefDescription>A text label that can be used to identify this model</BriefDescription>
<DefaultValue>default</DefaultValue>
</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">
<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>
<String Name="session-type" Label="Modeling Session" AdvanceLevel="1">
<BriefDescription></BriefDescription>
<DiscreteInfo DefaultIndex="0">
<Value Enum="Mesh">mesh</Value>
</DiscreteInfo>
</String>
</ItemDefinitions>
</AttDef>
</Definitions>
......
......@@ -59,7 +59,7 @@ Project::~Project()
this->close();
}
std::vector<smtk::resource::ResourcePtr> Project::getResources() const
std::vector<smtk::resource::ResourcePtr> Project::resources() const
{
std::vector<smtk::resource::ResourcePtr> resourceList; // return value
......@@ -69,7 +69,7 @@ std::vector<smtk::resource::ResourcePtr> Project::getResources() const
return resourceList;
}
for (auto& rd : m_resourceDescriptors)
for (const auto& rd : m_resourceDescriptors)
{
if (rd.m_uuid.isNull())
{
......@@ -87,6 +87,21 @@ std::vector<smtk::resource::ResourcePtr> Project::getResources() const
return resourceList;
}
std::string Project::importLocation(smtk::resource::ResourcePtr res) const
{
auto resId = res->id();
for (const auto& descriptor : m_resourceDescriptors)
{
if (descriptor.m_uuid == resId)
{
return descriptor.m_importLocation;
}
}
// (else)
return std::string();
}
void Project::setCoreManagers(
smtk::resource::ManagerPtr resManager, smtk::operation::ManagerPtr opManager)
{
......@@ -169,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;
}
......@@ -231,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>();
......@@ -260,7 +277,7 @@ bool Project::close()
this->releaseExportOperator();
// Release resources
for (auto& rd : m_resourceDescriptors)
for (const auto& rd : m_resourceDescriptors)
{
auto resourcePtr = resManager->get(rd.m_uuid);
if (resourcePtr)
......@@ -346,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)
......@@ -371,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");
}
else
{
importOp = opManager->create<smtk::operation::ImportResource>();
}
if (!importOp)
{
smtkErrorMacro(logger, "Import operator not found");
......@@ -485,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>();
......@@ -544,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>())
{
......@@ -635,8 +661,8 @@ bool Project::populateExportOperator(
// Locate project attribute and model resources
std::vector<smtk::resource::ResourcePtr> attResourceList;
std::vector<smtk::resource::ComponentPtr> modelList;
auto resourceList = this->getResources();
for (auto resource : resourceList)
auto resourceList = this->resources();
for (const auto resource : resourceList)
{
if (resource->isOfType(smtk::common::typeName<smtk::attribute::Resource>()))
{
......@@ -646,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)
......
......@@ -51,7 +51,12 @@ public:
std::string directory() const { return m_directory; }
/// Return project resources
std::vector<smtk::resource::ResourcePtr> getResources() const;
std::vector<smtk::resource::ResourcePtr> resources() const;
/// Return resource "import location", which is the location in the
/// file system that was imported to create the resource. The return
/// string might be empty (unknown).
std::string importLocation(smtk::resource::ResourcePtr res) const;
// Future:
// * methods to add/remove project resources
......@@ -76,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());
......
......@@ -25,7 +25,9 @@ PySharedPtrClass<smtk::project::Project> pybind11_init_smtk_project_Project(py::
.def("simulationCode", &smtk::project::Project::simulationCode)
.def("name", &smtk::project::Project::name)
.def("directory", &smtk::project::Project::directory)
.def("getResources", &smtk::project::Project::getResources);
.def("resources", &smtk::project::Project::resources)
.def("importLocation", &smtk::project::Project::importLocation)
;
return 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
spec.findVoid('use-vtk-session').setIsEnabled(False)
self.assertTrue(spec.isValid(), msg="project spec not valid")
# Create project
......@@ -100,7 +103,7 @@ class TestProjectManager(unittest.TestCase):
self.project = project
# Verify that 2 resources were created
self.assertEqual(len(self.project.getResources()), 2)
self.assertEqual(len(self.project.resources()), 2)
after_count = len(self.rm.resources())
self.assertEqual(after_count - before_count, 2)
......@@ -120,7 +123,7 @@ class TestProjectManager(unittest.TestCase):
def modify_project(self):
# Get simulation attributes
resources = self.project.getResources()
resources = self.project.resources()
for res in resources:
if isinstance(res, smtk.attribute.Resource):
att_resource = res
......@@ -164,7 +167,7 @@ class TestProjectManager(unittest.TestCase):
self.assertEqual(project.name(), PROJECT1)
self.assertEqual(project.directory(), path)
resources = project.getResources()
resources = project.resources()
self.assertEqual(len(resources), 2)
for res in resources:
......
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