Search in sources :

Example 16 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class MatlabScriptExportJob method performExport.

/**
 * {@inheritDoc}
 */
@Override
protected void performExport(final IProgressMonitor monitor, final PrintStream out) throws Exception {
    final DateFormat date_format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
    int count = 0;
    for (ModelItem item : model.getItems()) {
        // Item header
        if (count > 0)
            out.println();
        printItemInfo(out, item);
        // Get data
        monitor.subTask(NLS.bind("Fetching data for {0}", item.getName()));
        final ValueIterator values = createValueIterator(item);
        // Dump all values
        MatlabQualityHelper qualities = new MatlabQualityHelper();
        long line_count = 0;
        out.println("clear t;");
        out.println("clear v;");
        out.println("clear q;");
        while (values.hasNext() && !monitor.isCanceled()) {
            final VType value = values.next();
            ++line_count;
            // t(1)='2010/03/15 13:30:10.123';
            out.println("t{" + line_count + "}='" + date_format.format(Date.from(VTypeHelper.getTimestamp(value))) + "';");
            // v(1)=4.125;
            final double num = VTypeHelper.toDouble(value);
            if (Double.isNaN(num) || Double.isInfinite(num))
                out.println("v(" + line_count + ")=NaN;");
            else
                out.println("v(" + line_count + ")=" + num + ";");
            // q(1)=0;
            out.println("q(" + line_count + ")=" + qualities.getQualityCode(VTypeHelper.getSeverity(value), VTypeHelper.getMessage(value)) + ";");
            if (line_count % PROGRESS_UPDATE_LINES == 0)
                monitor.subTask(NLS.bind("{0}: Wrote {1} samples", item.getName(), line_count));
        }
        out.println(comment + "Convert time stamps into 'date numbers'");
        out.println("tn=datenum(t, 'yyyy/mm/dd HH:MM:SS.FFF');");
        out.println(comment + "Prepare patched data because");
        out.println(comment + "timeseries() cannot handle duplicate time stamps");
        out.println("[xx, idx]=unique(tn, 'last');");
        out.println("pt=tn(idx);");
        out.println("pv=v(idx);");
        out.println("pq=q(idx);");
        out.println("clear xx idx");
        out.println(comment + "Convert into time series and plot");
        // Patch "_" in name because Matlab plot will interprete it as LaTeX sub-script
        final String channel_name = item.getResolvedDisplayName().replace("_", "\\_");
        out.println("channel" + count + "=timeseries(pv', pt', pq', 'IsDatenum', true, 'Name', '" + channel_name + "');");
        out.print("channel" + count + ".QualityInfo.Code=[");
        for (int q = 0; q < qualities.getNumCodes(); ++q) out.print(" " + q);
        out.println(" ];");
        out.print("channel" + count + ".QualityInfo.Description={");
        for (int q = 0; q < qualities.getNumCodes(); ++q) out.print(" '" + qualities.getQuality(q) + "'");
        out.println(" };");
        out.println();
        ++count;
    }
    out.println(comment + "Example for plotting the data");
    for (int i = 0; i < count; ++i) {
        out.println("subplot(1, " + count + ", " + (i + 1) + ");");
        out.println("plot(channel" + i + ");");
    }
}
Also used : VType(org.diirt.vtype.VType) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) ValueIterator(org.csstudio.archive.reader.ValueIterator) SimpleDateFormat(java.text.SimpleDateFormat)

Example 17 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class JMatioDemo method writeMatlabFile2.

