Revision 23086 branches/v2_0_0_prep/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/EditVertexCADTool.java
EditVertexCADTool.java | ||
---|---|---|
52 | 52 |
import javax.swing.JOptionPane; |
53 | 53 |
|
54 | 54 |
import org.gvsig.fmap.data.ReadException; |
55 |
import org.gvsig.fmap.data.feature.Feature; |
|
56 |
import org.gvsig.fmap.data.feature.FeatureCollection; |
|
57 |
import org.gvsig.fmap.data.feature.FeatureStore; |
|
55 | 58 |
import org.gvsig.fmap.geom.Geometry; |
56 | 59 |
import org.gvsig.fmap.geom.GeometryFactory; |
57 | 60 |
import org.gvsig.fmap.geom.GeometryManager; |
61 |
import org.gvsig.fmap.geom.aggregate.BaseMultiPrimitive; |
|
58 | 62 |
import org.gvsig.fmap.geom.handler.Handler; |
59 | 63 |
import org.gvsig.fmap.geom.primitive.Curve2D; |
60 | 64 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
... | ... | |
71 | 75 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EditVertexCADToolContext; |
72 | 76 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EditVertexCADToolContext.EditVertexCADToolState; |
73 | 77 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
74 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
75 | 78 |
|
76 | 79 |
|
77 | 80 |
/** |
... | ... | |
127 | 130 |
* DOCUMENT ME! |
128 | 131 |
*/ |
129 | 132 |
public void selection() { |
130 |
ArrayList selectedRow=getSelectedRows(); |
|
131 |
if (selectedRow.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
133 |
FeatureCollection selection=null; |
|
134 |
try { |
|
135 |
selection = (FeatureCollection)getVLE().getFeatureStore().getSelection(); |
|
136 |
} catch (ReadException e) { |
|
137 |
// TODO Auto-generated catch block |
|
138 |
e.printStackTrace(); |
|
139 |
} |
|
140 |
if (selection.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
132 | 141 |
CADExtension.setCADTool("_selection",false); |
133 | 142 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
134 | 143 |
"_editvertex"); |
... | ... | |
148 | 157 |
} |
149 | 158 |
|
150 | 159 |
private Geometry getSelectedGeometry() { |
151 |
ArrayList selectedRows=getSelectedRows(); |
|
152 |
// VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter(); |
|
153 |
// FBitSet selection = vea.getSelection(); |
|
154 |
IRowEdited row=null; |
|
155 |
IGeometry ig=null; |
|
156 |
if (selectedRows.size()==1){ |
|
157 |
row=(DefaultRowEdited) selectedRows.get(0); |
|
158 |
//row = getCadToolAdapter().getVectorialAdapter().getRow(selection.nextSetBit(0)); |
|
159 |
ig=((IFeature)row.getLinkedRow()).getGeometry().cloneGeometry(); |
|
160 |
return ig; |
|
161 |
} |
|
160 |
FeatureCollection selection=null; |
|
161 |
try { |
|
162 |
selection = (FeatureCollection)getVLE().getFeatureStore().getSelection(); |
|
162 | 163 |
|
163 |
return null; |
|
164 |
} |
|
164 |
Feature feature=null; |
|
165 |
Geometry ig=null; |
|
166 |
if (selection.size()==1){ |
|
167 |
feature=selection.getFeature(0); |
|
168 |
//row = getCadToolAdapter().getVectorialAdapter().getRow(selection.nextSetBit(0)); |
|
169 |
ig=((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
|
170 |
return ig; |
|
171 |
} |
|
172 |
} catch (ReadException e) { |
|
173 |
// TODO Auto-generated catch block |
|
174 |
e.printStackTrace(); |
|
175 |
} |
|
165 | 176 |
|
177 |
return null; |
|
178 |
} |
|
179 |
|
|
166 | 180 |
/** |
167 | 181 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
168 | 182 |
* encontremos. |
... | ... | |
184 | 198 |
EditVertexCADToolState actualState = (EditVertexCADToolState) _fsm.getPreviousState(); |
185 | 199 |
String status = actualState.getName(); |
186 | 200 |
VectorialLayerEdited vle=getVLE(); |
187 |
VectorialEditableAdapter vea = vle.getVEA();
|
|
188 |
ArrayList selectedRows=vle.getSelectedRow();
|
|
189 |
IRowEdited row=null;
|
|
190 |
IGeometry ig=null;
|
|
201 |
FeatureStore featureStore=vle.getFeatureStore();
|
|
202 |
FeatureCollection selection=(FeatureCollection)featureStore.getSelection();
|
|
203 |
Feature feature=null;
|
|
204 |
Geometry ig=null; |
|
191 | 205 |
Handler[] handlers=null; |
192 |
if (selectedRows.size()==1){
|
|
193 |
row = (DefaultRowEdited) selectedRows.get(0);
|
|
194 |
ig=((IFeature)row.getLinkedRow()).getGeometry().cloneGeometry();
|
|
195 |
handlers=ig.getHandlers(IGeometry.SELECTHANDLER);
|
|
206 |
if (selection.size()==1){
|
|
207 |
feature = selection.getFeature(0);
|
|
208 |
ig=((Geometry)feature.getDefaultGeometry()).cloneGeometry();
|
|
209 |
handlers=ig.getHandlers(Geometry.SELECTHANDLER); |
|
196 | 210 |
numHandlers=handlers.length; |
197 | 211 |
if (numHandlers ==0){ |
198 | 212 |
try { |
199 |
vea.removeRow(row.getIndex(),getName(),EditionEvent.GRAPHIC); |
|
213 |
featureStore.delete(feature); |
|
214 |
// vea.removeRow(row.getIndex(),getName(),EditionEvent.GRAPHIC); |
|
200 | 215 |
} catch (ReadException e) { |
201 | 216 |
NotificationManager.addError(e.getMessage(),e); |
202 | 217 |
} |
... | ... | |
205 | 220 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"hay_mas_de_una_geometria_seleccionada")); |
206 | 221 |
} |
207 | 222 |
int dif=1;//En el caso de ser pol?gono. |
208 |
if (ig instanceof GeometryCollection){
|
|
223 |
if (ig instanceof BaseMultiPrimitive){
|
|
209 | 224 |
dif=2; |
210 | 225 |
} |
211 | 226 |
if (status.equals("EditVertex.SelectVertexOrDelete")){ |
... | ... | |
223 | 238 |
}else if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.delvertex")) || s.equals(PluginServices.getText(this,"del"))){ |
224 | 239 |
if (handlers!=null){ |
225 | 240 |
Geometry newGeometry=null; |
226 |
if (ig instanceof GeometryCollection) {
|
|
227 |
newGeometry=removeVertexGC((FGeometryCollection)ig,handlers[numSelect]);
|
|
241 |
if (ig instanceof BaseMultiPrimitive) {
|
|
242 |
newGeometry=removeVertexGC((BaseMultiPrimitive)ig,handlers[numSelect]);
|
|
228 | 243 |
}else { |
229 | 244 |
newGeometry=removeVertex(ig,handlers,numSelect); |
230 | 245 |
} |
231 | 246 |
//numSelect=0; |
232 |
|
|
233 |
IRow newRow=new DefaultFeature(newGeometry,row.getAttributes(),row.getID()); |
|
247 |
feature.editing(); |
|
248 |
feature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometry(),ig); |
|
249 |
// IRow newRow=new DefaultFeature(newGeometry,row.getAttributes(),row.getID()); |
|
234 | 250 |
try { |
235 |
vea.modifyRow(row.getIndex(),newRow,getName(),EditionEvent.GRAPHIC); |
|
251 |
featureStore.update(feature); |
|
252 |
// vea.modifyRow(row.getIndex(),newRow,getName(),EditionEvent.GRAPHIC); |
|
236 | 253 |
clearSelection(); |
237 |
} catch (ValidateRowException e) { |
|
238 |
NotificationManager.addError(e.getMessage(),e); |
|
239 |
} catch (ExpansionFileWriteException e) { |
|
254 |
} catch (ReadException e) { |
|
240 | 255 |
NotificationManager.addError(e.getMessage(),e); |
241 |
} catch (ReadException e) { |
|
242 |
NotificationManager.addError(e.getMessage(),e); |
|
243 | 256 |
} |
244 |
vle.addSelectionCache(new DefaultRowEdited(newRow, |
|
245 |
IRowEdited.STATUS_MODIFIED, row.getIndex())); |
|
257 |
// vle.addSelectionCache(new DefaultRowEdited(newRow,
|
|
258 |
// IRowEdited.STATUS_MODIFIED, row.getIndex()));
|
|
246 | 259 |
|
247 | 260 |
// vle.refreshSelectionCache(new Point2D.Double(0,0),getCadToolAdapter()); |
248 | 261 |
// refresh(); |
Also available in: Unified diff