Revision 325

View differences:

org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/pom.xml
30 30
		<module>org.gvsig.vectorediting.lib.prov.autopolygon</module>
31 31
		<module>org.gvsig.vectorediting.lib.prov.join</module>
32 32
		<module>org.gvsig.vectorediting.lib.prov.stretch</module>
33
		<module>org.gvsig.vectorediting.lib.prov.extendline</module>
33 34
	</modules>
34 35
	<dependencies>
35 36
		<dependency>
......
116 117
			<artifactId>org.gvsig.fmap.geometry.operation</artifactId>
117 118
			<scope>test</scope>
118 119
		</dependency>
120
		<dependency>
121
			<groupId>org.gvsig</groupId>
122
			<artifactId>org.gvsig.fmap.control</artifactId>
123
		</dependency>
119 124
	</dependencies>
120 125
</project>
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/src/main/java/org/gvsig/vectorediting/lib/prov/extendline/ExtendLineEditingProvider.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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

  
25
package org.gvsig.vectorediting.lib.prov.extendline;
26

  
27
import java.util.ArrayList;
28
import java.util.List;
29

  
30
import org.cresques.cts.IProjection;
31

  
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.feature.EditableFeature;
34
import org.gvsig.fmap.dal.feature.Feature;
35
import org.gvsig.fmap.dal.feature.FeatureQuery;
36
import org.gvsig.fmap.dal.feature.FeatureSelection;
37
import org.gvsig.fmap.dal.feature.FeatureSet;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.fmap.geom.Geometry;
40
import org.gvsig.fmap.geom.GeometryLocator;
41
import org.gvsig.fmap.geom.GeometryManager;
42
import org.gvsig.fmap.geom.aggregate.MultiCurve;
43
import org.gvsig.fmap.geom.exception.CreateGeometryException;
44
import org.gvsig.fmap.geom.operation.GeometryOperationException;
45
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
46
import org.gvsig.fmap.geom.primitive.Arc;
47
import org.gvsig.fmap.geom.primitive.Curve;
48
import org.gvsig.fmap.geom.primitive.Point;
49
import org.gvsig.fmap.geom.primitive.Primitive;
50
import org.gvsig.fmap.geom.type.GeometryType;
51
import org.gvsig.fmap.mapcontext.MapContext;
52
import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsGeometryEvaluator;
53
import org.gvsig.tools.dispose.DisposableIterator;
54
import org.gvsig.tools.dynobject.DynObject;
55
import org.gvsig.tools.exception.BaseException;
56
import org.gvsig.tools.service.spi.ProviderServices;
57
import org.gvsig.tools.visitor.VisitCanceledException;
58
import org.gvsig.tools.visitor.Visitor;
59
import org.gvsig.vectorediting.lib.api.DrawingStatus;
60
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
61
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE;
62
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException;
63
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException;
64
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException;
65
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException;
66
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException;
67
import org.gvsig.vectorediting.lib.prov.extendline.operation.ExtendLineOperation;
68
import org.gvsig.vectorediting.lib.prov.extendline.operation.ExtendLineOperationUtils;
69
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider;
70
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus;
71
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter;
72
import org.gvsig.vectorediting.lib.spi.EditingProvider;
73
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory;
74

  
75
/**
76
 * @author llmarques
77
 *
78
 */
79
public class ExtendLineEditingProvider extends AbstractEditingProvider
80
    implements EditingProvider {
81

  
82
    private final int TOLERANCE_PIXELS = 3;
83

  
84
    private Point insertedPoint;
85

  
86
    private EditingServiceParameter selectionParameter;
87

  
88
    private EditingServiceParameter linesToExtendParameter;
89

  
90
    private FeatureSelection selection;
91

  
92
    private FeatureSet linesToExtend;
93

  
94
    private FeatureStore featureStore;
95

  
96
    private MapContext mapContext;
97

  
98
    /**
99
     * Default constructor.
100
     *
101
     * @param providerServices
102
     *            available services for this provider
103
     * @param parameters
104
     * @param parameters
105
     *            of this provider
106
     */
107
    public ExtendLineEditingProvider(ProviderServices services,
108
        DynObject parameters) {
109
        super(services);
110

  
111
        this.featureStore =
112
            (FeatureStore) parameters
113
                .getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD);
114

  
115
        this.mapContext =
116
            (MapContext) parameters
117
                .getDynValue(EditingProviderFactory.MAPCONTEXT_FIELD);
118

  
119
        this.selectionParameter =
120
            new DefaultEditingServiceParameter("selection", "selection",
121
                TYPE.SELECTION);
122

  
123
        this.linesToExtendParameter =
124
            new DefaultEditingServiceParameter("line_to_extend",
125
                "line_to_extend", TYPE.POSITION);
126
    }
127

  
128
    public EditingServiceParameter next() {
129
        if (selection == null) {
130
            return selectionParameter;
131
        } else if (linesToExtend == null) {
132
            return linesToExtendParameter;
133
        }
134
        return null;
135
    }
136

  
137
    public DrawingStatus getDrawingStatus(Point mousePosition)
138
        throws DrawServiceException {
139

  
140
        if (selection != null) {
141
            DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus();
142
            double tolerance =
143
                mapContext.getViewPort().toMapDistance(TOLERANCE_PIXELS);
144

  
145
            Geometry buffer;
146
            FeatureSet geometries;
147
            DisposableIterator it = null;
148
            try {
149
                // Create buffer with tolerance to get the geometry to be
150
                // extended
151
                buffer = mousePosition.buffer(tolerance);
152
                geometries = getGeometryByBuffer(buffer);
153

  
154
                it = geometries.fastIterator();
155
                while (it.hasNext()) {
156
                    Feature feature = (Feature) it.next();
157
                    if (!selection.isSelected(feature)) {
158
                        Geometry geometry = feature.getDefaultGeometry();
159

  
160
                        if (geometry instanceof MultiCurve) {
161
                            MultiCurve multiCurve = (MultiCurve) geometry;
162

  
163
                            for (int i = 0; i < multiCurve
164
                                .getPrimitivesNumber(); i++) {
165

  
166
                                Curve curve = multiCurve.getCurveAt(i);
167
                                if (!isClosed(curve)) {
168
                                    Curve extendedCurve =
169
                                        extendLine(mousePosition, curve);
170
                                    drawingStatus.addGeometry(extendedCurve);
171
                                }
172
                            }
173

  
174
                        } else if (geometry instanceof Curve) {
175
                            if (!isClosed((Curve) geometry)) {
176
                                Curve extendedCurve =
177
                                    extendLine(mousePosition, (Curve) geometry);
178
                                drawingStatus.addGeometry(extendedCurve);
179
                            }
180
                        }
181
                    }
182
                }
183

  
184
            } catch (BaseException e) {
185
                throw new DrawServiceException(e);
186
            } finally {
187
                it.dispose();
188
            }
189
            return drawingStatus;
190
        }
191
        return null;
192
    }
