From 4ef2343716cf52858b7b4b469d9a929b1d610496 Mon Sep 17 00:00:00 2001 From: Jordan Deyton Date: Tue, 10 Mar 2015 10:24:24 -0400 Subject: [PATCH] Added code to determine the available plot categories and types in a ParaView file. Signed-off-by: Jordan Deyton --- .../viz/service/paraview/ParaViewPlot.java | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlot.java b/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlot.java index c1427f9a8..123bfa33d 100644 --- a/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlot.java +++ b/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlot.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import org.eclipse.ice.viz.service.PlotRender; import org.eclipse.ice.viz.service.connections.ConnectionPlot; @@ -73,16 +72,8 @@ protected PlotRender createPlotRender(Composite parent) { @Override protected Map getPlotTypes(URI file) throws IOException, Exception { - // TODO This needs to build from the contents of the file via the JSON - // RPC calls. - VtkWebClient client = getConnectionAdapter().getConnection(); - - // The code below lists out the contents of the base directory for - // the http server. - JSONObject object; - - List args = new ArrayList(); + Map plotTypes = new HashMap(); // Determine the relative path of the file from the ParaView web // client's working directory. @@ -92,15 +83,43 @@ protected Map getPlotTypes(URI file) throws IOException, if (relativePath != null) { int proxyId = openFile(relativePath); System.out.println("The file proxy id: " + proxyId); - - // Get the file's properties. - args.clear(); + + // Get the file proxy's properties from the file. + VtkWebClient client = getConnectionAdapter().getConnection(); + JSONObject object; + JSONArray array; + List args = new ArrayList(1); args.add(proxyId); - object = client.call("pv.proxy.manager.get", args).get(); - System.out.println(object.toString(4)); + 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 new HashMap(); + return plotTypes; } private String getRelativePath(String fullPath) { @@ -116,7 +135,7 @@ private String getRelativePath(String fullPath) { 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("/")) { @@ -163,4 +182,5 @@ private int openFile(String relativePath) { return proxyId; } + }