Extended PluginManager::create() to be able to work with references and ordered dictionaries
parent
263876f5b9
commit
bf9b5c5502
|
@ -527,13 +527,13 @@ static bp::object pluginmgr_createobject_2(PluginManager *mgr, const Class *cls,
|
||||||
return cast(mgr->createObject(cls, props));
|
return cast(mgr->createObject(cls, props));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConfigurableObject *pluginmgr_create(PluginManager *manager, bp::dict dict) {
|
static ConfigurableObject *pluginmgr_create_helper(PluginManager *manager, bp::dict dict, std::map<std::string, ConfigurableObject *> &objs) {
|
||||||
Properties properties;
|
Properties properties;
|
||||||
bp::list list = dict.items();
|
bp::list items = dict.items();
|
||||||
std::map<std::string, ConfigurableObject *> children;
|
std::map<std::string, ConfigurableObject *> children;
|
||||||
|
|
||||||
for (int i=0; i<bp::len(list); ++i) {
|
for (bp::stl_input_iterator<bp::tuple> it(items), end; it!=end; ++it) {
|
||||||
bp::tuple tuple = bp::extract<bp::tuple>(list[i]);
|
bp::tuple tuple = *it;
|
||||||
std::string name = bp::extract<std::string>(tuple[0]);
|
std::string name = bp::extract<std::string>(tuple[0]);
|
||||||
bp::extract<bp::dict> extractDict(tuple[1]);
|
bp::extract<bp::dict> extractDict(tuple[1]);
|
||||||
bp::extract<std::string> extractString(tuple[1]);
|
bp::extract<std::string> extractString(tuple[1]);
|
||||||
|
@ -544,8 +544,13 @@ static ConfigurableObject *pluginmgr_create(PluginManager *manager, bp::dict dic
|
||||||
SLog(EError, "'type' property must map to a string!");
|
SLog(EError, "'type' property must map to a string!");
|
||||||
else
|
else
|
||||||
properties.setPluginName(extractString());
|
properties.setPluginName(extractString());
|
||||||
|
} else if (name == "id") {
|
||||||
|
if (!extractString.check())
|
||||||
|
SLog(EError, "'id' property must map to a string!");
|
||||||
|
else
|
||||||
|
properties.setID(extractString());
|
||||||
} else if (extractDict.check()) {
|
} else if (extractDict.check()) {
|
||||||
children[name] = pluginmgr_create(manager, extractDict());
|
children[name] = pluginmgr_create_helper(manager, extractDict(), objs);
|
||||||
} else if (extractConfigurableObject.check()) {
|
} else if (extractConfigurableObject.check()) {
|
||||||
children[name] = extractConfigurableObject();
|
children[name] = extractConfigurableObject();
|
||||||
} else {
|
} else {
|
||||||
|
@ -554,10 +559,23 @@ static ConfigurableObject *pluginmgr_create(PluginManager *manager, bp::dict dic
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurableObject *object;
|
ConfigurableObject *object;
|
||||||
if (properties.getPluginName() == "scene")
|
if (properties.getPluginName() == "scene") {
|
||||||
object = new Scene(properties);
|
object = new Scene(properties);
|
||||||
else
|
} else if (properties.getPluginName() == "ref") {
|
||||||
|
std::string id = properties.getID();
|
||||||
|
if (id == "unnamed")
|
||||||
|
SLog(EError, "id parameter of reference is missing!");
|
||||||
|
if (objs.find(id) == objs.end())
|
||||||
|
SLog(EError, "Could not find referenced object with id \"%s\"", id.c_str());
|
||||||
|
return objs[id];
|
||||||
|
} else {
|
||||||
object = manager->createObject(properties);
|
object = manager->createObject(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (properties.getID() != "unnamed") {
|
||||||
|
objs[properties.getID()] = object;
|
||||||
|
object->incRef();
|
||||||
|
}
|
||||||
|
|
||||||
for (std::map<std::string, ConfigurableObject *>::iterator it = children.begin();
|
for (std::map<std::string, ConfigurableObject *>::iterator it = children.begin();
|
||||||
it != children.end(); ++it) {
|
it != children.end(); ++it) {
|
||||||
|
@ -569,6 +587,15 @@ static ConfigurableObject *pluginmgr_create(PluginManager *manager, bp::dict dic
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ConfigurableObject *pluginmgr_create(PluginManager *manager, bp::dict dict) {
|
||||||
|
std::map<std::string, ConfigurableObject *> objs;
|
||||||
|
ConfigurableObject *result = pluginmgr_create_helper(manager, dict, objs);
|
||||||
|
for (std::map<std::string, ConfigurableObject *>::iterator it = objs.begin();
|
||||||
|
it != objs.end(); ++it)
|
||||||
|
it->second->decRef();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static bp::tuple mkCoordinateSystem(const Vector &n) {
|
static bp::tuple mkCoordinateSystem(const Vector &n) {
|
||||||
Vector s, t;
|
Vector s, t;
|
||||||
coordinateSystem(n, s, t);
|
coordinateSystem(n, s, t);
|
||||||
|
@ -1032,6 +1059,7 @@ void export_core() {
|
||||||
coreModule.attr("Epsilon") = Epsilon;
|
coreModule.attr("Epsilon") = Epsilon;
|
||||||
coreModule.attr("ShadowEpsilon") = ShadowEpsilon;
|
coreModule.attr("ShadowEpsilon") = ShadowEpsilon;
|
||||||
coreModule.attr("DeltaEpsilon") = DeltaEpsilon;
|
coreModule.attr("DeltaEpsilon") = DeltaEpsilon;
|
||||||
|
coreModule.attr("SPECTRUM_SAMPLES") = SPECTRUM_SAMPLES;
|
||||||
|
|
||||||
bp::class_<Class, boost::noncopyable>("Class", bp::no_init)
|
bp::class_<Class, boost::noncopyable>("Class", bp::no_init)
|
||||||
.def("getName", &Class::getName, BP_RETURN_CONSTREF)
|
.def("getName", &Class::getName, BP_RETURN_CONSTREF)
|
||||||
|
|
Loading…
Reference in New Issue