Commit 7cc0e33a authored by sumpfralle's avatar sumpfralle

moved "display items" and "colors" settings to the respective plugins


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1176 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent f613629e
......@@ -577,4 +577,64 @@
<property name="upper">25</property>
<property name="step_increment">1</property>
</object>
<object class="GtkFrame" id="ColorPrefTab">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment4">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkTable" id="ColorTable">
<property name="visible">True</property>
<property name="n_columns">2</property>
<property name="column_spacing">3</property>
<property name="row_spacing">3</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="ColorSelectionFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Color Selection&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<object class="GtkFrame" id="DisplayItemsPrefTab">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment21">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkVBox" id="PreferencesVisibleItemsBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="VisualSettingsFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Display settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
</interface>
This diff is collapsed.
......@@ -127,8 +127,6 @@ user's home directory on startup/shutdown"""
MAX_UNDO_STATES = 10
FILENAME_DRAG_TARGETS = ("text/uri-list", "text-plain")
# floating point color values are only available since gtk 2.16
GTK_COLOR_MAX = 65535.0
log = pycam.Utils.log.get_logger()
......@@ -455,8 +453,6 @@ class ProjectGui(object):
for obj_name, label, priority in (
("GeneralSettingsPrefTab", "General", -50),
("GCodePrefTab", "GCode", 10),
("DisplayItemsPrefTab", "Display Items", 20),
("ColorPrefTab", "Colors", 30),
("ProgramsPrefTab", "Programs", 50)):
obj = self.gui.get_object(obj_name)
obj.unparent()
......@@ -533,20 +529,6 @@ class ProjectGui(object):
autoload_box)
self.settings.add_item("default_task_settings_file",
get_autoload_task_file, set_autoload_task_file)
# visual and general settings
for name, objname in (("show_model", "ShowModelCheckBox"),
("show_axes", "ShowAxesCheckBox"),
("show_support_grid", "ShowSupportGridCheckBox"),
("show_dimensions", "ShowDimensionsCheckBox"),
("show_bounding_box", "ShowBoundingCheckBox"),
("show_toolpath", "ShowToolPathCheckBox"),
("show_drill", "ShowDrillCheckBox"),
("show_directions", "ShowDirectionsCheckBox")):
obj = self.gui.get_object(objname)
self.settings.add_item(name, obj.get_active, obj.set_active)
# all of the objects above should trigger redraw
obj.connect("toggled", lambda widget: \
self.settings.emit_event("model-change-after"))
def disable_gui():
self.menubar.set_sensitive(False)
main_tab.set_sensitive(False)
......@@ -555,41 +537,6 @@ class ProjectGui(object):
main_tab.set_sensitive(True)
self.settings.register_event("gui-disable", disable_gui)
self.settings.register_event("gui-enable", enable_gui)
# color selectors
def get_color_wrapper(obj):
def gtk_color_to_float():
gtk_color = obj.get_color()
alpha = obj.get_alpha()
return (gtk_color.red / GTK_COLOR_MAX,
gtk_color.green / GTK_COLOR_MAX,
gtk_color.blue / GTK_COLOR_MAX,
alpha / GTK_COLOR_MAX)
return gtk_color_to_float
def set_color_wrapper(obj):
def set_gtk_color_by_float(components):
# use alpha if it was given
if len(components) == 3:
alpha = 1.0
else:
alpha = components[3]
red, green, blue = components[:3]
obj.set_color(gtk.gdk.Color(int(red * GTK_COLOR_MAX),
int(green * GTK_COLOR_MAX), int(blue * GTK_COLOR_MAX)))
obj.set_alpha(int(alpha * GTK_COLOR_MAX))
return set_gtk_color_by_float
for name, objname in (("color_background", "ColorBackground"),
("color_model", "ColorModel"),
("color_support_grid", "ColorSupportGrid"),
("color_bounding_box", "ColorBoundingBox"),
("color_cutter", "ColorDrill"),
("color_toolpath_cut", "ColorToolpathCut"),
("color_toolpath_return", "ColorToolpathReturn"),
("color_material", "ColorMaterial")):
obj = self.gui.get_object(objname)
self.settings.add_item(name, get_color_wrapper(obj), set_color_wrapper(obj))
# repaint the 3d view after a color change
obj.connect("color-set", lambda widget: \
self.settings.emit_event("visual-item-updated"))
# gcode settings
gcode_minimum_step_x = self.gui.get_object("GCodeMinimumStep_x")
self.settings.add_item("gcode_minimum_step_x",
......@@ -760,6 +707,9 @@ class ProjectGui(object):
self.gui.get_object("Quit"), 100)
self.settings.register_ui("file_menu", "QuitSeparator", None, 95)
self.settings.register_ui("main_window", "Main", self.menubar, -100)
# initialize plugins
self.plugin_manager = pycam.Plugins.PluginManager(core=self.settings)
self.plugin_manager.import_plugins()
# some more initialization
self.reset_preferences()
self.load_preferences()
......@@ -768,9 +718,6 @@ class ProjectGui(object):
self.add_to_recent_file_list)
self.settings.register_event("notify-file-opened",
self.add_to_recent_file_list)
# initialize plugins
self.plugin_manager = pycam.Plugins.PluginManager(core=self.settings)
self.plugin_manager.import_plugins()
# fallback - in case of a failure when opening a model file
model = pycam.Importers.TestModel.get_test_model()
self.settings.get("models").append(model)
......
......@@ -35,11 +35,14 @@ class OpenGLViewAxes(pycam.Plugins.PluginBase):
self._GL = OpenGL.GL
self._GLUT = OpenGL.GLUT
self.core.register_event("visualize-items", self.draw_axes)
self.core.get("register_display_item")("show_axes",
"Show Coordinate System", 50)
self.core.emit_event("visual-item-updated")
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_axes)
self.core.get("unregister_display_item")("show_axes")
self.core.emit_event("visual-item-updated")
def draw_axes(self):
......@@ -59,10 +62,6 @@ class OpenGLViewAxes(pycam.Plugins.PluginBase):
# the divider is just based on playing with numbers
scale = size / number(1500.0)
string_distance = number(1.1) * size
#GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
#GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, (0.0,0.0,0.0,1.0)); # no ambient light
#GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, (1.0,0.0,0.0,1.0)); # diffuse red
#GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, (1.0,1.0,1.0,1.0)); # highly specular
# otherwise plain colors like the next glColor4f wouldn't work
if self.core.get("view_light"):
GL.glDisable(GL.GL_LIGHTING)
......
......@@ -31,12 +31,18 @@ class OpenGLViewBounds(pycam.Plugins.PluginBase):
def setup(self):
import OpenGL.GL
self._GL = OpenGL.GL
self.core.get("register_color")("color_bounding_box", "Bounding box",
40)
self.core.get("register_display_item")("show_bounding_box",
"Show Bounding Box", 40)
self.core.register_event("visualize-items", self.draw_bounds)
self.core.emit_event("visual-item-updated")
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_bounds)
self.core.get("unregister_color")("color_bounding_box")
self.core.get("unregister_display_item")("show_bounding_box")
self.core.emit_event("visual-item-updated")
def draw_bounds(self):
......
......@@ -40,6 +40,7 @@ class OpenGLViewModel(pycam.Plugins.PluginBase):
self._event_handlers = (("visualize-items", self.draw_model),
("model-changed","visual-item-updated"),
("model-list-changed","visual-item-updated"))
self.core.get("register_display_item")("show_model", "Show Model", 10)
self.register_event_handlers(self._event_handlers)
self.core.emit_event("visual-item-updated")
self._cache = {}
......@@ -47,6 +48,7 @@ class OpenGLViewModel(pycam.Plugins.PluginBase):
def teardown(self):
self.unregister_event_handlers(self._event_handlers)
self.core.get("unregister_display_item")("show_model")
self.core.emit_event("visual-item-updated")
def _get_cache_key(self, model, *args, **kwargs):
......
......@@ -32,11 +32,19 @@ class OpenGLViewToolpath(pycam.Plugins.PluginBase):
import OpenGL.GL
self._GL = OpenGL.GL
self.core.register_event("visualize-items", self.draw_toolpath)
self.core.get("register_color")("color_toolpath_cut", "Toolpath cut",
60)
self.core.get("register_color")("color_toolpath_return",
"Toolpath rapid", 70)
self.core.get("register_display_item")("show_toolpath", "Show Toolpath", 30),
self.core.emit_event("visual-item-updated")
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_toolpath)
self.core.get("unregister_color")("color_toolpath_cut")
self.core.get("unregister_color")("color_toolpath_return")
self.core.get("unregister_display_item")("show_toolpath")
self.core.emit_event("visual-item-updated")
def draw_toolpath(self):
......
......@@ -31,8 +31,7 @@ try:
except (ImportError, RuntimeError):
GL_ENABLED = False
# imported later (on demand)
#import gtk
import gtk
import math
from pycam.Gui.OpenGLTools import draw_complete_model_view
......@@ -67,6 +66,9 @@ BUTTON_MOVE = gtk.gdk.BUTTON2_MASK
BUTTON_ZOOM = gtk.gdk.BUTTON3_MASK
BUTTON_RIGHT = 3
# floating point color values are only available since gtk 2.16
GTK_COLOR_MAX = 65535.0
class OpenGLWindow(pycam.Plugins.PluginBase):
......@@ -111,6 +113,40 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
skip_obj = self.gui.get_object("DrillProgressFrameSkipControl")
self.core.add_item("drill_progress_max_fps",
skip_obj.get_value, skip_obj.set_value)
# color box
color_frame = self.gui.get_object("ColorPrefTab")
color_frame.unparent()
self._color_settings = {}
self.core.register_ui("preferences", "Colors", color_frame, 30)
self.core.set("register_color", self.register_color_setting)
self.core.set("unregister_color", self.unregister_color_setting)
# TODO: move the "tool" color to a separate plugin
# TODO: move "material" to simulation viewer
# TODO: move "support grid" to support grid visualization
for name, label, weight in (
("color_background", "Background", 10),
("color_model", "Model", 20),
("color_support_grid", "Support grid", 30),
("color_cutter", "Tool", 50),
("color_material", "Material", 80)):
self.core.get("register_color")(name, label, weight)
# display items
items_frame = self.gui.get_object("DisplayItemsPrefTab")
items_frame.unparent()
self._display_items = {}
self.core.register_ui("preferences", "Display Items", items_frame,
20)
self.core.set("register_display_item", self.register_display_item)
self.core.set("unregister_display_item",
self.unregister_display_item)
# visual and general settings
# TODO: move support grid and drill to a separate plugin
for name, label, weight in (
("show_support_grid", "Show Support Grid", 20),
("show_dimensions", "Show Dimensions", 60),
("show_drill", "Show Tool", 70),
("show_directions", "Show Directions", 80)):
self.core.get("register_display_item")(name, label, weight)
# toggle window state
toggle_3d = self.gui.get_object("Toggle3DView")
self._gtk_handlers.append((toggle_3d, "toggled",
......@@ -236,11 +272,18 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
def teardown(self):
if self.gui:
self.window.hide()
toggle_3d = self.gui.get_object("Toggle3DView")
# hide the window
toggle_3d.set_active(False)
self.core.unregister_ui("view_menu", toggle_3d)
self.unregister_gtk_accelerator("opengl", toggle_3d)
self.core.unregister_ui("view_menu", toggle_3d)
for name in ("color_background", "color_model",
"color_support_grid", "color_cutter", "color_material"):
self.core.get("unregister_color")(name)
for name in ("show_support_grid", "show_dimensions", "show_drill",
"show_directions"):
self.core.get("unregister_display_item")(name)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
# the area will be created during setup again
......@@ -272,6 +315,94 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
value = "%.3f" % value
self.gui.get_object(label_name).set_label(value)
def register_display_item(self, name, label, weight=100):
if name in self._display_items:
self.log.debug("Tried to register display item '%s' twice" % name)
return
widget = gtk.CheckButton(label)
widget.connect("toggled", lambda widget: \
self.core.emit_event("visual-item-updated"))
self._display_items[name] = {"name": name, "label": label,
"weight": weight, "widget": widget}
self.core.add_item(name, widget.get_active, widget.set_active)
self._rebuild_display_items()
def unregister_display_item(self, name):
if not name in self._display_items:
self.log.debug("Failed to unregister unknown display item: %s" % \
name)
return
del self._display_items[name]
self._rebuild_display_items()
def _rebuild_display_items(self):
box = self.gui.get_object("PreferencesVisibleItemsBox")
for child in box.get_children():
box.remove(child)
items = self._display_items.values()
items.sort(key=lambda item: item["weight"])
for item in items:
box.pack_start(item["widget"], expand=False)
box.show_all()
def register_color_setting(self, name, label, weight=100):
if name in self._color_settings:
self.log.debug("Tried to register color '%s' twice" % name)
return
# color selectors
def get_color_wrapper(obj):
def gtk_color_to_float():
gtk_color = obj.get_color()
alpha = obj.get_alpha()
return (gtk_color.red / GTK_COLOR_MAX,
gtk_color.green / GTK_COLOR_MAX,
gtk_color.blue / GTK_COLOR_MAX,
alpha / GTK_COLOR_MAX)
return gtk_color_to_float
def set_color_wrapper(obj):
def set_gtk_color_by_float(components):
# use alpha if it was given
if len(components) == 3:
alpha = 1.0
else:
alpha = components[3]
red, green, blue = components[:3]
obj.set_color(gtk.gdk.Color(int(red * GTK_COLOR_MAX),
int(green * GTK_COLOR_MAX), int(blue * GTK_COLOR_MAX)))
obj.set_alpha(int(alpha * GTK_COLOR_MAX))
return set_gtk_color_by_float
widget = gtk.ColorButton()
widget.set_use_alpha(True)
self._color_settings[name] = {"name": name, "label": label,
"weight": weight, "widget": widget}
widget.connect("color-set", lambda widget: \
self.core.emit_event("visual-item-updated"))
self.core.add_item(name, get_color_wrapper(widget),
set_color_wrapper(widget))
self._rebuild_color_settings()
def unregister_color_setting(self, name):
if not name in self._color_settings:
self.log.debug("Failed to unregister unknown color item: %s" % name)
return
del self._color_settings[name]
self._rebuild_color_settings()
def _rebuild_color_settings(self):
color_table = self.gui.get_object("ColorTable")
for child in color_table.get_children():
color_table.remove(child)
items = self._color_settings.values()
items.sort(key=lambda item: item["weight"])
for index, item in enumerate(items):
label = gtk.Label("%s:" % item["label"])
label.set_alignment(0.0, 0.5)
color_table.attach(label, 0, 1, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
color_table.attach(item["widget"], 1, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
color_table.show_all()
def toggle_3d_view(self, widget=None, value=None):
current_state = self.is_visible
if value is None:
......
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