root / branches / gvSIG_CAD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / SymmetryCadTool.java @ 3513
History | View | Annotate | Download (7.42 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.FGeometry; |
44 |
import com.iver.cit.gvsig.fmap.core.Handler; |
45 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
46 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
47 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
48 |
import com.iver.cit.gvsig.fmap.edition.cad.Status; |
49 |
import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
50 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
51 |
import com.iver.cit.gvsig.gui.cad.CadTool; |
52 |
import com.iver.cit.gvsig.gui.cad.automaton.Simetria; |
53 |
|
54 |
import com.iver.fsac.Automaton; |
55 |
|
56 |
import java.awt.Graphics; |
57 |
import java.awt.Graphics2D; |
58 |
import java.awt.geom.Point2D; |
59 |
|
60 |
import java.io.IOException; |
61 |
|
62 |
|
63 |
/**
|
64 |
* Herramienta para crear una geometr?a simetr?ca a otra, con la posibilidad de
|
65 |
* borrar la original.
|
66 |
*
|
67 |
* @author Vicente Caballero Navarro
|
68 |
*/
|
69 |
public class SymmetryCadTool extends AbstractCadTool { |
70 |
private static Status[] STATUS = { |
71 |
new Status("Precise primer punto de l?nea de simetr?a(x,y):"), |
72 |
new Status("Precise segundo punto de l?nea de simetr?a(x,y):"), |
73 |
new Status("?Suprimir objetos de origen?[Si(S) o No(N)]:") |
74 |
}; |
75 |
private Simetria symmetryStatus = new Simetria(); |
76 |
private Point2D firstPoint; |
77 |
private Point2D lastPoint; |
78 |
|
79 |
/**
|
80 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
|
81 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
82 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
|
83 |
*/
|
84 |
public int transition(String text, EditableFeatureSource editingSource, |
85 |
FBitSet selectedGeometries, double[] ds) { |
86 |
int ret = symmetryStatus.transition(text);
|
87 |
int status = symmetryStatus.getStatus();
|
88 |
|
89 |
if (status == 0) { |
90 |
if (selectedGeometries.cardinality() == 0) { |
91 |
getCadToolAdapter().pushCadTool(new SelectionCadTool());
|
92 |
} |
93 |
} else if (status == 1) { |
94 |
if (ds.length != 0) { |
95 |
firstPoint = new Point2D.Double(ds[0], ds[1]); |
96 |
} |
97 |
} else if (status == 2) { |
98 |
lastPoint = new Point2D.Double(ds[0], ds[1]); |
99 |
} else if (status == 3) { |
100 |
try {
|
101 |
editingSource.startComplexGeometry(); |
102 |
|
103 |
for (int i = 0; i < editingSource.getGeometryCount(); i++) { |
104 |
if (selectedGeometries.get(i)) {
|
105 |
IGeometry geom = editingSource.getGeometry(i) |
106 |
.cloneGeometry(); |
107 |
Handler[] handlers = geom.getHandlers(FGeometry.SELECTHANDLER); |
108 |
|
109 |
for (int j = 0; j < handlers.length; j++) { |
110 |
Handler h = (Handler) handlers[j]; |
111 |
Point2D p = h.getPoint();
|
112 |
Point2D[] ps = TrigonometricalFunctions.getPerpendicular(firstPoint, |
113 |
lastPoint, p); |
114 |
Point2D inter = TrigonometricalFunctions.getIntersection(ps[0], |
115 |
ps[1], firstPoint, lastPoint);
|
116 |
Point2D dif = new Point2D.Double(inter.getX() - |
117 |
p.getX(), inter.getY() - p.getY()); |
118 |
h.set(inter.getX() + dif.getX(), |
119 |
inter.getY() + dif.getY()); |
120 |
} |
121 |
|
122 |
editingSource.removeGeometry(i); |
123 |
editingSource.addGeometry(geom); |
124 |
} |
125 |
} |
126 |
|
127 |
editingSource.endComplexGeometry(); |
128 |
} catch (DriverIOException e) {
|
129 |
e.printStackTrace(); |
130 |
} catch (IOException e1) { |
131 |
e1.printStackTrace(); |
132 |
} |
133 |
|
134 |
selectedGeometries.clear(); |
135 |
ret = ret | symmetryStatus.transition("cancel");
|
136 |
} else if (status == 4) { |
137 |
try {
|
138 |
editingSource.startComplexGeometry(); |
139 |
|
140 |
for (int i = 0; i < editingSource.getGeometryCount(); i++) { |
141 |
if (selectedGeometries.get(i)) {
|
142 |
IGeometry geom = editingSource.getGeometry(i) |
143 |
.cloneGeometry(); |
144 |
Handler[] handlers = geom.getHandlers(FGeometry.SELECTHANDLER); |
145 |
|
146 |
for (int j = 0; j < handlers.length; j++) { |
147 |
Handler h = (Handler) handlers[j]; |
148 |
Point2D p = h.getPoint();
|
149 |
Point2D[] ps = TrigonometricalFunctions.getPerpendicular(firstPoint, |
150 |
lastPoint, p); |
151 |
Point2D inter = TrigonometricalFunctions.getIntersection(ps[0], |
152 |
ps[1], firstPoint, lastPoint);
|
153 |
Point2D dif = new Point2D.Double(inter.getX() - |
154 |
p.getX(), inter.getY() - p.getY()); |
155 |
h.set(inter.getX() + dif.getX(), |
156 |
inter.getY() + dif.getY()); |
157 |
} |
158 |
|
159 |
editingSource.addGeometry(geom); |
160 |
} |
161 |
} |
162 |
|
163 |
editingSource.endComplexGeometry(); |
164 |
} catch (DriverIOException e) {
|
165 |
e.printStackTrace(); |
166 |
} catch (IOException e1) { |
167 |
e1.printStackTrace(); |
168 |
} |
169 |
|
170 |
ret = ret | symmetryStatus.transition("cancel");
|
171 |
} |
172 |
|
173 |
return ret;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
|
178 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
179 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
180 |
*/
|
181 |
public void drawOperation(Graphics g, EditableFeatureSource efs, |
182 |
FBitSet selectedGeometries, double x, double y) { |
183 |
int status = symmetryStatus.getStatus();
|
184 |
|
185 |
if (status == 1) { |
186 |
Point2D lP = new Point2D.Double(x, y); |
187 |
|
188 |
try {
|
189 |
for (int i = 0; i < efs.getGeometryCount(); i++) { |
190 |
if (selectedGeometries.get(i)) {
|
191 |
IGeometry geom = efs.getGeometry(i).cloneGeometry(); |
192 |
Handler[] handlers = geom.getHandlers(FGeometry.SELECTHANDLER); |
193 |
|
194 |
for (int j = 0; j < handlers.length; j++) { |
195 |
Handler h = (Handler) handlers[j]; |
196 |
Point2D p = h.getPoint();
|
197 |
Point2D[] ps = TrigonometricalFunctions.getPerpendicular(firstPoint, |
198 |
lP, p); |
199 |
Point2D inter = TrigonometricalFunctions.getIntersection(ps[0], |
200 |
ps[1], firstPoint, lP);
|
201 |
Point2D dif = new Point2D.Double(inter.getX() - |
202 |
p.getX(), inter.getY() - p.getY()); |
203 |
h.set(inter.getX() + dif.getX(), |
204 |
inter.getY() + dif.getY()); |
205 |
} |
206 |
|
207 |
drawLine((Graphics2D) g, firstPoint, lP);
|
208 |
geom.draw((Graphics2D) g,
|
209 |
getCadToolAdapter().getMapControl().getViewPort(), |
210 |
CadTool.modifySymbol); |
211 |
} |
212 |
} |
213 |
} catch (DriverIOException e) {
|
214 |
e.printStackTrace(); |
215 |
} catch (IOException e1) { |
216 |
e1.printStackTrace(); |
217 |
} |
218 |
} |
219 |
} |
220 |
|
221 |
/**
|
222 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
|
223 |
*/
|
224 |
public String getQuestion() { |
225 |
return STATUS[symmetryStatus.getStatus()].getQuestion();
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
|
230 |
*/
|
231 |
public void initializeStatus() { |
232 |
symmetryStatus.initialize(); |
233 |
} |
234 |
|
235 |
/**
|
236 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
|
237 |
*/
|
238 |
public Automaton getAutomaton() {
|
239 |
return symmetryStatus;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getName()
|
244 |
*/
|
245 |
public String getName() { |
246 |
return "SIMETR?A"; |
247 |
} |
248 |
} |