# add an event listener, this ensure that # on value changes the UI will react self.addEventListener('valueChanged', self.__onValueChanged) def getC(self): self.getDGNode().evaluate() return self.getDGNode().getValue('c', 0) def __onValueChanged(self, data): if data['name'] in ['a', 'b']: self.getParameter('c').fireValueChangedEvent() if __name__ == "__main__": # construct a scene # this manages the Core client scene = Scene() # construct a new SceneGraphNode myNode = MyNode(scene) # perform a full check on the # DG layout, operator source code etc scene.checkErrors() # set some data myNode.getParameter('a').setValue(7.0) myNode.getParameter('b').setValue(9.0) # evaluate and return print myNode.getParameter('c').getValue()
class MyNode(SceneGraphNode): def __init__(self, scene, **options): super(MyNode, self).__init__(scene, **options) # create a core node scalarDGNode = self.constructDGNode('Scalars') scalarDGNode.addMember('a', 'Scalar', 1.0) scalarDGNode.addMember('b', 'Scalar', 2.0) scalarDGNode.addMember('result', 'Scalar') # The operator that will perform our computation self.bindDGOperator(scalarDGNode.bindings, name = 'addOp', fileName = '1_basicMath.kl', layout = [ 'self.a', 'self.b', 'self.result' ] ) def compute(self): self.getDGNode('Scalars').evaluate() scene = Scene(None) node = MyNode(scene) node.compute() scene.close()
name = 'addOp', fileName = '2_basicMath.kl', layout = [ 'self.index', 'values.a<>', 'values.b<>', 'self.sum' ] ) self.__operatorsConstructed = True def compute(self): self.getDGNode('Calculator').evaluate() # setup a scene and two nodes scene = Scene(None) values = MyValuesNode(scene, count = 10) results = MyResultsNode(scene) # connect them through the reference interface results.getInPort('Values').setConnectedNode(values) # check errors scene.checkErrors() # fire computation results.compute() # destroy all objects scene.close()
from FabricEngine.SceneGraph.SceneImpl import Scene from FabricEngine.SceneGraph.Nodes.SceneGraphNodeImpl import SceneGraphNode class MyNode(SceneGraphNode): def __init__(self, scene, **options): super(MyNode, self).__init__(scene, **options) # create a core node scalarDGNode = self.constructDGNode('Scalars') scalarDGNode.addMember('a', 'Scalar', 1.0) scalarDGNode.addMember('b', 'Scalar', 2.0) scalarDGNode.addMember('result', 'Scalar') # The operator that will perform our computation self.bindDGOperator(scalarDGNode.bindings, name='addOp', fileName='1_basicMath.kl', layout=['self.a', 'self.b', 'self.result']) def compute(self): self.getDGNode('Scalars').evaluate() scene = Scene(None) node = MyNode(scene) node.compute() scene.close()