Commit 2bb1b65b authored by John Tourtellott's avatar John Tourtellott

Add method to get the import location for a project resource

Allows export scripts to provides option to use existing mesh file
instead of making copies. Also renames Project::getResources() to
just Project::resources().
parent 1b88899b
......@@ -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
......@@ -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 (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)
{
......@@ -635,7 +650,7 @@ 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();
auto resourceList = this->resources();
for (auto resource : resourceList)
{
if (resource->isOfType(smtk::common::typeName<smtk::attribute::Resource>()))
......
......@@ -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
......
......@@ -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;
}
......
......@@ -100,7 +100,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 +120,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 +164,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