root / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / display / FullScreenPanel.java @ 25334
History | View | Annotate | Download (10.2 KB)
1 |
package org.gvsig.gvsig3dgui.display; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.io.File; |
5 |
|
6 |
import javax.swing.JButton; |
7 |
import javax.swing.JCheckBox; |
8 |
import javax.swing.JFileChooser; |
9 |
import javax.swing.JLabel; |
10 |
import javax.swing.JPanel; |
11 |
import javax.swing.JTextField; |
12 |
import javax.swing.event.ChangeEvent; |
13 |
import javax.swing.event.ChangeListener; |
14 |
|
15 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
16 |
import org.gvsig.gvsig3dgui.view.View3D; |
17 |
import org.gvsig.osgvp.Group; |
18 |
import org.gvsig.osgvp.Matrix; |
19 |
import org.gvsig.osgvp.Node; |
20 |
import org.gvsig.osgvp.Vec4; |
21 |
import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions; |
22 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
23 |
import org.gvsig.osgvp.planets.Planet; |
24 |
import org.gvsig.osgvp.planets.PlanetViewer; |
25 |
import org.gvsig.osgvp.stereoconfig.StereoConfig; |
26 |
import org.gvsig.osgvp.viewer.Camera; |
27 |
import org.gvsig.osgvp.viewer.DisplaySettings; |
28 |
import org.gvsig.osgvp.viewer.OSGViewer; |
29 |
|
30 |
import com.iver.andami.PluginServices; |
31 |
import com.iver.andami.ui.mdiManager.IWindow; |
32 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
33 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
34 |
|
35 |
public class FullScreenPanel extends GridBagLayoutPanel implements IWindow, |
36 |
ChangeListener, IWindowListener {
|
37 |
|
38 |
/**
|
39 |
*
|
40 |
*/
|
41 |
private static final long serialVersionUID = 7918162328474597496L; |
42 |
|
43 |
private WindowInfo m_viewinfo;
|
44 |
|
45 |
private int width = 400; |
46 |
|
47 |
private int height = 130; |
48 |
|
49 |
private View3D view3D;
|
50 |
|
51 |
private JPanel jPanel1; |
52 |
|
53 |
private JButton jButton2; |
54 |
|
55 |
private JButton jButton1; |
56 |
|
57 |
private JLabel jLabel2; |
58 |
|
59 |
private JTextField jTextField1; |
60 |
|
61 |
private JButton jButton3; |
62 |
|
63 |
private JCheckBox jCheckBox1; |
64 |
|
65 |
private PlanetViewer _fullScreenViewer;
|
66 |
|
67 |
private DisplaySettings _ds;
|
68 |
|
69 |
public FullScreenPanel() {
|
70 |
|
71 |
if (PluginServices.getMDIManager().getActiveWindow() instanceof View3D) { |
72 |
view3D = (View3D) PluginServices.getMDIManager().getActiveWindow(); |
73 |
initialize(); |
74 |
} |
75 |
|
76 |
else
|
77 |
PluginServices.getMDIManager().closeWindow(this);
|
78 |
|
79 |
} |
80 |
|
81 |
public Object getWindowModel() { |
82 |
return view3D;
|
83 |
} |
84 |
|
85 |
public void initialize() { |
86 |
|
87 |
java.awt.GridBagConstraints gridBagConstraints; |
88 |
|
89 |
jPanel1 = new javax.swing.JPanel();
|
90 |
jButton2 = new javax.swing.JButton();
|
91 |
jButton1 = new javax.swing.JButton();
|
92 |
jLabel2 = new javax.swing.JLabel();
|
93 |
jTextField1 = new javax.swing.JTextField();
|
94 |
jButton3 = new javax.swing.JButton();
|
95 |
jCheckBox1 = new javax.swing.JCheckBox();
|
96 |
|
97 |
setLayout(new java.awt.GridBagLayout());
|
98 |
|
99 |
jPanel1.setLayout(new java.awt.GridBagLayout());
|
100 |
|
101 |
jButton2.setText("Cancelar");
|
102 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
103 |
gridBagConstraints.gridx = 2;
|
104 |
gridBagConstraints.gridy = 4;
|
105 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
106 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
107 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); |
108 |
jButton2.addActionListener(new java.awt.event.ActionListener() {
|
109 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
110 |
jButton2ActionPerformed(evt); |
111 |
} |
112 |
}); |
113 |
jPanel1.add(jButton2, gridBagConstraints); |
114 |
|
115 |
jButton1.setText("Aceptar");
|
116 |
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
117 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
118 |
jButton1ActionPerformed(evt); |
119 |
} |
120 |
}); |
121 |
|
122 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
123 |
gridBagConstraints.gridx = 1;
|
124 |
gridBagConstraints.gridy = 4;
|
125 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
126 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); |
127 |
jPanel1.add(jButton1, gridBagConstraints); |
128 |
|
129 |
jLabel2.setText("Archivo de Configuracion");
|
130 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
131 |
gridBagConstraints.gridx = 0;
|
132 |
gridBagConstraints.gridy = 0;
|
133 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 21); |
134 |
jPanel1.add(jLabel2, gridBagConstraints); |
135 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
136 |
gridBagConstraints.gridx = 1;
|
137 |
gridBagConstraints.gridy = 0;
|
138 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
139 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
140 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0); |
141 |
jPanel1.add(jTextField1, gridBagConstraints); |
142 |
|
143 |
jButton3.setText("Browse");
|
144 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
145 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0); |
146 |
jButton3.addActionListener(new java.awt.event.ActionListener() {
|
147 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
148 |
jButton3ActionPerformed(evt); |
149 |
} |
150 |
}); |
151 |
jPanel1.add(jButton3, gridBagConstraints); |
152 |
|
153 |
jCheckBox1.setText("Sincronizar camaras");
|
154 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
155 |
gridBagConstraints.gridx = 0;
|
156 |
gridBagConstraints.gridy = 2;
|
157 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
158 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); |
159 |
jPanel1.add(jCheckBox1, gridBagConstraints); |
160 |
jCheckBox1.setSelected(true);
|
161 |
|
162 |
add(jPanel1, new java.awt.GridBagConstraints());
|
163 |
|
164 |
} |
165 |
|
166 |
protected void jButton3ActionPerformed(ActionEvent evt) { |
167 |
JFileChooser jFileChooser1 = new JFileChooser(); |
168 |
int returnVal = jFileChooser1.showOpenDialog(this); |
169 |
|
170 |
if (returnVal == JFileChooser.APPROVE_OPTION) |
171 |
jTextField1.setText(jFileChooser1.getSelectedFile() |
172 |
.getAbsolutePath()); |
173 |
|
174 |
} |
175 |
|
176 |
protected void jButton1ActionPerformed(ActionEvent evt) { |
177 |
|
178 |
view3D = (View3D) PluginServices.getMDIManager().getActiveWindow(); |
179 |
_ds = view3D.getDisplaySettings(); |
180 |
PluginServices.getMDIManager().closeWindow(this);
|
181 |
Planet planet = null;
|
182 |
boolean synchronize = jCheckBox1.isSelected();
|
183 |
boolean changedManipulator = false; |
184 |
|
185 |
if (!jTextField1.getText().equals("")) { |
186 |
|
187 |
runMStereo(); |
188 |
return;
|
189 |
|
190 |
} |
191 |
|
192 |
try {
|
193 |
planet = ((PlanetViewer) view3D.getCanvas3d().getOSGViewer()) |
194 |
.getPlanet(0);
|
195 |
planet.setWaitElevationData(true);
|
196 |
_fullScreenViewer = new PlanetViewer();
|
197 |
_fullScreenViewer.addPlanet(planet); |
198 |
_fullScreenViewer.addSpecialNode((((PlanetViewer) view3D |
199 |
.getCanvas3d().getOSGViewer()).getSpecialNodes())); |
200 |
} catch (ChildIndexOutOfBoundsExceptions e1) {
|
201 |
// TODO Auto-generated catch block
|
202 |
e1.printStackTrace(); |
203 |
} catch (NodeException e1) {
|
204 |
// TODO Auto-generated catch block
|
205 |
e1.printStackTrace(); |
206 |
} |
207 |
Vec4 color = ((PlanetViewer) view3D.getCanvas3d().getOSGViewer()) |
208 |
.getClearColor(); |
209 |
_fullScreenViewer.setClearColor(color.x(), color.y(), color.z(), color |
210 |
.w()); |
211 |
_fullScreenViewer.setDisplaySettings(_ds); |
212 |
|
213 |
if (view3D.getCanvas3d().getOSGViewer().getCameraManipulator() == null) { |
214 |
((PlanetViewer) (view3D.getCanvas3d().getOSGViewer())) |
215 |
.restoreCustomTerrainManipulator(); |
216 |
changedManipulator = true;
|
217 |
} |
218 |
Matrix refView = view3D.getCanvas3d().getOSGViewer().getViewMatrix(); |
219 |
System.out.println("refCam view " + refView.toString()); |
220 |
Camera viewCam = new Camera();
|
221 |
viewCam.setViewMatrix(refView); |
222 |
_fullScreenViewer.setCamera(viewCam); |
223 |
|
224 |
if(synchronize)
|
225 |
_fullScreenViewer.setCameraManipulator(null);
|
226 |
|
227 |
while (!_fullScreenViewer.done()) {
|
228 |
|
229 |
if (synchronize) {
|
230 |
_fullScreenViewer.setFusionDistance((float)planet.getZoom());
|
231 |
refView = view3D.getCanvas3d().getOSGViewer().getViewMatrix(); |
232 |
viewCam.setViewMatrix(refView); |
233 |
_fullScreenViewer.setCamera(viewCam); |
234 |
|
235 |
} |
236 |
_fullScreenViewer.frame(); |
237 |
|
238 |
} |
239 |
_fullScreenViewer.releaseGLContext(); |
240 |
_fullScreenViewer.dispose(); |
241 |
_fullScreenViewer = null;
|
242 |
|
243 |
planet.setWaitElevationData(false);
|
244 |
|
245 |
if (changedManipulator) {
|
246 |
((PlanetViewer) (view3D.getCanvas3d().getOSGViewer())) |
247 |
.setCameraManipulator(null);
|
248 |
} |
249 |
System.gc();
|
250 |
} |
251 |
|
252 |
private boolean runMStereo() { |
253 |
Group g = new Group(); |
254 |
OSGViewer viewer; |
255 |
|
256 |
boolean synchronize = jCheckBox1.isSelected();
|
257 |
boolean changedManipulator = false; |
258 |
Planet planet = null;
|
259 |
StereoConfig sc = null;
|
260 |
try {
|
261 |
planet = ((PlanetViewer) view3D.getCanvas3d().getOSGViewer()) |
262 |
.getPlanet(0);
|
263 |
planet.setWaitElevationData(true);
|
264 |
g.addChild(planet); |
265 |
g.addChild(((PlanetViewer) view3D.getCanvas3d().getOSGViewer()) |
266 |
.getSpecialNodes()); |
267 |
viewer = new OSGViewer();
|
268 |
|
269 |
File config = new File(jTextField1.getText());//Util.extractFromURL(this.getClass().getResource( |
270 |
//"/oglConfig.txt"));
|
271 |
sc = new StereoConfig();
|
272 |
Node n = sc.pipes2screens1texture(g, viewer, config |
273 |
.getAbsolutePath()); |
274 |
viewer.setSceneData(n); |
275 |
|
276 |
Vec4 color = ((PlanetViewer) view3D.getCanvas3d().getOSGViewer()) |
277 |
.getClearColor(); |
278 |
viewer.setClearColor(color.x(), color.y(), color.z(), |
279 |
color.w()); |
280 |
viewer.setDisplaySettings(_ds); |
281 |
|
282 |
if (view3D.getCanvas3d().getOSGViewer().getCameraManipulator() == null) { |
283 |
((PlanetViewer) (view3D.getCanvas3d().getOSGViewer())) |
284 |
.restoreCustomTerrainManipulator(); |
285 |
changedManipulator = true;
|
286 |
} |
287 |
|
288 |
} catch (Exception e1) { |
289 |
|
290 |
e1.printStackTrace(); |
291 |
return false; |
292 |
} |
293 |
Matrix refView = view3D.getCanvas3d().getOSGViewer() |
294 |
.getViewMatrix(); |
295 |
System.out.println("refCam view " + refView.toString()); |
296 |
Camera viewCam = new Camera();
|
297 |
viewCam.setViewMatrix(refView); |
298 |
viewer.setCamera(viewCam); |
299 |
|
300 |
if (synchronize) {
|
301 |
viewer.setCameraManipulator(null);
|
302 |
} |
303 |
// viewer.setUpViewInWindow(100, 100, 400, 400);
|
304 |
while (!viewer.done()) {
|
305 |
if (synchronize) {
|
306 |
viewer.setFusionDistance((float)planet.getZoom());
|
307 |
refView = view3D.getCanvas3d().getOSGViewer().getViewMatrix(); |
308 |
viewCam.setViewMatrix(refView); |
309 |
viewer.setCamera(viewCam); |
310 |
|
311 |
} |
312 |
sc.updateCameras(viewer); |
313 |
viewer.frame(); |
314 |
} |
315 |
viewer.releaseGLContext(); |
316 |
viewer.dispose(); |
317 |
viewer = null;
|
318 |
|
319 |
planet.setWaitElevationData(false);
|
320 |
if (changedManipulator) {
|
321 |
((PlanetViewer) (view3D.getCanvas3d().getOSGViewer())) |
322 |
.setCameraManipulator(null);
|
323 |
} |
324 |
|
325 |
System.gc();
|
326 |
return true; |
327 |
|
328 |
} |
329 |
|
330 |
protected void jButton2ActionPerformed(ActionEvent evt) { |
331 |
PluginServices.getMDIManager().closeWindow(this);
|
332 |
|
333 |
} |
334 |
|
335 |
public WindowInfo getWindowInfo() {
|
336 |
m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
337 |
m_viewinfo.setTitle(PluginServices.getText(this, "FullScreen")); |
338 |
m_viewinfo.setHeight(height); |
339 |
m_viewinfo.setWidth(width); |
340 |
return m_viewinfo;
|
341 |
} |
342 |
|
343 |
public void stateChanged(ChangeEvent e) { |
344 |
|
345 |
} |
346 |
|
347 |
public void windowActivated() { |
348 |
view3D = (View3D) PluginServices.getMDIManager().getActiveWindow(); |
349 |
System.out.println(view3D.getName());
|
350 |
} |
351 |
|
352 |
public void windowClosed() { |
353 |
|
354 |
} |
355 |
|
356 |
public Object getWindowProfile() { |
357 |
// TODO Auto-generated method stub
|
358 |
return WindowInfo.DIALOG_PROFILE;
|
359 |
} |
360 |
} |