root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / JoinCADTool.java @ 38539
History | View | Annotate | Download (8.09 KB)
1 | 37138 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 26242 | vcaballero | *
|
3 | 37138 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 26242 | vcaballero | * 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 | 26242 | vcaballero | * 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 | 26242 | vcaballero | * 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 | 26242 | vcaballero | */
|
22 | 29616 | jpiera | package org.gvsig.editing.gui.cad.tools; |
23 | 26242 | vcaballero | |
24 | import java.awt.event.InputEvent; |
||
25 | |||
26 | 36480 | cordinyana | import org.slf4j.Logger; |
27 | import org.slf4j.LoggerFactory; |
||
28 | |||
29 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
30 | import org.gvsig.andami.messages.NotificationManager; |
||
31 | import org.gvsig.editing.CADExtension; |
||
32 | import org.gvsig.editing.gui.cad.DefaultCADTool; |
||
33 | import org.gvsig.editing.gui.cad.exception.CommandException; |
||
34 | import org.gvsig.editing.gui.cad.tools.smc.JoinCADToolContext; |
||
35 | import org.gvsig.editing.layers.VectorialLayerEdited; |
||
36 | 26242 | vcaballero | import org.gvsig.fmap.dal.exception.DataException; |
37 | import org.gvsig.fmap.dal.exception.ReadException; |
||
38 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
39 | import org.gvsig.fmap.dal.feature.Feature; |
||
40 | 35732 | jpiera | import org.gvsig.fmap.dal.feature.FeatureSelection; |
41 | 26242 | vcaballero | import org.gvsig.fmap.dal.feature.FeatureSet; |
42 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
43 | 35732 | jpiera | import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException; |
44 | import org.gvsig.fmap.geom.Geometry; |
||
45 | 26242 | vcaballero | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
46 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
47 | 30335 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
48 | 35732 | jpiera | import org.gvsig.tools.dispose.DisposableIterator; |
49 | 26242 | vcaballero | |
50 | /**
|
||
51 | * DOCUMENT ME!
|
||
52 | 37138 | cordinyana | *
|
53 | 26242 | vcaballero | * @author Vicente Caballero Navarro
|
54 | */
|
||
55 | public class JoinCADTool extends DefaultCADTool { |
||
56 | 36480 | cordinyana | |
57 | private static final Logger LOG = LoggerFactory |
||
58 | .getLogger(JoinCADTool.class); |
||
59 | |||
60 | 26242 | vcaballero | private JoinCADToolContext _fsm;
|
61 | |||
62 | /**
|
||
63 | * M?todo de inicio, para poner el c?digo de todo lo que se requiera de una
|
||
64 | * carga previa a la utilizaci?n de la herramienta.
|
||
65 | */
|
||
66 | public void init() { |
||
67 | _fsm = new JoinCADToolContext(this); |
||
68 | } |
||
69 | |||
70 | 37138 | cordinyana | /*
|
71 | * (non-Javadoc)
|
||
72 | *
|
||
73 | * @see
|
||
74 | * com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
||
75 | * .layers.FBitSet, double, double)
|
||
76 | 26242 | vcaballero | */
|
77 | public void transition(double x, double y, InputEvent event) { |
||
78 | _fsm.addPoint(x, y, event); |
||
79 | } |
||
80 | |||
81 | 37138 | cordinyana | /*
|
82 | * (non-Javadoc)
|
||
83 | *
|
||
84 | * @see
|
||
85 | * com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
||
86 | * .layers.FBitSet, double)
|
||
87 | 26242 | vcaballero | */
|
88 | public void transition(double d) { |
||
89 | _fsm.addValue(d); |
||
90 | } |
||
91 | |||
92 | 37138 | cordinyana | /*
|
93 | * (non-Javadoc)
|
||
94 | *
|
||
95 | * @see
|
||
96 | * com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
||
97 | * .layers.FBitSet, java.lang.String)
|
||
98 | 26242 | vcaballero | */
|
99 | public void transition(String s) throws CommandException { |
||
100 | 37138 | cordinyana | if (!super.changeCommand(s)) { |
101 | 35732 | jpiera | _fsm.addOption(s); |
102 | } |
||
103 | 26242 | vcaballero | } |
104 | |||
105 | /**
|
||
106 | * DOCUMENT ME!
|
||
107 | */
|
||
108 | public void selection() { |
||
109 | 35732 | jpiera | FeatureSet selection = null;
|
110 | try {
|
||
111 | selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
||
112 | 26242 | vcaballero | |
113 | 35732 | jpiera | if (selection.getSize() == 0 |
114 | && !CADExtension |
||
115 | 37138 | cordinyana | .getCADTool() |
116 | .getClass() |
||
117 | .getName() |
||
118 | .equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
||
119 | 35732 | jpiera | CADExtension.setCADTool("_selection", false); |
120 | ((SelectionCADTool) CADExtension.getCADTool()) |
||
121 | 37138 | cordinyana | .setNextTool("_join");
|
122 | 35732 | jpiera | } |
123 | } catch (ReadException e) {
|
||
124 | // TODO Auto-generated catch block
|
||
125 | e.printStackTrace(); |
||
126 | } catch (DataException e) {
|
||
127 | // TODO Auto-generated catch block
|
||
128 | e.printStackTrace(); |
||
129 | } |
||
130 | 26242 | vcaballero | } |
131 | |||
132 | /**
|
||
133 | * Equivale al transition del prototipo pero sin pasarle como par?metro el
|
||
134 | * editableFeatureSource que ya estar? creado.
|
||
135 | 37138 | cordinyana | *
|
136 | * @param x
|
||
137 | * par?metro x del punto que se pase en esta transici?n.
|
||
138 | * @param y
|
||
139 | * par?metro y del punto que se pase en esta transici?n.
|
||
140 | 26242 | vcaballero | */
|
141 | 37138 | cordinyana | public void addPoint(double x, double y, InputEvent event) { |
142 | |||
143 | 26242 | vcaballero | } |
144 | |||
145 | /**
|
||
146 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
147 | * encontremos.
|
||
148 | 37138 | cordinyana | *
|
149 | * @param g
|
||
150 | * Graphics sobre el que dibujar.
|
||
151 | * @param x
|
||
152 | * par?metro x del punto que se pase para dibujar.
|
||
153 | * @param y
|
||
154 | * par?metro x del punto que se pase para dibujar.
|
||
155 | 26242 | vcaballero | */
|
156 | 30335 | jpiera | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
157 | 37138 | cordinyana | |
158 | 26242 | vcaballero | } |
159 | 37138 | cordinyana | |
160 | 26242 | vcaballero | public void join() { |
161 | 35732 | jpiera | VectorialLayerEdited vle = getVLE(); |
162 | FeatureStore featureStore = null;
|
||
163 | try {
|
||
164 | featureStore = vle.getFeatureStore(); |
||
165 | } catch (ReadException e1) {
|
||
166 | 37138 | cordinyana | NotificationManager.addError(e1.getMessage(), e1); |
167 | 35732 | jpiera | } |
168 | DisposableIterator iterator = null;
|
||
169 | try {
|
||
170 | featureStore.beginEditingGroup(getName()); |
||
171 | 26242 | vcaballero | |
172 | 37138 | cordinyana | FeatureSelection selection = featureStore.createFeatureSelection(); |
173 | selection.select((FeatureSet) featureStore.getSelection()); |
||
174 | 26242 | vcaballero | |
175 | 37138 | cordinyana | Geometry geomTotal = null;
|
176 | iterator = selection.fastIterator(); |
||
177 | boolean first = true; |
||
178 | Feature firstFeature = null;
|
||
179 | while (iterator.hasNext()) {
|
||
180 | Feature feature = (Feature) iterator.next(); |
||
181 | if (first) {
|
||
182 | firstFeature = feature; |
||
183 | first = false;
|
||
184 | 35732 | jpiera | } |
185 | |||
186 | 37138 | cordinyana | Geometry currentGeometry = |
187 | feature.getDefaultGeometry().cloneGeometry(); |
||
188 | featureStore.delete(feature); |
||
189 | if (geomTotal == null) { |
||
190 | geomTotal = currentGeometry; |
||
191 | } else {
|
||
192 | geomTotal = geomTotal.union(currentGeometry); |
||
193 | } |
||
194 | } |
||
195 | |||
196 | EditableFeature editableFeature = |
||
197 | featureStore.createNewFeature(firstFeature.getType(), |
||
198 | firstFeature); |
||
199 | editableFeature.setGeometry(featureStore.getDefaultFeatureType() |
||
200 | .getDefaultGeometryAttributeName(), geomTotal); |
||
201 | featureStore.insert(editableFeature); |
||
202 | refresh(); |
||
203 | 35732 | jpiera | } catch (DataException e) {
|
204 | 37138 | cordinyana | NotificationManager.addError(e.getMessage(), e); |
205 | 35732 | jpiera | } catch (GeometryOperationNotSupportedException e) {
|
206 | 37138 | cordinyana | NotificationManager.addError(e.getMessage(), e); |
207 | 35732 | jpiera | } catch (GeometryOperationException e) {
|
208 | 37138 | cordinyana | NotificationManager.addError(e.getMessage(), e); |
209 | 35732 | jpiera | } finally {
|
210 | if (iterator != null) { |
||
211 | iterator.dispose(); |
||
212 | } |
||
213 | try {
|
||
214 | featureStore.endEditingGroup(); |
||
215 | } catch (NeedEditingModeException e) {
|
||
216 | LOG.error("Exception endEditingGroup", e);
|
||
217 | } |
||
218 | } |
||
219 | 26242 | vcaballero | } |
220 | 37138 | cordinyana | |
221 | 35732 | jpiera | /**
|
222 | * Add a diferent option.
|
||
223 | 37138 | cordinyana | *
|
224 | 35732 | jpiera | * @param s
|
225 | * Diferent option.
|
||
226 | */
|
||
227 | 26242 | vcaballero | public void addOption(String s) { |
228 | } |
||
229 | |||
230 | /*
|
||
231 | 35732 | jpiera | * (non-Javadoc)
|
232 | 37138 | cordinyana | *
|
233 | 35732 | jpiera | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
234 | */
|
||
235 | 26242 | vcaballero | public void addValue(double d) { |
236 | |||
237 | } |
||
238 | |||
239 | 35732 | jpiera | public String getName() { |
240 | 37138 | cordinyana | return PluginServices.getText(this, "join_"); |
241 | 35732 | jpiera | } |
242 | 26242 | vcaballero | |
243 | 35732 | jpiera | public String toString() { |
244 | return "_join"; |
||
245 | } |
||
246 | 37138 | cordinyana | |
247 | 37328 | cordinyana | @Override
|
248 | protected int[] getSupportedGeometryTypes() { |
||
249 | return new int[] { CURVE, SURFACE }; |
||
250 | 35732 | jpiera | } |
251 | 26242 | vcaballero | } |