root / trunk / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / debug / DwgEntityListener.java @ 9895
History | View | Annotate | Download (5.28 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 9895 2007-01-24 20:40:02Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.3 2007-01-24 20:40:02 azabala
|
49 |
* added debug of dwg class
|
50 |
*
|
51 |
* Revision 1.2 2007/01/12 19:57:44 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.1 2007/01/11 20:31:05 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
*
|
58 |
*/
|
59 |
package com.iver.cit.gvsig.drivers.dwg.debug; |
60 |
|
61 |
import java.awt.Cursor; |
62 |
import java.awt.geom.Point2D; |
63 |
import java.awt.geom.Rectangle2D; |
64 |
|
65 |
import javax.swing.JOptionPane; |
66 |
|
67 |
import com.iver.cit.gvsig.fmap.DriverException; |
68 |
import com.iver.cit.gvsig.fmap.MapControl; |
69 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
70 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
71 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
73 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
74 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
75 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
76 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
77 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
78 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
79 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
80 |
|
81 |
public class DwgEntityListener implements PointListener{ |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
public static int pixelTolerance = 3; |
87 |
private MapControl mapCtrl;
|
88 |
private Cursor cur = java.awt.Cursor. |
89 |
getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
|
90 |
|
91 |
public DwgEntityListener(MapControl mc) {
|
92 |
this.mapCtrl = mc;
|
93 |
} |
94 |
|
95 |
public void point(PointEvent event) throws BehaviorException { |
96 |
|
97 |
Point2D pReal = mapCtrl.
|
98 |
getMapContext(). |
99 |
getViewPort(). |
100 |
toMapPoint(event.getPoint()); |
101 |
|
102 |
SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
|
103 |
while (it.hasNext())
|
104 |
{ |
105 |
FLayer aux = it.next(); |
106 |
if (!aux.isActive())
|
107 |
continue;
|
108 |
if(! (aux instanceof FLyrVect)) |
109 |
return;
|
110 |
|
111 |
FLyrVect vectLyr = (FLyrVect) aux; |
112 |
VectorialDriver driver = vectLyr.getSource().getDriver(); |
113 |
|
114 |
// Class dwgMemoryDriverClass = LayerFactory.getDM().getDriverClassByName("gvSIG DWG Memory Driver");
|
115 |
// if(dwgMemoryDriverClass == null){
|
116 |
// System.out.println("Driver dwg no disponible???");
|
117 |
// return;
|
118 |
// }
|
119 |
// if(!dwgMemoryDriverClass.isInstance(driver))
|
120 |
// return;
|
121 |
// PluginClassLoader loader = PluginServices.
|
122 |
// getPluginServices(this).getClassLoader();
|
123 |
// try {
|
124 |
// loader.loadClass(dwgMemoryDriverClass.toString());
|
125 |
// } catch (ClassNotFoundException e1) {
|
126 |
// return;
|
127 |
// }
|
128 |
|
129 |
if(!(driver instanceof com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)) |
130 |
return;
|
131 |
final com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver dwgDriver = (com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)driver;
|
132 |
double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance);
|
133 |
|
134 |
Rectangle2D recPoint = new Rectangle2D.Double(pReal.getX() - (realTol / 2), |
135 |
pReal.getY() - (realTol / 2), realTol, realTol);
|
136 |
|
137 |
try {
|
138 |
vectLyr.process(new FeatureVisitor(){
|
139 |
public void visit(IGeometry g, int index) throws VisitException { |
140 |
DwgObject dwgObj = (DwgObject) dwgDriver.getCadSource(index); |
141 |
int lyrHdlCode = dwgObj.getLayerHandleCode();
|
142 |
int lyrHdl = dwgObj.getLayerHandle();
|
143 |
JOptionPane.showConfirmDialog(null, |
144 |
"hdlCode="+lyrHdlCode+",hdl="+lyrHdl+"entity="+dwgObj.getClass().getName()); |
145 |
} |
146 |
|
147 |
public String getProcessDescription() { |
148 |
return ""; |
149 |
} |
150 |
|
151 |
public void stop(FLayer layer) { |
152 |
} |
153 |
|
154 |
public boolean start(FLayer layer) { |
155 |
return true; |
156 |
}}, recPoint); |
157 |
} catch (VisitException e) {
|
158 |
// TODO Auto-generated catch block
|
159 |
e.printStackTrace(); |
160 |
} catch (DriverException e) {
|
161 |
// TODO Auto-generated catch block
|
162 |
e.printStackTrace(); |
163 |
}//try
|
164 |
}//while
|
165 |
} |
166 |
|
167 |
public Cursor getCursor() { |
168 |
return cur;
|
169 |
} |
170 |
|
171 |
public boolean cancelDrawing() { |
172 |
return false; |
173 |
} |
174 |
|
175 |
|
176 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
177 |
point(event); |
178 |
} |
179 |
|
180 |
|
181 |
} |
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|