Statistics
| Revision:

root / trunk / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / debug / DwgEntityListener.java @ 20098

History | View | Annotate | Download (8.07 KB)

1
/*
2
 * Created on 10-ene-2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: DwgEntityListener.java 20098 2008-04-14 08:42:53Z jmvivo $
47
* $Log$
48
* Revision 1.7  2007-09-20 07:16:02  jaume
49
* refactor name IVectorialLegend -> IVectorLegend and some method names
50
*
51
* Revision 1.6  2007/03/06 17:27:42  caballero
52
* Exceptions
53
*
54
* Revision 1.5  2007/02/15 16:28:36  fdiaz
55
* Compatibilizado con branch v10
56
*
57
* Revision 1.4  2007/02/01 20:03:21  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.3  2007/01/24 20:40:02  azabala
61
* added debug of dwg class
62
*
63
* Revision 1.2  2007/01/12 19:57:44  azabala
64
* *** empty log message ***
65
*
66
* Revision 1.1  2007/01/11 20:31:05  azabala
67
* *** empty log message ***
68
*
69
*
70
*/
71
package com.iver.cit.gvsig.drivers.dwg.debug;
72

    
73
import java.awt.Cursor;
74
import java.awt.geom.Point2D;
75
import java.awt.geom.Rectangle2D;
76

    
77
import javax.swing.JOptionPane;
78

    
79
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
80
import com.iver.cit.gvsig.drivers.dwg.DwgMemoryDriver;
81
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
82
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException;
83
import com.iver.cit.gvsig.exceptions.visitors.StartVisitorException;
84
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
85
import com.iver.cit.gvsig.fmap.MapControl;
86
import com.iver.cit.gvsig.fmap.core.IGeometry;
87
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
88
import com.iver.cit.gvsig.fmap.layers.FLayer;
89
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
90
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator;
91
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
92
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
93
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
94
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
95
import com.iver.cit.jdwglib.dwg.DwgHandleReference;
96
import com.iver.cit.jdwglib.dwg.DwgObject;
97

    
98
/**
99
 * <p>Listens events produced by the selection of a <i>control point</i> of any graphical geometry 
100
 *  in layers of the associated {@link MapControl MapControl} object.</p>
101
 *
102
 * <p>Listens a single or double click of any mouse's button, and also the events produced when
103
 *  the position of the cursor has changed on the associated <code>MapControl</code> object.</p>
104
 *  
105
 * <p>Uses {@link Cursor#CROSSHAIR_CURSOR Cursor#CROSSHAIR_CURSOR} as mouse's cursor image.</p>
106
 */
