Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Added the TimeSliderComposite to the VisItPlotRender and hooked it up to
Browse files Browse the repository at this point in the history
the associated VisIt widget.

Signed-off-by: Jordan Deyton <deytonjh@ornl.gov>
  • Loading branch information
Jordan Deyton committed Jun 22, 2015
1 parent 7c49e82 commit d793df6
Showing 1 changed file with 83 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
import gov.lbnl.visit.swt.VisItSwtConnection;
import gov.lbnl.visit.swt.VisItSwtWidget;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import org.eclipse.ice.client.common.ActionTree;
import org.eclipse.ice.viz.service.connections.ConnectionPlotRender;
Expand All @@ -25,6 +29,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
Expand Down Expand Up @@ -78,8 +84,27 @@ public class VisItPlotRender extends ConnectionPlotRender<VisItSwtConnection> {
*/
private String plotType;

/**
* The widget used to adjust the current timestep.
*/
private TimeSliderComposite timeSlider;

/**
* The currently timestep rendered by the VisIt widget.
*/
private int renderedTimestep = 0;
/**
* The current timestep as reported by the {@link #timeSlider} on the UI
* thread.
*/
private final AtomicInteger widgetTimestep = new AtomicInteger();
/**
* An ExecutorService for launching worker threads. Only one thread is
* processed at a time in the order in which they are added.
*/
private final ExecutorService executorService = Executors
.newSingleThreadExecutor();

/**
* The plot {@code Composite} that renders the files through the VisIt
* connection.
Expand Down Expand Up @@ -138,7 +163,7 @@ protected String getPreferenceNodeID() {
*/
@Override
protected Composite createPlotComposite(Composite parent, int style,
VisItSwtConnection connection) throws Exception {
final VisItSwtConnection connection) throws Exception {

// Create a new window on the VisIt server if one does not already
// exist. We will need the corresponding connection and a window ID. If
Expand Down Expand Up @@ -192,11 +217,63 @@ public void menuShown(MenuEvent e) {

canvas.setMenu(menu);

// TODO Add this back in when it's functional.
// timeSlider = new TimeSliderComposite(container, SWT.NONE);
// timeSlider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
// false));
// timeSlider.setBackground(parent.getBackground());
// Add a time slider widget.
timeSlider = new TimeSliderComposite(container, SWT.NONE);
timeSlider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
timeSlider.setBackground(parent.getBackground());
// Add a listener to trigger an update to the current timestep.
timeSlider.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
System.err.println("VisItPlotRender message: "
+ "Timestep changed to " + timeSlider.getTime()
+ "(timestep: " + timeSlider.getTimestep() + ").");

// Record the current timestep from the TimeSliderComposite.
widgetTimestep.set(timeSlider.getTimestep());

// Launch a worker thread to update the timestep for the VisIt
// widget.
executorService.submit(new Runnable() {
@Override
public void run() {

// FIXME We need a way to move to a specific timestep
// rather than cycling through them.

ViewerMethods methods = connection.getViewerMethods();

// Send next or previous timestep requests to the VisIt
// widget until it matches the current timestep in the
// TimeSliderComposite.
int targetStep;
while (renderedTimestep != (targetStep = widgetTimestep
.get())) {
if (renderedTimestep < targetStep) {
methods.animationNextState();
renderedTimestep++;
} else {
methods.animationPreviousState();
renderedTimestep--;
}
}
return;
}
});
return;
}
});

// TODO We need to figure out how to get the actual times from the VisIt
// client API. We are currently using the timestep indices.
// Get the available timesteps.
ViewerMethods widget = connection.getViewerMethods();
int timestepCount = widget.timeSliderGetNStates();
List<Double> times = new ArrayList<Double>(timestepCount);
for (double i = 0.0; i < timestepCount; i++) {
times.add(i);
}
timeSlider.setTimes(times);

return container;
}
Expand Down Expand Up @@ -261,11 +338,6 @@ protected void updatePlotComposite(Composite plotComposite,
// update the widget.
if (plotTypeChanged) {

// TODO Remove this output...
System.out.println("VisItPlot message: " + "Drawing plot "
+ category + " - " + type + " for source file \""
+ sourcePath + "\".");

// Draw the specified plot on the Canvas.
ViewerMethods widget = canvas.getViewerMethods();

Expand Down

0 comments on commit d793df6

Please sign in to comment.