Revision 35954 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/ComplexSelectionCADTool.java
ComplexSelectionCADTool.java | ||
---|---|---|
56 | 56 |
import org.gvsig.editing.gui.cad.tools.smc.ComplexSelectionCADToolContext.ComplexSelectionCADToolState; |
57 | 57 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
58 | 58 |
import org.gvsig.fmap.dal.exception.DataException; |
59 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
60 | 59 |
import org.gvsig.fmap.dal.exception.ReadException; |
61 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
62 | 60 |
import org.gvsig.fmap.dal.feature.Feature; |
63 | 61 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
64 | 62 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
65 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
66 | 63 |
import org.gvsig.fmap.geom.Geometry; |
67 | 64 |
import org.gvsig.fmap.geom.handler.Handler; |
68 | 65 |
import org.gvsig.fmap.geom.primitive.Curve; |
... | ... | |
72 | 69 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
73 | 70 |
import org.gvsig.fmap.mapcontrol.MapControl; |
74 | 71 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
75 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
76 | 72 |
|
77 | 73 |
|
78 | 74 |
/** |
... | ... | |
133 | 129 |
firstPoint = new Point2D.Double(x, y); |
134 | 130 |
pointsPolygon.add(firstPoint); |
135 | 131 |
} else if (status.equals("Selection.SecondPoint")) { |
136 |
} else if (status.equals("Selection.WithFeatures")) { |
|
132 |
|
|
133 |
} else if (status.equals("Selection.WithSelectedFeatures")) { |
|
134 |
|
|
137 | 135 |
} else if (status.equals("Selection.WithHandlers")) { |
138 | 136 |
FeatureStore featureStore = null; |
139 | 137 |
try { |
... | ... | |
148 | 146 |
} |
149 | 147 |
} |
150 | 148 |
|
151 |
/** |
|
152 |
* AddPoint method for the WithHandlers option |
|
153 |
* @param x |
|
154 |
* selected x coordinate. |
|
155 |
* @param y |
|
156 |
* selected y coordinate. |
|
157 |
* @param featureStore |
|
158 |
* the selected feature store. |
|
159 |
* @param selectedHandlers |
|
160 |
* the selected handlers |
|
161 |
*/ |
|
162 |
private void addPointWithHandlers(double x, double y, FeatureStore featureStore, ArrayList selectedHandlers){ |
|
163 |
String description = PluginServices.getText(this, "move_handlers"); |
|
164 |
DisposableIterator iterator = null; |
|
165 |
try { |
|
166 |
featureStore.beginEditingGroup(description); |
|
167 |
ArrayList selectedRowsAux = new ArrayList(); |
|
149 |
|
|
168 | 150 |
|
169 |
iterator = ((FeatureSelection) featureStore.getSelection()).fastIterator(); |
|
170 |
|
|
171 |
while (iterator.hasNext()) { |
|
172 |
Feature feature = (Feature) iterator.next(); |
|
173 |
|
|
174 |
// } |
|
175 |
Geometry ig = (feature.getDefaultGeometry()) |
|
176 |
.cloneGeometry(); |
|
177 |
// Movemos los handlers que hemos seleccionado |
|
178 |
// previamente dentro del m?todo select() |
|
179 |
Handler[] handlers = ig.getHandlers(Geometry.SELECTHANDLER); |
|
180 |
for (int k = 0; k < selectedHandlers.size(); k++) { |
|
181 |
Handler h = (Handler) selectedHandlers.get(k); |
|
182 |
for (int j = 0; j < handlers.length; j++) { |
|
183 |
if (h.getPoint().equals(handlers[j].getPoint())) { |
|
184 |
handlers[j].set(x, y); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
EditableFeature eFeature = feature.getEditable(); |
|
189 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
|
190 |
.getDefaultGeometryAttributeName(), ig); |
|
191 |
featureStore.update(eFeature); |
|
192 |
selectedRowsAux.add(eFeature); |
|
193 |
} |
|
194 |
|
|
195 |
firstPoint = new Point2D.Double(x, y); |
|
196 |
// vle.setSelectionCache(VectorialLayerEdited.SAVEPREVIOUS, |
|
197 |
// selectedRowsAux); |
|
198 |
|
|
199 |
featureStore.endEditingGroup(); |
|
200 |
} catch (DataException e1) { |
|
201 |
LOG.error("Error reading the store", e1); |
|
202 |
} finally { |
|
203 |
if (iterator != null) { |
|
204 |
iterator.dispose(); |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
|
|
209 | 151 |
/** |
210 | 152 |
* Receives second point |
211 | 153 |
* |
... | ... | |
533 | 475 |
} |
534 | 476 |
} |
535 | 477 |
|
536 |
public int selectHandlers(double x, double y, InputEvent event) { |
|
537 |
Point2D auxPoint = new Point2D.Double(x, y); |
|
538 |
|
|
539 |
VectorialLayerEdited vle = getVLE(); |
|
540 |
ArrayList selectedHandler = vle.getSelectedHandler(); |
|
541 |
selectedHandler.clear(); |
|
542 |
|
|
543 |
// Se comprueba si se pincha en una gemometr?a |
|
544 |
PluginServices.getMDIManager().setWaitCursor(); |
|
545 |
|
|
546 |
double tam = getCadToolAdapter().getMapControl().getViewPort() |
|
547 |
.toMapDistance(mapControlManager.getTolerance()); |
|
548 |
|
|
549 |
Handler[] handlers = null; |
|
550 |
rowselectedHandlers.clear(); |
|
551 |
FeatureStore featureStore = null; |
|
552 |
try { |
|
553 |
featureStore = vle.getFeatureStore(); |
|
554 |
} catch (ReadException e) { |
|
555 |
LOG.error("Error reading the store", e); |
|
556 |
} |
|
557 |
DisposableIterator iterator = null; |
|
558 |
try { |
|
559 |
iterator = ((FeatureSelection) featureStore.getSelection()).fastIterator(); |
|
560 |
while (iterator.hasNext()) { |
|
561 |
Feature feature = (Feature) iterator.next(); |
|
562 |
|
|
563 |
Geometry geom = (feature.getDefaultGeometry()).cloneGeometry(); |
|
564 |
handlers = geom.getHandlers(Geometry.SELECTHANDLER); |
|
565 |
// y miramos los handlers de cada entidad seleccionada |
|
566 |
double min = tam; |
|
567 |
|
|
568 |
for (int j = 0; j < handlers.length; j++) { |
|
569 |
Point2D handlerPoint = handlers[j].getPoint(); |
|
570 |
double distance = auxPoint.distance(handlerPoint); |
|
571 |
if (distance <= min) { |
|
572 |
min = distance; |
|
573 |
selectedHandler.add(handlers[j]); |
|
574 |
EditableFeature eFeature; |
|
575 |
try { |
|
576 |
eFeature = featureStore.createNewFeature(false); |
|
577 |
FeatureType featureType = featureStore |
|
578 |
.getDefaultFeatureType(); |
|
579 |
for (int i = 0; i < featureType.size(); i++) { |
|
580 |
eFeature.set(i, feature.get(i)); |
|
581 |
} |
|
582 |
eFeature.setGeometry(featureType |
|
583 |
.getDefaultGeometryAttributeName(), geom); |
|
584 |
} catch (InitializeException e) { |
|
585 |
LOG.error("Error reading the store", e); |
|
586 |
} catch (DataException e) { |
|
587 |
LOG.error("Error reading the store", e); |
|
588 |
} |
|
589 |
rowselectedHandlers.add(feature); |
|
590 |
} |
|
591 |
} |
|
592 |
} |
|
593 |
} catch (DataException e1) { |
|
594 |
LOG.error("Error reading the store", e1); |
|
595 |
} finally { |
|
596 |
if (iterator != null) { |
|
597 |
iterator.dispose(); |
|
598 |
} |
|
599 |
} |
|
600 |
|
|
601 |
PluginServices.getMDIManager().restoreCursor(); |
|
602 |
|
|
603 |
int numHandlesSelected = selectedHandler.size(); |
|
604 |
|
|
605 |
/* |
|
606 |
* if (numHandlesSelected == 0) selectFeatures(x,y); |
|
607 |
*/ |
|
608 |
|
|
609 |
return numHandlesSelected; |
|
610 |
} |
|
611 |
|
|
612 | 478 |
public String getType() { |
613 | 479 |
return type; |
614 | 480 |
} |
Also available in: Unified diff