Search in sources :

Example 1 with IPV

use of org.yamcs.studio.data.IPV in project yamcs-studio by yamcs.

the class AbstractScriptStore method init.

private void init() throws Exception {
    if (!(scriptData instanceof RuleScriptData) && !scriptData.isEmbedded()) {
        absoluteScriptPath = scriptData.getPath();
        if (!absoluteScriptPath.isAbsolute()) {
            // The following looked like this:
            // absoluteScriptPath = ResourceUtil.buildAbsolutePath(
            // editpart.getWidgetModel(), absoluteScriptPath);
            // .. but that doesn't work when the editpart is already a LinkingContainer.
            // It would fetch the parent's DisplayModel, i.e. look for scripts where the container is used,
            // instead of where it's defined.
            // 
            // After updating buildAbsolutePath() to handle (editpart instanceof LinkingContainer) as below,
            // the resolution of related displays failed again as in #977 because buildAbsolutePath() is
            // called in many placed while reading the *.opi file, and it would now build a different widget tree.
            // 
            // The following just fixes the relative script lookup from linking containers for #998,
            // without disturbing any other code.
            // 
            // TODO Understand & redo the whole widget model and its quirks for linking containers,
            // so all the recently added (.. instanceof ..Linking..) can be removed.
            var model = editPart.getWidgetModel();
            DisplayModel root;
            if (model instanceof AbstractLinkingContainerModel) {
                root = ((AbstractLinkingContainerModel) model).getDisplayModel();
            } else {
                root = model.getRootDisplayModel();
            }
            absoluteScriptPath = root.getOpiFilePath().removeLastSegments(1).append(absoluteScriptPath);
            // ---
            if (!ResourceUtil.isExsitingFile(absoluteScriptPath, true)) {
                throw new FileNotFoundException(scriptData.getPath().toString());
            }
        }
    }
    initScriptEngine();
    errorInScript = false;
    errorSource = (scriptData instanceof RuleScriptData ? ((RuleScriptData) scriptData).getRuleData().getName() : scriptData.getPath().toString()) + " on " + editPart.getWidgetModel().getName();
    if (scriptData instanceof RuleScriptData) {
        compileString(((RuleScriptData) scriptData).getScriptString());
    } else if (scriptData.isEmbedded()) {
        compileString(scriptData.getScriptText());
    } else {
        var inputStream = ResourceUtil.pathToInputStream(absoluteScriptPath);
        compileInputStream(inputStream);
        inputStream.close();
    }
    pvListenerMap = new HashMap<>();
    var suppressPVListener = new IPVListener() {

        @Override
        public synchronized void valueChanged(IPV pv) {
            if (triggerSuppressed && checkPVsConnected(scriptData, pvArray)) {
                executeScriptInUIThread(pv);
                triggerSuppressed = false;
            }
        }
    };
    var triggerPVListener = new IPVListener() {

        @Override
        public synchronized void valueChanged(IPV pv) {
            // execute script only if all input pvs are connected
            if (pvArray.length > 1) {
                if (!checkPVsConnected(scriptData, pvArray)) {
                    triggerSuppressed = true;
                    return;
                }
            }
            executeScriptInUIThread(pv);
        }
    };
    // register pv listener
    for (var i = 0; i < pvArray.length; i++) {
        var pv = pvArray[i];
        if (pv == null) {
            continue;
        }
        if (!scriptData.getPVList().get(i).trigger) {
            // execute the script if it was suppressed.
            pv.addListener(suppressPVListener);
            pvListenerMap.put(pv, suppressPVListener);
            continue;
        }
        pv.addListener(triggerPVListener);
        pvListenerMap.put(pv, triggerPVListener);
    }
}
Also used : DisplayModel(org.csstudio.opibuilder.model.DisplayModel) FileNotFoundException(java.io.FileNotFoundException) AbstractLinkingContainerModel(org.csstudio.opibuilder.model.AbstractLinkingContainerModel) IPVListener(org.yamcs.studio.data.IPVListener) IPV(org.yamcs.studio.data.IPV)

Example 2 with IPV

use of org.yamcs.studio.data.IPV in project yamcs-studio by yamcs.

the class ArrayEditPart method registerLoadPVDataTypeListener.

private void registerLoadPVDataTypeListener() {
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        var model = getWidgetModel();
        var pv = getPV();
        if (pv != null) {
            if (pvDataTypeListener == null) {
                pvDataTypeListener = new IPVListener() {

                    @Override
                    public void valueChanged(IPV pv) {
                        var value = pv.getValue();
                        if (value != null) {
                            model.setArrayLength(VTypeHelper.getSize(value));
                            var dataType = VTypeHelper.getBasicDataType(value);
                            model.setPropertyValue(PROP_DATA_TYPE, mapBasicDataTypeToArrayType(dataType));
                        }
                    }
                };
            }
            pv.addListener(pvDataTypeListener);
        }
    }
}
Also used : IPVListener(org.yamcs.studio.data.IPVListener) IPV(org.yamcs.studio.data.IPV)

Aggregations

IPV (org.yamcs.studio.data.IPV)2 IPVListener (org.yamcs.studio.data.IPVListener)2 FileNotFoundException (java.io.FileNotFoundException)1 AbstractLinkingContainerModel (org.csstudio.opibuilder.model.AbstractLinkingContainerModel)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1