--- a/editors/Viewer.py Tue Aug 20 01:13:14 2024 +0200
+++ b/editors/Viewer.py Tue Aug 20 01:25:39 2024 +0200
@@ -1542,15 +1542,18 @@
# -------------------------------------------------------------------------------
- def GetForceVariableMenuFunction(self, iec_path, element):
- iec_type = self.GetDataType(iec_path)
- def ForceVariableFunction(event):
- if iec_type is not None:
- dialog = ForceVariableDialog(self.ParentWindow, iec_type, str(element.GetValue()))
- if dialog.ShowModal() == wx.ID_OK:
- self.ParentWindow.AddDebugVariable(iec_path)
- self.ForceDataValue(iec_path, dialog.GetValue())
+ def GetForceVariableMenuFunction(self, iec_path, iec_type, value, immediate = False): + def ForceVariableFunction(event, value=value): + # use value as default value in dialog + dialog = ForceVariableDialog(self.ParentWindow, iec_type, str(value)) + if dialog.ShowModal() != wx.ID_OK: + value = dialog.GetValue() + self.ParentWindow.AddDebugVariable(iec_path) + self.ForceDataValue(iec_path, value) return ForceVariableFunction
def GetReleaseVariableMenuFunction(self, iec_path):
@@ -1570,13 +1573,39 @@
def PopupForceMenu(self):
iec_path = self.GetElementIECPath(self.SelectedElement)
+ # GetElementIECPath() does not work for variables and coils + # In such case get the IEC path using the instance path + for ElementType in [FBD_Variable, LD_Coil]: + if isinstance(self.SelectedElement, ElementType): + instance_path = self.GetInstancePath(True) + iec_path = "%s.%s" % (instance_path, self.SelectedElement.GetName()) + menu = wx.Menu(title='') - item = self.AppendItem(menu,
- self.GetForceVariableMenuFunction(
+ iec_type = self.GetDataType(iec_path) + self.GetForceVariableMenuFunction( + iec_path.upper(), iec_type, not(self.SelectedElement.GetValue()), True)) + self.GetForceVariableMenuFunction( + iec_path.upper(), iec_type, True, True)) + self.GetForceVariableMenuFunction( + iec_path.upper(), iec_type, False, True)) + self.GetForceVariableMenuFunction( + iec_path.upper(), iec_type, + self.SelectedElement.GetValue())) ritem = self.AppendItem(menu,
@@ -1585,6 +1614,7 @@
if self.Editor.HasCapture():
self.Editor.ReleaseMouse()
self.Editor.PopupMenu(menu)