Search in sources :

Example 1 with AnnotationInfo

use of org.csstudio.trends.databrowser3.model.AnnotationInfo in project org.csstudio.display.builder by kasemir.

the class ControllerBase method start.

/**
 * Start model items and initiate scrolling/updates
 *  @throws Exception on error: Already running, problem starting threads, ...
 *  @see #isRunning()
 */
public void start() throws Exception {
    if (isRunning())
        throw new IllegalStateException("Already started");
    plot.getPlot().setBackground(SWTMediaPool.getJFX(model.getPlotBackground()));
    plot.getPlot().getXAxis().setGridVisible(model.isGridVisible());
    plot.getPlot().showToolbar(model.isToolbarVisible());
    plot.getPlot().showLegend(model.isLegendVisible());
    plot.getPlot().setTitleFont(SWTMediaPool.getJFX(model.getTitleFont()));
    plot.getPlot().setLegendFont(SWTMediaPool.getJFX(model.getLegendFont()));
    String title = model.getTitle().orElse(null);
    if (title != null)
        title = model.resolveMacros(title);
    plot.getPlot().setTitle(title);
    plot.getPlot().setScrollStep(model.getScrollStep());
    final List<Trace<Instant>> traces = new ArrayList<>();
    for (Trace<Instant> trace : plot.getPlot().getTraces()) traces.add(trace);
    for (AnnotationInfo info : model.getAnnotations()) {
        final Trace<Instant> trace = traces.get(info.getItemIndex());
        final Annotation<Instant> annotation = new Annotation<Instant>(info.isInternal(), trace, info.getTime(), info.getValue(), info.getOffset(), info.getText());
        plot.getPlot().addAnnotation(annotation);
    }
    createUpdateTask();
    model.start();
    // Initial time range setup, schedule archive fetch
    if (!model.isScrollEnabled())
        plot.getPlot().setScrolling(false);
    model_listener.changedTimerange();
}
Also used : Trace(org.csstudio.javafx.rtplot.Trace) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Annotation(org.csstudio.javafx.rtplot.Annotation) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo)

Example 2 with AnnotationInfo

use of org.csstudio.trends.databrowser3.model.AnnotationInfo in project org.csstudio.display.builder by kasemir.

the class WaveformView method userMovedAnnotation.

private void userMovedAnnotation() {
    if (waveform_annotation == null)
        return;
    for (AnnotationInfo annotation : model.getAnnotations()) {
        // Locate the annotation for this waveform
        if (annotation.isInternal() && annotation.getItemIndex() == waveform_annotation.getItemIndex() && annotation.getText().equals(waveform_annotation.getText())) {
            // Locate index of sample for annotation's time stamp
            final PlotSamples samples = model_item.getSamples();
            final TimeDataSearch search = new TimeDataSearch();
            final int idx;
            samples.getLock().lock();
            try {
                idx = search.findClosestSample(samples, annotation.getTime());
            } finally {
                samples.getLock().unlock();
            }
            // Update waveform view for that sample on UI thread
            sample_index.getDisplay().asyncExec(() -> {
                sample_index.setSelection(idx);
                showSelectedSample();
            });
            return;
        }
    }
}
Also used : TimeDataSearch(org.csstudio.javafx.rtplot.data.TimeDataSearch) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo) PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples)

Example 3 with AnnotationInfo

use of org.csstudio.trends.databrowser3.model.AnnotationInfo in project org.csstudio.display.builder by kasemir.

the class ModelBasedPlot method setAnnotations.

/**
 * Set annotations in plot to match model's annotations
 *  @param newAnnotations Annotations to show in plot
 */
void setAnnotations(final Collection<AnnotationInfo> newAnnotations) {
    final List<Trace<Instant>> traces = new ArrayList<>();
    for (Trace<Instant> trace : plot.getTraces()) traces.add(trace);
    // Remove old annotations from plot
    final List<Annotation<Instant>> plot_annotations = new ArrayList<>(plot.getAnnotations());
    for (Annotation<Instant> old : plot_annotations) plot.removeAnnotation(old);
    // Set new annotations in plot
    for (AnnotationInfo annotation : newAnnotations) plot.addAnnotation(new Annotation<Instant>(annotation.isInternal(), traces.get(annotation.getItemIndex()), annotation.getTime(), annotation.getValue(), annotation.getOffset(), annotation.getText()));
}
Also used : Trace(org.csstudio.javafx.rtplot.Trace) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Annotation(org.csstudio.javafx.rtplot.Annotation) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo)

