diff pyink/domview.py @ 1469:c1e70540541c

Drawing functions for states and transitions
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 24 Apr 2011 12:30:47 +0800
parents c586981ecf1a
children 2a9b9c281f80
line wrap: on
line diff
--- a/pyink/domview.py	Mon Apr 18 11:54:10 2011 +0800
+++ b/pyink/domview.py	Sun Apr 24 12:30:47 2011 +0800
@@ -53,6 +53,7 @@
     condition = None
     target = None
     action = None
+    path = None
     
     def __init__(self, node=None):
         self.node = node
@@ -71,6 +72,13 @@
         node.setAttribute('action', action)
         pass
 
+    def set_path(self, path):
+        self.paht = path
+        node = self.node
+        path_txt = ' '.join([str(c) for c in path.strip().split()])
+        node.setAttribute('path', path_txt)
+        pass
+
     def reparse(self):
         condition = node.getAttribute('condition')
         target = node.getAttribute('target')
@@ -79,10 +87,17 @@
         except:
             action = None
             pass
+        try:
+            path = node.getAttribute('path').strip().split()
+            path = [float(c) for c in path]
+        except:
+            path = None
+            pass
         
         self.condition = condition
         self.target = target
         self.action = action
+        self.path = path
         pass
 
     def update_node(self):
@@ -92,6 +107,9 @@
         if self.action:
             node.setAttribute('action', self.action)
             pass
+        if self.path:
+            node.setAttribute('path', self.path)
+            pass
         pass
 
     ## \brief Create a node according status of the object.
@@ -136,6 +154,9 @@
     name = None
     entry_action = None
     transitions = None
+    r = None
+    x = 0
+    y = 0
     
     def __init__(self, node=None):
         self.node = node
@@ -152,6 +173,18 @@
         self.node.setAttribute('entry_action', action)
         pass
 
+    def set_r(self, r):
+        self.r = r
+        self.node.setAttribute('r', str(r))
+        pass
+
+    def set_xy(self, x, y):
+        self.x = x
+        self.y = y
+        self.node.setAttribute('x', str(x))
+        self.node.setAttribute('y', str(y))
+        pass
+
     def reparse(self):
         node = self.node
         
@@ -161,6 +194,21 @@
         except:
             entry_action = None
             pass
+        try:
+            r = float(node.getAttribute('r'))
+        except:
+            r = None
+            pass
+        try:
+            x = float(node.getAttribute('x'))
+        except:
+            x = 0
+            pass
+        try:
+            y = float(node.getAttribute('y'))
+        except:
+            y = 0
+            pass
         
         all_transitions = [Transition.parse_transition(child)
                            for child in node.childList()
@@ -171,6 +219,9 @@
         self.name = name
         self.transitions = transitions
         self.entry_action = entry_action
+        self.r = r
+        self.x = x
+        self.y = y
         pass
 
     def update_node(self):
@@ -180,6 +231,15 @@
         if self.entry_action:
             node.setAttribute('entry_action', self.entry_action)
             pass
+        if self.r:
+            node.setAttribute('r', self.r)
+            pass
+        if self.x:
+            node.setAttribute('x', self.x)
+            pass
+        if self.y:
+            node.setAttribute('y', self.y)
+            pass
 
         transitions = self.transitions
         for trn in transitions:
@@ -1050,6 +1110,31 @@
         state.set_entry_action(entry_action)
         pass
 
+    def set_state_r(self, state_name, r):
+        state = self._get_state(state_name)
+        state.set_r(r)
+        pass
+
+    def set_state_xy(self, state_name, x, y):
+        state = self._get_state(state_name)
+        state.set_xy(x, y)
+        pass
+
+    def get_state_entry_action(self, state_name):
+        state = self._get_state(state_name)
+        action = state.get_entry_action()
+        return action
+
+    def get_state_r(self, state_name):
+        state = self._get_state(state_name)
+        r = state.r
+        return r
+
+    def get_state_xy(self, state_name):
+        state = self._get_state(state_name)
+        xy = state.x, state.y
+        return xy
+
     def all_transitions(self, state_name):
         state = self._get_state(state_name)
         trn_names = state.all_transitions()
@@ -1077,13 +1162,19 @@
         cond = trn.condition
         target = trn.target
         action = trn.action
+        path = trn.path
         
-        return cond, target, action
+        return cond, target, action, path
 
     def set_transition_action(self, state_name, cond, action):
         trn = state.get_transition(state_name, cond)
         trn.set_action(action)
         pass
+
+    def set_transition_path(self, state_name, cond, path):
+        trn = state.get_transition(state_name, cond)
+        trn.set_path(path)
+        pass
     pass