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