svn-gvsig-desktop / trunk / extensions / extGPS / src / org / gvsig / gps / GPSExtension.java @ 7317
History | View | Annotate | Download (6.18 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: GPSExtension.java 7317 2006-09-18 08:02:46Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.15 2006-09-18 08:02:46 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.14 2006/09/14 07:06:00 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.13 2006/08/29 11:52:17 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.12 2006/08/29 07:45:35 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.11 2006/07/31 06:46:02 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.9 2006/05/02 15:57:53 jorpiell
|
62 |
* Se ha cambiado la interfaz Extension por dos clases: una interfaz (IExtension) y una clase abstract(Extension). A partir de ahora todas las extensiones deben heredar de Extension
|
63 |
*
|
64 |
* Revision 1.8 2006/04/10 11:21:52 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.7 2006/04/07 12:45:55 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.6 2006/04/07 11:10:26 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.5 2006/04/07 08:27:48 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.4 2006/04/06 10:34:58 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.3 2006/04/05 17:08:18 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.2 2006/04/05 16:02:09 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.1 2006/04/03 16:10:27 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.1 2006/03/31 09:55:34 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
*
|
92 |
*/
|
93 |
package org.gvsig.gps; |
94 |
|
95 |
import java.awt.Color; |
96 |
import java.awt.geom.Point2D; |
97 |
import java.io.BufferedReader; |
98 |
import java.io.File; |
99 |
import java.io.FileReader; |
100 |
import java.util.ArrayList; |
101 |
|
102 |
import org.cresques.cts.ICoordTrans; |
103 |
import org.cresques.cts.IProjection; |
104 |
import org.cresques.cts.ProjectionPool; |
105 |
import org.gvsig.gps.panel.GPSControlPanel; |
106 |
|
107 |
import com.iver.andami.PluginServices; |
108 |
import com.iver.andami.plugins.Extension; |
109 |
import com.iver.andami.ui.mdiManager.IWindow; |
110 |
import com.iver.cit.gvsig.fmap.MapControl; |
111 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
112 |
import com.iver.cit.gvsig.fmap.core.FShape; |
113 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
114 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
115 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
116 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
117 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
118 |
|
119 |
public class GPSExtension extends Extension{ |
120 |
|
121 |
public void execute(String actionCommand) { |
122 |
if (actionCommand.equals("GPS_CONTROL_PANEL")) |
123 |
PluginServices.getMDIManager().addWindow(GPSControlPanel.getInstance()); |
124 |
else if (actionCommand.equals("PAINT_POINTS")) { |
125 |
paintPointsFromFile(null, null, new File("c:/gps-capture")); |
126 |
} |
127 |
|
128 |
} |
129 |
|
130 |
public boolean isEnabled() { |
131 |
return true; |
132 |
} |
133 |
|
134 |
public boolean isVisible() { |
135 |
return true; |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Takes an array of gvSIG views and draws an symbol in the specified location.
|
140 |
* If views[] is empty (vies.length == 0) then no drawing in applied.
|
141 |
* If views[] is null, then the symbol is drawn in every view in the project.
|
142 |
* If the symbol is null, then a simple point is used as symbol.
|
143 |
* @param views
|
144 |
* @param location
|
145 |
* @param symbol
|
146 |
* @param refreshing, tells if the view will be refreshed (old points will be removed)
|
147 |
*/
|
148 |
public void drawSymbol(View[] views, FSymbol symbol, Point2D location, boolean refreshing) { |
149 |
if (location == null || location.getX()==0 || location.getY()==0) return; |
150 |
if (views == null) |
151 |
{ |
152 |
IWindow[] aViews = PluginServices.getMDIManager().getAllWindows();
|
153 |
ArrayList gvViews = new ArrayList(); |
154 |
for (int i = 0; i < aViews.length; i++) { |
155 |
if (aViews[i] instanceof View) { |
156 |
gvViews.add((View) aViews[i]);
|
157 |
} |
158 |
} |
159 |
views = (View[]) gvViews.toArray(new View[0]); |
160 |
} |
161 |
|
162 |
if (symbol == null) { |
163 |
symbol = new FSymbol(FShape.CIRCLE, Color.ORANGE); |
164 |
symbol.setSizeInPixels(true);
|
165 |
symbol.setSize(10);
|
166 |
} |
167 |
|
168 |
for (int i = 0; i < views.length; i++) { |
169 |
MapControl mc = views[i].getMapControl(); |
170 |
GraphicLayer graph = mc.getMapContext().getGraphicsLayer(); |
171 |
|
172 |
if (refreshing) {
|
173 |
// Remove old graphics
|
174 |
graph.clearAllGraphics(); |
175 |
graph.clearSymbolsGraphics(); |
176 |
mc.drawGraphics(); |
177 |
} |
178 |
|
179 |
// Obtain the current view's projection
|
180 |
IProjection reqProj = mc.getProjection(); |
181 |
|
182 |
// the geodesic projection
|
183 |
IProjection latLonProj = ProjectionPool.get("EPSG:4326");
|
184 |
|
185 |
// create a translator from geodesic to the current view's projection
|
186 |
ICoordTrans ct = latLonProj.getCT(reqProj); |
187 |
|
188 |
Point2D pDst = new Point2D.Double(); |
189 |
|
190 |
// reproject the point
|
191 |
pDst = ct.convert(location, pDst); |
192 |
|
193 |
// add and draw the FSymbol to the reprojected location.
|
194 |
graph.addSymbol(symbol); |
195 |
graph.addGraphic(new FGraphic(ShapeFactory.createPoint2D(new FPoint2D(pDst)), 0)); |
196 |
mc.drawGraphics(); |
197 |
} |
198 |
} |
199 |
|
200 |
private void paintPointsFromFile(View[] views, FSymbol symbol, File f){ |
201 |
try {
|
202 |
|
203 |
BufferedReader br = new BufferedReader(new FileReader(f)); |
204 |
String line;
|
205 |
for (line = br.readLine(); line!=null; line = br.readLine()){ |
206 |
String[] numbers = line.split(","); |
207 |
|
208 |
double lon = Double.parseDouble(numbers[0]); |
209 |
double lat = Double.parseDouble(numbers[1]); |
210 |
drawSymbol(views, symbol, new Point2D.Double(lon, lat), false); |
211 |
} |
212 |
} catch (Exception e) { |
213 |
e.printStackTrace(); |
214 |
} |
215 |
} |
216 |
|
217 |
public void initialize() { |
218 |
} |
219 |
} |