107
public class DwgEntityListener implements PointListener{
108
        /**
109
         * Used to calculate the pixel at the associated <code>MapControl</code> down the
110
         *  position of the mouse.
111
         */
112
        public static int pixelTolerance = 3;
113

    
114
        /**
115
         * Reference to the <code>MapControl</code> object that uses.
116
         */
117
        private MapControl mapCtrl;
118

    
119
        /**
120
         * The cursor used to work with this tool listener.
121
         * 
122
         * @see #getCursor()
123
         */  
124
        private Cursor cur = java.awt.Cursor.
125
                    getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
126

    
127
    /**
128
     * <p>Creates a new <code>DwgEntityListener</code> object.</p>
129
     *
130
     * @param mc the <code>MapControl</code> where will be applied the changes
131
     */
132
    public DwgEntityListener(MapControl mc) {
133
        this.mapCtrl = mc;
134
    }
135

    
136
    /*
137
     * (non-Javadoc)
138
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
139
     */
140
    public void point(PointEvent event) throws BehaviorException {
141

    
142
        Point2D pReal = mapCtrl.
143
                        getMapContext().
144
                        getViewPort().
145
                        toMapPoint(event.getPoint());
146

    
147
                SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
148
                while (it.hasNext())
149
                {
150
                        FLayer aux = it.next();
151
                        if (!aux.isActive())
152
                                continue;
153
                        if(! (aux instanceof FLyrVect))
154
                                return;
155

    
156
                        FLyrVect vectLyr = (FLyrVect) aux;
157
                        VectorialDriver driver = vectLyr.getSource().getDriver();
158

    
159
//                                Class dwgMemoryDriverClass = LayerFactory.getDM().getDriverClassByName("gvSIG DWG Memory Driver");
160
//                                if(dwgMemoryDriverClass == null){
161
//                                        System.out.println("Driver dwg no disponible???");
162
//                                        return;
163
//                                }
164
//                                if(!dwgMemoryDriverClass.isInstance(driver))
165
//                                        return;
166
//                                PluginClassLoader loader = PluginServices.
167
//                                        getPluginServices(this).getClassLoader();
168
//                                try {
169
//                                        loader.loadClass(dwgMemoryDriverClass.toString());
170
//                                } catch (ClassNotFoundException e1) {
171
//                                        return;
172
//                                }
173

    
174
                        if(!(driver instanceof com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver))
175
                                        return;
176
                        /*
177
                         * Comentarizar el if completo para que funcione en el libFMap del HEAD.
178
                         */
179
                        if(!(driver instanceof DwgMemoryDriver)){
180
                                JOptionPane.showConfirmDialog(null,
181
                                                "Esta herramienta s?lo funciona con libFMap del HEAD.\nVer comentarios en el codigo de esta clase."
182
                                );
183
                                return;
184
                        }
185

    
186
                        final com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver dwgDriver = (com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)driver;
187
                        double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance);
188

    
189
                                Rectangle2D recPoint = new Rectangle2D.Double(pReal.getX() - (realTol / 2),
190
                                pReal.getY() - (realTol / 2), realTol, realTol);
191

    
192
                                try {
193
                                        vectLyr.process(new FeatureVisitor(){
194
                                                public void visit(IGeometry g, int index) throws VisitorException {
195
                                                        /*
196
                                                         * Cambiar la comentarizacion de las dos lineas de abajo
197
                                                         * para funcione la herramienta en libFMap del HEAD.
198
                                                         * No funciona en la v10 porque AbstractCadMemoryDriver
199
                                                         * no declara el metodo getCadSource.
200
                                                         * Quitar tambi?n el if que muestra el mensaje de arriba.
201
                                                         */
202

    
203
//                                                                DwgObject dwgObj = (DwgObject) dwgDriver.getCadSource(index);
204
                                                        DwgObject dwgObj = (DwgObject) ((DwgMemoryDriver)dwgDriver).getCadSource(index);
205

    
206

    
207
                                                        DwgHandleReference handle = dwgObj.getLayerHandle();
208
                                                        int lyrHdlCode = handle.getCode();
209
                                                        int lyrHdl = handle.getOffset();
210
                                                        JOptionPane.showConfirmDialog(null,
211
                                                                        "hdlCode="+lyrHdlCode+",hdl="+lyrHdl+"entity="+dwgObj.getClass().getName());
212
                                                }
213

    
214
                                                public String getProcessDescription() {
215
                                                        return "";
216
                                                }
217

    
218
                                                public void stop(FLayer layer) throws VisitorException {
219
                                                }
220

    
221
                                                public boolean start(FLayer layer) throws StartVisitorException {
222
                                                        return true;
223
                                                }}, recPoint);
224
                                } catch (VisitorException e) {
225
                                        // TODO Auto-generated catch block
226
                                        e.printStackTrace();
227
                                } catch (ReadDriverException e) {
228
                                        // TODO Auto-generated catch block
229
                                        e.printStackTrace();
230
                                } 
231
                }//while
232
    }
233

    
234
    /*
235
     * (non-Javadoc)
236
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
237
     */
238
    public Cursor getCursor() {
239
        return cur;
240
    }
241

    
242
    /*
243
     * (non-Javadoc)
244
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
245
     */
246
    public boolean cancelDrawing() {
247
        return false;
248
    }
249

    
250
    /*
251
     * (non-Javadoc)
252
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
253
     */
254
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
255
                point(event);
256
        }
257
}
258

    
259

    
260

    
261

    
262