Commit 85c9ca8f authored by sumpfralle's avatar sumpfralle

all drawing colors are configurable


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@189 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d222d8e6
...@@ -34,6 +34,15 @@ BUTTON_ROTATE = gtk.gdk.BUTTON1_MASK ...@@ -34,6 +34,15 @@ BUTTON_ROTATE = gtk.gdk.BUTTON1_MASK
BUTTON_MOVE = gtk.gdk.BUTTON2_MASK BUTTON_MOVE = gtk.gdk.BUTTON2_MASK
BUTTON_ZOOM = gtk.gdk.BUTTON3_MASK BUTTON_ZOOM = gtk.gdk.BUTTON3_MASK
COLORS = {
"color_background": (0.0, 0.0, 0.0),
"color_model": (0.5, 0.5, 1.0),
"color_bounding_box": (0.3, 0.3, 0.3),
"color_cutter": (1.0, 0.2, 0.2),
"color_toolpath_cut": (1.0, 0.5, 0.5),
"color_toolpath_return": (0.5, 1.0, 0.5),
}
def show_error_dialog(window, message): def show_error_dialog(window, message):
warn_window = gtk.MessageDialog(window, type=gtk.MESSAGE_ERROR, warn_window = gtk.MessageDialog(window, type=gtk.MESSAGE_ERROR,
...@@ -141,6 +150,9 @@ class GLView: ...@@ -141,6 +150,9 @@ class GLView:
def refresh_wrapper(self, *args, **kwargs): def refresh_wrapper(self, *args, **kwargs):
prev_mode = GL.glGetIntegerv(GL.GL_MATRIX_MODE) prev_mode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)
GL.glMatrixMode(GL.GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
# clear the background with the configured color
bg_col = self.settings.get("color_background")
GL.glClearColor(bg_col[0], bg_col[1], bg_col[2], 0.0)
GL.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT) GL.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT)
result = func(self, *args, **kwargs) result = func(self, *args, **kwargs)
self.camera.position_camera() self.camera.position_camera()
...@@ -156,7 +168,8 @@ class GLView: ...@@ -156,7 +168,8 @@ class GLView:
return return
GLUT.glutInit() GLUT.glutInit()
GL.glShadeModel(GL.GL_FLAT) GL.glShadeModel(GL.GL_FLAT)
GL.glClearColor(0., 0., 0., 0.) bg_col = self.settings.get("color_background")
GL.glClearColor(bg_col[0], bg_col[1], bg_col[2], 0.0)
GL.glClearDepth(1.) GL.glClearDepth(1.)
GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_DEPTH_TEST)
GL.glDepthFunc(GL.GL_LEQUAL) GL.glDepthFunc(GL.GL_LEQUAL)
...@@ -286,6 +299,7 @@ class GLView: ...@@ -286,6 +299,7 @@ class GLView:
pass pass
def _paint_raw(self, widget=None): def _paint_raw(self, widget=None):
# draw the model
GuiCommon.draw_complete_model_view(self.settings) GuiCommon.draw_complete_model_view(self.settings)
# update the dimension display # update the dimension display
s = self.settings s = self.settings
...@@ -409,6 +423,29 @@ class ProjectGui: ...@@ -409,6 +423,29 @@ class ProjectGui:
# all of the objects above should trigger redraw # all of the objects above should trigger redraw
if name != "enable_ode": if name != "enable_ode":
obj.connect("toggled", self.update_view) obj.connect("toggled", self.update_view)
# color selectors
def get_color_wrapper(obj):
def gtk_color_to_float():
gtk_color = obj.get_color()
return (gtk_color.red_float, gtk_color.green_float, gtk_color.blue_float)
return gtk_color_to_float
def set_color_wrapper(obj):
def set_gtk_color_by_float((red, green, blue)):
obj.set_color(gtk.gdk.Color(red, green, blue))
return set_gtk_color_by_float
for name, objname in (("color_background", "ColorBackground"),
("color_model", "ColorModel"),
("color_bounding_box", "ColorBoundingBox"),
("color_cutter", "ColorDrill"),
("color_toolpath_return", "ColorToolpathReturn")):
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", self.update_view)
# pre-define the colors
for name in COLORS.keys():
print "Set: %s / %s" % (name, COLORS[name])
self.settings.set(name, COLORS[name])
# set the availability of ODE # set the availability of ODE
if GuiCommon.is_ode_available(): if GuiCommon.is_ode_available():
self.settings.set("enable_ode", True) self.settings.set("enable_ode", True)
......
...@@ -19,14 +19,6 @@ MODEL_TRANSFORMATIONS = { ...@@ -19,14 +19,6 @@ MODEL_TRANSFORMATIONS = {
"y_swap_z": ((1, 0, 0, 0), (0, 0, 1, 0), (0, 1, 0, 0)), "y_swap_z": ((1, 0, 0, 0), (0, 0, 1, 0), (0, 1, 0, 0)),
} }
COLORS = {
"model": (0.5, 0.5, 1.0),
"bounding": (0.3, 0.3, 0.3),
"cutter": (1.0, 0.2, 0.2),
"toolpath_way": (1.0, 0.5, 0.5),
"toolpath_back": (0.5, 1.0, 0.5),
}
def keep_gl_mode(func): def keep_gl_mode(func):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
prev_mode = GL.glGetIntegerv(GL.GL_MATRIX_MODE) prev_mode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)
...@@ -97,8 +89,7 @@ def draw_axes(settings): ...@@ -97,8 +89,7 @@ def draw_axes(settings):
draw_string(0, 0, string_distance, 'xz', "Z", scale=scale) draw_string(0, 0, string_distance, 'xz', "Z", scale=scale)
@keep_matrix @keep_matrix
def draw_bounding_box(minx, miny, minz, maxx, maxy, maxz): def draw_bounding_box(minx, miny, minz, maxx, maxy, maxz, color):
color = COLORS["bounding"]
p1 = [minx, miny, minz] p1 = [minx, miny, minz]
p2 = [minx, maxy, minz] p2 = [minx, maxy, minz]
p3 = [maxx, maxy, minz] p3 = [maxx, maxy, minz]
...@@ -120,9 +111,9 @@ def draw_bounding_box(minx, miny, minz, maxx, maxy, maxz): ...@@ -120,9 +111,9 @@ def draw_bounding_box(minx, miny, minz, maxx, maxy, maxz):
@keep_gl_mode @keep_gl_mode
@keep_matrix @keep_matrix
def draw_cutter(cutter): def draw_cutter(cutter, color):
if not cutter is None: if not cutter is None:
GL.glColor3f(*COLORS["cutter"]) GL.glColor3f(*color)
cutter.to_OpenGL() cutter.to_OpenGL()
@keep_gl_mode @keep_gl_mode
...@@ -137,36 +128,39 @@ def draw_complete_model_view(settings): ...@@ -137,36 +128,39 @@ def draw_complete_model_view(settings):
if settings.get("show_bounding_box"): if settings.get("show_bounding_box"):
draw_bounding_box(float(settings.get("minx")), float(settings.get("miny")), draw_bounding_box(float(settings.get("minx")), float(settings.get("miny")),
float(settings.get("minz")), float(settings.get("maxx")), float(settings.get("minz")), float(settings.get("maxx")),
float(settings.get("maxy")), float(settings.get("maxz"))) float(settings.get("maxy")), float(settings.get("maxz")),
settings.get("color_bounding_box"))
# draw the model # draw the model
if settings.get("show_model"): if settings.get("show_model"):
GL.glColor3f(*COLORS["model"]) GL.glColor3f(*settings.get("color_model"))
settings.get("model").to_OpenGL() settings.get("model").to_OpenGL()
# draw the toolpath # draw the toolpath
if settings.get("show_toolpath"): if settings.get("show_toolpath"):
for toolpath_obj in settings.get("toolpath"): for toolpath_obj in settings.get("toolpath"):
if toolpath_obj.visible: if toolpath_obj.visible:
draw_toolpath(toolpath_obj.get_path()) draw_toolpath(toolpath_obj.get_path(),
settings.get("color_toolpath_cut"),
settings.get("color_toolpath_return"))
# draw the drill # draw the drill
if settings.get("show_drill_progress"): if settings.get("show_drill_progress"):
draw_cutter(settings.get("cutter")) draw_cutter(settings.get("cutter"), settings.get("color_cutter"))
@keep_gl_mode @keep_gl_mode
@keep_matrix @keep_matrix
def draw_toolpath(toolpath): def draw_toolpath(toolpath, color_forward, color_backward):
GL.glMatrixMode(GL.GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity() GL.glLoadIdentity()
if toolpath: if toolpath:
last = None last = None
for path in toolpath: for path in toolpath:
if last: if last:
GL.glColor3f(*COLORS["toolpath_back"]) GL.glColor3f(*color_backward)
GL.glBegin(GL.GL_LINES) GL.glBegin(GL.GL_LINES)
GL.glVertex3f(last.x, last.y, last.z) GL.glVertex3f(last.x, last.y, last.z)
last = path.points[0] last = path.points[0]
GL.glVertex3f(last.x, last.y, last.z) GL.glVertex3f(last.x, last.y, last.z)
GL.glEnd() GL.glEnd()
GL.glColor3f(*COLORS["toolpath_way"]) GL.glColor3f(*color_forward)
GL.glBegin(GL.GL_LINE_STRIP) GL.glBegin(GL.GL_LINE_STRIP)
for point in path.points: for point in path.points:
GL.glVertex3f(point.x, point.y, point.z) GL.glVertex3f(point.x, point.y, point.z)
......
...@@ -2599,6 +2599,7 @@ ...@@ -2599,6 +2599,7 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="expand">False</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
...@@ -2748,11 +2749,195 @@ ...@@ -2748,11 +2749,195 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="expand">False</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="ColorSelectionFrame">
<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="table4">
<property name="visible">True</property>
<property name="n_rows">5</property>
<property name="n_columns">2</property>
<property name="column_spacing">23</property>
<child>
<object class="GtkColorButton" id="ColorModel">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ColorBackgroundLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Background:</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="ColorBackground">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="ColorBoundingBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ColorModelLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Model:</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ColorBoundingBoxLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Bounding Box:</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ColorToolpathReturnLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Toolpath return:</property>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="ColorToolpathReturn">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ColorDrillLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Drill:</property>
</object> </object>
<packing> <packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="ColorDrill">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</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>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </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