Search in sources :

Example 11 with AxisConfig

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

the class SampleImportAction method run.

@Override
public void run() {
    // Prompt for file
    final IPath path = SingleSourcePlugin.getUIHelper().openDialog(shell, SWT.OPEN, null, "*", NLS.bind(Messages.ImportActionFileSelectorTitleFmt, description));
    if (path == null)
        return;
    try {
        // Add to first empty axis, or create new axis
        final AxisConfig axis = model.getEmptyAxis().orElseGet(() -> new AddAxisCommand(op_manager, model).getAxis());
        // Add archivedatasource for "import:..." and let that load the file
        final String url = ImportArchiveReaderFactory.createURL(type, path.toString());
        final ArchiveDataSource imported = new ArchiveDataSource(url, 1, type);
        // Add PV Item with data to model
        AddModelItemCommand.forPV(shell, op_manager, model, type, Preferences.getScanPeriod(), axis, imported);
    } catch (Exception ex) {
        ExceptionDetailsErrorDialog.openError(shell, Messages.Error, ex);
    }
}
Also used : AddAxisCommand(org.csstudio.trends.databrowser3.propsheet.AddAxisCommand) IPath(org.eclipse.core.runtime.IPath) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource)

Example 12 with AxisConfig

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

the class ChangeVisibilityCommand method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    final AxisConfig axis = item.getAxis();
    item.setVisible(new_visibility);
    axis.setVisible(item.getModel().get().hasAxisActiveItems(axis));
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig)

Example 13 with AxisConfig

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

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

Example 15 with AxisConfig

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

the class AddPVAction method runWithSuggestedName.

/**
 * Run the 'add PV' dialog with optional defaults
 *  @param name Suggested PV name, for example from drag-n-drop
 *  @param archive Archive data source for the new PV
 *  @return <code>true</code> if PV name was added, <code>false</code> if canceled by user
 */
public boolean runWithSuggestedName(final String name, final ArchiveDataSource archive) {
    // Prompt for PV name
    final AddPVDialog dlg = new AddPVDialog(shell, 1, model, formula);
    dlg.setName(0, name);
    if (dlg.open() != Window.OK)
        return false;
    // Did user select axis?
    final AxisConfig axis;
    if (dlg.getAxisIndex(0) >= 0)
        axis = model.getAxis(dlg.getAxisIndex(0));
    else
        // Use first empty axis, or create a new one
        axis = model.getEmptyAxis().orElseGet(() -> new AddAxisCommand(operations_manager, model).getAxis());
    // Create item
    if (formula) {
        final Optional<AddModelItemCommand> command = AddModelItemCommand.forFormula(shell, operations_manager, model, dlg.getName(0), axis);
        if (!command.isPresent())
            return false;
        // Open configuration dialog
        final FormulaItem formula = (FormulaItem) command.get().getItem();
        final EditFormulaDialog edit = new EditFormulaDialog(operations_manager, shell, formula);
        edit.open();
    } else
        AddModelItemCommand.forPV(shell, operations_manager, model, dlg.getName(0), dlg.getScanPeriod(0), axis, archive);
    return true;
}
Also used : AddAxisCommand(org.csstudio.trends.databrowser3.propsheet.AddAxisCommand) FormulaItem(org.csstudio.trends.databrowser3.model.FormulaItem) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) EditFormulaDialog(org.csstudio.trends.databrowser3.propsheet.EditFormulaDialog)

Aggregations

AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)13 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)8 PVItem (org.csstudio.trends.databrowser3.model.PVItem)5 ArrayList (java.util.ArrayList)4 RGB (org.eclipse.swt.graphics.RGB)3 PrintWriter (java.io.PrintWriter)2 TraceType (org.csstudio.javafx.rtplot.TraceType)2 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)2 FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)2 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)2 RequestType (org.csstudio.trends.databrowser3.model.RequestType)2 AddAxisCommand (org.csstudio.trends.databrowser3.propsheet.AddAxisCommand)2 CellEditor (org.eclipse.jface.viewers.CellEditor)2 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)2 CheckboxCellEditor (org.eclipse.jface.viewers.CheckboxCellEditor)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 ViewerCell (org.eclipse.jface.viewers.ViewerCell)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2