svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / RectangleCADTool.java @ 40557
History | View | Annotate | Download (8.92 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing.gui.cad.tools; |
25 |
|
26 |
import java.awt.event.InputEvent; |
27 |
import java.awt.geom.Point2D; |
28 |
|
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
31 |
import org.gvsig.editing.gui.cad.tools.smc.RectangleCADToolContext; |
32 |
import org.gvsig.editing.gui.cad.tools.smc.RectangleCADToolContext.RectangleCADToolState; |
33 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
34 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
35 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
36 |
|
37 |
/**
|
38 |
* DOCUMENT ME!
|
39 |
*
|
40 |
* @author Vicente Caballero Navarro
|
41 |
*/
|
42 |
public class RectangleCADTool extends AbstractCurveSurfaceCADTool { |
43 |
|
44 |
protected RectangleCADToolContext _fsm;
|
45 |
protected Point2D firstPoint; |
46 |
protected Point2D lastPoint; |
47 |
|
48 |
/**
|
49 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
50 |
* carga previa a la utilizaci?n de la herramienta.
|
51 |
*/
|
52 |
public void init() { |
53 |
_fsm = new RectangleCADToolContext(this); |
54 |
} |
55 |
|
56 |
public void transition(double x, double y, InputEvent event) { |
57 |
_fsm.addPoint(x, y, event); |
58 |
} |
59 |
|
60 |
public void transition(double d) { |
61 |
_fsm.addValue(d); |
62 |
} |
63 |
|
64 |
public void transition(String s) throws CommandException { |
65 |
if (!super.changeCommand(s)) { |
66 |
_fsm.addOption(s); |
67 |
} |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
72 |
* editableFeatureSource que ya estar? creado.
|
73 |
*
|
74 |
* @param sel
|
75 |
* Bitset con las geometr?as que est?n seleccionadas.
|
76 |
* @param x
|
77 |
* par?metro x del punto que se pase en esta transici?n.
|
78 |
* @param y
|
79 |
* par?metro y del punto que se pase en esta transici?n.
|
80 |
*/
|
81 |
public void addPoint(double x, double y, InputEvent event) { |
82 |
RectangleCADToolState actualState = |
83 |
(RectangleCADToolState) _fsm.getPreviousState(); |
84 |
|
85 |
String status = actualState.getName();
|
86 |
|
87 |
if (status.equals("Rectangle.FirstPoint")) { |
88 |
firstPoint = new Point2D.Double(x, y); |
89 |
} else
|
90 |
if (status == "Rectangle.SecondPointOrSquare") { |
91 |
lastPoint = new Point2D.Double(x, y); |
92 |
|
93 |
OrientablePrimitive orientablePrimitive = |
94 |
createOrientablePrimitive(); |
95 |
|
96 |
orientablePrimitive.addMoveToVertex(createPoint( |
97 |
firstPoint.getX(), firstPoint.getY())); |
98 |
orientablePrimitive.addVertex(createPoint(lastPoint.getX(), |
99 |
firstPoint.getY())); |
100 |
orientablePrimitive.addVertex(createPoint(lastPoint.getX(), |
101 |
lastPoint.getY())); |
102 |
orientablePrimitive.addVertex(createPoint(firstPoint.getX(), |
103 |
lastPoint.getY())); |
104 |
orientablePrimitive.closePrimitive(); |
105 |
|
106 |
insertAndSelectGeometry(orientablePrimitive); |
107 |
|
108 |
firstPoint = (Point2D) lastPoint.clone();
|
109 |
} else
|
110 |
if (status == "Rectangle.SecondPointSquare") { |
111 |
lastPoint = new Point2D.Double(x, y); |
112 |
|
113 |
OrientablePrimitive orientablePrimitive = |
114 |
createOrientablePrimitive(); |
115 |
|
116 |
orientablePrimitive.addMoveToVertex(createPoint( |
117 |
firstPoint.getX(), firstPoint.getY())); |
118 |
orientablePrimitive.addVertex(createPoint(lastPoint.getX(), |
119 |
firstPoint.getY())); |
120 |
|
121 |
if (((lastPoint.getY() <= firstPoint.getY()) && (lastPoint
|
122 |
.getX() <= firstPoint.getX())) |
123 |
|| ((lastPoint.getY() > firstPoint.getY()) && (lastPoint |
124 |
.getX() > firstPoint.getX()))) { |
125 |
orientablePrimitive.addVertex(createPoint( |
126 |
lastPoint.getX(), |
127 |
firstPoint.getY() |
128 |
+ (lastPoint.getX() - firstPoint.getX()))); |
129 |
orientablePrimitive.addVertex(createPoint( |
130 |
firstPoint.getX(), |
131 |
firstPoint.getY() |
132 |
+ (lastPoint.getX() - firstPoint.getX()))); |
133 |
} else {
|
134 |
orientablePrimitive.addVertex(createPoint( |
135 |
lastPoint.getX(), |
136 |
firstPoint.getY() |
137 |
- (lastPoint.getX() - firstPoint.getX()))); |
138 |
orientablePrimitive.addVertex(createPoint( |
139 |
firstPoint.getX(), |
140 |
firstPoint.getY() |
141 |
- (lastPoint.getX() - firstPoint.getX()))); |
142 |
} |
143 |
orientablePrimitive.closePrimitive(); |
144 |
|
145 |
insertAndSelectGeometry(orientablePrimitive); |
146 |
|
147 |
firstPoint = (Point2D) lastPoint.clone();
|
148 |
} |
149 |
} |
150 |
|
151 |
/**
|
152 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
153 |
* encontremos.
|
154 |
*
|
155 |
* @param g
|
156 |
* Graphics sobre el que dibujar.
|
157 |
* @param selectedGeometries
|
158 |
* BitSet con las geometr?as seleccionadas.
|
159 |
* @param x
|
160 |
* par?metro x del punto que se pase para dibujar.
|
161 |
* @param y
|
162 |
* par?metro x del punto que se pase para dibujar.
|
163 |
*/
|
164 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
165 |
RectangleCADToolState actualState = _fsm.getState(); |
166 |
String status = actualState.getName();
|
167 |
|
168 |
if (status == "Rectangle.SecondPointOrSquare") { |
169 |
GeneralPathX elShape = |
170 |
new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 4); |
171 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
172 |
elShape.lineTo(x, firstPoint.getY()); |
173 |
elShape.lineTo(x, y); |
174 |
elShape.lineTo(firstPoint.getX(), y); |
175 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
176 |
|
177 |
renderer.draw(createCurve(elShape), |
178 |
mapControlManager.getGeometrySelectionSymbol()); |
179 |
} else
|
180 |
if (status == "Rectangle.SecondPointSquare") { |
181 |
GeneralPathX elShape = |
182 |
new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 4); |
183 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
184 |
elShape.lineTo(x, firstPoint.getY()); |
185 |
|
186 |
if (((y <= firstPoint.getY()) && (x <= firstPoint.getX()))
|
187 |
|| ((y > firstPoint.getY()) && (x > firstPoint.getX()))) { |
188 |
elShape.lineTo(x, |
189 |
firstPoint.getY() + (x - firstPoint.getX())); |
190 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY() |
191 |
+ (x - firstPoint.getX())); |
192 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
193 |
} else {
|
194 |
elShape.lineTo(x, |
195 |
firstPoint.getY() - (x - firstPoint.getX())); |
196 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY() |
197 |
- (x - firstPoint.getX())); |
198 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
199 |
} |
200 |
renderer.draw(createCurve(elShape), |
201 |
mapControlManager.getGeometrySelectionSymbol()); |
202 |
} |
203 |
} |
204 |
|
205 |
/**
|
206 |
* Add a diferent option.
|
207 |
*
|
208 |
* @param sel
|
209 |
* DOCUMENT ME!
|
210 |
* @param s
|
211 |
* Diferent option.
|
212 |
*/
|
213 |
public void addOption(String s) { |
214 |
RectangleCADToolState actualState = |
215 |
(RectangleCADToolState) _fsm.getPreviousState(); |
216 |
String status = actualState.getName();
|
217 |
|
218 |
if (status == "Rectangle.SecondPointOrSquare") { |
219 |
if (s.equalsIgnoreCase(PluginServices.getText(this, |
220 |
"RectangleCADTool.square"))) {
|
221 |
// Opci?n correcta
|
222 |
} |
223 |
} |
224 |
} |
225 |
|
226 |
public void addValue(double d) { |
227 |
} |
228 |
|
229 |
public String getName() { |
230 |
return PluginServices.getText(this, "rectangle_"); |
231 |
} |
232 |
|
233 |
public String toString() { |
234 |
return "_rectangle"; |
235 |
} |
236 |
|
237 |
} |