Commit 5d3779c9 authored by sumpfralle's avatar sumpfralle

added a first draft of the xml state representation


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1196 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 49ce4a72
......@@ -32,6 +32,7 @@ import ConfigParser
import StringIO
import pickle
import logging
import xml.etree.ElementTree as ET
import pycam.Gui.Settings
import pycam.Importers.CXFImporter
......@@ -150,6 +151,7 @@ class EventCore(pycam.Gui.Settings.Settings):
self.event_handlers = {}
self.ui_sections = {}
self.chains = {}
self.xml_dumps = []
def register_event(self, event, func, *args):
if not event in self.event_handlers:
......@@ -396,6 +398,22 @@ class ProjectGui(object):
self._store_undo_state)
self.settings.register_event("model-change-after",
lambda: self.settings.emit_event("visual-item-updated"))
def dump_xml():
result = []
self.settings.call_chain("xml_dump", result)
root = ET.Element("pycam")
for match, element in result:
parent = root
if match:
found = root.findall(match)
if found:
parent = found[0]
else:
log.debug("Failed to find XML parent: %s" % str(match))
parent.append(element)
# for DEBUGGING
#print ET.tostring(parent)
self.settings.register_event("visual-item-updated", dump_xml)
# set the availability of ODE
self.enable_ode_control = self.gui.get_object("SettingEnableODE")
self.settings.add_item("enable_ode", self.enable_ode_control.get_active,
......@@ -871,15 +889,6 @@ class ProjectGui(object):
log.error("Failed to open the model: %s" % str(uris[0]))
return False
def append_to_queue(self, func, *args, **kwargs):
# check if gui is currently active
if self.gui_is_active:
# queue the function call
self._batch_queue.append((func, args, kwargs))
else:
# call the function right now
func(*args, **kwargs)
def load_recent_model_file(self, widget):
uri = widget.get_current_uri()
self.load_model_file(filename=uri)
......
......@@ -20,6 +20,8 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import xml.etree.ElementTree as ET
import pycam.Plugins
# TODO: move Toolpath.Bounds here?
import pycam.Toolpath
......@@ -51,6 +53,7 @@ class Bounds(pycam.Plugins.ListPluginBase):
def setup(self):
self._event_handlers = []
self.core.set("bounds", self)
if self.gui:
import gtk
bounds_box = self.gui.get_object("BoundsBox")
......@@ -132,6 +135,7 @@ class Bounds(pycam.Plugins.ListPluginBase):
continue
self._gtk_handlers.append((self.gui.get_object("NameCell"),
"edited", self._edit_bounds_name))
self.core.register_chain("xml_dump", self.dump_xml)
self._event_handlers.extend((
("bounds-selection-changed", self._switch_bounds),
("bounds-changed", self._store_bounds_settings),
......@@ -141,13 +145,13 @@ class Bounds(pycam.Plugins.ListPluginBase):
self._trigger_table_update()
self._switch_bounds()
self._update_model_list()
self.core.set("bounds", self)
self._event_handlers.append(("bounds-changed", "visual-item-updated"))
self.register_event_handlers(self._event_handlers)
return True
def teardown(self):
if self.gui:
self.core.unregister_chain("xml_dump", self.dump_xml)
self.core.unregister_ui("main", self.gui.get_object("BoundsBox"))
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
......@@ -386,6 +390,12 @@ class Bounds(pycam.Plugins.ListPluginBase):
new_text:
self._treemodel[path][self.COLUMN_NAME] = new_text
def dump_xml(self, result):
root = ET.Element("bounds-list")
for bounds in self.core.get("bounds"):
root.append(bounds.dump_xml())
result.append((None, root))
class BoundsDict(dict):
......@@ -456,3 +466,19 @@ class BoundsDict(dict):
high[index] += offset
return low, high
def dump_xml(self, name):
leaf = ET.Element("bounds")
leaf.set("name", repr(name))
parameters = ET.SubElement(leaf, "parameters")
for key in self:
if "Models" == key:
models = self["Models"]
if len(models) > 0:
models_leaf = ET.SubElement(parameters, "Models")
for model in models:
name = self.core.get("models").get_attr(model, "name")
ET.SubElement(models_leaf, "model", text=name)
else:
parameters.set(key, repr(self[key]))
return leaf
......@@ -20,6 +20,8 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import xml.etree.ElementTree as ET
import pycam.Plugins
......@@ -32,6 +34,7 @@ class Processes(pycam.Plugins.ListPluginBase):
LIST_ATTRIBUTE_MAP = {"ref": COLUMN_REF, "name": COLUMN_NAME}
def setup(self):
self.core.set("processes", self)
if self.gui:
import gtk
self._gtk = gtk
......@@ -97,6 +100,7 @@ class Processes(pycam.Plugins.ListPluginBase):
self._gtk_handlers.append((self.gui.get_object("StrategySelector"),
"changed", "process-strategy-changed"))
self.register_model_update(update_model)
self.core.register_chain("xml_dump", self.dump_xml)
self._event_handlers = (
("process-strategy-list-changed", self._update_widgets),
("process-selection-changed", self._process_switch),
......@@ -104,11 +108,11 @@ class Processes(pycam.Plugins.ListPluginBase):
("process-strategy-changed", self._store_process_settings))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self.core.set("processes", self)
return True
def teardown(self):
if self.gui:
self.core.unregister_chain("xml_dump", self.dump_xml)
self.core.unregister_ui("main", self.gui.get_object("ProcessBox"))
self.core.unregister_ui_section("process_path_parameters")
self.core.unregister_ui("process_parameters",
......@@ -260,3 +264,14 @@ class Processes(pycam.Plugins.ListPluginBase):
self.append(new_process)
self.select(new_process)
def dump_xml(self, result):
root = ET.Element("processes")
for process in self:
leaf = ET.SubElement(root, "process")
leaf.set("name", repr(self.get_attr(process, "name")))
leaf.set("strategy", process["strategy"])
parameters = ET.SubElement(leaf, "parameters")
for key, value in process["parameters"].iteritems():
parameters.set(key, repr(value))
result.append((None, root))
......@@ -20,6 +20,8 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import xml.etree.ElementTree as ET
import pycam.Plugins
from pycam.Cutters.CylindricalCutter import CylindricalCutter
from pycam.Cutters.SphericalCutter import SphericalCutter
......@@ -35,6 +37,7 @@ class Tools(pycam.Plugins.ListPluginBase):
LIST_ATTRIBUTE_MAP = {"id": COLUMN_TOOL_ID, "name": COLUMN_NAME}
def setup(self):
self.core.set("tools", self)
if self.gui:
import gtk
tool_frame = self.gui.get_object("ToolBox")
......@@ -121,16 +124,17 @@ class Tools(pycam.Plugins.ListPluginBase):
("tool-selection-changed", self._tool_switch),
("tool-changed", self._store_tool_settings),
("tool-shape-changed", self._store_tool_settings))
self.core.register_chain("xml_dump", self.dump_xml)
self.register_model_update(update_model)
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_widgets()
self._tool_switch()
self.core.set("tools", self)
return True
def teardown(self):
if self.gui:
self.core.unregister_chain("xml_dump", self.dump_xml)
self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_ui_section("tool_speed")
self.core.unregister_ui_section("tool_size")
......@@ -286,3 +290,15 @@ class Tools(pycam.Plugins.ListPluginBase):
self.append(new_tool)
self.select(new_tool)
def dump_xml(self, result):
root = ET.Element("tools")
for tool in self:
leaf = ET.SubElement(root, "tool")
for key in self.LIST_ATTRIBUTE_MAP:
leaf.set(key, repr(self.get_attr(tool, key)))
leaf.set("shape", tool["shape"])
parameters = ET.SubElement(leaf, "parameters")
for key, value in tool["parameters"].iteritems():
parameters.set(key, repr(value))
result.append((None, root))
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