Skip to content

Commit

Permalink
graphics rename functions to lower_case
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo committed Dec 13, 2019
1 parent 46ddb2c commit 3500df1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 65 deletions.
8 changes: 4 additions & 4 deletions examples/utils/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def __init__(self, markers):
self.markers = markers

for m in self.markers:
m.on_drag.append(self.updatePolygon)
m.on_drag.append(self.update_polygon)

def updatePolygon(self):
def update_polygon(self):
self.points = sum([m.points for m in self.markers], [])

@property
Expand All @@ -36,9 +36,9 @@ def __init__(self, markers):
sum([m.points for m in markers], []), True)
self.markers = markers
for m in self.markers:
m.on_drag.append(self.updateLine)
m.on_drag.append(self.update_line)

def updateLine(self):
def update_line(self):
self.points = sum([m.points for m in self.markers], [])

@property
Expand Down
2 changes: 1 addition & 1 deletion examples/utils/marker_from_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main():
if myWindow == None: sys.exit(1)

# add a new marker type:
utils.addMarkerFromSvg("test.svg", "CUSTOM_MARKER", 50)
utils.add_marker_from_svg("test.svg", "CUSTOM_MARKER", 30)

root = coin.SoSeparator()
color = coin.SoMaterial()
Expand Down
116 changes: 59 additions & 57 deletions pivy/graphics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,70 +182,60 @@ def __init__(self, render_manager):
self += self.events, self.objects

def register(self):
self._highlightCB = self.events.addEventCallback(
coin.SoLocation2Event.getClassTypeId(), self.highlightCB)
self._selectCB = self.events.addEventCallback(
coin.SoMouseButtonEvent.getClassTypeId(), self.selectCB)
self._grabCB = self.events.addEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self.grabCB)
self._deleteCB = self.events.addEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self.deleteCB)
self._selectAllCB = self.events.addEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self.selectAllCB)
self._highlight_cb = self.events.addEventCallback(
coin.SoLocation2Event.getClassTypeId(), self.highlight_cb)
self._select_cb = self.events.addEventCallback(
coin.SoMouseButtonEvent.getClassTypeId(), self.select_cb)
self._grab_cb = self.events.addEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self.grab_cb)
self._delete_cb = self.events.addEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self.delete_cb)
self._select_all_cb = self.events.addEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self.select_all_cb)

def unregister(self):
self.events.removeEventCallback(
coin.SoLocation2Event.getClassTypeId(), self._highlightCB)
coin.SoLocation2Event.getClassTypeId(), self._highlight_cb)
self.events.removeEventCallback(
coin.SoMouseButtonEvent.getClassTypeId(), self._selectCB)
coin.SoMouseButtonEvent.getClassTypeId(), self._select_cb)
self.events.removeEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self._grabCB)
coin.SoKeyboardEvent.getClassTypeId(), self._grab_cb)
self.events.removeEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self._deleteCB)
coin.SoKeyboardEvent.getClassTypeId(), self._delete_cb)
self.events.removeEventCallback(
coin.SoKeyboardEvent.getClassTypeId(), self._selectAllCB)
coin.SoKeyboardEvent.getClassTypeId(), self._select_all_cb)


#-----------------------HIGHLIGHTING-----------------------#
# a SoLocation2Event calling a function which sends rays #
# into the scene. This will return the object the mouse is #
# currently hoovering. #

def addChild(self, child):
if hasattr(child, "dynamic"):
self.objects.addChild(child)
if child.dynamic:
self.dynamic_objects.append(child)
else:
self.static_objects.append(child)
else:
super(InteractionSeparator, self).addChild(child)

#-----------------------HIGHLIGHTING-----------------------#
# a SoLocation2Event calling a function which sends rays #
# int the scene. This will return the object the mouse is #
# currently hoovering. #

def highlightObject(self, obj):
def highlight_object(self, obj):
if self.over_object:
self.over_object.unset_mouse_over()
self.over_object = obj
if self.over_object:
self.over_object.set_mouse_over()
self.colorSelected()
self.color_selected()

def highlightCB(self, attr, event_callback):
def highlight_cb(self, attr, event_callback):
event = event_callback.getEvent()
pos = event.getPosition()
obj = self.sendRay(pos)
self.highlightObject(obj)
obj = self.send_ray(pos)
self.highlight_object(obj)

def sendRay(self, mouse_pos):
def send_ray(self, mouse_pos):
"""sends a ray trough the scene and return the nearest entity"""
ray_pick = coin.SoRayPickAction(self.render_manager.getViewportRegion())
ray_pick.setPoint(coin.SbVec2s(*mouse_pos))
ray_pick.setRadius(10)
ray_pick.setPickAll(True)
ray_pick.apply(self.render_manager.getSceneGraph())
picked_point = ray_pick.getPickedPointList()
return self.objByID(picked_point)
return self.obj_by_id(picked_point)

def objByID(self, picked_point):
def obj_by_id(self, picked_point):
for point in picked_point:
path = point.getPath()
length = path.getLength()
Expand All @@ -260,7 +250,7 @@ def objByID(self, picked_point):


