root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / LineCADTool.java @ 29616
History | View | Annotate | Download (7.59 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.LineCADToolContext; |
53 |
import org.gvsig.editing.gui.cad.tools.smc.LineCADToolContext.LineCADToolState; |
54 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
55 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
57 |
|
58 |
|
59 |
|
60 |
/**
|
61 |
* DOCUMENT ME!
|
62 |
*
|
63 |
* @author Vicente Caballero Navarro
|
64 |
*/
|
65 |
public class LineCADTool extends DefaultCADTool { |
66 |
protected LineCADToolContext _fsm;
|
67 |
protected Point2D firstPoint; |
68 |
protected Point2D lastPoint; |
69 |
protected double angle; |
70 |
protected double length; |
71 |
|
72 |
/**
|
73 |
* Crea un nuevo LineCADTool.
|
74 |
*/
|
75 |
public LineCADTool() {
|
76 |
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
81 |
* carga previa a la utilizaci?n de la herramienta.
|
82 |
*/
|
83 |
public void init() { |
84 |
_fsm = new LineCADToolContext(this); |
85 |
} |
86 |
|
87 |
/* (non-Javadoc)
|
88 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
89 |
*/
|
90 |
public void transition(double x, double y, InputEvent event) { |
91 |
_fsm.addPoint(x, y, event); |
92 |
} |
93 |
|
94 |
/* (non-Javadoc)
|
95 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
96 |
*/
|
97 |
public void transition(double d) { |
98 |
_fsm.addValue(d); |
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
103 |
*/
|
104 |
public void transition(String s) throws CommandException { |
105 |
if (!super.changeCommand(s)){ |
106 |
_fsm.addOption(s); |
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
112 |
* editableFeatureSource que ya estar? creado.
|
113 |
*
|
114 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
115 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
116 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
117 |
*/
|
118 |
public void addPoint(double x, double y,InputEvent event) { |
119 |
LineCADToolState actualState = (LineCADToolState) _fsm.getPreviousState(); |
120 |
String status = actualState.getName();
|
121 |
|
122 |
if (status.equals("Line.FirstPoint")) { |
123 |
firstPoint = new Point2D.Double(x, y); |
124 |
} else if (status == "Line.SecondPointOrAngle") { |
125 |
lastPoint = new Point2D.Double(x, y); |
126 |
|
127 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
128 |
2);
|
129 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
130 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
131 |
insertAndSelectGeometry(createCurve(elShape)); |
132 |
firstPoint = (Point2D) lastPoint.clone();
|
133 |
} else if (status == "Line.LenghtOrPoint") { |
134 |
length = firstPoint.distance(x, y); |
135 |
|
136 |
double w = (Math.cos(Math.toRadians(angle))) * length; |
137 |
double h = (Math.sin(Math.toRadians(angle))) * length; |
138 |
lastPoint = new Point2D.Double(firstPoint.getX() + w, |
139 |
firstPoint.getY() + h); |
140 |
|
141 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
142 |
2);
|
143 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
144 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
145 |
insertAndSelectGeometry(createCurve(elShape)); |
146 |
|
147 |
firstPoint = (Point2D) lastPoint.clone();
|
148 |
} |
149 |
} |
150 |
|
151 |
/**
|
152 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
153 |
* encontremos.
|
154 |
*
|
155 |
* @param g Graphics sobre el que dibujar.
|
156 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
157 |
* @param x par?metro x del punto que se pase para dibujar.
|
158 |
* @param y par?metro x del punto que se pase para dibujar.
|
159 |
*/
|
160 |
public void drawOperation(Graphics g,double x, |
161 |
double y) {
|
162 |
LineCADToolState actualState = _fsm.getState(); |
163 |
String status = actualState.getName();
|
164 |
|
165 |
if ((status != "Line.FirstPoint")) { // || (status == "5")) { |
166 |
|
167 |
if (firstPoint != null) { |
168 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y),DefaultCADTool.geometrySelectSymbol); |
169 |
} |
170 |
}else{
|
171 |
VectorialLayerEdited vle=getVLE(); |
172 |
if (!vle.getLayer().isVisible())
|
173 |
return;
|
174 |
try{
|
175 |
Image imgSel = vle.getSelectionImage();
|
176 |
if (imgSel!=null) |
177 |
g.drawImage(imgSel, 0, 0, null); |
178 |
Image imgHand = vle.getHandlersImage();
|
179 |
if (imgHand!=null) |
180 |
g.drawImage(imgHand, 0, 0, null); |
181 |
}catch (Exception e) { |
182 |
} |
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* Add a diferent option.
|
188 |
*
|
189 |
* @param sel DOCUMENT ME!
|
190 |
* @param s Diferent option.
|
191 |
*/
|
192 |
public void addOption(String s) { |
193 |
// TODO Auto-generated method stub
|
194 |
} |
195 |
|
196 |
/* (non-Javadoc)
|
197 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
198 |
*/
|
199 |
public void addValue(double d) { |
200 |
LineCADToolState actualState = (LineCADToolState) _fsm.getPreviousState(); |
201 |
String status = actualState.getName();
|
202 |
|
203 |
if (status == "Line.SecondPointOrAngle") { |
204 |
angle = d; |
205 |
} else if (status == "Line.LenghtOrPoint") { |
206 |
length = d; |
207 |
|
208 |
double w = Math.cos(Math.toRadians(angle)) * length; |
209 |
double h = Math.sin(Math.toRadians(angle)) * length; |
210 |
lastPoint = new Point2D.Double(firstPoint.getX() + w, |
211 |
firstPoint.getY() + h); |
212 |
|
213 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
214 |
2);
|
215 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
216 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
217 |
insertAndSelectGeometry(createCurve(elShape)); |
218 |
firstPoint = (Point2D) lastPoint.clone();
|
219 |
} |
220 |
} |
221 |
|
222 |
public String getName() { |
223 |
return PluginServices.getText(this,"line_"); |
224 |
} |
225 |
|
226 |
public String toString() { |
227 |
return "_line"; |
228 |
} |
229 |
public boolean isApplicable(int shapeType) { |
230 |
switch (shapeType) {
|
231 |
case Geometry.TYPES.POINT:
|
232 |
case Geometry.TYPES.SURFACE:
|
233 |
case Geometry.TYPES.MULTIPOINT:
|
234 |
return false; |
235 |
} |
236 |
return true; |
237 |
} |
238 |
} |