public void writeMatlabFile2() throws Exception {
    // Example values
    final VType[] values = new VType[10];
    for (int i = 0; i < 10; ++i) values[i] = new ArchiveVNumber(VTypeHelper.getTimestamp(null), AlarmSeverity.NONE, "OK", ValueFactory.displayNone(), Math.exp(-((5.0 - i) * (5.0 - i))));
    // Turn values into Matlab data
    final int[] dims = new int[] { values.length, 1 };
    final MLDouble value = new MLDouble(null, dims);
    final MLCell time = new MLCell(null, dims);
    final MLCell severity = new MLCell(null, dims);
    final MLCell status = new MLCell(null, dims);
    for (int i = 0; i < values.length; ++i) {
        value.set(VTypeHelper.toDouble(values[i]), i);
        setCellText(time, i, TimestampHelper.format(VTypeHelper.getTimestamp(values[i])));
        setCellText(severity, i, VTypeHelper.getSeverity(values[i]).toString());
        setCellText(severity, i, VTypeHelper.getMessage(values[i]));
    }
    final MLStructure struct = new MLStructure("channel0", new int[] { 1, 1 });
    struct.setField("value", value);
    struct.setField("time", time);
    struct.setField("severity", severity);
    struct.setField("status", status);
    // Write to file
    final MatFileIncrementalWriter writer = new MatFileIncrementalWriter("mat_file2.mat");
    writer.write(struct);
    writer.close();
}
Also used : MLDouble(com.jmatio.types.MLDouble) MLStructure(com.jmatio.types.MLStructure) VType(org.diirt.vtype.VType) MLCell(com.jmatio.types.MLCell) ArchiveVNumber(org.csstudio.archive.vtype.ArchiveVNumber) MatFileIncrementalWriter(com.jmatio.io.MatFileIncrementalWriter)

Example 18 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class RadioRepresentation method selectionChanged.

private void selectionChanged(final ObservableValue<? extends Toggle> obs, final Toggle oldval, final Toggle newval) {
    if (!active && newval != null) {
        active = true;
        try {
            // For now reset to old value.
            // New value will be shown if the PV accepts it and sends a value update.
            toggle.selectToggle(oldval);
            final Object value;
            final VType pv_value = model_widget.runtimePropValue().getValue();
            if (pv_value instanceof VEnum || pv_value instanceof VNumber)
                // PV uses enumerated or numeric type, so write the index
                value = toggle.getToggles().indexOf(newval);
            else
                // PV uses text
                value = FormatOptionHandler.parse(pv_value, ((RadioButton) newval).getText(), FormatOption.DEFAULT);
            logger.log(Level.FINE, "Writing " + value);
            toolkit.fireWrite(model_widget, value);
        } finally {
            active = false;
        }
    }
}
Also used : VType(org.diirt.vtype.VType) VNumber(org.diirt.vtype.next.VNumber) VEnum(org.diirt.vtype.VEnum)

Example 19 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class TankRepresentation method valueChanged.

private void valueChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final VType vtype = model_widget.runtimePropValue().getValue();
    final boolean limits_from_pv = model_widget.propLimitsFromPV().getValue();
    double min_val = model_widget.propMinimum().getValue();
    double max_val = model_widget.propMaximum().getValue();
    if (limits_from_pv) {
        // Try display range from PV
        final Display display_info = ValueUtil.displayOf(vtype);
        if (display_info != null) {
            min_val = display_info.getLowerDisplayLimit();
            max_val = display_info.getUpperDisplayLimit();
        }
    }
    tank.setRange(min_val, max_val);
    double value;
    if (toolkit.isEditMode())
        value = (min_val + max_val) / 2;
    else
        value = VTypeUtil.getValueNumber(vtype).doubleValue();
    tank.setValue(value);
}
Also used : VType(org.diirt.vtype.VType) Display(org.diirt.vtype.Display)

Example 20 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class BaseGaugeRepresentation method updateChanges.

