root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / ArcCADTool.java @ 38539
History | View | Annotate | Download (5.29 KB)
1 | 37138 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 3782 | caballero | *
|
3 | 37138 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 3782 | caballero | * 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 | 37138 | cordinyana | *
|
11 | 3782 | caballero | * 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 | 37138 | cordinyana | *
|
16 | 3782 | caballero | * 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 | 37138 | cordinyana | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 3782 | caballero | */
|
22 | 29616 | jpiera | package org.gvsig.editing.gui.cad.tools; |
23 | 3782 | caballero | |
24 | 4313 | fjp | import java.awt.event.InputEvent; |
25 | 3832 | caballero | import java.awt.geom.Point2D; |
26 | |||
27 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
28 | import org.gvsig.editing.gui.cad.exception.CommandException; |
||
29 | import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext; |
||
30 | import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext.ArcCADToolState; |
||
31 | 21668 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
32 | 26921 | jpiera | import org.gvsig.fmap.geom.primitive.Point; |
33 | 30335 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
34 | 21668 | vcaballero | |
35 | 3782 | caballero | /**
|
36 | 37138 | cordinyana | *
|
37 | 3782 | caballero | * @author Vicente Caballero Navarro
|
38 | */
|
||
39 | 37328 | cordinyana | public class ArcCADTool extends AbstractCurveCADTool { |
40 | 3782 | caballero | |
41 | 37138 | cordinyana | private ArcCADToolContext _fsm;
|
42 | private Point p1; |
||
43 | private Point p2; |
||
44 | private Point p3; |
||
45 | 3782 | caballero | |
46 | 37138 | cordinyana | /**
|
47 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
48 | * carga previa a la utilizaci?n de la herramienta.
|
||
49 | */
|
||
50 | public void init() { |
||
51 | _fsm = new ArcCADToolContext(this); |
||
52 | } |
||
53 | 3782 | caballero | |
54 | 37138 | cordinyana | public void transition(double x, double y, InputEvent event) { |
55 | _fsm.addPoint(x, y, event); |
||
56 | } |
||
57 | 3782 | caballero | |
58 | 37138 | cordinyana | public void transition(double d) { |
59 | _fsm.addValue(d); |
||
60 | } |
||
61 | 3782 | caballero | |
62 | 37138 | cordinyana | public void transition(String s) throws CommandException { |
63 | if (!super.changeCommand(s)) { |
||
64 | _fsm.addOption(s); |
||
65 | } |
||
66 | } |
||
67 | 3782 | caballero | |
68 | 37138 | cordinyana | /**
|
69 | * Equivale al transition del prototipo pero sin pasarle como par? metro el
|
||
70 | * editableFeatureSource que ya estar? creado.
|
||
71 | *
|
||
72 | * @param sel
|
||
73 | * Bitset con las geometr?as que est?n seleccionadas.
|
||
74 | * @param x
|
||
75 | * par?metro x del punto que se pase en esta transici?n.
|
||
76 | * @param y
|
||
77 | * par?metro y del punto que se pase en esta transici?n.
|
||
78 | */
|
||
79 | public void addPoint(double x, double y, InputEvent event) { |
||
80 | ArcCADToolState actualState = (ArcCADToolState) _fsm.getPreviousState(); |
||
81 | String status = actualState.getName();
|
||
82 | 3782 | caballero | |
83 | 37138 | cordinyana | if (status.equals("Arc.FirstPoint")) { |
84 | p1 = createPoint(x, y); |
||
85 | } else
|
||
86 | if (status.equals("Arc.SecondPoint")) { |
||
87 | p2 = createPoint(x, y); |
||
88 | } else
|
||
89 | if (status.equals("Arc.ThirdPoint")) { |
||
90 | p3 = createPoint(x, y); |
||
91 | Geometry ig = createArc(p1, p2, p3); |
||
92 | if (ig != null) { |
||
93 | insertAndSelectGeometry(ig); |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | 3782 | caballero | |
98 | 37138 | cordinyana | /**
|
99 | * M?todo para dibujar lo necesario para el estado en el que nos
|
||
100 | * encontremos.
|
||
101 | *
|
||
102 | * @param g
|
||
103 | * Graphics sobre el que dibujar.
|
||
104 | * @param selectedGeometries
|
||
105 | * BitSet con las geometr?as seleccionadas.
|
||
106 | * @param x
|
||
107 | * par?metro x del punto que se pase para dibujar.
|
||
108 | * @param y
|
||
109 | * par?metro x del punto que se pase para dibujar.
|
||
110 | */
|
||
111 | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
||
112 | ArcCADToolState actualState = _fsm.getState(); |
||
113 | String status = actualState.getName();
|
||
114 | 3782 | caballero | |
115 | 37138 | cordinyana | if (status.equals("Arc.SecondPoint")) { |
116 | renderer.drawLine(new Point2D.Double(p1.getX(), p1.getY()), |
||
117 | new Point2D.Double(x, y), |
||
118 | mapControlManager.getGeometrySelectionSymbol()); |
||
119 | } else
|
||
120 | if (status.equals("Arc.ThirdPoint")) { |
||
121 | Point current = createPoint(x, y);
|
||
122 | 30335 | jpiera | |
123 | 37138 | cordinyana | Geometry ig = createArc(p1, p2, current); |
124 | renderer.draw(ig, |
||
125 | mapControlManager.getGeometrySelectionSymbol()); |
||
126 | 3782 | caballero | |
127 | 37138 | cordinyana | Point2D p =
|
128 | getCadToolAdapter().getMapControl().getViewPort() |
||
129 | .fromMapPoint(p1.getX(), p1.getY()); |
||
130 | renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
||
131 | p = |
||
132 | getCadToolAdapter().getMapControl().getViewPort() |
||
133 | .fromMapPoint(p2.getX(), p2.getY()); |
||
134 | renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
||
135 | } |
||
136 | } |
||
137 | 3782 | caballero | |
138 | 37138 | cordinyana | /**
|
139 | * Add a diferent option.
|
||
140 | *
|
||
141 | * @param sel
|
||
142 | * DOCUMENT ME!
|
||
143 | * @param s
|
||
144 | * Diferent option.
|
||
145 | */
|
||
146 | public void addOption(String s) { |
||
147 | 37328 | cordinyana | // Nothing to do
|
148 | 37138 | cordinyana | } |
149 | 3883 | caballero | |
150 | 37138 | cordinyana | public void addValue(double d) { |
151 | 37328 | cordinyana | // Nothing to do
|
152 | 37138 | cordinyana | } |
153 | 4118 | caballero | |
154 | 37138 | cordinyana | public String getName() { |
155 | return PluginServices.getText(this, "arc_"); |
||
156 | } |
||
157 | 4892 | caballero | |
158 | 37138 | cordinyana | public String toString() { |
159 | return "_arc"; |
||
160 | } |
||
161 | 5170 | caballero | |
162 | 37328 | cordinyana | @Override
|
163 | protected int getSupportedPrimitiveGeometryType() { |
||
164 | return ARC;
|
||
165 | 37138 | cordinyana | } |
166 | |||
167 | 3782 | caballero | } |