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