root / branches / gvSIG_CAD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / LineCadTool.java @ 3513
History | View | Annotate | Download (6.57 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 com.iver.cit.gvsig.fmap.core.GeneralPathX; |
44 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
45 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
46 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
47 |
import com.iver.cit.gvsig.fmap.edition.cad.Status; |
48 |
import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
49 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
50 |
import com.iver.cit.gvsig.gui.cad.automaton.Linea; |
51 |
|
52 |
import com.iver.fsac.Automaton; |
53 |
|
54 |
import java.awt.Graphics; |
55 |
import java.awt.Graphics2D; |
56 |
import java.awt.geom.Point2D; |
57 |
|
58 |
import java.io.IOException; |
59 |
|
60 |
|
61 |
/**
|
62 |
* Herramienta para a?adir una geometr?a de tipo linea.
|
63 |
*
|
64 |
* @author Vicente Caballero Navarro
|
65 |
*/
|
66 |
public class LineCadTool extends AbstractCadTool { |
67 |
private static Status[] STATUS = { |
68 |
new Status("Precise primer punto(x,y):"), |
69 |
new Status("Precise punto siguiente(x,y) o ?ngulo[a]:"), |
70 |
new Status("Precise longitud[l] o punto(x,y):"), null, null, |
71 |
new Status("Precise punto siguiente(x,y) o ?ngulo[a]:"), |
72 |
new Status("Introduzca el ?ngulo:"), |
73 |
new Status("Introduzca la longitud:") |
74 |
}; |
75 |
private Linea lineStatus = new Linea(); |
76 |
private Point2D firstPoint; |
77 |
private Point2D lastPoint; |
78 |
private double angle; |
79 |
private double length; |
80 |
|
81 |
/**
|
82 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
|
83 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
84 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
|
85 |
*/
|
86 |
public int transition(String text, EditableFeatureSource editingSource, |
87 |
FBitSet selectedGeometries, double[] values) { |
88 |
int ret = lineStatus.transition(text);
|
89 |
|
90 |
int status = lineStatus.getStatus();
|
91 |
|
92 |
if (status == 0) { |
93 |
} else if (status == 1) { |
94 |
if ((lineStatus.getPreviousStatus() == 5) || |
95 |
(lineStatus.getPreviousStatus() == 1)) {
|
96 |
lastPoint = new Point2D.Double(values[0], values[1]); |
97 |
|
98 |
try {
|
99 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
100 |
2);
|
101 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
102 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
103 |
editingSource.addGeometry(ShapeFactory.createPolyline2D( |
104 |
elShape)); |
105 |
} catch (DriverIOException e) {
|
106 |
e.printStackTrace(); |
107 |
} catch (IOException e) { |
108 |
e.printStackTrace(); |
109 |
} |
110 |
|
111 |
firstPoint = (Point2D) lastPoint.clone();
|
112 |
} |
113 |
} else if (status == 2) { |
114 |
angle = values[0];
|
115 |
} else if (status == 3) { |
116 |
length = values[0];
|
117 |
|
118 |
double w = Math.cos(Math.toRadians(angle)) * length; |
119 |
double h = Math.sin(Math.toRadians(angle)) * length; |
120 |
lastPoint = new Point2D.Double(firstPoint.getX() + w, |
121 |
firstPoint.getY() + h); |
122 |
|
123 |
try {
|
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 |
editingSource.addGeometry(ShapeFactory.createPolyline2D(elShape)); |
129 |
} catch (DriverIOException e) {
|
130 |
e.printStackTrace(); |
131 |
} catch (IOException e) { |
132 |
e.printStackTrace(); |
133 |
} |
134 |
|
135 |
firstPoint = (Point2D) lastPoint.clone();
|
136 |
ret = ret | lineStatus.transition("end");
|
137 |
} else if (status == 4) { |
138 |
length = firstPoint.distance(values[0], values[1]); |
139 |
|
140 |
double w = (Math.cos(Math.toRadians(angle))) * length; |
141 |
double h = (Math.sin(Math.toRadians(angle))) * length; |
142 |
lastPoint = new Point2D.Double(firstPoint.getX() + w, |
143 |
firstPoint.getY() + h); |
144 |
|
145 |
try {
|
146 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
147 |
2);
|
148 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
149 |
elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
150 |
editingSource.addGeometry(ShapeFactory.createPolyline2D(elShape)); |
151 |
} catch (DriverIOException e) {
|
152 |
e.printStackTrace(); |
153 |
} catch (IOException e) { |
154 |
e.printStackTrace(); |
155 |
} |
156 |
|
157 |
firstPoint = (Point2D) lastPoint.clone();
|
158 |
ret = ret | lineStatus.transition("end");
|
159 |
} else if (status == 5) { |
160 |
firstPoint = new Point2D.Double(values[0], values[1]); |
161 |
} |
162 |
|
163 |
return ret;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
|
168 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
169 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
170 |
*/
|
171 |
public void drawOperation(Graphics g, EditableFeatureSource efs, |
172 |
FBitSet selectedGeometries, double x, double y) { |
173 |
int status = lineStatus.getStatus();
|
174 |
|
175 |
if ((status == 1) || (status == 5)) { |
176 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
177 |
System.err.println("angulo: " + |
178 |
TrigonometricalFunctions.getAngle(firstPoint, |
179 |
new Point2D.Double(x, y))); |
180 |
} else if (status == 2) { |
181 |
length = firstPoint.distance(x, y); |
182 |
|
183 |
double w = (Math.cos(Math.toRadians(angle))) * length; |
184 |
double h = (Math.sin(Math.toRadians(angle))) * length; |
185 |
drawLine((Graphics2D) g, firstPoint,
|
186 |
new Point2D.Double(firstPoint.getX() + w, firstPoint.getY() + |
187 |
h)); |
188 |
} |
189 |
} |
190 |
|
191 |
/**
|
192 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
|
193 |
*/
|
194 |
public String getQuestion() { |
195 |
return STATUS[lineStatus.getStatus()].getQuestion();
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
|
200 |
*/
|
201 |
public void initializeStatus() { |
202 |
lineStatus.initialize(); |
203 |
firstPoint = null;
|
204 |
lastPoint = null;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
|
209 |
*/
|
210 |
public Automaton getAutomaton() {
|
211 |
return lineStatus;
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getName()
|
216 |
*/
|
217 |
public String getName() { |
218 |
return "L?NEA"; |
219 |
} |
220 |
} |