#------------------------SELECTION------------------------#
def selectObject(self, obj, multi=False):
def select_object(self, obj, multi=False):
if not multi:
for o in self.selected_objects:
o.unselect()
Expand All @@ -270,16 +260,16 @@ def selectObject(self, obj, multi=False):
self.selected_objects.remove(obj)
else:
self.selected_objects.append(obj)
self.colorSelected()
self.selectionChanged()
self.color_selected()
self.selection_changed()

def selectCB(self, attr, event_callback):
def select_cb(self, attr, event_callback):
event = event_callback.getEvent()
if (event.getState() == coin.SoMouseButtonEvent.DOWN and
event.getButton() == event.BUTTON1):
pos = event.getPosition()
obj = self.sendRay(pos)
self.selectObject(obj, event.wasCtrlDown())
obj = self.send_ray(pos)
self.select_object(obj, event.wasCtrlDown())

def select_all_cb(self, event_callback):
event = event_callback.getEvent()
Expand All @@ -293,7 +283,7 @@ def select_all_cb(self, event_callback):
for obj in self.objects:
if obj.dynamic:
self.selected_objects.append(obj)
self.ColorSelected()
self.color_selected()
self.selection_changed()

def deselect_all(self):
Expand All @@ -302,14 +292,14 @@ def deselect_all(self):
o.unselect()
self.selected_objects = []

def colorSelected(self):
def color_selected(self):
for obj in self.selected_objects:
obj.select()

def selectionChanged(self):
def selection_changed(self):
pass

def selectAllCB(self, attr, event_callback):
def select_all_cb(self, attr, event_callback):
event = event_callback.getEvent()
if (event.getKey() == ord("a")):
if event.getState() == event.DOWN:
Expand All @@ -321,8 +311,8 @@ def selectAllCB(self, attr, event_callback):
for obj in self.dynamic_objects:
if obj.dynamic:
self.selected_objects.append(obj)
self.colorSelected()
self.selectionChanged()
self.color_selected()
self.selection_changed()


#------------------------INTERACTION------------------------#
Expand All @@ -343,7 +333,7 @@ def constrained_vector(self, vector):
elif self._direction == "z":
return [0, 0, vector[2]]

def grabCB(self, attr, event_callback):
def grab_cb(self, attr, event_callback):
# press g to move an entity
event = event_callback.getEvent()
# get all drag objects, every selected object can add some drag objects
Expand Down Expand Up @@ -417,14 +407,14 @@ def dragCB(self, attr, event_callback, force=False):
for foo in self.on_drag:
foo()

def deleteCB(self, attr, event_callback):
def delete_cb(self, attr, event_callback):
event = event_callback.getEvent()
# get all drag objects, every selected object can add some drag objects
# but the eventhandler is not allowed to call the drag twice on an object
if event.getKey() == ord(u"\uffff") and (event.getState() == 1):
self.removeSelected()
self.remove_selected()

def removeSelected(self):
def remove_selected(self):
temp = []
for i in self.selected_objects:
i.delete()
Expand All @@ -435,7 +425,7 @@ def removeSelected(self):
temp.append(i)
self.selected_objects = []
self.over_object = None
self.selectionChanged()
self.selection_changed()
for i in temp:
if i in self.dynamic_objects:
self.dynamic_objects.remove(i)
Expand All @@ -444,13 +434,25 @@ def removeSelected(self):
import sys
self.objects.removeChild(i)
del(i)
self.selectionChanged()
self.selection_changed()

# needs upper case as this must overwrite the addChild from coin.SoSeparator
def removeAllChildren(self):
for i in self.dynamic_objects:
i.delete()
self.dynamic_objects = []
self.static_objects = []
self.selected_objects = []
self.over_object = None
super(InteractionSeparator, self).removeAllChildren()
super(InteractionSeparator, self).removeAllChildren()

# needs upper case as this must overwrite the addChild from coin.SoSeparator
def addChild(self, child):
if hasattr(child, "dynamic"):
self.objects.addChild(child)
if child.dynamic:
self.dynamic_objects.append(child)
else:
self.static_objects.append(child)
else:
super(InteractionSeparator, self).addChild(child)
7 changes: 4 additions & 3 deletions pivy/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pivy import coin


def addMarkerFromSvg(file_path, marker_name, pixel_x=10, pixel_y=None,
def add_marker_from_svg(file_path, marker_name, pixel_x=10, pixel_y=None,
isLSBFirst=False, isUpToDown=False):
"""adds a new marker bitmap from a vector graphic (svg)"""

Expand All @@ -18,7 +18,8 @@ def addMarkerFromSvg(file_path, marker_name, pixel_x=10, pixel_y=None,
buffer.close()

# get a string from the XMP-icon
ary = str(buffer.buffer())
ary = str(buffer.buffer(), "utf8")
ary = ary.split("\n", 1)[1]
ary = ary.replace('\n', "").replace('"', "").replace(";", "")
ary = ary.replace("}", "").replace("#", "x").replace(".", " ")
string = str.join("", ary.split(",")[3:])
Expand All @@ -30,7 +31,7 @@ def addMarkerFromSvg(file_path, marker_name, pixel_x=10, pixel_y=None,
isLSBFirst, isUpToDown)


def getPointOnScreen(render_manager, screen_pos, normal="camera", point=None):
def get_point_on_screen(render_manager, screen_pos, normal="camera", point=None):
"""get coordinates from pixel position"""

pCam = render_manager.getCamera()
Expand Down

0 comments on commit 3500df1

Please sign in to comment.