This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
ParaViewPlot.java
186 lines (161 loc) · 5.43 KB
/
ParaViewPlot.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*******************************************************************************
* Copyright (c) 2015- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jordan Deyton
*******************************************************************************/
package org.eclipse.ice.viz.service.paraview;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
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;
import org.eclipse.swt.widgets.Composite;
import org.json.JSONArray;
import org.json.JSONObject;
import com.kitware.vtk.web.VtkWebClient;
/**
* This class is responsible for embedding ParaView-supported graphics inside
* client {@link Composite}s.
* <p>
* Instances of this class should not be created manually. Instead, a plot
* should be created via {@link ParaViewVizService#createPlot(URI)}.
* </p>
*
* @see ParaViewVizService
*
* @author Jordan Deyton
*
*/
public class ParaViewPlot extends ConnectionPlot<VtkWebClient> {
/**
* The default constructor.
*
* @param service
* The visualization service responsible for this plot.
*/
public ParaViewPlot(ParaViewVizService vizService) {
super(vizService);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.MultiPlot#createPlotRender(org.eclipse.swt
* .widgets.Composite)
*/
@Override
protected PlotRender createPlotRender(Composite parent) {
return new ParaViewPlotRender(parent, this);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.MultiPlot#getPlotTypes(java.net.URI)
*/
@Override
protected Map<String, String[]> getPlotTypes(URI file) throws IOException,
Exception {
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;
}
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;
}
}
} 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 {
object = client.call("pv.proxy.manager.create.reader", args).get();
if (object.has("id")) {
proxyId = object.getInt("id");
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
return proxyId;
}
}