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 | 9686 | azabala | /*
|
---|---|---|---|
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$
|
||
47 | * $Log$
|
||
48 | 10628 | caballero | * 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 | 10353 | fdiaz | * Compatibilizado con branch v10
|
53 | *
|
||
54 | * Revision 1.4 2007/02/01 20:03:21 azabala
|
||
55 | 10054 | azabala | * *** empty log message ***
|
56 | *
|
||
57 | * Revision 1.3 2007/01/24 20:40:02 azabala
|
||
58 | 9895 | azabala | * added debug of dwg class
|
59 | *
|
||
60 | * Revision 1.2 2007/01/12 19:57:44 azabala
|
||
61 | 9686 | azabala | * *** empty log message ***
|
62 | *
|
||
63 | 9721 | azabala | * Revision 1.1 2007/01/11 20:31:05 azabala
|
64 | * *** empty log message ***
|
||
65 | 9686 | azabala | *
|
66 | 9721 | azabala | *
|
67 | 9686 | azabala | */
|
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 | 10628 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
77 | 10353 | fdiaz | import com.iver.cit.gvsig.drivers.dwg.DwgMemoryDriver; |
78 | 10628 | caballero | 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 | 9686 | azabala | 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 | 10054 | azabala | import com.iver.cit.jdwglib.dwg.DwgHandleReference; |
93 | 9686 | azabala | import com.iver.cit.jdwglib.dwg.DwgObject; |
94 | |||
95 | public class DwgEntityListener implements PointListener{ |
||
96 | |||
97 | 10628 | caballero | |
98 | |||
99 | |||
100 | 9721 | azabala | public static int pixelTolerance = 3; |
101 | 9686 | azabala | private MapControl mapCtrl;
|
102 | private Cursor cur = java.awt.Cursor. |
||
103 | getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
|
||
104 | 10628 | caballero | |
105 | 9686 | azabala | public DwgEntityListener(MapControl mc) {
|
106 | this.mapCtrl = mc;
|
||
107 | } |
||
108 | |||
109 | public void point(PointEvent event) throws BehaviorException { |
||
110 | 10628 | caballero | |
111 | 9686 | azabala | Point2D pReal = mapCtrl.
|
112 | getMapContext(). |
||
113 | getViewPort(). |
||
114 | toMapPoint(event.getPoint()); |
||
115 | 10628 | caballero | |
116 | 9686 | azabala | 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 | 10628 | caballero | |
125 | 9686 | azabala | FLyrVect vectLyr = (FLyrVect) aux; |
126 | VectorialDriver driver = vectLyr.getSource().getDriver(); |
||
127 | 10628 | caballero | |
128 | 9721 | azabala | // 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 | 10628 | caballero | |
143 | 9721 | azabala | if(!(driver instanceof com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)) |
144 | return;
|
||
145 | 10353 | fdiaz | /*
|
146 | * Comentarizar el if completo para que funcione en el libFMap del HEAD.
|
||
147 | */
|
||
148 | if(!(driver instanceof DwgMemoryDriver)){ |
||
149 | JOptionPane.showConfirmDialog(null, |
||
150 | 10628 | caballero | "Esta herramienta s?lo funciona con libFMap del HEAD.\nVer comentarios en el codigo de esta clase."
|
151 | 10353 | fdiaz | ); |
152 | return;
|
||
153 | } |
||
154 | |||
155 | 9721 | azabala | final com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver dwgDriver = (com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)driver;
|
156 | 9686 | azabala | double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance);
|
157 | 10628 | caballero | |
158 | 9686 | azabala | Rectangle2D recPoint = new Rectangle2D.Double(pReal.getX() - (realTol / 2), |
159 | pReal.getY() - (realTol / 2), realTol, realTol);
|
||
160 | 10628 | caballero | |
161 | 9686 | azabala | try {
|
162 | vectLyr.process(new FeatureVisitor(){
|
||
163 | 10628 | caballero | public void visit(IGeometry g, int index) throws VisitorException { |
164 | /*
|
||
165 | 10353 | fdiaz | * 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 | 10628 | caballero | |
176 | 10054 | azabala | DwgHandleReference handle = dwgObj.getLayerHandle(); |
177 | int lyrHdlCode = handle.getCode();
|
||
178 | int lyrHdl = handle.getOffset();
|
||
179 | 9686 | azabala | JOptionPane.showConfirmDialog(null, |
180 | 9895 | azabala | "hdlCode="+lyrHdlCode+",hdl="+lyrHdl+"entity="+dwgObj.getClass().getName()); |
181 | 9686 | azabala | } |
182 | |||
183 | public String getProcessDescription() { |
||
184 | return ""; |
||
185 | } |
||
186 | |||
187 | 10628 | caballero | public void stop(FLayer layer) throws VisitorException { |
188 | 9686 | azabala | } |
189 | |||
190 | 10628 | caballero | public boolean start(FLayer layer) throws StartVisitorException { |
191 | 9686 | azabala | return true; |
192 | }}, recPoint); |
||
193 | 10628 | caballero | } catch (VisitorException e) {
|
194 | 9686 | azabala | // TODO Auto-generated catch block
|
195 | e.printStackTrace(); |
||
196 | 10628 | caballero | } catch (ReadDriverException e) {
|
197 | 9686 | azabala | // TODO Auto-generated catch block
|
198 | e.printStackTrace(); |
||
199 | 10628 | caballero | } catch (ExpansionFileReadException e) {
|
200 | // TODO Auto-generated catch block
|
||
201 | e.printStackTrace(); |
||
202 | } |
||
203 | }//while
|
||
204 | 9686 | azabala | } |
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 |