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