Example 4 with AnnotationInfo

use of org.csstudio.trends.databrowser3.model.AnnotationInfo in project org.csstudio.display.builder by kasemir.

the class XMLPersistence method write.

/**
 * Write XML formatted Model content.
 *  @param model Model to write
 *  @param out OutputStream, will NOT be closed when done.
 */
public void write(final Model model, final OutputStream out) {
    final PrintWriter writer = new PrintWriter(out);
    XMLWriter.header(writer);
    XMLWriter.start(writer, 0, TAG_DATABROWSER);
    writer.println();
    XMLWriter.XML(writer, 1, TAG_TITLE, model.getTitle().orElse(""));
    XMLWriter.XML(writer, 1, TAG_SAVE_CHANGES, model.shouldSaveChanges());
    // Visibility of toolbar and legend
    XMLWriter.XML(writer, 1, TAG_SHOW_LEGEND, model.isLegendVisible());
    XMLWriter.XML(writer, 1, TAG_SHOW_TOOLBAR, model.isToolbarVisible());
    // Time axis
    XMLWriter.XML(writer, 1, TAG_GRID, model.isGridVisible());
    XMLWriter.XML(writer, 1, TAG_SCROLL, model.isScrollEnabled());
    XMLWriter.XML(writer, 1, TAG_UPDATE_PERIOD, model.getUpdatePeriod());
    XMLWriter.XML(writer, 1, TAG_SCROLL_STEP, model.getScrollStep().getSeconds());
    XMLWriter.XML(writer, 1, TAG_START, model.getStartSpec());
    XMLWriter.XML(writer, 1, TAG_END, model.getEndSpec());
    XMLWriter.XML(writer, 1, TAG_ARCHIVE_RESCALE, model.getArchiveRescale().name());
    writeColor(writer, 1, TAG_BACKGROUND, model.getPlotBackground());
    XMLWriter.XML(writer, 1, TAG_TITLE_FONT, SWTMediaPool.getFontDescription(model.getTitleFont()));
    XMLWriter.XML(writer, 1, TAG_LABEL_FONT, SWTMediaPool.getFontDescription(model.getLabelFont()));
    XMLWriter.XML(writer, 1, TAG_SCALE_FONT, SWTMediaPool.getFontDescription(model.getScaleFont()));
    XMLWriter.XML(writer, 1, TAG_LEGEND_FONT, SWTMediaPool.getFontDescription(model.getLegendFont()));
    // Value axes
    XMLWriter.start(writer, 1, TAG_AXES);
    writer.println();
    for (AxisConfig axis : model.getAxes()) axis.write(writer);
    XMLWriter.end(writer, 1, TAG_AXES);
    writer.println();
    // Annotations
    XMLWriter.start(writer, 1, TAG_ANNOTATIONS);
    writer.println();
    for (AnnotationInfo annotation : model.getAnnotations()) annotation.write(writer);
    XMLWriter.end(writer, 1, TAG_ANNOTATIONS);
    writer.println();
    // PVs (Formulas)
    XMLWriter.start(writer, 1, TAG_PVLIST);
    writer.println();
    for (ModelItem item : model.getItems()) item.write(writer);
    XMLWriter.end(writer, 1, TAG_PVLIST);
    writer.println();
    XMLWriter.end(writer, 0, TAG_DATABROWSER);
    writer.flush();
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) PrintWriter(java.io.PrintWriter) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo)

Example 5 with AnnotationInfo

use of org.csstudio.trends.databrowser3.model.AnnotationInfo in project org.csstudio.display.builder by kasemir.

the class XMLPersistence method load.

