root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / LineCADTool.java @ 3832
History | View | Annotate | Download (6.64 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.geom.Point2D; |
46 |
|
47 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
48 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
49 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
50 |
import com.iver.cit.gvsig.gui.cad.tools.smc.LineCADToolContext; |
51 |
import com.iver.cit.gvsig.gui.cad.tools.smc.LineCADToolContext.LineCADToolState; |
52 |
|
53 |
|
54 |
/**
|
55 |
* DOCUMENT ME!
|
56 |
*
|
57 |
* @author Vicente Caballero Navarro
|
58 |
*/
|
59 |
public class LineCADTool extends DefaultCADTool { |
60 |
private LineCADToolContext _fsm;
|
61 |
private Point2D firstPoint; |
62 |
private Point2D lastPoint; |
63 |
private double angle; |
64 |
private double length; |
65 |
|
66 |
/**
|
67 |
* Crea un nuevo LineCADTool.
|
68 |
*/
|
69 |
public LineCADTool() {
|
70 |
_fsm = new LineCADToolContext(this); |
71 |
} |
72 |
|
73 |
/**
|
74 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
75 |
* carga previa a la utilizaci?n de la herramienta.
|
76 |
*/
|
77 |
public void init() { |
78 |
} |
79 |
|
80 |
/* (non-Javadoc)
|
81 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#end()
|
82 |
*/
|
83 |
public void end() { |
84 |
} |
85 |
|
86 |
/* (non-Javadoc)
|
87 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
88 |
*/
|
89 |
public void transition(double x, double y) { |
90 |
_fsm.addPoint(x, y); |
91 |
} |
92 |
|
93 |
/* (non-Javadoc)
|
94 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
95 |
*/
|
96 |
public void transition(double d) { |
97 |
_fsm.addValue(d); |
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
102 |
*/
|
103 |
public void transition(String s) { |
104 |
//_fsm.addOption(sel,s);
|
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) { |
116 |
LineCADToolState actualState = (LineCADToolState) _fsm.getPreviousState(); |
117 |
String status = actualState.getName();
|
118 |
|
119 |
if (status.equals("ExecuteMap.Initial")) { |
120 |
firstPoint = new Point2D.Double(x, y); |
121 |
} else if (status == "ExecuteMap.First") { |
122 |
lastPoint = new Point2D.Double(x, y); |
123 |
|
124 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
125 |
2);
|
126 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
127 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
128 |
addGeometry(ShapeFactory.createPolyline2D(elShape)); |
129 |
firstPoint = (Point2D) lastPoint.clone();
|
130 |
} else if (status == "ExecuteMap.Fourth") { |
131 |
length = firstPoint.distance(x, y); |
132 |
|
133 |
double w = (Math.cos(Math.toRadians(angle))) * length; |
134 |
double h = (Math.sin(Math.toRadians(angle))) * length; |
135 |
lastPoint = new Point2D.Double(firstPoint.getX() + w, |
136 |
firstPoint.getY() + h); |
137 |
|
138 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
139 |
2);
|
140 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
141 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
142 |
addGeometry(ShapeFactory.createPolyline2D(elShape)); |
143 |
|
144 |
firstPoint = (Point2D) lastPoint.clone();
|
145 |
} |
146 |
} |
147 |
|
148 |
/**
|
149 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
150 |
* encontremos.
|
151 |
*
|
152 |
* @param g Graphics sobre el que dibujar.
|
153 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
154 |
* @param x par?metro x del punto que se pase para dibujar.
|
155 |
* @param y par?metro x del punto que se pase para dibujar.
|
156 |
*/
|
157 |
public void drawOperation(Graphics g,double x, |
158 |
double y) {
|
159 |
LineCADToolState actualState = _fsm.getState(); |
160 |
String status = actualState.getName();
|
161 |
|
162 |
if ((status != "ExecuteMap.Initial")) { // || (status == "5")) { |
163 |
|
164 |
if (firstPoint != null) { |
165 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
166 |
} |
167 |
} |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Add a diferent option.
|
172 |
*
|
173 |
* @param sel DOCUMENT ME!
|
174 |
* @param s Diferent option.
|
175 |
*/
|
176 |
public void addOption(String s) { |
177 |
// TODO Auto-generated method stub
|
178 |
} |
179 |
|
180 |
/* (non-Javadoc)
|
181 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
182 |
*/
|
183 |
public void addValue(double d) { |
184 |
LineCADToolState actualState = (LineCADToolState) _fsm.getPreviousState(); |
185 |
String status = actualState.getName();
|
186 |
|
187 |
if (status == "ExecuteMap.Second") { |
188 |
angle = d; |
189 |
} else if (status == "ExecuteMap.Third") { |
190 |
length = d; |
191 |
|
192 |
double w = Math.cos(Math.toRadians(angle)) * length; |
193 |
double h = Math.sin(Math.toRadians(angle)) * length; |
194 |
lastPoint = new Point2D.Double(firstPoint.getX() + w, |
195 |
firstPoint.getY() + h); |
196 |
|
197 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
198 |
2);
|
199 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
200 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
201 |
addGeometry(ShapeFactory.createPolyline2D(elShape)); |
202 |
firstPoint = (Point2D) lastPoint.clone();
|
203 |
} |
204 |
} |
205 |
} |