root / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / RectangleCadTool.java @ 1695
History | View | Annotate | Download (9.32 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.cit.gvsig.fmap.core.FGeometryCollection; |
44 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
45 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
46 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
47 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
48 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
49 |
import com.iver.cit.gvsig.fmap.edition.cad.Status; |
50 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
51 |
import com.iver.cit.gvsig.gui.cad.CadTool; |
52 |
import com.iver.cit.gvsig.gui.cad.automaton.Rectangulo; |
53 |
|
54 |
import com.iver.fsac.Automaton; |
55 |
|
56 |
import java.awt.Graphics; |
57 |
import java.awt.Graphics2D; |
58 |
import java.awt.geom.Point2D; |
59 |
|
60 |
import java.io.IOException; |
61 |
|
62 |
import java.util.ArrayList; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Herramienta para a?adir una geometr?a rectangulo o cuadrado.
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*/
|
70 |
public class RectangleCadTool extends AbstractCadTool { |
71 |
private static Status[] STATUS = { |
72 |
new Status("Precise primer punto de esquina"), |
73 |
new Status("Precise esquina opuesta o tipo Cuadrado(C)"), |
74 |
new Status("Precise esquina opuesta") |
75 |
}; |
76 |
private Rectangulo rectangleStatus = new Rectangulo(); |
77 |
private Point2D firstPoint; |
78 |
private Point2D lastPoint; |
79 |
private ArrayList list = new ArrayList(); |
80 |
|
81 |
/**
|
82 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
|
83 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
84 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
|
85 |
*/
|
86 |
public int transition(String text, EditableFeatureSource editingSource, |
87 |
FBitSet selectedGeometries, double[] values) { |
88 |
int ret = rectangleStatus.transition(text);
|
89 |
|
90 |
int status = rectangleStatus.getStatus();
|
91 |
|
92 |
if (status == 0) { |
93 |
//firstPoint=new FPoint2D(values[0], values[1]);
|
94 |
} else if (status == 1) { |
95 |
if (values.length != 0) { |
96 |
firstPoint = new Point2D.Double(values[0], values[1]); |
97 |
} |
98 |
|
99 |
System.out.println("1"); |
100 |
} else if (status == 2) { |
101 |
System.out.println("2"); |
102 |
} else if (status == 3) { |
103 |
System.out.println("3"); |
104 |
|
105 |
if (values.length != 0) { |
106 |
lastPoint = new Point2D.Double(values[0], values[1]); |
107 |
} |
108 |
|
109 |
/*GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
110 |
4);
|
111 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY());
|
112 |
elShape.lineTo(lastPoint.getX(), firstPoint.getY());
|
113 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY());
|
114 |
elShape.lineTo(firstPoint.getX(), lastPoint.getY());
|
115 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY());
|
116 |
editingSource.addGeometry(ShapeFactory.createPolyline2D(
|
117 |
elShape));
|
118 |
*/
|
119 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
120 |
2);
|
121 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
122 |
elShape.lineTo(lastPoint.getX(), firstPoint.getY()); |
123 |
list.add(ShapeFactory.createPolyline2D(elShape)); |
124 |
|
125 |
elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
126 |
elShape.moveTo(lastPoint.getX(), firstPoint.getY()); |
127 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
128 |
list.add(ShapeFactory.createPolyline2D(elShape)); |
129 |
|
130 |
elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
131 |
elShape.moveTo(lastPoint.getX(), lastPoint.getY()); |
132 |
elShape.lineTo(firstPoint.getX(), lastPoint.getY()); |
133 |
list.add(ShapeFactory.createPolyline2D(elShape)); |
134 |
|
135 |
elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
136 |
elShape.moveTo(firstPoint.getX(), lastPoint.getY()); |
137 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
138 |
list.add(ShapeFactory.createPolyline2D(elShape)); |
139 |
|
140 |
IGeometry[] geoms = (IGeometry[]) list.toArray(new IGeometry[0]); |
141 |
|
142 |
FGeometryCollection fgc = new FGeometryCollection(geoms);
|
143 |
|
144 |
try {
|
145 |
editingSource.addGeometry(fgc); |
146 |
} catch (DriverIOException e1) {
|
147 |
e1.printStackTrace(); |
148 |
} catch (IOException e1) { |
149 |
e1.printStackTrace(); |
150 |
} |
151 |
list.clear(); |
152 |
ret = ret | rectangleStatus.transition("cancel");
|
153 |
} else if (status == 4) { |
154 |
System.out.println("4"); |
155 |
|
156 |
if (values.length != 0) { |
157 |
lastPoint = new Point2D.Double(values[0], values[1]); |
158 |
} |
159 |
|
160 |
/*
|
161 |
try {
|
162 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
163 |
4);
|
164 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY());
|
165 |
elShape.lineTo(lastPoint.getX(), firstPoint.getY());
|
166 |
elShape.lineTo(lastPoint.getX(),firstPoint.getY()-(lastPoint.getX()-firstPoint.getX()));
|
167 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()-(lastPoint.getX()-firstPoint.getX()));
|
168 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY());
|
169 |
editingSource.addGeometry(ShapeFactory.createPolyline2D(
|
170 |
elShape));
|
171 |
} catch (DriverIOException e) {
|
172 |
e.printStackTrace();
|
173 |
} catch (IOException e) {
|
174 |
e.printStackTrace();
|
175 |
}
|
176 |
*/
|
177 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
178 |
2);
|
179 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
180 |
elShape.lineTo(lastPoint.getX(), firstPoint.getY()); |
181 |
list.add(ShapeFactory.createPolyline2D(elShape)); |
182 |
|
183 |
elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
184 |
elShape.moveTo(lastPoint.getX(), firstPoint.getY()); |
185 |
elShape.lineTo(lastPoint.getX(), |
186 |
firstPoint.getY() - (lastPoint.getX() - firstPoint.getX())); |
187 |
list.add(ShapeFactory.createPolyline2D(elShape)); |
188 |
|
189 |
elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
190 |
elShape.moveTo(lastPoint.getX(), |
191 |
firstPoint.getY() - (lastPoint.getX() - firstPoint.getX())); |
192 |
elShape.lineTo(firstPoint.getX(), |
193 |
firstPoint.getY() - (lastPoint.getX() - firstPoint.getX())); |
194 |
list.add(ShapeFactory.createPolyline2D(elShape)); |
195 |
|
196 |
elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
197 |
elShape.moveTo(firstPoint.getX(), |
198 |
firstPoint.getY() - (lastPoint.getX() - firstPoint.getX())); |
199 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
200 |
list.add(ShapeFactory.createPolyline2D(elShape)); |
201 |
|
202 |
IGeometry[] geoms = (IGeometry[]) list.toArray(new IGeometry[0]); |
203 |
|
204 |
FGeometryCollection fgc = new FGeometryCollection(geoms);
|
205 |
|
206 |
try {
|
207 |
editingSource.addGeometry(fgc); |
208 |
} catch (DriverIOException e1) {
|
209 |
e1.printStackTrace(); |
210 |
} catch (IOException e1) { |
211 |
e1.printStackTrace(); |
212 |
} |
213 |
|
214 |
list.clear(); |
215 |
ret = ret | rectangleStatus.transition("cancel");
|
216 |
} |
217 |
|
218 |
return ret;
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
|
223 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
224 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
225 |
*/
|
226 |
public void drawOperation(Graphics g, EditableFeatureSource efs, |
227 |
FBitSet selectedGeometries, double x, double y) { |
228 |
int status = rectangleStatus.getStatus();
|
229 |
|
230 |
if (status == 1) { |
231 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
232 |
4);
|
233 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
234 |
elShape.lineTo(x, firstPoint.getY()); |
235 |
elShape.lineTo(x, y); |
236 |
elShape.lineTo(firstPoint.getX(), y); |
237 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
238 |
ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g,
|
239 |
getCadToolAdapter().getMapControl().getViewPort(), |
240 |
CadTool.modifySymbol); |
241 |
} else if (status == 2) { |
242 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
243 |
4);
|
244 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
245 |
elShape.lineTo(x, firstPoint.getY()); |
246 |
elShape.lineTo(x, firstPoint.getY() - (x - firstPoint.getX())); |
247 |
elShape.lineTo(firstPoint.getX(), |
248 |
firstPoint.getY() - (x - firstPoint.getX())); |
249 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
250 |
ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g,
|
251 |
getCadToolAdapter().getMapControl().getViewPort(), |
252 |
CadTool.modifySymbol); |
253 |
} |
254 |
} |
255 |
|
256 |
/**
|
257 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
|
258 |
*/
|
259 |
public String getQuestion() { |
260 |
return STATUS[rectangleStatus.getStatus()].getQuestion();
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
|
265 |
*/
|
266 |
public void initializeStatus() { |
267 |
rectangleStatus.initialize(); |
268 |
} |
269 |
|
270 |
/**
|
271 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
|
272 |
*/
|
273 |
public Automaton getAutomaton() {
|
274 |
return rectangleStatus;
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getName()
|
279 |
*/
|
280 |
public String getName() { |
281 |
return "RECT?NGULO"; |
282 |
} |
283 |
} |