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

Commit

Permalink
Updating the ParaView plot widgets to conform with the latest version of
Browse files Browse the repository at this point in the history
the HTTP proxy server.
Renamed an abstract method in MultiPlot.

Signed-off-by: Jordan Deyton <deytonjh@ornl.gov>
  • Loading branch information
Jordan Deyton committed Mar 11, 2015
1 parent b4794e9 commit 569b334
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 206 deletions.
Expand Up @@ -114,87 +114,6 @@ public boolean setConnectionProperties(List<Entry> row) {
return changed;
}

/**
* Creates a new view for rendering a different file or another
* representation of a file.
*
* @return The ID of the new view, or -1 if one could not be created.
*/
protected int createView() {
int viewId = -1;

// Attempt to create a new view. If successful, its ID should be added
// to the set of view IDs.
try {
viewId = getConnection().createView().get();
if (viewId >= 0) {
viewIds.add(viewId);
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}

return viewId;
}

/**
* Opens the file at the specified path inside the view with the specified
* ID. This creates a ParaView file proxy corresponding to the file.
*
* @param viewId
* The ID of the view that will render the file. This must be a
* valid view ID previously returned by {@link #createView()}.
* @param fullPath
* The full path to the file on the client connection's machine.
* @return The ID of the file proxy, or -1 if one could not be created.
*/
protected int createFileProxy(int viewId, String fullPath) {
int fileId = -1;

if (viewIds.contains(viewId)) {

// Determine the relative path based on the current data directory
// for the connection.
final String relativePath = findRelativePath(fullPath);

VtkWebClient client = getConnection();
List<Object> args = new ArrayList<Object>();
JSONObject object;

// Try to open the file.
args.add(relativePath);
try {
// Open a view in order to read the file.
viewId = client.createView().get();

// Create a proxy reader using the default settings, then pull
// the ID of the created proxy if it exists.
object = client.call("pv.proxy.manager.create.reader", args)
.get();
if (object.has("id")) {
fileId = object.getInt("id");
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
}

return fileId;
}

/**
* Determines the representation proxy for the specified file proxy.
*
* @param fileId
* The ID of the file proxy.
* @return The ID of the file's representation proxy, or -1 if it could not
* be found.
*/
protected int findRepresentationProxy(int fileId) {
// TODO
return -1;
}

/**
* Determines the relative path for the full path with respect to the client
* connection's data directory.
Expand All @@ -203,9 +122,11 @@ protected int findRepresentationProxy(int fileId) {
* The full path to the file.
* @return The relative path, or null if it could not be determined.
*/
private String findRelativePath(String fullPath) {
public String findRelativePath(String fullPath) {
String relativePath = null;

// TODO Move responsibility for this to the python code.

VtkWebClient client = getConnection();
List<Object> args = new ArrayList<Object>();
JSONObject object;
Expand Down
Expand Up @@ -17,7 +17,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import org.eclipse.ice.viz.service.PlotRender;
import org.eclipse.ice.viz.service.connections.ConnectionPlot;
Expand Down Expand Up @@ -47,6 +46,8 @@ public class ParaViewPlot extends ConnectionPlot<VtkWebClient> {
* The ID of a view that was created in order to read the file contents.
*/
private int viewId = -1;
private int fileId = -1;
private int repId = -1;

/**
* The default constructor.
Expand All @@ -67,11 +68,14 @@ public ParaViewPlot(ParaViewVizService vizService) {
*/
@Override
protected PlotRender createPlotRender(Composite parent) {
// Reset the view ID to -1 every time so that the same view is not used
// twice.
// Reset the view IDs so that the same view is not used twice.
int viewId = this.viewId;
int fileId = this.fileId;
int repId = this.repId;
this.viewId = -1;
return new ParaViewPlotRender(parent, this, viewId);
this.fileId = -1;
this.repId = -1;
return new ParaViewPlotRender(parent, this, viewId, fileId, repId);
}

/*
Expand All @@ -80,122 +84,61 @@ protected PlotRender createPlotRender(Composite parent) {
* @see org.eclipse.ice.viz.service.MultiPlot#getPlotTypes(java.net.URI)
*/
@Override
protected Map<String, String[]> getPlotTypes(URI file) throws IOException,
protected Map<String, String[]> findPlotTypes(URI file) throws IOException,
Exception {

// Set up the default return value.
Map<String, String[]> plotTypes = new HashMap<String, String[]>();

// Determine the relative path of the file from the ParaView web
// client's working directory.
String relativePath = getRelativePath(file.getPath());

System.out.println("Relative path: " + relativePath);
if (relativePath != null) {
int proxyId = openFile(relativePath);
System.out.println("The file proxy id: " + proxyId);

// Get the file proxy's properties from the file.
VtkWebClient client = getConnectionAdapter().getConnection();
JSONObject object;
JSONArray array;
List<Object> args = new ArrayList<Object>(1);
args.add(proxyId);
try {
object = client.call("pv.proxy.manager.get", args).get();
// Get the "ui" JSON array from the proxy's properties. This
// contains the names of all data sets that can be displayed in
// the plot.
if (object.has("ui")) {
array = object.getJSONArray("ui");

// Determine all plot categories and their types.
for (int i = 0; i < array.length(); i++) {
object = array.getJSONObject(i);

// Determine the plot category and its allowed types.
String name = object.getString("name");
JSONArray valueArray = object.getJSONArray("values");
String[] values = new String[valueArray.length()];
for (int j = 0; j < values.length; j++) {
values[j] = valueArray.getString(j);
}

// Store the plot category and types in the map.
plotTypes.put(name, values);
}
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
}

return plotTypes;
}
ParaViewConnectionAdapter adapter = getParaViewConnectionAdapter();
VtkWebClient client = adapter.getConnection();

private String getRelativePath(String fullPath) {
String relativePath = null;

VtkWebClient client = getConnectionAdapter().getConnection();
List<Object> args = new ArrayList<Object>();
JSONObject object;

args.add(".");
try {
object = client.call("file.server.directory.list", args).get();
if (object != null) {
String directory = object.getJSONArray("path").getString(0);
System.out.println("The directory is: " + directory);

// If the path is indeed a full path, we need to determine its
// relative path.
if (fullPath.startsWith("/")) {
// Determine the path to the base directory.
relativePath = "";
String[] split = directory.split("/");
for (int i = 0; i < split.length; i++) {
if (!split[i].trim().isEmpty()) {
relativePath += "../";
}
}
// Add in the rest of the full path, excluding the initial
// forward slash.
if (fullPath.length() > 1) {
relativePath += fullPath.substring(1);
}
} else {
relativePath = fullPath;
}
// Open the file. We *have* to create a new view to open the file. Use
// the custom server method, as the default ParaViewWeb method uses the
// currently active view.
args.clear();
args.add(adapter.findRelativePath(file.getPath()));
object = client.call("createView", args).get();
viewId = object.getInt("viewId");
fileId = object.getInt("proxyId");
repId = object.getInt("repId");

// Read the contents of the file to populate the map of plot types.
args.clear();
args.add(fileId);
object = client.call("pv.proxy.manager.get", args).get();
// Get the "ui" JSON array from the proxy's properties. This contains
// the names of all data sets that can be displayed in the plot.
JSONArray array = object.getJSONArray("ui");

// Determine all plot categories and their types.
for (int i = 0; i < array.length(); i++) {
object = array.getJSONObject(i);

// Determine the plot category and its allowed types.
String name = object.getString("name");
JSONArray valueArray = object.getJSONArray("values");
String[] values = new String[valueArray.length()];
for (int j = 0; j < values.length; j++) {
values[j] = valueArray.getString(j);
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}

return relativePath;
}

private int openFile(String relativePath) {
int proxyId = -1;

VtkWebClient client = getConnectionAdapter().getConnection();
List<Object> args = new ArrayList<Object>();
JSONObject object;

args.add(relativePath);
try {
// Open a view in order to read the file.
viewId = client.createView().get();

object = client.call("pv.proxy.manager.create.reader", args).get();
if (object.has("id")) {
proxyId = object.getInt("id");
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
// Store the plot category and types in the map.
plotTypes.put(name, values);
}

return proxyId;
return plotTypes;
}

/**
* Gets the connection adapter for the associated connection cast as a
* {@link ParaViewConnectionAdapter}.
*
* @return The associated connection adapter.
*/
protected ParaViewConnectionAdapter getParaViewConnectionAdapter() {
return (ParaViewConnectionAdapter) getConnectionAdapter();
}
Expand Down

0 comments on commit 569b334

Please sign in to comment.