phr34k / coral-repo

Automatically exported from code.google.com/p/coral-repo
0 stars 2 forks source link

save graph: attribute not saved for custom value types #31

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In python, it seems that we can not save the value of the attribute if the 
attribute value is custom (inherited from the Value class)

I did not have the chance to put breakpoints in the C++ code, but one 
possibility I suspect that it's the default Value::asString which is called, 
that's why Attribute::asScript returns an empty string.

here is the minimal repro:
--------------------

from coral import Node, Value, Attribute
from coral.plugin import Plugin

class DummyValue(Value):
    def __init__(self, value=0):
        Value.__init__(self)
        self._value = value

    def setFromString(self, string):
        self._value = int(string)

    def asString(self):
        return str(self._value)

class DummyAttribute(Attribute):
    def __init__(self, name, parent):
        Attribute.__init__(self, name, parent)
        self.setClassName("DummyAttribute")
        self._setValuePtr(DummyValue(1))

class DummyNode(Node):
    def __init__(self, name, parent):
        Node.__init__(self, name, parent)
        self.out = DummyAttribute("out", self)
        self.addOutputAttribute(self.out)
        self.out2 = StringAttribute("string", self)
        self.addOutputAttribute(self.out2)

def loadPlugin():
    plugin = Plugin("dummyPlug")
    plugin.registerNode("DummyNode", DummyNode, tags=["dummy"])
    plugin.registerAttribute("DummyAttribute", DummyAttribute)
    return plugin

---------------------

result crl file is:

# coral save script
version = 0.1

def runScript(topNode = 'root'):
    executeCommand('CreateNode', className = 'DummyNode', name = 'DummyNode', specializationPreset = 'none', parentNode = topNode)
    executeCommand('SetAttributeValue', attribute = topNode + '.DummyNode.string', value = 'dummy_string_value')

    # nodeEditor save data
    executeCommand('SetNodeUiData', node = topNode, data = {})
    executeCommand('SetNodeUiData', node = topNode + '.DummyNode', data = {'pos': [-23.0, -141.0]})

--------------------

we can see that there is a missing line:
executeCommand('SetAttributeValue', attribute = topNode + '.DummyNode.out', 
value = '1')
but the string attribute is correctly saved

Original issue reported on code.google.com by pierre.a...@gmail.com on 25 Jul 2012 at 4:54

GoogleCodeExporter commented 8 years ago
Hi, it looks like the problem is in the python bindings for the class Value:
http://code.google.com/p/coral-repo/source/browse/coral/coral/pythonWrappers/val
ueWrapper.h

It's missing the boost code to enable python overloading.
I'm not sure when I'll be able to work on this, so if you wanna give it a try, 
you could easily use the Node wrapper as an example, look for:
NodeWrapper::asScript, 
NodeWrapper::asScript_default, 
def("asScript", &Node::asScript, &NodeWrapper::asScript_default)

Doing the same for Value::asString/setFromString will allow you to overload 
those methods from python.

Original comment by aintergu...@gmail.com on 25 Jul 2012 at 5:20

GoogleCodeExporter commented 8 years ago
Thanks for such a quick reply, indeed I can see that there is no function 
defined in ValueWrapper to expose the virtual method Value::asScript (and 
Value::setFromString).
It seems quite straightforward to code, so I guess I will resolve this issue 
quickly.

Original comment by pierre.a...@gmail.com on 26 Jul 2012 at 10:14