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