@SuppressWarnings("unchecked")
@Override
public void updateChanges() {
    super.updateChanges();
    Object value;
    if (dirtyGeometry.checkAndClear()) {
        value = model_widget.propVisible().getValue();
        if (!Objects.equals(value, jfx_node.isVisible())) {
            jfx_node.setVisible((boolean) value);
        }
        jfx_node.setLayoutX(model_widget.propX().getValue());
        jfx_node.setLayoutY(model_widget.propY().getValue());
        jfx_node.setPrefWidth(model_widget.propWidth().getValue());
        jfx_node.setPrefHeight(model_widget.propHeight().getValue());
    }
    if (dirtyLook.checkAndClear()) {
        value = model_widget.propAutoScale().getValue();
        if (!Objects.equals(value, jfx_node.isAutoScale())) {
            jfx_node.setAutoScale((boolean) value);
        }
        Color bgColor = JFXUtil.convert(model_widget.propBackgroundColor().getValue());
        if (model_widget.propTransparent().getValue()) {
            bgColor = bgColor.deriveColor(0, 1, 1, 0);
        }
        if (!Objects.equals(bgColor, jfx_node.getBackgroundPaint())) {
            jfx_node.setBackgroundPaint(bgColor);
        }
        value = JFXUtil.convert(model_widget.propForegroundColor().getValue());
        if (!Objects.equals(value, jfx_node.getTitleColor())) {
            Color fgColor = (Color) value;
            jfx_node.setMajorTickMarkColor(fgColor);
            jfx_node.setMediumTickMarkColor(fgColor);
            jfx_node.setMinorTickMarkColor(fgColor);
            jfx_node.setTickLabelColor(fgColor);
            jfx_node.setTickMarkColor(fgColor);
            jfx_node.setTitleColor(fgColor);
            jfx_node.setUnitColor(fgColor);
            jfx_node.setValueColor(fgColor);
            jfx_node.setZeroColor(fgColor);
        }
        value = model_widget.propMajorTickSpace().getValue();
        if (!Objects.equals(value, jfx_node.getMajorTickSpace())) {
            jfx_node.setMajorTickSpace((double) value);
        }
        value = model_widget.propMinorTickSpace().getValue();
        if (!Objects.equals(value, jfx_node.getMinorTickSpace())) {
            jfx_node.setMinorTickSpace((double) value);
        }
        value = model_widget.propTitle().getValue();
        if (!Objects.equals(value, jfx_node.getTitle())) {
            jfx_node.setTitle((String) value);
        }
        value = model_widget.propValueVisible().getValue();
        if (!Objects.equals(value, jfx_node.isValueVisible())) {
            jfx_node.setValueVisible((boolean) value);
        }
    }
    if (dirtyContent.checkAndClear()) {
        value = FormatOptionHandler.actualPrecision(model_widget.runtimePropValue().getValue(), model_widget.propPrecision().getValue());
        if (!Objects.equals(value, jfx_node.getDecimals())) {
            jfx_node.setDecimals((int) value);
        }
    }
    if (dirtyLimits.checkAndClear()) {
        if (!Objects.equals(max, jfx_node.getMaxValue())) {
            jfx_node.setMaxValue(max);
        }
        if (!Objects.equals(min, jfx_node.getMinValue())) {
            jfx_node.setMinValue(min);
        }
        value = areZonesVisible();
        if (!Objects.equals(value, jfx_node.getSectionsVisible())) {
            jfx_node.setSectionsVisible((boolean) value);
        }
        value = createZones();
        if (!Objects.equals(value, jfx_node.getSections())) {
            jfx_node.setSections((List<Section>) value);
        }
    }
    if (dirtyUnit.checkAndClear()) {
        value = getUnit();
        if (!Objects.equals(value, jfx_node.getUnit())) {
            jfx_node.setUnit((String) value);
        }
    }
    if (dirtyStyle.checkAndClear()) {
        Styles.update(jfx_node, Styles.NOT_ENABLED, !model_widget.propEnabled().getValue());
    }
    if (dirtyValue.checkAndClear() && updatingValue.compareAndSet(false, true)) {
        try {
            final VType vtype = model_widget.runtimePropValue().getValue();
            double newval = VTypeUtil.getValueNumber(vtype).doubleValue();
            if (!Double.isNaN(newval)) {
                if (newval < min) {
                    newval = min;
                } else if (newval > max) {
                    newval = max;
                }
                jfx_node.setValue(newval);
            } else {
            // TODO: CR: do something!!!
            }
        } finally {
            updatingValue.set(false);
        }
    }
}
Also used : VType(org.diirt.vtype.VType) Color(javafx.scene.paint.Color) Section(eu.hansolo.medusa.Section)

Aggregations

VType (org.diirt.vtype.VType)76 Test (org.junit.Test)17 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)10 IFigure (org.eclipse.draw2d.IFigure)10 IPV (org.csstudio.simplepv.IPV)9 VEnum (org.diirt.vtype.VEnum)8 ArrayList (java.util.ArrayList)7 Display (org.diirt.vtype.Display)7 ListNumber (org.diirt.util.array.ListNumber)6 VNumberArray (org.diirt.vtype.VNumberArray)6 VString (org.diirt.vtype.VString)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 PropertyChangeListener (java.beans.PropertyChangeListener)5 Instant (java.time.Instant)5 List (java.util.List)5 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)5 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)4 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ValueIterator (org.csstudio.archive.reader.ValueIterator)3