Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / debug / DwgEntityListener.java @ 10628

History | View | Annotate | Download (6.7 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 10628 2007-03-06 17:27:42Z caballero $
47
* $Log$
48
* Revision 1.6  2007-03-06 17:27:42  caballero
49
* Exceptions
50
*
51
* Revision 1.5  2007/02/15 16:28:36  fdiaz
52
* Compatibilizado con branch v10
53
*
54
* Revision 1.4  2007/02/01 20:03:21  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.3  2007/01/24 20:40:02  azabala
58
* added debug of dwg class
59
*
60
* Revision 1.2  2007/01/12 19:57:44  azabala
61
* *** empty log message ***
62
*
63
* Revision 1.1  2007/01/11 20:31:05  azabala
64
* *** empty log message ***
65
*
66
*
67
*/
68
package com.iver.cit.gvsig.drivers.dwg.debug;
69

    
70
import java.awt.Cursor;
71
import java.awt.geom.Point2D;
72
import java.awt.geom.Rectangle2D;
73

    
74
import javax.swing.JOptionPane;
75

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

    
95
public class DwgEntityListener implements PointListener{
96

    
97

    
98

    
99

    
100
                public static int pixelTolerance = 3;
101
            private MapControl mapCtrl;
102
            private Cursor cur = java.awt.Cursor.
103
                            getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
104

    
105
            public DwgEntityListener(MapControl mc) {
106
                this.mapCtrl = mc;
107
            }
108

    
109
            public void point(PointEvent event) throws BehaviorException {
110

    
111
                Point2D pReal = mapCtrl.
112
                                getMapContext().
113
                                getViewPort().
114
                                toMapPoint(event.getPoint());
115

    
116
                        SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
117
                        while (it.hasNext())
118
                        {
119
                                FLayer aux = it.next();
120
                                if (!aux.isActive())
121
                                        continue;
122
                                if(! (aux instanceof FLyrVect))
123
                                        return;
124

    
125
                                FLyrVect vectLyr = (FLyrVect) aux;
126
                                VectorialDriver driver = vectLyr.getSource().getDriver();
127

    
128
//                                Class dwgMemoryDriverClass = LayerFactory.getDM().getDriverClassByName("gvSIG DWG Memory Driver");
129
//                                if(dwgMemoryDriverClass == null){
130
//                                        System.out.println("Driver dwg no disponible???");
131
//                                        return;
132
//                                }
133
//                                if(!dwgMemoryDriverClass.isInstance(driver))
134
//                                        return;
135
//                                PluginClassLoader loader = PluginServices.
136
//                                        getPluginServices(this).getClassLoader();
137
//                                try {
138
//                                        loader.loadClass(dwgMemoryDriverClass.toString());
139
//                                } catch (ClassNotFoundException e1) {
140
//                                        return;
141
//                                }
142

    
143
                                if(!(driver instanceof com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver))
144
                                                return;
145
                                /*
146
                                 * Comentarizar el if completo para que funcione en el libFMap del HEAD.
147
                                 */
148
                                if(!(driver instanceof DwgMemoryDriver)){
149
                                        JOptionPane.showConfirmDialog(null,
150
                                                        "Esta herramienta s?lo funciona con libFMap del HEAD.\nVer comentarios en el codigo de esta clase."
151
                                        );
152
                                        return;
153
                                }
154

    
155
                                final com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver dwgDriver = (com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)driver;
156
                                double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance);
157

    
158
                                        Rectangle2D recPoint = new Rectangle2D.Double(pReal.getX() - (realTol / 2),
159
                                        pReal.getY() - (realTol / 2), realTol, realTol);
160

    
161
                                        try {
162
                                                vectLyr.process(new FeatureVisitor(){
163
                                                        public void visit(IGeometry g, int index) throws VisitorException {
164
                                                                /*
165
                                                                 * Cambiar la comentarizacion de las dos lineas de abajo
166
                                                                 * para funcione la herramienta en libFMap del HEAD.
167
                                                                 * No funciona en la v10 porque AbstractCadMemoryDriver
168
                                                                 * no declara el metodo getCadSource.
169
                                                                 * Quitar tambi?n el if que muestra el mensaje de arriba.
170
                                                                 */
171

    
172
//                                                                DwgObject dwgObj = (DwgObject) dwgDriver.getCadSource(index);
173
                                                                DwgObject dwgObj = (DwgObject) ((DwgMemoryDriver)dwgDriver).getCadSource(index);
174

    
175

    
176
                                                                DwgHandleReference handle = dwgObj.getLayerHandle();
177
                                                                int lyrHdlCode = handle.getCode();
178
                                                                int lyrHdl = handle.getOffset();
179
                                                                JOptionPane.showConfirmDialog(null,
180
                                                                                "hdlCode="+lyrHdlCode+",hdl="+lyrHdl+"entity="+dwgObj.getClass().getName());
181
                                                        }
182

    
183
                                                        public String getProcessDescription() {
184
                                                                return "";
185
                                                        }
186

    
187
                                                        public void stop(FLayer layer) throws VisitorException {
188
                                                        }
189

    
190
                                                        public boolean start(FLayer layer) throws StartVisitorException {
191
                                                                return true;
192
                                                        }}, recPoint);
193
                                        } catch (VisitorException e) {
194
                                                // TODO Auto-generated catch block
195
                                                e.printStackTrace();
196
                                        } catch (ReadDriverException e) {
197
                                                // TODO Auto-generated catch block
198
                                                e.printStackTrace();
199
                                        } catch (ExpansionFileReadException e) {
200
                                                // TODO Auto-generated catch block
201
                                                e.printStackTrace();
202
                                        }
203
                        }//while
204
            }
205

    
206
            public Cursor getCursor() {
207
                return cur;
208
            }
209

    
210
            public boolean cancelDrawing() {
211
                return false;
212
            }
213

    
214

    
215
                public void pointDoubleClick(PointEvent event) throws BehaviorException {
216
                        point(event);
217
                }
218

    
219

    
220
        }
221

    
222

    
223

    
224

    
225