193

  
194
    private boolean isClosed(Curve curve) {
195
        if (curve instanceof Arc) {
196
            Arc arc = (Arc) curve;
197
            if (arc.getInitPoint().equals(arc.getEndPoint())) {
198
                return true;
199
            }
200
        } else if (curve instanceof Curve) {
201
            Point firstPoint = curve.getVertex(0);
202
            Point lastPoint = curve.getVertex(curve.getNumVertices() - 1);
203
            if (firstPoint.equals(lastPoint)) {
204
                return true;
205
            }
206
        }
207
        return false;
208
    }
209

  
210
    private Curve extendLine(Point mousePosition, Curve curve)
211
        throws GeometryOperationNotSupportedException,
212
        GeometryOperationException, DataException, CreateGeometryException {
213
        ExtendLineOperation operation =
214
            ExtendLineOperationUtils.getOperation((Primitive) curve);
215

  
216
        return operation.extendLine(curve, mousePosition, selection);
217
    }
218

  
219
    public void stop() throws StopServiceException {
220
        selection = null;
221
        linesToExtend = null;
222
    }
223

  
224
    public List<EditingServiceParameter> getParameters() {
225
        List<EditingServiceParameter> parameters =
226
            new ArrayList<EditingServiceParameter>();
227
        parameters.add(selectionParameter);
228
        parameters.add(linesToExtendParameter);
229
        return parameters;
230
    }
231

  
232
    public void setValue(Object value) throws InvalidEntryException {
233
        EditingServiceParameter parameter = next();
234
        validateAndInsertValue(parameter, value);
235
    }
236

  
237
    private void validateAndInsertValue(
238
        final EditingServiceParameter parameter, Object value)
239
        throws InvalidEntryException {
240

  
241
        if (parameter == selectionParameter) {
242
            if (value instanceof FeatureSelection) {
243
                FeatureSelection featureSelection = (FeatureSelection) value;
244
                if (featureSelection.getSelectedCount() > 0) {
245
                    try {
246
                        featureSelection.accept(new Visitor() {
247

  
248
                            public void visit(Object obj)
249
                                throws VisitCanceledException, BaseException {
250
                                Feature feature = (Feature) obj;
251
                                Geometry geometry =
252
                                    feature.getDefaultGeometry();
253
                                GeometryType geoType =
254
                                    geometry.getGeometryType();
255

  
256
                                if (!geoType.isTypeOf(SURFACE)
257
                                    && !geoType.isTypeOf(MULTISURFACE)
258
                                    && !geoType.isTypeOf(CURVE)
259
                                    && !geoType.isTypeOf(MULTICURVE)) {
260
                                    throw new InvalidEntryException(null);
261
                                }
262
                            }
263
                        });
264
                        selection = featureSelection;
265
                        return;
266
                    } catch (BaseException e) {
267
                        throw new InvalidEntryException(e);
268
                    }
269
                }
270
            }
271
        } else if (parameter == linesToExtendParameter) {
272
            if (value instanceof Point) {
273
                Point point = (Point) value;
274
                try {
275
                    double tolerance =
276
                        mapContext.getViewPort()
277
                            .toMapDistance(TOLERANCE_PIXELS);
278

  
279
                    // Create buffer with tolerance to get geometries to be
280
                    // extended
281
                    Geometry buffer = point.buffer(tolerance);
282
                    FeatureSet geometries = getGeometryByBuffer(buffer);
283

  
284
                    if (geometries.getSize() > 0) {
285

  
286
                        geometries.accept(new Visitor() {
287

  
288
                            public void visit(Object obj)
289
                                throws VisitCanceledException, BaseException {
290
                                Feature feature = (Feature) obj;
291
                                Geometry geometry =
292
                                    feature.getDefaultGeometry();
293
                                GeometryType geoType =
294
                                    geometry.getGeometryType();
295

  
296
                                if (!geoType.isTypeOf(CURVE)
297
                                    && !geoType.isTypeOf(MULTICURVE)) {
298
                                    throw new InvalidEntryException(null);
299
                                }
300
                            }
301
                        });
302

  
303
                        insertedPoint = point;
304
                        linesToExtend = geometries;
305
                        return;
306
                    }
307
                } catch (BaseException e) {
308
                    throw new InvalidEntryException(e);
309
                }
310
            }
311
        }
312
        throw new InvalidEntryException(null);
313
    }
314

  
315
    public FeatureSet getGeometryByBuffer(Geometry buffer) throws DataException {
316
        FeatureQuery queryByGeometry = featureStore.createFeatureQuery();
317

  
318
        // Get default SRS of default feature type
319
        IProjection defaultSRS =
320
            this.featureStore.getDefaultFeatureType().getDefaultSRS();
321

  
322
        // Name of default geometry type
323
        String geomName =
324
            featureStore.getDefaultFeatureType()
325
                .getDefaultGeometryAttributeName();
326

  
327
        IntersectsGeometryEvaluator iee =
328
            new IntersectsGeometryEvaluator(buffer, defaultSRS,
329
                featureStore.getDefaultFeatureType(), geomName);
330

  
331
        queryByGeometry.setFilter(iee);
332
        queryByGeometry.setAttributeNames(null);
333
        return this.featureStore.getFeatureSet(queryByGeometry);
334
    }
