svn-gvsig-desktop / branches / v10 / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / debug / DwgEntityListener.java @ 10539
History | View | Annotate | Download (6.37 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 | 10539 | jmvivo | * Revision 1.5.2.1 2007-02-28 07:35:06 jmvivo
|
49 | * Actualizado desde el HEAD.
|
||
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 | 10353 | fdiaz | import com.iver.cit.gvsig.drivers.dwg.DwgMemoryDriver; |
77 | 9686 | azabala | import com.iver.cit.gvsig.fmap.DriverException; |
78 | import com.iver.cit.gvsig.fmap.MapControl; |
||
79 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
80 | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
||
81 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
82 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
83 | import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
||
84 | import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
||
85 | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
||
86 | import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
||
87 | import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
||
88 | import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
||
89 | 10054 | azabala | import com.iver.cit.jdwglib.dwg.DwgHandleReference; |
90 | 9686 | azabala | import com.iver.cit.jdwglib.dwg.DwgObject; |
91 | |||
92 | public class DwgEntityListener implements PointListener{ |
||
93 | |||
94 | |||
95 | |||
96 | |||
97 | 9721 | azabala | public static int pixelTolerance = 3; |
98 | 9686 | azabala | private MapControl mapCtrl;
|
99 | private Cursor cur = java.awt.Cursor. |
||
100 | getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
|
||
101 | 9721 | azabala | |
102 | 9686 | azabala | public DwgEntityListener(MapControl mc) {
|
103 | this.mapCtrl = mc;
|
||
104 | } |
||
105 | |||
106 | public void point(PointEvent event) throws BehaviorException { |
||
107 | |||
108 | Point2D pReal = mapCtrl.
|
||
109 | getMapContext(). |
||
110 | getViewPort(). |
||
111 | toMapPoint(event.getPoint()); |
||
112 | |||
113 | SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
|
||
114 | while (it.hasNext())
|
||
115 | { |
||
116 | FLayer aux = it.next(); |
||
117 | if (!aux.isActive())
|
||
118 | continue;
|
||
119 | if(! (aux instanceof FLyrVect)) |
||
120 | return;
|
||
121 | |||
122 | FLyrVect vectLyr = (FLyrVect) aux; |
||
123 | VectorialDriver driver = vectLyr.getSource().getDriver(); |
||
124 | 9721 | azabala | |
125 | // Class dwgMemoryDriverClass = LayerFactory.getDM().getDriverClassByName("gvSIG DWG Memory Driver");
|
||
126 | // if(dwgMemoryDriverClass == null){
|
||
127 | // System.out.println("Driver dwg no disponible???");
|
||
128 | // return;
|
||
129 | // }
|
||
130 | // if(!dwgMemoryDriverClass.isInstance(driver))
|
||
131 | // return;
|
||
132 | // PluginClassLoader loader = PluginServices.
|
||
133 | // getPluginServices(this).getClassLoader();
|
||
134 | // try {
|
||
135 | // loader.loadClass(dwgMemoryDriverClass.toString());
|
||
136 | // } catch (ClassNotFoundException e1) {
|
||
137 | // return;
|
||
138 | // }
|
||
139 | |||
140 | if(!(driver instanceof com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)) |
||
141 | return;
|
||
142 | 10353 | fdiaz | /*
|
143 | * Comentarizar el if completo para que funcione en el libFMap del HEAD.
|
||
144 | */
|
||
145 | if(!(driver instanceof DwgMemoryDriver)){ |
||
146 | JOptionPane.showConfirmDialog(null, |
||
147 | "Esta herramienta s?lo funciona con libFMap del HEAD.\nVer comentarios en el codigo de esta clase."
|
||
148 | ); |
||
149 | return;
|
||
150 | } |
||
151 | |||
152 | 9721 | azabala | final com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver dwgDriver = (com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)driver;
|
153 | 9686 | azabala | double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance);
|
154 | |||
155 | Rectangle2D recPoint = new Rectangle2D.Double(pReal.getX() - (realTol / 2), |
||
156 | pReal.getY() - (realTol / 2), realTol, realTol);
|
||
157 | |||
158 | try {
|
||
159 | vectLyr.process(new FeatureVisitor(){
|
||
160 | public void visit(IGeometry g, int index) throws VisitException { |
||
161 | 10353 | fdiaz | /*
|
162 | * Cambiar la comentarizacion de las dos lineas de abajo
|
||
163 | * para funcione la herramienta en libFMap del HEAD.
|
||
164 | * No funciona en la v10 porque AbstractCadMemoryDriver
|
||
165 | * no declara el metodo getCadSource.
|
||
166 | * Quitar tambi?n el if que muestra el mensaje de arriba.
|
||
167 | */
|
||
168 | |||
169 | // DwgObject dwgObj = (DwgObject) dwgDriver.getCadSource(index);
|
||
170 | DwgObject dwgObj = (DwgObject) ((DwgMemoryDriver)dwgDriver).getCadSource(index); |
||
171 | |||
172 | 10054 | azabala | DwgHandleReference handle = dwgObj.getLayerHandle(); |
173 | int lyrHdlCode = handle.getCode();
|
||
174 | int lyrHdl = handle.getOffset();
|
||
175 | 9686 | azabala | JOptionPane.showConfirmDialog(null, |
176 | 9895 | azabala | "hdlCode="+lyrHdlCode+",hdl="+lyrHdl+"entity="+dwgObj.getClass().getName()); |
177 | 9686 | azabala | } |
178 | |||
179 | public String getProcessDescription() { |
||
180 | return ""; |
||
181 | } |
||
182 | |||
183 | public void stop(FLayer layer) { |
||
184 | } |
||
185 | |||
186 | public boolean start(FLayer layer) { |
||
187 | return true; |
||
188 | }}, recPoint); |
||
189 | } catch (VisitException e) {
|
||
190 | // TODO Auto-generated catch block
|
||
191 | e.printStackTrace(); |
||
192 | } catch (DriverException e) {
|
||
193 | // TODO Auto-generated catch block
|
||
194 | e.printStackTrace(); |
||
195 | }//try
|
||
196 | }//while
|
||
197 | } |
||
198 | |||
199 | public Cursor getCursor() { |
||
200 | return cur;
|
||
201 | } |
||
202 | |||
203 | public boolean cancelDrawing() { |
||
204 | return false; |
||
205 | } |
||
206 | |||
207 | |||
208 | public void pointDoubleClick(PointEvent event) throws BehaviorException { |
||
209 | point(event); |
||
210 | } |
||
211 | |||
212 | |||
213 | } |
||
214 | |||
215 | |||
216 | |||
217 |