svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / DefaultCADTool.java @ 23535
History | View | Annotate | Download (17.4 KB)
1 | 3831 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.gui.cad; |
||
42 | |||
43 | 3997 | fjp | import java.awt.Color; |
44 | 3883 | caballero | import java.awt.Graphics; |
45 | import java.awt.Graphics2D; |
||
46 | 17984 | vcaballero | import java.awt.event.MouseEvent; |
47 | 3883 | caballero | import java.awt.geom.AffineTransform; |
48 | import java.awt.geom.Point2D; |
||
49 | 13561 | caballero | import java.awt.geom.Rectangle2D; |
50 | 3883 | caballero | import java.awt.image.BufferedImage; |
51 | 4144 | fjp | import java.util.ArrayList; |
52 | 21668 | vcaballero | import java.util.Iterator; |
53 | 3883 | caballero | |
54 | 5893 | fjp | import org.apache.log4j.Logger; |
55 | 21911 | jmvivo | import org.gvsig.fmap.data.DataException; |
56 | import org.gvsig.fmap.data.ReadException; |
||
57 | import org.gvsig.fmap.data.commands.CommandsRecord; |
||
58 | 23424 | vcaballero | import org.gvsig.fmap.data.feature.AbstractFeature; |
59 | 22360 | jmvivo | import org.gvsig.fmap.data.feature.Feature; |
60 | import org.gvsig.fmap.data.feature.FeatureCollection; |
||
61 | import org.gvsig.fmap.data.feature.FeatureStore; |
||
62 | 21668 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
63 | import org.gvsig.fmap.geom.GeometryFactory; |
||
64 | import org.gvsig.fmap.geom.GeometryManager; |
||
65 | import org.gvsig.fmap.geom.handler.Handler; |
||
66 | 22025 | jmvivo | import org.gvsig.fmap.geom.operation.Draw; |
67 | import org.gvsig.fmap.geom.operation.DrawOperationContext; |
||
68 | 21668 | vcaballero | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
69 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
70 | 22986 | vcaballero | import org.gvsig.fmap.geom.primitive.DefaultEnvelope; |
71 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
72 | 21668 | vcaballero | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
73 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
74 | import org.gvsig.fmap.mapcontext.layers.SpatialCache; |
||
75 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
76 | import org.gvsig.fmap.mapcontext.rendering.symbols.FGraphicUtilities; |
||
77 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
78 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
||
79 | 5893 | fjp | |
80 | 3883 | caballero | import com.iver.andami.PluginServices; |
81 | 12148 | caballero | import com.iver.andami.messages.NotificationManager; |
82 | 3883 | caballero | import com.iver.cit.gvsig.CADExtension; |
83 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
84 | 4465 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
85 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
86 | 4892 | caballero | import com.iver.utiles.console.JConsole; |
87 | 3831 | caballero | |
88 | /**
|
||
89 | * DOCUMENT ME!
|
||
90 | 5985 | caballero | *
|
91 | 3831 | caballero | * @author Vicente Caballero Navarro
|
92 | */
|
||
93 | public abstract class DefaultCADTool implements CADTool { |
||
94 | 11437 | caballero | public static ISymbol selectionSymbol = SymbologyFactory. |
95 | 22036 | vcaballero | createDefaultSymbolByShapeType(Geometry.TYPES.GEOMETRY, new Color(255, 0,0, 100)); // Le ponemos una transparencia |
96 | 11437 | caballero | public static ISymbol axisReferencesSymbol = SymbologyFactory. |
97 | 22036 | vcaballero | createDefaultSymbolByShapeType(Geometry.TYPES.GEOMETRY, new Color(100, 100, 100, 100)); |
98 | 11437 | caballero | public static ISymbol geometrySelectSymbol = SymbologyFactory. |
99 | 22036 | vcaballero | createDefaultSymbolByShapeType(Geometry.TYPES.GEOMETRY, Color.RED);
|
100 | 11437 | caballero | public static ISymbol handlerSymbol = SymbologyFactory. |
101 | 22036 | vcaballero | createDefaultSymbolByShapeType(Geometry.TYPES.GEOMETRY, Color.ORANGE);
|
102 | 5923 | fjp | private static Logger logger = Logger.getLogger(DefaultCADTool.class |
103 | .getName()); |
||
104 | 4445 | fjp | private CADToolAdapter cadToolAdapter;
|
105 | 3831 | caballero | |
106 | 4445 | fjp | private String question; |
107 | 3831 | caballero | |
108 | 4445 | fjp | private String[] currentdescriptions; |
109 | 3831 | caballero | |
110 | 4708 | caballero | private String tool = "selection"; |
111 | |||
112 | 9052 | caballero | private DefaultCADTool previousTool;
|
113 | |||
114 | 13561 | caballero | private ArrayList temporalCache = new ArrayList(); |
115 | 22986 | vcaballero | protected GeometryFactory geomFactory=GeometryManager.getInstance().getGeometryFactory();
|
116 | 21668 | vcaballero | public void addTemporalCache(Geometry geom) { |
117 | 13561 | caballero | temporalCache.add(geom); |
118 | insertSpatialCache(geom); |
||
119 | } |
||
120 | public void clearTemporalCache() { |
||
121 | 21668 | vcaballero | Geometry[] geoms=(Geometry[])temporalCache.toArray(new Geometry[0]); |
122 | 13561 | caballero | for (int i=0;i<geoms.length;i++) { |
123 | removeSpatialCache(geoms[i]); |
||
124 | } |
||
125 | temporalCache.clear(); |
||
126 | } |
||
127 | 21668 | vcaballero | private void insertSpatialCache(Geometry geom) { |
128 | 13561 | caballero | VectorialLayerEdited vle = getVLE(); |
129 | SpatialCache spatialCache=((FLyrVect)vle.getLayer()).getSpatialCache(); |
||
130 | 22986 | vcaballero | Envelope r=geom.getEnvelope(); |
131 | 21668 | vcaballero | if (geom.getType()==Geometry.TYPES.POINT) {
|
132 | 22986 | vcaballero | r = new DefaultEnvelope(r.getMinimum(0),r.getMinimum(1),r.getMinimum(0)+1,r.getMinimum(1)+1);//Rectangle2D.Double(r.getX(),r.getY(),1,1); |
133 | 13561 | caballero | } |
134 | spatialCache.insert(r,geom); |
||
135 | |||
136 | } |
||
137 | 21668 | vcaballero | private void removeSpatialCache(Geometry geom) { |
138 | 13561 | caballero | VectorialLayerEdited vle = getVLE(); |
139 | SpatialCache spatialCache=((FLyrVect)vle.getLayer()).getSpatialCache(); |
||
140 | 22986 | vcaballero | Envelope r=geom.getEnvelope(); |
141 | 21668 | vcaballero | if (geom.getType()==Geometry.TYPES.POINT) {
|
142 | 22986 | vcaballero | r = new DefaultEnvelope(r.getMinimum(0),r.getMinimum(1),r.getMinimum(0)+1,r.getMinimum(1)+1);//Rectangle2D.Double(r.getX(),r.getY(),1,1); |
143 | 13561 | caballero | } |
144 | spatialCache.remove(r,geom); |
||
145 | |||
146 | } |
||
147 | 4445 | fjp | /**
|
148 | * DOCUMENT ME!
|
||
149 | */
|
||
150 | 21668 | vcaballero | public void draw(Geometry geometry) { |
151 | 4445 | fjp | if (geometry != null) { |
152 | BufferedImage img = getCadToolAdapter().getMapControl().getImage();
|
||
153 | Graphics2D gImag = (Graphics2D) img.getGraphics(); |
||
154 | ViewPort vp = getCadToolAdapter().getMapControl().getViewPort(); |
||
155 | 21668 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
156 | doc.setGraphics((Graphics2D)gImag);
|
||
157 | doc.setViewPort(vp); |
||
158 | doc.setSymbol(DefaultCADTool.geometrySelectSymbol); |
||
159 | try {
|
||
160 | geometry.cloneGeometry().invokeOperation(Draw.CODE,doc); |
||
161 | } catch (GeometryOperationNotSupportedException e) {
|
||
162 | e.printStackTrace(); |
||
163 | } catch (GeometryOperationException e) {
|
||
164 | e.printStackTrace(); |
||
165 | } |
||
166 | // geometry.draw(gImag, vp, DefaultCADTool.selectionSymbol);
|
||
167 | 4445 | fjp | } |
168 | } |
||
169 | 3831 | caballero | |
170 | 4445 | fjp | /**
|
171 | * DOCUMENT ME!
|
||
172 | 5985 | caballero | *
|
173 | 4445 | fjp | * @param cta
|
174 | * DOCUMENT ME!
|
||
175 | */
|
||
176 | public void setCadToolAdapter(CADToolAdapter cta) { |
||
177 | cadToolAdapter = cta; |
||
178 | } |
||
179 | 3831 | caballero | |
180 | 4445 | fjp | /**
|
181 | * DOCUMENT ME!
|
||
182 | 5985 | caballero | *
|
183 | 4445 | fjp | * @return DOCUMENT ME!
|
184 | */
|
||
185 | public CADToolAdapter getCadToolAdapter() {
|
||
186 | return cadToolAdapter;
|
||
187 | } |
||
188 | 5923 | fjp | |
189 | public VectorialLayerEdited getVLE() {
|
||
190 | return (VectorialLayerEdited) CADExtension.getEditionManager()
|
||
191 | .getActiveLayerEdited(); |
||
192 | 4637 | caballero | } |
193 | 3831 | caballero | |
194 | 4445 | fjp | /**
|
195 | * DOCUMENT ME!
|
||
196 | 5985 | caballero | *
|
197 | 4445 | fjp | * @param g
|
198 | * DOCUMENT ME!
|
||
199 | * @param firstPoint
|
||
200 | * DOCUMENT ME!
|
||
201 | * @param endPoint
|
||
202 | * DOCUMENT ME!
|
||
203 | */
|
||
204 | 11437 | caballero | public void drawLine(Graphics2D g, Point2D firstPoint, Point2D endPoint, ISymbol symbol) { |
205 | 4445 | fjp | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
206 | elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
||
207 | elShape.lineTo(endPoint.getX(), endPoint.getY()); |
||
208 | 21668 | vcaballero | GeometryFactory geomFactory=GeometryManager.getInstance().getGeometryFactory(); |
209 | DrawOperationContext doc=new DrawOperationContext();
|
||
210 | doc.setGraphics(g); |
||
211 | doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
||
212 | doc.setSymbol(symbol); |
||
213 | try {
|
||
214 | geomFactory.createPolyline2D(elShape).invokeOperation(Draw.CODE,doc); |
||
215 | } catch (GeometryOperationNotSupportedException e) {
|
||
216 | e.printStackTrace(); |
||
217 | } catch (GeometryOperationException e) {
|
||
218 | e.printStackTrace(); |
||
219 | } |
||
220 | // draw(g,
|
||
221 | // getCadToolAdapter().getMapControl().getViewPort(),
|
||
222 | // symbol);
|
||
223 | 4445 | fjp | } |
224 | |||
225 | /**
|
||
226 | * DOCUMENT ME!
|
||
227 | 5985 | caballero | *
|
228 | 4445 | fjp | * @param geometry
|
229 | * DOCUMENT ME!
|
||
230 | */
|
||
231 | 21668 | vcaballero | public void addGeometry(Geometry geometry) { |
232 | VectorialLayerEdited vle=getVLE(); |
||
233 | |||
234 | 4445 | fjp | try {
|
235 | 21668 | vcaballero | FeatureStore featureStore = ((FLyrVect)vle.getLayer()).getFeatureStore(); |
236 | 5893 | fjp | // Deber?amos comprobar que lo que escribimos es correcto:
|
237 | // Lo hacemos en el VectorialAdapter, justo antes de
|
||
238 | // a?adir, borrar o modificar una feature
|
||
239 | 21668 | vcaballero | Feature feature=featureStore.createDefaultFeature(true);
|
240 | // int numAttr = vea.getRecordset().getFieldCount();
|
||
241 | // Value[] values = new Value[numAttr];
|
||
242 | // for (int i = 0; i < numAttr; i++) {
|
||
243 | // values[i] = ValueFactory.createNullValue();
|
||
244 | // }
|
||
245 | // String newFID = vea.getNewFID();
|
||
246 | // DefaultFeature df = new DefaultFeature(geometry, values, newFID);
|
||
247 | feature.editing(); |
||
248 | feature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometry(),geometry); |
||
249 | featureStore.insert(feature); |
||
250 | 23535 | vcaballero | // feature = featureStore.getFeatureByID(feature.getID());
|
251 | 21668 | vcaballero | // int index = vea.addRow(df, getName(), EditionEvent.GRAPHIC);
|
252 | // VectorialLayerEdited vle = getVLE();
|
||
253 | 5985 | caballero | clearSelection(); |
254 | 8933 | caballero | //ArrayList selectedRow = vle.getSelectedRow();
|
255 | 4637 | caballero | |
256 | 5985 | caballero | |
257 | 6881 | cesar | ViewPort vp = vle.getLayer().getMapContext().getViewPort(); |
258 | 5923 | fjp | BufferedImage selectionImage = new BufferedImage(vp |
259 | .getImageWidth(), vp.getImageHeight(), |
||
260 | BufferedImage.TYPE_INT_ARGB);
|
||
261 | Graphics2D gs = selectionImage.createGraphics();
|
||
262 | 21668 | vcaballero | // int inversedIndex=vea.getInversedIndex(index);
|
263 | FeatureCollection selection=(FeatureCollection)featureStore.getSelection(); |
||
264 | 23424 | vcaballero | // selection.add(feature);
|
265 | 21668 | vcaballero | // vle.addSelectionCache(new DefaultRowEdited(df,
|
266 | // IRowEdited.STATUS_ADDED, inversedIndex ));
|
||
267 | // vea.getSelection().set(inversedIndex);
|
||
268 | 23424 | vcaballero | // Geometry geom = (Geometry)feature.getDefaultGeometry();
|
269 | 21668 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
270 | doc.setGraphics(gs); |
||
271 | doc.setViewPort(vp); |
||
272 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
273 | 23424 | vcaballero | geometry.cloneGeometry().invokeOperation(Draw.CODE,doc); |
274 | 21668 | vcaballero | // draw(gs, vp, DefaultCADTool.selectionSymbol);
|
275 | 23424 | vcaballero | vle.drawHandlers(geometry.cloneGeometry(), gs, vp); |
276 | 21668 | vcaballero | vle.setSelectionImage(selectionImage); |
277 | 23424 | vcaballero | insertSpatialCache(geometry); |
278 | 21668 | vcaballero | } catch (ReadException e) {
|
279 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
280 | 10626 | caballero | return;
|
281 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
282 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
283 | 10626 | caballero | return;
|
284 | 21668 | vcaballero | } catch (GeometryOperationException e) {
|
285 | NotificationManager.addError(e.getMessage(),e); |
||
286 | return;
|
||
287 | } catch (DataException e) {
|
||
288 | NotificationManager.addError(e.getMessage(),e); |
||
289 | return;
|
||
290 | 15637 | jmvivo | } |
291 | 4445 | fjp | draw(geometry.cloneGeometry()); |
292 | } |
||
293 | |||
294 | 13561 | caballero | |
295 | |||
296 | 4445 | fjp | /**
|
297 | * DOCUMENT ME!
|
||
298 | 5985 | caballero | *
|
299 | 4445 | fjp | * @param geometry
|
300 | * DOCUMENT ME!
|
||
301 | */
|
||
302 | 21668 | vcaballero | public void modifyFeature(Feature feature, Feature oldFeature) { |
303 | 4445 | fjp | try {
|
304 | 21668 | vcaballero | CommandsRecord cr=((FLyrVect)getVLE().getLayer()).getFeatureStore().getCommandsRecord(); |
305 | cr.update(feature, oldFeature); |
||
306 | } catch (ReadException e) {
|
||
307 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
308 | 15637 | jmvivo | } |
309 | 21668 | vcaballero | draw(((Geometry)feature.getDefaultGeometry()).cloneGeometry()); |
310 | 4445 | fjp | } |
311 | 3831 | caballero | |
312 | 4445 | fjp | /**
|
313 | * DOCUMENT ME!
|
||
314 | 5985 | caballero | *
|
315 | 4445 | fjp | * @param geometry
|
316 | * DOCUMENT ME!
|
||
317 | * @param values
|
||
318 | * DOCUMENT ME!
|
||
319 | */
|
||
320 | 23424 | vcaballero | public Feature addGeometry(Geometry geometry, Object[] values) { |
321 | 21668 | vcaballero | // int index = 0;
|
322 | 5884 | caballero | try {
|
323 | 21668 | vcaballero | FeatureStore featureStore = ((FLyrVect)getVLE().getLayer()).getFeatureStore(); |
324 | Feature feature=featureStore.createDefaultFeature(true);
|
||
325 | feature.editing(); |
||
326 | feature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometry(),geometry); |
||
327 | for (int i = 0; i < values.length; i++) { |
||
328 | feature.set(i,values[i]); |
||
329 | 15637 | jmvivo | } |
330 | 21668 | vcaballero | featureStore.insert(feature); |
331 | 23424 | vcaballero | return feature;
|
332 | 21668 | vcaballero | } catch (DataException e) {
|
333 | // TODO Auto-generated catch block
|
||
334 | e.printStackTrace(); |
||
335 | } |
||
336 | // try {
|
||
337 | // String newFID = vea.getNewFID();
|
||
338 | // DefaultFeature df = new DefaultFeature(geometry, values, newFID);
|
||
339 | // index = vea.addRow(df, getName(), EditionEvent.GRAPHIC);
|
||
340 | // insertSpatialCache(geometry);
|
||
341 | // } catch (ValidateRowException e) {
|
||
342 | // NotificationManager.addError(e);
|
||
343 | // } catch (ReadException e) {
|
||
344 | // NotificationManager.addError(e);
|
||
345 | // }
|
||
346 | // return vea.getInversedIndex(index);
|
||
347 | 23424 | vcaballero | return null; |
348 | 4445 | fjp | } |
349 | 3831 | caballero | |
350 | 4445 | fjp | /**
|
351 | * Devuelve la cadena que corresponde al estado en el que nos encontramos.
|
||
352 | 5985 | caballero | *
|
353 | 4445 | fjp | * @return Cadena para mostrar por consola.
|
354 | */
|
||
355 | public String getQuestion() { |
||
356 | return question;
|
||
357 | } |
||
358 | 3831 | caballero | |
359 | 4445 | fjp | /**
|
360 | * Actualiza la cadena que corresponde al estado actual.
|
||
361 | 5985 | caballero | *
|
362 | 4445 | fjp | * @param s
|
363 | * Cadena que aparecer? en consola.
|
||
364 | */
|
||
365 | public void setQuestion(String s) { |
||
366 | question = s; |
||
367 | 5923 | fjp | // ConsoleToken.addQuestion(s);
|
368 | 4445 | fjp | } |
369 | 3831 | caballero | |
370 | 4445 | fjp | /**
|
371 | 5923 | fjp | * Provoca un repintado "soft" de la capa activa en edici?n. Las capas por
|
372 | * debajo de ella no se dibujan de verdad, solo se dibuja la que est? en
|
||
373 | * edici?n y las que est?n por encima de ella en el TOC.
|
||
374 | 4445 | fjp | */
|
375 | public void refresh() { |
||
376 | 5923 | fjp | // getCadToolAdapter().getMapControl().drawMap(false);
|
377 | getVLE().getLayer().setDirty(true);
|
||
378 | |||
379 | getCadToolAdapter().getMapControl().rePaintDirtyLayers(); |
||
380 | 4445 | fjp | } |
381 | |||
382 | 5923 | fjp | /*
|
383 | * public void drawHandlers(Graphics g, FBitSet sel, AffineTransform at)
|
||
384 | * throws DriverIOException { for (int i = sel.nextSetBit(0); i >= 0; i =
|
||
385 | * sel.nextSetBit(i + 1)) { IGeometry ig =
|
||
386 | * getCadToolAdapter().getVectorialAdapter() .getShape(i).cloneGeometry();
|
||
387 | * if (ig == null) continue; Handler[] handlers =
|
||
388 | * ig.getHandlers(IGeometry.SELECTHANDLER);
|
||
389 | * FGraphicUtilities.DrawHandlers((Graphics2D) g, at, handlers); } }
|
||
390 | */
|
||
391 | 4445 | fjp | public void drawHandlers(Graphics g, ArrayList selectedRows, |
392 | AffineTransform at) {
|
||
393 | 21668 | vcaballero | FeatureCollection selection=null;
|
394 | try {
|
||
395 | selection = (FeatureCollection)((FLyrVect)getVLE().getLayer()).getFeatureStore().getSelection(); |
||
396 | } catch (ReadException e) {
|
||
397 | // TODO Auto-generated catch block
|
||
398 | e.printStackTrace(); |
||
399 | } |
||
400 | Iterator iterator=selection.iterator();
|
||
401 | while (iterator.hasNext()) {
|
||
402 | Feature feature = (Feature) iterator.next(); |
||
403 | |||
404 | // }
|
||
405 | // for (int i = 0; i < selectedRows.size(); i++) {
|
||
406 | // IRowEdited edRow = (IRowEdited) selectedRows.get(i);
|
||
407 | // IFeature feat = (IFeature) edRow.getLinkedRow();
|
||
408 | 4445 | fjp | // IFeature feat = (IFeature) selectedRows.get(i);
|
409 | 21668 | vcaballero | Geometry ig = ((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
410 | 4445 | fjp | if (ig == null) |
411 | continue;
|
||
412 | 21668 | vcaballero | Handler[] handlers = ig.getHandlers(Geometry.SELECTHANDLER); |
413 | 11437 | caballero | FGraphicUtilities.DrawHandlers((Graphics2D) g, at, handlers,DefaultCADTool.handlerSymbol);
|
414 | 4445 | fjp | } |
415 | } |
||
416 | 3883 | caballero | |
417 | public void setDescription(String[] currentdescriptions) { |
||
418 | this.currentdescriptions = currentdescriptions;
|
||
419 | } |
||
420 | 4445 | fjp | |
421 | public String[] getDescriptions() { |
||
422 | 3883 | caballero | return currentdescriptions;
|
423 | } |
||
424 | |||
425 | 4445 | fjp | /*
|
426 | * (non-Javadoc)
|
||
427 | 5985 | caballero | *
|
428 | 4445 | fjp | * @see com.iver.cit.gvsig.gui.cad.CADTool#end()
|
429 | */
|
||
430 | public void end() { |
||
431 | 5923 | fjp | CADExtension.setCADTool("_selection", true); |
432 | 5016 | caballero | PluginServices.getMainFrame().setSelectedTool("_selection");
|
433 | 9052 | caballero | CADTool cadtool=CADExtension.getCADTool(); |
434 | cadtool.setPreviosTool(this);
|
||
435 | 4445 | fjp | } |
436 | |||
437 | 3997 | fjp | public void init() { |
438 | 10828 | jaume | // jaume, should not be necessary
|
439 | // CADTool.drawingSymbol.setOutlined(true);
|
||
440 | // CADTool.drawingSymbol.setOutlineColor(Color.GREEN);
|
||
441 | 4024 | caballero | |
442 | 3997 | fjp | } |
443 | 5923 | fjp | |
444 | 21668 | vcaballero | // protected ArrayList getSelectedRows() {
|
445 | // VectorialLayerEdited vle = getVLE();
|
||
446 | // ArrayList selectedRow = vle.getSelectedRow();
|
||
447 | // return selectedRow;
|
||
448 | // }
|
||
449 | 5923 | fjp | |
450 | protected ArrayList getSelectedHandlers() { |
||
451 | 4637 | caballero | VectorialLayerEdited vle = getVLE(); |
452 | 5923 | fjp | ArrayList selectedHandlers = vle.getSelectedHandler();
|
453 | return selectedHandlers;
|
||
454 | 4584 | caballero | } |
455 | 5923 | fjp | |
456 | 21668 | vcaballero | public void clearSelection() throws ReadException { |
457 | 4637 | caballero | VectorialLayerEdited vle = getVLE(); |
458 | 21668 | vcaballero | FeatureCollection selection=(FeatureCollection)((FLyrVect)vle.getLayer()).getFeatureStore().getSelection(); |
459 | // ArrayList selectedRow = vle.getSelectedRow();
|
||
460 | 5923 | fjp | ArrayList selectedHandlers = vle.getSelectedHandler();
|
461 | 21668 | vcaballero | selection.clear(); |
462 | 5923 | fjp | selectedHandlers.clear(); |
463 | 21668 | vcaballero | // VectorialEditableAdapter vea = vle.getVEA();
|
464 | // FBitSet selection = vea.getSelection();
|
||
465 | // selection.clear();
|
||
466 | vle.setSelectionImage(null);
|
||
467 | vle.setHandlersImage(null);
|
||
468 | 4637 | caballero | |
469 | 4584 | caballero | } |
470 | 5923 | fjp | |
471 | 4708 | caballero | public String getNextTool() { |
472 | return tool;
|
||
473 | } |
||
474 | |||
475 | public void setNextTool(String tool) { |
||
476 | this.tool = tool;
|
||
477 | } |
||
478 | 5923 | fjp | |
479 | public boolean changeCommand(String name) throws CommandException { |
||
480 | CADTool[] cadtools = CADExtension.getCADTools();
|
||
481 | for (int i = 0; i < cadtools.length; i++) { |
||
482 | CADTool ct = cadtools[i]; |
||
483 | if (name.equalsIgnoreCase(ct.getName())
|
||
484 | || name.equalsIgnoreCase(ct.toString())) { |
||
485 | 21668 | vcaballero | int type = Geometry.TYPES.POINT;
|
486 | 5170 | caballero | try {
|
487 | 5923 | fjp | type = ((FLyrVect) getVLE().getLayer()).getShapeType(); |
488 | 21668 | vcaballero | } catch (ReadException e) {
|
489 | 12739 | caballero | throw new CommandException(e); |
490 | 5170 | caballero | } |
491 | if (ct.isApplicable(type)) {
|
||
492 | getCadToolAdapter().setCadTool(ct); |
||
493 | ct.init(); |
||
494 | View vista = (View) PluginServices.getMDIManager() |
||
495 | 6880 | cesar | .getActiveWindow(); |
496 | 5170 | caballero | vista.getConsolePanel().addText("\n" + ct.getName(),
|
497 | JConsole.COMMAND); |
||
498 | 9121 | caballero | String question=ct.getQuestion();
|
499 | vista.getConsolePanel().addText( |
||
500 | "\n" + "#" + question + " > ", JConsole.MESSAGE); |
||
501 | 5170 | caballero | return true; |
502 | } |
||
503 | 10626 | caballero | throw new CommandException(name); |
504 | 4892 | caballero | } |
505 | } |
||
506 | return false; |
||
507 | } |
||
508 | 5923 | fjp | |
509 | 5170 | caballero | public boolean isApplicable(int shapeType) { |
510 | return true; |
||
511 | } |
||
512 | 5923 | fjp | |
513 | 4892 | caballero | public abstract String toString(); |
514 | 5735 | caballero | |
515 | 5923 | fjp | public void throwValueException(String s, double d) { |
516 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
517 | 5923 | fjp | vista.getConsolePanel().addText(s + " : " + d, JConsole.ERROR);
|
518 | 5735 | caballero | } |
519 | 5923 | fjp | |
520 | public void throwOptionException(String s, String o) { |
||
521 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
522 | 5923 | fjp | vista.getConsolePanel().addText(s + " : " + o, JConsole.ERROR);
|
523 | 5735 | caballero | } |
524 | 5923 | fjp | |
525 | public void throwPointException(String s, double x, double y) { |
||
526 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
527 | 5923 | fjp | vista.getConsolePanel().addText(s + " : " + " X = " + x + ", Y = " + y, |
528 | JConsole.ERROR); |
||
529 | 5735 | caballero | } |
530 | |||
531 | 9052 | caballero | public void setPreviosTool(DefaultCADTool tool) { |
532 | previousTool=tool; |
||
533 | } |
||
534 | public void restorePreviousTool() { |
||
535 | CADExtension.setCADTool(previousTool.toString(), true);
|
||
536 | PluginServices.getMainFrame().setSelectedTool(previousTool.toString()); |
||
537 | } |
||
538 | 17984 | vcaballero | public void endTransition(double x, double y, MouseEvent e) { |
539 | // TODO Auto-generated method stub
|
||
540 | 9052 | caballero | |
541 | 17984 | vcaballero | } |
542 | |||
543 | 3831 | caballero | } |