Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / layers / FLyrPoints.java @ 3058

History | View | Annotate | Download (9.24 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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
package com.iver.cit.gvsig.fmap.layers;
42

    
43
import java.awt.Color;
44
import java.awt.Graphics2D;
45
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47
import java.awt.image.BufferedImage;
48
import java.util.ArrayList;
49
import java.util.Iterator;
50

    
51
import com.iver.andami.PluginServices;
52
import com.iver.cit.gvsig.fmap.DriverException;
53
import com.iver.cit.gvsig.fmap.ViewPort;
54
import com.iver.cit.gvsig.fmap.operations.Cancellable;
55
import com.iver.cit.gvsig.gui.View;
56
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel;
57

    
58

    
59
/**
60
 * Clase de capa de marcado de puntos sobre una vista. Dibuja un puntero sobre 
61
 * cada punto en la vista.
62
 *
63
 * @author Nacho Brodin (brodin_ign@gva.es)
64
 */
65
public class FLyrPoints extends FLyrDefault {
66
        
67
        public class GeoPoint{
68
                public Point2D pixelPoint = null;
69
                public Point2D mapPoint = null;
70
                public ViewPort leftViewPort =  null, rightViewPort = null;
71
                public Point2D  leftCenterPoint = null, rightCenterPoint = null;
72
                public GeoPoint(Point2D p, Point2D m){
73
                        this.pixelPoint = p;
74
                        this.mapPoint = m;
75
                }
76

    
77
        }
78
        
79
        private ArrayList pointList = new ArrayList();
80
        private final int DIAM_CIRCLE = 18;
81
        private String lastTool = null;
82
        
83
        /**
84
         * Obtiene el array de puntos
85
         * @return
86
         */
87
        public ArrayList getListPoint(){
88
                return pointList;
89
        }
90
        
91
        /**
92
         * Asigna el array de puntos 
93
         * @param list
94
         */
95
        public void setListPoint(ArrayList list){
96
                pointList = list;
97
        }
98
        
99
        /**
100
         * Dibujado de la capa de raster georeferenciado aplicando la 
101
         * transformaci?n del viewPort.
102
         */
103
        public void draw(BufferedImage image, Graphics2D g, ViewPort vp,
104
                        Cancellable cancel,double scale) throws DriverException {
105
                View theView = (View) PluginServices.getMDIManager().getActiveView();
106
                //BufferedImage img = theView.getMapControl().getImage();
107
                //g.drawImage(img, 0, 0, null);
108
                int dpto = (DIAM_CIRCLE >> 1);
109
                int incr = 5;
110
                Point2D pto = null;
111
                FLyrGeoRaster lyrGeoRaster = null;
112
                //Obtenemos la capa de puntos y la capa de georaster
113
                
114
                for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
115
                        FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
116
                        if(        lyr instanceof FLyrGeoRaster && 
117
                                lyr.getName().startsWith("*") &&
118
                                lyr.isActive())
119
                                lyrGeoRaster = (FLyrGeoRaster)lyr;
120
                }
121
                
122
                if(lyrGeoRaster != null){
123
                        for(int i=0; i<pointList.size();i++){
124
                                
125
                                //Punto de la imagen
126
                                pto = ((GeoPoint)pointList.get(i)).pixelPoint;
127
                                
128
                                if(pto != null){
129
                                        g.setColor(Color.red);
130
                                        //g.setXORMode(Color.white);
131
                                        Point2D p = lyrGeoRaster.img2World(pto);
132
                                        p = vp.fromMapPoint(p);
133
                                        g.drawOval(        (int)p.getX() - dpto, 
134
                                                                (int)p.getY() - dpto, 
135
                                                                DIAM_CIRCLE, 
136
                                                                DIAM_CIRCLE);
137
                                        g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
138
                                        g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
139
                                }
140
                                
141
                                //Punto de la vista
142
                                pto = ((GeoPoint)pointList.get(i)).mapPoint;
143
                                if(pto != null){
144
                                        Point2D p = vp.fromMapPoint(pto);
145
                                        g.setColor(Color.green);
146
                                        //g.setXORMode(Color.white);
147
                                        g.drawOval(        (int)p.getX() - dpto, 
148
                                                                (int)p.getY() - dpto, 
149
                                                                DIAM_CIRCLE, 
150
                                                                DIAM_CIRCLE);
151
                                        g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
152
                                        g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
153
                                }
154
                        }
155
                } 
156
        }
157
        
158
        /* (non-Javadoc)
159
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double)
160
         */
161
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
162
                        double scale) throws DriverException {
163
                // TODO Auto-generated method stub
164

    
165
        }
166
        
167
        /**
168
         * Elimina los puntos de la lista que no tiene las dos coordenadas asignadas.
169
         */
170
        public void clean(){
171
                Iterator iter = pointList.iterator();
172
                while (iter.hasNext()) {
173
                        GeoPoint gp = (GeoPoint) iter.next();
174
                        if(gp.mapPoint == null || gp.pixelPoint == null)
175
                                iter.remove();
176
                }
177
        }
178
        /**
179
         * A?ade un punto a la lista
180
         * @param point punto para la lista
181
         */
182
        public void addPoint(Point2D pixel, Point2D map){
183
                pointList.add(new GeoPoint(pixel, map));
184
        }
185
        
186
        /**
187
         * Obtiene el punto de la posici?n pos 
188
         */
189
        public GeoPoint getPoint(int pos){
190
                return (GeoPoint)pointList.get(pos);
191
        }
