Revision 521
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/DefaultMapControl3D.java | ||
---|---|---|
161 | 161 |
} |
162 | 162 |
|
163 | 163 |
this.synchronizer = |
164 |
new DefaultSynchronizer(this, this.mapContext, getWwd().getModel());
|
|
164 |
new DefaultSynchronizer(this, this.mapContext, getWwd()); |
|
165 | 165 |
|
166 | 166 |
super.add(getWwd(), BorderLayout.CENTER); |
167 | 167 |
|
... | ... | |
255 | 255 |
Layer rasterTiledLayer = converter.convertToLayer(this, layer); |
256 | 256 |
rasterTiledLayer.setEnabled(layer.isVisible()); |
257 | 257 |
getWwd().getModel().getLayers().add(index, rasterTiledLayer); |
258 |
LOG.debug("/////////////////////////////"); |
|
259 |
LOG.debug("Layers {}", getWwd().getModel().getLayers().toString()); |
|
260 |
LOG.debug("Layer {} added like tileImageLayer", layer.getName()); |
|
261 |
LOG.debug("/////////////////////////////"); |
|
262 | 258 |
} else { |
263 | 259 |
return; //TODO Convert to 3D vectorial layer |
264 | 260 |
} |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/DefaultSynchronizer.java | ||
---|---|---|
1 | 1 |
package org.gvsig.view3d.swing.impl; |
2 | 2 |
|
3 |
import gov.nasa.worldwind.Model;
|
|
3 |
import gov.nasa.worldwind.WorldWindow;
|
|
4 | 4 |
import gov.nasa.worldwind.avlist.AVKey; |
5 | 5 |
import gov.nasa.worldwind.avlist.AVList; |
6 |
import gov.nasa.worldwind.geom.Angle; |
|
7 |
import gov.nasa.worldwind.geom.Box; |
|
8 |
import gov.nasa.worldwind.geom.Position; |
|
9 |
import gov.nasa.worldwind.geom.Sector; |
|
6 | 10 |
import gov.nasa.worldwind.globes.ElevationModel; |
7 | 11 |
import gov.nasa.worldwind.layers.Layer; |
8 | 12 |
import gov.nasa.worldwind.terrain.CompoundElevationModel; |
13 |
import gov.nasa.worldwind.view.orbit.OrbitView; |
|
9 | 14 |
|
15 |
import java.awt.geom.Point2D; |
|
10 | 16 |
import java.util.ArrayList; |
11 | 17 |
import java.util.HashMap; |
12 | 18 |
import java.util.List; |
... | ... | |
14 | 20 |
import java.util.Map.Entry; |
15 | 21 |
|
16 | 22 |
import org.gvsig.fmap.dal.exception.DataException; |
23 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
17 | 24 |
import org.gvsig.fmap.mapcontext.MapContext; |
25 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
26 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
|
27 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
|
28 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
|
29 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
|
18 | 30 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
19 | 31 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
20 | 32 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
... | ... | |
29 | 41 |
import org.gvsig.view3d.lib.api.View3DLocator; |
30 | 42 |
import org.gvsig.view3d.lib.api.View3DManager; |
31 | 43 |
import org.gvsig.view3d.lib.api.properties.LayerProperties3D; |
44 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
|
45 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
|
46 |
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D; |
|
32 | 47 |
import org.gvsig.view3d.swing.api.properties.MapControlProperties3D; |
33 | 48 |
import org.gvsig.view3d.swing.impl.data.DefaultTiledImageLayer; |
34 | 49 |
import org.slf4j.Logger; |
... | ... | |
47 | 62 |
|
48 | 63 |
private DefaultMapControl3D mapControl3D; |
49 | 64 |
private MapContext mapContext; |
50 |
private Model modelWW;
|
|
65 |
private WorldWindow wwd;
|
|
51 | 66 |
|
52 | 67 |
protected DefaultSynchronizer(DefaultMapControl3D theMapControl3D, |
53 |
MapContext theMapContext, Model theModelWW) {
|
|
68 |
MapContext theMapContext, WorldWindow wwd) {
|
|
54 | 69 |
|
55 | 70 |
this.mapControl3D = theMapControl3D; |
56 | 71 |
this.mapContext = theMapContext; |
57 |
this.modelWW = theModelWW;
|
|
72 |
this.wwd = wwd;
|
|
58 | 73 |
|
59 | 74 |
intializeRegisters(); |
60 | 75 |
|
61 | 76 |
addLayerCollectionListener(mapContext.getLayers()); |
62 | 77 |
addLayerListener(mapContext.getLayers()); |
78 |
addViewPortListener(mapContext.getViewPort()); |
|
63 | 79 |
} |
64 | 80 |
|
65 | 81 |
private void intializeRegisters() { |
... | ... | |
187 | 203 |
} |
188 | 204 |
}; |
189 | 205 |
} |
206 |
|
|
207 |
private void addViewPortListener(ViewPort viewPort) { |
|
208 |
|
|
209 |
viewPort.addViewPortListener(new ViewPortListener() { |
|
210 |
|
|
211 |
public void projectionChanged(ProjectionEvent e) { |
|
212 |
} |
|
213 |
|
|
214 |
public void extentChanged(ExtentEvent e) { |
|
215 |
MapControlProperties3D properties = |
|
216 |
mapControl3D.getProperties(); |
|
217 |
boolean autoViewSynchronize = |
|
218 |
properties.getAutoViewSynchronize(); |
|
219 |
if (autoViewSynchronize) { |
|
220 |
synchronizeViewPorts(); |
|
221 |
} |
|
222 |
} |
|
223 |
|
|
224 |
public void backColorChanged(ColorEvent e) { |
|
225 |
} |
|
226 |
}); |
|
227 |
} |
|
190 | 228 |
|
229 |
|
|
191 | 230 |
private Layer getTileImageLayer(FLayer layer) { |
192 | 231 |
List<Layer> layers = |
193 |
modelWW.getLayers().getLayersByClass(DefaultTiledImageLayer.class);
|
|
232 |
wwd.getModel().getLayers().getLayersByClass(DefaultTiledImageLayer.class);
|
|
194 | 233 |
for (Layer tiledLayer : layers) { |
195 | 234 |
AVList constructionParams = |
196 | 235 |
(AVList) tiledLayer.getValue(AVKey.CONSTRUCTION_PARAMETERS); |
... | ... | |
207 | 246 |
} |
208 | 247 |
|
209 | 248 |
private ElevationModel getElevationModel(FLayer layer) { |
210 |
ElevationModel elevationModel = modelWW.getGlobe().getElevationModel();
|
|
249 |
ElevationModel elevationModel = wwd.getModel().getGlobe().getElevationModel();
|
|
211 | 250 |
|
212 | 251 |
if (elevationModel instanceof CompoundElevationModel) { |
213 | 252 |
CompoundElevationModel compoundModel = |
... | ... | |
327 | 366 |
} |
328 | 367 |
|
329 | 368 |
protected void synchronizeViewPorts() { |
330 |
throw new UnsupportedOperationException(); |
|
369 |
|
|
370 |
// Convert envelope to WorldWind sector |
|
371 |
ViewPort viewPort = this.mapContext.getViewPort(); |
|
372 |
Envelope envelope = viewPort.getEnvelope(); |
|
373 |
Sector sector = getSector(envelope); |
|
374 |
|
|
375 |
// Create a bounding box for the specified sector in order to estimate |
|
376 |
// its size in model coordinates. |
|
377 |
Box extent = Sector.computeBoundingBox(wwd.getModel().getGlobe(), |
|
378 |
mapControl3D.getVerticalExaggeration(), sector); |
|
379 |
|
|
380 |
// Estimate the distance between the center position and the eye |
|
381 |
// position that is necessary to cause the sector to |
|
382 |
// fill a viewport with the specified field of view. Note that we change |
|
383 |
// the distance between the center and eye |
|
384 |
// position here, and leave the field of view constant. |
|
385 |
Angle fov = wwd.getView().getFieldOfView(); |
|
386 |
double zoom = extent.getRadius() / fov.cosHalfAngle() / fov.tanHalfAngle(); |
|
387 |
|
|
388 |
View3DSwingManager swingManager = View3DSwingLocator.getManager(); |
|
389 |
GeneralProperties3D general3dProperties = swingManager.getGeneral3DProperties(); |
|
390 |
|
|
391 |
if(general3dProperties.getViewPortAnimation()){ |
|
392 |
wwd.getView().goTo(new Position(sector.getCentroid(), 0d), zoom); |
|
393 |
} else { |
|
394 |
((OrbitView) wwd.getView()).setCenterPosition(new Position(sector |
|
395 |
.getCentroid(), 0d)); |
|
396 |
((OrbitView) wwd.getView()).setZoom(zoom); |
|
397 |
wwd.redraw(); |
|
398 |
} |
|
331 | 399 |
} |
332 | 400 |
|
401 |
private Sector getSector(Envelope envelope) { |
|
402 |
|
|
403 |
Point2D p1 = null; |
|
404 |
Point2D p2 = null; |
|
405 |
|
|
406 |
p1 = new Point2D.Double(envelope.getMinimum(0), envelope.getMinimum(1)); |
|
407 |
p2 = new Point2D.Double(envelope.getMaximum(0), envelope.getMaximum(1)); |
|
408 |
|
|
409 |
double minLatitude = |
|
410 |
Double.isInfinite(p1.getY()) || p1.getY() < Angle.NEG90.degrees |
|
411 |
? Angle.NEG90.degrees : p1.getY(); |
|
412 |
double maxLatitude = |
|
413 |
Double.isInfinite(p2.getY()) || p2.getY() > Angle.POS90.degrees |
|
414 |
? Angle.POS90.degrees : p2.getY(); |
|
415 |
double minLongitude = |
|
416 |
Double.isInfinite(p1.getX()) || p1.getX() < Angle.NEG180.degrees |
|
417 |
? Angle.NEG180.degrees : p1.getX(); |
|
418 |
double maxLongitude = |
|
419 |
Double.isInfinite(p2.getX()) || p2.getX() > Angle.POS180.degrees |
|
420 |
? Angle.POS180.degrees : p2.getX(); |
|
421 |
|
|
422 |
Sector sector = |
|
423 |
new Sector(Sector.fromDegrees(minLatitude, maxLatitude, |
|
424 |
minLongitude, maxLongitude)); |
|
425 |
|
|
426 |
return sector; |
|
427 |
} |
|
428 |
|
|
333 | 429 |
private void updateLayer(FLayer layer) { |
334 | 430 |
int index = getLayerIndex(layer); |
335 | 431 |
removeLayer(layer); |
... | ... | |
345 | 441 |
if(layerProperties.getElevation()){ |
346 | 442 |
ElevationModel layerEModel = getElevationModel(layer); |
347 | 443 |
CompoundElevationModel eModel = |
348 |
(CompoundElevationModel) modelWW.getGlobe().getElevationModel();
|
|
444 |
(CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel();
|
|
349 | 445 |
if(layerEModel != null){ |
350 | 446 |
|
351 | 447 |
index = eModel.getElevationModels().indexOf(layerEModel); |
... | ... | |
356 | 452 |
|
357 | 453 |
Layer tileImageLayer = getTileImageLayer(layer); |
358 | 454 |
if(tileImageLayer != null){ |
359 |
index = modelWW.getLayers().indexOf(tileImageLayer);
|
|
455 |
index = wwd.getModel().getLayers().indexOf(tileImageLayer);
|
|
360 | 456 |
} else { |
361 |
return modelWW.getLayers().size();
|
|
457 |
return wwd.getModel().getLayers().size();
|
|
362 | 458 |
} |
363 | 459 |
} |
364 | 460 |
|
... | ... | |
388 | 484 |
|
389 | 485 |
if (eModel != null) { |
390 | 486 |
CompoundElevationModel compoundEModel = |
391 |
(CompoundElevationModel) modelWW.getGlobe().getElevationModel();
|
|
487 |
(CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel();
|
|
392 | 488 |
compoundEModel.removeElevationModel(eModel); |
393 | 489 |
} else if (tiledImageLayer != null) { |
394 |
modelWW.getLayers().remove(tiledImageLayer);
|
|
490 |
wwd.getModel().getLayers().remove(tiledImageLayer);
|
|
395 | 491 |
} |
396 | 492 |
} |
397 | 493 |
|
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.app/org.gvsig.view3d.app.common/src/main/resources-plugin/i18n/text.properties | ||
---|---|---|
20 | 20 |
show_scale = Mostrar scala |
21 | 21 |
show_stars_background= Mostrar fondo de estrellas |
22 | 22 |
synchronize_view_3d= Sincronizar visores |
23 |
synchronize_viewport_3d= Sincronizar enfoques |
|
23 | 24 |
sphere_vertical_exaggeration= Exageraci\u00F3n vertical visor esf\u00E9rico |
24 | 25 |
sphere_view_3d= Visor 3D esf\u00E9rico |
25 | 26 |
tile_configuration= Configuraci\u00F3n de tiles |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.app/org.gvsig.view3d.app.common/src/main/resources-plugin/i18n/text_en.properties | ||
---|---|---|
20 | 20 |
show_scale = Show scale |
21 | 21 |
show_stars_background= Show stars background |
22 | 22 |
synchronize_view_3d= Synchronize view |
23 |
synchronize_viewport_3d= Synchronize view ports |
|
23 | 24 |
sphere_vertical_exaggeration= Sphere vertical exaggeration |
24 | 25 |
sphere_view_3d= Sphere 3D viewer |
25 | 26 |
tile_configuration= Tile configuration |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.app/org.gvsig.view3d.app.common/src/main/resources-plugin/config.xml | ||
---|---|---|
55 | 55 |
</tool-bar> |
56 | 56 |
|
57 | 57 |
</extension> |
58 |
|
|
59 |
<extension |
|
60 |
class-name="org.gvsig.view3d.app.mainplugin.SynchronizeViewPort3DExtension" |
|
61 |
description="" active="true" priority="1"> |
|
62 |
|
|
63 |
<action name="synchronize-viewport-3d" label="synchronize_viewport_3d" |
|
64 |
tooltip="synchronize_viewport_3d" position="650400400" action-command="synchronize-viewport-3d" |
|
65 |
icon="synchronize-viewport-3d" accelerator="" /> |
|
66 |
|
|
67 |
<menu text="View/view_3d/synchronize_viewport_3d" name="synchronize-viewport-3d" /> |
|
68 |
|
|
69 |
<tool-bar name="view-3d" position="650400000"> |
|
70 |
<action-tool name="synchronize-viewport-3d" /> |
|
71 |
</tool-bar> |
|
72 |
|
|
73 |
</extension> |
|
58 | 74 |
</extensions> |
59 | 75 |
</plugin-config> |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.app/org.gvsig.view3d.app.common/src/main/java/org/gvsig/view3d/app/mainplugin/SynchronizeViewPort3DExtension.java | ||
---|---|---|
1 |
package org.gvsig.view3d.app.mainplugin; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.gvsig.andami.IconThemeHelper; |
|
6 |
import org.gvsig.andami.plugins.Extension; |
|
7 |
import org.gvsig.app.ApplicationLocator; |
|
8 |
import org.gvsig.app.ApplicationManager; |
|
9 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
10 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
11 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport; |
|
12 |
import org.gvsig.view3d.swing.api.MapControl3D; |
|
13 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
|
14 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
|
15 |
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE; |
|
16 |
|
|
17 |
|
|
18 |
public class SynchronizeViewPort3DExtension extends Extension { |
|
19 |
|
|
20 |
public void initialize() { |
|
21 |
registerIcons(); |
|
22 |
} |
|
23 |
|
|
24 |
private void registerIcons() { |
|
25 |
IconThemeHelper.registerIcon("view3d", "synchronize-viewport-3d", this); |
|
26 |
} |
|
27 |
|
|
28 |
public void execute(String actionCommand) { |
|
29 |
|
|
30 |
if ("synchronize-viewport-3d".equals(actionCommand)) { |
|
31 |
IView view = getActiveView(); |
|
32 |
|
|
33 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
|
34 |
MapControl3D mapControl3DFlat = |
|
35 |
manager.getMapControl3D( |
|
36 |
(ExtendedPropertiesSupport) view.getViewDocument(), |
|
37 |
TYPE.FLAT); |
|
38 |
if (mapControl3DFlat != null) { |
|
39 |
mapControl3DFlat.synchronizeViewPorts(); |
|
40 |
} |
|
41 |
|
|
42 |
MapControl3D mapControl3DSphere = |
|
43 |
manager.getMapControl3D( |
|
44 |
(ExtendedPropertiesSupport) view.getViewDocument(), |
|
45 |
TYPE.SPHERE); |
|
46 |
if (mapControl3DSphere != null) { |
|
47 |
mapControl3DSphere.synchronizeViewPorts(); |
|
48 |
} |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
public boolean isEnabled() { |
|
53 |
IView view = getActiveView(); |
|
54 |
if (view != null) { |
|
55 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
|
56 |
List<MapControl3D> mapControls3D = |
|
57 |
manager.getMapControl3D((ExtendedPropertiesSupport) view |
|
58 |
.getViewDocument()); |
|
59 |
if (mapControls3D.size() > 0) { |
|
60 |
return true; |
|
61 |
} |
|
62 |
} |
|
63 |
return false; |
|
64 |
} |
|
65 |
|
|
66 |
public boolean isVisible() { |
|
67 |
IView view = getActiveView(); |
|
68 |
if (view != null) { |
|
69 |
return true; |
|
70 |
} |
|
71 |
return false; |
|
72 |
} |
|
73 |
|
|
74 |
private IView getActiveView() { |
|
75 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
76 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
77 |
return view; |
|
78 |
} |
|
79 |
|
|
80 |
} |
Also available in: Unified diff