Updates will be applied - 3:30pm EDT (UTC -500). No downtime expected.

Commit af39c78a authored by David Thompson's avatar David Thompson

Fix loading of attribute-model association from files.

These 2 changes provide defense in depth against associations
read from files when no model manager is specified:
1. First, the `ResourceSetLoader` now has a constructor that allows
   you to specify a model manager.
2. Second, if `EntityRef` objects with a null model manager are
   created at load time and *then* a reference model manager is set
   on the attribute system, use that model manager when returning values.
parent 0d735ce2
......@@ -11,6 +11,10 @@
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/attribute/ModelEntityItemDefinition.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/System.h"
#include "smtk/model/Manager.h"
using namespace smtk::attribute;
/// Construct an item given its owning attribute and location in the attribute.
......@@ -141,7 +145,16 @@ smtk::model::EntityRef ModelEntityItem::value(std::size_t i) const
{
if (i >= static_cast<std::size_t>(this->m_values.size()))
return smtk::model::EntityRef();
return this->m_values[i];
auto result = this->m_values[i];
if (!result.manager())
{
smtk::model::Manager::Ptr mgr = this->attribute()->system()->refModelManager();
if (mgr)
{
result.setManager(mgr);
}
}
return result;
}
/**\brief Set the entity stored with this item.
......
......@@ -19,6 +19,8 @@
#include "smtk/common/CompilerInformation.h"
#include "smtk/model/Manager.h"
SMTK_THIRDPARTY_PRE_INCLUDE
#include "boost/filesystem.hpp"
SMTK_THIRDPARTY_POST_INCLUDE
......@@ -33,6 +35,15 @@ namespace smtk
namespace io
{
ResourceSetReader::ResourceSetReader()
{
}
ResourceSetReader::ResourceSetReader(smtk::model::ManagerPtr mgr)
: m_modelManager(mgr)
{
}
bool ResourceSetReader::readFile(
std::string filename, ResourceSet& resources, smtk::io::Logger& logger, bool loadLinkedFiles)
{
......@@ -225,6 +236,11 @@ bool ResourceSetReader::readEmbeddedAttSystem(pugi::xml_node& element,
return false;
}
if (m_modelManager && !system->refModelManager())
{
system->setRefModelManager(m_modelManager);
}
// Instantiate AttributeReader and load contents
AttributeReader reader;
if (linkStartPath != "")
......
......@@ -40,6 +40,9 @@ class SMTKCORE_EXPORT ResourceSetReader
typedef std::map<std::string, smtk::common::ResourcePtr> ResourceMapType;
public:
ResourceSetReader();
ResourceSetReader(smtk::model::ManagerPtr mgr);
bool readFile(std::string filename, smtk::common::ResourceSet& resources,
smtk::io::Logger& logger, bool loadLinkedFiles = true);
bool readString(const std::string& content, smtk::common::ResourceSet& resources,
......@@ -52,6 +55,8 @@ protected:
std::string& path, smtk::io::Logger& logger);
std::string buildIncludePath(
const smtk::common::ResourceSet& resources, const std::string link) const;
smtk::model::ManagerPtr m_modelManager;
};
} // namespace io
......
......@@ -23,6 +23,7 @@ PySharedPtrClass< smtk::io::ResourceSetReader > pybind11_init_smtk_io_ResourceSe
PySharedPtrClass< smtk::io::ResourceSetReader > instance(m, "ResourceSetReader");
instance
.def(py::init<>())
.def(py::init<::smtk::model::ManagerPtr>())
.def(py::init<::smtk::io::ResourceSetReader const &>())
.def("deepcopy", (smtk::io::ResourceSetReader & (smtk::io::ResourceSetReader::*)(::smtk::io::ResourceSetReader const &)) &smtk::io::ResourceSetReader::operator=)
.def("readFile", &smtk::io::ResourceSetReader::readFile, py::arg("filename"), py::arg("resources"), py::arg("logger"), py::arg("loadLinkedFiles") = true)
......
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