root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / CircleCADTool.java @ 29973
History | View | Annotate | Download (8.46 KB)
1 |
/* 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 |
package org.gvsig.editing.gui.cad.tools; |
42 |
|
43 |
import java.awt.Graphics; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Image; |
46 |
import java.awt.event.InputEvent; |
47 |
import java.awt.geom.Point2D; |
48 |
|
49 |
import org.gvsig.andami.PluginServices; |
50 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
51 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
52 |
import org.gvsig.editing.gui.cad.tools.smc.CircleCADToolContext; |
53 |
import org.gvsig.editing.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState; |
54 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
55 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.geom.operation.Draw; |
57 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
58 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
59 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
60 |
|
61 |
|
62 |
|
63 |
/**
|
64 |
* DOCUMENT ME!
|
65 |
*
|
66 |
* @author Vicente Caballero Navarro
|
67 |
*/
|
68 |
public class CircleCADTool extends DefaultCADTool { |
69 |
protected CircleCADToolContext _fsm;
|
70 |
protected Point2D center; |
71 |
protected Point2D firstPoint; |
72 |
protected Point2D secondPoint; |
73 |
protected Point2D thirdPoint; |
74 |
|
75 |
/**
|
76 |
* Crea un nuevo LineCADTool.
|
77 |
*/
|
78 |
public CircleCADTool() {
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
83 |
* carga previa a la utilizaci?n de la herramienta.
|
84 |
*/
|
85 |
public void init() { |
86 |
_fsm = new CircleCADToolContext(this); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
91 |
*/
|
92 |
public void transition(double x, double y, InputEvent event){ |
93 |
_fsm.addPoint(x, y, event); |
94 |
} |
95 |
|
96 |
/* (non-Javadoc)
|
97 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
98 |
*/
|
99 |
public void transition(double d){ |
100 |
_fsm.addValue(d); |
101 |
} |
102 |
|
103 |
/* (non-Javadoc)
|
104 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
105 |
*/
|
106 |
public void transition(String s) throws CommandException{ |
107 |
if (!super.changeCommand(s)){ |
108 |
_fsm.addOption(s); |
109 |
} |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
114 |
* editableFeatureSource que ya estar? creado.
|
115 |
*
|
116 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
117 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
118 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
119 |
*/
|
120 |
public void addPoint(double x, double y,InputEvent event) { |
121 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
122 |
String status = actualState.getName();
|
123 |
|
124 |
if (status.equals("Circle.CenterPointOr3p")) { |
125 |
center = new Point2D.Double(x, y); |
126 |
} else if (status == "Circle.PointOrRadius") { |
127 |
insertAndSelectGeometry(createCircle(createPoint(center), |
128 |
createPoint(x, y))); |
129 |
} else if (status == "Circle.FirstPoint") { |
130 |
firstPoint = new Point2D.Double(x, y); |
131 |
} else if (status == "Circle.SecondPoint") { |
132 |
secondPoint = new Point2D.Double(x, y); |
133 |
} else if (status == "Circle.ThirdPoint") { |
134 |
thirdPoint = new Point2D.Double(x, y); |
135 |
insertAndSelectGeometry(createCircle(createPoint(firstPoint), |
136 |
createPoint(secondPoint), |
137 |
createPoint(thirdPoint))); |
138 |
} |
139 |
} |
140 |
|
141 |
/**
|
142 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
143 |
* encontremos.
|
144 |
*
|
145 |
* @param g Graphics sobre el que dibujar.
|
146 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
147 |
* @param x par?metro x del punto que se pase para dibujar.
|
148 |
* @param y par?metro x del punto que se pase para dibujar.
|
149 |
*/
|
150 |
public void drawOperation(Graphics g,double x, |
151 |
double y) {
|
152 |
CircleCADToolState actualState = _fsm.getState(); |
153 |
String status = actualState.getName();
|
154 |
|
155 |
if ((status == "Circle.CenterPointOr3p")) { // || (status == "5")) { |
156 |
|
157 |
if (firstPoint != null) { |
158 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y),DefaultCADTool.geometrySelectSymbol); |
159 |
} |
160 |
} |
161 |
|
162 |
if (status == "Circle.PointOrRadius") { |
163 |
Point2D currentPoint = new Point2D.Double(x, y); |
164 |
DrawOperationContext doc=new DrawOperationContext();
|
165 |
doc.setGraphics((Graphics2D)g);
|
166 |
doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
167 |
doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
168 |
try {
|
169 |
createCircle(createPoint(center), createPoint(currentPoint)).invokeOperation(Draw.CODE,doc); |
170 |
} catch (GeometryOperationNotSupportedException e) {
|
171 |
e.printStackTrace(); |
172 |
} catch (GeometryOperationException e) {
|
173 |
e.printStackTrace(); |
174 |
} |
175 |
} else if (status == "Circle.SecondPoint") { |
176 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y),DefaultCADTool.geometrySelectSymbol); |
177 |
} else if (status == "Circle.ThirdPoint") { |
178 |
Point2D currentPoint = new Point2D.Double(x, y); |
179 |
Geometry geom = createCircle(createPoint(firstPoint), |
180 |
createPoint(secondPoint), |
181 |
createPoint(currentPoint)); |
182 |
|
183 |
if (geom != null) { |
184 |
DrawOperationContext doc=new DrawOperationContext();
|
185 |
doc.setGraphics((Graphics2D)g);
|
186 |
doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
187 |
doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
188 |
try {
|
189 |
geom.invokeOperation(Draw.CODE,doc); |
190 |
} catch (GeometryOperationNotSupportedException e) {
|
191 |
e.printStackTrace(); |
192 |
} catch (GeometryOperationException e) {
|
193 |
e.printStackTrace(); |
194 |
} |
195 |
} |
196 |
}else{
|
197 |
VectorialLayerEdited vle=getVLE(); |
198 |
if (!vle.getLayer().isVisible())
|
199 |
return;
|
200 |
try{
|
201 |
Image imgSel = vle.getSelectionImage();
|
202 |
if (imgSel!=null) |
203 |
g.drawImage(imgSel, 0, 0, null); |
204 |
Image imgHand = vle.getHandlersImage();
|
205 |
if (imgHand!=null) |
206 |
g.drawImage(imgHand, 0, 0, null); |
207 |
}catch (Exception e) { |
208 |
} |
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* Add a diferent option.
|
214 |
*
|
215 |
* @param sel DOCUMENT ME!
|
216 |
* @param s Diferent option.
|
217 |
*/
|
218 |
public void addOption(String s) { |
219 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
220 |
String status = actualState.getName();
|
221 |
|
222 |
if (status == "Circle.CenterPointOr3p") { |
223 |
if (s.equalsIgnoreCase(PluginServices.getText(this,"CircleCADTool.3p"))) { |
224 |
//Opci?n correcta.
|
225 |
} |
226 |
} |
227 |
} |
228 |
|
229 |
/* (non-Javadoc)
|
230 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
231 |
*/
|
232 |
public void addValue(double d) { |
233 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
234 |
String status = actualState.getName();
|
235 |
|
236 |
if (status == "Circle.PointOrRadius") { |
237 |
insertAndSelectGeometry(createCircle(createPoint(center), d)); |
238 |
} |
239 |
} |
240 |
|
241 |
public String getName() { |
242 |
return PluginServices.getText(this,"circle_"); |
243 |
} |
244 |
|
245 |
public String toString() { |
246 |
return "_circle"; |
247 |
} |
248 |
|
249 |
public boolean isApplicable(int shapeType) { |
250 |
switch (shapeType) {
|
251 |
case Geometry.TYPES.POINT:
|
252 |
case Geometry.TYPES.MULTIPOINT:
|
253 |
return false; |
254 |
} |
255 |
return true; |
256 |
} |
257 |
|
258 |
} |