gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.align / src / main / java / org / gvsig / vectorediting / lib / prov / align / AlignEdgesEditingProvider.java @ 3067
History | View | Annotate | Download (24.1 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2014 gvSIG Association
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.vectorediting.lib.prov.align; |
25 |
|
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.util.ArrayList; |
28 |
import java.util.HashMap; |
29 |
import java.util.List; |
30 |
import java.util.Map; |
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
32 |
import org.gvsig.fmap.dal.feature.Feature; |
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
34 |
import org.gvsig.fmap.geom.Geometry; |
35 |
import org.gvsig.fmap.geom.Geometry.DIMENSIONS; |
36 |
import org.gvsig.fmap.geom.GeometryUtils; |
37 |
import org.gvsig.fmap.geom.primitive.Envelope; |
38 |
import org.gvsig.fmap.geom.primitive.Line; |
39 |
import org.gvsig.fmap.geom.primitive.Point; |
40 |
import org.gvsig.fmap.mapcontext.MapContext; |
41 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
42 |
import org.gvsig.tools.ToolsLocator; |
43 |
import org.gvsig.tools.dataTypes.DataTypes; |
44 |
import org.gvsig.tools.dynobject.DynObject; |
45 |
import org.gvsig.tools.i18n.I18nManager; |
46 |
import org.gvsig.tools.service.spi.ProviderServices; |
47 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
48 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
49 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
50 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
51 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
52 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
53 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
54 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
55 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
56 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
57 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
58 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameterOptions; |
59 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
60 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
61 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
62 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
63 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
64 |
|
65 |
/**
|
66 |
* @author fdiaz
|
67 |
*
|
68 |
*/
|
69 |
public class AlignEdgesEditingProvider extends AbstractEditingProvider implements EditingProvider { |
70 |
|
71 |
private static final String ALIGN_MODE = "_align_mode"; |
72 |
|
73 |
private static final String ALIGN_UP = "_up"; |
74 |
private static final String ALIGN_DOWN = "_down"; |
75 |
private static final String ALIGN_LEFT = "_left"; |
76 |
private static final String ALIGN_RIGHT = "_right"; |
77 |
private static final String ALIGN_HORIZONTAL_CENTER = "_horizontal_centering"; |
78 |
private static final String ALIGN_VERTICAL_CENTER = "_vertical_centering"; |
79 |
private static final String ALIGN_BOTH_CENTER = "_both_centering"; |
80 |
|
81 |
private static final String SHORT_ALIGN_UP = "_short_up"; |
82 |
private static final String SHORT_ALIGN_DOWN = "_short_down"; |
83 |
private static final String SHORT_ALIGN_LEFT = "_short_left"; |
84 |
private static final String SHORT_ALIGN_RIGHT = "_short_right"; |
85 |
private static final String SHORT_ALIGN_HORIZONTAL_CENTER = "_short_horizontal_centering"; |
86 |
private static final String SHORT_ALIGN_VERTICAL_CENTER = "_short_vertical_centering"; |
87 |
private static final String SHORT_ALIGN_BOTH_CENTER = "_short_both_centering"; |
88 |
|
89 |
private static final String DO_COPY_QUESTION = "_do_copy_question"; |
90 |
|
91 |
private static final String DELETE_ORIGINAL_GEOMETRIES = "_delete_original_geometries"; |
92 |
private static final String DO_COPY = "_do_copy"; |
93 |
|
94 |
private static final String YES = "_yes"; |
95 |
private static final String NO = "_no"; |
96 |
|
97 |
private static final String SHORT_YES = "_short_yes"; |
98 |
private static final String SHORT_NO = "_short_no"; |
99 |
|
100 |
//Variables est?ticas para guardarnos el align_mode y el do_copy
|
101 |
private static String savedAlignMode; |
102 |
private static Boolean savedDoCopy; |
103 |
|
104 |
private final EditingServiceParameter geometryBaseParameter; |
105 |
|
106 |
private final EditingServiceParameter alignModeParameter; |
107 |
|
108 |
private final EditingServiceParameter doCopyParameter; |
109 |
|
110 |
private final EditingServiceParameter featureToAlignParameter; |
111 |
|
112 |
private final Map<EditingServiceParameter, Object> values; |
113 |
|
114 |
private final FeatureStore featureStore; |
115 |
|
116 |
private final MapContext mapContext; |
117 |
|
118 |
private List<Feature> selectedFeatures; |
119 |
|
120 |
/**
|
121 |
* Default constructor.
|
122 |
*
|
123 |
* @param providerServices available services for this provider
|
124 |
* @param parameters of this provider
|
125 |
*/
|
126 |
public AlignEdgesEditingProvider(ProviderServices providerServices,
|
127 |
DynObject parameters) { |
128 |
super(providerServices);
|
129 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
130 |
|
131 |
this.featureStore
|
132 |
= (FeatureStore) parameters |
133 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
134 |
|
135 |
this.mapContext
|
136 |
= (MapContext) parameters |
137 |
.getDynValue(EditingProviderFactory.MAPCONTEXT_FIELD); |
138 |
|
139 |
this.geometryBaseParameter
|
140 |
= new DefaultEditingServiceParameter("_geometry_base", "_geometry_base", |
141 |
TYPE.POSITION); |
142 |
|
143 |
this.featureToAlignParameter
|
144 |
= new DefaultEditingServiceParameter("_geometry_to_align", "_geometry_to_align", |
145 |
TYPE.POSITION); |
146 |
|
147 |
DefaultEditingServiceParameterOptions alignModeOptions = new DefaultEditingServiceParameterOptions()
|
148 |
.add(i18nManager.getTranslation(ALIGN_UP), ALIGN_UP, i18nManager.getTranslation(SHORT_ALIGN_UP)) |
149 |
.add(i18nManager.getTranslation(ALIGN_DOWN), ALIGN_DOWN, i18nManager.getTranslation(SHORT_ALIGN_DOWN)) |
150 |
.add(i18nManager.getTranslation(ALIGN_LEFT), ALIGN_LEFT, i18nManager.getTranslation(SHORT_ALIGN_LEFT)) |
151 |
.add(i18nManager.getTranslation(ALIGN_RIGHT), ALIGN_RIGHT, i18nManager.getTranslation(SHORT_ALIGN_RIGHT)) |
152 |
.add(i18nManager.getTranslation(ALIGN_HORIZONTAL_CENTER), ALIGN_HORIZONTAL_CENTER, i18nManager.getTranslation(SHORT_ALIGN_HORIZONTAL_CENTER)) |
153 |
.add(i18nManager.getTranslation(ALIGN_VERTICAL_CENTER), ALIGN_VERTICAL_CENTER, i18nManager.getTranslation(SHORT_ALIGN_VERTICAL_CENTER)) |
154 |
.add(i18nManager.getTranslation(ALIGN_BOTH_CENTER), ALIGN_BOTH_CENTER, i18nManager.getTranslation(SHORT_ALIGN_BOTH_CENTER)) |
155 |
; |
156 |
|
157 |
String alignModeConsoleMsg
|
158 |
= ((EditingProviderServices) providerServices).makeConsoleMessage( |
159 |
i18nManager.getTranslation(ALIGN_MODE), alignModeOptions); |
160 |
|
161 |
|
162 |
|
163 |
this.alignModeParameter
|
164 |
= new DefaultEditingServiceParameter(
|
165 |
ALIGN_MODE, |
166 |
alignModeConsoleMsg, |
167 |
alignModeOptions, |
168 |
i18nManager.getTranslation(SHORT_ALIGN_BOTH_CENTER), |
169 |
true,
|
170 |
TYPE.OPTION); |
171 |
|
172 |
DefaultEditingServiceParameterOptions doCopyOptions= new DefaultEditingServiceParameterOptions()
|
173 |
.add(DO_COPY, true, i18nManager.getTranslation(SHORT_YES))
|
174 |
.add(DELETE_ORIGINAL_GEOMETRIES, false, i18nManager.getTranslation(SHORT_NO));
|
175 |
|
176 |
String consoleMsg
|
177 |
= ((EditingProviderServices) providerServices).makeConsoleMessage( |
178 |
DO_COPY_QUESTION, doCopyOptions); |
179 |
|
180 |
this.doCopyParameter
|
181 |
= new DefaultEditingServiceParameter(
|
182 |
DO_COPY, |
183 |
consoleMsg, |
184 |
doCopyOptions, |
185 |
i18nManager.getTranslation(SHORT_YES), |
186 |
true,
|
187 |
TYPE.OPTION).setDataType(DataTypes.BOOLEAN); |
188 |
|
189 |
this.values = new HashMap<>(); |
190 |
} |
191 |
|
192 |
@Override
|
193 |
public String getName() { |
194 |
return AlignEdgesEditingProviderFactory.PROVIDER_NAME;
|
195 |
} |
196 |
|
197 |
@Override
|
198 |
public EditingServiceParameter next() {
|
199 |
if (values.get(geometryBaseParameter) == null) { |
200 |
return this.geometryBaseParameter; |
201 |
} else if (values.get(alignModeParameter) == null) { |
202 |
return this.alignModeParameter; |
203 |
} else if (values.get(doCopyParameter) == null) { |
204 |
return this.doCopyParameter; |
205 |
} else if (values.get(featureToAlignParameter) == null) { |
206 |
return this.featureToAlignParameter; |
207 |
} |
208 |
return null; |
209 |
} |
210 |
|
211 |
@Override
|
212 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
213 |
throws DrawServiceException {
|
214 |
DefaultDrawingStatus geometries = new DefaultDrawingStatus();
|
215 |
|
216 |
EditingProviderManager editingProviderManager |
217 |
= EditingProviderLocator.getProviderManager(); |
218 |
ISymbol lineSymbolEditing = editingProviderManager.getSymbol("line-symbol-editing");
|
219 |
ISymbol auxiliaryLineSymbolEditing = editingProviderManager.getSymbol("auxiliary-line-symbol-editing");
|
220 |
ISymbol auxiliaryPointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing");
|
221 |
ISymbol polygonSymbolEditing = editingProviderManager.getSymbol("polygon-symbol-editing");
|
222 |
|
223 |
EditingProviderServices editingProviderServices |
224 |
= (EditingProviderServices) getProviderServices(); |
225 |
|
226 |
try {
|
227 |
int subtype = editingProviderServices.getSubType(featureStore);
|
228 |
if (values != null) { |
229 |
Geometry geometryBaseValue = (Geometry) values.get(geometryBaseParameter); |
230 |
String alignModeValue = (String) values.get(alignModeParameter); |
231 |
Boolean doCopyValue = (Boolean) values.get(doCopyParameter); |
232 |
if (geometryBaseValue != null) { |
233 |
if (geometryBaseValue.getGeometryType().isTypeOf(Geometry.TYPES.POINT) ||
|
234 |
geometryBaseValue.getGeometryType().isTypeOf(Geometry.TYPES.MULTIPOINT)) { |
235 |
geometries.addStatus(geometryBaseValue, auxiliaryPointSymbolEditing, "");
|
236 |
} else if (geometryBaseValue.getGeometryType().isTypeOf(Geometry.TYPES.CURVE) || |
237 |
geometryBaseValue.getGeometryType().isTypeOf(Geometry.TYPES.MULTICURVE)) { |
238 |
geometries.addStatus(geometryBaseValue, auxiliaryLineSymbolEditing, "");
|
239 |
} else {
|
240 |
geometries.addStatus(geometryBaseValue, polygonSymbolEditing, "");
|
241 |
} |
242 |
|
243 |
if (alignModeValue != null && doCopyValue != null) { |
244 |
Feature feature = getFeatureToAlign(mousePosition); //getFeatureToAlign(mousePosition);
|
245 |
if (feature != null) { |
246 |
ISymbol previewSymbol = this.getPreviewSymbol(feature);
|
247 |
Geometry geom = feature.getDefaultGeometry(); //getGeometryToAlign(mousePosition); //getFeatureToAlign(mousePosition);
|
248 |
if (geom != null) { |
249 |
if (geom.getGeometryType().isTypeOf(Geometry.TYPES.POINT)
|
250 |
|| geom.getGeometryType().isTypeOf(Geometry.TYPES.MULTIPOINT)) { |
251 |
geometries.addStatus(geom, auxiliaryPointSymbolEditing, "");
|
252 |
} else if (geom.getGeometryType().isTypeOf(Geometry.TYPES.CURVE) |
253 |
|| geom.getGeometryType().isTypeOf(Geometry.TYPES.MULTICURVE)) { |
254 |
geometries.addStatus(geom, auxiliaryLineSymbolEditing, "");
|
255 |
} else if (geom.getGeometryType().isTypeOf(Geometry.TYPES.SURFACE) |
256 |
|| geom.getGeometryType().isTypeOf(Geometry.TYPES.MULTISURFACE)) { |
257 |
geometries.addStatus(geom, polygonSymbolEditing, "");
|
258 |
} |
259 |
geometries.addStatus(geom, previewSymbol, "");
|
260 |
Geometry alignedGeom = align(geometryBaseValue, geom, alignModeValue); |
261 |
if (alignedGeom != null) { |
262 |
|
263 |
Point basePoint = getAlignPoint(geometryBaseValue, alignModeValue);
|
264 |
Point geomPoint = getAlignPoint(alignedGeom, alignModeValue);
|
265 |
Line alignLine = GeometryUtils.createLine(basePoint, geomPoint, subtype);
|
266 |
geometries.addStatus(alignLine, auxiliaryLineSymbolEditing, "");
|
267 |
|
268 |
if (alignedGeom.getGeometryType().isTypeOf(Geometry.TYPES.POINT)
|
269 |
|| alignedGeom.getGeometryType().isTypeOf(Geometry.TYPES.MULTIPOINT)) { |
270 |
geometries.addStatus(alignedGeom, auxiliaryPointSymbolEditing, "");
|
271 |
} else if (alignedGeom.getGeometryType().isTypeOf(Geometry.TYPES.CURVE) |
272 |
|| alignedGeom.getGeometryType().isTypeOf(Geometry.TYPES.MULTICURVE)) { |
273 |
geometries.addStatus(alignedGeom, lineSymbolEditing, "");
|
274 |
} else if (alignedGeom.getGeometryType().isTypeOf(Geometry.TYPES.SURFACE) |
275 |
|| alignedGeom.getGeometryType().isTypeOf(Geometry.TYPES.MULTISURFACE)) { |
276 |
geometries.addStatus(alignedGeom, polygonSymbolEditing, "");
|
277 |
} |
278 |
geometries.addStatus(alignedGeom, previewSymbol, "");
|
279 |
} |
280 |
} |
281 |
} |
282 |
} |
283 |
} |
284 |
} |
285 |
} catch (Exception e) { |
286 |
throw new DrawServiceException(e); |
287 |
} |
288 |
|
289 |
return geometries;
|
290 |
} |
291 |
|
292 |
@Override
|
293 |
public List<EditingServiceParameter> getParameters() { |
294 |
List<EditingServiceParameter> parameters
|
295 |
= new ArrayList<>(); |
296 |
parameters.add(geometryBaseParameter); |
297 |
parameters.add(alignModeParameter); |
298 |
parameters.add(doCopyParameter); |
299 |
parameters.add(featureToAlignParameter); |
300 |
return parameters;
|
301 |
} |
302 |
|
303 |
@Override
|
304 |
public boolean isEnabled(EditingServiceParameter parameter) { |
305 |
return true; |
306 |
} |
307 |
|
308 |
@Override
|
309 |
public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException { |
310 |
validateAndInsertValue(parameter, value); |
311 |
} |
312 |
|
313 |
@Override
|
314 |
public void setValue(Object value) throws InvalidEntryException { |
315 |
EditingServiceParameter param = next(); |
316 |
validateAndInsertValue(param, value); |
317 |
} |
318 |
|
319 |
private void validateAndInsertValue(EditingServiceParameter param, |
320 |
Object value) throws InvalidEntryException { |
321 |
if (param == geometryBaseParameter) {
|
322 |
if (value instanceof Point) { |
323 |
Point point = (Point) value; |
324 |
|
325 |
Geometry geom = getGeometryOfVisibleLayers(point); |
326 |
if (geom != null) { |
327 |
values.put(param, geom); |
328 |
return;
|
329 |
} |
330 |
} |
331 |
} else if (param == featureToAlignParameter) { |
332 |
if (value instanceof Point) { |
333 |
Point point = (Point) value; |
334 |
|
335 |
Feature feat = getFeatureToAlign(point); |
336 |
if (feat != null) { |
337 |
values.put(param, feat); |
338 |
return;
|
339 |
} |
340 |
} |
341 |
} else if (param == alignModeParameter) { |
342 |
savedAlignMode = (String) param.getOptions2().getValue(value, param.getDefaultValue());
|
343 |
values.put(param, savedAlignMode); |
344 |
return;
|
345 |
} else if (param == doCopyParameter) { |
346 |
savedDoCopy = (Boolean) param.getOptions2().getValue(value, param.getDefaultValue());
|
347 |
values.put(param, savedDoCopy); |
348 |
return;
|
349 |
} |
350 |
throw new InvalidEntryException(null); |
351 |
} |
352 |
|
353 |
private Geometry getGeometryOfVisibleLayers(Point point) { |
354 |
EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
355 |
Geometry geometry = editingProviderServices.getGeometryOfVisibleLayers(point, featureStore, mapContext); |
356 |
return geometry;
|
357 |
} |
358 |
|
359 |
private Feature getFeatureToAlign(Point point) { |
360 |
EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
361 |
Feature feature = editingProviderServices.getFeature(point, featureStore, mapContext); |
362 |
return feature;
|
363 |
} |
364 |
|
365 |
private Geometry getGeometryToAlign(Point point) { |
366 |
EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
367 |
return editingProviderServices.getGeometry(point, featureStore, mapContext);
|
368 |
} |
369 |
|
370 |
@Override
|
371 |
public Geometry finish() throws FinishServiceException { |
372 |
return null; |
373 |
} |
374 |
|
375 |
@Override
|
376 |
public void finishAndStore() throws FinishServiceException { |
377 |
Geometry geometryBaseValue = (Geometry) values.get(geometryBaseParameter); |
378 |
Feature featureValue = (Feature) values.get(featureToAlignParameter); |
379 |
String alignModeValue = (String) values.get(alignModeParameter); |
380 |
Boolean doCopy = (Boolean) values.get(doCopyParameter); |
381 |
|
382 |
EditingProviderServices editingProviderServices |
383 |
= (EditingProviderServices) getProviderServices(); |
384 |
|
385 |
try {
|
386 |
|
387 |
Geometry geom; |
388 |
geom = align(geometryBaseValue, featureValue.getDefaultGeometry(), alignModeValue); |
389 |
|
390 |
if (doCopy) {
|
391 |
// Se crea una feature nueva copiando los valores de
|
392 |
// la feature original excepto aquellos que sean PK
|
393 |
EditableFeature editableFeature |
394 |
= editingProviderServices |
395 |
.getFeatureCopyWithoutUniqueIndex(featureStore, |
396 |
featureValue); |
397 |
editableFeature.setDefaultGeometry(geom); |
398 |
editingProviderServices |
399 |
.insertFeatureIntoFeatureStore(editableFeature, |
400 |
featureStore); |
401 |
} else {
|
402 |
// Se sustituye la geometr?a original por la
|
403 |
// calculada
|
404 |
EditableFeature editableFeature |
405 |
= featureValue.getEditable(); |
406 |
editableFeature.setDefaultGeometry(geom); |
407 |
((EditingProviderServices) getProviderServices()) |
408 |
.updateFeatureInFeatureStore(editableFeature, |
409 |
featureStore); |
410 |
|
411 |
} |
412 |
|
413 |
} catch (Exception e) { |
414 |
throw new FinishServiceException(e); |
415 |
} |
416 |
} |
417 |
|
418 |
private Geometry align(Geometry geometryBase, Geometry geometry, String alignMode) { |
419 |
|
420 |
if (geometryBase != null && geometry != null) { |
421 |
geometry = geometry.cloneGeometry(); |
422 |
AffineTransform at = getAffineTransform(geometryBase, geometry, alignMode);
|
423 |
geometry.transform(at); |
424 |
} |
425 |
return geometry;
|
426 |
} |
427 |
|
428 |
private Point getAlignPoint(Geometry geometry, String alignMode) { |
429 |
|
430 |
Point point = null; |
431 |
if (geometry != null) { |
432 |
if (geometry instanceof Point) { |
433 |
point = (Point) geometry;
|
434 |
} else {
|
435 |
Envelope env = geometry.getEnvelope(); |
436 |
switch (alignMode) {
|
437 |
case ALIGN_UP:
|
438 |
point = GeometryUtils.createPoint(env.getCenter(DIMENSIONS.X), env.getMaximum(DIMENSIONS.Y)); |
439 |
break;
|
440 |
case ALIGN_DOWN:
|
441 |
point = GeometryUtils.createPoint(env.getCenter(DIMENSIONS.X), env.getMinimum(DIMENSIONS.Y)); |
442 |
break;
|
443 |
case ALIGN_LEFT:
|
444 |
point = GeometryUtils.createPoint(env.getMinimum(DIMENSIONS.X), env.getCenter(DIMENSIONS.Y)); |
445 |
break;
|
446 |
case ALIGN_RIGHT:
|
447 |
point = GeometryUtils.createPoint(env.getMaximum(DIMENSIONS.X), env.getCenter(DIMENSIONS.Y)); |
448 |
break;
|
449 |
case ALIGN_HORIZONTAL_CENTER:
|
450 |
point = GeometryUtils.createPoint(env.getCenter(DIMENSIONS.X), env.getCenter(DIMENSIONS.Y)); |
451 |
break;
|
452 |
case ALIGN_VERTICAL_CENTER:
|
453 |
point = GeometryUtils.createPoint(env.getCenter(DIMENSIONS.X), env.getCenter(DIMENSIONS.Y)); |
454 |
break;
|
455 |
case ALIGN_BOTH_CENTER:
|
456 |
point = GeometryUtils.createPoint(env.getCenter(DIMENSIONS.X), env.getCenter(DIMENSIONS.Y)); |
457 |
break;
|
458 |
} |
459 |
} |
460 |
} |
461 |
return point;
|
462 |
} |
463 |
|
464 |
private AffineTransform getAffineTransform(Geometry geometryBase, Geometry geometry, String alignMode) { |
465 |
|
466 |
Point basePoint = getAlignPoint(geometryBase, alignMode);
|
467 |
Point geomPoint = getAlignPoint(geometry, alignMode);
|
468 |
AffineTransform at = null; |
469 |
|
470 |
switch (alignMode) {
|
471 |
case ALIGN_UP:
|
472 |
at = new AffineTransform( |
473 |
1d, 0d, |
474 |
0d, 1d, |
475 |
0d, basePoint.getY() - geomPoint.getY());
|
476 |
|
477 |
break;
|
478 |
case ALIGN_DOWN:
|
479 |
at = new AffineTransform( |
480 |
1d, 0d, |
481 |
0d, 1d, |
482 |
0d, basePoint.getY() - geomPoint.getY());
|
483 |
|
484 |
break;
|
485 |
case ALIGN_LEFT:
|
486 |
at = new AffineTransform( |
487 |
1d, 0d, |
488 |
0d, 1d, |
489 |
basePoint.getX() - geomPoint.getX(), 0d);
|
490 |
|
491 |
break;
|
492 |
case ALIGN_RIGHT:
|
493 |
at = new AffineTransform( |
494 |
1d, 0d, |
495 |
0d, 1d, |
496 |
basePoint.getX() - geomPoint.getX(), 0d);
|
497 |
|
498 |
break;
|
499 |
case ALIGN_HORIZONTAL_CENTER:
|
500 |
at = new AffineTransform( |
501 |
1d, 0d, |
502 |
0d, 1d, |
503 |
0d, basePoint.getY() - geomPoint.getY());
|
504 |
|
505 |
break;
|
506 |
case ALIGN_VERTICAL_CENTER:
|
507 |
at = new AffineTransform( |
508 |
1d, 0d, |
509 |
0d, 1d, |
510 |
basePoint.getX() - geomPoint.getX(), 0d);
|
511 |
|
512 |
break;
|
513 |
case ALIGN_BOTH_CENTER:
|
514 |
at = new AffineTransform( |
515 |
1d, 0d, |
516 |
0d, 1d, |
517 |
basePoint.getX() - geomPoint.getX(), basePoint.getY() - geomPoint.getY()); |
518 |
|
519 |
break;
|
520 |
} |
521 |
return at;
|
522 |
} |
523 |
|
524 |
@Override
|
525 |
public void activate() { |
526 |
//Se limpia todo pero se recuperan los valores guardados de alignMode y doCopy
|
527 |
this.values.clear();
|
528 |
if(savedAlignMode != null){ |
529 |
this.values.put(alignModeParameter, savedAlignMode);
|
530 |
} |
531 |
if(savedDoCopy != null){ |
532 |
this.values.put(doCopyParameter, savedDoCopy);
|
533 |
} |
534 |
} |
535 |
|
536 |
@Override
|
537 |
public void start() throws StartServiceException { |
538 |
|
539 |
} |
540 |
|
541 |
@Override
|
542 |
public void stop() throws StopServiceException { |
543 |
//Se limpiar solo la geometr?a a alinear
|
544 |
this.values.remove(featureToAlignParameter);
|
545 |
} |
546 |
|
547 |
@Override
|
548 |
public Object getValue(EditingServiceParameter parameter) { |
549 |
return values != null ? values.get(parameter) : null; |
550 |
} |
551 |
|
552 |
private Feature getCurrentFeature() {
|
553 |
return (Feature) getValue(featureToAlignParameter);
|
554 |
} |
555 |
|
556 |
} |