Search in sources :

Example 6 with Model

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

the class OpenDataBrowserPopup method add.

/**
 * Add item
 *  @param model Model to which to add the item
 *  @param pv PV to add
 *  @param archive Archive to use or <code>null</code>
 *  @throws Exception on error
 */
private void add(final Model model, final ProcessVariable pv, final ArchiveDataSource archive) throws Exception {
    final PVItem item = new PVItem(pv.getName(), period);
    if (archive == null)
        item.useDefaultArchiveDataSources();
    else
        item.addArchiveDataSource(archive);
    // Add item to new axis
    item.setAxis(model.addAxis());
    model.addItem(item);
}
Also used : PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 7 with Model

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

the class OpenDataBrowserPopup method execute.

/**
 * {@inheritDoc}
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // Get selection first because the ApplicationContext might change.
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        // This works for double-clicks.
        selection = HandlerUtil.getCurrentSelection(event);
    }
    // Create new editor
    final DataBrowserEditor editor = DataBrowserEditor.createInstance();
    if (editor == null)
        return null;
    // Add received items
    final Model model = editor.getModel();
    try {
        if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() instanceof ChannelInfo) {
            // Received items are from search dialog
            final Object[] channels = ((IStructuredSelection) selection).toArray();
            for (Object channel : channels) {
                final ChannelInfo info = (ChannelInfo) channel;
                add(model, info.getProcessVariable(), info.getArchiveDataSource());
            }
        } else {
            // Add received PVs with default archive data sources
            final List<TimestampedPV> timestampedPVs = Arrays.asList(AdapterUtil.convert(selection, TimestampedPV.class));
            if (!timestampedPVs.isEmpty()) {
                // Add received items, tracking their start..end time
                long start_ms = Long.MAX_VALUE, end_ms = 0;
                for (TimestampedPV timestampedPV : timestampedPVs) {
                    final long time = timestampedPV.getTime();
                    if (time < start_ms)
                        start_ms = time;
                    if (time > end_ms)
                        end_ms = time;
                    final PVItem item = new PVItem(timestampedPV.getName().trim(), period);
                    item.setAxis(model.addAxis());
                    item.useDefaultArchiveDataSources();
                    model.addItem(item);
                }
                final Instant start = Instant.ofEpochMilli(start_ms).minus(Duration.ofMinutes(30));
                final Instant end = Instant.ofEpochMilli(end_ms).plus(Duration.ofMinutes(30));
                model.enableScrolling(false);
                model.setTimerange(start, end);
            } else {
                final ProcessVariable[] pvs = AdapterUtil.convert(selection, ProcessVariable.class);
                for (ProcessVariable pv : pvs) add(model, pv, null);
            }
        }
    } catch (Exception ex) {
        MessageDialog.openError(editor.getSite().getShell(), Messages.Error, NLS.bind(Messages.ErrorFmt, ex.getMessage()));
    }
    return null;
}
Also used : ProcessVariable(org.csstudio.csdata.ProcessVariable) Instant(java.time.Instant) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) TimestampedPV(org.csstudio.csdata.TimestampedPV) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) ISelection(org.eclipse.jface.viewers.ISelection) Model(org.csstudio.trends.databrowser3.model.Model) PVItem(org.csstudio.trends.databrowser3.model.PVItem) DataBrowserEditor(org.csstudio.trends.databrowser3.editor.DataBrowserEditor)

Example 8 with Model

use of org.csstudio.trends.databrowser3.model.Model 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 9 with Model

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

the class DataBrowserWidget method cloneModel.

public Model cloneModel() {
    // XXX: see about copying over live samples from old to new model
    final Model model = new Model();
    model.setMacros(this.getMacrosOrProperties());
    try {
        final InputStream input = this.getFileInputStream();
        new XMLPersistence().load(model, input);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Cannot create copy of data browser", ex);
    }
    return model;
}
Also used : InputStream(java.io.InputStream) DisplayModel(org.csstudio.display.builder.model.DisplayModel) Model(org.csstudio.trends.databrowser3.model.Model) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence)

Example 10 with Model

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

the class ExportTest method speadsheetExport.

/**
 * Export channels in a spreadsheet
 *  @throws Exception on error
 */
@Test
public void speadsheetExport() throws Exception {
    final Model model = getTestModel();
    final ExportJob export = new SpreadsheetExportJob(model, model.getStartTime(), model.getEndTime(), Source.RAW_ARCHIVE, 10, new ValueWithInfoFormatter(Style.Exponential, 3), "/tmp/sheet.dat", this);
    export.run(new SysoutProgressMonitor());
}
Also used : Model(org.csstudio.trends.databrowser3.model.Model) Test(org.junit.Test)

Aggregations

ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)16 Model (org.csstudio.trends.databrowser3.model.Model)15 ArrayList (java.util.ArrayList)10 PVItem (org.csstudio.trends.databrowser3.model.PVItem)10 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)9 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)7 Instant (java.time.Instant)6 InputStream (java.io.InputStream)5 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)5 FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)4 Shell (org.eclipse.swt.widgets.Shell)4 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)3 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)3 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)3 MinSizeTableColumnLayout (org.csstudio.ui.util.MinSizeTableColumnLayout)3 IPath (org.eclipse.core.runtime.IPath)3 Separator (org.eclipse.jface.action.Separator)3 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 PartInitException (org.eclipse.ui.PartInitException)3