add comment about clearing Py::Dict when changing C++ data

This commit is contained in:
J-Dunn
2021-01-04 08:58:55 +00:00
committed by wmayer
parent 08297e5239
commit 8cb513ba45

View File

@@ -56,6 +56,11 @@ std::string CommandPy::representation(void) const
return str.str();
}
//
// Py::Dict parameters_copy_dict is now a class member to avoid delete/create/copy on every read access from python code
// Now the pre-filled Py::Dict is returned which is more consistent with normal python behaviour.
// It should be cleared whenever the c++ Parameters object is changed eg setParameters() or other objects invalidate its content, eg setPlacement()
// https://forum.freecadweb.org/viewtopic.php?f=15&t=50583
PyObject *CommandPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
@@ -158,7 +163,7 @@ void CommandPy::setName(Py::String arg)
Py::Dict CommandPy::getParameters(void) const
{
// dict now a class member , https://forum.freecadweb.org/viewtopic.php?f=15&t=50583&
// dict now a class member , https://forum.freecadweb.org/viewtopic.php?f=15&t=50583
if (parameters_copy_dict.length()==0) {
for(std::map<std::string,double>::iterator i = getCommandPtr()->Parameters.begin(); i != getCommandPtr()->Parameters.end(); ++i) {
parameters_copy_dict.setItem(i->first, Py::Float(i->second));