svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / MultiPointCADTool.java @ 39127
History | View | Annotate | Download (6.65 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 | } |
||
62 | 6024 | caballero | |
63 | 37138 | cordinyana | /**
|
64 | * DOCUMENT ME!
|
||
65 | *
|
||
66 | * @param x
|
||
67 | * DOCUMENT ME!
|
||
68 | * @param y
|
||
69 | * DOCUMENT ME!
|
||
70 | * @param sel
|
||
71 | * DOCUMENT ME!
|
||
72 | */
|
||
73 | public void transition(double x, double y, InputEvent event) { |
||
74 | _fsm.addPoint(x, y, event); |
||
75 | } |
||
76 | 6024 | caballero | |
77 | 37138 | cordinyana | public void transition(double d) { |
78 | _fsm.addValue(d); |
||
79 | } |
||
80 | 6024 | caballero | |
81 | 37138 | cordinyana | public void transition(String s) throws CommandException { |
82 | if (!super.changeCommand(s)) { |
||
83 | _fsm.addOption(s); |
||
84 | } |
||
85 | } |
||
86 | 6024 | caballero | |
87 | 37138 | cordinyana | /**
|
88 | * Equivale al transition del prototipo pero sin pasarle como par? metro el
|
||
89 | * editableFeatureSource que ya estar? creado.
|
||
90 | *
|
||
91 | * @param sel
|
||
92 | * Bitset con las geometr?as que est?n seleccionadas.
|
||
93 | * @param x
|
||
94 | * par?metro x del punto que se pase en esta transici?n.
|
||
95 | * @param y
|
||
96 | * par?metro y del punto que se pase en esta transici?n.
|
||
97 | */
|
||
98 | public void addPoint(double x, double y, InputEvent event) { |
||
99 | MultiPointCADToolState actualState = |
||
100 | (MultiPointCADToolState) _fsm.getPreviousState(); |
||
101 | String status = actualState.getName();
|
||
102 | 6024 | caballero | |
103 | 37138 | cordinyana | if (status.equals("MultiPoint.InsertPoint")) { |
104 | points.add(new double[] { x, y }); |
||
105 | // addGeometry(ShapeFactory.createPoint2D(x, y));
|
||
106 | } |
||
107 | } |
||
108 | 21668 | vcaballero | |
109 | 37138 | cordinyana | /**
|
110 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
111 | * encontremos.
|
||
112 | *
|
||
113 | * @param g
|
||
114 | * Graphics sobre el que dibujar.
|
||
115 | * @param selectedGeometries
|
||
116 | * BitSet con las geometr?as seleccionadas.
|
||
117 | * @param x
|
||
118 | * par?metro x del punto que se pase para dibujar.
|
||
119 | * @param y
|
||
120 | * par?metro x del punto que se pase para dibujar.
|
||
121 | */
|
||
122 | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
||
123 | try {
|
||
124 | int num = points.size();
|
||
125 | Point[] pointsAux = new Point[num]; |
||
126 | for (int i = 0; i < num; i++) { |
||
127 | double[] p = (double[]) points.get(i); |
||
128 | pointsAux[i] = |
||
129 | (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
||
130 | pointsAux[i].setX(p[0]);
|
||
131 | pointsAux[i].setY(p[1]);
|
||
132 | } |
||
133 | 27039 | jpiera | |
134 | 37138 | cordinyana | MultiPoint multiPoint = |
135 | (MultiPoint) geomManager.create(TYPES.MULTIPOINT, |
||
136 | SUBTYPES.GEOM2D); |
||
137 | for (int i = 0; i < pointsAux.length; i++) { |
||
138 | multiPoint.addPoint(pointsAux[i]); |
||
139 | } |
||
140 | renderer.draw(multiPoint, |
||
141 | mapControlManager.getGeometrySelectionSymbol()); |
||
142 | 30335 | jpiera | |
143 | 37138 | cordinyana | renderer.draw(createPoint(x, y), |
144 | mapControlManager.getGeometrySelectionSymbol()); |
||
145 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
146 | 34696 | cordinyana | LOG.error("Error drawing with renderer: " + renderer + ", x=" + x |
147 | + ",y=" + y, new CreateGeometryException(TYPES.MULTIPOINT, |
||
148 | SUBTYPES.GEOM2D, e)); |
||
149 | 37138 | cordinyana | } |
150 | } |
||
151 | 6024 | caballero | |
152 | 37138 | cordinyana | /**
|
153 | * Add a diferent option.
|
||
154 | *
|
||
155 | * @param sel
|
||
156 | * DOCUMENT ME!
|
||
157 | * @param s
|
||
158 | * Diferent option.
|
||
159 | */
|
||
160 | public void addOption(String s) { |
||
161 | 37328 | cordinyana | // Nothing to do
|
162 | 37138 | cordinyana | } |
163 | 6024 | caballero | |
164 | 37138 | cordinyana | public void addValue(double d) { |
165 | 37328 | cordinyana | // Nothing to do
|
166 | 37138 | cordinyana | } |
167 | 6024 | caballero | |
168 | 37138 | cordinyana | public String getName() { |
169 | return PluginServices.getText(this, "multipoint_"); |
||
170 | } |
||
171 | 6024 | caballero | |
172 | 37138 | cordinyana | public String toString() { |
173 | return "_multipoint"; |
||
174 | } |
||
175 | 6024 | caballero | |
176 | 37328 | cordinyana | @Override
|
177 | protected int[] getSupportedGeometryTypes() { |
||
178 | return new int[] { MULTIPOINT }; |
||
179 | 37138 | cordinyana | } |
180 | 27039 | jpiera | |
181 | 37138 | cordinyana | public void endGeometry() { |
182 | try {
|
||
183 | int num = points.size();
|
||
184 | Point[] pointsAux = new Point[num]; |
||
185 | for (int i = 0; i < num; i++) { |
||
186 | double[] p = (double[]) points.get(i); |
||
187 | pointsAux[i] = |
||
188 | (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
||
189 | pointsAux[i].setX(p[0]);
|
||
190 | pointsAux[i].setY(p[1]);
|
||
191 | } |
||
192 | 27039 | jpiera | |
193 | 37328 | cordinyana | MultiPoint multiPoint = createMultiPoint(); |
194 | 37138 | cordinyana | |
195 | for (int i = 0; i < pointsAux.length; i++) { |
||
196 | multiPoint.addPoint(pointsAux[i]); |
||
197 | } |
||
198 | insertAndSelectGeometry(multiPoint); |
||
199 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
200 | 34696 | cordinyana | LOG.error("Error ending geometry", new CreateGeometryException( |
201 | TYPES.MULTIPOINT, SUBTYPES.GEOM2D, e)); |
||
202 | 37138 | cordinyana | } |
203 | end(); |
||
204 | } |
||
205 | |||
206 | public void end() { |
||
207 | points.clear(); |
||
208 | super.end();
|
||
209 | } |
||
210 | 6024 | caballero | } |