Commit ed791695 authored by sumpfralle's avatar sumpfralle

added preview of support models

fixed distributed support models
add multiple seperate support models 
change default color of new support models
renamed configuration settings:
* "show_support_grid" -> "show_support_preview"
* "color_support_grid" -> "color_support_preview"


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1212 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 6797b868
......@@ -67,7 +67,7 @@ PREFERENCES_DEFAULTS = {
"unit": "mm",
"default_task_settings_file": "",
"show_model": True,
"show_support_grid": True,
"show_support_preview": True,
"show_axes": True,
"show_dimensions": True,
"show_bounding_box": True,
......@@ -76,7 +76,7 @@ PREFERENCES_DEFAULTS = {
"show_directions": False,
"color_background": {"red": 0.0, "green": 0.0, "blue": 0.0, "alpha": 1.0},
"color_model": {"red": 0.5, "green": 0.5, "blue": 1.0, "alpha": 1.0},
"color_support_grid": {"red": 0.8, "green": 0.8, "blue": 0.3, "alpha": 1.0},
"color_support_preview": {"red": 0.8, "green": 0.8, "blue": 0.3, "alpha": 1.0},
"color_bounding_box": {"red": 0.3, "green": 0.3, "blue": 0.3, "alpha": 1.0},
"color_cutter": {"red": 1.0, "green": 0.2, "blue": 0.2, "alpha": 1.0},
"color_toolpath_cut": {"red": 1.0, "green": 0.5, "blue": 0.5, "alpha": 1.0},
......
......@@ -22,6 +22,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Plugins
import pycam.Geometry.Model
class ModelSupport(pycam.Plugins.PluginBase):
......@@ -40,7 +41,7 @@ class ModelSupport(pycam.Plugins.PluginBase):
"SupportGridTypesControl")
self._gtk_handlers = []
self._gtk_handlers.append((support_model_type_selector, "changed",
self._support_model_changed))
"support-model-changed"))
def add_support_type(obj, name):
types_model = support_model_type_selector.get_model()
types_model.append((obj, name))
......@@ -81,12 +82,12 @@ class ModelSupport(pycam.Plugins.PluginBase):
set_support_model_type)
grid_thickness = self.gui.get_object("SupportGridThickness")
self._gtk_handlers.append((grid_thickness, "value-changed",
self._support_model_changed))
"support-model-changed"))
self.core.add_item("support_grid_thickness",
grid_thickness.get_value, grid_thickness.set_value)
grid_height = self.gui.get_object("SupportGridHeight")
self._gtk_handlers.append((grid_height, "value-changed",
self._support_model_changed))
"support-model-changed"))
self.core.add_item("support_grid_height",
grid_height.get_value, grid_height.set_value)
self._gtk_handlers.append((
......@@ -96,11 +97,13 @@ class ModelSupport(pycam.Plugins.PluginBase):
self.core.set("support_grid_thickness", 0.5)
self.core.set("support_grid_height", 0.5)
self.core.set("support_grid_type", "none")
self.core.register_chain("get_draw_dimension",
self.get_draw_dimension)
# handlers
self._event_handlers = (
("model-change-after", self._support_model_changed),
("bounds-changed", self._support_model_changed),
("model-selection-changed", self._update_widgets),
("model-change-after", "support-model-changed"),
("bounds-changed", "support-model-changed"),
("model-selection-changed", "support-model-changed"),
("support-model-changed", self.update_support_model))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
......@@ -114,25 +117,64 @@ class ModelSupport(pycam.Plugins.PluginBase):
self.core.unregister_ui("support_model_type_selector", "none")
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.unregister_chain("get_draw_dimension",
self.get_draw_dimension)
def _update_widgets(self):
if self.core.get("models").get_selected():
models = self.core.get("models").get_selected()
if models:
self._support_frame.show()
else:
self._support_frame.hide()
def _support_model_changed(self, widget=None):
self.core.emit_event("support-model-changed")
grid_type = self.core.get("support_model_type")
details_box = self.gui.get_object("SupportGridDetailsBox")
# show/hide the common details (width/height)
# enable/disable the "create support model" button
create_button = self.gui.get_object("CreateSupportModel")
if grid_type == "none":
details_box.hide()
create_button.set_sensitive(False)
else:
details_box.show()
create_button.set_sensitive(True)
def _add_support_model(self, widget=None):
model = self.core.get("current_support_model")
if model:
models = self.core.get("current_support_models")
for model in models:
self.core.get("models").add_model(model,
name_template="Support model #%d")
name_template="Support model #%d",
color=self.core.get("color_support_preview"))
# Disable the support model type -> avoid confusing visualization.
# (this essentially removes the support grid from the 3D view)
self.gui.get_object("SupportGridTypesControl").set_active(0)
def get_draw_dimension(self, low, high):
if not self.core.get("show_support_preview"):
return
mlow, mhigh = pycam.Geometry.Model.get_combined_bounds(self.core.get(
"current_support_models"))
if None in mlow or None in mhigh:
return
for index in range(3):
if (low[index] is None) or (mlow[index] < low[index]):
low[index] = mlow[index]
if (high[index] is None) or (mhigh[index] > high[index]):
high[index] = mhigh[index]
def update_support_model(self, widget=None):
old_support_models = self.core.get("current_support_models")
selected_models = self.core.get("models").get_selected()
grid_type = self.core.get("support_model_type")
if grid_type == "none":
self.core.set("current_support_model", None)
new_support_models = []
if (grid_type == "none") or (not selected_models):
new_support_models = []
else:
# update the support model
self.core.call_chain("get_support_models", selected_models,
new_support_models)
if old_support_models != new_support_models:
self.core.set("current_support_models", new_support_models)
self.core.emit_event("visual-item-updated")
# show/hide controls
self._update_widgets()
......@@ -43,27 +43,28 @@ class ModelSupportDistributed(pycam.Plugins.PluginBase):
support_expander)
grid_length = self.gui.get_object("SupportGridLength")
self._gtk_handlers.append((grid_length, "value-changed",
self.update_support_model))
"support-model-changed"))
self.core.add_item("support_grid_length",
grid_length.get_value, grid_length.set_value)
average_distance = self.gui.get_object("GridAverageDistance")
self._gtk_handlers.append((average_distance, "value-changed",
self.update_support_model))
"support-model-changed"))
self.core.add_item("support_grid_average_distance",
average_distance.get_value, average_distance.set_value)
minimum_bridges = self.gui.get_object("GridMinBridgesPerPolygon")
self._gtk_handlers.append((minimum_bridges, "value-changed",
self.update_support_model))
"support-model-changed"))
self.core.add_item("support_grid_minimum_bridges",
minimum_bridges.get_value, minimum_bridges.set_value)
# TODO: remove these public settings
self.core.set("support_grid_average_distance", 30)
self.core.set("support_grid_minimum_bridges", 2)
self.core.set("support_grid_length", 5)
self.core.register_chain("get_support_models",
self._get_support_models)
# register handlers
self._event_handlers = (
("support-model-changed", self.update_support_controls),
("support-model-changed", self.update_support_model))
("support-model-changed", self.update_support_controls),)
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
return True
......@@ -72,6 +73,8 @@ class ModelSupportDistributed(pycam.Plugins.PluginBase):
if self.gui:
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.unregister_chain("get_support_models",
self._get_support_models)
self.core.unregister_ui("support_model_type_selector",
"distributed_edges")
self.core.unregister_ui("support_model_type_selector",
......@@ -86,35 +89,27 @@ class ModelSupportDistributed(pycam.Plugins.PluginBase):
else:
self.gui.get_object("DistributedSupportExpander").hide()
def update_support_model(self, widget=None):
model = self.core.get("model")
if not model:
return
def _get_support_models(self, models, support_models):
grid_type = self.core.get("support_model_type")
support_model = None
# TODO: completely broken code
if grid_type in ("distributed_edges", "distributed_corners"):
s = self.core
if (s.get("support_grid_thickness") > 0) \
and (s.get("support_grid_height") > 0) \
and (s.get("support_grid_average_distance") > 0) \
and (s.get("support_grid_minimum_bridges") > 0):
# get the minimum z value of the bounding box
bounds = s.get("current_bounds")
if bounds:
minz = bounds.get_absolute_limits(
reference=model.model.get_bounds())[0][2]
while models:
model = models.pop(0)
if model.model and (s.get("support_grid_thickness") > 0) \
and (s.get("support_grid_height") > 0) \
and (s.get("support_grid_average_distance") > 0) \
and (s.get("support_grid_minimum_bridges") > 0):
# get the minimum z value of the bounding box
minz = model.model.minz
corner_start = (grid_type == "distributed_corners")
support_model = pycam.Toolpath.SupportGrid.get_support_distributed(
s.get("model"), minz,
model.model, minz,
s.get("support_grid_average_distance"),
s.get("support_grid_minimum_bridges"),
s.get("support_grid_thickness"),
s.get("support_grid_height"),
s.get("support_grid_length"),
bounds.get_referenced_bounds(s.get("model").get_bounds()),
start_at_corners=corner_start)
if support_model != self.core.get("current_support_model"):
self.core.set("current_support_model", support_model)
self.core.emit_event("visual-item-updated")
if support_model:
support_models.append(support_model)
......@@ -126,31 +126,36 @@ class ModelSupportGrid(pycam.Plugins.PluginBase):
adjustments[index] = value
# TODO: remove these public settings
self.core.add_item("support_grid_adjustment_value",
get_set_grid_adjustment_value, get_set_grid_adjustment_value)
get_set_grid_adjustment_value,
get_set_grid_adjustment_value)
grid_distance_square.set_active(True)
self.core.set("support_grid_distance_x", 10.0)
self.core.register_chain("get_support_models",
self._get_support_models)
# handlers
self._event_handlers = ((
("support-model-changed", self.update_support_controls),
("support-model-changed", self.update_support_model)))
self._event_handlers = (
("support-model-changed", self.update_support_controls), )
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
return True
def teardown(self):
if self.gui:
self.core.unregister_chain("get_support_models",
self._get_support_models)
self.core.unregister_ui("support_model_type_selector", "grid")
self.core.unregister_ui("support_model_settings",
self.gui.get_object("SupportModelGridBox"))
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
def update_support_model(self, widget=None):
def _get_support_models(self, models, support_models):
grid_type = self.core.get("support_model_type")
if grid_type == "grid":
if (grid_type == "grid") and models:
# we create exactly one support model for all input models
s = self.core
support_grid = None
low, high = self._get_bounds()
low, high = self._get_bounds(models)
if (s.get("support_grid_thickness") > 0) \
and ((s.get("support_grid_distance_x") > 0) \
or (s.get("support_grid_distance_y") > 0)) \
......@@ -171,8 +176,10 @@ class ModelSupportGrid(pycam.Plugins.PluginBase):
offset_y=s.get("support_grid_offset_y"),
adjustments_x=self.grid_adjustments_x,
adjustments_y=self.grid_adjustments_y)
self.core.set("current_support_model", support_grid)
self.core.emit_event("visual-item-updated")
# all models are processed -> wipe the input list
while models:
models.pop()
support_models.append(support_grid)
def update_support_controls(self, widget=None):
grid_type = self.core.get("support_model_type")
......@@ -287,8 +294,10 @@ class ModelSupportGrid(pycam.Plugins.PluginBase):
else:
self.grid_adjustment_selector.set_active(-1)
def _get_bounds(self):
models = [m.model for m in self.core.get("models").get_selected()]
def _get_bounds(self, models=None):
if not models:
models = self.core.get("models").get_selected()
models = [m.model for m in models]
low, high = pycam.Geometry.Model.get_combined_bounds(models)
if None in low or None in high:
return [0, 0, 0], [0, 0, 0]
......
# -*- 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 OpenGLViewSupportModelPreview(pycam.Plugins.PluginBase):
DEPENDS = ["OpenGLWindow", "OpenGLViewModel"]
CATEGORIES = ["Visualization", "OpenGL", "Support bridges"]
def setup(self):
import OpenGL.GL
import OpenGL.GLUT
self._GL = OpenGL.GL
self.core.register_event("visualize-items", self.draw_support_preview)
self.core.get("register_display_item")("show_support_preview", "Show Support Model Preview", 30)
self.core.get("register_color")("color_support_preview", "Support model", 30)
self.core.emit_event("visual-item-updated")
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_support_preview)
self.core.get("unregister_display_item")("show_support_preview")
self.core.get("unregister_color")("color_support_preview")
self.core.emit_event("visual-item-updated")
def draw_support_preview(self):
if not self.core.get("show_support_preview"):
return
models = self.core.get("current_support_models")[:]
if not models:
return
GL = self._GL
# disable lighting
if self.core.get("view_light"):
GL.glDisable(GL.GL_LIGHTING)
# show a wireframe
if self.core.get("view_polygon"):
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
# change the color
col = self.core.get("color_support_preview")
color = (col["red"], col["green"], col["blue"], col["alpha"])
GL.glColor4f(*color)
# we need to wait until the color change is active
GL.glFinish()
# draw the models
self.core.call_chain("draw_models", models)
# enable lighting again
if self.core.get("view_light"):
GL.glEnable(GL.GL_LIGHTING)
# enable polygon fill mode again
if self.core.get("view_polygon"):
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
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