svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / JoinCADTool.java @ 35732
History | View | Annotate | Download (8.32 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.editing.gui.cad.tools; |
42 |
|
43 |
import java.awt.event.InputEvent; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.messages.NotificationManager; |
47 |
import org.gvsig.editing.CADExtension; |
48 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
49 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
50 |
import org.gvsig.editing.gui.cad.tools.smc.JoinCADToolContext; |
51 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
52 |
import org.gvsig.fmap.dal.exception.DataException; |
53 |
import org.gvsig.fmap.dal.exception.ReadException; |
54 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
55 |
import org.gvsig.fmap.dal.feature.Feature; |
56 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
57 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
58 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
59 |
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException; |
60 |
import org.gvsig.fmap.geom.Geometry; |
61 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
62 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
63 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
64 |
import org.gvsig.tools.dispose.DisposableIterator; |
65 |
|
66 |
|
67 |
/**
|
68 |
* DOCUMENT ME!
|
69 |
*
|
70 |
* @author Vicente Caballero Navarro
|
71 |
*/
|
72 |
public class JoinCADTool extends DefaultCADTool { |
73 |
private JoinCADToolContext _fsm;
|
74 |
|
75 |
/**
|
76 |
* Crea un nuevo JoinCADTool.
|
77 |
*/
|
78 |
public JoinCADTool() {
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* M?todo de inicio, para poner el c?digo de todo lo que se requiera de una
|
83 |
* carga previa a la utilizaci?n de la herramienta.
|
84 |
*/
|
85 |
public void init() { |
86 |
_fsm = new JoinCADToolContext(this); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
91 |
*/
|
92 |
public void transition(double x, double y, InputEvent event) { |
93 |
_fsm.addPoint(x, y, event); |
94 |
} |
95 |
|
96 |
/* (non-Javadoc)
|
97 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
98 |
*/
|
99 |
public void transition(double d) { |
100 |
_fsm.addValue(d); |
101 |
} |
102 |
|
103 |
/* (non-Javadoc)
|
104 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
105 |
*/
|
106 |
public void transition(String s) throws CommandException { |
107 |
if (!super.changeCommand(s)){ |
108 |
_fsm.addOption(s); |
109 |
} |
110 |
} |
111 |
|
112 |
/**
|
113 |
* DOCUMENT ME!
|
114 |
*/
|
115 |
public void selection() { |
116 |
FeatureSet selection = null;
|
117 |
try {
|
118 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
119 |
|
120 |
if (selection.getSize() == 0 |
121 |
&& !CADExtension |
122 |
.getCADTool() |
123 |
.getClass() |
124 |
.getName() |
125 |
.equals( |
126 |
"com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
127 |
CADExtension.setCADTool("_selection", false); |
128 |
((SelectionCADTool) CADExtension.getCADTool()) |
129 |
.setNextTool("_join");
|
130 |
} |
131 |
} catch (ReadException e) {
|
132 |
// TODO Auto-generated catch block
|
133 |
e.printStackTrace(); |
134 |
} catch (DataException e) {
|
135 |
// TODO Auto-generated catch block
|
136 |
e.printStackTrace(); |
137 |
} |
138 |
} |
139 |
|
140 |
/**
|
141 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
142 |
* editableFeatureSource que ya estar? creado.
|
143 |
*
|
144 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
145 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
146 |
*/
|
147 |
public void addPoint(double x, double y,InputEvent event) { |
148 |
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
153 |
* encontremos.
|
154 |
*
|
155 |
* @param g Graphics sobre el que dibujar.
|
156 |
* @param x par?metro x del punto que se pase para dibujar.
|
157 |
* @param y par?metro x del punto que se pase para dibujar.
|
158 |
*/
|
159 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
160 |
|
161 |
} |
162 |
|
163 |
public void join() { |
164 |
VectorialLayerEdited vle = getVLE(); |
165 |
FeatureStore featureStore = null;
|
166 |
try {
|
167 |
featureStore = vle.getFeatureStore(); |
168 |
} catch (ReadException e1) {
|
169 |
NotificationManager.addError(e1.getMessage(),e1); |
170 |
} |
171 |
DisposableIterator iterator = null;
|
172 |
try {
|
173 |
featureStore.beginEditingGroup(getName()); |
174 |
|
175 |
FeatureSelection selection = featureStore.createFeatureSelection(); |
176 |
selection.select((FeatureSet) featureStore.getSelection()); |
177 |
|
178 |
Geometry geomTotal = null;
|
179 |
iterator = selection.fastIterator(); |
180 |
boolean first = true; |
181 |
Feature firstFeature = null;
|
182 |
while (iterator.hasNext()) {
|
183 |
Feature feature = (Feature) iterator.next(); |
184 |
if (first){
|
185 |
firstFeature = feature; |
186 |
first = false;
|
187 |
} |
188 |
|
189 |
Geometry currentGeometry = feature.getDefaultGeometry().cloneGeometry(); |
190 |
featureStore.delete(feature); |
191 |
if (geomTotal == null){ |
192 |
geomTotal = currentGeometry; |
193 |
}else{
|
194 |
geomTotal = geomTotal.union(currentGeometry); |
195 |
} |
196 |
} |
197 |
|
198 |
EditableFeature editableFeature = featureStore.createNewFeature(firstFeature.getType(), firstFeature); |
199 |
editableFeature.setGeometry(featureStore.getDefaultFeatureType().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 |
public boolean isApplicable(int shapeType) { |
246 |
switch (shapeType) {
|
247 |
case org.gvsig.fmap.geom.Geometry.TYPES.POINT:
|
248 |
return false; |
249 |
} |
250 |
return true; |
251 |
} |
252 |
} |