Commit c9cf01f5 authored by sumpfralle's avatar sumpfralle

implemented loading and saving of the new settings


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@274 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 8a7c529b
This diff is collapsed.
...@@ -54,7 +54,7 @@ class Settings: ...@@ -54,7 +54,7 @@ class Settings:
return str(result) return str(result)
class SettingsManager: class SettingsFileManager:
DEFAULT_CONFIG = """ DEFAULT_CONFIG = """
[ToolDefault] [ToolDefault]
...@@ -81,7 +81,6 @@ torus_radius: 0.2 ...@@ -81,7 +81,6 @@ torus_radius: 0.2
[ProcessDefault] [ProcessDefault]
path_direction: x path_direction: x
safety_height: 5 safety_height: 5
step_down: 1
[Process0] [Process0]
name: Rough name: Rough
...@@ -104,6 +103,7 @@ name: Finish ...@@ -104,6 +103,7 @@ name: Finish
path_generator: DropCutter path_generator: DropCutter
path_postprocessor: ZigZagCutter path_postprocessor: ZigZagCutter
material_allowance: 0.0 material_allowance: 0.0
step_down: 1.0
overlap: 60 overlap: 60
[TaskDefault] [TaskDefault]
...@@ -134,7 +134,7 @@ process: 2 ...@@ -134,7 +134,7 @@ process: 2
"path_postprocessor": str, "path_postprocessor": str,
"safety_height": float, "safety_height": float,
"material_allowance": float, "material_allowance": float,
"overlap": float, "overlap": int,
"step_down": float, "step_down": float,
"tool": object, "tool": object,
"process": object, "process": object,
...@@ -160,6 +160,8 @@ process: 2 ...@@ -160,6 +160,8 @@ process: 2
"task": "Task", "task": "Task",
} }
DEFAULT_SUFFIX = "Default"
def __init__(self): def __init__(self):
self.config = None self.config = None
self._cache = {} self._cache = {}
...@@ -191,10 +193,11 @@ process: 2 ...@@ -191,10 +193,11 @@ process: 2
return False return False
return True return True
def write_to_file(self, filename): def write_to_file(self, filename, tools=None, processes=None, tasks=None):
text = self.get_config_text(tools, processes, tasks)
try: try:
fi = open(filename, "w") fi = open(filename, "w")
self.config.write(fi) fi.write(text)
fi.close() fi.close()
except IOError, err_msg: except IOError, err_msg:
print >> sys.stderr, "Failed to write configuration to file (%s): %s" % (filename, err_msg) print >> sys.stderr, "Failed to write configuration to file (%s): %s" % (filename, err_msg)
...@@ -224,7 +227,7 @@ process: 2 ...@@ -224,7 +227,7 @@ process: 2
value_raw = self.config.get(current_section_name, key) value_raw = self.config.get(current_section_name, key)
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
try: try:
value_raw = self.config.get(prefix + "Default", key) value_raw = self.config.get(prefix + self.DEFAULT_SUFFIX, key)
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
value_raw = None value_raw = None
if not value_raw is None: if not value_raw is None:
...@@ -245,3 +248,70 @@ process: 2 ...@@ -245,3 +248,70 @@ process: 2
self._cache[type_name] = item_list self._cache[type_name] = item_list
return self._cache[type_name][:] return self._cache[type_name][:]
def _value_to_string(self, lists, key, value):
value_type = self.SETTING_TYPES[key]
if value_type == bool:
if value:
return "1"
else:
return "0"
elif value_type == object:
try:
return lists[key].index(value)
except IndexError:
return None
else:
return str(value)
def get_config_text(self, tools=None, processes=None, tasks=None):
result = []
if tools is None:
tools = []
if processes is None:
processes = []
if tasks is None:
tasks = []
lists = {}
lists["tool"] = tools
lists["process"] = processes
lists["task"] = tasks
for type_name in lists.keys():
type_list = lists[type_name]
# generate "Default" section
common_keys = []
for key in self.CATEGORY_KEYS[type_name]:
try:
values = [item[key] for item in type_list]
except KeyError, err_msg:
values = None
# check if there are values and if they all have the same value
if values and (values.count(values[0]) == len(values)):
common_keys.append(key)
if common_keys:
section = "[%s%s]" % (self.SECTION_PREFIXES[type_name], self.DEFAULT_SUFFIX)
result.append(section)
for key in common_keys:
value = type_list[0][key]
value_string = self._value_to_string(lists, key, value)
if not value_string is None:
result.append("%s: %s" % (key, value_string))
# add an empty line to separate sections
result.append("")
# generate individual sections
for index in range(len(type_list)):
section = "[%s%d]" % (self.SECTION_PREFIXES[type_name], index)
result.append(section)
item = type_list[index]
for key in self.CATEGORY_KEYS[type_name]:
if key in common_keys:
# skip keys, that are listed in the "Default" section
continue
if item.has_key(key):
value = item[key]
value_string = self._value_to_string(lists, key, value)
if not value_string is None:
result.append("%s: %s" % (key, value_string))
# add an empty line to separate sections
result.append("")
return os.linesep.join(result)
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
<menuitem action="Quit"/> <menuitem action="Quit"/>
</menu> </menu>
<menu action="SettingsMenu"> <menu action="SettingsMenu">
<menuitem action="LoadProcessingTemplates"/> <menuitem action="LoadSettings"/>
<menuitem action="SaveProcessingTemplates"/> <menuitem action="SaveSettings"/>
<menuitem action="SaveAsProcessingTemplates"/> <menuitem action="SaveAsSettings"/>
<separator /> <separator />
<menuitem action="GeneralSettings"/> <menuitem action="GeneralSettings"/>
</menu> </menu>
......
...@@ -2068,18 +2068,18 @@ This combination is added to the above task list.</property> ...@@ -2068,18 +2068,18 @@ This combination is added to the above task list.</property>
<property name="tooltip">Write all current toolpaths to a file.</property> <property name="tooltip">Write all current toolpaths to a file.</property>
<property name="stock_id">gtk-execute</property> <property name="stock_id">gtk-execute</property>
</object> </object>
<object class="GtkAction" id="LoadProcessingTemplates"> <object class="GtkAction" id="LoadSettings">
<property name="label">_Load Processing Settings</property> <property name="label">_Load Settings</property>
<property name="tooltip">Loads a set of processing templates from a file.</property> <property name="tooltip">Loads a set of processing templates from a file.</property>
<property name="stock_id">gtk-open</property> <property name="stock_id">gtk-open</property>
</object> </object>
<object class="GtkAction" id="SaveProcessingTemplates"> <object class="GtkAction" id="SaveSettings">
<property name="label">_Save Processing Settings</property> <property name="label">_Save Settings</property>
<property name="tooltip">Save the currently visible set of processing templates to a file.</property> <property name="tooltip">Save the currently visible set of processing templates to a file.</property>
<property name="stock_id">gtk-save</property> <property name="stock_id">gtk-save</property>
</object> </object>
<object class="GtkAction" id="SaveAsProcessingTemplates"> <object class="GtkAction" id="SaveAsSettings">
<property name="label">Save Processing Settings _as ...</property> <property name="label">Save Settings _as ...</property>
<property name="tooltip">Save the currently visible set of processing templates to a new file.</property> <property name="tooltip">Save the currently visible set of processing templates to a new file.</property>
<property name="stock_id">gtk-save-as</property> <property name="stock_id">gtk-save-as</property>
</object> </object>
...@@ -3739,6 +3739,8 @@ You should have received a copy of the GNU General Public License along with thi ...@@ -3739,6 +3739,8 @@ You should have received a copy of the GNU General Public License along with thi
<object class="GtkSpinButton" id="OverlapPercentControl"> <object class="GtkSpinButton" id="OverlapPercentControl">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">The distance between two neighbouring drill positions is based on the overlap value.
Use high values for fine-grained toolpaths.</property>
<property name="invisible_char">&#x2022;</property> <property name="invisible_char">&#x2022;</property>
<property name="adjustment">OverlapPercentValue</property> <property name="adjustment">OverlapPercentValue</property>
<property name="numeric">True</property> <property name="numeric">True</property>
...@@ -3769,6 +3771,11 @@ You should have received a copy of the GNU General Public License along with thi ...@@ -3769,6 +3771,11 @@ You should have received a copy of the GNU General Public License along with thi
<object class="GtkSpinButton" id="MaterialAllowanceControl"> <object class="GtkSpinButton" id="MaterialAllowanceControl">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Material allowance determines the minimum distance that should be preserved between the tool and the model.
This value should be greater than zero for the first roughing operation.
The last finishing operation should have zero material allowance.
ODE is required for this setting.</property>
<property name="invisible_char">&#x2022;</property> <property name="invisible_char">&#x2022;</property>
<property name="adjustment">MaterialAllowanceValue</property> <property name="adjustment">MaterialAllowanceValue</property>
<property name="digits">2</property> <property name="digits">2</property>
...@@ -3787,6 +3794,7 @@ You should have received a copy of the GNU General Public License along with thi ...@@ -3787,6 +3794,7 @@ You should have received a copy of the GNU General Public License along with thi
<object class="GtkSpinButton" id="MaxStepDownControl"> <object class="GtkSpinButton" id="MaxStepDownControl">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">This value determines the maximum height of each PushCutter slice.</property>
<property name="invisible_char">&#x2022;</property> <property name="invisible_char">&#x2022;</property>
<property name="adjustment">MaxStepDownValue</property> <property name="adjustment">MaxStepDownValue</property>
<property name="digits">2</property> <property name="digits">2</property>
...@@ -3829,6 +3837,7 @@ You should have received a copy of the GNU General Public License along with thi ...@@ -3829,6 +3837,7 @@ You should have received a copy of the GNU General Public License along with thi
<object class="GtkSpinButton" id="SafetyHeightControl"> <object class="GtkSpinButton" id="SafetyHeightControl">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">The drill will return between lines and slices to the safe height.</property>
<property name="invisible_char">&#x2022;</property> <property name="invisible_char">&#x2022;</property>
<property name="adjustment">SafetyHeightValue</property> <property name="adjustment">SafetyHeightValue</property>
<property name="digits">1</property> <property name="digits">1</property>
......
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