Commit 21de7ac0 authored by sumpfralle's avatar sumpfralle

coloring of models fixed

toolpath-grid plugin improved
units plugin separated


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1127 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 0b069aaf
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -21,6 +21,10 @@ You should have received a copy of the GNU General Public License ...@@ -21,6 +21,10 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
import uuid
import math
import pycam.Exporters.STLExporter import pycam.Exporters.STLExporter
import pycam.Exporters.SVGExporter import pycam.Exporters.SVGExporter
from pycam.Geometry.Triangle import Triangle from pycam.Geometry.Triangle import Triangle
...@@ -35,10 +39,6 @@ from pycam.Geometry.utils import INFINITE, epsilon ...@@ -35,10 +39,6 @@ from pycam.Geometry.utils import INFINITE, epsilon
from pycam.Geometry import TransformableContainer from pycam.Geometry import TransformableContainer
from pycam.Utils import ProgressCounter from pycam.Utils import ProgressCounter
import pycam.Utils.log import pycam.Utils.log
import uuid
import math
# OpenGLTools will be imported later, if necessary
#import pycam.Gui.OpenGLTools
try: try:
...@@ -169,7 +169,6 @@ class BaseModel(TransformableContainer): ...@@ -169,7 +169,6 @@ class BaseModel(TransformableContainer):
if not coords in vertices: if not coords in vertices:
vertices[coords] = [] vertices[coords] = []
vertices[coords].append((t.normal.normalized(), t.get_area())) vertices[coords].append((t.normal.normalized(), t.get_area()))
print "Triangles: %d / Vertices: %d" % (len(self.triangles()), len(vertices))
GL.glBegin(GL.GL_TRIANGLES) GL.glBegin(GL.GL_TRIANGLES)
for t in self.triangles(): for t in self.triangles():
# The triangle's points are in clockwise order, but GL expects # The triangle's points are in clockwise order, but GL expects
......
...@@ -415,10 +415,6 @@ class ProjectGui(object): ...@@ -415,10 +415,6 @@ class ProjectGui(object):
self.about_window = self.gui.get_object("AboutWindow") self.about_window = self.gui.get_object("AboutWindow")
self.about_window.set_version(VERSION) self.about_window.set_version(VERSION)
self.gui.get_object("About").connect("activate", self.toggle_about_window, True) self.gui.get_object("About").connect("activate", self.toggle_about_window, True)
# "unit change" window
self.unit_change_window = self.gui.get_object("UnitChangeDialog")
self.gui.get_object("UnitChangeApply").connect("clicked", self.change_unit_apply)
self.unit_change_window.connect("delete_event", self.change_unit_apply, False)
# we assume, that the last child of the window is the "close" button # we assume, that the last child of the window is the "close" button
# TODO: fix this ugly hack! # TODO: fix this ugly hack!
self.gui.get_object("AboutWindowButtons").get_children()[-1].connect("clicked", self.toggle_about_window, False) self.gui.get_object("AboutWindowButtons").get_children()[-1].connect("clicked", self.toggle_about_window, False)
...@@ -430,6 +426,7 @@ class ProjectGui(object): ...@@ -430,6 +426,7 @@ class ProjectGui(object):
self.settings.add_item("gtk-accel-group", lambda: self._accel_group) self.settings.add_item("gtk-accel-group", lambda: self._accel_group)
for window in (self.window, self.about_window, self.preferences_window): for window in (self.window, self.about_window, self.preferences_window):
window.add_accel_group(self._accel_group) window.add_accel_group(self._accel_group)
# preferences tab
preferences_book = self.gui.get_object("PreferencesNotebook") preferences_book = self.gui.get_object("PreferencesNotebook")
def clear_preferences(): def clear_preferences():
for index in range(preferences_book.get_n_pages()): for index in range(preferences_book.get_n_pages()):
...@@ -448,9 +445,23 @@ class ProjectGui(object): ...@@ -448,9 +445,23 @@ class ProjectGui(object):
obj = self.gui.get_object(obj_name) obj = self.gui.get_object(obj_name)
obj.unparent() obj.unparent()
self.settings.register_ui("preferences", label, obj, priority) self.settings.register_ui("preferences", label, obj, priority)
# general preferences
general_prefs = self.gui.get_object("GeneralPreferencesBox")
def clear_general_prefs():
for item in general_prefs.get_children():
general_prefs.remove(item)
def add_general_prefs_item(item, name):
general_prefs.pack_start(item, expand=False, padding=3)
self.settings.register_ui_section("preferences_general",
add_general_prefs_item, clear_general_prefs)
for obj_name, priority in (("SettingEnableODE", 10),
("TaskSettingsDefaultFileBox", 30)):
obj = self.gui.get_object(obj_name)
obj.unparent()
self.settings.register_ui("preferences_general", None,
obj, priority)
# set defaults # set defaults
self.cutter = None self.cutter = None
self._last_unit = None
# add some dummies - to be implemented later ... # add some dummies - to be implemented later ...
self.settings.add_item("cutter", lambda: self.cutter) self.settings.add_item("cutter", lambda: self.cutter)
main_tab = self.gui.get_object("MainTabs") main_tab = self.gui.get_object("MainTabs")
...@@ -475,17 +486,6 @@ class ProjectGui(object): ...@@ -475,17 +486,6 @@ class ProjectGui(object):
clear_main_window) clear_main_window)
self.settings.register_ui("main_window", "Tabs", main_tab, -20, self.settings.register_ui("main_window", "Tabs", main_tab, -20,
args_dict={"expand": True, "fill": True}) args_dict={"expand": True, "fill": True})
# unit control (mm/inch)
unit_field = self.gui.get_object("unit_control")
unit_field.connect("changed", self.change_unit_init)
def set_unit(text):
unit_field.set_active(0 if text == "mm" else 1)
self._last_unit = text
self.settings.add_item("unit", unit_field.get_active_text, set_unit)
self.gui.get_object("UnitChangeSelectAll").connect("clicked",
self.change_unit_set_selection, True)
self.gui.get_object("UnitChangeSelectNone").connect("clicked",
self.change_unit_set_selection, False)
# autoload task settings file on startup # autoload task settings file on startup
autoload_enable = self.gui.get_object("AutoLoadTaskFile") autoload_enable = self.gui.get_object("AutoLoadTaskFile")
autoload_box = self.gui.get_object("StartupTaskFileBox") autoload_box = self.gui.get_object("StartupTaskFileBox")
...@@ -746,7 +746,6 @@ class ProjectGui(object): ...@@ -746,7 +746,6 @@ class ProjectGui(object):
def update_all_controls(self): def update_all_controls(self):
self.update_save_actions() self.update_save_actions()
self.update_unit_labels()
self.update_gcode_controls() self.update_gcode_controls()
self.update_ode_settings() self.update_ode_settings()
...@@ -930,113 +929,6 @@ class ProjectGui(object): ...@@ -930,113 +929,6 @@ class ProjectGui(object):
# don't close the window - just hide it (for "delete-event") # don't close the window - just hide it (for "delete-event")
return True return True
def change_unit_init(self, widget=None):
new_unit = self.gui.get_object("unit_control").get_active_text()
if self._last_unit is None:
# first initialization
self._last_unit = new_unit
return
if self._last_unit == new_unit:
# don't show the dialog if the conversion would make no sense
return
if self.no_dialog:
# without the dialog we don't scale anything
return
# show a dialog asking for a possible model scaling due to the unit change
self.unit_change_window.show()
def change_unit_set_selection(self, widget, state):
for key in ("UnitChangeModel", "UnitChangeProcesses", "UnitChangeTools",
"UnitChangeBounds"):
self.gui.get_object(key).set_active(state)
def change_unit_apply(self, widget=None, data=None, apply_scale=True):
if self.no_dialog:
# without the dialog we don't scale anything
return
new_unit = self.gui.get_object("unit_control").get_active_text()
factors = {
("mm", "inch"): 1 / 25.4,
("inch", "mm"): 25.4,
}
conversion = (self._last_unit, new_unit)
if conversion in factors.keys():
factor = factors[conversion]
if apply_scale:
if self.gui.get_object("UnitChangeModel").get_active():
# transform the model if it is selected
# keep the original center of the model
self.settings.emit_event("model-change-before")
models = self.settings.get("models")
progress = self.settings.get("progress")
progress.disable_cancel()
progress.set_multiple(len(models), "Scaling model")
for model in models:
new_x, new_y, new_z = ((model.maxx + model.minx) / 2,
(model.maxy + model.miny) / 2,
(model.maxz + model.minz) / 2)
model.scale(factor, callback=progress.update)
cur_x, cur_y, cur_z = self._get_model_center()
model.shift(new_x - cur_x, new_y - cur_y,
new_z - cur_z,
callback=progress.update)
progress.update_multiple()
progress.finish()
if self.gui.get_object("UnitChangeProcesses").get_active():
# scale the process settings
for process in self.settings.get("processes"):
for key in ("MaterialAllowanceControl",
"MaxStepDownControl",
"EngraveOffsetControl"):
process[key] *= factor
if self.gui.get_object("UnitChangeBounds").get_active():
# scale the boundaries and keep their center
for bounds in self.settings.get("bounds"):
low, high = bounds.get_bounds()
if bounds.get_type() == Bounds.TYPE_FIXED_MARGIN:
low[0] *= factor
high[0] *= factor
low[1] *= factor
high[1] *= factor
low[2] *= factor
high[2] *= factor
bounds.set_bounds(low, high)
elif bounds.get_type() == Bounds.TYPE_CUSTOM:
center = [0, 0, 0]
for i in range(3):
center[i] = (high[i] + low[i]) / 2
for i in range(3):
low[i] = center[i] + (low[i] - center[i]) * factor
high[i] = center[i] + (high[i] - center[i]) * factor
bounds.set_bounds(low, high)
elif bounds.get_type() == Bounds.TYPE_RELATIVE_MARGIN:
# no need to change relative margins
pass
if self.gui.get_object("UnitChangeTools").get_active():
# scale all tool dimensions
for tool in self.settings.get("tools"):
for key in ("tool_radius", "torus_radius"):
# TODO: fix this invalid access
tool[key] *= factor
self.unit_change_window.hide()
# store the current unit (for the next run of this function)
self._last_unit = new_unit
# update all labels containing the unit size
self.update_unit_labels()
# redraw the model
self.settings.emit_event("model-change-after")
def update_unit_labels(self, widget=None, data=None):
# don't use the "unit" setting, since we need the plural of "inch"
if self.settings.get("unit") == "mm":
base_unit = "mm"
else:
base_unit = "inches"
for key in ("SpeedUnit2", ):
self.gui.get_object(key).set_text("%s/minute" % base_unit)
for key in ("LengthUnit1", "LengthUnit2", "LengthUnitTouchOffHeight"):
self.gui.get_object(key).set_text(base_unit)
def get_filename_with_suffix(self, filename, type_filter): def get_filename_with_suffix(self, filename, type_filter):
# use the first extension provided by the filter as the default # use the first extension provided by the filter as the default
if isinstance(type_filter[0], (tuple, list)): if isinstance(type_filter[0], (tuple, list)):
......
...@@ -43,6 +43,7 @@ class OpenGLViewModel(pycam.Plugins.PluginBase): ...@@ -43,6 +43,7 @@ class OpenGLViewModel(pycam.Plugins.PluginBase):
return True return True
def draw_model(self): def draw_model(self):
GL = self._GL
if self.core.get("show_model") \ if self.core.get("show_model") \
and not (self.core.get("show_simulation") \ and not (self.core.get("show_simulation") \
and self.core.get("simulation_toolpath_moves")): and self.core.get("simulation_toolpath_moves")):
...@@ -50,9 +51,13 @@ class OpenGLViewModel(pycam.Plugins.PluginBase): ...@@ -50,9 +51,13 @@ class OpenGLViewModel(pycam.Plugins.PluginBase):
color_str = self.core.get("models").get_attr(model, "color") color_str = self.core.get("models").get_attr(model, "color")
alpha = self.core.get("models").get_attr(model, "alpha") alpha = self.core.get("models").get_attr(model, "alpha")
col = self._gtk.gdk.color_parse(color_str) col = self._gtk.gdk.color_parse(color_str)
self._GL.glColor4f(col.red / GTK_COLOR_MAX, col.green / GTK_COLOR_MAX, color = (col.red / GTK_COLOR_MAX, col.green / GTK_COLOR_MAX,
col.blue / GTK_COLOR_MAX, alpha / GTK_COLOR_MAX) col.blue / GTK_COLOR_MAX, alpha / GTK_COLOR_MAX)
GL.glColor4f(*color)
# reset the material color
GL.glMaterial(GL.GL_FRONT_AND_BACK,
GL.GL_AMBIENT_AND_DIFFUSE, color)
# we need to wait until the color change is active # we need to wait until the color change is active
self._GL.glFinish() GL.glFinish()
model.to_OpenGL(show_directions=self.core.get("show_directions")) model.to_OpenGL(show_directions=self.core.get("show_directions"))
...@@ -239,7 +239,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -239,7 +239,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self.reset_view() self.reset_view()
else: else:
# the window is just hidden # the window is just hidden
self.view3d.show() self.show()
else: else:
self.hide() self.hide()
......
...@@ -28,8 +28,16 @@ class ToolpathGrid(pycam.Plugins.PluginBase): ...@@ -28,8 +28,16 @@ class ToolpathGrid(pycam.Plugins.PluginBase):
UI_FILE = "toolpath_grid.ui" UI_FILE = "toolpath_grid.ui"
def setup(self):
if self.gui:
for objname in ("GridYCount", "GridXCount", "GridYDistance",
"GridXDistance"):
self.gui.get_object(objname).connect("value-changed",
self.update_toolpath_grid_window)
# TODO: add a button to the toolpath action UI
return True
def update_toolpath_grid_window(self, widget=None): def update_toolpath_grid_window(self, widget=None):
return False
data = self._toolpath_for_grid_data data = self._toolpath_for_grid_data
x_dim = data["maxx"] - data["minx"] x_dim = data["maxx"] - data["minx"]
y_dim = data["maxy"] - data["miny"] y_dim = data["maxy"] - data["miny"]
...@@ -43,10 +51,6 @@ class ToolpathGrid(pycam.Plugins.PluginBase): ...@@ -43,10 +51,6 @@ class ToolpathGrid(pycam.Plugins.PluginBase):
(x_width, self.settings.get("unit"))) (x_width, self.settings.get("unit")))
self.gui.get_object("LabelGridYWidth").set_label("%g%s" % \ self.gui.get_object("LabelGridYWidth").set_label("%g%s" % \
(y_width, self.settings.get("unit"))) (y_width, self.settings.get("unit")))
for objname in ("GridYCount", "GridXCount", "GridYDistance",
"GridXDistance"):
self.gui.get_object(objname).connect("value-changed",
self.update_toolpath_grid_window)
def create_toolpath_grid(self, toolpath): def create_toolpath_grid(self, toolpath):
dialog = self.gui.get_object("ToolpathGridDialog") dialog = self.gui.get_object("ToolpathGridDialog")
...@@ -80,6 +84,7 @@ class ToolpathGrid(pycam.Plugins.PluginBase): ...@@ -80,6 +84,7 @@ class ToolpathGrid(pycam.Plugins.PluginBase):
toolpath.toolpath_settings) toolpath.toolpath_settings)
toolpath.visible = False toolpath.visible = False
new_toolpath.visible = True new_toolpath.visible = True
# TODO: emit "toolpath-list-changed"
self.toolpath.append(new_toolpath) self.toolpath.append(new_toolpath)
self.update_toolpath_table() self.update_toolpath_table()
dialog.hide() dialog.hide()
......
...@@ -152,33 +152,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase): ...@@ -152,33 +152,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self.core.get("gcode_safety_height"))) self.core.get("gcode_safety_height")))
cell.set_property("text", text) cell.set_property("text", text)
def _update_toolpath_table(self, new_index=None, skip_model_update=False):
self._update_widgets()
# reset the model data and the selection
if new_index is None:
# keep the old selection - this may return "None" if nothing is selected
new_index = self._treeview_get_active_index(self.toolpath_table, self.toolpath)
if not skip_model_update:
# update the TreeModel data
self._treemodel.clear()
# columns: name, visible, drill_size, drill_id, allowance, speed, feedrate
for index in range(len(self.toolpath)):
tp = self.toolpath[index]
toolpath_settings = tp.get_toolpath_settings()
tool = toolpath_settings.get_tool_settings()
process = toolpath_settings.get_process_settings()
items = (index, tp.name, tp.visible, tool["tool_radius"],
tool["id"], process["material_allowance"],
tool["speed"], tool["feedrate"],
get_time_string(tp.get_machine_time(
self.core.get("gcode_safety_height"))))
self._treemodel.append(items)
if not new_index is None:
self._treeview_set_active_index(self.toolpath_table, new_index)
# enable/disable the modification buttons
self.gui.get_object("toolpath_simulate").set_sensitive(not new_index is None)
self.gui.get_object("ToolpathGrid").set_sensitive(not new_index is None)
def save_toolpath(self, widget=None, only_visible=False): def save_toolpath(self, widget=None, only_visible=False):
if only_visible: if only_visible:
toolpaths = self.get_selected() toolpaths = self.get_selected()
......
# -*- 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 Toolpaths(pycam.Plugins.PluginBase):
UI_FILE = "units.ui"
def setup(self):
if self.gui:
unit_pref_box = self.gui.get_object("UnitPrefBox")
unit_pref_box.unparent()
self.core.register_ui("preferences_general", "Units",
unit_pref_box, 20)
# unit control (mm/inch)
unit_field = self.gui.get_object("unit_control")
unit_field.connect("changed", self.change_unit_init)
def set_unit(text):
unit_field.set_active(0 if text == "mm" else 1)
self._last_unit = text
self.core.add_item("unit", unit_field.get_active_text, set_unit)
self.gui.get_object("UnitChangeSelectAll").connect("clicked",
self.change_unit_set_selection, True)
self.gui.get_object("UnitChangeSelectNone").connect("clicked",
self.change_unit_set_selection, False)
# "unit change" window
self.unit_change_window = self.gui.get_object("UnitChangeDialog")
self.gui.get_object("UnitChangeApply").connect("clicked", self.change_unit_apply)
self.unit_change_window.connect("delete_event", self.change_unit_apply, False)
return True
def teardown(self):
self.core.unregister_ui("preferences_general",
self.gui.get_object("UnitPrefBox"))
def change_unit_init(self, widget=None):
new_unit = self.gui.get_object("unit_control").get_active_text()
if self._last_unit is None:
# first initialization
self._last_unit = new_unit
return
if self._last_unit == new_unit:
# don't show the dialog if the conversion would make no sense
return
# show a dialog asking for a possible model scaling due to the unit change
self.unit_change_window.show()
def change_unit_set_selection(self, widget, state):
for key in ("UnitChangeModel", "UnitChangeProcesses", "UnitChangeTools",
"UnitChangeBounds"):
self.gui.get_object(key).set_active(state)
def change_unit_apply(self, widget=None, data=None, apply_scale=True):
# TODO: move tool/process/task related code to these plugins
new_unit = self.gui.get_object("unit_control").get_active_text()
factors = {
("mm", "inch"): 1 / 25.4,
("inch", "mm"): 25.4,
}
conversion = (self._last_unit, new_unit)
if conversion in factors.keys():
factor = factors[conversion]
if apply_scale:
if self.gui.get_object("UnitChangeModel").get_active():
# transform the model if it is selected
# keep the original center of the model
self.core.emit_event("model-change-before")
models = self.core.get("models")
progress = self.core.get("progress")
progress.disable_cancel()
progress.set_multiple(len(models), "Scaling model")
for model in models:
new_x, new_y, new_z = ((model.maxx + model.minx) / 2,
(model.maxy + model.miny) / 2,
(model.maxz + model.minz) / 2)
model.scale(factor, callback=progress.update)
cur_x, cur_y, cur_z = self._get_model_center()
model.shift(new_x - cur_x, new_y - cur_y,
new_z - cur_z,
callback=progress.update)
progress.update_multiple()
progress.finish()
if self.gui.get_object("UnitChangeProcesses").get_active():
# scale the process settings
for process in self.core.get("processes"):
for key in ("MaterialAllowanceControl",
"MaxStepDownControl",
"EngraveOffsetControl"):
process[key] *= factor
if self.gui.get_object("UnitChangeBounds").get_active():
# scale the boundaries and keep their center
for bounds in self.core.get("bounds"):
low, high = bounds.get_bounds()
if bounds.get_type() == Bounds.TYPE_FIXED_MARGIN:
low[0] *= factor
high[0] *= factor
low[1] *= factor
high[1] *= factor
low[2] *= factor
high[2] *= factor
bounds.set_bounds(low, high)
elif bounds.get_type() == Bounds.TYPE_CUSTOM:
center = [0, 0, 0]
for i in range(3):
center[i] = (high[i] + low[i]) / 2
for i in range(3):
low[i] = center[i] + (low[i] - center[i]) * factor
high[i] = center[i] + (high[i] - center[i]) * factor
bounds.set_bounds(low, high)
elif bounds.get_type() == Bounds.TYPE_RELATIVE_MARGIN:
# no need to change relative margins
pass
if self.gui.get_object("UnitChangeTools").get_active():
# scale all tool dimensions
for tool in self.core.get("tools"):
for key in ("tool_radius", "torus_radius"):
# TODO: fix this invalid access
tool[key] *= factor
self.unit_change_window.hide()
# store the current unit (for the next run of this function)
self._last_unit = new_unit
# update all labels containing the unit size
self.update_unit_labels()
# redraw the model
self.core.emit_event("model-change-after")
def update_unit_labels(self, widget=None, data=None):
# don't use the "unit" setting, since we need the plural of "inch"
if self.core.get("unit") == "mm":
base_unit = "mm"
else:
base_unit = "inches"
for key in ("SpeedUnit2", ):
self.gui.get_object(key).set_text("%s/minute" % base_unit)
for key in ("LengthUnit1", "LengthUnit2", "LengthUnitTouchOffHeight"):
self.gui.get_object(key).set_text(base_unit)
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