Search in sources :

Example 6 with ModelItem

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

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

the class SampleView method update.

/**
 * Update combo box of this view.
 * @param model_changed set true if the model was changed.
 */
private void update(final boolean model_changed) {
    if (model == null) {
        // Clear/disable GUI
        items.setItems(new String[] { Messages.SampleView_NoPlot });
        items.select(0);
        items.setEnabled(false);
        sample_table.setInput(null);
        return;
    }
    // Show PV names.
    // Also build array for following index-based check of selected item
    final List<ModelItem> model_items = new ArrayList<>();
    final List<String> names_list = new ArrayList<>();
    names_list.add(Messages.SampleView_SelectItem);
    for (ModelItem item : model.getItems()) {
        model_items.add(item);
        names_list.add(item.getName());
    }
    final String[] names = names_list.toArray(new String[names_list.size()]);
    if (!model_changed && items.getSelectionIndex() > 0) {
        // Is the previously selected item still valid?
        if (sample_table.getInput() instanceof ModelItem) {
            final ModelItem selected_item = (ModelItem) sample_table.getInput();
            if (model_items.indexOf(selected_item) != -1) {
                // Show same PV name again in combo box
                items.setItems(names);
                items.select(model_items.indexOf(selected_item) + 1);
                items.setEnabled(true);
                // Update sample table size. Not locking for size()
                sample_table.setItemCount(selected_item.getSamples().size());
                sample_table.refresh();
                return;
            }
        }
    }
    // Previously selected item no longer valid.
    // Show new items, clear rest
    items.setItems(names);
    items.select(0);
    items.setEnabled(true);
    sample_table.setInput(null);
}
Also used : ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem)

Example 8 with ModelItem

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

the class ControllerBase method getArchivedData.

/**
 * Initiate archive data retrieval for all model items
 *  @param start Start time
 *  @param end End time
 */
private void getArchivedData() {
    final Instant start = model.getStartTime();
    final Instant end = model.getEndTime();
    for (ModelItem item : model.getItems()) getArchivedData(item, start, end);
}
Also used : Instant(java.time.Instant) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem)

Example 9 with ModelItem

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

the class ControllerBase method createPlotTraces.

/**
 * (Re-) create traces in plot for each item in the model
 */
public void createPlotTraces() {
    plot.removeAll();
    int i = 0;
    for (AxisConfig axis : model.getAxes()) plot.updateAxis(i++, axis);
    for (ModelItem item : model.getItems()) if (item.isVisible())
        plot.addTrace(item);
    setAxisFonts();
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem)

Example 10 with ModelItem

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

the class WaveformView method update.

/**
 * Update combo box of this view.
 *  Since it interacts with the UI run on the UI thread.
 *  @param model_changed Is this a different model?
 */
private void update(final boolean model_changed) {
    pv_name.getDisplay().asyncExec(() -> {
        if (pv_name.isDisposed())
            return;
        if (model == null) {
            // Clear/disable GUI
            pv_name.setItems(new String[] { Messages.SampleView_NoPlot });
            pv_name.select(0);
            pv_name.setEnabled(false);
            selectPV(null);
            return;
        }
        // Show PV names
        final List<String> names_list = new ArrayList<>();
        names_list.add(Messages.SampleView_SelectItem);
        for (ModelItem item : model.getItems()) names_list.add(item.getName());
        final String[] names = names_list.toArray(new String[names_list.size()]);
        // Is the previously selected item still valid?
        final int selected = pv_name.getSelectionIndex();
        if (!model_changed && selected > 0 && model_item != null && pv_name.getText().equals(model_item.getName())) {
            // Show same PV name again in combo box
            pv_name.setItems(names);
            pv_name.select(selected);
            pv_name.setEnabled(true);
            return;
        }
        // Previously selected item no longer valid.
        // Show new items, clear rest
        pv_name.setItems(names);
        pv_name.select(0);
        pv_name.setEnabled(true);
        selectPV(null);
    });
}
Also used : ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem)

Aggregations

ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)23 ArrayList (java.util.ArrayList)12 PVItem (org.csstudio.trends.databrowser3.model.PVItem)10 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)7 VType (org.diirt.vtype.VType)6 Instant (java.time.Instant)5 ValueIterator (org.csstudio.archive.reader.ValueIterator)5 Model (org.csstudio.trends.databrowser3.model.Model)4 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)4 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)3 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)3 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 PrintWriter (java.io.PrintWriter)2 InputItem (org.csstudio.apputil.ui.formula.InputItem)2 TraceType (org.csstudio.javafx.rtplot.TraceType)2 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)2 RequestType (org.csstudio.trends.databrowser3.model.RequestType)2 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)2