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