示例#1
0
  /**
   * Add item to the model.
   *
   * <p>If the item has no color, this will define its color based on the model's next available
   * color.
   *
   * <p>If the model is already 'running', the item will be 'start'ed.
   *
   * @param item {@link ModelItem} to add
   * @throws RuntimeException if item is already in model
   * @throws Exception on error trying to start a PV Item that's added to a running model
   */
  public void addItem(final ModelItem item) throws Exception {
    // A new item with the same PV name are allowed to be added in the
    // model. This way Data Browser can show the trend of the same PV
    // in different axes or with different waveform indexes. For example,
    // one may want to show the first element of epics://aaa:bbb in axis 1
    // while showing the third element of the same PV in axis 2 to compare
    // their trends in one chart.
    //
    // if (getItem(item.getName()) != null)
    //        throw new RuntimeException("Item " + item.getName() + " already in Model");

    // But, if exactly the same instance of the given ModelItem already exists in this
    // model, it will not be added.
    if (items.indexOf(item) != -1)
      throw new RuntimeException("Item " + item.getName() + " already in Model");

    // Assign default color
    if (item.getColor() == null) item.setColor(getNextItemColor());

    // Force item to be on an axis
    if (item.getAxis() == null) {
      if (axes.size() == 0) addAxis(item.getDisplayName());
      item.setAxis(axes.get(0));
    }
    // Check item axis
    if (!axes.contains(item.getAxis()))
      throw new Exception("Item " + item.getName() + " added with invalid axis " + item.getAxis());

    // Add to model
    items.add(item);
    item.setModel(this);
    if (is_running && item instanceof PVItem) ((PVItem) item).start(scanner);
    // Notify listeners of new item
    for (ModelListener listener : listeners) listener.itemAdded(item);
  }
示例#2
0
 /**
  * Add value axis with default settings
  *
  * @return Newly added axis configuration
  */
 public AxisConfig addAxis(String name) {
   if (name == null) name = NLS.bind(Messages.Plot_ValueAxisNameFMT, getAxisCount() + 1);
   final AxisConfig axis = new AxisConfig(name);
   axis.setColor(getNextItemColor());
   addAxis(axis);
   return axis;
 }
示例#3
0
  /**
   * Load model
   *
   * @param doc DOM document
   * @throws Exception on error
   * @throws RuntimeException if model was already in use
   */
  private void loadFromDocument(final Document doc) throws Exception {
    if (is_running || items.size() > 0) 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("Wrong document type");

    synchronized (this) {
      scroll_enabled = DOMHelper.getSubelementBoolean(root_node, TAG_SCROLL, scroll_enabled);
    }
    update_period = DOMHelper.getSubelementDouble(root_node, TAG_UPDATE_PERIOD, update_period);

    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) {
      final StartEndTimeParser times = new StartEndTimeParser(start, end);
      setTimerange(
          TimestampHelper.fromCalendar(times.getStart()),
          TimestampHelper.fromCalendar(times.getEnd()));
    }

    RGB color = loadColorFromDocument(root_node, TAG_BACKGROUND);
    if (color != null) background = color;

    try {
      archive_rescale =
          ArchiveRescale.valueOf(DOMHelper.getSubelementString(root_node, TAG_ARCHIVE_RESCALE));
    } catch (Throwable ex) {
      archive_rescale = ArchiveRescale.STAGGER;
    }

    // Load Time Axis
    final Element timeAxisNode =
        DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_TIME_AXIS);
    if (timeAxisNode != null) {
      // Load PV items
      Element axisNode = DOMHelper.findFirstElementNode(timeAxisNode.getFirstChild(), TAG_AXIS);
      timeAxis = AxisConfig.fromDocument(axisNode);
    }

    // Load value Axes
    Element list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_AXES);
    if (list != null) {
      // Load PV items
      Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_AXIS);
      while (item != null) {
        addAxis(AxisConfig.fromDocument(item));
        item = DOMHelper.findNextElementNode(item, TAG_AXIS);
      }
    }

    // Load Annotations
    list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_ANNOTATIONS);
    if (list != null) {
      // Load PV items
      Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_ANNOTATION);
      final List<AnnotationInfo> infos = new ArrayList<AnnotationInfo>();
      try {
        while (item != null) {
          final AnnotationInfo annotation = AnnotationInfo.fromDocument(item);
          infos.add(annotation);
          item = DOMHelper.findNextElementNode(item, TAG_ANNOTATION);
        }
      } catch (Throwable ex) {
        Activator.getLogger().log(Level.INFO, "XML error in Annotation", ex);
      }
      // Add to document
      annotations = infos.toArray(new AnnotationInfo[infos.size()]);
    }

    // ADD by Laurent PHILIPPE
    // Load Title and graph settings
    try {
      graphSettings = XYGraphSettingsXMLUtil.fromDocument(root_node.getFirstChild());
    } catch (Throwable ex) {
      Activator.getLogger().log(Level.INFO, "XML error in Title or  graph settings", ex);
    }

    // Backwards compatibility with previous data browser which
    // used global buffer size for all PVs
    final int buffer_size =
        DOMHelper.getSubelementInt(root_node, Model.TAG_LIVE_SAMPLE_BUFFER_SIZE, -1);

    // 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(this, item);
        if (buffer_size > 0) model_item.setLiveCapacity(buffer_size);
        // Adding item creates the axis for it if not already there
        addItem(model_item);
        // Backwards compatibility with previous data browser which
        // 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, Model.TAG_MIN, axis.getMin());
        final double max = DOMHelper.getSubelementDouble(item, Model.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) {
        addItem(FormulaItem.fromDocument(this, item));
        item = DOMHelper.findNextElementNode(item, TAG_FORMULA);
      }
    }
  }