# HG changeset patch # User laurent # Date 1260193498 -3600 # Node ID fc0b3c064208913f755775434c010e41947e8f35 # Parent 80eb3bde98e3c2ee2c1d8f551e46aae1ad6d9a58# Parent 98a39261db9ee9471a98f32a909e059c28de0019 Changes merged diff -r 98a39261db9e -r fc0b3c064208 LPCBeremiz.py --- a/LPCBeremiz.py Mon Dec 07 14:00:33 2009 +0100 +++ b/LPCBeremiz.py Mon Dec 07 14:44:58 2009 +0100 @@ -72,6 +72,17 @@ # LPCModule Class #------------------------------------------------------------------------------- +LOCATION_TYPES = {"I": LOCATION_VAR_INPUT, + "Q": LOCATION_VAR_OUTPUT, + "M": LOCATION_VAR_MEMORY} + +LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()]) + +LOCATION_SIZES = {} +for size, types in LOCATIONDATATYPES.iteritems(): + for type in types: + LOCATION_SIZES[type] = size + def _GetModuleChildren(module): children = [] for child in module["children"]: @@ -96,9 +107,9 @@ return child return None -def _GetModuleVariable(module, location): +def _GetModuleVariable(module, location, direction): for child in _GetModuleChildren(module): - if child["location"] == location: + if child["location"] == location and child["type"] == LOCATION_TYPES[direction]: return child return None @@ -110,17 +121,6 @@ if group["type"] == LOCATION_GROUP and child in group["children"]: group["children"].remove(child) -LOCATION_TYPES = {"I": LOCATION_VAR_INPUT, - "Q": LOCATION_VAR_OUTPUT, - "M": LOCATION_VAR_MEMORY} - -LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()]) - -LOCATION_SIZES = {} -for size, types in LOCATIONDATATYPES.iteritems(): - for type in types: - LOCATION_SIZES[type] = size - BUS_TEXT = """/* Code generated by LPCBus plugin */ /* LPCBus plugin includes */ @@ -893,7 +893,7 @@ for child in _GetModuleChildren(module): if child["name"] == name: return "Error: A variable named %s already exists" % name - if child["location"] == location: + if child["location"] == location and child["type"] == LOCATION_TYPES[direction]: return "Error: A variable with location %s already exists" % ".".join(map(str, location)) _GetLastModuleGroup(module).append({"name": name, "location": location, @@ -911,7 +911,7 @@ return "Error: No parent found" variable = None for child in _GetModuleChildren(module): - if child["location"] == location: + if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]: variable = child elif child["name"] == new_name: return "Error: A variable named %s already exists" % new_name @@ -929,11 +929,11 @@ variable["description"] = new_description self.RestartTimer() - def RemoveVariable(self, parent, location): + def RemoveVariable(self, parent, location, direction): module = self.PluginRoot.GetChildByIECLocation(parent) if module is None: return "Error: No parent found" - child = _GetModuleVariable(module, location) + child = _GetModuleVariable(module, location, direction) if child is None: return "Error: No variable found" size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])]