svn-gvsig-desktop / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / StretchingCadTool.java @ 1763
History | View | Annotate | Download (7.83 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.tools; |
42 |
|
43 |
import com.iver.andami.PluginServices; |
44 |
|
45 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
46 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
47 |
import com.iver.cit.gvsig.fmap.core.Handler; |
48 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
49 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
50 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
51 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
52 |
import com.iver.cit.gvsig.fmap.edition.cad.Status; |
53 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
54 |
import com.iver.cit.gvsig.gui.cad.CadTool; |
55 |
import com.iver.cit.gvsig.gui.cad.automaton.Estirar; |
56 |
|
57 |
import com.iver.fsac.Automaton; |
58 |
|
59 |
import java.awt.Graphics; |
60 |
import java.awt.Graphics2D; |
61 |
import java.awt.geom.Point2D; |
62 |
import java.awt.geom.Rectangle2D; |
63 |
|
64 |
import java.io.IOException; |
65 |
|
66 |
|
67 |
/**
|
68 |
* Herramienta para estirar los handlers que seleccionemos previamente.
|
69 |
*
|
70 |
* @author Vicente Caballero Navarro
|
71 |
*/
|
72 |
public class StretchingCadTool extends AbstractCadTool { |
73 |
private static Status[] STATUS = { |
74 |
new Status("Seleccione primer punto de zona a estirar(x,y):"), |
75 |
new Status("Seleccione segundo punto de zona a estirar(x,y):"), |
76 |
new Status("Precise punto de estiramiento(x,y):"), |
77 |
new Status("Precise segundo punto(x,y):") |
78 |
}; |
79 |
private Estirar stretchingStatus = new Estirar(); |
80 |
private Point2D selfirstPoint; |
81 |
private Point2D sellastPoint; |
82 |
private Point2D movefirstPoint; |
83 |
private Point2D movelastPoint; |
84 |
private Rectangle2D rect = null; |
85 |
|
86 |
/**
|
87 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
|
88 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
89 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
|
90 |
*/
|
91 |
public int transition(String text, |
92 |
final EditableFeatureSource editingSource,
|
93 |
final FBitSet selectedGeometries, final double[] ds) { |
94 |
int ret = stretchingStatus.transition(text);
|
95 |
|
96 |
int status = stretchingStatus.getStatus();
|
97 |
|
98 |
if (status == 0) { |
99 |
if (selectedGeometries.cardinality() == 0) { |
100 |
getCadToolAdapter().pushCadTool(new SelectionCadTool());
|
101 |
} |
102 |
|
103 |
if (ds.length != 0) { |
104 |
sellastPoint = new Point2D.Double(ds[0], ds[1]); |
105 |
|
106 |
double x;
|
107 |
double y;
|
108 |
double w;
|
109 |
double h;
|
110 |
|
111 |
if (selfirstPoint.getX() < sellastPoint.getX()) {
|
112 |
x = selfirstPoint.getX(); |
113 |
w = sellastPoint.getX() - selfirstPoint.getX(); |
114 |
} else {
|
115 |
x = sellastPoint.getX(); |
116 |
w = selfirstPoint.getX() - sellastPoint.getX(); |
117 |
} |
118 |
|
119 |
if (selfirstPoint.getY() < sellastPoint.getY()) {
|
120 |
y = selfirstPoint.getY(); |
121 |
h = sellastPoint.getY() - selfirstPoint.getY(); |
122 |
} else {
|
123 |
y = sellastPoint.getY(); |
124 |
h = selfirstPoint.getY() - sellastPoint.getY(); |
125 |
} |
126 |
|
127 |
rect = new Rectangle2D.Double(x, y, w, h); |
128 |
} |
129 |
} else if (status == 1) { |
130 |
if (ds.length != 0) { |
131 |
selfirstPoint = new Point2D.Double(ds[0], ds[1]); |
132 |
} |
133 |
} else if (status == 2) { |
134 |
} else if (status == 3) { |
135 |
movefirstPoint = new Point2D.Double(ds[0], ds[1]); |
136 |
} else if (status == 4) { |
137 |
PluginServices.getMDIManager().setWaitCursor(); |
138 |
movelastPoint = new Point2D.Double(ds[0], ds[1]); |
139 |
|
140 |
Handler[] handlers = null; |
141 |
|
142 |
for (int i = selectedGeometries.nextSetBit(0); i >= 0; |
143 |
i = selectedGeometries.nextSetBit(i + 1)) {
|
144 |
IGeometry geometry = null;
|
145 |
|
146 |
try {
|
147 |
geometry = editingSource.getGeometry(i); |
148 |
} catch (IOException e) { |
149 |
e.printStackTrace(); |
150 |
} catch (DriverIOException e) {
|
151 |
e.printStackTrace(); |
152 |
} |
153 |
|
154 |
handlers = geometry.getHandlers(FGeometry.STRETCHINGHANDLER); |
155 |
|
156 |
for (int j = 0; j < handlers.length; j++) { |
157 |
if (rect.contains(handlers[j].getPoint())) {
|
158 |
handlers[j].move(movelastPoint.getX() - |
159 |
movefirstPoint.getX(), |
160 |
movelastPoint.getY() - movefirstPoint.getY()); |
161 |
} |
162 |
} |
163 |
|
164 |
try {
|
165 |
editingSource.modifyGeometry(i, geometry); |
166 |
} catch (IOException e1) { |
167 |
e1.printStackTrace(); |
168 |
} catch (DriverIOException e) {
|
169 |
e.printStackTrace(); |
170 |
} |
171 |
} |
172 |
|
173 |
PluginServices.getMDIManager().restoreCursor(); |
174 |
ret = ret | stretchingStatus.transition("cancel");
|
175 |
} |
176 |
|
177 |
return ret;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
|
182 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
183 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
184 |
*/
|
185 |
public void drawOperation(Graphics g, EditableFeatureSource efs, |
186 |
FBitSet selectedGeometries, double x, double y) { |
187 |
double dx;
|
188 |
double dy;
|
189 |
double dw;
|
190 |
double dh;
|
191 |
int status = stretchingStatus.getStatus();
|
192 |
|
193 |
if (status == 1) { |
194 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
195 |
4);
|
196 |
elShape.moveTo(selfirstPoint.getX(), selfirstPoint.getY()); |
197 |
elShape.lineTo(x, selfirstPoint.getY()); |
198 |
elShape.lineTo(x, y); |
199 |
elShape.lineTo(selfirstPoint.getX(), y); |
200 |
elShape.lineTo(selfirstPoint.getX(), selfirstPoint.getY()); |
201 |
ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g,
|
202 |
getCadToolAdapter().getMapControl().getViewPort(), |
203 |
CadTool.modifySymbol); |
204 |
} else if (status == 3) { |
205 |
// drawLine((Graphics2D)g, movefirstPoint, new Point2D.Double(x, y));
|
206 |
//}else if (status == 4){
|
207 |
if (selfirstPoint.getX() < x) {
|
208 |
dx = selfirstPoint.getX(); |
209 |
dw = x - selfirstPoint.getX(); |
210 |
} else {
|
211 |
dx = x; |
212 |
dw = selfirstPoint.getX() - x; |
213 |
} |
214 |
|
215 |
if (selfirstPoint.getY() < sellastPoint.getY()) {
|
216 |
dy = selfirstPoint.getY(); |
217 |
dh = y - selfirstPoint.getY(); |
218 |
} else {
|
219 |
dy = y; |
220 |
dh = selfirstPoint.getY() - y; |
221 |
} |
222 |
|
223 |
Rectangle2D rec = new Rectangle2D.Double(dx, dy, dw, dh); |
224 |
Handler[] handlers = null; |
225 |
|
226 |
for (int i = selectedGeometries.nextSetBit(0); i >= 0; |
227 |
i = selectedGeometries.nextSetBit(i + 1)) {
|
228 |
IGeometry geometry = null;
|
229 |
|
230 |
try {
|
231 |
geometry = efs.getGeometry(i); |
232 |
} catch (IOException e) { |
233 |
e.printStackTrace(); |
234 |
} catch (DriverIOException e) {
|
235 |
e.printStackTrace(); |
236 |
} |
237 |
|
238 |
handlers = geometry.getHandlers(FGeometry.STRETCHINGHANDLER); |
239 |
|
240 |
for (int j = 0; j < handlers.length; j++) { |
241 |
if (rect.contains(handlers[j].getPoint())) {
|
242 |
handlers[j].move(x - movefirstPoint.getX(), |
243 |
y - movefirstPoint.getY()); |
244 |
} |
245 |
} |
246 |
|
247 |
geometry.draw((Graphics2D) g,
|
248 |
getCadToolAdapter().getMapControl().getViewPort(), |
249 |
CadTool.modifySymbol); |
250 |
} |
251 |
} |
252 |
} |
253 |
|
254 |
/**
|
255 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
|
256 |
*/
|
257 |
public String getQuestion() { |
258 |
return STATUS[stretchingStatus.getStatus()].getQuestion();
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
|
263 |
*/
|
264 |
public void initializeStatus() { |
265 |
stretchingStatus.initialize(); |
266 |
} |
267 |
|
268 |
/**
|
269 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
|
270 |
*/
|
271 |
public Automaton getAutomaton() {
|
272 |
return stretchingStatus;
|
273 |
} |
274 |
|
275 |
/**
|
276 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getName()
|
277 |
*/
|
278 |
public String getName() { |
279 |
return "ESTIRAR"; |
280 |
} |
281 |
} |