Commit 16acdad6 authored by sumpfralle's avatar sumpfralle

separated some more OpenGL visualization items to separate plugins

fixed various small issues


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1124 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 0b5ac044
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -184,6 +184,34 @@ class Bounds(pycam.Plugins.ListPluginBase): ...@@ -184,6 +184,34 @@ class Bounds(pycam.Plugins.ListPluginBase):
for not_found in remaining: for not_found in remaining:
models.remove(not_found) models.remove(not_found)
def get_bounds_limit(self, bounds):
default = (None, None, None), (None, None, None)
get_low_value = lambda axis: bounds["BoundaryLow%s" % "XYZ"[axis]]
get_high_value = lambda axis: bounds["BoundaryHigh%s" % "XYZ"[axis]]
if bounds["TypeRelativeMargin"]:
low_model, high_model = pycam.Geometry.Model.get_combined_bounds(
bounds["Models"])
if None in low_model or None in high_model:
# zero-sized models -> no action
return default
is_percent = self.RELATIVE_UNIT[bounds["RelativeUnit"]] == "%"
low, high = [], []
if is_percent:
for axis in range(3):
dim = high_model[axis] - low_model[axis]
low.append(low_model[axis] - (get_low_value(axis) / 100.0 * dim))
high.append(high_model[axis] + (get_high_value(axis) / 100.0 * dim))
else:
for axis in range(3):
low.append(low_model[axis] - get_low_value(axis))
high.append(high_model[axis] + get_high_value(axis))
else:
low, high = [], []
for axis in range(3):
low.append(get_low_value(axis))
high.append(get_high_value(axis))
return low, high
def _render_model_name(self, column, cell, model, m_iter): def _render_model_name(self, column, cell, model, m_iter):
path = model.get_path(m_iter) path = model.get_path(m_iter)
all_models = self.core.get("models") all_models = self.core.get("models")
......
...@@ -78,17 +78,10 @@ class Fonts(pycam.Plugins.PluginBase): ...@@ -78,17 +78,10 @@ class Fonts(pycam.Plugins.PluginBase):
self.update_font_dialog_preview) self.update_font_dialog_preview)
# use global key accel map # use global key accel map
self.font_dialog_window.add_accel_group(self.core.get("gtk-accel-group")) self.font_dialog_window.add_accel_group(self.core.get("gtk-accel-group"))
# menu item and shortcut
actiongroup = self._gtk.ActionGroup("fonts")
font_action = self.gui.get_object("ShowFontDialog") font_action = self.gui.get_object("ShowFontDialog")
self.register_gtk_accelerator("fonts", font_action,
"<Control><Shift>t", "ShowFontDialog")
font_action.connect("activate", self.toggle_font_dialog_window) font_action.connect("activate", self.toggle_font_dialog_window)
key, mod = self._gtk.accelerator_parse("<Control><Shift>t")
# TODO: move the "<pycam>" accel path somewhere else
accel_path = "<pycam>/ShowFontDialog"
font_action.set_accel_path(accel_path)
self._gtk.accel_map_change_entry(accel_path, key, mod, True)
actiongroup.add_action(font_action)
self.core.get("gtk-uimanager").insert_action_group(actiongroup, pos=-1)
# store window position # store window position
self._font_dialog_window_visible = False self._font_dialog_window_visible = False
self._font_dialog_window_position = None self._font_dialog_window_position = None
......
...@@ -95,6 +95,11 @@ class ModelPosition(pycam.Plugins.PluginBase): ...@@ -95,6 +95,11 @@ class ModelPosition(pycam.Plugins.PluginBase):
self.core.emit_event("model-change-before") self.core.emit_event("model-change-before")
dest = [self.gui.get_object("AlignPosition%s" % axis).get_value() dest = [self.gui.get_object("AlignPosition%s" % axis).get_value()
for axis in "XYZ"] for axis in "XYZ"]
progress = self.core.get("progress")
progress.update(text="Shifting model")
progress.disable_cancel()
progress.set_multiple(len(models), "Model")
for model in models:
shift_values = [] shift_values = []
for axis in "XYZ": for axis in "XYZ":
dest = self.gui.get_object("AlignPosition%s" % axis).get_value() dest = self.gui.get_object("AlignPosition%s" % axis).get_value()
...@@ -111,11 +116,6 @@ class ModelPosition(pycam.Plugins.PluginBase): ...@@ -111,11 +116,6 @@ class ModelPosition(pycam.Plugins.PluginBase):
else: else:
shift = dest - max_axis shift = dest - max_axis
shift_values.append(shift) shift_values.append(shift)
progress = self.core.get("progress")
progress.update(text="Shifting model")
progress.disable_cancel()
progress.set_multiple(len(models), "Model")
for model in models:
model.shift(shift_values[0], shift_values[1], shift_values[2], model.shift(shift_values[0], shift_values[1], shift_values[2],
callback=progress.update) callback=progress.update)
progress.update_multiple() progress.update_multiple()
......
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
from pycam.Geometry.utils import number
class OpenGLViewAxes(pycam.Plugins.PluginBase):
DEPENDS = ["OpenGLWindow"]
def setup(self):
import OpenGL.GL
import OpenGL.GLUT
self._GL = OpenGL.GL
self._GLUT = OpenGL.GLUT
self.core.register_event("visualize-items", self.draw_axes)
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_axes)
def draw_axes(self):
if not self.core.get("show_axes"):
return
GL = self._GL
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
low, high = pycam.Geometry.Model.get_combined_bounds(
self.core.get("models").get_visible())
if None in low or None in high:
low, high = (0, 0, 0), (1, 1, 1)
size_x = abs(high[0])
size_y = abs(high[1])
size_z = abs(high[2])
size = number(1.7) * max(size_x, size_y, size_z)
# 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)
GL.glBegin(GL.GL_LINES)
GL.glColor4f(1, 0, 0, 1)
GL.glVertex3f(0, 0, 0)
GL.glVertex3f(size, 0, 0)
GL.glEnd()
self.draw_string(string_distance, 0, 0, 'xy', "X", scale=scale)
GL.glBegin(GL.GL_LINES)
GL.glColor3f(0, 1, 0)
GL.glVertex3f(0, 0, 0)
GL.glVertex3f(0, size, 0)
GL.glEnd()
self.draw_string(0, string_distance, 0, 'yz', "Y", scale=scale)
GL.glBegin(GL.GL_LINES)
GL.glColor3f(0, 0, 1)
GL.glVertex3f(0, 0, 0)
GL.glVertex3f(0, 0, size)
GL.glEnd()
self.draw_string(0, 0, string_distance, 'xz', "Z", scale=scale)
if self.core.get("view_light"):
GL.glEnable(GL.GL_LIGHTING)
def draw_string(self, x, y, z, p, s, scale=.01):
GL = self._GL
GLUT = self._GLUT
GL.glPushMatrix()
GL.glTranslatef(x, y, z)
if p == 'xy':
GL.glRotatef(90, 1, 0, 0)
elif p == 'yz':
GL.glRotatef(90, 0, 1, 0)
GL.glRotatef(90, 0, 0, 1)
elif p == 'xz':
GL.glRotatef(90, 0, 1, 0)
GL.glRotatef(90, 0, 0, 1)
GL.glRotatef(45, 0, 1, 0)
GL.glScalef(scale, scale, scale)
for c in str(s):
GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(c))
GL.glPopMatrix()
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
class OpenGLViewBounds(pycam.Plugins.PluginBase):
DEPENDS = ["OpenGLWindow", "Bounds"]
def setup(self):
import OpenGL.GL
self._GL = OpenGL.GL
self.core.register_event("visualize-items", self.draw_bounds)
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_bounds)
def draw_bounds(self):
GL = self._GL
if not self.core.get("show_bounding_box"):
return
bounds = self.core.get("bounds").get_selected()
if not bounds:
return
low, high = self.core.get("bounds").get_bounds_limit(bounds)
if None in low or None in high:
return
minx, miny, minz = low[0], low[1], low[2]
maxx, maxy, maxz = high[0], high[1], high[2]
p1 = [minx, miny, minz]
p2 = [minx, maxy, minz]
p3 = [maxx, maxy, minz]
p4 = [maxx, miny, minz]
p5 = [minx, miny, maxz]
p6 = [minx, maxy, maxz]
p7 = [maxx, maxy, maxz]
p8 = [maxx, miny, maxz]
if self.core.get("view_light"):
GL.glDisable(GL.GL_LIGHTING)
# lower rectangle
GL.glColor4f(*self.core.get("color_bounding_box"))
GL.glFinish()
GL.glBegin(GL.GL_LINES)
# all combinations of neighbouring corners
for corner_pair in [(p1, p2), (p1, p5), (p1, p4), (p2, p3),
(p2, p6), (p3, p4), (p3, p7), (p4, p8), (p5, p6),
(p6, p7), (p7, p8), (p8, p5)]:
GL.glVertex3f(*(corner_pair[0]))
GL.glVertex3f(*(corner_pair[1]))
GL.glEnd()
if self.core.get("view_light"):
GL.glEnable(GL.GL_LIGHTING)
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
GTK_COLOR_MAX = 65535.0
class OpenGLWindow(pycam.Plugins.PluginBase):
DEPENDS = ["OpenGLWindow", "Models"]
def setup(self):
import gtk
import OpenGL.GL
self._gtk = gtk
self._GL = OpenGL.GL
self.core.register_event("visualize-items", self.draw_model)
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_model)
return True
def draw_model(self):
if self.core.get("show_model") \
and not (self.core.get("show_simulation") \
and self.core.get("simulation_toolpath_moves")):
for model in self.core.get("models").get_visible():
color_str = self.core.get("models").get_attr(model, "color")
alpha = self.core.get("models").get_attr(model, "alpha")
col = self._gtk.gdk.color_parse(color_str)
self._GL.glColor4f(col.red / GTK_COLOR_MAX, col.green / GTK_COLOR_MAX,
col.blue / GTK_COLOR_MAX, alpha / GTK_COLOR_MAX)
# we need to wait until the color change is active
self._GL.glFinish()
model.to_OpenGL(show_directions=self.core.get("show_directions"))
This diff is collapsed.
...@@ -76,8 +76,23 @@ class PluginBase(object): ...@@ -76,8 +76,23 @@ class PluginBase(object):
"'setup'") % (self.name, __file__)) "'setup'") % (self.name, __file__))
def teardown(self): def teardown(self):
raise NotImplementedError("Module %s (%s) does not implement " + \ raise NotImplementedError(("Module %s (%s) does not implement " + \
"'teardown'" % (self.name, __file__)) "'teardown'") % (self.name, __file__))
def register_gtk_accelerator(self, groupname, action, accel_string,
accel_name):
# menu item and shortcut
try:
import gtk
except ImportError:
return
actiongroup = gtk.ActionGroup(groupname)
key, mod = gtk.accelerator_parse(accel_string)
accel_path = "<pycam>/%s" % accel_name
action.set_accel_path(accel_path)
gtk.accel_map_change_entry(accel_path, key, mod, True)
actiongroup.add_action(action)
self.core.get("gtk-uimanager").insert_action_group(actiongroup, pos=-1)
class PluginManager(object): class PluginManager(object):
......
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