root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / DefaultCADTool.java @ 30011
History | View | Annotate | Download (27.4 KB)
1 |
/* 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 org.gvsig.editing.gui.cad; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Graphics; |
45 |
import java.awt.Graphics2D; |
46 |
import java.awt.event.MouseEvent; |
47 |
import java.awt.geom.AffineTransform; |
48 |
import java.awt.geom.Point2D; |
49 |
import java.awt.image.BufferedImage; |
50 |
import java.util.ArrayList; |
51 |
|
52 |
import org.apache.log4j.Logger; |
53 |
import org.gvsig.andami.PluginServices; |
54 |
import org.gvsig.andami.messages.NotificationManager; |
55 |
import org.gvsig.app.project.documents.view.gui.View; |
56 |
import org.gvsig.editing.CADExtension; |
57 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
58 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
59 |
import org.gvsig.fmap.dal.exception.DataException; |
60 |
import org.gvsig.fmap.dal.exception.ReadException; |
61 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
62 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
63 |
import org.gvsig.fmap.dal.feature.Feature; |
64 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
65 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
66 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
67 |
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
68 |
import org.gvsig.fmap.geom.Geometry; |
69 |
import org.gvsig.fmap.geom.GeometryLocator; |
70 |
import org.gvsig.fmap.geom.GeometryManager; |
71 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
72 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
73 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
74 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
75 |
import org.gvsig.fmap.geom.handler.Handler; |
76 |
import org.gvsig.fmap.geom.operation.Draw; |
77 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
78 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
79 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
80 |
import org.gvsig.fmap.geom.primitive.Arc; |
81 |
import org.gvsig.fmap.geom.primitive.Circle; |
82 |
import org.gvsig.fmap.geom.primitive.Curve; |
83 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
84 |
import org.gvsig.fmap.geom.primitive.Envelope; |
85 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
86 |
import org.gvsig.fmap.geom.primitive.Point; |
87 |
import org.gvsig.fmap.geom.primitive.Primitive; |
88 |
import org.gvsig.fmap.geom.primitive.Spline; |
89 |
import org.gvsig.fmap.geom.primitive.Surface; |
90 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
91 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
92 |
import org.gvsig.fmap.mapcontext.ViewPort; |
93 |
import org.gvsig.fmap.mapcontext.layers.SpatialCache; |
94 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
95 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
96 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.FGraphicUtilities; |
97 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SymbologyFactory; |
98 |
import org.gvsig.utils.console.JConsole; |
99 |
|
100 |
|
101 |
|
102 |
/**
|
103 |
* DOCUMENT ME!
|
104 |
*
|
105 |
* @author Vicente Caballero Navarro
|
106 |
*/
|
107 |
public abstract class DefaultCADTool implements CADTool { |
108 |
|
109 |
/**
|
110 |
* Reference to the MapContext library manager, used to create symbols
|
111 |
* and legends.
|
112 |
*/
|
113 |
private static MapContextManager mapContextManager = MapContextLocator |
114 |
.getMapContextManager(); |
115 |
|
116 |
// Le ponemos una transparencia
|
117 |
public static ISymbol selectionSymbol = mapContextManager.createSymbol( |
118 |
Geometry.TYPES.GEOMETRY, new Color(255, 0, 0, 100)); |
119 |
public static ISymbol axisReferencesSymbol = mapContextManager |
120 |
.createSymbol(Geometry.TYPES.GEOMETRY, |
121 |
new Color(100, 100, 100, 100)); |
122 |
public static ISymbol geometrySelectSymbol = mapContextManager |
123 |
.createSymbol(Geometry.TYPES.GEOMETRY, Color.RED);
|
124 |
public static ISymbol handlerSymbol = mapContextManager.createSymbol( |
125 |
Geometry.TYPES.GEOMETRY, Color.ORANGE);
|
126 |
|
127 |
protected static Logger logger = Logger.getLogger(DefaultCADTool.class |
128 |
.getName()); |
129 |
private CADToolAdapter cadToolAdapter;
|
130 |
|
131 |
private String question; |
132 |
|
133 |
private String[] currentdescriptions; |
134 |
|
135 |
private String tool = "selection"; |
136 |
|
137 |
private DefaultCADTool previousTool;
|
138 |
|
139 |
private ArrayList temporalCache = new ArrayList(); |
140 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
141 |
|
142 |
public void addTemporalCache(Geometry geom) { |
143 |
temporalCache.add(geom); |
144 |
try {
|
145 |
insertSpatialCache(geom); |
146 |
} catch (CreateEnvelopeException e) {
|
147 |
logger.error("Error adding the spatial cache", e);
|
148 |
} |
149 |
} |
150 |
|
151 |
public void clearTemporalCache() { |
152 |
Geometry[] geoms = (Geometry[]) temporalCache.toArray(new Geometry[0]); |
153 |
for (int i = 0; i < geoms.length; i++) { |
154 |
try {
|
155 |
removeSpatialCache(geoms[i]); |
156 |
} catch (CreateEnvelopeException e) {
|
157 |
logger.error("Error removing the temporal cache", e);
|
158 |
} |
159 |
} |
160 |
temporalCache.clear(); |
161 |
} |
162 |
|
163 |
private void insertSpatialCache(Geometry geom) throws CreateEnvelopeException { |
164 |
VectorialLayerEdited vle = getVLE(); |
165 |
SpatialCache spatialCache = ((FLyrVect) vle.getLayer()) |
166 |
.getSpatialCache(); |
167 |
Envelope r = geom.getEnvelope(); |
168 |
if (geom.getType() == Geometry.TYPES.POINT) {
|
169 |
r = geomManager.createEnvelope(r.getMinimum(0), r.getMinimum(1), r |
170 |
.getMinimum(0) + 1, r.getMinimum(1) + 1, SUBTYPES.GEOM2D);// Rectangle2D.Double(r.getX(),r.getY(),1,1); |
171 |
} |
172 |
spatialCache.insert(r, geom); |
173 |
|
174 |
} |
175 |
|
176 |
private void removeSpatialCache(Geometry geom) throws CreateEnvelopeException { |
177 |
VectorialLayerEdited vle = getVLE(); |
178 |
SpatialCache spatialCache = ((FLyrVect) vle.getLayer()) |
179 |
.getSpatialCache(); |
180 |
Envelope r = geom.getEnvelope(); |
181 |
if (geom.getType() == Geometry.TYPES.POINT) {
|
182 |
r = geomManager.createEnvelope(r.getMinimum(0), r.getMinimum(1), r |
183 |
.getMinimum(0) + 1, r.getMinimum(1) + 1, SUBTYPES.GEOM2D);// Rectangle2D.Double(r.getX(),r.getY(),1,1); |
184 |
} |
185 |
spatialCache.remove(r, geom); |
186 |
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* DOCUMENT ME!
|
191 |
*/
|
192 |
public void draw(Geometry geometry) { |
193 |
if (geometry != null) { |
194 |
BufferedImage img = getCadToolAdapter().getMapControl().getImage();
|
195 |
Graphics2D gImag = (Graphics2D) img.getGraphics(); |
196 |
ViewPort vp = getCadToolAdapter().getMapControl().getViewPort(); |
197 |
DrawOperationContext doc = new DrawOperationContext();
|
198 |
doc.setGraphics(gImag); |
199 |
doc.setViewPort(vp); |
200 |
doc.setSymbol(DefaultCADTool.geometrySelectSymbol); |
201 |
try {
|
202 |
geometry.cloneGeometry().invokeOperation(Draw.CODE, doc); |
203 |
} catch (GeometryOperationNotSupportedException e) {
|
204 |
e.printStackTrace(); |
205 |
} catch (GeometryOperationException e) {
|
206 |
e.printStackTrace(); |
207 |
} |
208 |
// geometry.draw(gImag, vp, DefaultCADTool.selectionSymbol);
|
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* DOCUMENT ME!
|
214 |
*
|
215 |
* @param cta
|
216 |
* DOCUMENT ME!
|
217 |
*/
|
218 |
public void setCadToolAdapter(CADToolAdapter cta) { |
219 |
cadToolAdapter = cta; |
220 |
} |
221 |
|
222 |
/**
|
223 |
* DOCUMENT ME!
|
224 |
*
|
225 |
* @return DOCUMENT ME!
|
226 |
*/
|
227 |
public CADToolAdapter getCadToolAdapter() {
|
228 |
return cadToolAdapter;
|
229 |
} |
230 |
|
231 |
public VectorialLayerEdited getVLE() {
|
232 |
return (VectorialLayerEdited) CADExtension.getEditionManager()
|
233 |
.getActiveLayerEdited(); |
234 |
} |
235 |
|
236 |
/**
|
237 |
* DOCUMENT ME!
|
238 |
*
|
239 |
* @param g
|
240 |
* DOCUMENT ME!
|
241 |
* @param firstPoint
|
242 |
* DOCUMENT ME!
|
243 |
* @param endPoint
|
244 |
* DOCUMENT ME!
|
245 |
*/
|
246 |
public void drawLine(Graphics2D g, Point2D firstPoint, Point2D endPoint, |
247 |
ISymbol symbol) { |
248 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
249 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
250 |
elShape.lineTo(endPoint.getX(), endPoint.getY()); |
251 |
DrawOperationContext doc = new DrawOperationContext();
|
252 |
doc.setGraphics(g); |
253 |
doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
254 |
doc.setSymbol(symbol); |
255 |
try {
|
256 |
Curve curve = (Curve)geomManager.create(Geometry.TYPES.CURVE, Geometry.SUBTYPES.GEOM2D); |
257 |
curve.setGeneralPath(elShape); |
258 |
curve.invokeOperation(Draw.CODE, doc); |
259 |
} catch (GeometryOperationNotSupportedException e) {
|
260 |
e.printStackTrace(); |
261 |
} catch (GeometryOperationException e) {
|
262 |
e.printStackTrace(); |
263 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
264 |
e.printStackTrace(); |
265 |
} |
266 |
// draw(g,
|
267 |
// getCadToolAdapter().getMapControl().getViewPort(),
|
268 |
// symbol);
|
269 |
|
270 |
} |
271 |
|
272 |
/**
|
273 |
* DOCUMENT ME!
|
274 |
*
|
275 |
* @param geometry
|
276 |
* DOCUMENT ME!
|
277 |
*/
|
278 |
public Feature insertGeometry(Geometry geometry, Feature feature) {
|
279 |
VectorialLayerEdited vle = getVLE(); |
280 |
|
281 |
try {
|
282 |
FeatureStore featureStore = ((FLyrVect) vle.getLayer()) |
283 |
.getFeatureStore(); |
284 |
EditableFeature eFeature = featureStore.createNewFeature( |
285 |
featureStore.getDefaultFeatureType(), feature); |
286 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
287 |
.getDefaultGeometryAttributeName(), geometry); |
288 |
featureStore.insert(eFeature); |
289 |
// drawToImage(featureStore, vle, eFeature);
|
290 |
insertSpatialCache(geometry); |
291 |
draw(geometry.cloneGeometry()); |
292 |
return eFeature;
|
293 |
} catch (ReadException e) {
|
294 |
NotificationManager.addError(e.getMessage(), e); |
295 |
return null; |
296 |
} catch (DataException e) {
|
297 |
NotificationManager.addError(e.getMessage(), e); |
298 |
return null; |
299 |
} catch (CreateEnvelopeException e) {
|
300 |
NotificationManager.addError(e.getMessage(), e); |
301 |
return null; |
302 |
} |
303 |
} |
304 |
public Feature insertAndSelectGeometry(Geometry geometry){
|
305 |
Feature feature=null;
|
306 |
try{
|
307 |
FeatureStore featureStore = getVLE().getFeatureStore(); |
308 |
featureStore.beginComplexNotification(); |
309 |
featureStore.beginEditingGroup(getName()); |
310 |
FeatureSelection newSelection = featureStore |
311 |
.createFeatureSelection(); |
312 |
feature=insertGeometry(geometry); |
313 |
newSelection.select(feature); |
314 |
// clearSelection();
|
315 |
featureStore.setSelection(newSelection); |
316 |
featureStore.endEditingGroup(); |
317 |
featureStore.endComplexNotification(); |
318 |
}catch (DataException e) {
|
319 |
NotificationManager.showMessageError("insertAndSelectGeoemtry", e);
|
320 |
} |
321 |
return feature;
|
322 |
} |
323 |
public Feature insertGeometry(Geometry geometry) {
|
324 |
VectorialLayerEdited vle = getVLE(); |
325 |
|
326 |
try {
|
327 |
FeatureStore featureStore = ((FLyrVect) vle.getLayer()) |
328 |
.getFeatureStore(); |
329 |
EditableFeature eFeature = featureStore.createNewFeature(true);
|
330 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
331 |
.getDefaultGeometryAttributeName(), geometry); |
332 |
featureStore.insert(eFeature); |
333 |
|
334 |
// drawToImage(featureStore, vle, eFeature);
|
335 |
insertSpatialCache(geometry); |
336 |
draw(geometry.cloneGeometry()); |
337 |
return eFeature;
|
338 |
} catch (ReadException e) {
|
339 |
NotificationManager.addError(e.getMessage(), e); |
340 |
return null; |
341 |
} catch (DataException e) {
|
342 |
NotificationManager.addError(e.getMessage(), e); |
343 |
return null; |
344 |
} catch (CreateEnvelopeException e) {
|
345 |
NotificationManager.addError(e.getMessage(), e); |
346 |
return null; |
347 |
} |
348 |
|
349 |
} |
350 |
private void drawToImage(FeatureStore featureStore,VectorialLayerEdited vle, Feature feature) throws DataException, GeometryOperationNotSupportedException, GeometryOperationException { |
351 |
// clearSelection();
|
352 |
// ViewPort vp = vle.getLayer().getMapContext().getViewPort();
|
353 |
// BufferedImage selectionImage = new BufferedImage(
|
354 |
// vp.getImageWidth(), vp.getImageHeight(),
|
355 |
// BufferedImage.TYPE_INT_ARGB);
|
356 |
// Graphics2D gs = selectionImage.createGraphics();
|
357 |
// BufferedImage handlersImage = new BufferedImage(
|
358 |
// vp.getImageWidth(), vp.getImageHeight(),
|
359 |
// BufferedImage.TYPE_INT_ARGB);
|
360 |
// Graphics2D gh = handlersImage.createGraphics();
|
361 |
|
362 |
// int inversedIndex=vea.getInversedIndex(index);
|
363 |
// FeatureSelection selection = (FeatureSelection)
|
364 |
// featureStore.getSelection();
|
365 |
// selection.select(feature);
|
366 |
// vle.addSelectionCache(new DefaultRowEdited(df,
|
367 |
// IRowEdited.STATUS_ADDED, inversedIndex ));
|
368 |
// vea.getSelection().set(inversedIndex);
|
369 |
// Geometry geom = (Geometry)feature.getDefaultGeometry();
|
370 |
// DrawOperationContext doc = new DrawOperationContext();
|
371 |
// doc.setGraphics(gs);
|
372 |
// doc.setViewPort(vp);
|
373 |
// doc.setSymbol(DefaultCADTool.selectionSymbol);
|
374 |
Geometry geometry=feature.getDefaultGeometry(); |
375 |
// geometry.cloneGeometry().invokeOperation(Draw.CODE, doc);
|
376 |
// // draw(gs, vp, DefaultCADTool.selectionSymbol);
|
377 |
// vle.drawHandlers(geometry.cloneGeometry(), gh, vp);
|
378 |
// vle.setHandlersImage(handlersImage);
|
379 |
// vle.setSelectionImage(selectionImage);
|
380 |
try {
|
381 |
insertSpatialCache(geometry); |
382 |
} catch (CreateEnvelopeException e) {
|
383 |
logger.error("Error creating the envelope", e);
|
384 |
} |
385 |
|
386 |
} |
387 |
|
388 |
/**
|
389 |
* DOCUMENT ME!
|
390 |
*
|
391 |
* @param geometry
|
392 |
* DOCUMENT ME!
|
393 |
*/
|
394 |
// public void modifyFeature(Feature feature, Feature oldFeature) {
|
395 |
// try {
|
396 |
// CommandsRecord
|
397 |
// cr=((FLyrVect)getVLE().getLayer()).getFeatureStore().getCommandsRecord();
|
398 |
// cr.update(feature, oldFeature);
|
399 |
// } catch (ReadException e) {
|
400 |
// NotificationManager.addError(e.getMessage(),e);
|
401 |
// }
|
402 |
// draw(((Geometry)feature.getDefaultGeometry()).cloneGeometry());
|
403 |
// }
|
404 |
/**
|
405 |
* DOCUMENT ME!
|
406 |
*
|
407 |
* @param geometry
|
408 |
* DOCUMENT ME!
|
409 |
* @param values
|
410 |
* DOCUMENT ME!
|
411 |
*/
|
412 |
// public Feature addGeometry(Geometry geometry, Object[] values) {
|
413 |
// // int index = 0;
|
414 |
// try {
|
415 |
// FeatureStore featureStore = ((FLyrVect) getVLE().getLayer())
|
416 |
// .getFeatureStore();
|
417 |
// EditableFeature eFeature = featureStore.createNewFeature(true);
|
418 |
// eFeature.setGeometry(featureStore.getDefaultFeatureType()
|
419 |
// .getDefaultGeometryAttributeName(), geometry);
|
420 |
// for (int i = 0; i < values.length; i++) {
|
421 |
// eFeature.set(i, values[i]);
|
422 |
// }
|
423 |
// featureStore.insert(eFeature);
|
424 |
// return eFeature;
|
425 |
// } catch (DataException e) {
|
426 |
// // TODO Auto-generated catch block
|
427 |
// e.printStackTrace();
|
428 |
// }
|
429 |
// // try {
|
430 |
// // String newFID = vea.getNewFID();
|
431 |
// // DefaultFeature df = new DefaultFeature(geometry, values, newFID);
|
432 |
// // index = vea.addRow(df, getName(), EditionEvent.GRAPHIC);
|
433 |
// // insertSpatialCache(geometry);
|
434 |
// // } catch (ValidateRowException e) {
|
435 |
// // NotificationManager.addError(e);
|
436 |
// // } catch (ReadException e) {
|
437 |
// // NotificationManager.addError(e);
|
438 |
// // }
|
439 |
// // return vea.getInversedIndex(index);
|
440 |
// return null;
|
441 |
// }
|
442 |
|
443 |
/**
|
444 |
* Devuelve la cadena que corresponde al estado en el que nos encontramos.
|
445 |
*
|
446 |
* @return Cadena para mostrar por consola.
|
447 |
*/
|
448 |
public String getQuestion() { |
449 |
return question;
|
450 |
} |
451 |
|
452 |
/**
|
453 |
* Actualiza la cadena que corresponde al estado actual.
|
454 |
*
|
455 |
* @param s
|
456 |
* Cadena que aparecer� en consola.
|
457 |
*/
|
458 |
public void setQuestion(String s) { |
459 |
question = s; |
460 |
// ConsoleToken.addQuestion(s);
|
461 |
} |
462 |
|
463 |
/**
|
464 |
* Provoca un repintado "soft" de la capa activa en edici�n. Las capas por
|
465 |
* debajo de ella no se dibujan de verdad, solo se dibuja la que est� en
|
466 |
* edici�n y las que est�n por encima de ella en el TOC.
|
467 |
*/
|
468 |
public void refresh() { |
469 |
// getCadToolAdapter().getMapControl().drawMap(false);
|
470 |
|
471 |
getCadToolAdapter().getMapControl().rePaintDirtyLayers(); |
472 |
} |
473 |
|
474 |
/*
|
475 |
* public void drawHandlers(Graphics g, FBitSet sel, AffineTransform at)
|
476 |
* throws DriverIOException { for (int i = sel.nextSetBit(0); i >= 0; i =
|
477 |
* sel.nextSetBit(i + 1)) { IGeometry ig =
|
478 |
* getCadToolAdapter().getVectorialAdapter() .getShape(i).cloneGeometry();
|
479 |
* if (ig == null) continue; Handler[] handlers =
|
480 |
* ig.getHandlers(IGeometry.SELECTHANDLER);
|
481 |
* FGraphicUtilities.DrawHandlers((Graphics2D) g, at, handlers); } }
|
482 |
*/
|
483 |
public void drawHandlers(Graphics g, ArrayList selectedRows, |
484 |
AffineTransform at) {
|
485 |
FeatureSet selection = null;
|
486 |
DisposableIterator iterator = null;
|
487 |
try {
|
488 |
selection = (FeatureSet) ((FLyrVect) getVLE().getLayer()) |
489 |
.getFeatureStore().getSelection(); |
490 |
|
491 |
iterator = selection.iterator(); |
492 |
while (iterator.hasNext()) {
|
493 |
Feature feature = (Feature) iterator.next(); |
494 |
|
495 |
// }
|
496 |
// for (int i = 0; i < selectedRows.size(); i++) {
|
497 |
// IRowEdited edRow = (IRowEdited) selectedRows.get(i);
|
498 |
// IFeature feat = (IFeature) edRow.getLinkedRow();
|
499 |
// IFeature feat = (IFeature) selectedRows.get(i);
|
500 |
Geometry ig = (feature.getDefaultGeometry()) |
501 |
.cloneGeometry(); |
502 |
if (ig == null) { |
503 |
continue;
|
504 |
} |
505 |
Handler[] handlers = ig.getHandlers(Geometry.SELECTHANDLER); |
506 |
FGraphicUtilities.DrawHandlers((Graphics2D) g, at, handlers,
|
507 |
DefaultCADTool.handlerSymbol); |
508 |
} |
509 |
|
510 |
} catch (ReadException e) {
|
511 |
// TODO Auto-generated catch block
|
512 |
e.printStackTrace(); |
513 |
} catch (DataException e) {
|
514 |
// TODO Auto-generated catch block
|
515 |
e.printStackTrace(); |
516 |
} finally {
|
517 |
if (iterator != null) { |
518 |
iterator.dispose(); |
519 |
} |
520 |
} |
521 |
|
522 |
} |
523 |
|
524 |
public void setDescription(String[] currentdescriptions) { |
525 |
this.currentdescriptions = currentdescriptions;
|
526 |
} |
527 |
|
528 |
public String[] getDescriptions() { |
529 |
return currentdescriptions;
|
530 |
} |
531 |
|
532 |
/*
|
533 |
* (non-Javadoc)
|
534 |
*
|
535 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#end()
|
536 |
*/
|
537 |
public void end() { |
538 |
CADExtension.setCADTool("_selection", true); |
539 |
PluginServices.getMainFrame().setSelectedTool("_selection");
|
540 |
CADTool cadtool = CADExtension.getCADTool(); |
541 |
cadtool.setPreviosTool(this);
|
542 |
} |
543 |
|
544 |
public void init() { |
545 |
// jaume, should not be necessary
|
546 |
// CADTool.drawingSymbol.setOutlined(true);
|
547 |
// CADTool.drawingSymbol.setOutlineColor(Color.GREEN);
|
548 |
|
549 |
} |
550 |
|
551 |
// protected ArrayList getSelectedRows() {
|
552 |
// VectorialLayerEdited vle = getVLE();
|
553 |
// ArrayList selectedRow = vle.getSelectedRow();
|
554 |
// return selectedRow;
|
555 |
// }
|
556 |
|
557 |
protected ArrayList getSelectedHandlers() { |
558 |
VectorialLayerEdited vle = getVLE(); |
559 |
ArrayList selectedHandlers = vle.getSelectedHandler();
|
560 |
return selectedHandlers;
|
561 |
} |
562 |
|
563 |
public void clearSelection() throws DataException { |
564 |
VectorialLayerEdited vle = getVLE(); |
565 |
FeatureSelection selection = null;
|
566 |
selection = (FeatureSelection) ((FLyrVect) vle.getLayer()) |
567 |
.getFeatureStore().getSelection(); |
568 |
// ArrayList selectedRow = vle.getSelectedRow();
|
569 |
ArrayList selectedHandlers = vle.getSelectedHandler();
|
570 |
selection.deselectAll(); |
571 |
selectedHandlers.clear(); |
572 |
// VectorialEditableAdapter vea = vle.getVEA();
|
573 |
// FBitSet selection = vea.getSelection();
|
574 |
// selection.clear();
|
575 |
vle.setSelectionImage(null);
|
576 |
vle.setHandlersImage(null);
|
577 |
|
578 |
} |
579 |
|
580 |
public String getNextTool() { |
581 |
return tool;
|
582 |
} |
583 |
|
584 |
public void setNextTool(String tool) { |
585 |
this.tool = tool;
|
586 |
} |
587 |
|
588 |
public boolean changeCommand(String name) throws CommandException { |
589 |
CADTool[] cadtools = CADExtension.getCADTools();
|
590 |
for (int i = 0; i < cadtools.length; i++) { |
591 |
CADTool ct = cadtools[i]; |
592 |
if (name.equalsIgnoreCase(ct.getName())
|
593 |
|| name.equalsIgnoreCase(ct.toString())) { |
594 |
int type = Geometry.TYPES.POINT;
|
595 |
try {
|
596 |
type = ((FLyrVect) getVLE().getLayer()).getShapeType(); |
597 |
} catch (ReadException e) {
|
598 |
throw new CommandException(e); |
599 |
} |
600 |
if (ct.isApplicable(type)) {
|
601 |
getCadToolAdapter().setCadTool(ct); |
602 |
ct.init(); |
603 |
View vista = (View) PluginServices.getMDIManager() |
604 |
.getActiveWindow(); |
605 |
vista.getConsolePanel().addText("\n" + ct.getName(),
|
606 |
JConsole.COMMAND); |
607 |
String question = ct.getQuestion();
|
608 |
vista.getConsolePanel().addText( |
609 |
"\n" + "#" + question + " > ", JConsole.MESSAGE); |
610 |
return true; |
611 |
} |
612 |
throw new CommandException(name); |
613 |
} |
614 |
} |
615 |
return false; |
616 |
} |
617 |
|
618 |
public boolean isApplicable(int shapeType) { |
619 |
return true; |
620 |
} |
621 |
|
622 |
public abstract String toString(); |
623 |
|
624 |
public void throwValueException(String s, double d) { |
625 |
View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
626 |
vista.getConsolePanel().addText(s + " : " + d, JConsole.ERROR);
|
627 |
} |
628 |
|
629 |
public void throwOptionException(String s, String o) { |
630 |
View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
631 |
vista.getConsolePanel().addText(s + " : " + o, JConsole.ERROR);
|
632 |
} |
633 |
|
634 |
public void throwPointException(String s, double x, double y) { |
635 |
View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
636 |
vista.getConsolePanel().addText(s + " : " + " X = " + x + ", Y = " + y, |
637 |
JConsole.ERROR); |
638 |
} |
639 |
|
640 |
public void setPreviosTool(DefaultCADTool tool) { |
641 |
previousTool = tool; |
642 |
} |
643 |
|
644 |
public void restorePreviousTool() { |
645 |
CADExtension.setCADTool(previousTool.toString(), true);
|
646 |
PluginServices.getMainFrame().setSelectedTool(previousTool.toString()); |
647 |
} |
648 |
|
649 |
public void endTransition(double x, double y, MouseEvent e) { |
650 |
// TODO Auto-generated method stub
|
651 |
|
652 |
} |
653 |
|
654 |
/**
|
655 |
* Create a curve from a GeneralPath. If there is an
|
656 |
* error return <code>null</code> and add the error
|
657 |
* to the log
|
658 |
* @param gpx
|
659 |
* The GeneralPath
|
660 |
* @return
|
661 |
* The Curve
|
662 |
*/
|
663 |
protected Curve createCurve(GeneralPathX gpx){
|
664 |
Curve curve = null;
|
665 |
try {
|
666 |
curve = (Curve)geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D); |
667 |
curve.setGeneralPath(gpx); |
668 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
669 |
logger.error(new CreateGeometryException(TYPES.CURVE, SUBTYPES.GEOM2D, e));
|
670 |
} |
671 |
return curve;
|
672 |
} |
673 |
|
674 |
/**
|
675 |
* Create a surface from a GeneralPath. If there is an
|
676 |
* error return <code>null</code> and add the error
|
677 |
* to the log
|
678 |
* @param gpx
|
679 |
* The general path
|
680 |
* @return
|
681 |
* The Surface
|
682 |
*/
|
683 |
protected Surface createSurface(GeneralPathX gpx){
|
684 |
Surface surface = null;
|
685 |
try {
|
686 |
surface = (Surface)geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
687 |
surface.setGeneralPath(gpx); |
688 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
689 |
logger.error(new CreateGeometryException(TYPES.SURFACE, SUBTYPES.GEOM2D, e));
|
690 |
} |
691 |
return surface;
|
692 |
} |
693 |
|
694 |
/**
|
695 |
* Create a curve point. If there is an
|
696 |
* error return <code>null</code> and add the error
|
697 |
* to the log
|
698 |
* @param p1
|
699 |
* The AWT point
|
700 |
* @return
|
701 |
* The gvSIG point
|
702 |
*/
|
703 |
protected Point createPoint(Point2D p1){ |
704 |
return createPoint(p1.getX(), p1.getY());
|
705 |
} |
706 |
|
707 |
/**
|
708 |
* Create point. If there is an
|
709 |
* error return <code>null</code> and add the error
|
710 |
* to the log
|
711 |
* @param x
|
712 |
* The X coordinate
|
713 |
* @param y
|
714 |
* The y coordinate
|
715 |
* @return
|
716 |
* The Point
|
717 |
*/
|
718 |
protected Point createPoint(double x, double y){ |
719 |
Point point = null; |
720 |
try {
|
721 |
point = (Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
722 |
point.setX(x); |
723 |
point.setY(y); |
724 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
725 |
logger.error(new CreateGeometryException(TYPES.POINT, SUBTYPES.GEOM2D, e));
|
726 |
} |
727 |
return point;
|
728 |
} |
729 |
|
730 |
/**
|
731 |
* Create an Arc. If there is an
|
732 |
* error return <code>null</code> and add the error
|
733 |
* to the log
|
734 |
* @param p1
|
735 |
* @param p2
|
736 |
* @param p3
|
737 |
* @return
|
738 |
* The arc
|
739 |
*/
|
740 |
protected Arc createArc(Point2D p1, Point2D p2, Point2D p3){ |
741 |
return createArc(createPoint(p1), createPoint(p2), createPoint(p3));
|
742 |
} |
743 |
|
744 |
/**
|
745 |
* Create an arc. If there is an
|
746 |
* error return <code>null</code> and add the error
|
747 |
* to the log
|
748 |
* @param p1
|
749 |
* @param p2
|
750 |
* @param p3
|
751 |
* @return
|
752 |
* The arc
|
753 |
*/
|
754 |
protected Arc createArc(Point p1, Point p2, Point p3){ |
755 |
Arc arc = null;
|
756 |
try {
|
757 |
arc = (Arc)geomManager.create(TYPES.ARC, SUBTYPES.GEOM2D); |
758 |
arc.setPoints(p1, p2, p3); |
759 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
760 |
logger.error(new CreateGeometryException(TYPES.ARC, SUBTYPES.GEOM2D, e));
|
761 |
} |
762 |
return arc;
|
763 |
} |
764 |
|
765 |
/**
|
766 |
* Create a circle. If there is an
|
767 |
* error return <code>null</code> and add the error
|
768 |
* to the log
|
769 |
* @param p1
|
770 |
* @param p2
|
771 |
* @param p3
|
772 |
* @return
|
773 |
* The Circle
|
774 |
*/
|
775 |
protected Circle createCircle(Point p1, Point p2, Point p3){ |
776 |
Circle circle = null;
|
777 |
try {
|
778 |
circle = (Circle)geomManager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
779 |
circle.setPoints(p1, p2, p3); |
780 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
781 |
logger.error(new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e));
|
782 |
} |
783 |
return circle;
|
784 |
} |
785 |
|
786 |
/**
|
787 |
* Create a circle from a GeneralPath. If there is an
|
788 |
* error return <code>null</code> and add the error
|
789 |
* to the log
|
790 |
* @param p1
|
791 |
* @param p2
|
792 |
* @return
|
793 |
* The circle
|
794 |
*/
|
795 |
protected Circle createCircle(Point2D p1, Point2D p2){ |
796 |
return createCircle(createPoint(p1), createPoint(p2));
|
797 |
} |
798 |
|
799 |
/**
|
800 |
* Create a circle. If there is an
|
801 |
* error return <code>null</code> and add the error
|
802 |
* to the log
|
803 |
* @param p1
|
804 |
* @param p2
|
805 |
* @return
|
806 |
* The circle
|
807 |
*/
|
808 |
protected Circle createCircle(Point p1, Point p2){ |
809 |
Circle circle = null;
|
810 |
try {
|
811 |
circle = (Circle)geomManager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
812 |
circle.setPoints(p1, p2); |
813 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
814 |
logger.error(new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e));
|
815 |
} |
816 |
return circle;
|
817 |
} |
818 |
|
819 |
/**
|
820 |
* Create a circle. If there is an
|
821 |
* error return <code>null</code> and add the error
|
822 |
* to the log
|
823 |
* @param p1
|
824 |
* @param radious
|
825 |
* @return
|
826 |
* The Circle
|
827 |
*/
|
828 |
protected Circle createCircle(Point2D p1, double radious){ |
829 |
return createCircle(createPoint(p1), radious);
|
830 |
} |
831 |
|
832 |
/**
|
833 |
* Create a circle. If there is an
|
834 |
* error return <code>null</code> and add the error
|
835 |
* to the log
|
836 |
* @param p1
|
837 |
* @param radious
|
838 |
* @return
|
839 |
* The Circle
|
840 |
*/
|
841 |
protected Circle createCircle(Point p1, double radious){ |
842 |
Circle circle = null;
|
843 |
try {
|
844 |
circle = (Circle)geomManager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
845 |
circle.setPoints(p1, radious); |
846 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
847 |
logger.error(new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e));
|
848 |
} |
849 |
return circle;
|
850 |
} |
851 |
|
852 |
/**
|
853 |
* Create an Ellipse. If there is an
|
854 |
* error return <code>null</code> and add the error
|
855 |
* to the log
|
856 |
* @param p1
|
857 |
* @param p2
|
858 |
* @param d
|
859 |
* @return
|
860 |
* The Ellipse
|
861 |
*/
|
862 |
protected Ellipse createEllipse(Point2D p1, Point2D p2, double d){ |
863 |
return createEllipse(createPoint(p1), createPoint(p2), d);
|
864 |
} |
865 |
|
866 |
/**
|
867 |
* Create an Ellipse. If there is an
|
868 |
* error return <code>null</code> and add the error
|
869 |
* to the log
|
870 |
* @param p1
|
871 |
* @param p2
|
872 |
* @param d
|
873 |
* @return
|
874 |
* The Ellipse
|
875 |
*/
|
876 |
protected Ellipse createEllipse(Point p1, Point p2, double d){ |
877 |
Ellipse ellipse = null;
|
878 |
try {
|
879 |
ellipse = (Ellipse)geomManager.create(TYPES.ELLIPSE, SUBTYPES.GEOM2D); |
880 |
ellipse.setPoints(p1, p2, d); |
881 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
882 |
logger.error(new CreateGeometryException(TYPES.ELLIPSE, SUBTYPES.GEOM2D, e));
|
883 |
} |
884 |
return ellipse;
|
885 |
} |
886 |
|
887 |
/**
|
888 |
* Create a Spline from a GeneralPath. If there is an
|
889 |
* error return <code>null</code> and add the error
|
890 |
* to the log
|
891 |
* @param points
|
892 |
* @return
|
893 |
* The Spline
|
894 |
*/
|
895 |
protected Spline createSpline(Point2D[] points){ |
896 |
Spline spline = null;
|
897 |
try {
|
898 |
spline = (Spline)geomManager.create(TYPES.SPLINE, SUBTYPES.GEOM2D); |
899 |
for (int i=0 ; i<points.length ; i++){ |
900 |
spline.addVertex(createPoint(points[i])); |
901 |
} |
902 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
903 |
logger.error(new CreateGeometryException(TYPES.SPLINE, SUBTYPES.GEOM2D, e));
|
904 |
} |
905 |
return spline;
|
906 |
} |
907 |
|
908 |
/**
|
909 |
* Create a MultiPrimitive. If there is an
|
910 |
* error return <code>null</code> and add the error
|
911 |
* to the log
|
912 |
* @param geometries
|
913 |
* @return
|
914 |
*/
|
915 |
protected MultiPrimitive createMultiPrimitive(Geometry[] geometries){ |
916 |
MultiPrimitive multiPrimitive = null;
|
917 |
try {
|
918 |
multiPrimitive = (MultiPrimitive)geomManager.create(TYPES.AGGREGATE, SUBTYPES.GEOM2D); |
919 |
for (int i=0 ; i<geometries.length ; i++){ |
920 |
multiPrimitive.addPrimitive((Primitive)geometries[i]); |
921 |
} |
922 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
923 |
logger.error(new CreateGeometryException(TYPES.SPLINE, SUBTYPES.GEOM2D, e));
|
924 |
} |
925 |
return multiPrimitive;
|
926 |
} |
927 |
} |