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