A full example is below, but the important bit is the event handler:
Code: Select all
def key_cb(self, attr, event_cb):
state = event_cb.getAction().getState()
co_el = coin.SoCoordinateElement.getInstance(state)
points = co_el.getArrayPtr3()
Code: Select all
import FreeCAD, FreeCADGui
from pivy import coin
from pivy import graphics
class TestSep(coin.SoSeparator):
def __init__(self):
super(coin.SoSeparator, self).__init__()
self.marker = coin.SoMarkerSet()
self.events = coin.SoEventCallback()
self += self.events, self.marker
self.events.addEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self.key_cb)
def key_cb(self, attr, event_cb):
state = event_cb.getAction().getState()
co_el = coin.SoCoordinateElement.getInstance(state)
points = co_el.getArrayPtr3()
class TestObj():
def __init__(self, obj):
# self.Type = 'hull'
obj.Proxy = self
TestObjViewProvider(obj.ViewObject)
def onChanged(self, fp, prop):
pass
def execute(self, obj):
pass
class TestObjViewProvider():
def __init__(self, obj):
self.ViewObject = obj
obj.Proxy = self
def attach(self, obj):
parent = coin.SoSeparator()
c = coin.SoCoordinate3()
c.point.setValues(0, 1, [FreeCAD.Vector(0, 1, 0)])
m = TestSep()
parent += c, m
for mode in self.getDisplayModes(obj):
obj.addDisplayMode(parent, mode)
def updateData(self, fp, prop):
pass
def getDisplayModes(self, obj):
return ['Shaded']
def getDefaultDisplayMode(self):
return 'Shaded'
def setDisplayMode(self, mode):
return mode
def onChanged(self, vp, prop):
pass
def getIcon(self):
return """
/* XPM */
static const char * ViewProviderBox_xpm[] = {
"16 16 6 1",
" c None",
". c #141010",
"+ c #615BD2",
"@ c #C39D55",
"# c #000000",
"$ c #57C355",
" ........",
" ......++..+..",
" .@@@@.++..++.",
" .@@@@.++..++.",
" .@@ .++++++.",
" ..@@ .++..++.",
"###@@@@ .++..++.",
"##$.@@$#.++++++.",
"#$#$.$$$........",
"#$$####### ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
" #$#$$$$$# ",
" ##$$$$$# ",
" ####### "};
"""
def __getstate__(self):
return None
def __setState__(self, state):
return None
def makeTest():
a = FreeCAD.ActiveDocument.addObject('App::FeaturePython', 'Test')
TestObj(a)