private void load(final Model model, final Document doc) throws Exception {
    if (model.getItems().iterator().hasNext())
        throw new RuntimeException("Model was already in use");
    // Check if it's a <databrowser/>.
    doc.getDocumentElement().normalize();
    final Element root_node = doc.getDocumentElement();
    if (!root_node.getNodeName().equals(TAG_DATABROWSER))
        throw new Exception("Expected " + TAG_DATABROWSER + " but got " + root_node.getNodeName());
    // Global settings
    String title = DOMHelper.getSubelementString(root_node, TAG_TITLE);
    if (!title.isEmpty())
        model.setTitle(title);
    model.setSaveChanges(DOMHelper.getSubelementBoolean(root_node, TAG_SAVE_CHANGES, true));
    model.setGridVisible(DOMHelper.getSubelementBoolean(root_node, TAG_GRID, false));
    model.enableScrolling(DOMHelper.getSubelementBoolean(root_node, TAG_SCROLL, true));
    model.setUpdatePeriod(DOMHelper.getSubelementDouble(root_node, TAG_UPDATE_PERIOD, Preferences.getUpdatePeriod()));
    try {
        model.setScrollStep(Duration.ofSeconds(DOMHelper.getSubelementInt(root_node, TAG_SCROLL_STEP, (int) Preferences.getScrollStep().getSeconds())));
    } catch (Throwable ex) {
    // Ignore
    }
    final String start = DOMHelper.getSubelementString(root_node, TAG_START);
    final String end = DOMHelper.getSubelementString(root_node, TAG_END);
    if (start.length() > 0 && end.length() > 0)
        model.setTimerange(start, end);
    final String rescale = DOMHelper.getSubelementString(root_node, TAG_ARCHIVE_RESCALE, ArchiveRescale.STAGGER.name());
    try {
        model.setArchiveRescale(ArchiveRescale.valueOf(rescale));
    } catch (Throwable ex) {
    // Ignore
    }
    model.setToolbarVisible(DOMHelper.getSubelementBoolean(root_node, TAG_SHOW_TOOLBAR, true));
    model.setLegendVisible(DOMHelper.getSubelementBoolean(root_node, TAG_SHOW_LEGEND, true));
    // Value Axes
    Element list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_AXES);
    if (list != null) {
        Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_AXIS);
        while (item != null) {
            model.addAxis(AxisConfig.fromDocument(item));
            item = DOMHelper.findNextElementNode(item, TAG_AXIS);
        }
    } else {
        // Check for legacy <xyGraphSettings> <axisSettingsList>
        list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_OLD_XYGRAPH_SETTINGS);
        if (list != null) {
            loadColorFromDocument(list, "plotAreaBackColor").ifPresent(model::setPlotBackground);
            Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), "axisSettingsList");
            if (item != null) {
                // First axis is 'X'
                model.setGridVisible(DOMHelper.getSubelementBoolean(item, "showMajorGrid", false));
                // Read 'Y' axes
                item = DOMHelper.findNextElementNode(item, "axisSettingsList");
                while (item != null) {
                    final String name = DOMHelper.getSubelementString(item, "title", null);
                    final AxisConfig axis = new AxisConfig(name);
                    loadColorFromDocument(item, "foregroundColor").ifPresent(axis::setColor);
                    axis.setGridVisible(DOMHelper.getSubelementBoolean(item, "showMajorGrid", false));
                    axis.setLogScale(DOMHelper.getSubelementBoolean(item, "logScale", false));
                    axis.setAutoScale(DOMHelper.getSubelementBoolean(item, "autoScale", false));
                    final Element range = DOMHelper.findFirstElementNode(item.getFirstChild(), "range");
                    if (range != null) {
                        double min = DOMHelper.getSubelementDouble(range, "lower", axis.getMin());
                        double max = DOMHelper.getSubelementDouble(range, "upper", axis.getMax());
                        axis.setRange(min, max);
                    }
                    model.addAxis(axis);
                    // Using legacy settings from _last_ axis for fonts
                    loadFontFromDocument(item, "scaleFont").ifPresent(model::setScaleFont);
                    loadFontFromDocument(item, "titleFont").ifPresent(model::setLabelFont);
                    item = DOMHelper.findNextElementNode(item, "axisSettingsList");
                }
            }
        }
    }
    // New settings, possibly replacing settings from legacy <xyGraphSettings> <axisSettingsList>
    loadColorFromDocument(root_node, TAG_BACKGROUND).ifPresent(model::setPlotBackground);
    loadFontFromDocument(root_node, TAG_TITLE_FONT).ifPresent(model::setTitleFont);
    loadFontFromDocument(root_node, TAG_LABEL_FONT).ifPresent(model::setLabelFont);
    loadFontFromDocument(root_node, TAG_SCALE_FONT).ifPresent(model::setScaleFont);
    loadFontFromDocument(root_node, TAG_LEGEND_FONT).ifPresent(model::setLegendFont);
    // Load Annotations
    list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_ANNOTATIONS);
    if (list != null) {
        // Load PV items
        final List<AnnotationInfo> annotations = new ArrayList<>();
        Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_ANNOTATION);
        while (item != null) {
            try {
                annotations.add(AnnotationInfo.fromDocument(item));
            } catch (Throwable ex) {
                Activator.getLogger().log(Level.INFO, "XML error in Annotation", ex);
            }
            item = DOMHelper.findNextElementNode(item, TAG_ANNOTATION);
        }
        model.setAnnotations(annotations);
    }
    // Load PVs/Formulas
    list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_PVLIST);
    if (list != null) {
        // Load PV items
        Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_PV);
        while (item != null) {
            final PVItem model_item = PVItem.fromDocument(model, item);
            // Adding item creates the axis for it if not already there
            model.addItem(model_item);
            // Ancient data browser stored axis configuration with each item: Update axis from that.
            final AxisConfig axis = model_item.getAxis();
            String s = DOMHelper.getSubelementString(item, TAG_AUTO_SCALE);
            if (s.equalsIgnoreCase("true"))
                axis.setAutoScale(true);
            s = DOMHelper.getSubelementString(item, TAG_LOG_SCALE);
            if (s.equalsIgnoreCase("true"))
                axis.setLogScale(true);
            final double min = DOMHelper.getSubelementDouble(item, TAG_MIN, axis.getMin());
            final double max = DOMHelper.getSubelementDouble(item, TAG_MAX, axis.getMax());
            axis.setRange(min, max);
            item = DOMHelper.findNextElementNode(item, TAG_PV);
        }
        // Load Formulas
        item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_FORMULA);
        while (item != null) {
            model.addItem(FormulaItem.fromDocument(model, item));
            item = DOMHelper.findNextElementNode(item, TAG_FORMULA);
        }
    }
    // Update items from legacy <xyGraphSettings>
    list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_OLD_XYGRAPH_SETTINGS);
    if (list != null) {
        title = DOMHelper.getSubelementString(list, TAG_TITLE);
        if (!title.isEmpty())
            model.setTitle(title);
        final Iterator<ModelItem> model_items = model.getItems().iterator();
        Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), "traceSettingsList");
        while (item != null) {
            if (!model_items.hasNext())
                break;
            final ModelItem pv = model_items.next();
            Optional<RGB> rgb = loadColorFromDocument(item, "traceColor");
            if (rgb.isPresent()) {
                pv.setColor(SWTMediaPool.getJFX(rgb.get()));
            }
            pv.setLineWidth(DOMHelper.getSubelementInt(item, "lineWidth", pv.getLineWidth()));
            pv.setDisplayName(DOMHelper.getSubelementString(item, "name", pv.getDisplayName()));
            item = DOMHelper.findNextElementNode(item, "traceSettingsList");
        }
    }
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) RGB(org.eclipse.swt.graphics.RGB) PVItem(org.csstudio.trends.databrowser3.model.PVItem) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo)

Aggregations

AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)6 ArrayList (java.util.ArrayList)4 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)3 Instant (java.time.Instant)2 Annotation (org.csstudio.javafx.rtplot.Annotation)2 Trace (org.csstudio.javafx.rtplot.Trace)2 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)2 PrintWriter (java.io.PrintWriter)1 Point2D (javafx.geometry.Point2D)1 TimeDataSearch (org.csstudio.javafx.rtplot.data.TimeDataSearch)1 PVItem (org.csstudio.trends.databrowser3.model.PVItem)1 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)1 RGB (org.eclipse.swt.graphics.RGB)1 Element (org.w3c.dom.Element)1