Revision 37138 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/CircleCADTool.java
CircleCADTool.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
|
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
|
2 | 2 |
* |
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
5 | 6 |
* This program is free software; you can redistribute it and/or |
6 | 7 |
* modify it under the terms of the GNU General Public License |
7 | 8 |
* as published by the Free Software Foundation; either version 2 |
8 | 9 |
* of the License, or (at your option) any later version. |
9 |
* |
|
10 |
*
|
|
10 | 11 |
* This program is distributed in the hope that it will be useful, |
11 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | 14 |
* GNU General Public License for more details. |
14 |
* |
|
15 |
*
|
|
15 | 16 |
* You should have received a copy of the GNU General Public License |
16 | 17 |
* 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 |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
40 | 21 |
*/ |
41 | 22 |
package org.gvsig.editing.gui.cad.tools; |
42 | 23 |
|
... | ... | |
53 | 34 |
import org.gvsig.fmap.geom.primitive.Circle; |
54 | 35 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
55 | 36 |
|
56 |
|
|
57 |
|
|
58 | 37 |
/** |
59 | 38 |
* DOCUMENT ME! |
60 |
* |
|
39 |
*
|
|
61 | 40 |
* @author Vicente Caballero Navarro |
62 | 41 |
*/ |
63 | 42 |
public class CircleCADTool extends DefaultCADTool { |
43 |
|
|
64 | 44 |
protected CircleCADToolContext _fsm; |
65 | 45 |
protected Point2D center; |
66 | 46 |
protected Point2D firstPoint; |
... | ... | |
81 | 61 |
_fsm = new CircleCADToolContext(this); |
82 | 62 |
} |
83 | 63 |
|
84 |
/* (non-Javadoc) |
|
85 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double) |
|
64 |
/* |
|
65 |
* (non-Javadoc) |
|
66 |
* |
|
67 |
* @see |
|
68 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
69 |
* .layers.FBitSet, double, double) |
|
86 | 70 |
*/ |
87 |
public void transition(double x, double y, InputEvent event){ |
|
71 |
public void transition(double x, double y, InputEvent event) {
|
|
88 | 72 |
_fsm.addPoint(x, y, event); |
89 | 73 |
} |
90 | 74 |
|
91 |
/* (non-Javadoc) |
|
92 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double) |
|
75 |
/* |
|
76 |
* (non-Javadoc) |
|
77 |
* |
|
78 |
* @see |
|
79 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
80 |
* .layers.FBitSet, double) |
|
93 | 81 |
*/ |
94 |
public void transition(double d){ |
|
82 |
public void transition(double d) {
|
|
95 | 83 |
_fsm.addValue(d); |
96 | 84 |
} |
97 | 85 |
|
98 |
/* (non-Javadoc) |
|
99 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String) |
|
86 |
/* |
|
87 |
* (non-Javadoc) |
|
88 |
* |
|
89 |
* @see |
|
90 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
91 |
* .layers.FBitSet, java.lang.String) |
|
100 | 92 |
*/ |
101 |
public void transition(String s) throws CommandException{ |
|
102 |
if (!super.changeCommand(s)){
|
|
103 |
_fsm.addOption(s);
|
|
104 |
}
|
|
93 |
public void transition(String s) throws CommandException {
|
|
94 |
if (!super.changeCommand(s)) {
|
|
95 |
_fsm.addOption(s);
|
|
96 |
}
|
|
105 | 97 |
} |
106 | 98 |
|
107 | 99 |
/** |
108 | 100 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el |
109 | 101 |
* editableFeatureSource que ya estar? creado. |
110 |
* |
|
111 |
* @param sel Bitset con las geometr?as que est?n seleccionadas. |
|
112 |
* @param x par?metro x del punto que se pase en esta transici?n. |
|
113 |
* @param y par?metro y del punto que se pase en esta transici?n. |
|
102 |
* |
|
103 |
* @param sel |
|
104 |
* Bitset con las geometr?as que est?n seleccionadas. |
|
105 |
* @param x |
|
106 |
* par?metro x del punto que se pase en esta transici?n. |
|
107 |
* @param y |
|
108 |
* par?metro y del punto que se pase en esta transici?n. |
|
114 | 109 |
*/ |
115 |
public void addPoint(double x, double y,InputEvent event) { |
|
116 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
|
110 |
public void addPoint(double x, double y, InputEvent event) { |
|
111 |
CircleCADToolState actualState = |
|
112 |
(CircleCADToolState) _fsm.getPreviousState(); |
|
117 | 113 |
String status = actualState.getName(); |
118 | 114 |
|
119 | 115 |
if (status.equals("Circle.CenterPointOr3p")) { |
120 | 116 |
center = new Point2D.Double(x, y); |
121 |
} else if (status == "Circle.PointOrRadius") { |
|
122 |
insertAndSelectGeometry(createCircle(createPoint(center), |
|
123 |
createPoint(x, y))); |
|
124 |
} else if (status == "Circle.FirstPoint") { |
|
125 |
firstPoint = new Point2D.Double(x, y); |
|
126 |
} else if (status == "Circle.SecondPoint") { |
|
127 |
secondPoint = new Point2D.Double(x, y); |
|
128 |
} else if (status == "Circle.ThirdPoint") { |
|
129 |
thirdPoint = new Point2D.Double(x, y); |
|
130 |
insertAndSelectGeometry(createCircle(createPoint(firstPoint), |
|
131 |
createPoint(secondPoint), |
|
132 |
createPoint(thirdPoint))); |
|
133 |
} |
|
117 |
} else |
|
118 |
if (status == "Circle.PointOrRadius") { |
|
119 |
insertAndSelectGeometry(createCircle(createPoint(center), |
|
120 |
createPoint(x, y))); |
|
121 |
} else |
|
122 |
if (status == "Circle.FirstPoint") { |
|
123 |
firstPoint = new Point2D.Double(x, y); |
|
124 |
} else |
|
125 |
if (status == "Circle.SecondPoint") { |
|
126 |
secondPoint = new Point2D.Double(x, y); |
|
127 |
} else |
|
128 |
if (status == "Circle.ThirdPoint") { |
|
129 |
thirdPoint = new Point2D.Double(x, y); |
|
130 |
insertAndSelectGeometry(createCircle( |
|
131 |
createPoint(firstPoint), |
|
132 |
createPoint(secondPoint), |
|
133 |
createPoint(thirdPoint))); |
|
134 |
} |
|
134 | 135 |
} |
135 | 136 |
|
136 | 137 |
/** |
137 | 138 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
138 | 139 |
* encontremos. |
139 |
* |
|
140 |
* @param g Graphics sobre el que dibujar. |
|
141 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas. |
|
142 |
* @param x par?metro x del punto que se pase para dibujar. |
|
143 |
* @param y par?metro x del punto que se pase para dibujar. |
|
140 |
* |
|
141 |
* @param g |
|
142 |
* Graphics sobre el que dibujar. |
|
143 |
* @param selectedGeometries |
|
144 |
* BitSet con las geometr?as seleccionadas. |
|
145 |
* @param x |
|
146 |
* par?metro x del punto que se pase para dibujar. |
|
147 |
* @param y |
|
148 |
* par?metro x del punto que se pase para dibujar. |
|
144 | 149 |
*/ |
145 |
public void drawOperation(MapControlDrawer renderer,double x, |
|
146 |
double y) { |
|
150 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
|
147 | 151 |
CircleCADToolState actualState = _fsm.getState(); |
148 | 152 |
String status = actualState.getName(); |
149 | 153 |
|
150 | 154 |
if ((status == "Circle.CenterPointOr3p")) { // || (status == "5")) { |
151 | 155 |
|
152 | 156 |
if (firstPoint != null) { |
153 |
renderer.drawLine(firstPoint, new Point2D.Double(x, y), mapControlManager.getGeometrySelectionSymbol()); |
|
157 |
renderer.drawLine(firstPoint, new Point2D.Double(x, y), |
|
158 |
mapControlManager.getGeometrySelectionSymbol()); |
|
154 | 159 |
} |
155 | 160 |
} |
156 | 161 |
|
157 | 162 |
if (status == "Circle.PointOrRadius") { |
158 | 163 |
Point2D currentPoint = new Point2D.Double(x, y); |
159 |
DrawOperationContext doc=new DrawOperationContext(); |
|
160 |
Circle circle = createCircle(createPoint(center), createPoint(currentPoint)); |
|
161 |
renderer.draw(circle, mapControlManager.getAxisReferenceSymbol()); |
|
162 |
} else if (status == "Circle.SecondPoint") { |
|
163 |
renderer.drawLine(firstPoint, new Point2D.Double(x, y), mapControlManager.getGeometrySelectionSymbol()); |
|
164 |
} else if (status == "Circle.ThirdPoint") { |
|
165 |
Point2D currentPoint = new Point2D.Double(x, y); |
|
166 |
Geometry geom = createCircle(createPoint(firstPoint), |
|
167 |
createPoint(secondPoint), |
|
168 |
createPoint(currentPoint)); |
|
164 |
DrawOperationContext doc = new DrawOperationContext(); |
|
165 |
Circle circle = |
|
166 |
createCircle(createPoint(center), createPoint(currentPoint)); |
|
167 |
renderer.draw(circle, mapControlManager.getAxisReferenceSymbol()); |
|
168 |
} else |
|
169 |
if (status == "Circle.SecondPoint") { |
|
170 |
renderer.drawLine(firstPoint, new Point2D.Double(x, y), |
|
171 |
mapControlManager.getGeometrySelectionSymbol()); |
|
172 |
} else |
|
173 |
if (status == "Circle.ThirdPoint") { |
|
174 |
Point2D currentPoint = new Point2D.Double(x, y); |
|
175 |
Geometry geom = |
|
176 |
createCircle(createPoint(firstPoint), |
|
177 |
createPoint(secondPoint), createPoint(currentPoint)); |
|
169 | 178 |
|
170 |
if (geom != null) { |
|
171 |
renderer.draw(geom, mapControlManager.getAxisReferenceSymbol()); |
|
172 |
} |
|
173 |
} |
|
179 |
if (geom != null) { |
|
180 |
renderer.draw(geom, |
|
181 |
mapControlManager.getAxisReferenceSymbol()); |
|
182 |
} |
|
183 |
} |
|
174 | 184 |
} |
175 | 185 |
|
176 | 186 |
/** |
177 | 187 |
* Add a diferent option. |
178 |
* |
|
179 |
* @param sel DOCUMENT ME! |
|
180 |
* @param s Diferent option. |
|
188 |
* |
|
189 |
* @param sel |
|
190 |
* DOCUMENT ME! |
|
191 |
* @param s |
|
192 |
* Diferent option. |
|
181 | 193 |
*/ |
182 | 194 |
public void addOption(String s) { |
183 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
|
195 |
CircleCADToolState actualState = |
|
196 |
(CircleCADToolState) _fsm.getPreviousState(); |
|
184 | 197 |
String status = actualState.getName(); |
185 | 198 |
|
186 | 199 |
if (status == "Circle.CenterPointOr3p") { |
187 |
if (s.equalsIgnoreCase(PluginServices.getText(this,"CircleCADTool.3p"))) { |
|
188 |
//Opci?n correcta. |
|
200 |
if (s.equalsIgnoreCase(PluginServices.getText(this, |
|
201 |
"CircleCADTool.3p"))) { |
|
202 |
// Opci?n correcta. |
|
189 | 203 |
} |
190 | 204 |
} |
191 | 205 |
} |
192 | 206 |
|
193 |
/* (non-Javadoc) |
|
207 |
/* |
|
208 |
* (non-Javadoc) |
|
209 |
* |
|
194 | 210 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
195 | 211 |
*/ |
196 | 212 |
public void addValue(double d) { |
197 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
|
213 |
CircleCADToolState actualState = |
|
214 |
(CircleCADToolState) _fsm.getPreviousState(); |
|
198 | 215 |
String status = actualState.getName(); |
199 | 216 |
|
200 | 217 |
if (status == "Circle.PointOrRadius") { |
201 |
insertAndSelectGeometry(createCircle(createPoint(center), d));
|
|
218 |
insertAndSelectGeometry(createCircle(createPoint(center), d));
|
|
202 | 219 |
} |
203 | 220 |
} |
204 | 221 |
|
205 |
public String getName() {
|
|
206 |
return PluginServices.getText(this,"circle_");
|
|
207 |
}
|
|
222 |
public String getName() {
|
|
223 |
return PluginServices.getText(this, "circle_");
|
|
224 |
}
|
|
208 | 225 |
|
209 |
public String toString() {
|
|
210 |
return "_circle";
|
|
211 |
}
|
|
226 |
public String toString() {
|
|
227 |
return "_circle";
|
|
228 |
}
|
|
212 | 229 |
|
213 |
public boolean isApplicable(int shapeType) {
|
|
214 |
switch (shapeType) {
|
|
215 |
case Geometry.TYPES.POINT:
|
|
216 |
case Geometry.TYPES.MULTIPOINT:
|
|
217 |
return false;
|
|
218 |
}
|
|
219 |
return true;
|
|
220 |
}
|
|
230 |
public boolean isApplicable(int shapeType) {
|
|
231 |
switch (shapeType) {
|
|
232 |
case Geometry.TYPES.POINT:
|
|
233 |
case Geometry.TYPES.MULTIPOINT:
|
|
234 |
return false;
|
|
235 |
}
|
|
236 |
return true;
|
|
237 |
}
|
|
221 | 238 |
|
222 | 239 |
} |
Also available in: Unified diff