245 if not isinstance(values, TupleType): |
245 if not isinstance(values, TupleType): |
246 message = _("Invalid value \"%s\" for variable grid element")%data |
246 message = _("Invalid value \"%s\" for variable grid element")%data |
247 values = None |
247 values = None |
248 if values is not None: |
248 if values is not None: |
249 if col != wx.NOT_FOUND and row != wx.NOT_FOUND: |
249 if col != wx.NOT_FOUND and row != wx.NOT_FOUND: |
250 if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location": |
250 colname = self.ParentWindow.Table.GetColLabelValue(col, False) |
251 return |
251 if colname == "Location" and values[1] == "location": |
252 if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
252 if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
253 message = _("Can't give a location to a function block instance") |
253 message = _("Can't give a location to a function block instance") |
254 elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]: |
254 elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]: |
255 message = _("Can only give a location to local or global variables") |
255 message = _("Can only give a location to local or global variables") |
256 elif values is not None and values[1] == "location": |
|
257 location = values[0] |
|
258 variable_type = self.ParentWindow.Table.GetValueByName(row, "Type") |
|
259 base_type = self.ParentWindow.Controler.GetBaseType(variable_type) |
|
260 if location.startswith("%"): |
|
261 if base_type != values[2]: |
|
262 message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type) |
|
263 else: |
|
264 self.ParentWindow.Table.SetValue(row, col, location) |
|
265 self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
266 self.ParentWindow.SaveValues() |
|
267 else: |
256 else: |
268 if location[0].isdigit() and base_type != "BOOL": |
257 location = values[0] |
269 message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location |
258 variable_type = self.ParentWindow.Table.GetValueByName(row, "Type") |
270 elif location[0] not in LOCATIONDATATYPES: |
259 base_type = self.ParentWindow.Controler.GetBaseType(variable_type) |
271 message = _("Unrecognized data size \"%s\"")%location[0] |
260 if location.startswith("%"): |
272 elif base_type not in LOCATIONDATATYPES[location[0]]: |
261 if base_type != values[2]: |
273 message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type) |
262 message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type) |
274 else: |
263 else: |
275 dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Select a variable class:"), _("Variable class"), ["Input", "Output", "Memory"], wx.OK|wx.CANCEL) |
|
276 if dialog.ShowModal() == wx.ID_OK: |
|
277 selected = dialog.GetSelection() |
|
278 if selected == 0: |
|
279 location = "%I" + location |
|
280 elif selected == 1: |
|
281 location = "%Q" + location |
|
282 else: |
|
283 location = "%M" + location |
|
284 self.ParentWindow.Table.SetValue(row, col, location) |
264 self.ParentWindow.Table.SetValue(row, col, location) |
285 self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
265 self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
286 self.ParentWindow.SaveValues() |
266 self.ParentWindow.SaveValues() |
287 dialog.Destroy() |
267 else: |
|
268 if location[0].isdigit() and base_type != "BOOL": |
|
269 message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location |
|
270 elif location[0] not in LOCATIONDATATYPES: |
|
271 message = _("Unrecognized data size \"%s\"")%location[0] |
|
272 elif base_type not in LOCATIONDATATYPES[location[0]]: |
|
273 message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type) |
|
274 else: |
|
275 dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Select a variable class:"), _("Variable class"), ["Input", "Output", "Memory"], wx.OK|wx.CANCEL) |
|
276 if dialog.ShowModal() == wx.ID_OK: |
|
277 selected = dialog.GetSelection() |
|
278 if selected == 0: |
|
279 location = "%I" + location |
|
280 elif selected == 1: |
|
281 location = "%Q" + location |
|
282 else: |
|
283 location = "%M" + location |
|
284 self.ParentWindow.Table.SetValue(row, col, location) |
|
285 self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
286 self.ParentWindow.SaveValues() |
|
287 dialog.Destroy() |
|
288 elif colname == "Initial Value" and values[1] == "Constant": |
|
289 if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
|
290 message = _("Can't set an initial value to a function block instance") |
|
291 else: |
|
292 self.ParentWindow.Table.SetValue(row, col, values[0]) |
|
293 self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
294 self.ParentWindow.SaveValues() |
288 elif (element_type not in ["config", "resource"] and values[1] == "Global" and self.ParentWindow.Filter in ["All", "Interface", "External"] or |
295 elif (element_type not in ["config", "resource"] and values[1] == "Global" and self.ParentWindow.Filter in ["All", "Interface", "External"] or |
289 element_type in ["config", "resource"] and values[1] == "location"): |
296 element_type in ["config", "resource"] and values[1] == "location"): |
290 if values[1] == "location": |
297 if values[1] == "location": |
291 var_name = values[3] |
298 var_name = values[3] |
292 else: |
299 else: |