Revision 26269
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/build.xml | ||
---|---|---|
1 |
<project name="Generar extension en Andami ext3D" default="generate-without-source" basedir="."> |
|
2 |
<description> |
|
3 |
Instala el plugin de ejemplo en Andami. |
|
4 |
</description> |
|
5 |
<!-- set global properties for this build --> |
|
6 |
<property name="src" location="src" /> |
|
7 |
<property name="build" location="bin" /> |
|
8 |
<property name="dist" location="dist" /> |
|
9 |
<property name="resources" location="resources" /> |
|
10 |
<property name="plugin" value="com.iver.ai2.gvsig3d" /> |
|
11 |
<property name="extension-dir" location="../_fwAndami/gvSIG/extensiones" /> |
|
12 |
<property name="logos-dir" location="../_fwAndami/theme" /> |
|
13 |
<property name="gvsig-lib" location="../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/lib" /> |
|
14 |
<property name="binaries-dir" location="../binaries/" /> |
|
15 |
<property name="ext3D" value="../_fwAndami/gvSIG/extensiones/com.iver.ai2.gvsig3d" /> |
|
16 |
<property name="ext3Dgui-lib" value="../ext3Dgui/lib" /> |
|
17 |
<property name="ext3D-lib" value="../ext3D/lib" /> |
|
18 |
<property name="buildman.executable" value="buildman/bin/bmn.py"/> |
|
19 |
<import file="../binaries/ant/utilities.xml"/> |
|
20 |
|
|
21 |
<target name="batch-build" description="Builds all. This is called by appgvSIG script" |
|
22 |
depends="compile,create-jar,copy-files,clean-dist"> |
|
23 |
</target> |
|
24 |
|
|
25 |
<target name="init"> |
|
26 |
<mkdir dir="${build}" /> |
|
27 |
|
|
28 |
</target> |
|
29 |
|
|
30 |
|
|
31 |
<target name="compile" description="compile the source" > |
|
32 |
<!-- Compile the Java code from ${src} to ${build} --> |
|
33 |
<mkdir dir="${build}" /> |
|
34 |
<loadEclipseClasspath project="${basedir}"/> |
|
35 |
<gvSIG-javac |
|
36 |
classpath="${eclipseClasspath}" /> |
|
37 |
</target> |
|
38 |
|
|
39 |
<target name="create-jar" |
|
40 |
description="Creates the jar"> |
|
41 |
|
|
42 |
<mkdir dir="${dist}" /> |
|
43 |
<mkdir dir="${dist}/lib" /> |
|
44 |
<!-- Put everything in ${build} into the jar file |
|
45 |
Except classes to be instantiated in core gvSIG --> |
|
46 |
<jar jarfile="${dist}/lib/${plugin}.jar" basedir="${build}" excludes="com/iver/ai2/gvsig3d/map3d/layers/Layer3DProps.*,com/iver/ai2/gvsig3d/gui/VectorLayerMenu.*,com/iver/ai2/gvsig3d/camera/ProjectCamera.*,com/iver/ai2/gvsig3d/resources/ResourcesFactory.*" /> |
|
47 |
|
|
48 |
<!-- Put in this .jar the classes to be instantiated in gvSIG --> |
|
49 |
<jar jarfile="${dist}/lib/${plugin}_share.jar" basedir="${build}" includes="com/iver/ai2/gvsig3d/map3d/layers/Layer3DProps.*,com/iver/ai2/gvsig3d/gui/VectorLayerMenu.*,com/iver/ai2/gvsig3d/camera/ProjectCamera.*,com/iver/ai2/gvsig3d/resources/ResourcesFactory.*" /> |
|
50 |
<jar jarfile="${gvsig-lib}/${plugin}_share.jar" basedir="${build}" includes="com/iver/ai2/gvsig3d/map3d/layers/Layer3DProps.*,com/iver/ai2/gvsig3d/gui/VectorLayerMenu.*,com/iver/ai2/gvsig3d/camera/ProjectCamera.*,com/iver/ai2/gvsig3d/resources/ResourcesFactory.*" /> |
|
51 |
|
|
52 |
</target> |
|
53 |
|
|
54 |
<target name="copy-files"> |
|
55 |
<copy todir="${dist}/lib/"> |
|
56 |
<fileset dir="lib/" includes="*.jar" /> |
|
57 |
</copy> |
|
58 |
|
|
59 |
<copy todir="${ext3Dgui-lib}/"> |
|
60 |
<fileset dir="${dist}/lib/" includes="*.jar" /> |
|
61 |
</copy> |
|
62 |
|
|
63 |
<mkdir dir="../ext3Dgui/resources" /> |
|
64 |
<copy todir="../ext3Dgui/resources/"> |
|
65 |
<fileset dir="resources" includes="*.**" /> |
|
66 |
</copy> |
|
67 |
|
|
68 |
</target> |
|
69 |
|
|
70 |
|
|
71 |
<target name="generate-without-source" description="generate the distribution without the source file" |
|
72 |
depends="create-jar,copy-files,clean-dist"> |
|
73 |
</target> |
|
74 |
|
|
75 |
<target name="clean" description="clean up" depends="clean-dist"> |
|
76 |
<echo message="dentro de clean" /> |
|
77 |
<delete dir="${build}" /> |
|
78 |
</target> |
|
79 |
|
|
80 |
<target name="clean-dist" description="clean up dist"> |
|
81 |
<delete dir="${dist}" /> |
|
82 |
</target> |
|
83 |
|
|
84 |
<!--target name="copy-binaries"> |
|
85 |
<copy todir="${binaries-dir}"> |
|
86 |
<fileset dir="binaries/" includes="**/**" /> |
|
87 |
</copy> |
|
88 |
</target--> |
|
89 |
|
|
90 |
<target name="update-binaries-cache"> |
|
91 |
<exec executable="python"> |
|
92 |
<arg value="${buildman.executable}"/> |
|
93 |
<arg value="update"/> |
|
94 |
<arg value="--cache"/> |
|
95 |
</exec> |
|
96 |
</target> |
|
97 |
|
|
98 |
<target name="update-binaries-remote"> |
|
99 |
<exec executable="python"> |
|
100 |
<arg value="${buildman.executable}"/> |
|
101 |
<arg value="update"/> |
|
102 |
<arg value="--remote"/> |
|
103 |
</exec> |
|
104 |
</target> |
|
105 |
|
|
106 |
<target name="update-binaries-atifglrx-remote"> |
|
107 |
<exec executable="python"> |
|
108 |
<arg value="${buildman.executable}"/> |
|
109 |
<arg value="update"/> |
|
110 |
<arg value="--file"/> |
|
111 |
<arg value="depman-atifglrx.xml"/> |
|
112 |
<arg value="--remote"/> |
|
113 |
</exec> |
|
114 |
</target> |
|
115 |
</project> |
|
116 |
|
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/test/com/iver/ai2/gvsig3d/TransformacionesTest.java | ||
---|---|---|
1 |
//package com.iver.ai2.gvsig3d; |
|
2 |
// |
|
3 |
//import junit.framework.TestCase; |
|
4 |
// |
|
5 |
//import com.iver.ai2.gvsig3d.gui.Hud; |
|
6 |
//import com.iver.ai2.gvsig3d.utils.UtilCoord; |
|
7 |
// |
|
8 |
//import es.upv.ai2.osgvp.Vec3; |
|
9 |
//import es.upv.ai2.osgvp.planets.Planet; |
|
10 |
//import es.upv.ai2.osgvp.viewer.ViewerFactory; |
|
11 |
// |
|
12 |
//public class TransformacionesTest extends TestCase { |
|
13 |
// public void testTrasnform() throws Throwable { |
|
14 |
// |
|
15 |
// System.out.println("De grados a radianes " + UtilCoord.radianes(180)); |
|
16 |
// System.out |
|
17 |
// .println("De radianes a grados " + UtilCoord.degrees(Math.PI)); |
|
18 |
// |
|
19 |
// Vec3 esferica = new Vec3(6378137, 0.0, 40.0); |
|
20 |
// Vec3 cartesianas = new Vec3(4885936.723, 0, 4099786.416); |
|
21 |
// |
|
22 |
// Vec3 e = UtilCoord.GeoToCarte(esferica); |
|
23 |
// Vec3 c = UtilCoord.CarteToGeo(cartesianas); |
|
24 |
// |
|
25 |
// System.out.println("De geocentricas a cartesianas " + e.x() + " " |
|
26 |
// + e.y() + " " + e.z()); |
|
27 |
// System.out.println("De cartesianas a geocentricas " + c.x() + " " |
|
28 |
// + c.y() + " " + c.z()); |
|
29 |
// |
|
30 |
// } |
|
31 |
// |
|
32 |
// public void testTraPla() throws Throwable { |
|
33 |
// |
|
34 |
//// ViewerFactory m_canvas3d = new ViewerFactory(); |
|
35 |
//// |
|
36 |
//// m_canvas3d.startAnimator(); |
|
37 |
//// |
|
38 |
//// Planet m_planet = new Planet(); |
|
39 |
//// |
|
40 |
//// m_planet.setCoordinateSystemType(Planet.CoordinateSystemType.PROJECTED); |
|
41 |
//// |
|
42 |
//// Vec3 cartesianas = new Vec3(4886013.328, 0, 4099850.692); |
|
43 |
//// Vec3 e = m_planet.convertXYZToLatLongHeight(cartesianas); |
|
44 |
//// |
|
45 |
//// System.out.println("De geocentricas a cartesianas " + e.x() + " " |
|
46 |
//// + e.y() + " " + e.z()); |
|
47 |
// |
|
48 |
// } |
|
49 |
// |
|
50 |
// public void testHome() throws Throwable { |
|
51 |
// |
|
52 |
// // System.out.println(new File("home").getCanonicalPath()); |
|
53 |
// |
|
54 |
// String home = System.getProperty("user.home"); |
|
55 |
// System.out.println(home); |
|
56 |
// |
|
57 |
// String wd = System.getProperty("user.dir"); |
|
58 |
// System.out.println(wd); |
|
59 |
// |
|
60 |
// } |
|
61 |
// |
|
62 |
// public void testGrados() throws Throwable { |
|
63 |
// |
|
64 |
//// System.out.println(Hud.getSexagesinal(74.90555556, false)); |
|
65 |
// |
|
66 |
// } |
|
67 |
// |
|
68 |
// public void testJDialog() throws Throwable { |
|
69 |
//// |
|
70 |
//// VectorLayerMenu vectorLayerMenu = new VectorLayerMenu(null); |
|
71 |
//// vectorLayerMenu.setModal(true); |
|
72 |
//// vectorLayerMenu.pack(); |
|
73 |
//// vectorLayerMenu.setVisible(true); |
|
74 |
// } |
|
75 |
// |
|
76 |
//} |
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/test/com/iver/ai2/gvsig3d/OperationTest.java | ||
---|---|---|
1 |
//package com.iver.ai2.gvsig3d; |
|
2 |
// |
|
3 |
//import junit.framework.TestCase; |
|
4 |
// |
|
5 |
//import org.gvsig.exceptions.BaseException; |
|
6 |
// |
|
7 |
//import com.iver.ai2.gvsig3d.geometry.GeometryFactory; |
|
8 |
//import com.iver.ai2.gvsig3d.geometry.Point3D; |
|
9 |
// |
|
10 |
//public class OperationTest extends TestCase { |
|
11 |
// |
|
12 |
// public void testRegisterOperation() throws BaseException { |
|
13 |
// |
|
14 |
// // Registering operation |
|
15 |
// System.out.println("Registering operations."); |
|
16 |
//// Draw3DDefaultOperation.registerOperations(); |
|
17 |
// |
|
18 |
// } |
|
19 |
// |
|
20 |
// public void testPoint3DDrawOperation() throws BaseException { |
|
21 |
// |
|
22 |
// //Registering operation |
|
23 |
// System.out.println("Registering operations."); |
|
24 |
//// Draw3DDefaultOperation.registerOperations(); |
|
25 |
// |
|
26 |
// System.out.println("Drawing point 3D"); |
|
27 |
// Point3D point = (Point3D) GeometryFactory.createPoint3D("punto3D"); |
|
28 |
//// point.doOperation(GeometryOperation.DRAW3D_OPERATION); |
|
29 |
// |
|
30 |
// } |
|
31 |
//} |
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/config/about.htm | ||
---|---|---|
1 |
<html> |
|
2 |
<head> |
|
3 |
<title>Extension 3D del programa GvSIG </title> |
|
4 |
<meta content=""> |
|
5 |
<style></style> |
|
6 |
</head> |
|
7 |
<body> |
|
8 |
<table width="60%" border="0"> |
|
9 |
<tr> |
|
10 |
<td width="64%"><img src="images/logo_horiz_bicolor_gva.png" width="329" height="50"></td> |
|
11 |
<td width="36%"><div align="right"><img src="images/logoIver.png" width="87" height="50"></div></td> |
|
12 |
</tr> |
|
13 |
<tr> |
|
14 |
<td colspan="2"><font face="Arial, Helvetica, sans-serif">© Copyright |
|
15 |
Generalitat Valenciana, IVER T.I and other contributors 2005.</font></td> |
|
16 |
</tr> |
|
17 |
</table> |
|
18 |
<h3>Extesión de la Aplicación para el tratamiento de topónimos del Instituto Geográfico Nacional</h3> |
|
19 |
<p><br><br><b> Build Number: #build.number#</b></p> |
|
20 |
</body> |
|
21 |
</html> |
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/build.number | ||
---|---|---|
1 |
#Build Number for ANT. Do not edit! |
|
2 |
#Mon Jul 16 14:09:59 CEST 2007 |
|
3 |
build.number=12 |
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/src/org/gvsig/gvsig3d/listener/EditorListener.java | ||
---|---|---|
1 |
package org.gvsig.gvsig3d.listener; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* osgVP. OSG Virtual Planets. |
|
5 |
* |
|
6 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
7 |
* of the Valencian Government (CIT) |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 |
|
12 |
* of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
22 |
* MA 02110-1301, USA. |
|
23 |
* |
|
24 |
*/ |
|
25 |
/* |
|
26 |
* AUTHORS (In addition to CIT): |
|
27 |
* 2008 Instituto de Automática e Informática Industrial, UPV. |
|
28 |
*/ |
|
29 |
|
|
30 |
import java.awt.event.KeyEvent; |
|
31 |
import java.awt.event.KeyListener; |
|
32 |
import java.awt.event.MouseEvent; |
|
33 |
import java.awt.event.MouseListener; |
|
34 |
import java.util.logging.Level; |
|
35 |
import org.apache.log4j.Logger; |
|
36 |
import org.geotools.data.wms.xml.WMSDescribeLayerTypes._LayerDescription; |
|
37 |
import org.gvsig.gvsig3d.cacheservices.OSGCacheService; |
|
38 |
import org.gvsig.gvsig3d.navigation.NavigationMode; |
|
39 |
import org.gvsig.osgvp.ActionCommand; |
|
40 |
import org.gvsig.osgvp.Group; |
|
41 |
import org.gvsig.osgvp.Node; |
|
42 |
import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions; |
|
43 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
|
44 |
import org.gvsig.osgvp.manipulator.AddSelectionCommand; |
|
45 |
import org.gvsig.osgvp.manipulator.EditionManager; |
|
46 |
import org.gvsig.osgvp.manipulator.Manipulator; |
|
47 |
import org.gvsig.osgvp.manipulator.ManipulatorHandler; |
|
48 |
import org.gvsig.osgvp.manipulator.RemoveAllSelectionCommand; |
|
49 |
import org.gvsig.osgvp.manipulator.UngroupCommand; |
|
50 |
import org.gvsig.osgvp.planets.CustomTerrainManipulator; |
|
51 |
import org.gvsig.osgvp.planets.PlanetViewer; |
|
52 |
import org.gvsig.osgvp.planets.PlanetViewer; |
|
53 |
import org.gvsig.osgvp.util.Util; |
|
54 |
import org.gvsig.osgvp.viewer.Camera; |
|
55 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
|
56 |
import org.gvsig.osgvp.viewer.Intersection; |
|
57 |
import org.gvsig.osgvp.viewer.Intersections; |
|
58 |
import org.gvsig.osgvp.viewer.manipulator.CameraManipulator; |
|
59 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
|
60 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
61 |
|
|
62 |
public class EditorListener implements MouseListener, KeyListener { |
|
63 |
|
|
64 |
private boolean _lockPick = false; |
|
65 |
private EditionManager _manager; |
|
66 |
private ManipulatorHandler _handler; |
|
67 |
private IViewerContainer viewer; |
|
68 |
private FLayer _layer; |
|
69 |
IViewerContainer _canvas3d; |
|
70 |
private Camera _cam; |
|
71 |
private static Logger logger = Logger.getLogger(EditorListener.class |
|
72 |
.getName()); |
|
73 |
|
|
74 |
private PlanetViewer planetViewer; |
|
75 |
|
|
76 |
public EditorListener(EditionManager manager, ManipulatorHandler handler, |
|
77 |
FLayer layer, IViewerContainer canvas3d, PlanetViewer planetViewer) { |
|
78 |
|
|
79 |
_manager = manager; |
|
80 |
_handler = handler; |
|
81 |
_layer = layer; |
|
82 |
_canvas3d = canvas3d; |
|
83 |
viewer = canvas3d; |
|
84 |
viewer.addMouseListener(this); |
|
85 |
viewer.addKeyListener(this); |
|
86 |
this.planetViewer = planetViewer; |
|
87 |
|
|
88 |
} |
|
89 |
|
|
90 |
public void mouseDoubleClick(MouseEvent e) { |
|
91 |
|
|
92 |
} |
|
93 |
|
|
94 |
public void mouseDown(MouseEvent e) { |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
public void mouseUp(MouseEvent e) { |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
public void keyPressed(KeyEvent e) { |
|
103 |
|
|
104 |
if (e.getKeyCode() == KeyEvent.VK_SHIFT) { |
|
105 |
|
|
106 |
Util.logger.log(Level.INFO, "Control Pressed"); |
|
107 |
if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) { |
|
108 |
_lockPick = true; |
|
109 |
_handler.setActive(true); |
|
110 |
/* |
|
111 |
* _cam = _canvas3d.getOSGViewer().getCamera(); |
|
112 |
* _canvas3d.getOSGViewer().setCameraManipulator(null); |
|
113 |
* _canvas3d.getOSGViewer().setCamera(_cam); |
|
114 |
*/ |
|
115 |
NavigationMode.removeAllNavigationModes(this.planetViewer |
|
116 |
.getCustomTerrainManipulator()); |
|
117 |
|
|
118 |
} |
|
119 |
|
|
120 |
} |
|
121 |
|
|
122 |
else if (e.getKeyCode() == KeyEvent.VK_G) { |
|
123 |
|
|
124 |
_manager.group(); |
|
125 |
|
|
126 |
} |
|
127 |
|
|
128 |
else if (e.getKeyCode() == KeyEvent.VK_U) { |
|
129 |
_manager.ungroup(); |
|
130 |
|
|
131 |
} |
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
public void keyReleased(KeyEvent e) { |
|
136 |
|
|
137 |
if (e.getKeyCode() == KeyEvent.VK_SHIFT) { |
|
138 |
|
|
139 |
if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) { |
|
140 |
Util.logger.log(Level.INFO, "Control Released"); |
|
141 |
_lockPick = false; |
|
142 |
_handler.setActive(false); |
|
143 |
// NavigationMode.restoreAllNavigationModes(); |
|
144 |
/* |
|
145 |
* ((PlanetViewer) _canvas3d.getOSGViewer()) |
|
146 |
* .restoreCustomTerrainManipulator(); |
|
147 |
* _canvas3d.getOSGViewer().setCamera(_cam); try { |
|
148 |
* ((PlanetViewer) _canvas3d.getOSGViewer()) .activePlanet(0); |
|
149 |
* ((PlanetViewer) |
|
150 |
* _canvas3d.getOSGViewer()).computeActiveCoordinateSystemNodePath(); } |
|
151 |
* catch (ChildIndexOutOfBoundsExceptions e1) { |
|
152 |
* logger.fatal("Planet doesn't exist"); } |
|
153 |
*/ |
|
154 |
|
|
155 |
NavigationMode.restoreAllNavigationModes(planetViewer |
|
156 |
.getCustomTerrainManipulator()); |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
} |
|
161 |
|
|
162 |
if (e.getKeyCode() == KeyEvent.VK_DELETE) { |
|
163 |
|
|
164 |
if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) { |
|
165 |
_manager.deleteSelectedNodes(); |
|
166 |
} |
|
167 |
|
|
168 |
} |
|
169 |
|
|
170 |
} |
|
171 |
|
|
172 |
public void mouseClicked(MouseEvent e) { |
|
173 |
|
|
174 |
ActionCommand command; |
|
175 |
if (_lockPick) { |
|
176 |
|
|
177 |
try { |
|
178 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
179 |
Intersections polytopeHits; |
|
180 |
polytopeHits = viewer.getOSGViewer().rayPick( |
|
181 |
this._manager.getScene(), e.getX(), e.getY(), |
|
182 |
Manipulator.NEG_MANIPULATOR_NODEMASK); |
|
183 |
|
|
184 |
if (polytopeHits.containsIntersections()) { |
|
185 |
|
|
186 |
Intersection hit = polytopeHits.getFirstIntersection(); |
|
187 |
Node nodeHit = (Node) hit.getNodePath().get(1); |
|
188 |
System.out.println("Node name: " |
|
189 |
+ nodeHit.getNodeName()); |
|
190 |
Group parent; |
|
191 |
parent = new Group(nodeHit.getParent(0).getCPtr()); |
|
192 |
int k; |
|
193 |
k = parent.getChildIndex(nodeHit); |
|
194 |
command = new AddSelectionCommand(k, _manager); |
|
195 |
command.execute(); |
|
196 |
|
|
197 |
} |
|
198 |
|
|
199 |
else { |
|
200 |
|
|
201 |
command = new RemoveAllSelectionCommand(_manager); |
|
202 |
command.execute(); |
|
203 |
|
|
204 |
} |
|
205 |
} |
|
206 |
} catch (NodeException e2) { |
|
207 |
// TODO Auto-generated catch block |
|
208 |
e2.printStackTrace(); |
|
209 |
} |
|
210 |
} |
|
211 |
// } else if (e.getButton() == MouseEvent.BUTTON2) { |
|
212 |
// |
|
213 |
// command = new UngroupCommand(_manager); |
|
214 |
// command.execute(); |
|
215 |
// |
|
216 |
// } |
|
217 |
|
|
218 |
} |
|
219 |
|
|
220 |
public void mouseEntered(MouseEvent e) { |
|
221 |
// TODO Auto-generated method stub |
|
222 |
|
|
223 |
} |
|
224 |
|
|
225 |
public void mouseExited(MouseEvent e) { |
|
226 |
// TODO Auto-generated method stub |
|
227 |
|
|
228 |
} |
|
229 |
|
|
230 |
public void mousePressed(MouseEvent e) { |
|
231 |
// TODO Auto-generated method stub |
|
232 |
|
|
233 |
} |
|
234 |
|
|
235 |
public void mouseReleased(MouseEvent e) { |
|
236 |
// TODO Auto-generated method stub |
|
237 |
|
|
238 |
} |
|
239 |
|
|
240 |
public void keyTyped(KeyEvent e) { |
|
241 |
// TODO Auto-generated method stub |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
} |
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/src/org/gvsig/gvsig3d/listener/canvasListener.java | ||
---|---|---|
1 |
package org.gvsig.gvsig3d.listener; |
|
2 |
|
|
3 |
import java.awt.event.KeyEvent; |
|
4 |
import java.awt.event.KeyListener; |
|
5 |
import java.awt.event.MouseEvent; |
|
6 |
import java.awt.event.MouseListener; |
|
7 |
|
|
8 |
import org.gvsig.osgvp.Vec3; |
|
9 |
import org.gvsig.osgvp.planets.Planet; |
|
10 |
import org.gvsig.osgvp.planets.PlanetViewer; |
|
11 |
import org.gvsig.osgvp.viewer.Camera; |
|
12 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
|
13 |
import org.gvsig.osgvp.viewer.Intersection; |
|
14 |
import org.gvsig.osgvp.viewer.Intersections; |
|
15 |
import org.gvsig.osgvp.viewer.OSGViewer; |
|
16 |
|
|
17 |
public class canvasListener implements KeyListener, MouseListener { |
|
18 |
private static boolean active = false; |
|
19 |
|
|
20 |
private IViewerContainer m_canvas3d = null; |
|
21 |
|
|
22 |
private Planet planet; |
|
23 |
|
|
24 |
private RotatePlanet updateViewThread; |
|
25 |
|
|
26 |
private int frameRate = 24; |
|
27 |
|
|
28 |
private PlanetViewer m_planetViewer; |
|
29 |
|
|
30 |
private static boolean activeRot; |
|
31 |
|
|
32 |
public void setCanvas(IViewerContainer m_canvas3d) { |
|
33 |
this.m_canvas3d = m_canvas3d; |
|
34 |
this.m_planetViewer = (PlanetViewer) m_canvas3d.getOSGViewer(); |
|
35 |
} |
|
36 |
|
|
37 |
public void keyPressed(KeyEvent kev) { |
|
38 |
// TODO Auto-generated method stub |
|
39 |
int codigo = kev.getKeyCode(); |
|
40 |
switch (kev.getKeyChar()) { |
|
41 |
case 'w': |
|
42 |
case 'W': |
|
43 |
active = !active; |
|
44 |
if (active) { |
|
45 |
m_planetViewer.setPolygonMode( |
|
46 |
OSGViewer.PolygonModeType.GL_LINE); |
|
47 |
} else { |
|
48 |
m_planetViewer.setPolygonMode( |
|
49 |
OSGViewer.PolygonModeType.GL_FILL); |
|
50 |
} |
|
51 |
break; |
|
52 |
case 'a': |
|
53 |
case 'A': |
|
54 |
Thread thread; |
|
55 |
activeRot = !activeRot; |
|
56 |
if (activeRot) { |
|
57 |
|
|
58 |
updateViewThread = new RotatePlanet(1000/frameRate); |
|
59 |
|
|
60 |
// Create the thread supplying it with the runnable object |
|
61 |
thread = new Thread(updateViewThread); |
|
62 |
|
|
63 |
// Start the thread |
|
64 |
thread.start(); |
|
65 |
} else { |
|
66 |
updateViewThread.end(); |
|
67 |
} |
|
68 |
break; |
|
69 |
|
|
70 |
case 'e': |
|
71 |
case 'E': |
|
72 |
updateViewThread.setTime(1000/frameRate++); |
|
73 |
break; |
|
74 |
case 'd': |
|
75 |
case 'D': |
|
76 |
updateViewThread.setTime(1000/frameRate--); |
|
77 |
break; |
|
78 |
} |
|
79 |
|
|
80 |
} |
|
81 |
|
|
82 |
public void keyReleased(KeyEvent kev) { |
|
83 |
// TODO Auto-generated method stub |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
public void keyTyped(KeyEvent kev) { |
|
88 |
// TODO Auto-generated method stub |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Class to rotate the planet. This class implements runnable and contructor |
|
94 |
* with time parameter. |
|
95 |
* |
|
96 |
* @author julio |
|
97 |
* |
|
98 |
*/ |
|
99 |
public class RotatePlanet implements Runnable { |
|
100 |
|
|
101 |
private boolean finish = false; |
|
102 |
|
|
103 |
private long time; |
|
104 |
|
|
105 |
public RotatePlanet(long time) { |
|
106 |
this.time = time; |
|
107 |
} |
|
108 |
|
|
109 |
double lat = 0.0; |
|
110 |
|
|
111 |
double longi = 0.0; |
|
112 |
|
|
113 |
// This method is called when the thread runs |
|
114 |
public void run() { |
|
115 |
while (true) { |
|
116 |
try { |
|
117 |
Thread.sleep(time); |
|
118 |
synchronized (this) { |
|
119 |
if (finish) { |
|
120 |
break; |
|
121 |
} |
|
122 |
} |
|
123 |
} catch (InterruptedException e) { |
|
124 |
|
|
125 |
e.printStackTrace(); |
|
126 |
} |
|
127 |
// Rotate planet |
|
128 |
longi += 1.0; |
|
129 |
longi = longi > 360 ? 0 : longi; |
|
130 |
Camera cam = m_planetViewer.getCamera(); |
|
131 |
Vec3 camPos = planet.convertLatLongHeightToXYZ(new Vec3(lat, |
|
132 |
longi, cam.getEye().z())); |
|
133 |
|
|
134 |
cam.setViewByLookAt(camPos.x(), camPos.y(), 500000 * 16.6, |
|
135 |
0, 0, 0, 0, 0, 1); |
|
136 |
m_planetViewer.setCamera(cam); |
|
137 |
|
|
138 |
// Repainting canvas |
|
139 |
m_canvas3d.repaint(); |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
public synchronized void end() { |
|
144 |
finish = true; |
|
145 |
} |
|
146 |
|
|
147 |
public long getTime() { |
|
148 |
return time; |
|
149 |
} |
|
150 |
|
|
151 |
public void setTime(long time) { |
|
152 |
this.time = time; |
|
153 |
} |
|
154 |
|
|
155 |
} |
|
156 |
|
|
157 |
public Planet getPlanet() { |
|
158 |
return planet; |
|
159 |
} |
|
160 |
|
|
161 |
public void setPlanet(Planet planet) { |
|
162 |
this.planet = planet; |
|
163 |
} |
|
164 |
|
|
165 |
public void mouseClicked(MouseEvent e) { |
|
166 |
if (e.getButton() == MouseEvent.BUTTON1) { |
|
167 |
Intersections hits = m_planetViewer.rayPick(this.planet, e.getX(), e.getY()); |
|
168 |
if(hits.containsIntersections()) { |
|
169 |
Intersection hit = hits.getFirstIntersection(); |
|
170 |
System.err.println("Point:" + hit.getIntersectionPoint().toString()); |
|
171 |
Vec3 point = planet.convertXYZToLatLongHeight(hit |
|
172 |
.getIntersectionPoint()); |
|
173 |
System.err.println("LatLonHeight: " + point.toString()); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
} |
|
178 |
|
|
179 |
public void mouseEntered(MouseEvent arg0) { |
|
180 |
// TODO Auto-generated method stub |
|
181 |
|
|
182 |
} |
|
183 |
|
|
184 |
public void mouseExited(MouseEvent arg0) { |
|
185 |
// TODO Auto-generated method stub |
|
186 |
|
|
187 |
} |
|
188 |
|
|
189 |
public void mousePressed(MouseEvent arg0) { |
|
190 |
// TODO Auto-generated method stub |
|
191 |
|
|
192 |
} |
|
193 |
|
|
194 |
public void mouseReleased(MouseEvent arg0) { |
|
195 |
// TODO Auto-generated method stub |
|
196 |
|
|
197 |
} |
|
198 |
|
|
199 |
} |
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/src/org/gvsig/gvsig3d/cacheservices/OSGCacheService.java | ||
---|---|---|
1 |
package org.gvsig.gvsig3d.cacheservices; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileNotFoundException; |
|
6 |
|
|
7 |
import javax.swing.JOptionPane; |
|
8 |
|
|
9 |
import org.apache.log4j.Logger; |
|
10 |
import org.cresques.cts.IProjection; |
|
11 |
import org.gvsig.cacheservice.CacheService; |
|
12 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
13 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
14 |
import org.gvsig.fmap.geom.primitive.AbstractPrimitive; |
|
15 |
import org.gvsig.geometries3D.MultiGeometry; |
|
16 |
import org.gvsig.geometries3D.MultiSolid; |
|
17 |
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG; |
|
18 |
import org.gvsig.gvsig3d.listener.EditorListener; |
|
19 |
import org.gvsig.operations3D.Draw3DMultiSolid; |
|
20 |
import org.gvsig.operations3D.context.Draw3DContext; |
|
21 |
import org.gvsig.osgvp.Group; |
|
22 |
import org.gvsig.osgvp.Node; |
|
23 |
import org.gvsig.osgvp.PositionAttitudeTransform; |
|
24 |
import org.gvsig.osgvp.Vec3; |
|
25 |
import org.gvsig.osgvp.osgDB; |
|
26 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
|
27 |
import org.gvsig.osgvp.manipulator.EditionManager; |
|
28 |
import org.gvsig.osgvp.manipulator.ManipulatorHandler; |
|
29 |
import org.gvsig.osgvp.manipulator.RemoveAllSelectionCommand; |
|
30 |
import org.gvsig.osgvp.planets.Planet; |
|
31 |
import org.gvsig.osgvp.planets.PlanetViewer; |
|
32 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
|
33 |
|
|
34 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
35 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
|
36 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
|
37 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
38 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
39 |
|
|
40 |
public class OSGCacheService extends CacheService { |
|
41 |
|
|
42 |
private IViewerContainer _canvas3D; |
|
43 |
|
|
44 |
private PlanetViewer _planetViewer; |
|
45 |
|
|
46 |
private Rectangle2D _lyrExtentRect; |
|
47 |
|
|
48 |
private FLayer _layer; |
|
49 |
|
|
50 |
// vector caching for libJOSG |
|
51 |
private Group _layerNode; |
|
52 |
|
|
53 |
private boolean newLayerOSG = false; |
|
54 |
|
|
55 |
private EditionManager editionManager; |
|
56 |
|
|
57 |
private ManipulatorHandler manipulatorHandler; |
|
58 |
|
|
59 |
private EditorListener editionListener; |
|
60 |
|
|
61 |
private RemoveAllSelectionCommand command; |
|
62 |
|
|
63 |
private String filePath; |
|
64 |
|
|
65 |
private static Logger logger = Logger.getLogger(OSGCacheService.class |
|
66 |
.getName()); |
|
67 |
|
|
68 |
// private ISymbol _currentSymbol; |
|
69 |
|
|
70 |
public OSGCacheService(IViewerContainer canvas3D, Planet planet, |
|
71 |
String name, FLayer layer, IProjection viewProj) { |
|
72 |
super(planet.getPlanetName(), name); |
|
73 |
|
|
74 |
// getNames(); |
|
75 |
|
|
76 |
_canvas3D = canvas3D; |
|
77 |
_planetViewer = (PlanetViewer) canvas3D.getOSGViewer(); |
|
78 |
_layer = layer; |
|
79 |
_layerNode = new Group(); |
|
80 |
_layerNode.setNodeName("layer3DOSG"); |
|
81 |
try { |
|
82 |
editionManager = new EditionManager(); |
|
83 |
_layerNode.addChild(editionManager); |
|
84 |
manipulatorHandler = new ManipulatorHandler(); |
|
85 |
manipulatorHandler.setActive(false); |
|
86 |
|
|
87 |
editionListener = new EditorListener(editionManager, |
|
88 |
manipulatorHandler, layer, _canvas3D, _planetViewer); |
|
89 |
|
|
90 |
_canvas3D.getOSGViewer().addEventHandler(manipulatorHandler); |
|
91 |
|
|
92 |
} catch (NodeException e2) { |
|
93 |
// TODO Auto-generated catch block |
|
94 |
e2.printStackTrace(); |
|
95 |
} |
|
96 |
|
|
97 |
try { |
|
98 |
_planetViewer.addSpecialNode(_layerNode); |
|
99 |
} catch (NodeException e1) { |
|
100 |
logger.error("Command: " |
|
101 |
+ "Error adding new child node to the special node.", e1); |
|
102 |
} |
|
103 |
|
|
104 |
int cacheType = CacheService.GLOBAL; |
|
105 |
if (planet.getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) |
|
106 |
cacheType += SPHERIC; |
|
107 |
else |
|
108 |
cacheType += PLANE; |
|
109 |
setCacheType(cacheType); |
|
110 |
|
|
111 |
try { |
|
112 |
_lyrExtentRect = _layer.getFullExtent(); |
|
113 |
} catch (ExpansionFileReadException e) { |
|
114 |
// TODO Auto-generated catch block |
|
115 |
e.printStackTrace(); |
|
116 |
} catch (ReadDriverException e) { |
|
117 |
// TODO Auto-generated catch block |
|
118 |
e.printStackTrace(); |
|
119 |
} |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
public Group getLayerNode() { |
|
124 |
|
|
125 |
if (!Layer3DProps.getLayer3DProps(this._layer).isEditing()) { |
|
126 |
try { |
|
127 |
return (Group) editionManager.getScene(); |
|
128 |
} catch (NodeException e) { |
|
129 |
// TODO Auto-generated catch block |
|
130 |
e.printStackTrace(); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
else { |
|
135 |
|
|
136 |
try { |
|
137 |
return editionManager.getTransformedScene(); |
|
138 |
} catch (NodeException e) { |
|
139 |
// TODO Auto-generated catch block |
|
140 |
e.printStackTrace(); |
|
141 |
} |
|
142 |
|
|
143 |
} |
|
144 |
return _layerNode; |
|
145 |
} |
|
146 |
|
|
147 |
// uses a strategy to get all features from layer and their symbols |
|
148 |
// and add them to the planet |
|
149 |
|
|
150 |
public void AddFeaturesToPlanet() { |
|
151 |
|
|
152 |
boolean newLayer = Layer3DProps.getLayer3DProps(_layer).isNewLayerOSG(); |
|
153 |
|
|
154 |
if (!newLayer) { |
|
155 |
GvsigDriverOSG osgD = (GvsigDriverOSG) ((FLyrVect) _layer) |
|
156 |
.getSource().getDriver(); |
|
157 |
try { |
|
158 |
File file = osgD.getFile(); |
|
159 |
filePath = file.getAbsolutePath(); |
|
160 |
Node n = null; |
|
161 |
|
|
162 |
try { |
|
163 |
n = osgDB.readNodeFile(file.getAbsolutePath()); |
|
164 |
} catch (FileNotFoundException e) { |
|
165 |
// TODO Auto-generated catch block |
|
166 |
e.printStackTrace(); |
|
167 |
} |
|
168 |
MultiGeometry root = osgD.getOSGDriver().getRootFeature(); |
|
169 |
// Insert the geometry in the root node of the graph. |
|
170 |
Group g = new Group(n.getCPtr()); |
|
171 |
// buildGeometry(root, g); |
|
172 |
// g.addChild(n); |
|
173 |
for (int i = 0; i < g.getNumChildren(); i++) { |
|
174 |
|
|
175 |
editionManager.setScene(g.getChild(i)); |
|
176 |
|
|
177 |
} |
|
178 |
|
|
179 |
// _layerNode.addChild(n); |
|
180 |
// startEditing(); |
|
181 |
// _layerNode.addChild(g); |
|
182 |
} catch (NodeException e) { |
|
183 |
logger |
|
184 |
.error( |
|
185 |
"Command: " |
|
186 |
+ "Error loading OSG file. File must be generated with gvSIG", |
|
187 |
e); |
|
188 |
|
|
189 |
} |
|
190 |
} |
|
191 |
this._canvas3D.repaint(); |
|
192 |
} |
|
193 |
|
|
194 |
public void RefreshFeaturesToPlanet() { |
|
195 |
this.DeleteFeaturesToPlanet(); |
|
196 |
this.AddFeaturesToPlanet(); |
|
197 |
} |
|
198 |
|
|
199 |
public void DeleteFeaturesToPlanet() { |
|
200 |
try { |
|
201 |
endEditing(); |
|
202 |
_planetViewer.removeSpecialNode(_layerNode); |
|
203 |
} catch (NodeException e) { |
|
204 |
logger.error("Command: " |
|
205 |
+ "Error removing new child node to the special node.", e); |
|
206 |
} |
|
207 |
} |
|
208 |
|
|
209 |
public void refreshFeaturesToPlanet(boolean visible) { |
|
210 |
_layerNode.setNodeMask(visible ? 0xffffffff : 0x00000000); |
|
211 |
} |
|
212 |
|
|
213 |
public void AddGeometryToLayer(MultiGeometry multiGeometry, Vec3 position, |
|
214 |
Vec3 rotation, Vec3 scale) { |
|
215 |
Group group = new Group(); |
|
216 |
group.setNodeName("GROUP-PAT"); |
|
217 |
PositionAttitudeTransform posAttTrasn = null; |
|
218 |
try { |
|
219 |
posAttTrasn = new PositionAttitudeTransform(); |
|
220 |
posAttTrasn.setPosition(position); |
|
221 |
posAttTrasn.setScale(scale); |
|
222 |
posAttTrasn.setNodeName("PAT"); |
|
223 |
// posAttTrasn.setAttitude((float) rotation.x(), new Vec3(1,0,0)); |
|
224 |
// posAttTrasn.setAttitude((float) rotation.y(), new Vec3(0,1,0)); |
|
225 |
// posAttTrasn.setAttitude((float) rotation.z(), new Vec3(0,0,1)); |
|
226 |
buildGeometry(multiGeometry, group); |
|
227 |
posAttTrasn.addChild(group); |
|
228 |
|
|
229 |
Layer3DProps props3D = Layer3DProps.getLayer3DProps(this._layer); |
|
230 |
// if (props3D.isEditing()){ |
|
231 |
editionManager.setScene(posAttTrasn); |
|
232 |
// }else{ |
|
233 |
// _layerNode.addChild(posAttTrasn); |
|
234 |
// } |
|
235 |
// _layerNode.addChild(group); |
|
236 |
} catch (NodeException e1) { |
|
237 |
// TODO Auto-generated catch block |
|
238 |
e1.printStackTrace(); |
|
239 |
} |
|
240 |
|
|
241 |
} |
|
242 |
|
|
243 |
private void buildGeometry(AbstractPrimitive geom, Group group) |
|
244 |
throws NodeException { |
|
245 |
|
|
246 |
int i; |
|
247 |
|
|
248 |
if (geom instanceof MultiGeometry) { |
|
249 |
MultiGeometry multiGeometry = (MultiGeometry) geom; |
|
250 |
for (i = 0; i < multiGeometry.getGeometries().size(); i++) { |
|
251 |
|
|
252 |
Group child = new Group(); |
|
253 |
group.addChild(child); |
|
254 |
buildGeometry(multiGeometry.getGeometries().get(i), child); |
|
255 |
} |
|
256 |
} else if (geom instanceof MultiSolid) { |
|
257 |
// Getting the geometry |
|
258 |
MultiSolid multiSolid = (MultiSolid) geom; |
|
259 |
// Creating the context and adding parameters |
|
260 |
Draw3DContext ctx3D = new Draw3DContext(); |
|
261 |
ctx3D.setGroup(group); |
|
262 |
// Creating the drawing operation |
|
263 |
Draw3DMultiSolid d3DMultiSolid = new Draw3DMultiSolid(); |
|
264 |
|
|
265 |
try { |
|
266 |
// Invoking the operation for the multisolid |
|
267 |
multiSolid.invokeOperation(d3DMultiSolid.getOperationIndex(), |
|
268 |
ctx3D); |
|
269 |
} catch (GeometryOperationNotSupportedException e) { |
|
270 |
// TODO Auto-generated catch block |
|
271 |
e.printStackTrace(); |
|
272 |
} catch (GeometryOperationException e) { |
|
273 |
// TODO Auto-generated catch block |
|
274 |
e.printStackTrace(); |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
} |
|
279 |
|
|
280 |
public void startEditing() { |
|
281 |
|
|
282 |
Layer3DProps props3D = Layer3DProps.getLayer3DProps(this._layer); |
|
283 |
if ((props3D.getType() == Layer3DProps.layer3DOSG) |
|
284 |
&& (!props3D.isEditing())) { |
|
285 |
props3D.setEditing(true); |
|
286 |
props3D.setNewLayerOSG(true); |
|
287 |
JOptionPane.showMessageDialog(null, |
|
288 |
"La capa ha sido puesta en edicion"); |
|
289 |
|
|
290 |
// editionManager = new EditionManager(); |
|
291 |
// editionManager.setNodeName("EDITIONMANAGER"); |
|
292 |
// editionManager.getChild(0).setNodeName("GROUP"); |
|
293 |
// for (int i = 0; i < _layerNode.getNumChildren(); i++) { |
|
294 |
// Node node = _layerNode.getChild(i); |
|
295 |
// editionManager.setScene(node); |
|
296 |
// _layerNode.removeChild(node); |
|
297 |
// } |
|
298 |
// _layerNode.addChild(editionManager); |
|
299 |
// _layerNode.setNodeName("LAYERNODE"); |
|
300 |
// Group parent = _layerNode.getParent(0); |
|
301 |
// parent.removeChild(_layerNode); |
|
302 |
// parent.addChild(editionManager); |
|
303 |
|
|
304 |
// ManipulatorHandler manipulatorHandler = new ManipulatorHandler(); |
|
305 |
// manipulatorHandler.setActive(true); |
|
306 |
// public void changeDragger(String draggerType) |
|
307 |
// editionManager.changeDragger(DraggerType.ROTATE_SPHERE_DRAGGER |
|
308 |
// ); |
|
309 |
// editionManager.changeDragger(DraggerType.TABBOX_DRAGGER); |
|
310 |
// editionManager.changeDragger(DraggerType.TRANSLATE_AXIS_DRAGGER |
|
311 |
// ); |
|
312 |
|
|
313 |
} |
|
314 |
} |
|
315 |
|
|
316 |
public void endEditing() { |
|
317 |
|
|
318 |
Layer3DProps props3D = Layer3DProps.getLayer3DProps(this._layer); |
|
319 |
if ((props3D.getType() == Layer3DProps.layer3DOSG) |
|
320 |
&& (props3D.isEditing())) { |
|
321 |
props3D.setEditing(false); |
|
322 |
|
|
323 |
if (props3D.isNewLayerOSG()) |
|
324 |
JOptionPane |
|
325 |
.showMessageDialog(null, |
|
326 |
"La capa ha sido modificada, recuerde salvar los cambios."); |
|
327 |
|
|
328 |
command = new RemoveAllSelectionCommand(editionManager); |
|
329 |
command.execute(); |
|
330 |
|
|
331 |
// Group scene = editionManager.getTransformedScene(); |
|
332 |
|
|
333 |
// for (int i = 0; i < _layerNode.getNumChildren(); i++) { |
|
334 |
// Node node = _layerNode.getChild(i); |
|
335 |
// _layerNode.removeChild(node); |
|
336 |
// |
|
337 |
// } |
|
338 |
// _layerNode.removeChildren(); |
|
339 |
|
|
340 |
// for (int i =0; i < scene.getNumChildren(); i++){ |
|
341 |
// |
|
342 |
// _layerNode.addChild(scene.getChild(i)); |
|
343 |
// |
|
344 |
// } |
|
345 |
// |
|
346 |
|
|
347 |
// Group parent = _layerNode.getParent(0); |
|
348 |
// parent.removeChild(_layerNode); |
|
349 |
// parent.addChild(scene); |
|
350 |
// public void changeDragger(String draggerType) |
|
351 |
// editionManager.changeDragger(DraggerType.ROTATE_SPHERE_DRAGGER |
|
352 |
// ); |
|
353 |
// editionManager.changeDragger(DraggerType.TABBOX_DRAGGER); |
|
354 |
// editionManager.changeDragger(DraggerType.TRANSLATE_AXIS_DRAGGER |
|
355 |
// ); |
|
356 |
|
|
357 |
manipulatorHandler.setActive(false); |
|
358 |
|
|
359 |
} |
|
360 |
|
|
361 |
} |
|
362 |
|
|
363 |
public EditionManager getEditionManager() { |
|
364 |
return editionManager; |
|
365 |
} |
|
366 |
|
|
367 |
public void setEditionManager(EditionManager editionManager) { |
|
368 |
this.editionManager = editionManager; |
|
369 |
} |
|
370 |
|
|
371 |
public String getLayerPath() { |
|
372 |
|
|
373 |
return filePath; |
|
374 |
} |
|
375 |
|
|
376 |
} |
tags/3D_Animation_v1_0alpha_Build_7/libraries/lib3DMap/src/org/gvsig/gvsig3d/cacheservices/FLayerCacheService.java | ||
---|---|---|
1 |
package org.gvsig.gvsig3d.cacheservices; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Dimension; |
|
5 |
import java.awt.Graphics2D; |
|
6 |
import java.awt.Image; |
|
7 |
import java.awt.geom.AffineTransform; |
|
8 |
import java.awt.geom.Rectangle2D; |
|
9 |
import java.awt.image.BufferedImage; |
|
10 |
import java.io.File; |
|
11 |
import java.io.IOException; |
|
12 |
import java.net.URL; |
|
13 |
import java.util.HashMap; |
|
14 |
import java.util.Hashtable; |
|
15 |
import java.util.Vector; |
|
16 |
|
|
17 |
import org.cresques.cts.IProjection; |
|
18 |
import org.cresques.px.Extent; |
|
19 |
import org.gvsig.cacheservice.CacheService; |
|
20 |
import org.gvsig.cacheservice.CacheServiceException; |
|
21 |
import org.gvsig.cacheservice.RasterCacheService; |
|
22 |
import org.gvsig.cacheservice.TileNum; |
|
23 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
|
24 |
import org.gvsig.osgvp.planets.Planet; |
|
25 |
import org.gvsig.raster.buffer.BufferFactory; |
|
26 |
import org.gvsig.raster.buffer.RasterBuffer; |
|
27 |
import org.gvsig.raster.buffer.WriterBufferServer; |
|
28 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
|
29 |
import org.gvsig.raster.dataset.InvalidSetViewException; |
|
30 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
|
31 |
import org.gvsig.raster.dataset.Params; |
|
32 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
|
33 |
import org.gvsig.remoteClient.utils.Utilities; |
|
34 |
import org.gvsig.remoteClient.wcs.WCSStatus; |
|
35 |
import org.gvsig.remoteClient.wms.ICancellable; |
|
36 |
import org.gvsig.remoteClient.wms.WMSStatus; |
|
37 |
|
|
38 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
39 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
|
40 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
|
41 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
42 |
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver; |
|
43 |
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriverFactory; |
|
44 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver; |
|
45 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory; |
|
46 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
47 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
|
48 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
49 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
|
50 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
|
51 |
import com.iver.utiles.FileUtils; |
|
52 |
import com.iver.utiles.swing.threads.Cancellable; |
|
53 |
|
|
54 |
public class FLayerCacheService extends RasterCacheService { |
|
55 |
private boolean _loadFailed = true; |
|
56 |
private Extent _extent; |
|
57 |
private Rectangle2D _lyrExtentRect; |
|
58 |
private FLayer _layer; |
|
59 |
private IProjection _viewProj; |
|
60 |
private int _dataType; |
|
61 |
|
|
62 |
// WMS terrain |
|
63 |
// TODO Un toggle this comment to use WMS and WCS extensions. |
|
64 |
FMapWMSDriver _wmsDriver = null; |
|
65 |
FMapWCSDriver _wcsDriver = null; |
|
66 |
|
|
67 |
WMSStatus _wmsStatus = null; |
|
68 |
WCSStatus _wcsStatus = null; |
|
69 |
|
|
70 |
public FLayerCacheService(Planet planet, String name, FLayer layer, |
|
71 |
IProjection viewProj) { |
|
72 |
super(planet.getPlanetName(), name); |
|
73 |
|
|
74 |
_layer = layer; |
|
75 |
_viewProj = viewProj; |
|
76 |
_loadFailed = true; |
|
77 |
|
|
78 |
int cacheType = CacheService.GLOBAL; |
|
79 |
if (planet.getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) |
|
80 |
cacheType += SPHERIC; |
|
81 |
else |
|
82 |
cacheType += PLANE; |
|
83 |
setCacheType(cacheType); |
|
84 |
|
|
85 |
try { |
|
86 |
_lyrExtentRect = _layer.getFullExtent(); |
|
87 |
} catch (ExpansionFileReadException e) { |
|
88 |
e.printStackTrace(); |
|
89 |
} catch (ReadDriverException e) { |
|
90 |
e.printStackTrace(); |
|
91 |
} |
|
92 |
|
|
93 |
_extent = new Extent(_lyrExtentRect); |
|
94 |
|
|
95 |
Layer3DProps props3D = Layer3DProps.getLayer3DProps(layer); |
|
96 |
_dataType = props3D.getType(); |
|
97 |
if (_dataType == Layer3DProps.layer3DImage) |
|
98 |
setFileExtension(".png"); |
|
99 |
else |
|
100 |
setFileExtension(".tif"); |
|
101 |
|
|
102 |
_loadFailed = false; |
|
103 |
|
|
104 |
} |
|
105 |
|
|
106 |
protected class MyCancel implements Cancellable, ICancellable { |
|
107 |
|
|
108 |
public boolean isCanceled() { |
|
109 |
return false; |
|
110 |
} |
|
111 |
|
|
112 |
public void setCanceled(boolean canceled) { |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
/* if you don?t put and ID the wms donwload will be fail */ |
|
117 |
public Object getID() { |
|
118 |
return this; |
|
119 |
} |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
private Image getTileFromLayer(String fName, Rectangle2D tileExtent) { |
|
124 |
BufferedImage image; |
|
125 |
|
|
126 |
if (_dataType == Layer3DProps.layer3DImage) { |
|
127 |
int size = getTileSize(); |
|
128 |
image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); |
|
129 |
|
|
130 |
ViewPort vp = new ViewPort(_viewProj); |
|
131 |
vp.setExtent(tileExtent); // the real extent of the tile |
|
132 |
// NotificationManager.addInfo("Extent solicitado--> " |
|
133 |
// + tileExtent.getMinX() + " " + tileExtent.getMinY() + " " |
|
134 |
// + tileExtent.getMaxX() + " " + tileExtent.getMaxY()); |
|
135 |
vp.setAdjustable(false); |
|
136 |
vp.setImageSize(new Dimension(size, size)); |
|
137 |
// vp.setDist1pixel(1 / 150000); |
|
138 |
vp.setDist1pixel(0.000000001); |
|
139 |
|
|
140 |
Graphics2D graphics = image.createGraphics(); |
|
141 |
Color backgColor = new Color(255, 255, 255, 0); // transparent |
|
142 |
// background |
|
143 |
graphics.setColor(backgColor); |
|
144 |
graphics.fillRect(0, 0, size, size); |
|
145 |
|
|
146 |
// CancelDraw canceldraw = new MapControl.CancelDraw(); |
|
147 |
// canceldraw.setCanceled(false); |
|
148 |
// For now we'll use a trick to make sure the layer is drawn |
|
149 |
// even if it has scale dependency |
|
150 |
// In the future, a scale corresponding to the tile should be passed |
|
151 |
double scale = 0.5 * (_layer.getMaxScale() + _layer.getMinScale()); |
|
152 |
int trans = 255; |
|
153 |
|
|
154 |
// The layers of remote services don�t have transparency. |
|
155 |
if (_layer.getClass().equals(FLyrVect.class)) { |
|
156 |
// Generate layers 3D properties |
|
157 |
Layer3DProps props3D = Layer3DProps.getLayer3DProps(_layer); |
|
158 |
// // Getting layer transparency |
|
159 |
// trans = ((FLyrDefault) _layer).getTransparency(); |
|
160 |
// // Casting to float |
|
161 |
// float transFloat = (float) ((float) (trans) / 255.0); |
|
162 |
// // Setting in the layers 3D props |
|
163 |
// props3D.setOpacity(transFloat); |
|
164 |
// fix opaque the layer to save in disk |
|
165 |
((FLyrDefault) _layer).setTransparency((int) (props3D.getOpacity()*255)); |
|
166 |
} |
|
167 |
|
|
168 |
try { |
|
169 |
// disabling the iterator |
|
170 |
// if (_layer instanceof FLyrVect) { |
|
171 |
// FLyrVect layerVect = (FLyrVect) _layer; |
|
172 |
// boolean strategyUse = layerVect.isUseStrategy(); |
|
173 |
// layerVect.setUseStrategy(true); |
|
174 |
// layerVect.draw(image, graphics, vp, new MyCancel(), scale); |
|
175 |
// layerVect.setUseStrategy(strategyUse); |
|
176 |
// } else |
|
177 |
_layer.draw(image, graphics, vp, new MyCancel(), scale); |
|
178 |
} catch (ReadDriverException e) { |
|
179 |
e.printStackTrace(); |
|
180 |
} |
|
181 |
// Restoring the real value of transparency |
|
182 |
if (_layer.getClass().equals(FLyrVect.class)) { |
|
183 |
// fix the real transparency to the layer |
|
184 |
((FLyrDefault) _layer).setTransparency(trans); |
|
185 |
} |
|
186 |
|
|
187 |
try { |
|
188 |
File file = new File(fName); |
|
189 |
String format = getFileExtension().substring(1); |
|
190 |
saveCachedFile(image, format, file); |
|
191 |
} catch (IOException e1) { |
|
192 |
e1.printStackTrace(); |
|
193 |
return null; |
|
194 |
} |
|
195 |
return image; |
|
196 |
} else { // Elevation data |
|
197 |
// TODO Un toggle this comment to use WCS and WMS extensions. |
|
198 |
if (_layer instanceof FLyrWMS) { // WMS Elevation |
|
199 |
try { |
|
200 |
FLyrWMS wmsLayer = (FLyrWMS) _layer; |
|
201 |
if (_wmsDriver == null) { |
|
202 |
|
|
203 |
URL host = wmsLayer.getHost(); |
|
204 |
_wmsDriver = FMapWMSDriverFactory |
|
205 |
.getFMapDriverForURL(host); |
|
206 |
} |
|
207 |
if (_wmsStatus == null) { |
|
208 |
_wmsStatus = new WMSStatus(); |
|
209 |
_wmsStatus.setFormat(wmsLayer.getFormat()); |
|
210 |
_wmsStatus.setHeight(32); |
|
211 |
_wmsStatus.setWidth(32); |
|
212 |
_wmsStatus.setLayerNames(Utilities.createVector( |
|
213 |
wmsLayer.getLayerQuery(), ",")); |
|
214 |
_wmsStatus.setSrs(wmsLayer.getSRS()); |
|
215 |
|
|
216 |
HashMap props = wmsLayer.getProperties(); |
|
217 |
Vector styles; |
|
218 |
Vector dimensions; |
|
219 |
styles = (Vector) (props.get("styles")); |
|
220 |
dimensions = (Vector) (props.get("dimensions")); |
|
221 |
_wmsStatus.setStyles(styles); |
|
222 |
_wmsStatus.setDimensions(dimensions); |
|
223 |
_wmsStatus.setTransparency(false); |
|
224 |
String getMapStr = wmsLayer.getOnlineResource("GetMap"); |
|
225 |
_wmsStatus.setOnlineResource(getMapStr); |
|
226 |
} |
|
227 |
_wmsStatus.setExtent(tileExtent); |
|
228 |
File f = _wmsDriver.getMap(_wmsStatus, new MyCancel()); |
|
229 |
if (f == null) |
|
230 |
return null; |
|
231 |
FileUtils.copy(f, new File(fName)); |
|
232 |
|
|
233 |
String fileName = f.getPath(); |
|
234 |
// System.out.println(fileName); |
|
235 |
|
|
236 |
} catch (Exception e) { |
|
237 |
return null; |
|
238 |
} |
|
239 |
} else if (_layer instanceof FLyrWCS) { // WCS Elevation |
|
240 |
try { |
|
241 |
FLyrWCS wcsLayer = (FLyrWCS) _layer; |
|
242 |
if (_wcsDriver == null) { |
|
243 |
|
|
244 |
URL host = wcsLayer.getHost(); |
|
245 |
_wcsDriver = FMapWCSDriverFactory |
|
246 |
.getFMapDriverForURL(host); |
|
247 |
} |
|
248 |
if (_wcsStatus == null) { |
|
249 |
_wcsStatus = new WCSStatus(); |
|
250 |
|
|
251 |
Hashtable props = wcsLayer.getProperties(); |
|
252 |
|
|
253 |
_wcsStatus.setCoveraName((String) props.get("name")); |
|
254 |
_wcsStatus.setFormat((String) props.get("format")); |
|
255 |
_wcsStatus.setHeight(32); |
|
256 |
_wcsStatus.setWidth(32); |
|
257 |
_wcsStatus.setSrs((String) props.get("crs")); |
|
258 |
_wcsStatus.setParameters((String) props |
|
259 |
.get("parameter")); |
|
260 |
String time = (String) props.get("time"); |
|
261 |
if (time.length() > 0) |
|
262 |
_wcsStatus.setTime(time); |
|
263 |
// _wcsStatus.setOnlineResource(wcsLayer.getOnlineResource("GetCoverage")); |
|
264 |
} |
|
265 |
_wcsStatus.setExtent(tileExtent); |
|
266 |
|
|
267 |
File f = _wcsDriver.getCoverage(_wcsStatus, new MyCancel()); |
|
268 |
if (f == null) |
|
269 |
return null; |
|
270 |
|
|
271 |
FileUtils.copy(f, new File(fName)); |
|
272 |
|
|
273 |
String fileName = f.getPath(); |
|
274 |
// System.out.println(fileName); |
|
275 |
|
|
276 |
} catch (Exception e) { |
|
277 |
return null; |
|
278 |
} |
|
279 |
} |
|
280 |
// RASTER_GRID |
|
281 |
if (_layer instanceof FLyrRasterSE) { |
|
282 |
// Grid grid = null; |
|
283 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) _layer; |
|
284 |
|
|
285 |
// grid = rasterLayer.getSource().getGrid(); |
|
286 |
// if (grid == null) |
|
287 |
// return null; |
|
288 |
|
|
289 |
BufferFactory bufferFactory = new BufferFactory(rasterLayer |
|
290 |
.getDataSource()); |
|
291 |
|
|
292 |
int bands[] = { 0 }; |
|
293 |
bufferFactory.setDrawableBands(bands); |
|
294 |
// bufferFactory.setNoDataValue(0.0); |
|
295 |
// ((IBuffer) bufferFactory).setNoDataValue(0.0); |
|
296 |
bufferFactory.setAdjustToExtent(false); |
|
297 |
|
|
298 |
try { |
|
299 |
bufferFactory.setAreaOfInterest(tileExtent.getMinX(), |
|
300 |
tileExtent.getMinY(), tileExtent.getMaxX(), |
|
301 |
tileExtent.getMaxY(), 32, 32); |
|
302 |
} catch (ArrayIndexOutOfBoundsException e1) { |
|
303 |
// TODO Auto-generated catch block |
|
304 |
e1.printStackTrace(); |
|
305 |
} catch (InvalidSetViewException e1) { |
|
306 |
// // TODO Auto-generated catch block |
|
307 |
e1.printStackTrace(); |
|
308 |
} catch (InterruptedException e1) { |
|
309 |
// // TODO Auto-generated catch block |
|
310 |
e1.printStackTrace(); |
|
311 |
} catch (RasterDriverException e) { |
|
312 |
// TODO Auto-generated catch block |
|
313 |
e.printStackTrace(); |
|
314 |
} |
|
315 |
|
|
316 |
RasterBuffer raster = (RasterBuffer) bufferFactory |
|
317 |
.getRasterBuf(); |
|
318 |
raster.setNoDataValue(0.0); |
|
319 |
try { |
|
320 |
// raster.save(fName, new Extent(tileExtent)); |
|
321 |
WriterBufferServer bufferServer = new WriterBufferServer( |
|
322 |
raster); |
|
323 |
Params p = GeoRasterWriter.getWriter(fName).getParams(); |
|
324 |
AffineTransform at = new AffineTransform(tileExtent |
|
325 |
.getWidth() / 32, 0, 0, |
|
326 |
-(tileExtent.getHeight() / 32), tileExtent |
|
327 |
.getMinX(), tileExtent.getMaxY()); |
|
328 |
GeoRasterWriter grw = GeoRasterWriter.getWriter( |
|
329 |
bufferServer, fName, 1, at, raster.getWidth(), |
|
330 |
raster.getHeight(), raster.getDataType(), p, null); |
|
331 |
// grw.setWkt(d.getWktProjection()); |
|
332 |
try { |
|
333 |
grw.dataWrite(); |
|
334 |
} catch (InterruptedException e) { |
|
335 |
// TODO Auto-generated catch block |
|
336 |
e.printStackTrace(); |
|
337 |
} |
|
338 |
grw.writeClose(); |
|
339 |
} catch (NotSupportedExtensionException e) { |
|
340 |
e.printStackTrace(); |
|
341 |
} catch (RasterDriverException e) { |
|
342 |
e.printStackTrace(); |
|
343 |
} catch (IOException e) { |
|
344 |
e.printStackTrace(); |
|
345 |
} |
|
346 |
|
|
347 |
} |
|
348 |
return null; // no image |
|
349 |
} |
|
350 |
|
|
351 |
} |
|
352 |
|
|
353 |
public String getTileAsFName(TileNum t, Rectangle2D extent) |
|
354 |
throws CacheServiceException { |
|
355 |
if (_loadFailed) { |
|
356 |
throw new CacheServiceException(new Exception()); |
|
357 |
} |
|
358 |
String tileId = t.numToOpTileId(); |
|
359 |
String fName = getTileFileName(t); |
|
360 |
// System.out.println("CMTexture2D: requestTexture: "+tileId); |
|
361 |
if (!new File(fName).exists()) { |
|
362 |
Rectangle2D tileExtent = extent; |
|
363 |
getTileFromLayer(fName, tileExtent); |
|
364 |
} |
|
365 |
return fName; |
|
366 |
} |
|
367 |
|
|
368 |
public Image getTileAsImage(TileNum tileNum, Rectangle2D extent) |
|
369 |
throws CacheServiceException { |
|
370 |
if ((tileNum.getLevel() == 5)) {// && (tileNum.getX())==29 && |
|
371 |
// (tileNum.getY()==9)){ |
|
372 |
System.err.println("pillado"); |
|
373 |
} |
|
374 |
|
|
375 |
if (_loadFailed) { |
|
376 |
throw new CacheServiceException(new Exception()); |
|
377 |
} |
|
378 |
String tileId = tileNum.numToOpTileId(); |
|
379 |
String fName = getTileFileName(tileNum); |
|
380 |
// System.out.println("CMTexture2D: requestTexture: "+tileId); |
|
381 |
Rectangle2D tileExtent = extent; |
|
382 |
return getTileFromLayer(fName, tileExtent); |
|
383 |
} |
|
384 |
|
|
385 |
public boolean intersectsLayer(Rectangle2D extent) { |
|
386 |
// Rectangle2D tileExtent = extent; |
|
387 |
return _lyrExtentRect.intersects(extent); |
|
388 |
// return Math.max(_lyrExtentRect.getMinX(),tileExtent.getMinX()) <= |
|
389 |
// Math.min(_lyrExtentRect.getMaxX(),tileExtent.getMaxX()) && |
Also available in: Unified diff