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
BUTTON_MOVE = gtk.gdk.BUTTON2_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):
warn_window = gtk.MessageDialog(window, type=gtk.MESSAGE_ERROR,
......@@ -141,6 +150,9 @@ class GLView:
def refresh_wrapper(self, *args, **kwargs):
prev_mode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)
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)
result = func(self, *args, **kwargs)
self.camera.position_camera()
......@@ -156,7 +168,8 @@ class GLView:
return
GLUT.glutInit()
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.glEnable(GL.GL_DEPTH_TEST)
GL.glDepthFunc(GL.GL_LEQUAL)
......@@ -286,6 +299,7 @@ class GLView:
pass
def _paint_raw(self, widget=None):
# draw the model
GuiCommon.draw_complete_model_view(self.settings)
# update the dimension display
s = self.settings
......@@ -409,6 +423,29 @@ class ProjectGui:
# all of the objects above should trigger redraw
if name != "enable_ode":
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
if GuiCommon.is_ode_available():
self.settings.set("enable_ode", True)
......
......@@ -19,14 +19,6 @@ MODEL_TRANSFORMATIONS = {
"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 wrapper(*args, **kwargs):
prev_mode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)
......@@ -97,8 +89,7 @@ def draw_axes(settings):
draw_string(0, 0, string_distance, 'xz', "Z", scale=scale)
@keep_matrix
def draw_bounding_box(minx, miny, minz, maxx, maxy, maxz):
color = COLORS["bounding"]
def draw_bounding_box(minx, miny, minz, maxx, maxy, maxz, color):
p1 = [minx, miny, minz]
p2 = [minx, maxy, minz]
p3 = [maxx, maxy, minz]
......@@ -120,9 +111,9 @@ def draw_bounding_box(minx, miny, minz, maxx, maxy, maxz):
@keep_gl_mode
@keep_matrix
def draw_cutter(cutter):
def draw_cutter(cutter, color):
if not cutter is None:
GL.glColor3f(*COLORS["cutter"])
GL.glColor3f(*color)
cutter.to_OpenGL()
@keep_gl_mode
......@@ -137,36 +128,39 @@ def draw_complete_model_view(settings):
if settings.get("show_bounding_box"):
draw_bounding_box(float(settings.get("minx")), float(settings.get("miny")),
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
if settings.get("show_model"):
GL.glColor3f(*COLORS["model"])
GL.glColor3f(*settings.get("color_model"))
settings.get("model").to_OpenGL()
# draw the toolpath
if settings.get("show_toolpath"):
for toolpath_obj in settings.get("toolpath"):
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
if settings.get("show_drill_progress"):
draw_cutter(settings.get("cutter"))
draw_cutter(settings.get("cutter"), settings.get("color_cutter"))
@keep_gl_mode
@keep_matrix
def draw_toolpath(toolpath):
def draw_toolpath(toolpath, color_forward, color_backward):
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
if toolpath:
last = None
for path in toolpath:
if last:
GL.glColor3f(*COLORS["toolpath_back"])
GL.glColor3f(*color_backward)
GL.glBegin(GL.GL_LINES)
GL.glVertex3f(last.x, last.y, last.z)
last = path.points[0]
GL.glVertex3f(last.x, last.y, last.z)
GL.glEnd()
GL.glColor3f(*COLORS["toolpath_way"])
GL.glColor3f(*color_forward)
GL.glBegin(GL.GL_LINE_STRIP)
for point in path.points:
GL.glVertex3f(point.x, point.y, point.z)
......
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