root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / LineCADTool.java @ 38378
History | View | Annotate | Download (6.51 KB)
1 | 37138 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 3702 | caballero | *
|
3 | 37138 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 3702 | 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 | 3702 | 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 | 3702 | 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 | 3702 | 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.LineCADToolContext; |
||
30 | import org.gvsig.editing.gui.cad.tools.smc.LineCADToolContext.LineCADToolState; |
||
31 | 21668 | vcaballero | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
32 | 30335 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
33 | 21668 | vcaballero | |
34 | 3782 | caballero | /**
|
35 | * DOCUMENT ME!
|
||
36 | 37138 | cordinyana | *
|
37 | 3782 | caballero | * @author Vicente Caballero Navarro
|
38 | */
|
||
39 | 37328 | cordinyana | public class LineCADTool extends AbstractCurveCADTool { |
40 | 37138 | cordinyana | |
41 | 26921 | jpiera | protected LineCADToolContext _fsm;
|
42 | protected Point2D firstPoint; |
||
43 | protected Point2D lastPoint; |
||
44 | protected double angle; |
||
45 | protected double length; |
||
46 | 27270 | vcaballero | |
47 | 3702 | caballero | /**
|
48 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
49 | * carga previa a la utilizaci?n de la herramienta.
|
||
50 | */
|
||
51 | public void init() { |
||
52 | 37138 | cordinyana | _fsm = new LineCADToolContext(this); |
53 | 3744 | caballero | } |
54 | 3712 | caballero | |
55 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
56 | 4324 | caballero | _fsm.addPoint(x, y, event); |
57 | 3744 | caballero | } |
58 | 3782 | caballero | |
59 | 3832 | caballero | public void transition(double d) { |
60 | _fsm.addValue(d); |
||
61 | 3782 | caballero | } |
62 | 3744 | caballero | |
63 | 5735 | caballero | public void transition(String s) throws CommandException { |
64 | 37138 | cordinyana | if (!super.changeCommand(s)) { |
65 | _fsm.addOption(s); |
||
66 | } |
||
67 | 3782 | caballero | } |
68 | |||
69 | 3744 | caballero | /**
|
70 | 3702 | caballero | * Equivale al transition del prototipo pero sin pasarle como par? metro el
|
71 | * editableFeatureSource que ya estar? creado.
|
||
72 | 37138 | cordinyana | *
|
73 | * @param sel
|
||
74 | * Bitset con las geometr?as que est?n seleccionadas.
|
||
75 | * @param x
|
||
76 | * par?metro x del punto que se pase en esta transici?n.
|
||
77 | * @param y
|
||
78 | * par?metro y del punto que se pase en esta transici?n.
|
||
79 | 3702 | caballero | */
|
80 | 37138 | cordinyana | public void addPoint(double x, double y, InputEvent event) { |
81 | LineCADToolState actualState = |
||
82 | (LineCADToolState) _fsm.getPreviousState(); |
||
83 | 3702 | caballero | String status = actualState.getName();
|
84 | 3782 | caballero | |
85 | 3978 | caballero | if (status.equals("Line.FirstPoint")) { |
86 | 3744 | caballero | firstPoint = new Point2D.Double(x, y); |
87 | 37138 | cordinyana | } else
|
88 | if (status == "Line.SecondPointOrAngle") { |
||
89 | lastPoint = new Point2D.Double(x, y); |
||
90 | 3782 | caballero | |
91 | 37138 | cordinyana | GeneralPathX elShape = |
92 | new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
||
93 | elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
||
94 | elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
||
95 | insertAndSelectGeometry(createCurve(elShape)); |
||
96 | firstPoint = (Point2D) lastPoint.clone();
|
||
97 | } else
|
||
98 | if (status == "Line.LenghtOrPoint") { |
||
99 | length = firstPoint.distance(x, y); |
||
100 | 3744 | caballero | |
101 | 37138 | cordinyana | double w = (Math.cos(Math.toRadians(angle))) * length; |
102 | double h = (Math.sin(Math.toRadians(angle))) * length; |
||
103 | lastPoint = |
||
104 | new Point2D.Double(firstPoint.getX() + w, |
||
105 | firstPoint.getY() + h); |
||
106 | 3744 | caballero | |
107 | 37138 | cordinyana | GeneralPathX elShape = |
108 | new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
||
109 | elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
||
110 | elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
||
111 | insertAndSelectGeometry(createCurve(elShape)); |
||
112 | 3744 | caballero | |
113 | 37138 | cordinyana | firstPoint = (Point2D) lastPoint.clone();
|
114 | } |
||
115 | 3702 | caballero | } |
116 | |||
117 | /**
|
||
118 | 3744 | caballero | * M?todo para dibujar la lo necesario para el estado en el que nos
|
119 | * encontremos.
|
||
120 | 37138 | cordinyana | *
|
121 | * @param g
|
||
122 | * Graphics sobre el que dibujar.
|
||
123 | * @param selectedGeometries
|
||
124 | * BitSet con las geometr?as seleccionadas.
|
||
125 | * @param x
|
||
126 | * par?metro x del punto que se pase para dibujar.
|
||
127 | * @param y
|
||
128 | * par?metro x del punto que se pase para dibujar.
|
||
129 | 3702 | caballero | */
|
130 | 37138 | cordinyana | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
131 | 3744 | caballero | LineCADToolState actualState = _fsm.getState(); |
132 | String status = actualState.getName();
|
||
133 | 3782 | caballero | |
134 | 3978 | caballero | if ((status != "Line.FirstPoint")) { // || (status == "5")) { |
135 | 3702 | caballero | |
136 | 3744 | caballero | if (firstPoint != null) { |
137 | 37138 | cordinyana | renderer.drawLine(firstPoint, new Point2D.Double(x, y), |
138 | mapControlManager.getGeometrySelectionSymbol()); |
||
139 | 3744 | caballero | } |
140 | } |
||
141 | } |
||
142 | |||
143 | 3702 | caballero | /**
|
144 | * Add a diferent option.
|
||
145 | 37138 | cordinyana | *
|
146 | * @param sel
|
||
147 | * DOCUMENT ME!
|
||
148 | * @param s
|
||
149 | * Diferent option.
|
||
150 | 3702 | caballero | */
|
151 | 3832 | caballero | public void addOption(String s) { |
152 | 37328 | cordinyana | // Nothing to do
|
153 | 3702 | caballero | } |
154 | 3712 | caballero | |
155 | 3832 | caballero | public void addValue(double d) { |
156 | 37138 | cordinyana | LineCADToolState actualState = |
157 | (LineCADToolState) _fsm.getPreviousState(); |
||
158 | 3744 | caballero | String status = actualState.getName();
|
159 | |||
160 | 3978 | caballero | if (status == "Line.SecondPointOrAngle") { |
161 | 3744 | caballero | angle = d; |
162 | 37138 | cordinyana | } else
|
163 | if (status == "Line.LenghtOrPoint") { |
||
164 | length = d; |
||
165 | 3744 | caballero | |
166 | 37138 | cordinyana | double w = Math.cos(Math.toRadians(angle)) * length; |
167 | double h = Math.sin(Math.toRadians(angle)) * length; |
||
168 | lastPoint = |
||
169 | new Point2D.Double(firstPoint.getX() + w, firstPoint.getY() |
||
170 | + h); |
||
171 | 3744 | caballero | |
172 | 37138 | cordinyana | GeneralPathX elShape = |
173 | new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
||
174 | elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
||
175 | elShape.lineTo(lastPoint.getX(), lastPoint.getY()); |
||
176 | insertAndSelectGeometry(createCurve(elShape)); |
||
177 | firstPoint = (Point2D) lastPoint.clone();
|
||
178 | } |
||
179 | 3744 | caballero | } |
180 | 3883 | caballero | |
181 | 37138 | cordinyana | public String getName() { |
182 | return PluginServices.getText(this, "line_"); |
||
183 | } |
||
184 | 4118 | caballero | |
185 | 37138 | cordinyana | public String toString() { |
186 | return "_line"; |
||
187 | } |
||
188 | 35619 | jpiera | |
189 | 37328 | cordinyana | @Override
|
190 | protected int getSupportedPrimitiveGeometryType() { |
||
191 | return CURVE;
|
||
192 | 37138 | cordinyana | } |
193 | 3702 | caballero | } |