335

  
336
    public Geometry finish() throws FinishServiceException {
337
        return null;
338
    }
339

  
340
    public void finishAndStore() throws FinishServiceException {
341
        if (selection != null && linesToExtend != null) {
342

  
343
            try {
344
                linesToExtend.accept(new Visitor() {
345

  
346
                    public void visit(Object obj)
347
                        throws VisitCanceledException, BaseException {
348
                        Feature feature = (Feature) obj;
349
                        Geometry geometry = feature.getDefaultGeometry();
350
                        EditableFeature eFeature = feature.getEditable();
351

  
352
                        if (geometry instanceof MultiCurve) {
353

  
354
                            // Create new multicurve geometry
355
                            MultiCurve extendedMultiCurve =
356
                                createMultiCurve(geometry);
357

  
358
                            // Iterate overs primitives and execute extend
359
                            // line operation
360
                            MultiCurve multiCurve = (MultiCurve) geometry;
361

  
362
                            for (int i = 0; i < multiCurve
363
                                .getPrimitivesNumber(); i++) {
364

  
365
                                Curve curve = multiCurve.getCurveAt(i);
366
                                Curve extendedCurve =
367
                                    extendLine(insertedPoint, curve);
368
                                extendedMultiCurve.addCurve(extendedCurve);
369
                            }
370

  
371
                            eFeature.setDefaultGeometry(extendedMultiCurve);
372

  
373
                        } else if (geometry instanceof Curve) {
374
                            Curve extendedCurve =
375
                                extendLine(insertedPoint, (Curve) geometry);
376
                            eFeature.setDefaultGeometry(extendedCurve);
377
                        }
378

  
379
                        linesToExtend.update(eFeature);
380
                    }
381
                });
382

  
383
                linesToExtend.dispose();
384

  
385
            } catch (BaseException e) {
386
                throw new FinishServiceException(e);
387
            }
388
        }
389
    }
390

  
391
    private MultiCurve createMultiCurve(Geometry geometry)
392
        throws FinishServiceException {
393

  
394
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
395
        int subtype = geometry.getGeometryType().getSubType();
396
        MultiCurve extendedMultiCurve = null;
397

  
398
        try {
399
            extendedMultiCurve = geoManager.createMultiCurve(subtype);
400
        } catch (CreateGeometryException e) {
401
            throw new FinishServiceException(e);
402
        }
403
        return extendedMultiCurve;
404
    }
405

  
406
    public void start() throws StartServiceException, InvalidEntryException {
407
        selection = null;
408
        linesToExtend = null;
409
        FeatureSelection selected = null;
410
        if (featureStore != null) {
411
            try {
412
                selected = featureStore.getFeatureSelection();
413
            } catch (DataException e) {
414
                throw new StartServiceException(e);
415
            }
416
            if (selected.getSelectedCount() > 0) {
417
                try {
418
                    setValue(selected);
419
                } catch (InvalidEntryException e) {
420
                    throw new InvalidEntryException(e);
421
                }
422
            }
423
        }
424
    }
425

  
426
    public String getName() {
427
        return ExtendLineEditingProviderFactory.PROVIDER_NAME;
428
    }
429

  
430
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/src/main/java/org/gvsig/vectorediting/lib/prov/extendline/operation/ExtendLineOperation.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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

  
25
package org.gvsig.vectorediting.lib.prov.extendline.operation;
26

  
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.FeatureSelection;
29
import org.gvsig.fmap.geom.exception.CreateGeometryException;
30
import org.gvsig.fmap.geom.operation.GeometryOperationException;
31
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
32
import org.gvsig.fmap.geom.primitive.Curve;
33
import org.gvsig.fmap.geom.primitive.Point;
34

  
35
/**
36
 * Represents an operation to extend curve.
37
 * 
38
 * @author llmarques
39
 *
40
 */
