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