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