Commit 8a7c529b authored by sumpfralle's avatar sumpfralle

added the import of some tool, process and task templates by default


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@273 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent fc7cf235
...@@ -549,8 +549,10 @@ class ProjectGui: ...@@ -549,8 +549,10 @@ class ProjectGui:
self.gui.get_object(objname).connect("changed", self.handle_process_settings_change) self.gui.get_object(objname).connect("changed", self.handle_process_settings_change)
self.gui.get_object("ProcessSettingName").connect("changed", self.handle_process_settings_change) self.gui.get_object("ProcessSettingName").connect("changed", self.handle_process_settings_change)
# load a processing configuration object # load a processing configuration object
self.processing_settings = pycam.Gui.Settings.ProcessingSettings(self.settings) default_settings = pycam.Gui.Settings.SettingsManager()
self.process_settings_list = [] self.tool_list.extend(default_settings.get_tools())
self.process_settings_list.extend(default_settings.get_processes())
self.task_list.extend(default_settings.get_tasks())
self.process_table = self.gui.get_object("ProcessListTable") self.process_table = self.gui.get_object("ProcessListTable")
self.process_editor_table = self.gui.get_object("ProcessEditorWindowTable") self.process_editor_table = self.gui.get_object("ProcessEditorWindowTable")
self.process_editor_table.get_selection().connect("changed", self.switch_process_table_selection) self.process_editor_table.get_selection().connect("changed", self.switch_process_table_selection)
...@@ -626,7 +628,6 @@ class ProjectGui: ...@@ -626,7 +628,6 @@ class ProjectGui:
window_box.pack_start(self.menubar, False) window_box.pack_start(self.menubar, False)
window_box.reorder_child(self.menubar, 0) window_box.reorder_child(self.menubar, 0)
# some more initialization # some more initialization
self.processing_settings.enable_config()
self.update_toolpath_table() self.update_toolpath_table()
self.update_tool_table() self.update_tool_table()
self.update_tool_controls() self.update_tool_controls()
...@@ -673,9 +674,10 @@ class ProjectGui: ...@@ -673,9 +674,10 @@ class ProjectGui:
self.view3d.glsetup() self.view3d.glsetup()
self.view3d.paint() self.view3d.paint()
def get_physics(self, cutter): def get_physics(self, cutter, material_allowance):
if self.settings.get("enable_ode"): if self.settings.get("enable_ode"):
self._physics_cache = ode_objects.generate_physics(self.settings, cutter, self._physics_cache) self._physics_cache = ode_objects.generate_physics(self.model, cutter,
self._physics_cache, material_allowance)
else: else:
self._physics_cache = None self._physics_cache = None
return self._physics_cache return self._physics_cache
...@@ -1033,9 +1035,13 @@ class ProjectGui: ...@@ -1033,9 +1035,13 @@ class ProjectGui:
@gui_activity_guard @gui_activity_guard
def switch_tool_editor_table_selection(self, widget=None, data=None): def switch_tool_editor_table_selection(self, widget=None, data=None):
new_index = self._treeview_get_active_index(self.tool_editor_table, self.tool_list) new_index = self._treeview_get_active_index(self.tool_editor_table, self.tool_list)
# hide all controls if no process is defined
if not new_index is None: if not new_index is None:
self.gui.get_object("ToolSettingsControlsBox").show()
self._put_tool_settings_to_gui(self.tool_list[new_index]) self._put_tool_settings_to_gui(self.tool_list[new_index])
self.update_tool_controls() self.update_tool_controls()
else:
self.gui.get_object("ToolSettingsControlsBox").hide()
@gui_activity_guard @gui_activity_guard
def _tool_editor_button_event(self, widget, data, action=None): def _tool_editor_button_event(self, widget, data, action=None):
...@@ -1373,8 +1379,11 @@ class ProjectGui: ...@@ -1373,8 +1379,11 @@ class ProjectGui:
def switch_process_table_selection(self, widget=None, data=None): def switch_process_table_selection(self, widget=None, data=None):
new_index = self._treeview_get_active_index(self.process_editor_table, self.process_settings_list) new_index = self._treeview_get_active_index(self.process_editor_table, self.process_settings_list)
if not new_index is None: if not new_index is None:
self.gui.get_object("ProcessSettingsControlsBox").show()
self._put_process_settings_to_gui(self.process_settings_list[new_index]) self._put_process_settings_to_gui(self.process_settings_list[new_index])
self.update_process_table() self.update_process_table()
else:
self.gui.get_object("ProcessSettingsControlsBox").hide()
@gui_activity_guard @gui_activity_guard
def handle_process_table_event(self, widget, data, action=None): def handle_process_table_event(self, widget, data, action=None):
...@@ -1491,7 +1500,7 @@ class ProjectGui: ...@@ -1491,7 +1500,7 @@ class ProjectGui:
def get_pathgenerator_instance(self, cutter, process_settings): def get_pathgenerator_instance(self, cutter, process_settings):
pathgenerator = process_settings["path_generator"] pathgenerator = process_settings["path_generator"]
pathprocessor = process_settings["path_postprocessor"] pathprocessor = process_settings["path_postprocessor"]
physics = self.get_physics(cutter) physics = self.get_physics(cutter, process_settings["material_allowance"])
if pathgenerator == "DropCutter": if pathgenerator == "DropCutter":
if pathprocessor == "ZigZagCutter": if pathprocessor == "ZigZagCutter":
processor = pycam.PathProcessors.PathAccumulator(zigzag=True) processor = pycam.PathProcessors.PathAccumulator(zigzag=True)
......
...@@ -54,83 +54,119 @@ class Settings: ...@@ -54,83 +54,119 @@ class Settings:
return str(result) return str(result)
class ProcessingSettings: class SettingsManager:
DEFAULT_CONFIG = """ DEFAULT_CONFIG = """
[DEFAULT] [ToolDefault]
cutter_shape: SphericalCutter
path_direction: x
path_generator: DropCutter
path_postprocessor: PathAccumulator
# the dimensions of the bounding box are disabled to keep the previous values
#minx: -7
#miny: -7
#minz: 0
#maxx: 7
#maxy: 7
#maxz: 3
tool_radius: 1.0
torus_radius: 0.25 torus_radius: 0.25
speed: 1000 feedrate: 1000
feedrate: 200 speed: 200
material_allowance: 0.0
overlap: 20 [Tool0]
step_down: 1.0 name: Cylindrical (3 inch)
# default sort weight is low (thus new items will appear above the defaults) shape: CylindricalCutter
sort_weight: 0 tool_radius: 3
[Tool1]
name: Spherical (0.1 inch)
shape: SphericalCutter
tool_radius: 1
[Tool2]
name: Toroidal (2 inch)
shape: ToroidalCutter
tool_radius: 2
torus_radius: 0.2
[ProcessDefault]
path_direction: x
safety_height: 5
step_down: 1
[Rough] [Process0]
sort_weight: 90 name: Rough
cutter_shape: CylindricalCutter
path_generator: PushCutter path_generator: PushCutter
path_postprocessor: PolygonCutter path_postprocessor: PolygonCutter
tool_radius: 1.0 material_allowance: 0.5
material_allowance: 1.0 step_down: 0.8
overlap: 0
[Process1]
[Semi-finish] name: Semi-finish
sort_weight: 91
cutter_shape: ToroidalCutter
path_generator: PushCutter path_generator: PushCutter
path_postprocessor: ContourCutter path_postprocessor: ContourCutter
tool_radius: 0.5 material_allowance: 0.2
material_allowance: 0.3 step_down: 0.5
overlap: 20
[Finish] [Process2]
sort_weight: 92 name: Finish
cutter_shape: SphericalCutter
path_generator: DropCutter path_generator: DropCutter
path_postprocessor: ZigZagCutter path_postprocessor: ZigZagCutter
tool_radius: 0.1
material_allowance: 0.0 material_allowance: 0.0
overlap: 60
[TaskDefault]
enabled: 1
[Task0]
tool: 0
process: 0
[Task1]
tool: 2
process: 1
[Task2]
tool: 1
process: 2
""" """
SETTING_TYPES = { SETTING_TYPES = {
"cutter_shape": str, "name": str,
"shape": str,
"tool_radius": float,
"torus_radius": float,
"speed": float,
"feedrate": float,
"path_direction": str, "path_direction": str,
"path_generator": str, "path_generator": str,
"path_postprocessor": str, "path_postprocessor": str,
"safety_height": float,
"material_allowance": float,
"overlap": float,
"step_down": float,
"tool": object,
"process": object,
"enabled": bool,
"minx": float, "minx": float,
"miny": float, "miny": float,
"minz": float, "minz": float,
"maxx": float, "maxx": float,
"maxy": float, "maxy": float,
"maxz": float, "maxz": float,
"tool_radius": float,
"torus_radius": float,
"speed": float,
"feedrate": float,
"material_allowance": float,
"overlap": float,
"step_down": float,
} }
def __init__(self, settings): CATEGORY_KEYS = {
self.settings = settings "tool": ("name", "shape", "tool_radius", "torus_radius", "feedrate", "speed"),
"process": ("name", "path_generator", "path_postprocessor", "path_direction",
"safety_height", "material_allowance", "overlap", "step_down"),
"task": ("tool", "process", "enabled"),
}
SECTION_PREFIXES = {
"tool": "Tool",
"process": "Process",
"task": "Task",
}
def __init__(self):
self.config = None self.config = None
self._cache = {}
self.reset() self.reset()
def reset(self, config_text=None): def reset(self, config_text=None):
self._cache = {}
self.config = ConfigParser.SafeConfigParser() self.config = ConfigParser.SafeConfigParser()
if config_text is None: if config_text is None:
config_text = StringIO.StringIO(self.DEFAULT_CONFIG) config_text = StringIO.StringIO(self.DEFAULT_CONFIG)
...@@ -165,43 +201,47 @@ material_allowance: 0.0 ...@@ -165,43 +201,47 @@ material_allowance: 0.0
return False return False
return True return True
def enable_config(self, section="DEFAULT"): def get_tools(self):
for key, value_type in self.SETTING_TYPES.items(): return self._get_category_items("tool")
def get_processes(self):
return self._get_category_items("process")
def get_tasks(self):
return self._get_category_items("task")
def _get_category_items(self, type_name):
if not self._cache.has_key(type_name):
item_list = []
index = 0
prefix = self.SECTION_PREFIXES[type_name]
current_section_name = "%s%d" % (prefix, index)
while current_section_name in self.config.sections():
item = {}
for key in self.CATEGORY_KEYS[type_name]:
value_type = self.SETTING_TYPES[key]
try: try:
value = value_type(self.config.get(section, key)) value_raw = self.config.get(current_section_name, key)
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
# we can safely ignore it and keep the original
try: try:
value = value_type(self.config.get("DEFAULT", key)) value_raw = self.config.get(prefix + "Default", key)
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
value = None value_raw = None
except ValueError, err_msg: if not value_raw is None:
print >> sys.stderr, "Invalid config value for '%s = %s': %s" % (key, self.config.get(section, key), err_msg) try:
if value_type == object:
# try to get the referenced object
value = self._get_category_items(key)[int(value_raw)]
else:
# just do a simple type cast
value = value_type(value_raw)
except (ValueError, IndexError):
value = None value = None
if not value is None: if not value is None:
self.settings.set(key, value) item[key] = value
item_list.append(item)
def get_config_list(self): index += 1
items = self.config.sections()[:] current_section_name = "%s%d" % (prefix, index)
# sort the list according to "sort_weight" self._cache[type_name] = item_list
def cmp(sec1, sec2): return self._cache[type_name][:]
diff = int(self.config.get(sec1, "sort_weight")) - int(self.config.get(sec2, "sort_weight"))
if diff < 0:
return -1
elif diff == 0:
return 0
else:
return 1
items.sort(cmp)
return items
def store_config(self, section="DEFAULT"):
if not self.config.has_section(section):
self.config.add_section(section)
for key, value_type in self.SETTING_TYPES.items():
self.config.set(section, key, str(self.settings.get(key)))
def delete_config(self, section=None):
if self.config.has_section(section):
self.config.remove_section(section)
...@@ -1016,7 +1016,6 @@ ...@@ -1016,7 +1016,6 @@
<property name="headers_clickable">False</property> <property name="headers_clickable">False</property>
<property name="expander_column">Material Allowance</property> <property name="expander_column">Material Allowance</property>
<property name="enable_search">False</property> <property name="enable_search">False</property>
<property name="search_column">0</property>
<child> <child>
<object class="GtkTreeViewColumn" id="task_enabled"> <object class="GtkTreeViewColumn" id="task_enabled">
<property name="title">Enabled</property> <property name="title">Enabled</property>
...@@ -1232,12 +1231,14 @@ ...@@ -1232,12 +1231,14 @@
<property name="shadow_type">etched-in</property> <property name="shadow_type">etched-in</property>
<child> <child>
<object class="GtkTreeView" id="ToolListTable"> <object class="GtkTreeView" id="ToolListTable">
<property name="width_request">180</property>
<property name="height_request">120</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="model">ToolList</property> <property name="model">ToolList</property>
<property name="headers_clickable">False</property> <property name="headers_clickable">False</property>
<property name="rules_hint">True</property> <property name="rules_hint">True</property>
<property name="search_column">0</property> <property name="enable_search">False</property>
<child> <child>
<object class="GtkTreeViewColumn" id="tool_id_column"> <object class="GtkTreeViewColumn" id="tool_id_column">
<property name="title">ID</property> <property name="title">ID</property>
...@@ -1340,12 +1341,14 @@ This combination is added to the above task list.</property> ...@@ -1340,12 +1341,14 @@ This combination is added to the above task list.</property>
<property name="shadow_type">etched-in</property> <property name="shadow_type">etched-in</property>
<child> <child>
<object class="GtkTreeView" id="ProcessListTable"> <object class="GtkTreeView" id="ProcessListTable">
<property name="width_request">180</property>
<property name="height_request">120</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="model">ProcessList</property> <property name="model">ProcessList</property>
<property name="headers_clickable">False</property> <property name="headers_clickable">False</property>
<property name="rules_hint">True</property> <property name="rules_hint">True</property>
<property name="search_column">0</property> <property name="enable_search">False</property>
<child> <child>
<object class="GtkTreeViewColumn" id="Description1"> <object class="GtkTreeViewColumn" id="Description1">
<property name="title">Description</property> <property name="title">Description</property>
......
...@@ -10,12 +10,12 @@ ShapeCapsule = lambda radius, height: ode.GeomCapsule(None, radius, height - (2 ...@@ -10,12 +10,12 @@ ShapeCapsule = lambda radius, height: ode.GeomCapsule(None, radius, height - (2
_ode_override_state = None _ode_override_state = None
def generate_physics(settings, cutter, physics=None): def generate_physics(model, cutter, physics=None, material_allowance=0.0):
if physics is None: if physics is None:
physics = PhysicalWorld() physics = PhysicalWorld()
physics.reset() physics.reset()
physics.add_mesh((0, 0, 0), settings.get("model").triangles()) physics.add_mesh((0, 0, 0), model.triangles())
shape_info = cutter.get_shape("ODE", additional_distance=settings.get("material_allowance")) shape_info = cutter.get_shape("ODE", additional_distance=material_allowance)
physics.set_drill(shape_info[0], (0.0, 0.0, 0.0)) physics.set_drill(shape_info[0], (0.0, 0.0, 0.0))
return physics return physics
......
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