root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / StretchCADTool.java @ 33205
History | View | Annotate | Download (11.1 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.tools; |
42 |
|
43 |
import java.awt.Image; |
44 |
import java.awt.event.InputEvent; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
|
48 |
import org.gvsig.andami.PluginServices; |
49 |
import org.gvsig.andami.messages.NotificationManager; |
50 |
import org.gvsig.editing.CADExtension; |
51 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
52 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
53 |
import org.gvsig.editing.gui.cad.tools.smc.StretchCADToolContext; |
54 |
import org.gvsig.editing.gui.cad.tools.smc.StretchCADToolContext.StretchCADToolState; |
55 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
56 |
import org.gvsig.fmap.dal.exception.DataException; |
57 |
import org.gvsig.fmap.dal.exception.ReadException; |
58 |
import org.gvsig.tools.dispose.DisposableIterator; |
59 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
60 |
import org.gvsig.fmap.dal.feature.Feature; |
61 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
62 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
63 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
64 |
import org.gvsig.fmap.geom.Geometry; |
65 |
import org.gvsig.fmap.geom.handler.Handler; |
66 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
67 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
68 |
|
69 |
|
70 |
/**
|
71 |
* Herramienta para estirar los handlers que seleccionemos previamente.
|
72 |
*
|
73 |
* @author Vicente Caballero Navarro
|
74 |
*/
|
75 |
public class StretchCADTool extends DefaultCADTool { |
76 |
protected StretchCADToolContext _fsm;
|
77 |
protected Point2D selfirstPoint; |
78 |
protected Point2D sellastPoint; |
79 |
protected Point2D movefirstPoint; |
80 |
protected Point2D movelastPoint; |
81 |
protected Rectangle2D rect = null; |
82 |
|
83 |
/**
|
84 |
* Crea un nuevo PolylineCADTool.
|
85 |
*/
|
86 |
public StretchCADTool() {
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
91 |
* carga previa a la utilizaci?n de la herramienta.
|
92 |
*/
|
93 |
public void init() { |
94 |
_fsm = new StretchCADToolContext(this); |
95 |
} |
96 |
|
97 |
/*
|
98 |
* (non-Javadoc)
|
99 |
*
|
100 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
101 |
* double, double)
|
102 |
*/
|
103 |
public void transition(double x, double y, InputEvent event) { |
104 |
_fsm.addPoint(x, y, event); |
105 |
} |
106 |
|
107 |
/*
|
108 |
* (non-Javadoc)
|
109 |
*
|
110 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
111 |
* double)
|
112 |
*/
|
113 |
public void transition(double d) { |
114 |
_fsm.addValue(d); |
115 |
} |
116 |
|
117 |
/*
|
118 |
* (non-Javadoc)
|
119 |
*
|
120 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
121 |
* java.lang.String)
|
122 |
*/
|
123 |
public void transition(String s) throws CommandException { |
124 |
if (!super.changeCommand(s)) { |
125 |
_fsm.addOption(s); |
126 |
} |
127 |
} |
128 |
|
129 |
/**
|
130 |
* DOCUMENT ME!
|
131 |
*/
|
132 |
public void selection() { |
133 |
FeatureSet selection = null;
|
134 |
try {
|
135 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
136 |
|
137 |
if (selection.getSize() == 0 |
138 |
&& !CADExtension |
139 |
.getCADTool() |
140 |
.getClass() |
141 |
.getName() |
142 |
.equals( |
143 |
"com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
144 |
CADExtension.setCADTool("_selection", false); |
145 |
((SelectionCADTool) CADExtension.getCADTool()) |
146 |
.setNextTool("_stretch");
|
147 |
} |
148 |
} catch (ReadException e) {
|
149 |
// TODO Auto-generated catch block
|
150 |
e.printStackTrace(); |
151 |
} catch (DataException e) {
|
152 |
// TODO Auto-generated catch block
|
153 |
e.printStackTrace(); |
154 |
} |
155 |
} |
156 |
|
157 |
/**
|
158 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
159 |
* editableFeatureSource que ya estar? creado.
|
160 |
*
|
161 |
* @param x
|
162 |
* par?metro x del punto que se pase en esta transici?n.
|
163 |
* @param y
|
164 |
* par?metro y del punto que se pase en esta transici?n.
|
165 |
*/
|
166 |
public void addPoint(double x, double y, InputEvent event) { |
167 |
StretchCADToolState actualState = (StretchCADToolState) _fsm |
168 |
.getPreviousState(); |
169 |
String status = actualState.getName();
|
170 |
|
171 |
if (status.equals("Stretch.SelFirstPoint")) { |
172 |
selfirstPoint = new Point2D.Double(x, y); |
173 |
} else if (status.equals("Stretch.SelLastPoint")) { |
174 |
sellastPoint = new Point2D.Double(x, y); |
175 |
|
176 |
double x1;
|
177 |
double y1;
|
178 |
double w1;
|
179 |
double h1;
|
180 |
|
181 |
if (selfirstPoint.getX() < sellastPoint.getX()) {
|
182 |
x1 = selfirstPoint.getX(); |
183 |
w1 = sellastPoint.getX() - selfirstPoint.getX(); |
184 |
} else {
|
185 |
x1 = sellastPoint.getX(); |
186 |
w1 = selfirstPoint.getX() - sellastPoint.getX(); |
187 |
} |
188 |
|
189 |
if (selfirstPoint.getY() < sellastPoint.getY()) {
|
190 |
y1 = selfirstPoint.getY(); |
191 |
h1 = sellastPoint.getY() - selfirstPoint.getY(); |
192 |
} else {
|
193 |
y1 = sellastPoint.getY(); |
194 |
h1 = selfirstPoint.getY() - sellastPoint.getY(); |
195 |
} |
196 |
|
197 |
rect = new Rectangle2D.Double(x1, y1, w1, h1); |
198 |
} else if (status.equals("Stretch.MoveFirstPoint")) { |
199 |
movefirstPoint = new Point2D.Double(x, y); |
200 |
} else if (status.equals("Stretch.MoveLastPoint")) { |
201 |
VectorialLayerEdited vle = getVLE(); |
202 |
FeatureStore featureStore = null;
|
203 |
DisposableIterator iterator = null;
|
204 |
try {
|
205 |
featureStore = vle.getFeatureStore(); |
206 |
|
207 |
// VectorialEditableAdapter vea=vle.getVEA();
|
208 |
featureStore.beginEditingGroup(getName()); |
209 |
// ArrayList selectedRow=getSelectedRows();
|
210 |
// ArrayList selectedRowAux = new ArrayList();
|
211 |
// PluginServices.getMDIManager().setWaitCursor();
|
212 |
movelastPoint = new Point2D.Double(x, y); |
213 |
|
214 |
Handler[] handlers = null; |
215 |
|
216 |
// for (int i = selectedGeometries.nextSetBit(0); i >= 0;
|
217 |
// i = selectedGeometries.nextSetBit(i + 1)) {
|
218 |
iterator = ((FeatureSelection) featureStore |
219 |
.getSelection()).iterator(); |
220 |
while (iterator.hasNext()) {
|
221 |
Feature feature = (Feature) iterator.next(); |
222 |
|
223 |
// }
|
224 |
// for (int i =0;i<selectedRow.size(); i++) {
|
225 |
// IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
226 |
// DefaultFeature fea = (DefaultFeature)
|
227 |
// edRow.getLinkedRow().cloneRow();
|
228 |
Geometry geometry = null;
|
229 |
geometry = (feature.getDefaultGeometry()) |
230 |
.cloneGeometry(); |
231 |
|
232 |
handlers = geometry.getHandlers(Geometry.STRETCHINGHANDLER); |
233 |
|
234 |
for (int j = 0; j < handlers.length; j++) { |
235 |
if (rect.contains(handlers[j].getPoint())) {
|
236 |
handlers[j].move(movelastPoint.getX() |
237 |
- movefirstPoint.getX(), movelastPoint |
238 |
.getY() |
239 |
- movefirstPoint.getY()); |
240 |
} |
241 |
} |
242 |
EditableFeature eFeature = feature.getEditable(); |
243 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
244 |
.getDefaultGeometryAttributeName(), geometry); |
245 |
// vea.modifyRow(edRow.getIndex(),fea,getName(),EditionEvent.GRAPHIC);
|
246 |
featureStore.update(eFeature); |
247 |
// selectedRowAux.add(feature);
|
248 |
} |
249 |
featureStore.endEditingGroup(); |
250 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
|
251 |
// selectedRowAux);
|
252 |
|
253 |
// PluginServices.getMDIManager().restoreCursor();
|
254 |
} catch (DataException e) {
|
255 |
NotificationManager.addError(e.getMessage(), e); |
256 |
} finally {
|
257 |
if (iterator != null) { |
258 |
iterator.dispose(); |
259 |
} |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
/**
|
265 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
266 |
* encontremos.
|
267 |
*
|
268 |
* @param g
|
269 |
* Graphics sobre el que dibujar.
|
270 |
* @param x
|
271 |
* par?metro x del punto que se pase para dibujar.
|
272 |
* @param y
|
273 |
* par?metro x del punto que se pase para dibujar.
|
274 |
*/
|
275 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
276 |
StretchCADToolState actualState = (_fsm) |
277 |
.getState(); |
278 |
String status = actualState.getName();
|
279 |
|
280 |
// ArrayList selectedRow = getSelectedRows();
|
281 |
DisposableIterator iterator = null;
|
282 |
try {
|
283 |
iterator = ((FeatureSelection) getVLE().getFeatureStore() |
284 |
.getSelection()).iterator(); |
285 |
if (status.equals("Stretch.SelLastPoint")) { |
286 |
GeneralPathX elShape = new GeneralPathX(
|
287 |
GeneralPathX.WIND_EVEN_ODD, 4);
|
288 |
elShape.moveTo(selfirstPoint.getX(), selfirstPoint.getY()); |
289 |
elShape.lineTo(x, selfirstPoint.getY()); |
290 |
elShape.lineTo(x, y); |
291 |
elShape.lineTo(selfirstPoint.getX(), y); |
292 |
elShape.lineTo(selfirstPoint.getX(), selfirstPoint.getY()); |
293 |
|
294 |
renderer.draw(createCurve(elShape), mapControlManager.getAxisReferenceSymbol()); |
295 |
} else if (status.equals("Stretch.MoveFirstPoint")) { |
296 |
|
297 |
Handler[] handlers = null; |
298 |
while (iterator.hasNext()) {
|
299 |
Feature feature = (Feature) iterator.next(); |
300 |
|
301 |
Geometry geometry = null;
|
302 |
geometry = (feature.getDefaultGeometry()).cloneGeometry(); |
303 |
|
304 |
handlers = geometry.getHandlers(Geometry.STRETCHINGHANDLER); |
305 |
|
306 |
for (int j = 0; j < handlers.length; j++) { |
307 |
if (rect.contains(handlers[j].getPoint())) {
|
308 |
renderer.drawHandlers(handlers, |
309 |
getCadToolAdapter().getMapControl() |
310 |
.getViewPort() |
311 |
.getAffineTransform(), |
312 |
mapControlManager.getHandlerSymbol()); |
313 |
} |
314 |
} |
315 |
} |
316 |
} else if (status.equals("Stretch.MoveLastPoint")) { |
317 |
Handler[] handlers = null; |
318 |
while (iterator.hasNext()) {
|
319 |
Feature feature = (Feature) iterator.next(); |
320 |
// for (int i = 0;i<selectedRow.size();i++) {
|
321 |
// IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
322 |
// DefaultFeature fea = (DefaultFeature)
|
323 |
// edRow.getLinkedRow().cloneRow();
|
324 |
Geometry geometry = null;
|
325 |
geometry = (feature.getDefaultGeometry()).cloneGeometry(); |
326 |
|
327 |
handlers = geometry.getHandlers(Geometry.STRETCHINGHANDLER); |
328 |
|
329 |
for (int j = 0; j < handlers.length; j++) { |
330 |
if (rect.contains(handlers[j].getPoint())) {
|
331 |
handlers[j].move(x - movefirstPoint.getX(), y |
332 |
- movefirstPoint.getY()); |
333 |
} |
334 |
} |
335 |
renderer.draw(geometry, mapControlManager.getAxisReferenceSymbol()); |
336 |
} |
337 |
} |
338 |
} catch (DataException e) {
|
339 |
// TODO Auto-generated catch block
|
340 |
e.printStackTrace(); |
341 |
} finally {
|
342 |
if (iterator != null) { |
343 |
iterator.dispose(); |
344 |
} |
345 |
} |
346 |
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* Add a diferent option.
|
351 |
*
|
352 |
* @param s
|
353 |
* Diferent option.
|
354 |
*/
|
355 |
public void addOption(String s) { |
356 |
} |
357 |
|
358 |
/*
|
359 |
* (non-Javadoc)
|
360 |
*
|
361 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
362 |
*/
|
363 |
public void addValue(double d) { |
364 |
} |
365 |
|
366 |
public String getName() { |
367 |
return PluginServices.getText(this, "stretch_"); |
368 |
} |
369 |
|
370 |
public String toString() { |
371 |
return "_stretch"; |
372 |
} |
373 |
|
374 |
public boolean isApplicable(int shapeType) { |
375 |
switch (shapeType) {
|
376 |
case Geometry.TYPES.POINT:
|
377 |
case Geometry.TYPES.MULTIPOINT:
|
378 |
return false; |
379 |
} |
380 |
return true; |
381 |
} |
382 |
} |