gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / extension / DefaultView3DPanel.java @ 257
History | View | Annotate | Download (10.5 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.gvsig3d.app.extension; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Color; |
26 |
import java.awt.Component; |
27 |
import java.awt.Cursor; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.Image; |
30 |
import java.awt.Point; |
31 |
import java.awt.Toolkit; |
32 |
import java.beans.PropertyChangeEvent; |
33 |
import java.beans.PropertyChangeListener; |
34 |
import java.net.URL; |
35 |
|
36 |
import javax.swing.ImageIcon; |
37 |
import javax.swing.JPanel; |
38 |
import javax.swing.JSplitPane; |
39 |
|
40 |
import org.cresques.cts.IProjection; |
41 |
import org.gvsig.andami.PluginServices; |
42 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
43 |
import org.gvsig.app.project.documents.Document; |
44 |
import org.gvsig.app.project.documents.view.MapOverview; |
45 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
46 |
import org.gvsig.app.project.documents.view.toc.gui.TOC; |
47 |
import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
48 |
import org.gvsig.fmap.crs.CRSFactory; |
49 |
import org.gvsig.fmap.geom.primitive.Envelope; |
50 |
import org.gvsig.fmap.geom.primitive.impl.Envelope2D; |
51 |
import org.gvsig.fmap.mapcontext.ViewPort; |
52 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
53 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
54 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
55 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
56 |
import org.gvsig.fmap.mapcontrol.MapControl.MapToolListener; |
57 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
58 |
import org.gvsig.fmap.mapcontrol.MapControlManager; |
59 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
60 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
61 |
import org.gvsig.gvsig3d.Gvsig3DException; |
62 |
import org.gvsig.gvsig3d.Gvsig3DLocator; |
63 |
import org.gvsig.gvsig3d.Gvsig3DManager; |
64 |
import org.gvsig.gvsig3d.app.resources.ResourcesFactory; |
65 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
66 |
import org.gvsig.gvsig3d.map3d.ViewPort3D; |
67 |
import org.gvsig.gvsig3d.navigation.NavigationMode; |
68 |
import org.gvsig.osgvp.terrain.JavaDataDriver; |
69 |
import org.gvsig.osgvp.terrain.LayerManager; |
70 |
import org.gvsig.osgvp.terrain.Terrain; |
71 |
import org.gvsig.osgvp.viewer.DisplaySettings; |
72 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
73 |
import org.gvsig.osgvp.viewer.OSGViewer; |
74 |
import org.gvsig.tools.locator.LocatorException; |
75 |
|
76 |
/**
|
77 |
* @author gvSIG Team
|
78 |
* @version $Id$
|
79 |
*
|
80 |
*/
|
81 |
|
82 |
// WAS VIEW3D////////////////////////////////////////////
|
83 |
public class DefaultView3DPanel extends AbstractViewPanel { |
84 |
|
85 |
/**
|
86 |
*
|
87 |
*/
|
88 |
private static final long serialVersionUID = -4044661453954786519L; |
89 |
|
90 |
private IViewerContainer _canvas3d = null; |
91 |
private Terrain _terrain = null; |
92 |
private JavaDataDriver _terrainDataManager = null; |
93 |
private LayerManager _terrainLayerManager = null; |
94 |
private NavigationMode _navMode = null; |
95 |
private static MapControlManager mapControlManager = MapControlLocator |
96 |
.getMapControlManager(); |
97 |
|
98 |
private String buttonPath; |
99 |
|
100 |
public DefaultView3DPanel() {
|
101 |
super();
|
102 |
this.setName("View3D"); |
103 |
} |
104 |
|
105 |
public void initialize() { |
106 |
super.initialize();
|
107 |
initComponents(); |
108 |
|
109 |
} |
110 |
|
111 |
public Document getDocument() { |
112 |
|
113 |
return this.modelo; |
114 |
} |
115 |
|
116 |
public void setDocument(Document document) { |
117 |
setModel((DefaultView3DDocument) document); |
118 |
|
119 |
} |
120 |
|
121 |
public void setModel(DefaultView3DDocument model) { |
122 |
|
123 |
this.modelo = model;
|
124 |
|
125 |
MapContext3D mContext3D = (MapContext3D) modelo.getMapContext(); |
126 |
|
127 |
// set projection for 3D view
|
128 |
IProjection projection = null;
|
129 |
ViewPort3D vPort3D = null;
|
130 |
Envelope extent; |
131 |
if (_terrain.getCoordinateSystemType() == Terrain.CoordinateSystemType.GEOCENTRIC) {
|
132 |
projection = CRSFactory.getCRS("EPSG:4326");
|
133 |
extent = new Envelope2D(-180.0, 90.0, 180.0, -90.0); |
134 |
} else {
|
135 |
if ((mContext3D != null) && (mContext3D.getProjection() != null)) |
136 |
projection = mContext3D.getProjection(); |
137 |
else
|
138 |
projection = CRSFactory.getCRS("EPSG:23030");
|
139 |
extent = new Envelope2D(20000000.0, 10000000.0, -20000000.0, |
140 |
-10000000.0);
|
141 |
} |
142 |
try {
|
143 |
vPort3D = Gvsig3DLocator.getManager() |
144 |
.createtDefaultViewPort3DInstance(projection); |
145 |
vPort3D.setEnvelope(extent); |
146 |
mContext3D.setViewPort((ViewPort) vPort3D); |
147 |
vPort3D.setTerrain(_terrain); |
148 |
} catch (LocatorException e) {
|
149 |
// TODO Auto-generated catch block
|
150 |
e.printStackTrace(); |
151 |
} |
152 |
|
153 |
// Add ViewPort3D listener to canvas3D. to refresh locator.
|
154 |
// _canvas3d.addMouseListener((ViewPort3D) vp);
|
155 |
|
156 |
// Pass JOSG objects to MapContext3D
|
157 |
mContext3D.setViewer(_canvas3d); |
158 |
mContext3D.setViewProjection(projection); |
159 |
mContext3D.setDataManager(_terrainDataManager); |
160 |
mContext3D.setLayerManager(_terrainLayerManager); |
161 |
mContext3D.setTerrain(_terrain); |
162 |
|
163 |
// Se configura el mapControl
|
164 |
|
165 |
MapToolListener mapToolListener = m_MapControl.getMapToolListener(); |
166 |
_canvas3d.addMouseListener(mapToolListener); |
167 |
_canvas3d.addMouseMotionListener(mapToolListener); |
168 |
_canvas3d.addMouseWheelListener(mapToolListener); |
169 |
//
|
170 |
m_MapControl.setMapContext(mContext3D); |
171 |
m_TOC.setMapContext(mContext3D); |
172 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
173 |
if (modelo.getMapOverViewContext() != null) { |
174 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
175 |
} |
176 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
177 |
|
178 |
public void propertyChange(PropertyChangeEvent evt) { |
179 |
if (evt.getPropertyName().equals("name")) { |
180 |
PluginServices |
181 |
.getMDIManager() |
182 |
.getWindowInfo(DefaultView3DPanel.this) |
183 |
.setTitle( |
184 |
PluginServices.getText(this, "Vista3D") |
185 |
+ " : "
|
186 |
+ (String) evt.getNewValue());
|
187 |
} |
188 |
} |
189 |
}); |
190 |
if (m_MapControl.getViewPort() != null) { |
191 |
m_MapControl.getViewPort().addViewPortListener( |
192 |
new ViewPortListener() {
|
193 |
|
194 |
public void extentChanged(ExtentEvent e) { |
195 |
/*
|
196 |
* if (PluginServices.getMainFrame() != null){
|
197 |
* PluginServices.getMainFrame().getStatusBar().
|
198 |
* setControlValue
|
199 |
* ("scale",String.valueOf(m_MapControl
|
200 |
* .getMapContext ().getScaleView()));
|
201 |
*
|
202 |
*
|
203 |
*
|
204 |
* PluginServices.getMainFrame().getStatusBar().
|
205 |
* setMessage ("projection",
|
206 |
*
|
207 |
*
|
208 |
*
|
209 |
* getMapControl().getViewPort().getProjection().
|
210 |
* getAbrev ()); }
|
211 |
*/
|
212 |
} |
213 |
|
214 |
public void backColorChanged(ColorEvent e) { |
215 |
} |
216 |
|
217 |
public void projectionChanged(ProjectionEvent e) { |
218 |
m_MapLoc.setProjection(e.getNewProjection()); |
219 |
} |
220 |
}); |
221 |
} |
222 |
|
223 |
} |
224 |
|
225 |
protected void initComponents() { |
226 |
|
227 |
Gvsig3DManager manager = Gvsig3DLocator.getManager(); |
228 |
|
229 |
try {
|
230 |
m_MapControl = manager.createDefaultMapControl3DInstance(); |
231 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
232 |
m_TOC = new TOC();
|
233 |
m_MapLoc = new MapOverview(m_MapControl);
|
234 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
235 |
|
236 |
removeAll(); |
237 |
tempMainSplit = new ViewSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
238 |
|
239 |
if (windowLayout == null) { |
240 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
241 |
} |
242 |
|
243 |
tempMainSplit.setLeftComponent(m_TOC); |
244 |
|
245 |
m_TOC.setVisible(true);
|
246 |
|
247 |
JPanel panel = new JPanel(); |
248 |
panel.setLayout(new BorderLayout()); |
249 |
System.out.println(_canvas3d.getWidth() + " " |
250 |
+ _canvas3d.getHeight()); |
251 |
panel.add((Component) _canvas3d);
|
252 |
panel.setMinimumSize(new Dimension(100, 100)); |
253 |
|
254 |
tempMainSplit.setRightComponent(panel); |
255 |
|
256 |
this.setLayout(new BorderLayout()); |
257 |
this.add(tempMainSplit, BorderLayout.CENTER); |
258 |
|
259 |
// default cursor
|
260 |
String oldPath = ResourcesFactory.getExtPath();// Save the path. |
261 |
ResourcesFactory |
262 |
.setExtPath("/gvSIG/extensiones/org.gvsig.gvsig3d.app.extension/images/");// my |
263 |
// new
|
264 |
// path
|
265 |
buttonPath = ResourcesFactory.getResourcesPath(); |
266 |
ResourcesFactory.setExtPath(oldPath);// Restore the old path.
|
267 |
|
268 |
URL path;
|
269 |
path = this.getClass().getClassLoader().getResource("images/"); |
270 |
buttonPath = path.getPath(); |
271 |
|
272 |
Image navCursorImage = new ImageIcon(buttonPath |
273 |
+ "/NavigationCursor.gif").getImage();
|
274 |
|
275 |
Cursor navCursor = Toolkit.getDefaultToolkit().createCustomCursor( |
276 |
navCursorImage, new Point(16, 16), ""); |
277 |
((Component) _canvas3d).setCursor(navCursor);
|
278 |
|
279 |
// Seleccion por punto
|
280 |
// PointSelectListener3D psl = new
|
281 |
// PointSelectListener3D(m_MapControl);
|
282 |
// m_MapControl.addBehavior("pointSelection", new Behavior[] { new
|
283 |
// PointBehavior(psl) });
|
284 |
// m_MapControl.setCurrentMapTool(new PointBehavior(psl));
|
285 |
//
|
286 |
// Info por punto
|
287 |
InfoListener il = new InfoListener(m_MapControl);
|
288 |
m_MapControl.addBehavior("info",
|
289 |
new Behavior[] { new PointBehavior(il) }); |
290 |
m_MapControl.setCurrentMapTool(new PointBehavior(il));
|
291 |
|
292 |
// // Selecci�n por rect�ngulo
|
293 |
// RectangleSelectListener3D rsl = new
|
294 |
// RectangleSelectListener3D(m_MapControl);
|
295 |
// m_MapControl.addMapTool("rectSelection", new Behavior[] { new
|
296 |
// RectangleBehavior3D(rsl) });
|
297 |
//
|
298 |
|
299 |
} catch (Gvsig3DException e) {
|
300 |
// TODO Auto-generated catch block
|
301 |
e.printStackTrace(); |
302 |
} |
303 |
|
304 |
} |
305 |
|
306 |
public IViewerContainer getCanvas3d() {
|
307 |
return _canvas3d;
|
308 |
} |
309 |
|
310 |
public void setCanvas3d(IViewerContainer canvas3d) { |
311 |
_canvas3d = canvas3d; |
312 |
} |
313 |
|
314 |
public DisplaySettings getDisplaySettings() {
|
315 |
|
316 |
return ((OSGViewer) getCanvas3d().getOSGViewer()).getDisplaySettings();
|
317 |
|
318 |
} |
319 |
|
320 |
public Object getWindowProfile() { |
321 |
return WindowInfo.EDITOR_PROFILE;
|
322 |
} |
323 |
|
324 |
public Terrain getTerrain() {
|
325 |
return _terrain;
|
326 |
} |
327 |
|
328 |
public void setTerrain(Terrain terrain) { |
329 |
if (_canvas3d == null) |
330 |
return;
|
331 |
_terrain = terrain; |
332 |
} |
333 |
|
334 |
public JavaDataDriver getDataManager() {
|
335 |
return _terrainDataManager;
|
336 |
} |
337 |
|
338 |
public void setDataManager(JavaDataDriver manager) { |
339 |
_terrainDataManager = manager; |
340 |
} |
341 |
|
342 |
public LayerManager getLayerManager() {
|
343 |
return _terrainLayerManager;
|
344 |
} |
345 |
|
346 |
public void setLayerManager(LayerManager manager) { |
347 |
_terrainLayerManager = manager; |
348 |
} |
349 |
|
350 |
public NavigationMode getNavMode() {
|
351 |
return _navMode;
|
352 |
} |
353 |
|
354 |
public void setNavMode(NavigationMode navMode) { |
355 |
_navMode = navMode; |
356 |
} |
357 |
|
358 |
} |