192
        
193
        /**
194
         * Elimina la lista de puntos almacenada
195
         */
196
        public void clear(){
197
                pointList = new ArrayList();
198
        }
199
        
200
        /**
201
         * Elimina el punto de la posici?n indicada por el par?metro pos
202
         * @param pos        Posici?n del punto a eliminar
203
         */
204
        public void remove(int pos){
205
                pointList.remove(pos);
206
        }
207
        
208
        /**
209
         *Elimina el ?ltimo punto de la lista.
210
         */
211
        public void delLastPoint(){
212
                pointList.remove(pointList.size() - 1);
213
        }
214
        
215
        /**
216
         * Obtiene le ?ltimo punto de la lista
217
         *
218
         */
219
        public GeoPoint getLastPoint(){
220
                return (GeoPoint)pointList.get(pointList.size());
221
        }
222
        
223
        /**
224
         * Devuelve el n?mero de puntos de la capa
225
         * @return
226
         */
227
        public int length(){
228
                return pointList.size();
229
        }
230
        
231
        /**
232
         * Actualiza un punto de la lista de una posici?n determinada
233
         * @param point punto para la lista
234
         */
235
        public void updatePoint(Point2D pixel, Point2D map, int pos){
236
                GeoPoint gp = (GeoPoint)pointList.get(pos);
237
                if(pixel != null)
238
                        gp.pixelPoint = pixel;
239
                if(map != null)
240
                        gp.mapPoint = map;
241
        }
242
        
243
        /**
244
         * Devuelve el n?mero de puntos de la lista
245
         * @return
246
         */
247
        public int getCountPoints(){
248
                if(pointList != null)
249
                        return pointList.size();
250
                else 
251
                        return 0;
252
        }
253
                
254
        /**
255
         * Obtiene el extent de la capa
256
         * @return extent en Rectangle2D.
257
         */
258
        public Rectangle2D getFullExtent()throws DriverException {
259
                View theView = (View) PluginServices.getMDIManager().getActiveView();
260
                return theView.getMapControl().getMapContext().getViewPort().getExtent();
261
        }
262
        
263
        /**
264
         * @return Returns the lastTool.
265
         */
266
        public String getLastTool() {
267
                return lastTool;
268
        }
269
        
270
        /**
271
         * @param lastTool The lastTool to set.
272
         */
273
        public void setLastTool(String lastTool) {
274
                this.lastTool = lastTool;
275
        }
276
        
277
        /**
278
         *Asigna el extent para las mini imagenes. Estas deben ser recuperadas cuando se selecciona
279
         *un punto
280
         */
281
        public void setMiniExtent(int nPoint, Point2D centerPoint, ViewPort vp, boolean isRight){
282
                System.out.println("1---->>>"+vp.getExtent());
283
                if(isRight){
284
                        ((GeoPoint)pointList.get(nPoint)).rightCenterPoint = centerPoint;
285
                        ((GeoPoint)pointList.get(nPoint)).rightViewPort = vp;
286
                }else{
287
                        ((GeoPoint)pointList.get(nPoint)).leftCenterPoint = centerPoint;
288
                        ((GeoPoint)pointList.get(nPoint)).leftViewPort = vp;
289
                }
290
        }
291
        
292
        /**
293
         * Obtiene el extent de la mini imagen
294
         * @param nPoint Punto de la lista
295
         * @return
296
         */
297
        public ViewPort getMiniExtent(int nPoint, boolean isRight){
298
                if(isRight){
299
                        System.out.println("2---->>>"+((GeoPoint)pointList.get(nPoint)).rightViewPort.getExtent());
300
                        return ((GeoPoint)pointList.get(nPoint)).rightViewPort;
301
                }else{
302
                        System.out.println("2---->>>"+((GeoPoint)pointList.get(nPoint)).leftViewPort.getExtent());
303
                        return ((GeoPoint)pointList.get(nPoint)).leftViewPort;
304
                }
305
        }
306
        
307
        /**
308
         * Obtiene el punto central de la mini imagen
309
         * @param nPoint Punto de la lista
310
         * @return
311
         */
312
        public Point2D getCenterPoint(int nPoint, boolean isRight){
313
                if(isRight)
314
                        return ((GeoPoint)pointList.get(nPoint)).rightCenterPoint;
315
                else
316
                        return ((GeoPoint)pointList.get(nPoint)).leftCenterPoint;
317
        }
318
        
319
        /**
320
         * Muestra en consola los puntos de la capa
321
         */
322
        public void showPoints(){
323
                for(int i=0;i<pointList.size();i++){
324
                        if(((GeoPoint)pointList.get(i)).pixelPoint != null && ((GeoPoint)pointList.get(i)).mapPoint != null){
325
                                System.out.println("PUNTO "+i+": ");
326
                                System.out.println("pix->"+((GeoPoint)pointList.get(i)).pixelPoint.getX()+" "+((GeoPoint)pointList.get(i)).pixelPoint.getY());
327
                                System.out.println("map->"+((GeoPoint)pointList.get(i)).mapPoint.getX()+" "+((GeoPoint)pointList.get(i)).mapPoint.getY());
328
                                System.out.println("extRight->"+((GeoPoint)pointList.get(i)).rightViewPort.getExtent());
329
                                System.out.println("extLeft->"+((GeoPoint)pointList.get(i)).leftViewPort.getExtent());
330
                        }else
331
                                System.out.println("PUNTO "+i+": NULL");
332
                }
333
        }
334
}