Revision 24429 branches/v2_0_0_prep/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/ScaleCADTool.java
ScaleCADTool.java | ||
---|---|---|
53 | 53 |
|
54 | 54 |
import org.gvsig.fmap.data.exceptions.DataException; |
55 | 55 |
import org.gvsig.fmap.data.exceptions.ReadException; |
56 |
import org.gvsig.fmap.data.feature.EditableFeature; |
|
56 | 57 |
import org.gvsig.fmap.data.feature.Feature; |
57 | 58 |
import org.gvsig.fmap.data.feature.FeatureSelection; |
58 | 59 |
import org.gvsig.fmap.data.feature.FeatureSet; |
... | ... | |
75 | 76 |
import com.iver.cit.gvsig.gui.cad.tools.smc.ScaleCADToolContext.ScaleCADToolState; |
76 | 77 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
77 | 78 |
|
78 |
|
|
79 | 79 |
/** |
80 | 80 |
* DOCUMENT ME! |
81 | 81 |
* |
82 | 82 |
* @author Vicente Caballero Navarro |
83 | 83 |
*/ |
84 | 84 |
public class ScaleCADTool extends DefaultCADTool { |
85 |
private ScaleCADToolContext _fsm;
|
|
86 |
private Point2D firstPoint;
|
|
87 |
private Point2D lastPoint;
|
|
85 |
private ScaleCADToolContext _fsm;
|
|
86 |
private Point2D firstPoint;
|
|
87 |
private Point2D lastPoint;
|
|
88 | 88 |
private Point2D scalePoint; |
89 | 89 |
private Double orr; |
90 | 90 |
private Double frr; |
91 | 91 |
private Double ore; |
92 | 92 |
private Double fre; |
93 | 93 |
|
94 |
/**
|
|
95 |
* Crea un nuevo PolylineCADTool.
|
|
96 |
*/
|
|
97 |
public ScaleCADTool() {
|
|
98 |
}
|
|
94 |
/**
|
|
95 |
* Crea un nuevo PolylineCADTool.
|
|
96 |
*/
|
|
97 |
public ScaleCADTool() {
|
|
98 |
}
|
|
99 | 99 |
|
100 |
/**
|
|
101 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
|
102 |
* carga previa a la utilizaci?n de la herramienta.
|
|
103 |
*/
|
|
104 |
public void init() {
|
|
105 |
_fsm = new ScaleCADToolContext(this);
|
|
106 |
}
|
|
100 |
/**
|
|
101 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
|
102 |
* carga previa a la utilizaci?n de la herramienta.
|
|
103 |
*/
|
|
104 |
public void init() {
|
|
105 |
_fsm = new ScaleCADToolContext(this);
|
|
106 |
}
|
|
107 | 107 |
|
108 |
/* (non-Javadoc) |
|
109 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double) |
|
110 |
*/ |
|
111 |
public void transition(double x, double y, InputEvent event) { |
|
112 |
_fsm.addPoint(x, y, event); |
|
113 |
} |
|
108 |
/* |
|
109 |
* (non-Javadoc) |
|
110 |
* |
|
111 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, |
|
112 |
* double, double) |
|
113 |
*/ |
|
114 |
public void transition(double x, double y, InputEvent event) { |
|
115 |
_fsm.addPoint(x, y, event); |
|
116 |
} |
|
114 | 117 |
|
115 |
/* (non-Javadoc) |
|
116 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double) |
|
117 |
*/ |
|
118 |
public void transition(double d) { |
|
119 |
_fsm.addValue(d); |
|
120 |
} |
|
118 |
/* |
|
119 |
* (non-Javadoc) |
|
120 |
* |
|
121 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, |
|
122 |
* double) |
|
123 |
*/ |
|
124 |
public void transition(double d) { |
|
125 |
_fsm.addValue(d); |
|
126 |
} |
|
121 | 127 |
|
122 |
/* (non-Javadoc) |
|
123 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String) |
|
124 |
*/ |
|
125 |
public void transition(String s) throws CommandException { |
|
126 |
if (!super.changeCommand(s)){ |
|
127 |
_fsm.addOption(s); |
|
128 |
} |
|
129 |
} |
|
128 |
/* |
|
129 |
* (non-Javadoc) |
|
130 |
* |
|
131 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, |
|
132 |
* java.lang.String) |
|
133 |
*/ |
|
134 |
public void transition(String s) throws CommandException { |
|
135 |
if (!super.changeCommand(s)) { |
|
136 |
_fsm.addOption(s); |
|
137 |
} |
|
138 |
} |
|
130 | 139 |
|
131 |
/** |
|
132 |
* DOCUMENT ME! |
|
133 |
*/ |
|
134 |
public void selection() { |
|
135 |
FeatureSet selection=null; |
|
136 |
try { |
|
137 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
|
138 |
} catch (ReadException e) { |
|
139 |
// TODO Auto-generated catch block |
|
140 |
e.printStackTrace(); |
|
141 |
} |
|
142 |
if (selection.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
143 |
CADExtension.setCADTool("_selection",false); |
|
144 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
|
145 |
"_scale"); |
|
146 |
} |
|
147 |
} |
|
140 |
/** |
|
141 |
* DOCUMENT ME! |
|
142 |
*/ |
|
143 |
public void selection() { |
|
144 |
FeatureSet selection = null; |
|
145 |
try { |
|
146 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
|
147 |
if (selection.getSize() == 0 |
|
148 |
&& !CADExtension |
|
149 |
.getCADTool() |
|
150 |
.getClass() |
|
151 |
.getName() |
|
152 |
.equals( |
|
153 |
"com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
154 |
CADExtension.setCADTool("_selection", false); |
|
155 |
((SelectionCADTool) CADExtension.getCADTool()) |
|
156 |
.setNextTool("_scale"); |
|
157 |
} |
|
158 |
} catch (ReadException e) { |
|
159 |
// TODO Auto-generated catch block |
|
160 |
e.printStackTrace(); |
|
161 |
} catch (DataException e) { |
|
162 |
// TODO Auto-generated catch block |
|
163 |
e.printStackTrace(); |
|
164 |
} |
|
165 |
} |
|
148 | 166 |
|
149 |
/** |
|
150 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el |
|
151 |
* editableFeatureSource que ya estar? creado. |
|
152 |
* |
|
153 |
* @param x par?metro x del punto que se pase en esta transici?n. |
|
154 |
* @param y par?metro y del punto que se pase en esta transici?n. |
|
155 |
*/ |
|
156 |
public void addPoint(double x, double y,InputEvent event) { |
|
157 |
ScaleCADToolState actualState = (ScaleCADToolState) _fsm.getPreviousState(); |
|
158 |
String status = actualState.getName(); |
|
167 |
/** |
|
168 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el |
|
169 |
* editableFeatureSource que ya estar? creado. |
|
170 |
* |
|
171 |
* @param x |
|
172 |
* par?metro x del punto que se pase en esta transici?n. |
|
173 |
* @param y |
|
174 |
* par?metro y del punto que se pase en esta transici?n. |
|
175 |
*/ |
|
176 |
public void addPoint(double x, double y, InputEvent event) { |
|
177 |
ScaleCADToolState actualState = (ScaleCADToolState) _fsm |
|
178 |
.getPreviousState(); |
|
179 |
String status = actualState.getName(); |
|
159 | 180 |
|
160 |
if (status.equals("Scale.PointMain")) {
|
|
161 |
firstPoint = new Point2D.Double(x, y);
|
|
162 |
scalePoint = firstPoint;
|
|
181 |
if (status.equals("Scale.PointMain")) {
|
|
182 |
firstPoint = new Point2D.Double(x, y); |
|
183 |
scalePoint = firstPoint; |
|
163 | 184 |
} else if (status.equals("Scale.ScaleFactorOrReference")) { |
164 | 185 |
PluginServices.getMDIManager().setWaitCursor(); |
165 | 186 |
lastPoint = new Point2D.Double(x, y); |
166 | 187 |
|
167 |
//double w; |
|
168 |
//double h; |
|
169 |
//w = lastPoint.getX() - firstPoint.getX(); |
|
170 |
//h = lastPoint.getY() - firstPoint.getY(); |
|
188 |
// double w;
|
|
189 |
// double h;
|
|
190 |
// w = lastPoint.getX() - firstPoint.getX();
|
|
191 |
// h = lastPoint.getY() - firstPoint.getY();
|
|
171 | 192 |
|
172 | 193 |
try { |
173 |
double size=getCadToolAdapter().getMapControl().getViewPort().toMapDistance(getCadToolAdapter().getMapControl().getWidth()); |
|
174 |
scale(firstPoint.distance(lastPoint)/(size/40)); |
|
194 |
double size = getCadToolAdapter().getMapControl().getViewPort() |
|
195 |
.toMapDistance( |
|
196 |
getCadToolAdapter().getMapControl().getWidth()); |
|
197 |
scale(firstPoint.distance(lastPoint) / (size / 40)); |
|
175 | 198 |
} catch (ReadException e) { |
176 |
NotificationManager.addError(e.getMessage(),e); |
|
199 |
NotificationManager.addError(e.getMessage(), e);
|
|
177 | 200 |
} |
178 | 201 |
|
179 | 202 |
PluginServices.getMDIManager().restoreCursor(); |
... | ... | |
194 | 217 |
try { |
195 | 218 |
scale(escalado); |
196 | 219 |
} catch (ReadException e) { |
197 |
NotificationManager.addError(e.getMessage(),e); |
|
220 |
NotificationManager.addError(e.getMessage(), e);
|
|
198 | 221 |
} |
199 | 222 |
} |
200 | 223 |
|
201 |
}
|
|
224 |
}
|
|
202 | 225 |
|
203 |
/** |
|
204 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
|
205 |
* encontremos. |
|
206 |
* |
|
207 |
* @param g Graphics sobre el que dibujar. |
|
208 |
* @param x par?metro x del punto que se pase para dibujar. |
|
209 |
* @param y par?metro x del punto que se pase para dibujar. |
|
210 |
*/ |
|
211 |
public void drawOperation(Graphics g, double x, double y) { |
|
226 |
/** |
|
227 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
|
228 |
* encontremos. |
|
229 |
* |
|
230 |
* @param g |
|
231 |
* Graphics sobre el que dibujar. |
|
232 |
* @param x |
|
233 |
* par?metro x del punto que se pase para dibujar. |
|
234 |
* @param y |
|
235 |
* par?metro x del punto que se pase para dibujar. |
|
236 |
*/ |
|
237 |
public void drawOperation(Graphics g, double x, double y) { |
|
212 | 238 |
ScaleCADToolState actualState = _fsm.getState(); |
213 | 239 |
String status = actualState.getName(); |
214 |
FeatureSet selection=null;
|
|
240 |
FeatureSet selection = null;
|
|
215 | 241 |
try { |
216 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
|
242 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection();
|
|
217 | 243 |
|
218 |
// ArrayList selectedRow = getSelectedRows(); |
|
219 |
Point2D currentPoint = new Point2D.Double(x, y); |
|
220 |
long selectionCount=selection.getSize(); |
|
221 |
if (status.equals("Scale.ScaleFactorOrReference")) { |
|
222 |
VectorialLayerEdited vle = getVLE(); |
|
223 |
ViewPort vp = vle.getLayer().getMapContext().getViewPort(); |
|
224 |
Point2D point = vp.fromMapPoint(firstPoint.getX(), firstPoint |
|
225 |
.getY()); |
|
226 |
double size = getCadToolAdapter().getMapControl().getViewPort() |
|
227 |
.toMapDistance( |
|
228 |
getCadToolAdapter().getMapControl().getWidth()); |
|
229 |
double scale = firstPoint.distance(currentPoint) / (size / 40); |
|
230 |
drawLine((Graphics2D) g, firstPoint, currentPoint,DefaultCADTool.axisReferencesSymbol); |
|
244 |
// ArrayList selectedRow = getSelectedRows(); |
|
245 |
Point2D currentPoint = new Point2D.Double(x, y); |
|
246 |
long selectionCount = selection.getSize(); |
|
247 |
if (status.equals("Scale.ScaleFactorOrReference")) { |
|
248 |
VectorialLayerEdited vle = getVLE(); |
|
249 |
ViewPort vp = vle.getLayer().getMapContext().getViewPort(); |
|
250 |
Point2D point = vp.fromMapPoint(firstPoint.getX(), firstPoint |
|
251 |
.getY()); |
|
252 |
double size = getCadToolAdapter().getMapControl().getViewPort() |
|
253 |
.toMapDistance( |
|
254 |
getCadToolAdapter().getMapControl().getWidth()); |
|
255 |
double scale = firstPoint.distance(currentPoint) / (size / 40); |
|
256 |
drawLine((Graphics2D) g, firstPoint, currentPoint, |
|
257 |
DefaultCADTool.axisReferencesSymbol); |
|
231 | 258 |
|
232 |
if (selectionCount < CADTool.TOPGEOMETRY) { |
|
233 |
Iterator iterator=selection.iterator();
|
|
234 |
while (iterator.hasNext()) { |
|
235 |
Feature feature = (Feature) iterator.next(); |
|
259 |
if (selectionCount < CADTool.TOPGEOMETRY) {
|
|
260 |
Iterator iterator = selection.iterator();
|
|
261 |
while (iterator.hasNext()) {
|
|
262 |
Feature feature = (Feature) iterator.next();
|
|
236 | 263 |
|
237 |
// } |
|
238 |
// for (int i = 0; i < selectionCount; i++) { |
|
239 |
// DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited) selectedRow |
|
240 |
// .get(i)).getLinkedRow(); |
|
241 |
Geometry geometry = ((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
|
264 |
// } |
|
265 |
// for (int i = 0; i < selectionCount; i++) { |
|
266 |
// DefaultFeature fea = (DefaultFeature) |
|
267 |
// ((DefaultRowEdited) selectedRow |
|
268 |
// .get(i)).getLinkedRow(); |
|
269 |
Geometry geometry = ((Geometry) feature |
|
270 |
.getDefaultGeometry()).cloneGeometry(); |
|
242 | 271 |
|
243 |
UtilFunctions.scaleGeom(geometry, firstPoint, scale, scale); |
|
272 |
UtilFunctions.scaleGeom(geometry, firstPoint, scale, |
|
273 |
scale); |
|
244 | 274 |
|
245 |
DrawOperationContext doc=new DrawOperationContext(); |
|
246 |
doc.setGraphics((Graphics2D)g); |
|
247 |
doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
|
248 |
doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
|
249 |
try { |
|
250 |
geometry.invokeOperation(Draw.CODE,doc); |
|
251 |
} catch (GeometryOperationNotSupportedException e) { |
|
252 |
e.printStackTrace(); |
|
253 |
} catch (GeometryOperationException e) { |
|
254 |
e.printStackTrace(); |
|
255 |
} |
|
275 |
DrawOperationContext doc = new DrawOperationContext(); |
|
276 |
doc.setGraphics((Graphics2D) g); |
|
277 |
doc.setViewPort(getCadToolAdapter().getMapControl() |
|
278 |
.getViewPort()); |
|
279 |
doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
|
280 |
try { |
|
281 |
geometry.invokeOperation(Draw.CODE, doc); |
|
282 |
} catch (GeometryOperationNotSupportedException e) { |
|
283 |
e.printStackTrace(); |
|
284 |
} catch (GeometryOperationException e) { |
|
285 |
e.printStackTrace(); |
|
286 |
} |
|
256 | 287 |
|
257 |
// geometry.draw((Graphics2D) g, getCadToolAdapter()
|
|
258 |
// .getMapControl().getViewPort(),
|
|
259 |
// DefaultCADTool.axisReferencesSymbol);
|
|
288 |
// geometry.draw((Graphics2D) g, getCadToolAdapter()
|
|
289 |
// .getMapControl().getViewPort(),
|
|
290 |
// DefaultCADTool.axisReferencesSymbol);
|
|
260 | 291 |
|
261 |
} |
|
292 |
}
|
|
262 | 293 |
|
263 |
} else { |
|
264 |
AffineTransform at = new AffineTransform(); |
|
265 |
at.setToTranslation(point.getX(), point.getY()); |
|
266 |
at.scale(scale, scale); |
|
267 |
at.translate(-point.getX(), -point.getY()); |
|
268 |
Image imgSel = vle.getSelectionImage(); |
|
269 |
try { |
|
270 |
((Graphics2D) g).drawImage(imgSel, at, null); |
|
271 |
} catch (ImagingOpException e) { |
|
294 |
} else { |
|
295 |
AffineTransform at = new AffineTransform(); |
|
296 |
at.setToTranslation(point.getX(), point.getY()); |
|
297 |
at.scale(scale, scale); |
|
298 |
at.translate(-point.getX(), -point.getY()); |
|
299 |
Image imgSel = vle.getSelectionImage(); |
|
300 |
try { |
|
301 |
((Graphics2D) g).drawImage(imgSel, at, null); |
|
302 |
} catch (ImagingOpException e) { |
|
303 |
} |
|
272 | 304 |
} |
273 |
} |
|
274 |
PluginServices.getMainFrame().getStatusBar().setMessage("5", |
|
275 |
"Factor = " + scale); |
|
276 |
} else if (status.equals("Scale.EndPointScale")) { |
|
277 |
VectorialLayerEdited vle = getVLE(); |
|
278 |
ViewPort vp = vle.getLayer().getMapContext().getViewPort(); |
|
279 |
Point2D point = vp.fromMapPoint(scalePoint.getX(), scalePoint |
|
280 |
.getY()); |
|
305 |
PluginServices.getMainFrame().getStatusBar().setMessage("5", |
|
306 |
"Factor = " + scale); |
|
307 |
} else if (status.equals("Scale.EndPointScale")) { |
|
308 |
VectorialLayerEdited vle = getVLE(); |
|
309 |
ViewPort vp = vle.getLayer().getMapContext().getViewPort(); |
|
310 |
Point2D point = vp.fromMapPoint(scalePoint.getX(), scalePoint |
|
311 |
.getY()); |
|
281 | 312 |
|
282 |
double distrr = orr.distance(frr); |
|
283 |
double distre = ore.distance(currentPoint); |
|
284 |
double escalado = distre / distrr; |
|
285 |
if (selectionCount < CADTool.TOPGEOMETRY) { |
|
286 |
Iterator iterator=selection.iterator(); |
|
287 |
while (iterator.hasNext()) { |
|
288 |
Feature feature = (Feature) iterator.next(); |
|
289 |
// for (int i = 0; i < selectedRow.size(); i++) { |
|
290 |
// DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited) selectedRow |
|
291 |
// .get(i)).getLinkedRow(); |
|
292 |
Geometry geometry = ((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
|
313 |
double distrr = orr.distance(frr); |
|
314 |
double distre = ore.distance(currentPoint); |
|
315 |
double escalado = distre / distrr; |
|
316 |
if (selectionCount < CADTool.TOPGEOMETRY) { |
|
317 |
Iterator iterator = selection.iterator(); |
|
318 |
while (iterator.hasNext()) { |
|
319 |
Feature feature = (Feature) iterator.next(); |
|
320 |
// for (int i = 0; i < selectedRow.size(); i++) { |
|
321 |
// DefaultFeature fea = (DefaultFeature) |
|
322 |
// ((DefaultRowEdited) selectedRow |
|
323 |
// .get(i)).getLinkedRow(); |
|
324 |
Geometry geometry = ((Geometry) feature |
|
325 |
.getDefaultGeometry()).cloneGeometry(); |
|
293 | 326 |
UtilFunctions.scaleGeom(geometry, scalePoint, escalado, |
294 | 327 |
escalado); |
295 | 328 |
|
296 |
DrawOperationContext doc=new DrawOperationContext(); |
|
297 |
doc.setGraphics((Graphics2D)g); |
|
298 |
doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
|
299 |
doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
|
300 |
try { |
|
301 |
geometry.invokeOperation(Draw.CODE,doc); |
|
329 |
DrawOperationContext doc = new DrawOperationContext(); |
|
330 |
doc.setGraphics((Graphics2D) g); |
|
331 |
doc.setViewPort(getCadToolAdapter().getMapControl() |
|
332 |
.getViewPort()); |
|
333 |
doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
|
334 |
try { |
|
335 |
geometry.invokeOperation(Draw.CODE, doc); |
|
302 | 336 |
} catch (GeometryOperationNotSupportedException e) { |
303 | 337 |
e.printStackTrace(); |
304 | 338 |
} catch (GeometryOperationException e) { |
305 | 339 |
e.printStackTrace(); |
306 | 340 |
} |
307 | 341 |
|
308 |
// geometry.draw((Graphics2D) g, getCadToolAdapter()
|
|
309 |
// .getMapControl().getViewPort(),
|
|
310 |
// DefaultCADTool.axisReferencesSymbol);
|
|
342 |
// geometry.draw((Graphics2D) g, getCadToolAdapter()
|
|
343 |
// .getMapControl().getViewPort(),
|
|
344 |
// DefaultCADTool.axisReferencesSymbol);
|
|
311 | 345 |
|
312 | 346 |
} |
313 | 347 |
} else { |
... | ... | |
321 | 355 |
} catch (ImagingOpException e) { |
322 | 356 |
} |
323 | 357 |
} |
324 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y),DefaultCADTool.axisReferencesSymbol); |
|
358 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y), |
|
359 |
DefaultCADTool.axisReferencesSymbol); |
|
325 | 360 |
} |
326 | 361 |
} catch (ReadException e1) { |
327 | 362 |
// TODO Auto-generated catch block |
... | ... | |
332 | 367 |
} |
333 | 368 |
} |
334 | 369 |
|
335 |
/**
|
|
370 |
/**
|
|
336 | 371 |
* Add a diferent option. |
337 | 372 |
* |
338 | 373 |
* @param s |
339 | 374 |
* Diferent option. |
340 | 375 |
*/ |
341 |
public void addOption(String s) { |
|
342 |
ScaleCADToolState actualState = (ScaleCADToolState) _fsm.getPreviousState(); |
|
343 |
String status = actualState.getName(); |
|
344 |
if (status.equals("Scale.ScaleFactorOrReference")) { |
|
345 |
/* try { |
|
346 |
scale(2); |
|
347 |
} catch (DriverIOException e) { |
|
348 |
// TODO Auto-generated catch block |
|
349 |
e.printStackTrace(); |
|
350 |
} catch (IOException e) { |
|
351 |
// TODO Auto-generated catch block |
|
352 |
e.printStackTrace(); |
|
376 |
public void addOption(String s) { |
|
377 |
ScaleCADToolState actualState = (ScaleCADToolState) _fsm |
|
378 |
.getPreviousState(); |
|
379 |
String status = actualState.getName(); |
|
380 |
if (status.equals("Scale.ScaleFactorOrReference")) { |
|
381 |
/* |
|
382 |
* try { scale(2); } catch (DriverIOException e) { // TODO |
|
383 |
* Auto-generated catch block e.printStackTrace(); } catch |
|
384 |
* (IOException e) { // TODO Auto-generated catch block |
|
385 |
* e.printStackTrace(); } |
|
386 |
*/ |
|
387 |
} |
|
388 |
} |
|
389 |
|
|
390 |
/* |
|
391 |
* (non-Javadoc) |
|
392 |
* |
|
393 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
|
394 |
*/ |
|
395 |
public void addValue(double d) { |
|
396 |
ScaleCADToolState actualState = (ScaleCADToolState) _fsm |
|
397 |
.getPreviousState(); |
|
398 |
String status = actualState.getName(); |
|
399 |
if (status.equals("Scale.ScaleFactorOrReference")) { |
|
400 |
try { |
|
401 |
scale(d); |
|
402 |
} catch (ReadException e) { |
|
403 |
NotificationManager.addError(e.getMessage(), e); |
|
353 | 404 |
} |
354 |
*/ |
|
355 |
} |
|
356 |
} |
|
405 |
} |
|
406 |
} |
|
357 | 407 |
|
358 |
/* (non-Javadoc) |
|
359 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
|
360 |
*/ |
|
361 |
public void addValue(double d) { |
|
362 |
ScaleCADToolState actualState = (ScaleCADToolState) _fsm.getPreviousState(); |
|
363 |
String status = actualState.getName(); |
|
364 |
if (status.equals("Scale.ScaleFactorOrReference")) { |
|
365 |
try { |
|
366 |
scale(d); |
|
367 |
} catch (ReadException e) { |
|
368 |
NotificationManager.addError(e.getMessage(),e); |
|
369 |
} |
|
370 |
} |
|
371 |
} |
|
372 |
private void scale(double scaleFactor) throws ReadException{ |
|
373 |
VectorialLayerEdited vle=getVLE(); |
|
374 |
FeatureStore featureStore=vle.getFeatureStore(); |
|
408 |
private void scale(double scaleFactor) throws ReadException { |
|
409 |
VectorialLayerEdited vle = getVLE(); |
|
410 |
try { |
|
411 |
FeatureStore featureStore = vle.getFeatureStore(); |
|
375 | 412 |
|
376 |
featureStore.getCommandsRecord().startComplex(); |
|
377 |
Iterator iterator =((FeatureSelection)featureStore.getSelection()).iterator(); |
|
378 |
ArrayList selectedRowAux=new ArrayList(); |
|
379 |
while (iterator.hasNext()) { |
|
380 |
Feature feature = (Feature) iterator.next(); |
|
413 |
featureStore.beginEditingGroup(getName()); |
|
414 |
Iterator iterator = ((FeatureSelection) featureStore.getSelection()) |
|
415 |
.iterator(); |
|
416 |
ArrayList selectedRowAux = new ArrayList(); |
|
417 |
while (iterator.hasNext()) { |
|
418 |
Feature feature = (Feature) iterator.next(); |
|
381 | 419 |
|
382 |
// } |
|
383 |
// for (int i = 0; i < selectedRow.size(); i++) { |
|
384 |
// IRowEdited edRow = (IRowEdited) selectedRow.get(i); |
|
385 |
// DefaultFeature fea = (DefaultFeature) edRow.getLinkedRow().cloneRow(); |
|
386 |
Geometry geometry=((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
|
387 |
UtilFunctions.scaleGeom(geometry, scalePoint, scaleFactor, scaleFactor); |
|
388 |
try { |
|
389 |
feature.editing(); |
|
390 |
feature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(), geometry); |
|
391 |
featureStore.update(feature); |
|
392 |
} catch (DataException e) { |
|
393 |
// TODO Auto-generated catch block |
|
394 |
e.printStackTrace(); |
|
420 |
// } |
|
421 |
// for (int i = 0; i < selectedRow.size(); i++) { |
|
422 |
// IRowEdited edRow = (IRowEdited) selectedRow.get(i); |
|
423 |
// DefaultFeature fea = (DefaultFeature) |
|
424 |
// edRow.getLinkedRow().cloneRow(); |
|
425 |
Geometry geometry = ((Geometry) feature.getDefaultGeometry()) |
|
426 |
.cloneGeometry(); |
|
427 |
UtilFunctions.scaleGeom(geometry, scalePoint, scaleFactor, |
|
428 |
scaleFactor); |
|
429 |
|
|
430 |
EditableFeature eFeature = feature.getEditable(); |
|
431 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
|
432 |
.getDefaultGeometryAttributeName(), geometry); |
|
433 |
featureStore.update(eFeature); |
|
434 |
|
|
435 |
// vea.modifyRow(edRow.getIndex(), |
|
436 |
// fea,getName(),EditionEvent.GRAPHIC); |
|
437 |
selectedRowAux.add(feature); |
|
395 | 438 |
} |
396 |
// vea.modifyRow(edRow.getIndex(), fea,getName(),EditionEvent.GRAPHIC); |
|
397 |
selectedRowAux.add(feature); |
|
398 |
} |
|
399 |
featureStore.getCommandsRecord().endComplex(getName()); |
|
400 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, selectedRowAux); |
|
401 |
//clearSelection(); |
|
402 |
//selectedRow.addAll(selectedRowAux); |
|
403 |
} |
|
439 |
featureStore.endEditingGroup(); |
|
440 |
} catch (DataException e) { |
|
441 |
// TODO Auto-generated catch block |
|
442 |
e.printStackTrace(); |
|
443 |
} |
|
444 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, |
|
445 |
// selectedRowAux); |
|
446 |
// clearSelection(); |
|
447 |
// selectedRow.addAll(selectedRowAux); |
|
448 |
} |
|
404 | 449 |
|
405 |
public String getName() {
|
|
406 |
return PluginServices.getText(this,"scale_"); |
|
450 |
public String getName() {
|
|
451 |
return PluginServices.getText(this, "scale_");
|
|
407 | 452 |
} |
408 | 453 |
|
409 | 454 |
public String toString() { |
Also available in: Unified diff