Revision 35732
branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/JoinCADTool.java | ||
---|---|---|
51 | 51 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
52 | 52 |
import org.gvsig.fmap.dal.exception.DataException; |
53 | 53 |
import org.gvsig.fmap.dal.exception.ReadException; |
54 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
55 | 54 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
56 | 55 |
import org.gvsig.fmap.dal.feature.Feature; |
56 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
57 | 57 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
58 | 58 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
59 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
59 |
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException; |
|
60 |
import org.gvsig.fmap.geom.Geometry; |
|
60 | 61 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
61 | 62 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
62 |
import org.gvsig.fmap.geom.operation.tojts.ToJTS; |
|
63 |
import org.gvsig.fmap.geom.util.Converter; |
|
64 | 63 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
64 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
65 | 65 |
|
66 |
import com.vividsolutions.jts.geom.Geometry; |
|
67 | 66 |
|
68 |
|
|
69 | 67 |
/** |
70 | 68 |
* DOCUMENT ME! |
71 | 69 |
* |
... | ... | |
106 | 104 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String) |
107 | 105 |
*/ |
108 | 106 |
public void transition(String s) throws CommandException { |
109 |
if (!super.changeCommand(s)){
|
|
110 |
_fsm.addOption(s);
|
|
111 |
}
|
|
107 |
if (!super.changeCommand(s)){
|
|
108 |
_fsm.addOption(s);
|
|
109 |
}
|
|
112 | 110 |
} |
113 | 111 |
|
114 | 112 |
/** |
115 | 113 |
* DOCUMENT ME! |
116 | 114 |
*/ |
117 | 115 |
public void selection() { |
118 |
FeatureSet selection = null;
|
|
119 |
try {
|
|
120 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection();
|
|
116 |
FeatureSet selection = null;
|
|
117 |
try {
|
|
118 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection();
|
|
121 | 119 |
|
122 |
if (selection.getSize() == 0
|
|
123 |
&& !CADExtension
|
|
124 |
.getCADTool()
|
|
125 |
.getClass()
|
|
126 |
.getName()
|
|
127 |
.equals(
|
|
128 |
"com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
|
129 |
CADExtension.setCADTool("_selection", false);
|
|
130 |
((SelectionCADTool) CADExtension.getCADTool())
|
|
131 |
.setNextTool("_join");
|
|
132 |
}
|
|
133 |
} catch (ReadException e) {
|
|
134 |
// TODO Auto-generated catch block
|
|
135 |
e.printStackTrace();
|
|
136 |
} catch (DataException e) {
|
|
137 |
// TODO Auto-generated catch block
|
|
138 |
e.printStackTrace();
|
|
139 |
}
|
|
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 |
}
|
|
140 | 138 |
} |
141 | 139 |
|
142 | 140 |
/** |
... | ... | |
147 | 145 |
* @param y par?metro y del punto que se pase en esta transici?n. |
148 | 146 |
*/ |
149 | 147 |
public void addPoint(double x, double y,InputEvent event) { |
148 |
|
|
150 | 149 |
} |
151 | 150 |
|
152 | 151 |
/** |
... | ... | |
158 | 157 |
* @param y par?metro x del punto que se pase para dibujar. |
159 | 158 |
*/ |
160 | 159 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
160 |
|
|
161 | 161 |
} |
162 |
|
|
162 | 163 |
public void join() { |
163 |
VectorialLayerEdited vle = getVLE(); |
|
164 |
FeatureStore featureStore = null; |
|
165 |
try { |
|
166 |
featureStore = vle.getFeatureStore(); |
|
167 |
} catch (ReadException e1) { |
|
168 |
NotificationManager.addError(e1.getMessage(),e1); |
|
169 |
} |
|
170 |
DisposableIterator features = null; |
|
171 |
try { |
|
172 |
FeatureSet selection = (FeatureSet) featureStore.getSelection(); |
|
173 |
// getSelectedRows(); |
|
174 |
featureStore.beginEditingGroup(getName()); |
|
175 |
Geometry geomTotal=null; |
|
176 |
features = selection.iterator(); |
|
177 |
boolean first=true; |
|
178 |
Feature firstFeature=null; |
|
179 |
while (features.hasNext()) { |
|
180 |
Feature feature = (Feature) features.next(); |
|
181 |
if (first){ |
|
182 |
firstFeature=feature; |
|
183 |
first=false; |
|
184 |
} |
|
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()); |
|
185 | 177 |
|
186 |
org.gvsig.fmap.geom.Geometry geom = (feature
|
|
187 |
.getDefaultGeometry()).cloneGeometry();
|
|
188 |
featureStore.delete(feature);
|
|
189 |
if (geomTotal==null){
|
|
190 |
geomTotal=(Geometry)geom.invokeOperation(ToJTS.CODE, null);
|
|
191 |
}else{
|
|
192 |
Geometry geomJTS=(Geometry)geom.invokeOperation(ToJTS.CODE, null);
|
|
193 |
geomTotal=geomTotal.union(geomJTS);
|
|
194 |
}
|
|
195 |
}
|
|
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 |
}
|
|
196 | 188 |
|
197 |
EditableFeature eFeature = featureStore.createNewFeature(firstFeature |
|
198 |
.getType(), firstFeature); |
|
199 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
|
200 |
.getDefaultGeometryAttributeName(), Converter.jtsToGeometry(geomTotal)); |
|
201 |
featureStore.insert(eFeature); |
|
202 |
refresh(); |
|
203 |
} catch (DataException e) { |
|
204 |
NotificationManager.addError(e.getMessage(),e); |
|
205 |
} catch (GeometryOperationNotSupportedException e) { |
|
206 |
NotificationManager.addError(e.getMessage(),e); |
|
207 |
} catch (GeometryOperationException e) { |
|
208 |
NotificationManager.addError(e.getMessage(),e); |
|
209 |
} catch (CreateGeometryException e) { |
|
210 |
NotificationManager.addError(e.getMessage(),e); |
|
211 |
} finally { |
|
212 |
if (features != null) { |
|
213 |
features.dispose(); |
|
214 |
} |
|
215 |
} |
|
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 |
} |
|
216 | 218 |
} |
217 |
/** |
|
218 |
* Add a diferent option. |
|
219 |
* |
|
220 |
* @param s |
|
221 |
* Diferent option. |
|
222 |
*/ |
|
219 |
|
|
220 |
/** |
|
221 |
* Add a diferent option. |
|
222 |
* |
|
223 |
* @param s |
|
224 |
* Diferent option. |
|
225 |
*/ |
|
223 | 226 |
public void addOption(String s) { |
224 | 227 |
} |
225 | 228 |
|
226 | 229 |
/* |
227 |
* (non-Javadoc)
|
|
228 |
*
|
|
229 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
|
230 |
*/
|
|
230 |
* (non-Javadoc)
|
|
231 |
*
|
|
232 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
|
233 |
*/
|
|
231 | 234 |
public void addValue(double d) { |
232 | 235 |
|
233 | 236 |
} |
234 | 237 |
|
235 |
public String getName() {
|
|
236 |
return PluginServices.getText(this,"join_");
|
|
237 |
}
|
|
238 |
public String getName() {
|
|
239 |
return PluginServices.getText(this,"join_");
|
|
240 |
}
|
|
238 | 241 |
|
239 |
public String toString() {
|
|
240 |
return "_join";
|
|
241 |
}
|
|
242 |
public boolean isApplicable(int shapeType) {
|
|
243 |
switch (shapeType) {
|
|
244 |
case org.gvsig.fmap.geom.Geometry.TYPES.POINT:
|
|
245 |
return false;
|
|
246 |
}
|
|
247 |
return true;
|
|
248 |
}
|
|
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 |
}
|
|
249 | 252 |
} |
Also available in: Unified diff