41
public interface ExtendLineOperation {
42

  
43
    /**
44
     * Extend line to boundary objects received as parameters.
45
     * 
46
     * Inserted point is the point inserted by user. It is used to determinate
47
     * what side of curve it must extend.
48
     * 
49
     * If curveToBeExtended does not intersect with any geometry, the geometry will
50
     * not be modified.
51
     * 
52
     * @param curveToBeExtended
53
     *            Curve to be extended.
54
     * @param insertedPoint
55
     *            Point inserted by user to determinate what side of curve must
56
     *            be extended.
57
     * @param boundaryObjects
58
     *            If curveToBeExtended intersects with some boundary object, it will
59
     *            be extend to it. If there are several boundary objects that
60
     *            intersects with curveToBeExtended, it will be extended to nearest
61
     *            point.
62
     * @return extended line.
63
     */
64
    public Curve extendLine(Curve curveToBeExtended, Point insertedPoint,
65
        FeatureSelection boundaryObjects)
66
        throws GeometryOperationNotSupportedException,
67
        GeometryOperationException, DataException, CreateGeometryException;
68

  
69
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/src/main/java/org/gvsig/vectorediting/lib/prov/extendline/operation/ExtendLineOperationUtils.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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

  
25
package org.gvsig.vectorediting.lib.prov.extendline.operation;
26

  
27
import java.util.HashMap;
28
import java.util.Map;
29

  
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureSelection;
33
import org.gvsig.fmap.geom.Geometry;
34
import org.gvsig.fmap.geom.Geometry.TYPES;
35
import org.gvsig.fmap.geom.GeometryLocator;
36
import org.gvsig.fmap.geom.GeometryManager;
37
import org.gvsig.fmap.geom.aggregate.MultiPoint;
38
import org.gvsig.fmap.geom.exception.CreateGeometryException;
39
import org.gvsig.fmap.geom.operation.GeometryOperationException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
41
import org.gvsig.fmap.geom.primitive.Arc;
42
import org.gvsig.fmap.geom.primitive.Curve;
43
import org.gvsig.fmap.geom.primitive.Point;
44
import org.gvsig.fmap.geom.primitive.Primitive;
45
import org.gvsig.tools.dispose.DisposableIterator;
46

  
47
/**
48
 * @author llmarques
49
 *
50
 */
51
public class ExtendLineOperationUtils {
52

  
53
    /**
54
     * Use it to indicate start side should be extended
55
     */
56
    public static final String START_SIDE = "start";
57

  
58
    /**
59
     * Use it to indicate end side should be extended
60
     */
61
    public static final String END_SIDE = "end";
62

  
63
    /**
64
     * Number of projections computed to know intersection points.
65
     */
66
    private final static int PROJECTION_LIMIT = 100;
67

  
68
    private static Map<Integer, ExtendLineOperation> operations =
69
        new HashMap<Integer, ExtendLineOperation>();
70

  
71
    public ExtendLineOperationUtils() {
72
    }
73

  
74
    public static void register(ExtendLineOperation operation, int geometryType) {
75
        operations.put(geometryType, operation);
76
    }
77

  
78
    public static ExtendLineOperation getOperation(Primitive geom) {
79
        Integer type = geom.getGeometryType().getType();
80

  
81
        ExtendLineOperation operation = operations.get(type);
82

  
83
        return operation;
84
    }
85

  
86
    /**
87
     * Calculates the nearest intersection among curve and boundary objects
88
     * depending on side received as parameter.
89
     * 
90
     * @param line
91
     *            to be extended
92
     * @param sideToExtend
93
     *            What side will be extend. Use
94
     *            {@link ExtendLineOperationUtils#START_SIDE} and
95
     *            {@link ExtendLineOperationUtils#END_SIDE}
96
     * @param boundaryObjects
97
     *            to calculate intersection points.
98
     * @return the nearest intersection point. Return Null if arc does not
99
     *         intersect
100
     *         with any boundary object
101
     */
102
    public static Point curveIntersection(Curve line, String sideToExtend,
103
        FeatureSelection boundaryObjects) throws CreateGeometryException,
104
        DataException, GeometryOperationNotSupportedException,
105
        GeometryOperationException {
106

  
107
        Point initPoint = null;
108
        Point endPoint = null;
109

  
110
        // Start side line is formed by second point and first point
111
        if (sideToExtend.equalsIgnoreCase(START_SIDE)) {
112

  
113
            initPoint = line.getVertex(1);
114
            endPoint = line.getVertex(0);
115

  
116
            // End side line is formed by penultimate point and last point
117
        } else if (sideToExtend.equalsIgnoreCase(END_SIDE)) {
118

  
119
            initPoint = line.getVertex(line.getNumVertices() - 2);
120
            endPoint = line.getVertex(line.getNumVertices() - 1);
121

  
122
        }
123

  
124
        return getIntersectionOfProjectedLine(initPoint, endPoint,
125
            boundaryObjects);
126
    }
127

  
128
    /**
129
     * Calculates the nearest intersection point among arc and boundary objects
130
     * depending on side received as parameter.
131
     * 
132
     * Strategy:
133
     * 
134
     * 1- Create a full arc with the same center and radius of arc received by
135
     * parameter.
136
     * 2- Iterate over boundary objects.
137
     * 3- If some boundary object intersects with full arc, calculates the
138
     * distance to start point or end point depending on side to be extend.
139
     * 4- Return the nearest intersection point.
140
     * 
141
     * @param arcToBeExtended
142
     *            Arc to be extended
143
     * @param sideToExtend
144
     *            What side will be extend. Use
145
     *            {@link ExtendLineOperationUtils#START_SIDE} and
146
     *            {@link ExtendLineOperationUtils#END_SIDE}
147
     * @param boundaryObjects
148
     *            to calculate intersection points.
149
     * @return the nearest intersection point. Return Null if arc does not
150
     *         intersect with any boundary object
151
     */
152
    public static Point arcIntersection(Arc arcToBeExtended,
153
        String sideToExtend, FeatureSelection boundaryObjects)
154
        throws GeometryOperationNotSupportedException,
155
        GeometryOperationException, CreateGeometryException, DataException {
156

  
157
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
158
        int subtype = arcToBeExtended.getGeometryType().getSubType();
159

  
160
        Point center = arcToBeExtended.getCenterPoint();
161
        double radius = center.distance(arcToBeExtended.getInitPoint());
162

  
163
        Point intersection = null;
164

  
165
        double minDistance = Double.POSITIVE_INFINITY;
166

  
167
        Arc tmpArc = (Arc) geoManager.create(TYPES.ARC, subtype);
168
        tmpArc.setPoints(center, radius, 0, Math.PI * 2);
169

  
170
        DisposableIterator it = boundaryObjects.fastIterator();
171
        while (it.hasNext()) {
172
            Feature feature = (Feature) it.next();
173
            Geometry geometry = feature.getDefaultGeometry();
174
            if (tmpArc.intersects(geometry)) {
175
                Geometry intersectionGeometry = tmpArc.intersection(geometry);
176

  
177
                if (intersectionGeometry instanceof MultiPoint) {
178
                    MultiPoint intersectionMultiPoint =
179
                        (MultiPoint) intersectionGeometry;
180

  
181
                    for (int i = 0; i < intersectionMultiPoint
182
                        .getPrimitivesNumber(); i++) {
183
                        Point point = intersectionMultiPoint.getPointAt(i);
184
                        double distance = Double.POSITIVE_INFINITY;
185

  
186
                        if (sideToExtend.equalsIgnoreCase(START_SIDE)) {
187
                            distance =
188
                                point.distance(arcToBeExtended.getInitPoint());
189
                        } else if (sideToExtend.equalsIgnoreCase(END_SIDE)) {
190
                            distance =
191
                                point.distance(arcToBeExtended.getEndPoint());
192
                        }
193

  
194
                        if (distance < minDistance) {
195
                            intersection = point;
196
                            minDistance = distance;
197
                        }
198
                    }
199
                } else if (intersectionGeometry instanceof Point) {
200
                    Point intersectionPoint = (Point) intersectionGeometry;
201
                    double distance = Double.POSITIVE_INFINITY;
202

  
203
                    if (sideToExtend.equalsIgnoreCase("start")) {
204
                        distance =
205
                            intersectionPoint.distance(arcToBeExtended
206
                                .getInitPoint());
207
                    } else if (sideToExtend.equalsIgnoreCase("end")) {
208
                        distance =
209
                            intersectionPoint.distance(arcToBeExtended
210
                                .getEndPoint());
211
                    }
212

  
213
                    if (distance < minDistance) {
214
                        intersection = intersectionPoint;
215
                        minDistance = distance;
216
                    }
217
                }
218
            }
219
        }
220
        it.dispose();
221
        return intersection;
222
    }
223

  
224
    // FIXME: remove this method when geometry library has this utility method
225
    public static double getAngle(Point start, Point end)
226
        throws GeometryOperationNotSupportedException,
227
        GeometryOperationException {
228
        double angle =
229
            Math.acos((end.getX() - start.getX()) / start.distance(end));
230

  
231
        if (start.getY() > end.getY()) {
232
            angle = -angle;
233
        }
234

  
235
        if (angle < 0) {
236
            angle += (2 * Math.PI);
237
        }
238

  
239
        return angle;
240
    }
241

  
242
    /**
243
     * Gets intersection among the line formed by initPoint and endPoint and
244
     * boundary objects. If line or its projection does not intersect with any
245
     * boundary object return null.
246
     * 
247
     * Strategy:
248
     * 
249
     * 1- Get module of line to determine if an intersection point already be
250
     * vertex of line. If the distance between intersection point and start
251
     * point of line is less than module indicates that intersection point
252
     * already be curve point.
253
     * 2- Project line with the line parametric equation.
254
     * 3- Iterate over boundary objects.
255
     * 4- Check if boundary object does not contains end point of projected
256
     * line.
257
     * 5- If projected line intersects with any boundary object, get the nearest
258
     * intersection point
259
     * 6- Return it.
260
     * 
261
     * 
262
     * @param initPoint
263
     *            of curve to extend
264
     * @param endPoint
265
     *            end point of curve to extend
266
     * @param boundaryObjects
267
     *            to calculate intersection points.
268
     * @return the nearest intersection point. Return Null if arc does not
269
     *         intersect with any boundary object
270
     */
271
    public static Point getIntersectionOfProjectedLine(Point initPoint,
272
        Point endPoint, FeatureSelection boundaryObjects)
273
        throws GeometryOperationNotSupportedException,
274
        GeometryOperationException, DataException, CreateGeometryException {
275

  
276
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
277
        int subtype = initPoint.getGeometryType().getSubType();
278

  
279
        double module = initPoint.distance(endPoint);
280

  
281
        double minDistance = Double.POSITIVE_INFINITY;
282
        Point intersectionPoint = null;
283

  
284
        double x, y;
285
        double x1 = initPoint.getX();
286
        double y1 = initPoint.getY();
287
        double x2 = endPoint.getX();
288
        double y2 = endPoint.getY();
289

  
290
        for (int t = 1; t < PROJECTION_LIMIT; t += 10) {
291
            x = (x2 - x1) * t + x1;
292
            y = (y2 - y1) * t + y1;
293

  
294
            DisposableIterator it = boundaryObjects.fastIterator();
295
            while (it.hasNext()) {
296
                Feature feature = (Feature) it.next();
297
                Geometry geometry = feature.getDefaultGeometry();
298
                Point projectedPoint = geoManager.createPoint(x, y, subtype);
299

  
300
                if (!geometry.contains(projectedPoint)) {
301
                    Curve tmpLine = geoManager.createLine(subtype);
302
                    tmpLine.setPoints(initPoint, projectedPoint);
303

  
304
                    if (tmpLine.intersects(geometry)) {
305

  
306
                        Geometry intersecionGeometry =
307
                            geometry.intersection(tmpLine);
308

  
309
                        if (intersecionGeometry instanceof Point) {
310

  
311
                            double distance =
312
                                ((Point) intersecionGeometry)
313
                                    .distance(initPoint);
314

  
315
                            if (distance < minDistance && distance > module) {
316
                                intersectionPoint = (Point) intersecionGeometry;
317
                                minDistance = distance;
318
                            }
319

  
320
                        } else if (intersecionGeometry instanceof MultiPoint) {
321

  
322
                            MultiPoint intersectionMultiPoint =
323
                                (MultiPoint) intersecionGeometry;
324

  
325
                            for (int i = 0; i < intersectionMultiPoint
326
                                .getPrimitivesNumber(); i++) {
327

  
328
                                double distance =
329
                                    intersectionMultiPoint.getPointAt(i)
330
                                        .distance(initPoint);
331

  
332
                                if (distance < minDistance && distance > module) {
333
                                    intersectionPoint =
334
                                        intersectionMultiPoint.getPointAt(i);
335
                                    minDistance = distance;
336
                                }
337
                            }
338
                        } else if (intersecionGeometry instanceof Curve) {
339

  
340
                            Curve intersectionCurve =
341
                                (Curve) intersecionGeometry;
342

  
343
                            for (int i = 0; i < intersectionCurve
344
                                .getNumVertices(); i++) {
345

  
346
                                double distance =
347
                                    intersectionCurve.getVertex(i).distance(
348
                                        initPoint);
349

  
350
                                if (distance < minDistance && distance > module) {
351
                                    intersectionPoint =
352
                                        intersectionCurve.getVertex(i);
353
                                    minDistance = distance;
354
                                }
355
                            }
356
                        }
357
                    }
358
                }
359
            }
360
            it.dispose();
361
            if (intersectionPoint != null) {
362
                break;
363
            }
364
        }
365
        return intersectionPoint;
366
    }
367
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/src/main/java/org/gvsig/vectorediting/lib/prov/extendline/operation/CurveExtendLineOperation.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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

  
25
package org.gvsig.vectorediting.lib.prov.extendline.operation;
26

  
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.FeatureSelection;
29
import org.gvsig.fmap.geom.GeometryLocator;
30
import org.gvsig.fmap.geom.GeometryManager;
31
import org.gvsig.fmap.geom.exception.CreateGeometryException;
32
import org.gvsig.fmap.geom.operation.GeometryOperationException;
33
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
34
import org.gvsig.fmap.geom.primitive.Curve;
35
import org.gvsig.fmap.geom.primitive.Point;
36

  
37
/**
38
 * @author llmarques
39
 *
40
 */
41
public class CurveExtendLineOperation implements ExtendLineOperation {
42

  
43
    public Curve extendLine(Curve lineToExtend, Point insertedPoint,
44
        FeatureSelection boundaryObjects)
45
        throws GeometryOperationNotSupportedException,
46
        GeometryOperationException, DataException, CreateGeometryException {
47

  
48
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
49
        int subtype = lineToExtend.getGeometryType().getSubType();
50
        Curve extendedLine = geoManager.createLine(subtype);
51

  
52
        Point startVertex = lineToExtend.getVertex(0);
53
        Point endVertex =
54
            lineToExtend.getVertex(lineToExtend.getNumVertices() - 1);
55

  
56
        Point startIntersectionPoint = null;
57
        Point endIntersectionPoint = null;
58
        if (insertedPoint.distance(startVertex) < insertedPoint
59
            .distance(endVertex)) {
60
            startIntersectionPoint =
61
                ExtendLineOperationUtils.curveIntersection(lineToExtend,
62
                    ExtendLineOperationUtils.START_SIDE, boundaryObjects);
63

  
64
        } else {
65
            endIntersectionPoint =
66
                ExtendLineOperationUtils.curveIntersection(lineToExtend,
67
                    ExtendLineOperationUtils.END_SIDE, boundaryObjects);
68
        }
69

  
70
        if (startIntersectionPoint != null) {
71
            extendedLine.addVertex(startIntersectionPoint);
72
        }
73

  
74
        for (int i = 0; i < lineToExtend.getNumVertices(); i++) {
75
            extendedLine.addVertex(lineToExtend.getVertex(i));
76
        }
77

  
78
        if (endIntersectionPoint != null) {
79
            extendedLine.addVertex(endIntersectionPoint);
80
        }
81

  
82
        return extendedLine;
83
    }
84
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/src/main/java/org/gvsig/vectorediting/lib/prov/extendline/operation/ArcExtendLineOperation.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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

  
25
package org.gvsig.vectorediting.lib.prov.extendline.operation;
26

  
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.FeatureSelection;
29
import org.gvsig.fmap.geom.Geometry.TYPES;
30
import org.gvsig.fmap.geom.GeometryLocator;
31
import org.gvsig.fmap.geom.GeometryManager;
32
import org.gvsig.fmap.geom.exception.CreateGeometryException;
33
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
35
import org.gvsig.fmap.geom.primitive.Arc;
36
import org.gvsig.fmap.geom.primitive.Curve;
37
import org.gvsig.fmap.geom.primitive.Point;
38

  
39
/**
40
 * @author llmarques
41
 *
42
 */
43
public class ArcExtendLineOperation implements ExtendLineOperation {
44

  
45
    public Curve extendLine(Curve lineToExtend, Point insertedPoint,
46
        FeatureSelection boundaryObjects)
47
        throws GeometryOperationNotSupportedException,
48
        GeometryOperationException, DataException, CreateGeometryException {
49

  
50
        Arc arcToBeExtend = (Arc) lineToExtend;
51

  
52
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
53
        int subtype = lineToExtend.getGeometryType().getSubType();
54
        Arc extendedArc = (Arc) geoManager.create(TYPES.ARC, subtype);
55

  
56
        Point startVertex = arcToBeExtend.getInitPoint();
57
        Point endVertex = arcToBeExtend.getEndPoint();
58

  
59
        Point startIntersectionPoint = null;
60
        Point endIntersectionPoint = null;
61

  
62
        if (insertedPoint.distance(startVertex) < insertedPoint
63
            .distance(endVertex)) {
64
            startIntersectionPoint =
65
                ExtendLineOperationUtils.arcIntersection(arcToBeExtend,
66
                    ExtendLineOperationUtils.START_SIDE, boundaryObjects);
67

  
68
        } else {
69
            endIntersectionPoint =
70
                ExtendLineOperationUtils.arcIntersection(arcToBeExtend,
71
                    ExtendLineOperationUtils.END_SIDE, boundaryObjects);
72
        }
73

  
74
        if (startIntersectionPoint == null) {
75
            startIntersectionPoint = arcToBeExtend.getInitPoint();
76
        }
77

  
78
        if (endIntersectionPoint == null) {
79
            endIntersectionPoint = arcToBeExtend.getEndPoint();
80
        }
81

  
82
        Point center = arcToBeExtend.getCenterPoint();
83
        double radius = center.distance(arcToBeExtend.getInitPoint());
84
        double startAngle =
85
            ExtendLineOperationUtils.getAngle(center, startIntersectionPoint);
86
        double endAngle =
87
            ExtendLineOperationUtils.getAngle(center, endIntersectionPoint);
88

  
89
        extendedArc.setPointsStartEnd(center, radius, startAngle, endAngle);
90
        return extendedArc;
91
    }
92
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/src/main/java/org/gvsig/vectorediting/lib/prov/extendline/ExtendLineEditingProviderFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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

  
25
package org.gvsig.vectorediting.lib.prov.extendline;
26

  
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.dynobject.DynClass;
30
import org.gvsig.tools.dynobject.DynObject;
31
import org.gvsig.tools.service.spi.AbstractProviderFactory;
32
import org.gvsig.tools.service.spi.Provider;
33
import org.gvsig.tools.service.spi.ProviderServices;
34
import org.gvsig.vectorediting.lib.api.EditingServiceInfo;
35
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceinfo;
36
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory;
37

  
38
/**
39
 * @author llmarques
40
 *
41
 */
42
public class ExtendLineEditingProviderFactory extends AbstractProviderFactory
43
    implements EditingProviderFactory {
44

  
45
    public static final String PROVIDER_NAME = "modify-extend-line";
46

  
47
    private final static String PROVIDER_DESCRIPTION =
48
        "Extends lines to selected objects";
49

  
50
    public void initialize() {
51
    }
52

  
53
    public EditingServiceInfo getServiceInfo() {
54
        EditingServiceInfo serviceInfo =
55
            new DefaultEditingServiceinfo(PROVIDER_NAME, PROVIDER_DESCRIPTION,
56
                false, null, new int[] { Geometry.TYPES.CURVE,
57
                    Geometry.TYPES.MULTICURVE });
58

  
59
        return serviceInfo;
60
    }
61

  
62
    @Override
63
    protected Provider doCreate(DynObject parameters, ProviderServices services) {
64
        return new ExtendLineEditingProvider(services, parameters);
65
    }
66

  
67
    @Override
68
    public DynObject createParameters() {
69
        DynObject parameters = super.createParameters();
70
        parameters.setDynValue(PROVIDER_NAME_FIELD, PROVIDER_NAME);
71
        return parameters;
72
    }
73

  
74
    @Override
75
    protected DynClass createParametersDynClass() {
76
        DynClass dynclass =
77
            ToolsLocator.getDynObjectManager().createDynClass(PROVIDER_NAME,
78
                PROVIDER_DESCRIPTION);
79

  
80
        dynclass.addDynFieldString(PROVIDER_NAME_FIELD);
81
        dynclass.addDynFieldObject(FEATURE_STORE_FIELD);
82
        dynclass.addDynFieldObject(MAPCONTEXT_FIELD);
83
        return dynclass;
84
    }
85

  
86
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/src/main/java/org/gvsig/vectorediting/lib/prov/extendline/ExtendLineEditingLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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

  
25
package org.gvsig.vectorediting.lib.prov.extendline;
26

  
27
import org.gvsig.fmap.geom.Geometry.TYPES;
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.i18n.I18nManager;
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32
import org.gvsig.vectorediting.lib.api.EditingLibrary;
33
import org.gvsig.vectorediting.lib.prov.extendline.operation.ArcExtendLineOperation;
34
import org.gvsig.vectorediting.lib.prov.extendline.operation.CurveExtendLineOperation;
35
import org.gvsig.vectorediting.lib.prov.extendline.operation.ExtendLineOperationUtils;
36
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
37
import org.gvsig.vectorediting.lib.spi.EditingProviderManager;
38

  
39
/**
40
 * @author llmarques
41
 *
42
 */
43
public class ExtendLineEditingLibrary extends AbstractLibrary {
44

  
45
    @Override
46
    public void doRegistration() {
47
        registerAsServiceOf(EditingLibrary.class);
48
    }
49

  
50
    @Override
51
    protected void doInitialize() throws LibraryException {
52
    }
53

  
54
    @Override
55
    protected void doPostInitialize() throws LibraryException {
56
        EditingProviderManager manager =
57
            EditingProviderLocator.getProviderManager();
58

  
59
        manager.addProviderFactory(new ExtendLineEditingProviderFactory());
60

  
61
        manager.registerIcon("vectorediting-tools", "modify-extend-line", this
62
            .getClass().getClassLoader(), this.getClass().getName());
63

  
64
        ExtendLineOperationUtils.register(new ArcExtendLineOperation(),
65
            TYPES.ARC);
66
        ExtendLineOperationUtils.register(new CurveExtendLineOperation(),
67
            TYPES.SPLINE);
68
        ExtendLineOperationUtils.register(new CurveExtendLineOperation(),
69
            TYPES.LINE);
70
        ExtendLineOperationUtils.register(new CurveExtendLineOperation(),
71
            TYPES.CURVE);
72

  
73
        registerTranslations();
74
    }
75

  
76
    private void registerTranslations() {
77
        I18nManager manager = ToolsLocator.getI18nManager();
78
        manager.addResourceFamily("i18n/text",
79
            this.getClass().getClassLoader(), "modidy-extend-line");
80
    }
81

  
82
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.vectorediting.lib.prov.extendline.ExtendLineEditingLibrary
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.extendline/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.vectorediting.lib.prov</artifactId>
6
    <version>1.0.1-SNAPSHOT</version>
7
  </parent>
8
  <artifactId>org.gvsig.vectorediting.lib.prov.extendline</artifactId>
9
  <name>org.gvsig.vectorediting.lib.prov.extendline</name>
10
</project>
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
81 81
	    <include>org.gvsig:org.gvsig.vectorediting.lib.prov.autopolygon</include>
82 82
		<include>org.gvsig:org.gvsig.vectorediting.lib.prov.join</include>
83 83
	    <include>org.gvsig:org.gvsig.vectorediting.lib.prov.stretch</include>
84
	    <include>org.gvsig:org.gvsig.vectorediting.lib.prov.extendline</include>
84 85

  
85 86
      </includes>
86 87
    </dependencySet>
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/resources-plugin/i18n/text.properties
24 24
modify_rotate = Rotar geometr\u00eda
25 25
modify_duplicate = Duplicar geometr\u00eda
26 26
modify_split_line = Partir linea por un punto
27
modify_split = Partir geometr\u00eda
27 28
modify_scale = Escalar geometr\u00eda
28 29
modify_simplify = Simplificar geometr\u00eda
29 30
modify_join = Unir geometr\u00edas
30 31
insert_autopolygon = Insertar autopol\u00edgono
31 32
modify_stretch = Estirar geometr\u00eda
33
moidfy_extend_line = Alargar l\u00ednea hasta objeto
32 34
selection=Selecci\u00f3n
33 35
invalid_option=Opci\u00f3n no v\u00e1lida
34 36
center=Centro
......
42 44
arc_mode = Modo arco
43 45
line_mode = Modo l\u00ednea
44 46
select_new_tool= Seleccione una nueva herramienta
45
draw_geometry= Seleccione una herramienta para dibujar un poligono interno
46
draw_geometry_to_autopolygon = Seleccione una herramienta para dibujar un autopol?gono
47
draw_geometry_to_select_vertex = Seleccione una herramienta poligonal para seleccionar v?rtices
47
draw_geometry_to_internal_polygon= Seleccione una herramienta para dibujar un pol\u00edgono interno
48
draw_geometry_to_autopolygon = Seleccione una herramienta para dibujar un autopol\u00edgono
49
draw_geometry_to_split = Seleccione una herramienta para partir las geometr\u00edas
50
draw_geometry_to_select_vertex = Seleccione una herramienta poligonal para seleccionar v\u00e9rtices
48 51
save = Guardar
49 52
discard = Descartar
50 53
continue = Continuar
......
86 89
origin_point = Origen
87 90
scale_factor_or_reference_point = Factor de escala o punto de referencia
88 91
second_scale_point = Segundo punto para la escala
89
tolerance = Tolerancia
92
tolerance = Tolerancia
93
line_to_extend = Seleccione lineas para alargar
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
24 24
modify_rotate = Rotate geometry
25 25
modify_duplicate = Duplicate geometry
26 26
modify_split_line = Split line open by a point
27
modify_split = Split geometry
27 28
modify_scale = Scale geometry
28 29
modify_simplify = Simplify geometry
29 30
insert_autopolygon = Insert autopolygon
30 31
modify_join = Join geometries
31 32
modify_stretch = Stretch geometry
33
moidfy_extend_line = Extend line to object
32 34
selection=Selection
33 35
invalid_option=Invalid option
34 36
center=Center
......
42 44
arc_mode = Arc mode
43 45
line_mode = Line mode
44 46
select_new_tool= Select a new tool
45
draw_geometry= Select tool to draw a internal polygon
47
draw_geometry_to_interal_polygon= Select tool to draw a internal polygon
46 48
draw_geometry_to_autopolygon = Select tool to draw an autopolygon
49
draw_geometry_to_split = Select tool to split selected geometries
47 50
draw_geometry_to_select_vertex = Select a polygonal tool to select vertex
48 51
save = Save
49 52
discard = Discard
......
86 89
origin_point = Origin
87 90
scale_factor_or_reference_point = Scale factor or reference point
88 91
second_scale_point = Second scale point
89
tolerance = Tolerance
92
tolerance = Tolerance
93
line_to_extend = Select lines to extend
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/resources-plugin/config.xml
132 132
        position="601002900" action-command="modify-duplicate" icon="modify-duplicate"
133 133
        accelerator="" />
134 134

  
135
      <action name="modify-split-line" label="modify_split_line" tooltip="modify_split_line"
135
       <action name="modify-split-line" label="modify_split_line" tooltip="modify_split_line"
136 136
        position="601003000" action-command="modify-split-line" icon="modify-split-line"
137 137
        accelerator="" />
138 138

  
......
155 155
      <action name="modify-stretch" label="modify_stretch" tooltip="modify_stretch"
156 156
        position="601003500" action-command="modify-stretch" icon="modify-stretch"
157 157
        accelerator="" />
158
        
159
      <action name="modify-extend-line" label="modify_extend_line" tooltip="modify_extend_line"
160
        position="601003600" action-command="modify-extend-line" icon="modify-extend-line"
161
        accelerator="" />
158 162

  
159 163

  
160 164
      <menu text="Layer/Insert/insert_point" name="insert-point" />
......
186 190
      <menu text="Layer/Modify/insert_autopolygon" name="insert_autopolygon" />
187 191
      <menu text="Layer/Modify/modify_join" name="modify-join" />
188 192
      <menu text="Layer/Modify/modify_stretch" name="modify-stretch" />
193
      <menu text="Layer/Modify/modify_extend_line" name="modify-extend-line" />
189 194

  
190 195
      <tool-bar name="vector_editing" position="600800000">
191 196
        <selectable-tool name="insert-point" />
......
217 222
        <selectable-tool name="insert-autopolygon" />
218 223
        <selectable-tool name="modify-join" />
219 224
        <selectable-tool name="modify-stretch" />
225
        <selectable-tool name="modify-extend-line" />
220 226
      </tool-bar>
221 227

  
222 228
    </extension>
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/pom.xml
1 1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3 4
	<modelVersion>4.0.0</modelVersion>
4 5
	<artifactId>org.gvsig.vectorediting.app.mainplugin</artifactId>
5 6
	<packaging>jar</packaging>
......
14 15
	<properties>
15 16
		<!-- Package info property values -->
16 17
		<gvsig.package.info.state>devel</gvsig.package.info.state>
17
		<gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.1.0-A</gvsig.package.info.dependencies>
18
		<gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin
19
			-ge 2.1.0-A</gvsig.package.info.dependencies>
18 20
		<gvsig.package.info.official>true</gvsig.package.info.official>
19 21
		<gvsig.package.info.name>Vector editing</gvsig.package.info.name>
20
		<gvsig.package.info.description>Vector editing: provides tools to edit vectorial layers.</gvsig.package.info.description>
22
		<gvsig.package.info.description>Vector editing: provides tools to edit
23
			vectorial layers.</gvsig.package.info.description>
21 24
		<gvsig.package.info.categories>Vector</gvsig.package.info.categories>
22 25
		<gvsig.package.info.javaVM>j1_6</gvsig.package.info.javaVM>
23 26
		<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-vectorediting/pool</gvsig.package.info.poolURL>
......
171 174
				org.gvsig.vectorediting.lib.prov.multipoint
172 175
			</artifactId>
173 176
		</dependency>
174
    <dependency>
175
      <groupId>org.gvsig</groupId>
176
      <artifactId>
177
        org.gvsig.vectorediting.lib.prov.autopolygon
178
      </artifactId>
179
    </dependency>
180
    		<dependency>
177
		<dependency>
181 178
			<groupId>org.gvsig</groupId>
182 179
			<artifactId>
180
                org.gvsig.vectorediting.lib.prov.autopolygon
181
            </artifactId>
182
		</dependency>
183
		<dependency>
184
			<groupId>org.gvsig</groupId>
185
			<artifactId>
183 186
				org.gvsig.vectorediting.lib.prov.join
184 187
			</artifactId>
185
	</dependency>
186
    
187

  
188
    <dependency>
189
      <groupId>org.gvsig</groupId>
190
      <artifactId>
191
        org.gvsig.vectorediting.lib.prov.stretch
192
      </artifactId>
193
    </dependency>
194

  
188
		</dependency>
189
		<dependency>
190
			<groupId>org.gvsig</groupId>
191
			<artifactId>
192
                org.gvsig.vectorediting.lib.prov.stretch
193
            </artifactId>
194
		</dependency>
195
		<dependency>
196
			<groupId>org.gvsig</groupId>
197
			<artifactId>
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff