svn-gvsig-desktop / tags / v1_1_Build_1001 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / LineCADTool.java @ 11984
History | View | Annotate | Download (7.14 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.GeneralPathX; |
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.LineCADToolContext; |
55 |
import com.iver.cit.gvsig.gui.cad.tools.smc.LineCADToolContext.LineCADToolState; |
56 |
|
57 |
|
58 |
/**
|
59 |
* DOCUMENT ME!
|
60 |
*
|
61 |
* @author Vicente Caballero Navarro
|
62 |
*/
|
63 |
public class LineCADTool extends DefaultCADTool { |
64 |
private LineCADToolContext _fsm;
|
65 |
private Point2D firstPoint; |
66 |
private Point2D lastPoint; |
67 |
private double angle; |
68 |
private double length; |
69 |
|
70 |
/**
|
71 |
* Crea un nuevo LineCADTool.
|
72 |
*/
|
73 |
public LineCADTool() {
|
74 |
|
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 LineCADToolContext(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 |
LineCADToolState actualState = (LineCADToolState) _fsm.getPreviousState(); |
118 |
String status = actualState.getName();
|
119 |
|
120 |
if (status.equals("Line.FirstPoint")) { |
121 |
firstPoint = new Point2D.Double(x, y); |
122 |
} else if (status == "Line.SecondPointOrAngle") { |
123 |
lastPoint = new Point2D.Double(x, y); |
124 |
|
125 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
126 |
2);
|
127 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
128 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
129 |
addGeometry(ShapeFactory.createPolyline2D(elShape)); |
130 |
firstPoint = (Point2D) lastPoint.clone();
|
131 |
} else if (status == "Line.LenghtOrPoint") { |
132 |
length = firstPoint.distance(x, y); |
133 |
|
134 |
double w = (Math.cos(Math.toRadians(angle))) * length; |
135 |
double h = (Math.sin(Math.toRadians(angle))) * length; |
136 |
lastPoint = new Point2D.Double(firstPoint.getX() + w, |
137 |
firstPoint.getY() + h); |
138 |
|
139 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
140 |
2);
|
141 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
142 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
143 |
addGeometry(ShapeFactory.createPolyline2D(elShape)); |
144 |
|
145 |
firstPoint = (Point2D) lastPoint.clone();
|
146 |
} |
147 |
} |
148 |
|
149 |
/**
|
150 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
151 |
* encontremos.
|
152 |
*
|
153 |
* @param g Graphics sobre el que dibujar.
|
154 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
155 |
* @param x par?metro x del punto que se pase para dibujar.
|
156 |
* @param y par?metro x del punto que se pase para dibujar.
|
157 |
*/
|
158 |
public void drawOperation(Graphics g,double x, |
159 |
double y) {
|
160 |
LineCADToolState actualState = _fsm.getState(); |
161 |
String status = actualState.getName();
|
162 |
|
163 |
if ((status != "Line.FirstPoint")) { // || (status == "5")) { |
164 |
|
165 |
if (firstPoint != null) { |
166 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y),DefaultCADTool.geometrySelectSymbol); |
167 |
} |
168 |
} |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Add a diferent option.
|
173 |
*
|
174 |
* @param sel DOCUMENT ME!
|
175 |
* @param s Diferent option.
|
176 |
*/
|
177 |
public void addOption(String s) { |
178 |
// TODO Auto-generated method stub
|
179 |
} |
180 |
|
181 |
/* (non-Javadoc)
|
182 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
183 |
*/
|
184 |
public void addValue(double d) { |
185 |
LineCADToolState actualState = (LineCADToolState) _fsm.getPreviousState(); |
186 |
String status = actualState.getName();
|
187 |
|
188 |
if (status == "Line.SecondPointOrAngle") { |
189 |
angle = d; |
190 |
} else if (status == "Line.LenghtOrPoint") { |
191 |
length = d; |
192 |
|
193 |
double w = Math.cos(Math.toRadians(angle)) * length; |
194 |
double h = Math.sin(Math.toRadians(angle)) * length; |
195 |
lastPoint = new Point2D.Double(firstPoint.getX() + w, |
196 |
firstPoint.getY() + h); |
197 |
|
198 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
199 |
2);
|
200 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
201 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
202 |
addGeometry(ShapeFactory.createPolyline2D(elShape)); |
203 |
firstPoint = (Point2D) lastPoint.clone();
|
204 |
} |
205 |
} |
206 |
|
207 |
public String getName() { |
208 |
return PluginServices.getText(this,"line_"); |
209 |
} |
210 |
|
211 |
public String toString() { |
212 |
return "_line"; |
213 |
} |
214 |
public boolean isApplicable(int shapeType) { |
215 |
switch (shapeType) {
|
216 |
case FShape.POINT:
|
217 |
case FShape.POLYGON:
|
218 |
case FShape.MULTIPOINT:
|
219 |
return false; |
220 |
} |
221 |
return true; |
222 |
} |
223 |
} |