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