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