70 |
70 |
71 #------------------------------------------------------------------------------- |
71 #------------------------------------------------------------------------------- |
72 # LPCModule Class |
72 # LPCModule Class |
73 #------------------------------------------------------------------------------- |
73 #------------------------------------------------------------------------------- |
74 |
74 |
|
75 LOCATION_TYPES = {"I": LOCATION_VAR_INPUT, |
|
76 "Q": LOCATION_VAR_OUTPUT, |
|
77 "M": LOCATION_VAR_MEMORY} |
|
78 |
|
79 LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()]) |
|
80 |
|
81 LOCATION_SIZES = {} |
|
82 for size, types in LOCATIONDATATYPES.iteritems(): |
|
83 for type in types: |
|
84 LOCATION_SIZES[type] = size |
|
85 |
75 def _GetModuleChildren(module): |
86 def _GetModuleChildren(module): |
76 children = [] |
87 children = [] |
77 for child in module["children"]: |
88 for child in module["children"]: |
78 if child["type"] == LOCATION_GROUP: |
89 if child["type"] == LOCATION_GROUP: |
79 children.extend(child["children"]) |
90 children.extend(child["children"]) |
94 if len(toks) > 1: |
105 if len(toks) > 1: |
95 return _GetModuleBySomething(child, something, toks[1:]) |
106 return _GetModuleBySomething(child, something, toks[1:]) |
96 return child |
107 return child |
97 return None |
108 return None |
98 |
109 |
99 def _GetModuleVariable(module, location): |
110 def _GetModuleVariable(module, location, direction): |
100 for child in _GetModuleChildren(module): |
111 for child in _GetModuleChildren(module): |
101 if child["location"] == location: |
112 if child["location"] == location and child["type"] == LOCATION_TYPES[direction]: |
102 return child |
113 return child |
103 return None |
114 return None |
104 |
115 |
105 def _RemoveModuleChild(module, child): |
116 def _RemoveModuleChild(module, child): |
106 if child in module["children"]: |
117 if child in module["children"]: |
107 module["children"].remove(child) |
118 module["children"].remove(child) |
108 else: |
119 else: |
109 for group in module["children"]: |
120 for group in module["children"]: |
110 if group["type"] == LOCATION_GROUP and child in group["children"]: |
121 if group["type"] == LOCATION_GROUP and child in group["children"]: |
111 group["children"].remove(child) |
122 group["children"].remove(child) |
112 |
|
113 LOCATION_TYPES = {"I": LOCATION_VAR_INPUT, |
|
114 "Q": LOCATION_VAR_OUTPUT, |
|
115 "M": LOCATION_VAR_MEMORY} |
|
116 |
|
117 LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()]) |
|
118 |
|
119 LOCATION_SIZES = {} |
|
120 for size, types in LOCATIONDATATYPES.iteritems(): |
|
121 for type in types: |
|
122 LOCATION_SIZES[type] = size |
|
123 |
123 |
124 BUS_TEXT = """/* Code generated by LPCBus plugin */ |
124 BUS_TEXT = """/* Code generated by LPCBus plugin */ |
125 |
125 |
126 /* LPCBus plugin includes */ |
126 /* LPCBus plugin includes */ |
127 #include "app_glue.h" |
127 #include "app_glue.h" |
891 if module is None: |
891 if module is None: |
892 return "Error: No parent found" |
892 return "Error: No parent found" |
893 for child in _GetModuleChildren(module): |
893 for child in _GetModuleChildren(module): |
894 if child["name"] == name: |
894 if child["name"] == name: |
895 return "Error: A variable named %s already exists" % name |
895 return "Error: A variable named %s already exists" % name |
896 if child["location"] == location: |
896 if child["location"] == location and child["type"] == LOCATION_TYPES[direction]: |
897 return "Error: A variable with location %s already exists" % ".".join(map(str, location)) |
897 return "Error: A variable with location %s already exists" % ".".join(map(str, location)) |
898 _GetLastModuleGroup(module).append({"name": name, |
898 _GetLastModuleGroup(module).append({"name": name, |
899 "location": location, |
899 "location": location, |
900 "type": LOCATION_TYPES[direction], |
900 "type": LOCATION_TYPES[direction], |
901 "IEC_type": type, |
901 "IEC_type": type, |
909 module = self.PluginRoot.GetChildByIECLocation(parent) |
909 module = self.PluginRoot.GetChildByIECLocation(parent) |
910 if module is None: |
910 if module is None: |
911 return "Error: No parent found" |
911 return "Error: No parent found" |
912 variable = None |
912 variable = None |
913 for child in _GetModuleChildren(module): |
913 for child in _GetModuleChildren(module): |
914 if child["location"] == location: |
914 if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]: |
915 variable = child |
915 variable = child |
916 elif child["name"] == new_name: |
916 elif child["name"] == new_name: |
917 return "Error: A variable named %s already exists" % new_name |
917 return "Error: A variable named %s already exists" % new_name |
918 if variable is None: |
918 if variable is None: |
919 return "Error: No variable found" |
919 return "Error: No variable found" |
927 variable["publish"] = new_pcode |
927 variable["publish"] = new_pcode |
928 if new_description is not None: |
928 if new_description is not None: |
929 variable["description"] = new_description |
929 variable["description"] = new_description |
930 self.RestartTimer() |
930 self.RestartTimer() |
931 |
931 |
932 def RemoveVariable(self, parent, location): |
932 def RemoveVariable(self, parent, location, direction): |
933 module = self.PluginRoot.GetChildByIECLocation(parent) |
933 module = self.PluginRoot.GetChildByIECLocation(parent) |
934 if module is None: |
934 if module is None: |
935 return "Error: No parent found" |
935 return "Error: No parent found" |
936 child = _GetModuleVariable(module, location) |
936 child = _GetModuleVariable(module, location, direction) |
937 if child is None: |
937 if child is None: |
938 return "Error: No variable found" |
938 return "Error: No variable found" |
939 size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])] |
939 size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])] |
940 address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location)) |
940 address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location)) |
941 self.PluginRoot.RemoveProjectVariableByAddress(address) |
941 self.PluginRoot.RemoveProjectVariableByAddress(address) |