Commit 5c6e6dfb authored by sumpfralle's avatar sumpfralle

added OpenGL settings for "light", "shadow" and "polygon fill"

added shortkeys for these settings (done by lode)
seperated settings window into multiple tabs


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@208 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 66ed9af2
......@@ -103,6 +103,7 @@ class GLView:
self.area.connect("button-press-event", self.mouse_handler)
self.area.connect('motion-notify-event', self.mouse_handler)
self.area.show()
self.container.add(self.area)
self.camera = ogl_tools.Camera(self.settings, lambda: (self.area.allocation.width, self.area.allocation.height))
# color the dimension value according to the axes
# for "y" axis: 100% green is too bright on light background - we reduce it a bit
......@@ -114,7 +115,7 @@ class GLView:
attributes.insert(color)
for name in names:
self.gui.get_object(name).set_attributes(attributes)
self.container.add(self.area)
# show the window
self.container.show()
self.show()
......@@ -139,6 +140,21 @@ class GLView:
if not (0 <= keyval <= 255):
# e.g. "shift" key
return
if chr(keyval) in ('l', 'm', 's'):
if (chr(keyval) == 'l'):
key = "view_light"
elif (chr(keyval) == 'm'):
key = "view_polygon"
elif (chr(keyval) == 's'):
key = "view_shadow"
else:
key = None
# toggle setting
self.settings.set(key, not self.settings.get(key))
# re-init gl settings
self.glsetup()
self.paint()
else:
print "Key pressed: %s (%s)" % (chr(keyval), get_state())
def check_busy(func):
......@@ -168,10 +184,11 @@ class GLView:
return refresh_wrapper
def glsetup(self):
if self.initialized:
return
GLUT.glutInit()
if self.settings.get("view_shadow"):
GL.glShadeModel(GL.GL_FLAT)
else:
GL.glShadeModel(GL.GL_SMOOTH)
bg_col = self.settings.get("color_background")
GL.glClearColor(bg_col[0], bg_col[1], bg_col[2], 0.0)
GL.glClearDepth(1.)
......@@ -183,7 +200,10 @@ class GLView:
#GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, (0.1, 0.1, 0.1, 1.0))
GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, (0.1, 0.1, 0.1, 1.0))
#GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, (0.5))
if self.settings.get("view_polygon"):
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
else:
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glMatrixMode(GL.GL_PROJECTION)
......@@ -195,7 +215,10 @@ class GLView:
GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, (.3, .3, .3, 1.0)) # Setup The SpecularLight
GL.glEnable(GL.GL_LIGHT0)
# Enable Light One
if self.settings.get("view_light"):
GL.glEnable(GL.GL_LIGHTING)
else:
GL.glDisable(GL.GL_LIGHTING)
GL.glEnable(GL.GL_NORMALIZE)
GL.glColorMaterial(GL.GL_FRONT_AND_BACK,GL.GL_AMBIENT_AND_DIFFUSE)
#GL.glColorMaterial(GL.GL_FRONT_AND_BACK,GL.GL_SPECULAR)
......@@ -224,6 +247,9 @@ class GLView:
return result
return decorated # TODO: make this a well behaved decorator (keeping name, docstring etc)
def keyboard_handler(self, widget, event):
print "KEY:", event
@check_busy
@gtkgl_functionwrapper
def mouse_handler(self, widget, event):
......@@ -419,6 +445,14 @@ class ProjectGui:
# all of the objects above should trigger redraw
if name != "enable_ode":
obj.connect("toggled", self.update_view)
for name, objname in (
("view_light", "OpenGLLight"),
("view_shadow", "OpenGLShadow"),
("view_polygon", "OpenGLPolygon")):
obj = self.gui.get_object(objname)
self.settings.add_item(name, obj.get_active, obj.set_active)
# send "True" to trigger a re-setup of GL settings
obj.connect("toggled", self.update_view, True)
# color selectors
def get_color_wrapper(obj):
def gtk_color_to_float():
......@@ -458,6 +492,9 @@ class ProjectGui:
self.settings.set("show_bounding_box", True)
self.settings.set("show_axes", True)
self.settings.set("show_dimensions", True)
self.settings.set("view_light", True)
self.settings.set("view_shadow", True)
self.settings.set("view_polygon", True)
skip_obj = self.gui.get_object("DrillProgressFrameSkipControl")
self.settings.add_item("drill_progress_max_fps", skip_obj.get_value, skip_obj.set_value)
self.settings.set("drill_progress_max_fps", 2)
......@@ -581,6 +618,8 @@ class ProjectGui:
def update_view(self, widget=None, data=None):
if self.view3d and self.view3d.is_visible and not self.no_dialog:
if data:
self.view3d.glsetup()
self.view3d.paint()
def update_physics(self, cutter):
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment