Search in sources :

Example 1 with PlotSamples

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

the class ControllerDemo method debug.

protected void debug() {
    for (ModelItem item : model.getItems()) {
        if (!(item instanceof PVItem)) {
            continue;
        }
        System.out.println("\n" + item.getName() + ":");
        final PlotSamples samples = item.getSamples();
        samples.getLock().lock();
        try {
            if (samples.size() <= 0)
                continue;
            Instant last = samples.get(0).getPosition();
            for (int s = 0; s < samples.size(); ++s) {
                final PlotSample sample = samples.get(s);
                System.out.println(sample);
                final Instant time = sample.getPosition();
                if (time.compareTo(last) < 0) {
                    System.out.println("Time sequence error!");
                    break;
                }
                last = time;
            }
        } finally {
            samples.getLock().unlock();
        }
    }
    new XMLPersistence().write(model, System.out);
}
Also used : Instant(java.time.Instant) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) PVItem(org.csstudio.trends.databrowser3.model.PVItem) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples)

Example 2 with PlotSamples

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

the class PlotDemo method createGUI.

// final private PlotListener listener = new PlotListener()
// {
// @Override
// public void scrollRequested(final boolean enable_scrolling)
// {
// System.out.println("Scroll enabled: " + enable_scrolling);
// scroll = enable_scrolling;
// }
// 
// @Override
// public void timeConfigRequested()
// {
// System.out.println("Time Config requested");
// }
// 
// @Override
// public void timeAxisChanged(final long start_ms, final long end_ms)
// {
// start_time = TimestampHelper.fromMillisecs(start_ms);
// end_time = TimestampHelper.fromMillisecs(end_ms);
// System.out.println("Time axis: " + start_time + " ... " + end_time);
// }
// 
// @Override
// public void valueAxisChanged(final int index, final double lower, final double upper)
// {
// System.out.println("Value axis " + index + ": " + lower + " ... " + upper);
// }
// 
// @Override
// public void droppedName(final String name)
// {
// System.out.println("Name dropped: " + name);
// }
// 
// @Override
// public void droppedPVName(final ProcessVariable name, final ArchiveDataSource archive)
// {
// System.out.println("PV Name dropped: " + name);
// }
// 
// @Override
// public void droppedFilename(final String file_name)
// {
// System.out.println("File Name dropped: " + file_name);
// }
// 
// @Override
// public void xyGraphConfigChanged(XYGraph newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void removeAnnotationChanged(Annotation oldValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void addAnnotationChanged(Annotation newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void backgroundColorChanged(Color newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void timeAxisForegroundColorChanged(Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisForegroundColorChanged(int index, Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisTitleChanged(int index, String oldTitle,
// String newTitle) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisAutoScaleChanged(int index, boolean oldAutoScale,
// boolean newAutoScale) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceNameChanged(int index, String oldName, String newName) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceYAxisChanged(int index, AxisConfig oldConfig,
// AxisConfig config) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceTypeChanged(int index, TraceType old,
// TraceType newTraceType) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceColorChanged(int index, Color old, Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisLogScaleChanged(int index, boolean old,
// boolean logScale) {
// // TODO Auto-generated method stub
// 
// }
// };
private void createGUI(final Composite parent) {
    final GridLayout layout = new GridLayout(1, false);
    parent.setLayout(layout);
    ModelBasedPlot plot;
    try {
        plot = new ModelBasedPlot(true);
    } catch (Exception e1) {
        e1.printStackTrace();
        return;
    }
    final FXCanvas canvas = new FXCanvas(parent, SWT.NONE);
    canvas.setScene(new Scene(plot.getPlot()));
    canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    // [Done] button to end demo
    final Button ok = new Button(parent, SWT.PUSH);
    ok.setText("Done");
    ok.setLayoutData(new GridData(SWT.RIGHT, 0, true, false));
    ok.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            run = false;
        }
    });
    // plot.addListener(listener);
    // Create demo samples
    final List<PlotSample> values = new ArrayList<PlotSample>();
    for (int i = 1; i < 10; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
    values.add(new PlotSample("Test", TestHelper.makeError(15, "Disconnected")));
    // Single value. Line should continue until the following 'disconnect'.
    values.add(new PlotSample("Test", TestHelper.makeValue(17)));
    values.add(new PlotSample("Test", TestHelper.makeError(18, "Disconnected")));
    for (int i = 20; i < 30; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
    final PlotSampleArray samples = new PlotSampleArray();
    samples.set(values);
    // Add item with demo samples
    final ModelItem item = new ModelItem("Demo") {

        @Override
        public PlotSamples getSamples() {
            return samples;
        }

        @Override
        public void write(final PrintWriter writer) {
        // NOP
        }
    };
    // TODO: Fix or remove
    // item.setColor(new RGB(0, 0, 255));
    plot.addTrace(item);
// start_time = VTypeHelper.getTimestamp(samples.getSample(0).getValue());
// end_time = VTypeHelper.getTimestamp(samples.getSample(samples.getSize()-1).getValue());
// plot.setTimeRange(start_time, end_time);
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) Scene(javafx.scene.Scene) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) PlotSampleArray(org.csstudio.trends.databrowser3.model.PlotSampleArray) FXCanvas(javafx.embed.swt.FXCanvas) PrintWriter(java.io.PrintWriter)

Example 3 with PlotSamples

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

the class AdapterFactory method convertToPvWithSamples.

/**
 * Create copy of data array for use outside of the data browser
 *  @param item {@link ModelItem}
 *  @return {@link ProcessVariableWithSamples} for the model item
 */
private ProcessVariableWithSamples convertToPvWithSamples(final ModelItem item) {
    final PlotSamples plot_samples = item.getSamples();
    try {
        if (!plot_samples.getLock().tryLock(10, TimeUnit.SECONDS))
            throw new TimeoutException("Cannot lock data for " + item + ": " + plot_samples);
        try {
            final int size = plot_samples.size();
            final VType[] samples = new VType[size];
            for (int i = 0; i < size; ++i) samples[i] = plot_samples.get(i).getVType();
            return new ProcessVariableWithSamples(new ProcessVariable(item.getName()), samples);
        } finally {
            plot_samples.getLock().unlock();
        }
    } catch (Exception ex) {
        logger.log(Level.WARNING, "AdapterFactory cannot lock data for " + item + ": " + plot_samples);
        return null;
    }
}
Also used : VType(org.diirt.vtype.VType) ProcessVariable(org.csstudio.csdata.ProcessVariable) TimeoutException(java.util.concurrent.TimeoutException) PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with PlotSamples

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

the class ArchiveFetchJobTest method fetchCompleted.

@Override
public void fetchCompleted(final ArchiveFetchJob job) {
    System.out.println("Completed " + job);
    final PlotSamples samples = item.getSamples();
    System.out.println(samples);
    got_anything = samples.size() > 0;
}
Also used : PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples)

Example 5 with PlotSamples

use of org.csstudio.trends.databrowser3.model.PlotSamples 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)

Aggregations

PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)5 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)3 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)2 VType (org.diirt.vtype.VType)2 PrintWriter (java.io.PrintWriter)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1 FXCanvas (javafx.embed.swt.FXCanvas)1 Scene (javafx.scene.Scene)1 ProcessVariable (org.csstudio.csdata.ProcessVariable)1 TimeDataSearch (org.csstudio.javafx.rtplot.data.TimeDataSearch)1 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)1 PVItem (org.csstudio.trends.databrowser3.model.PVItem)1 PlotSampleArray (org.csstudio.trends.databrowser3.model.PlotSampleArray)1 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)1 VNumberArray (org.diirt.vtype.VNumberArray)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1