kasemir / org.csstudio.display.builder

Update of org.csstudio.opibuilder.*
Eclipse Public License 1.0
2 stars 10 forks source link

Update widget macro with text entry #556

Open ewaagaard opened 4 years ago

ewaagaard commented 4 years ago

Hi!

In a pop-up in .bob menu from the main system called Gersemi, there is an embedded display with text update templates showing various statuses and values of a wanted device determined by the user. For this purpose, I have created a text entry where one enters the process variable name of the wanted device in the system that becomes a local variable through loc://GersemiAIdevNam. I would like the macro "AI2Macro" to be the prefix (determined from user input) that then makes the text update templates show the status, e.g. $(AI2Macro):sRdV. The problem is that when this local PV is turned into a macro, the widgets (the text updates) don't seem to notice that the user has updated this PV. In runtime mode, the embedded display has indeed a macro "AI2Macro" that is exactly equal to the user input, so that seems to work. The following attached python script below is what I use:

from org.csstudio.display.builder.runtime.script import PVUtil

GersemiAIdevNam = PVUtil.getString(pvs[0]) widget.getPropertyValue("macros").add("AI2Macro", GersemiAIdevNam)

However, the other widgets in the embedded display don't seem to notice this updated macro. In the old .opi version of the menu, this JavaScript was used:

importPackage(Packages.org.csstudio.opibuilder.scriptUtil);

var macroInput = DataUtil.createMacrosInput(true); var GersemiAIdevNam = PVUtil.getString(pvArray[0]);

macroInput.put("AI2Macro", GersemiAIdevNam); widgetController.setPropertyValue("macros", macroInput);

Strangly enough, the display builder in CS Studio does not seem to import packages properly in JavaScript, so that's why I used python for the .bob version. In Python, the "import DataUtil" does not seem to work either. Do you have any idea of how to make other widgets understand that there is this new updated PV from the text entry user input? Thanks in advance for your help!

Best wishes, sailew

kasemir commented 4 years ago

Use the latest version of CS-Studio (https://controlssoftware.sns.ornl.gov/css_phoebus/, https://github.com/ControlSystemStudio/phoebus). Install the example displays. Check the embedded/structure_embedded.bob example. In the lower left corner, it includes an embedded display with a script to update the file and the macros:

# Example script that updates the 'file' of
# an embedded display widget.
#
# Meant as an embedded display widget test.
# Unlikely to be useful in a production setup
# because displays should only change their fundamental
# content in response to operator input.
from org.csstudio.display.builder.runtime.script import PVUtil

# PV is supposed to cycle through values 0, 1, 2, 3
sel = PVUtil.getDouble(pvs[0])
if sel < 0.5:
    # Initial value: Show some file with macros
    widget.getPropertyValue("macros").add("M", "Value 1")
    widget.setPropertyValue("file", "a.bob")
elif sel < 1.5:
    # Next value: Show same file with different macros
    widget.getPropertyValue("macros").add("M", "Value 2")
    # Need to change the file name and then revert back to force a reload
    widget.setPropertyValue("file", "")
    widget.setPropertyValue("file", "a.bob")
elif sel < 2.5:
    # Different file
    widget.setPropertyValue("file", "b.bob")
else:
    # File that doesn't actually exist.
    # Widget will indicate error.
    widget.setPropertyValue("file", "missing.bob")

For general info about compatibility, see https://github.com/ControlSystemStudio/phoebus/wiki/Display-Builder-Compatibility For some specifics on scripting, see https://github.com/ControlSystemStudio/phoebus/wiki/Display-Builder-Script-Compatibility

ewaagaard commented 4 years ago

Thank you!

Is the embedded folder in the org.csstudio.display.builder repository? Or where can I find it?

I still wonder about the a.bob and b.bob files, and how the macro values "Value 2" and "Value 1" can be implemented. In the image below, the AI-sim-top.bob is displayed, with embedded display AI-SIM.bob. The user input comes from the text entry as the local PV through loc://GersemiAIdevNam. In this case, I suppose "M" in the example above corresponds to "AI2Macro". But what should "Value 1" and "Value 2" be? Always loc://GersemiAIdevNam?

Regarding the "file" part, should I set a.bob always to be AI-SIM.bob or AI-sim-top.bob? Or how would the applied example script above update what comes from the text entry, such that the widgets inside AI-SIM.bob understand that the parent macro "AI2Macro" has been updated?

image

kasemir commented 4 years ago

You can install the examples from the latest CS-Studio via Example Display from the menu Applications, Display, Examples. They're also in the repo under https://github.com/ControlSystemStudio/phoebus/tree/master/app/display/model/src/main/resources/examples

In the outer, container display, you can have some text input widget with loc://macro("") write the desired macro value. On the embedded display widget, you then have a script that's triggered by loc://macro("") and uses that value to update the macros passed to the content:

# Script on embedded widget,
# pvs[0]: loc://macro("")
from org.csstudio.display.builder.runtime.script import PVUtil

widget.getPropertyValue("macros").add("M", PVUtil.getString(pvs[0]))
# Just updating the macros, though, doesn't do anything.
# Need to change what file is displayed.
# Since it doesn't really change, create a fake change to "" and then the name again:
widget.setPropertyValue("file", "")
widget.setPropertyValue("file", "AI-SIM.bob")

There are, however, a few concerns: First, operators should not have to enter PV names nor macros for PV names. Operators just open displays which "work". In the middle of the night, how is an operator supposed to come up with the correct PV name?

Second, anything related to scripts will change (as you noticed).

ewaagaard commented 4 years ago

Thank you, now it works for all systems with a generic script! The operator is only supposed to enter the device name and all the PV values are displayed below, so that should also be fine.