svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / MultiPointCADTool.java @ 39137
History | View | Annotate | Download (6.8 KB)
1 | 37138 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 6024 | caballero | *
|
3 | 37138 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 6024 | 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 | 6024 | 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 | 6024 | 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 | 6024 | caballero | */
|
22 | 29616 | jpiera | package org.gvsig.editing.gui.cad.tools; |
23 | 6024 | caballero | |
24 | import java.awt.event.InputEvent; |
||
25 | import java.util.ArrayList; |
||
26 | |||
27 | 34696 | cordinyana | import org.slf4j.Logger; |
28 | import org.slf4j.LoggerFactory; |
||
29 | |||
30 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
31 | import org.gvsig.editing.gui.cad.DefaultCADTool; |
||
32 | import org.gvsig.editing.gui.cad.exception.CommandException; |
||
33 | import org.gvsig.editing.gui.cad.tools.smc.MultiPointCADToolContext; |
||
34 | import org.gvsig.editing.gui.cad.tools.smc.MultiPointCADToolContext.MultiPointCADToolState; |
||
35 | 26921 | jpiera | import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
36 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
37 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
38 | import org.gvsig.fmap.geom.aggregate.MultiPoint; |
||
39 | 27039 | jpiera | import org.gvsig.fmap.geom.primitive.Point; |
40 | 30335 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
41 | 21668 | vcaballero | |
42 | 6024 | caballero | /**
|
43 | * DOCUMENT ME!
|
||
44 | 37138 | cordinyana | *
|
45 | 6024 | caballero | * @author Vicente Caballero Navarro
|
46 | */
|
||
47 | public class MultiPointCADTool extends DefaultCADTool { |
||
48 | 34696 | cordinyana | |
49 | private static final Logger LOG = LoggerFactory |
||
50 | .getLogger(MultiPointCADTool.class); |
||
51 | |||
52 | 37138 | cordinyana | protected MultiPointCADToolContext _fsm;
|
53 | protected ArrayList points = new ArrayList(); |
||
54 | 6024 | caballero | |
55 | 37138 | cordinyana | /**
|
56 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
57 | * carga previa a la utilizaci?n de la herramienta.
|
||
58 | */
|
||
59 | public void init() { |
||
60 | _fsm = new MultiPointCADToolContext(this); |
||
61 | 39137 | jldominguez | /*
|
62 | * Clear points in case the user exited editing
|
||
63 | * the previous time without ending multipoint
|
||
64 | */
|
||
65 | points.clear(); |
||
66 | 37138 | cordinyana | } |
67 | 6024 | caballero | |
68 | 37138 | cordinyana | /**
|
69 | * DOCUMENT ME!
|
||
70 | *
|
||
71 | * @param x
|
||
72 | * DOCUMENT ME!
|
||
73 | * @param y
|
||
74 | * DOCUMENT ME!
|
||
75 | * @param sel
|
||
76 | * DOCUMENT ME!
|
||
77 | */
|
||
78 | public void transition(double x, double y, InputEvent event) { |
||
79 | _fsm.addPoint(x, y, event); |
||
80 | } |
||
81 | 6024 | caballero | |
82 | 37138 | cordinyana | public void transition(double d) { |
83 | _fsm.addValue(d); |
||
84 | } |
||
85 | 6024 | caballero | |
86 | 37138 | cordinyana | public void transition(String s) throws CommandException { |
87 | if (!super.changeCommand(s)) { |
||
88 | _fsm.addOption(s); |
||
89 | } |
||
90 | } |
||
91 | 6024 | caballero | |
92 | 37138 | cordinyana | /**
|
93 | * Equivale al transition del prototipo pero sin pasarle como par? metro el
|
||
94 | * editableFeatureSource que ya estar? creado.
|
||
95 | *
|
||
96 | * @param sel
|
||
97 | * Bitset con las geometr?as que est?n seleccionadas.
|
||
98 | * @param x
|
||
99 | * par?metro x del punto que se pase en esta transici?n.
|
||
100 | * @param y
|
||
101 | * par?metro y del punto que se pase en esta transici?n.
|
||
102 | */
|
||
103 | public void addPoint(double x, double y, InputEvent event) { |
||
104 | MultiPointCADToolState actualState = |
||
105 | (MultiPointCADToolState) _fsm.getPreviousState(); |
||
106 | String status = actualState.getName();
|
||
107 | 6024 | caballero | |
108 | 37138 | cordinyana | if (status.equals("MultiPoint.InsertPoint")) { |
109 | points.add(new double[] { x, y }); |
||
110 | // addGeometry(ShapeFactory.createPoint2D(x, y));
|
||
111 | } |
||
112 | } |
||
113 | 21668 | vcaballero | |
114 | 37138 | cordinyana | /**
|
115 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
116 | * encontremos.
|
||
117 | *
|
||
118 | * @param g
|
||
119 | * Graphics sobre el que dibujar.
|
||
120 | * @param selectedGeometries
|
||
121 | * BitSet con las geometr?as seleccionadas.
|
||
122 | * @param x
|
||
123 | * par?metro x del punto que se pase para dibujar.
|
||
124 | * @param y
|
||
125 | * par?metro x del punto que se pase para dibujar.
|
||
126 | */
|
||
127 | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
||
128 | try {
|
||
129 | int num = points.size();
|
||
130 | Point[] pointsAux = new Point[num]; |
||
131 | for (int i = 0; i < num; i++) { |
||
132 | double[] p = (double[]) points.get(i); |
||
133 | pointsAux[i] = |
||
134 | (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
||
135 | pointsAux[i].setX(p[0]);
|
||
136 | pointsAux[i].setY(p[1]);
|
||
137 | } |
||
138 | 27039 | jpiera | |
139 | 37138 | cordinyana | MultiPoint multiPoint = |
140 | (MultiPoint) geomManager.create(TYPES.MULTIPOINT, |
||
141 | SUBTYPES.GEOM2D); |
||
142 | for (int i = 0; i < pointsAux.length; i++) { |
||
143 | multiPoint.addPoint(pointsAux[i]); |
||
144 | } |
||
145 | renderer.draw(multiPoint, |
||
146 | mapControlManager.getGeometrySelectionSymbol()); |
||
147 | 30335 | jpiera | |
148 | 37138 | cordinyana | renderer.draw(createPoint(x, y), |
149 | mapControlManager.getGeometrySelectionSymbol()); |
||
150 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
151 | 34696 | cordinyana | LOG.error("Error drawing with renderer: " + renderer + ", x=" + x |
152 | + ",y=" + y, new CreateGeometryException(TYPES.MULTIPOINT, |
||
153 | SUBTYPES.GEOM2D, e)); |
||
154 | 37138 | cordinyana | } |
155 | } |
||
156 | 6024 | caballero | |
157 | 37138 | cordinyana | /**
|
158 | * Add a diferent option.
|
||
159 | *
|
||
160 | * @param sel
|
||
161 | * DOCUMENT ME!
|
||
162 | * @param s
|
||
163 | * Diferent option.
|
||
164 | */
|
||
165 | public void addOption(String s) { |
||
166 | 37328 | cordinyana | // Nothing to do
|
167 | 37138 | cordinyana | } |
168 | 6024 | caballero | |
169 | 37138 | cordinyana | public void addValue(double d) { |
170 | 37328 | cordinyana | // Nothing to do
|
171 | 37138 | cordinyana | } |
172 | 6024 | caballero | |
173 | 37138 | cordinyana | public String getName() { |
174 | return PluginServices.getText(this, "multipoint_"); |
||
175 | } |
||
176 | 6024 | caballero | |
177 | 37138 | cordinyana | public String toString() { |
178 | return "_multipoint"; |
||
179 | } |
||
180 | 6024 | caballero | |
181 | 37328 | cordinyana | @Override
|
182 | protected int[] getSupportedGeometryTypes() { |
||
183 | return new int[] { MULTIPOINT }; |
||
184 | 37138 | cordinyana | } |
185 | 27039 | jpiera | |
186 | 37138 | cordinyana | public void endGeometry() { |
187 | try {
|
||
188 | int num = points.size();
|
||
189 | Point[] pointsAux = new Point[num]; |
||
190 | for (int i = 0; i < num; i++) { |
||
191 | double[] p = (double[]) points.get(i); |
||
192 | pointsAux[i] = |
||
193 | (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
||
194 | pointsAux[i].setX(p[0]);
|
||
195 | pointsAux[i].setY(p[1]);
|
||
196 | } |
||
197 | 27039 | jpiera | |
198 | 37328 | cordinyana | MultiPoint multiPoint = createMultiPoint(); |
199 | 37138 | cordinyana | |
200 | for (int i = 0; i < pointsAux.length; i++) { |
||
201 | multiPoint.addPoint(pointsAux[i]); |
||
202 | } |
||
203 | insertAndSelectGeometry(multiPoint); |
||
204 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
205 | 34696 | cordinyana | LOG.error("Error ending geometry", new CreateGeometryException( |
206 | TYPES.MULTIPOINT, SUBTYPES.GEOM2D, e)); |
||
207 | 37138 | cordinyana | } |
208 | end(); |
||
209 | } |
||
210 | |||
211 | public void end() { |
||
212 | points.clear(); |
||
213 | super.end();
|
||
214 | } |
||
215 | 6024 | caballero | } |