root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / CircleCADTool.java @ 9243
History | View | Annotate | Download (7.11 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 com.iver.cit.gvsig.gui.cad.tools; |
42 |
|
43 |
import java.awt.Graphics; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.event.InputEvent; |
46 |
import java.awt.geom.Point2D; |
47 |
|
48 |
import com.iver.andami.PluginServices; |
49 |
import com.iver.cit.gvsig.fmap.core.FShape; |
50 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
51 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
52 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
53 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
54 |
import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
55 |
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext; |
56 |
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState; |
57 |
|
58 |
|
59 |
/**
|
60 |
* DOCUMENT ME!
|
61 |
*
|
62 |
* @author Vicente Caballero Navarro
|
63 |
*/
|
64 |
public class CircleCADTool extends DefaultCADTool { |
65 |
private CircleCADToolContext _fsm;
|
66 |
private Point2D center; |
67 |
private Point2D firstPoint; |
68 |
private Point2D secondPoint; |
69 |
private Point2D thirdPoint; |
70 |
|
71 |
/**
|
72 |
* Crea un nuevo LineCADTool.
|
73 |
*/
|
74 |
public CircleCADTool() {
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
79 |
* carga previa a la utilizaci?n de la herramienta.
|
80 |
*/
|
81 |
public void init() { |
82 |
_fsm = new CircleCADToolContext(this); |
83 |
} |
84 |
|
85 |
/* (non-Javadoc)
|
86 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
87 |
*/
|
88 |
public void transition(double x, double y, InputEvent event){ |
89 |
_fsm.addPoint(x, y, event); |
90 |
} |
91 |
|
92 |
/* (non-Javadoc)
|
93 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
94 |
*/
|
95 |
public void transition(double d){ |
96 |
_fsm.addValue(d); |
97 |
} |
98 |
|
99 |
/* (non-Javadoc)
|
100 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
101 |
*/
|
102 |
public void transition(String s) throws CommandException{ |
103 |
if (!super.changeCommand(s)){ |
104 |
_fsm.addOption(s); |
105 |
} |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
110 |
* editableFeatureSource que ya estar? creado.
|
111 |
*
|
112 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
113 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
114 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
115 |
*/
|
116 |
public void addPoint(double x, double y,InputEvent event) { |
117 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
118 |
String status = actualState.getName();
|
119 |
|
120 |
if (status.equals("Circle.CenterPointOr3p")) { |
121 |
center = new Point2D.Double(x, y); |
122 |
} else if (status == "Circle.PointOrRadius") { |
123 |
addGeometry(ShapeFactory.createCircle(center, |
124 |
new Point2D.Double(x, y))); |
125 |
} else if (status == "Circle.FirstPoint") { |
126 |
firstPoint = new Point2D.Double(x, y); |
127 |
} else if (status == "Circle.SecondPoint") { |
128 |
secondPoint = new Point2D.Double(x, y); |
129 |
} else if (status == "Circle.ThirdPoint") { |
130 |
thirdPoint = new Point2D.Double(x, y); |
131 |
addGeometry(ShapeFactory.createCircle(firstPoint, secondPoint, |
132 |
thirdPoint)); |
133 |
} |
134 |
} |
135 |
|
136 |
/**
|
137 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
138 |
* 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.
|
144 |
*/
|
145 |
public void drawOperation(Graphics g,double x, |
146 |
double y) {
|
147 |
CircleCADToolState actualState = _fsm.getState(); |
148 |
String status = actualState.getName();
|
149 |
|
150 |
if ((status == "Circle.CenterPointOr3p")) { // || (status == "5")) { |
151 |
|
152 |
if (firstPoint != null) { |
153 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
154 |
} |
155 |
} |
156 |
|
157 |
if (status == "Circle.PointOrRadius") { |
158 |
Point2D currentPoint = new Point2D.Double(x, y); |
159 |
ShapeFactory.createCircle(center, currentPoint).draw((Graphics2D) g,
|
160 |
getCadToolAdapter().getMapControl().getViewPort(), |
161 |
CADTool.drawingSymbol); |
162 |
} else if (status == "Circle.SecondPoint") { |
163 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
164 |
} else if (status == "Circle.ThirdPoint") { |
165 |
Point2D currentPoint = new Point2D.Double(x, y); |
166 |
IGeometry geom = ShapeFactory.createCircle(firstPoint, secondPoint, |
167 |
currentPoint); |
168 |
|
169 |
if (geom != null) { |
170 |
geom.draw((Graphics2D) g,
|
171 |
getCadToolAdapter().getMapControl().getViewPort(), |
172 |
CADTool.drawingSymbol); |
173 |
} |
174 |
} |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Add a diferent option.
|
179 |
*
|
180 |
* @param sel DOCUMENT ME!
|
181 |
* @param s Diferent option.
|
182 |
*/
|
183 |
public void addOption(String s) { |
184 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
185 |
String status = actualState.getName();
|
186 |
|
187 |
if (status == "Circle.CenterPointOr3p") { |
188 |
if (s.equalsIgnoreCase(PluginServices.getText(this,"CircleCADTool.3p"))) { |
189 |
//Opci?n correcta.
|
190 |
} |
191 |
} |
192 |
} |
193 |
|
194 |
/* (non-Javadoc)
|
195 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
196 |
*/
|
197 |
public void addValue(double d) { |
198 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
199 |
String status = actualState.getName();
|
200 |
|
201 |
if (status == "Circle.PointOrRadius") { |
202 |
addGeometry(ShapeFactory.createCircle(center, d)); |
203 |
} |
204 |
} |
205 |
|
206 |
public String getName() { |
207 |
return PluginServices.getText(this,"circle_"); |
208 |
} |
209 |
|
210 |
public String toString() { |
211 |
return "_circle"; |
212 |
} |
213 |
|
214 |
public boolean isApplicable(int shapeType) { |
215 |
switch (shapeType) {
|
216 |
case FShape.POINT:
|
217 |
case FShape.MULTIPOINT:
|
218 |
return false; |
219 |
} |
220 |
return true; |
221 |
} |
222 |
|
223 |
} |