/**
  * Register and perform the command
  *
  * @param operations_manager OperationsManager where command will be reg'ed
  * @param item Model item to configure
  * @param new_index New value
  */
 public ChangeWaveformIndexCommand(
     final OperationsManager operations_manager, final ModelItem item, final int new_index) {
   this.item = item;
   this.old_index = item.getWaveformIndex();
   this.new_index = new_index;
   operations_manager.addCommand(this);
   redo();
 }
示例#2
0
  /**
   * 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);
  }
示例#3
0
  /**
   * 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 Set<String> existing_names = new HashSet<>();
    for (ModelItem item : model.getItems()) existing_names.add(item.getName());
    final List<AxisConfig> axes = new ArrayList<>();
    final List<String> axes_names = new ArrayList<>();
    for (AxisConfig axis : model.getAxes()) {
      axes.add(axis);
      axes_names.add(axis.getName());
    }
    final AddPVDialog dlg = new AddPVDialog(shell, existing_names, axes_names, formula);
    dlg.setName(name);
    if (dlg.open() != Window.OK) return false;

    // Did user select axis?
    final AxisConfig axis;
    if (dlg.getAxisIndex() >= 0) axis = axes.get(dlg.getAxisIndex());
    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(), 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(), dlg.getScanPeriod(), axis, archive);
    return true;
  }
 /**
  * Initialize
  *
  * @param item Item from which to get samples /** @param start Start time /** @param end End time
  */
 public ModelSampleIterator(final ModelItem item, final Instant start, final Instant end) {
   this.samples = item.getSamples();
   this.end = end;
   samples.getLock().lock();
   try {
     // Anything?
     if (samples.size() <= 0) index = -1;
     // All data after start time?
     else if (samples.get(0).getPosition().compareTo(start) >= 0) index = 0;
     else { // There is data before the start time. Find sample just before start time.
       index = findSampleLessOrEqual(start);
     }
     // Is first sample already after end time?
     if (index >= 0) {
       final PlotSample sample = samples.get(index);
       value = sample.getVType();
       if (sample.getPosition().compareTo(end) > 0) index = -1;
     }
   } finally {
     samples.getLock().unlock();
   }
 }
示例#5
0
  /** {@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(VTypeHelper.getTimestamp(value).toDate())
                + "';");
        // 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.getDisplayName().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 + ");");
    }
  }
 /** {@inheritDoc} */
 @Override
 public void undo() {
   item.setWaveformIndex(old_index);
 }
 /** {@inheritDoc} */
 @Override
 public void redo() {
   item.setWaveformIndex(new_index);
 }