root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / RectangleCADTool.java @ 30788
History | View | Annotate | Download (9.39 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 |
|
47 |
import org.gvsig.andami.PluginServices; |
48 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
49 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
50 |
import org.gvsig.editing.gui.cad.tools.smc.RectangleCADToolContext; |
51 |
import org.gvsig.editing.gui.cad.tools.smc.RectangleCADToolContext.RectangleCADToolState; |
52 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
53 |
import org.gvsig.fmap.geom.Geometry; |
54 |
import org.gvsig.fmap.geom.operation.Draw; |
55 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
56 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
57 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
58 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
59 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
60 |
|
61 |
|
62 |
|
63 |
/**
|
64 |
* DOCUMENT ME!
|
65 |
*
|
66 |
* @author Vicente Caballero Navarro
|
67 |
*/
|
68 |
public class RectangleCADTool extends DefaultCADTool { |
69 |
protected RectangleCADToolContext _fsm;
|
70 |
protected Point2D firstPoint; |
71 |
protected Point2D lastPoint; |
72 |
|
73 |
/**
|
74 |
* Crea un nuevo LineCADTool.
|
75 |
*/
|
76 |
public RectangleCADTool() {
|
77 |
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
82 |
* carga previa a la utilizaci?n de la herramienta.
|
83 |
*/
|
84 |
public void init() { |
85 |
_fsm = new RectangleCADToolContext(this); |
86 |
} |
87 |
|
88 |
/* (non-Javadoc)
|
89 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
90 |
*/
|
91 |
public void transition(double x, double y, InputEvent event) { |
92 |
_fsm.addPoint(x, y, event); |
93 |
} |
94 |
|
95 |
/* (non-Javadoc)
|
96 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
97 |
*/
|
98 |
public void transition(double d) { |
99 |
_fsm.addValue(d); |
100 |
} |
101 |
|
102 |
/* (non-Javadoc)
|
103 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
104 |
*/
|
105 |
public void transition(String s) throws CommandException { |
106 |
if (!super.changeCommand(s)){ |
107 |
_fsm.addOption(s); |
108 |
} |
109 |
} |
110 |
|
111 |
/**
|
112 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
113 |
* editableFeatureSource que ya estar? creado.
|
114 |
*
|
115 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
116 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
117 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
118 |
*/
|
119 |
public void addPoint(double x, double y,InputEvent event) { |
120 |
RectangleCADToolState actualState = (RectangleCADToolState) _fsm.getPreviousState(); |
121 |
|
122 |
String status = actualState.getName();
|
123 |
|
124 |
if (status.equals("Rectangle.FirstPoint")) { |
125 |
firstPoint = new Point2D.Double(x, y); |
126 |
} else if (status == "Rectangle.SecondPointOrSquare") { |
127 |
lastPoint = new Point2D.Double(x, y); |
128 |
|
129 |
GeneralPathX elShape = new GeneralPathX();
|
130 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
131 |
elShape.lineTo(lastPoint.getX(), firstPoint.getY()); |
132 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
133 |
elShape.lineTo(firstPoint.getX(), lastPoint.getY()); |
134 |
//elShape.lineTo(firstPoint.getX(), firstPoint.getY());
|
135 |
elShape.closePath(); |
136 |
int type=getCadToolAdapter().getActiveLayerType();
|
137 |
if (type==Geometry.TYPES.SURFACE){
|
138 |
insertAndSelectGeometry(createSurface(elShape)); |
139 |
}else{
|
140 |
insertAndSelectGeometry(createCurve(elShape)); |
141 |
} |
142 |
firstPoint = (Point2D) lastPoint.clone();
|
143 |
} else if (status == "Rectangle.SecondPointSquare") { |
144 |
lastPoint = new Point2D.Double(x, y); |
145 |
|
146 |
GeneralPathX elShape = new GeneralPathX();
|
147 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
148 |
elShape.lineTo(lastPoint.getX(), firstPoint.getY()); |
149 |
|
150 |
if (((lastPoint.getY() <= firstPoint.getY()) &&
|
151 |
(lastPoint.getX() <= firstPoint.getX())) || |
152 |
((lastPoint.getY() > firstPoint.getY()) && |
153 |
(lastPoint.getX() > firstPoint.getX()))) { |
154 |
elShape.lineTo(lastPoint.getX(), |
155 |
firstPoint.getY() + (lastPoint.getX() - firstPoint.getX())); |
156 |
elShape.lineTo(firstPoint.getX(), |
157 |
firstPoint.getY() + (lastPoint.getX() - firstPoint.getX())); |
158 |
} else {
|
159 |
elShape.lineTo(lastPoint.getX(), |
160 |
firstPoint.getY() - (lastPoint.getX() - firstPoint.getX())); |
161 |
elShape.lineTo(firstPoint.getX(), |
162 |
firstPoint.getY() - (lastPoint.getX() - firstPoint.getX())); |
163 |
} |
164 |
|
165 |
//elShape.lineTo(firstPoint.getX(), firstPoint.getY());
|
166 |
elShape.closePath(); |
167 |
int type=getCadToolAdapter().getActiveLayerType();
|
168 |
if (type==Geometry.TYPES.SURFACE){
|
169 |
insertAndSelectGeometry(createSurface(elShape)); |
170 |
}else{
|
171 |
insertAndSelectGeometry(createCurve(elShape)); |
172 |
} |
173 |
firstPoint = (Point2D) lastPoint.clone();
|
174 |
} |
175 |
} |
176 |
|
177 |
/**
|
178 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
179 |
* encontremos.
|
180 |
*
|
181 |
* @param g Graphics sobre el que dibujar.
|
182 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
183 |
* @param x par?metro x del punto que se pase para dibujar.
|
184 |
* @param y par?metro x del punto que se pase para dibujar.
|
185 |
*/
|
186 |
public void drawOperation(MapControlDrawer renderer, double x, |
187 |
double y) {
|
188 |
RectangleCADToolState actualState = _fsm.getState(); |
189 |
String status = actualState.getName();
|
190 |
|
191 |
if (status == "Rectangle.SecondPointOrSquare") { |
192 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
193 |
4);
|
194 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
195 |
elShape.lineTo(x, firstPoint.getY()); |
196 |
elShape.lineTo(x, y); |
197 |
elShape.lineTo(firstPoint.getX(), y); |
198 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
199 |
|
200 |
renderer.draw(createCurve(elShape), mapControlManager.getGeometrySelectionSymbol()); |
201 |
} else if (status == "Rectangle.SecondPointSquare") { |
202 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
203 |
4);
|
204 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
205 |
elShape.lineTo(x, firstPoint.getY()); |
206 |
|
207 |
if (((y <= firstPoint.getY()) && (x <= firstPoint.getX())) ||
|
208 |
((y > firstPoint.getY()) && (x > firstPoint.getX()))) { |
209 |
elShape.lineTo(x, firstPoint.getY() + (x - firstPoint.getX())); |
210 |
elShape.lineTo(firstPoint.getX(), |
211 |
firstPoint.getY() + (x - firstPoint.getX())); |
212 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
213 |
} else {
|
214 |
elShape.lineTo(x, firstPoint.getY() - (x - firstPoint.getX())); |
215 |
elShape.lineTo(firstPoint.getX(), |
216 |
firstPoint.getY() - (x - firstPoint.getX())); |
217 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
218 |
} |
219 |
renderer.draw(createCurve(elShape), mapControlManager.getGeometrySelectionSymbol()); |
220 |
} |
221 |
} |
222 |
|
223 |
/**
|
224 |
* Add a diferent option.
|
225 |
*
|
226 |
* @param sel DOCUMENT ME!
|
227 |
* @param s Diferent option.
|
228 |
*/
|
229 |
public void addOption(String s) { |
230 |
RectangleCADToolState actualState = (RectangleCADToolState) _fsm.getPreviousState(); |
231 |
String status = actualState.getName();
|
232 |
|
233 |
if (status == "Rectangle.SecondPointOrSquare") { |
234 |
if (s.equalsIgnoreCase(PluginServices.getText(this,"RectangleCADTool.square"))) { |
235 |
//Opci?n correcta
|
236 |
} |
237 |
} |
238 |
} |
239 |
|
240 |
/* (non-Javadoc)
|
241 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
242 |
*/
|
243 |
public void addValue(double d) { |
244 |
} |
245 |
|
246 |
public String getName() { |
247 |
return PluginServices.getText(this,"rectangle_"); |
248 |
} |
249 |
|
250 |
public String toString() { |
251 |
return "_rectangle"; |
252 |
} |
253 |
public boolean isApplicable(int shapeType) { |
254 |
switch (shapeType) {
|
255 |
case Geometry.TYPES.POINT:
|
256 |
case Geometry.TYPES.MULTIPOINT:
|
257 |
return false; |
258 |
} |
259 |
return true; |
260 |
} |
261 |
} |