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
......@@ -95,7 +95,7 @@ class GLView:
# first run; might also be important when doing other fancy gtk/gdk stuff
self.area.connect_after('realize', self.paint)
# called when a part of the screen is uncovered
self.area.connect('expose-event', self.paint)
self.area.connect('expose-event', self.paint)
# resize window
self.area.connect('configure-event', self._resize_window)
# catch mouse events
......@@ -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,7 +140,22 @@ class GLView:
if not (0 <= keyval <= 255):
# e.g. "shift" key
return
print "Key pressed: %s (%s)" % (chr(keyval), get_state())
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):
def busy_wrapper(self, *args, **kwargs):
......@@ -168,10 +184,11 @@ class GLView:
return refresh_wrapper
def glsetup(self):
if self.initialized:
return
GLUT.glutInit()
GL.glShadeModel(GL.GL_FLAT)
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))
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
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,12 +215,15 @@ 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
GL.glEnable(GL.GL_LIGHTING)
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)
#GL.glColorMaterial(GL.GL_FRONT_AND_BACK,GL.GL_EMISSION)
GL.glEnable(GL.GL_COLOR_MATERIAL)
GL.glEnable(GL.GL_COLOR_MATERIAL)
def destroy(self, widget=None, data=None):
if self.notify_destroy_func:
......@@ -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)
......@@ -578,9 +615,11 @@ class ProjectGui:
batch_func(*batch_args, **batch_kwargs)
return result
return wrapper
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):
......@@ -792,13 +831,13 @@ class ProjectGui:
while self._progress_running:
time.sleep(0.5)
gtk.main_quit()
def open(self, filename):
""" This function is used by the commandline handler """
self.last_model_file = filename
self.load_model_file(filename=filename)
self.update_save_actions()
def append_to_queue(self, func, *args, **kwargs):
# check if gui is currently active
if self.gui_is_active:
......
......@@ -2546,100 +2546,106 @@
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkVBox" id="vbox7">
<object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<property name="can_focus">True</property>
<child>
<object class="GtkFrame" id="GeneralSettingsFrame">
<object class="GtkVBox" id="vbox7">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<child>
<object class="GtkAlignment" id="alignment6">
<object class="GtkFrame" id="GeneralSettingsFrame">
<property name="visible">True</property>
<property name="left_padding">12</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkVBox" id="vbox14">
<object class="GtkAlignment" id="alignment6">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkCheckButton" id="SettingEnableODE">
<property name="label" translatable="yes">Enable experimental ODE calculations</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<property name="left_padding">12</property>
<child>
<object class="GtkHBox" id="unit_box">
<object class="GtkVBox" id="vbox14">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="UnitLabel">
<object class="GtkCheckButton" id="SettingEnableODE">
<property name="label" translatable="yes">Enable experimental ODE calculations</property>
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Unit:</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="padding">3</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="unit_control">
<object class="GtkHBox" id="unit_box">
<property name="visible">True</property>
<property name="model">unit_model</property>
<property name="active">0</property>
<child>
<object class="GtkCellRendererText" id="unit_name"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
<object class="GtkLabel" id="UnitLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Unit:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="padding">3</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="unit_control">
<property name="visible">True</property>
<property name="model">unit_model</property>
<property name="active">0</property>
<child>
<object class="GtkCellRendererText" id="unit_name"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="GeneralSettingsFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;General Settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="GeneralSettingsFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;General Settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator5">
<child type="tab">
<object class="GtkLabel" id="GeneralSettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">General</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
......@@ -2734,38 +2740,6 @@
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox7">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="DrillUpdateFPSLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Maximum Frames per Second:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="DrillProgressFrameSkipControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="adjustment">DrillProgressMaxFPS</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">6</property>
</packing>
</child>
</object>
</child>
</object>
......@@ -2779,17 +2753,17 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator1">
<child type="tab">
<object class="GtkLabel" id="DisplayItemSettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Display Items</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
......@@ -2961,13 +2935,136 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="ColorSettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Colors</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="OpenGLSettingsFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment11">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkCheckButton" id="OpenGLPolygon">
<property name="label" translatable="yes">Polygon fill</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Hotkey: &lt;p&gt;</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="OpenGLLight">
<property name="label" translatable="yes">Lightning</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Hotkey: &lt;l&gt;</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="OpenGLShadow">
<property name="label" translatable="yes">Shadows</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Hotkey: &lt;s&gt;</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox7">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="DrillUpdateFPSLabel">
<property name="visible">True</property>
<property name="tooltip_text" translatable="yes">Maximum number of frame updates per second for drill progress visualization.</property>
<property name="label" translatable="yes">Maximum Frames per Second:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="DrillProgressFrameSkipControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="adjustment">DrillProgressMaxFPS</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="OpenGLSettingsFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;OpenGL Settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="GLSettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">OpenGL</property>
</object>
<packing>
<property name="position">3</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
......
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