root / tags / v2_0_0_Build_2058 / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / ArcCADTool.java @ 39229
History | View | Annotate | Download (5.88 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.editing.gui.cad.tools; |
23 |
|
24 |
import java.awt.event.InputEvent; |
25 |
import java.awt.geom.Point2D; |
26 |
|
27 |
import javax.swing.JOptionPane; |
28 |
|
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.app.ApplicationLocator; |
31 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
32 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext; |
33 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext.ArcCADToolState; |
34 |
import org.gvsig.fmap.geom.Geometry; |
35 |
import org.gvsig.fmap.geom.primitive.Point; |
36 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
37 |
import org.gvsig.i18n.Messages; |
38 |
|
39 |
/**
|
40 |
*
|
41 |
* @author Vicente Caballero Navarro
|
42 |
*/
|
43 |
public class ArcCADTool extends AbstractCurveCADTool { |
44 |
|
45 |
private ArcCADToolContext _fsm;
|
46 |
private Point p1; |
47 |
private Point p2; |
48 |
private Point p3; |
49 |
|
50 |
/**
|
51 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
52 |
* carga previa a la utilizaci?n de la herramienta.
|
53 |
*/
|
54 |
public void init() { |
55 |
_fsm = new ArcCADToolContext(this); |
56 |
} |
57 |
|
58 |
public void transition(double x, double y, InputEvent event) { |
59 |
_fsm.addPoint(x, y, event); |
60 |
} |
61 |
|
62 |
public void transition(double d) { |
63 |
_fsm.addValue(d); |
64 |
} |
65 |
|
66 |
public void transition(String s) throws CommandException { |
67 |
if (!super.changeCommand(s)) { |
68 |
_fsm.addOption(s); |
69 |
} |
70 |
} |
71 |
|
72 |
/**
|
73 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
74 |
* editableFeatureSource que ya estar? creado.
|
75 |
*
|
76 |
* @param sel
|
77 |
* Bitset con las geometr?as que est?n seleccionadas.
|
78 |
* @param x
|
79 |
* par?metro x del punto que se pase en esta transici?n.
|
80 |
* @param y
|
81 |
* par?metro y del punto que se pase en esta transici?n.
|
82 |
*/
|
83 |
public void addPoint(double x, double y, InputEvent event) { |
84 |
ArcCADToolState actualState = (ArcCADToolState) _fsm.getPreviousState(); |
85 |
String status = actualState.getName();
|
86 |
|
87 |
if (status.equals("Arc.FirstPoint")) { |
88 |
p1 = createPoint(x, y); |
89 |
} else
|
90 |
if (status.equals("Arc.SecondPoint")) { |
91 |
p2 = createPoint(x, y); |
92 |
} else
|
93 |
if (status.equals("Arc.ThirdPoint")) { |
94 |
p3 = createPoint(x, y); |
95 |
Geometry ig = createArc(p1, p2, p3); |
96 |
if (ig != null) { |
97 |
insertAndSelectGeometry(ig); |
98 |
} else {
|
99 |
ApplicationLocator.getManager().message( |
100 |
Messages.getText("_Unable_to_create_arc"),
|
101 |
JOptionPane.ERROR_MESSAGE);
|
102 |
} |
103 |
} |
104 |
} |
105 |
|
106 |
/**
|
107 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
108 |
* encontremos.
|
109 |
*
|
110 |
* @param g
|
111 |
* Graphics sobre el que dibujar.
|
112 |
* @param selectedGeometries
|
113 |
* BitSet con las geometr?as seleccionadas.
|
114 |
* @param x
|
115 |
* par?metro x del punto que se pase para dibujar.
|
116 |
* @param y
|
117 |
* par?metro x del punto que se pase para dibujar.
|
118 |
*/
|
119 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
120 |
ArcCADToolState actualState = _fsm.getState(); |
121 |
String status = actualState.getName();
|
122 |
|
123 |
if (status.equals("Arc.SecondPoint")) { |
124 |
renderer.drawLine(new Point2D.Double(p1.getX(), p1.getY()), |
125 |
new Point2D.Double(x, y), |
126 |
mapControlManager.getGeometrySelectionSymbol()); |
127 |
} else
|
128 |
if (status.equals("Arc.ThirdPoint")) { |
129 |
Point current = createPoint(x, y);
|
130 |
|
131 |
Geometry ig = createArc(p1, p2, current); |
132 |
|
133 |
if (ig != null) { |
134 |
/*
|
135 |
* sometims it's not possible to create arc
|
136 |
* (example: aligned points)
|
137 |
*/
|
138 |
renderer.draw(ig, |
139 |
mapControlManager.getGeometrySelectionSymbol()); |
140 |
|
141 |
Point2D p =
|
142 |
getCadToolAdapter().getMapControl().getViewPort() |
143 |
.fromMapPoint(p1.getX(), p1.getY()); |
144 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
145 |
p = |
146 |
getCadToolAdapter().getMapControl().getViewPort() |
147 |
.fromMapPoint(p2.getX(), p2.getY()); |
148 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
149 |
} |
150 |
} |
151 |
} |
152 |
|
153 |
/**
|
154 |
* Add a diferent option.
|
155 |
*
|
156 |
* @param sel
|
157 |
* DOCUMENT ME!
|
158 |
* @param s
|
159 |
* Diferent option.
|
160 |
*/
|
161 |
public void addOption(String s) { |
162 |
// Nothing to do
|
163 |
} |
164 |
|
165 |
public void addValue(double d) { |
166 |
// Nothing to do
|
167 |
} |
168 |
|
169 |
public String getName() { |
170 |
return PluginServices.getText(this, "arc_"); |
171 |
} |
172 |
|
173 |
public String toString() { |
174 |
return "_arc"; |
175 |
} |
176 |
|
177 |
@Override
|
178 |
protected int getSupportedPrimitiveGeometryType() { |
179 |
return ARC;
|
180 |
} |
181 |
|
182 |
} |