Revision 2109

View differences:

org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.circlecr/src/main/java/org/gvsig/vectorediting/lib/prov/circlecr/CircleCREditingLibrary.java
52 52
        manager.addProviderFactory(new CircumferenceCREditingProviderFactory());
53 53
        manager.addProviderFactory(new Circle2Tg1PEditingProviderFactory());
54 54
        manager.addProviderFactory(new Circumference2Tg1PEditingProviderFactory());
55
        manager.addProviderFactory(new CircleTanTanRadiusEditingProviderFactory());
56
        manager.addProviderFactory(new CircumferenceTanTanRadiusEditingProviderFactory());
55 57

  
56 58
        manager.registerIcon("vectorediting-tools", "insert-circle-cr", this
57 59
            .getClass().getClassLoader(), this.getClass().getName());
......
61 63
            .getClass().getClassLoader(), this.getClass().getName());
62 64
        manager.registerIcon("vectorediting-tools", "insert-circumference-2tg1p",
63 65
            this.getClass().getClassLoader(), this.getClass().getName());
66
        manager.registerIcon("vectorediting-tools", "insert-circle-tantanradius", this
67
            .getClass().getClassLoader(), this.getClass().getName());
68
        manager.registerIcon("vectorediting-tools", "insert-circumference-tantanradius",
69
            this.getClass().getClassLoader(), this.getClass().getName());
64 70

  
65 71
        registerTranslations();
66 72
    }
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.circlecr/src/main/java/org/gvsig/vectorediting/lib/prov/circlecr/CircumferenceTanTanRadiusEditingProviderFactory.java
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

  
25
package org.gvsig.vectorediting.lib.prov.circlecr;
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
public class CircumferenceTanTanRadiusEditingProviderFactory extends AbstractProviderFactory
39
implements EditingProviderFactory {
40

  
41
    public static final String PROVIDER_NAME = "insert-circumference-tantanradius";
42

  
43
    private final static String PROVIDER_DESCRIPTION =
44
        "Creates circumferences from two tangent objects and the radius";
45

  
46
    public void initialize() {
47

  
48
    }
49

  
50
    public EditingServiceInfo getServiceInfo() {
51
        EditingServiceInfo serviceInfo =
52
            new DefaultEditingServiceinfo(
53
                PROVIDER_NAME,
54
                "",
55
                true,
56
                null,
57
                new int[] { Geometry.TYPES.LINE, Geometry.TYPES.MULTILINE, Geometry.TYPES.CURVE, Geometry.TYPES.MULTICURVE });
58

  
59
        return serviceInfo;
60
    }
61

  
62
    @Override
63
    protected Provider doCreate(DynObject parameters, ProviderServices services) {
64
        return new CircumferenceTanTanRadiusEditingProvider(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.circlecr/src/main/java/org/gvsig/vectorediting/lib/prov/circlecr/CircleTanTanRadiusEditingProviderFactory.java
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

  
25
package org.gvsig.vectorediting.lib.prov.circlecr;
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
public class CircleTanTanRadiusEditingProviderFactory extends AbstractProviderFactory
39
implements EditingProviderFactory {
40

  
41
    public static final String PROVIDER_NAME = "insert-circle-tantanradius";
42

  
43
    private final static String PROVIDER_DESCRIPTION =
44
        "Creates circles from two tangent objects and the radius";
45

  
46
    public void initialize() {
47

  
48
    }
49

  
50
    public EditingServiceInfo getServiceInfo() {
51
        EditingServiceInfo serviceInfo =
52
            new DefaultEditingServiceinfo(
53
                PROVIDER_NAME,
54
                "",
55
                true,
56
                null,
57
                new int[] { Geometry.TYPES.POLYGON, Geometry.TYPES.MULTIPOLYGON, Geometry.TYPES.SURFACE, Geometry.TYPES.MULTISURFACE });
58

  
59
        return serviceInfo;
60
    }
61

  
62
    @Override
63
    protected Provider doCreate(DynObject parameters, ProviderServices services) {
64
        return new CircleTanTanRadiusEditingProvider(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.circlecr/src/main/java/org/gvsig/vectorediting/lib/prov/circlecr/CircumferenceTanTanRadiusEditingProvider.java
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

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

  
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.GeometryLocator;
29
import org.gvsig.fmap.geom.GeometryManager;
30
import org.gvsig.fmap.geom.aggregate.MultiCurve;
31
import org.gvsig.fmap.geom.primitive.Circle;
32
import org.gvsig.fmap.geom.primitive.Circumference;
33
import org.gvsig.fmap.geom.primitive.Point;
34
import org.gvsig.fmap.geom.type.GeometryType;
35
import org.gvsig.tools.dynobject.DynObject;
36
import org.gvsig.tools.service.spi.ProviderServices;
37
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException;
38
import org.gvsig.vectorediting.lib.spi.EditingProvider;
39
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
40

  
41
public class CircumferenceTanTanRadiusEditingProvider extends CircleTanTanRadiusEditingProvider
42
implements EditingProvider {
43

  
44
    public CircumferenceTanTanRadiusEditingProvider(ProviderServices providerServices,
45
        DynObject parameters) {
46
        super(providerServices, parameters);
47
    }
48

  
49
    public Geometry finish() throws FinishServiceException {
50

  
51
        final GeometryManager geomManager = GeometryLocator.getGeometryManager();
52

  
53
        Point firstPointValue = (Point) values.get(firstPoint);
54
        Point secondPointValue = (Point) values.get(secondPoint);
55
        Double radiusValue = (Double) values.get(radius);
56

  
57
        EditingProviderServices editingProviderServices =
58
            (EditingProviderServices) getProviderServices();
59

  
60
        try {
61
            int subtype = editingProviderServices.getSubType(featureStore);
62
            GeometryType storeGeomType =
63
                editingProviderServices.getGeomType(featureStore);
64
            Circle circle =
65
                editingProviderServices.createCircle(firstGeometry, secondGeometry, radiusValue, firstPointValue, secondPointValue, subtype);
66
            Circumference circumference = (Circumference) geomManager.create(CIRCUMFERENCE, subtype);
67
            circumference.setPoints(circle.getCenter(), circle.getRadious());
68

  
69
            if (storeGeomType.isTypeOf(MULTICURVE)) {
70
                MultiCurve multicurve;
71
                multicurve =
72
                    geomManager.createMultiCurve(
73
                        storeGeomType.getSubType());
74
                multicurve.addCurve((Circumference) circumference);
75
                return multicurve;
76
            }
77

  
78
            return circumference;
79
        } catch (Exception e) {
80
            throw new FinishServiceException(e);
81
        }
82
    }
83

  
84
    @Override
85
    public String getName() {
86
        return CircumferenceTanTanRadiusEditingProviderFactory.PROVIDER_NAME;
87
    }
88

  
89
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.circlecr/src/main/java/org/gvsig/vectorediting/lib/prov/circlecr/CircleTanTanRadiusEditingProvider.java
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.circlecr;
25

  
26
import java.util.ArrayList;
27
import java.util.HashMap;
28
import java.util.List;
29
import java.util.Map;
30
import org.gvsig.euclidean.EuclideanManager;
31
import org.gvsig.fmap.dal.exception.DataException;
32

  
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.fmap.geom.GeometryLocator;
36
import org.gvsig.fmap.geom.GeometryManager;
37
import org.gvsig.fmap.geom.aggregate.MultiSurface;
38
import org.gvsig.fmap.geom.exception.CreateGeometryException;
39
import org.gvsig.fmap.geom.primitive.Circle;
40
import org.gvsig.fmap.geom.primitive.Point;
41
import org.gvsig.fmap.geom.type.GeometryType;
42
import org.gvsig.fmap.mapcontext.MapContext;
43
import org.gvsig.fmap.mapcontext.layers.FLayer;
44
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
45
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
46
import org.gvsig.tools.dynobject.DynObject;
47
import org.gvsig.tools.service.spi.ProviderServices;
48
import org.gvsig.tools.util.ToolsUtilLocator;
49
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
50
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE;
51
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException;
52
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException;
53
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException;
54
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException;
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.EditingProvider;
59
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory;
60
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
61
import org.gvsig.vectorediting.lib.spi.EditingProviderManager;
62
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
63
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
65

  
66
public class CircleTanTanRadiusEditingProvider extends AbstractEditingProvider implements
67
        EditingProvider {
68

  
69
    protected EditingServiceParameter firstPoint;
70

  
71
    protected EditingServiceParameter secondPoint;
72

  
73
    protected EditingServiceParameter radius;
74
    
75
    protected Geometry firstGeometry;
76

  
77
    protected Geometry secondGeometry;
78

  
79
    protected Map<EditingServiceParameter, Object> values;
80

  
81
    protected FeatureStore featureStore;
82
    
83
    private final DynObject parameters;
84
    
85
    private static final Logger LOGGER = LoggerFactory
86
            .getLogger(CircleTanTanRadiusEditingProvider.class);
87

  
88

  
89
    public CircleTanTanRadiusEditingProvider(ProviderServices providerServices,
90
            DynObject parameters) {
91
        super(providerServices);
92

  
93
        this.parameters = parameters;
94
        
95
        this.featureStore
96
                = (FeatureStore) parameters
97
                        .getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD);
98

  
99
        this.firstPoint
100
                = new DefaultEditingServiceParameter("point_near_tangent_in_first_geometry", "point_near_tangent_in_first_geometry",
101
                        TYPE.POSITION);
102

  
103
        this.secondPoint
104
                = new DefaultEditingServiceParameter("point_near_tangent_in_second_geometry", "point_near_tangent_in_second_geometry",
105
                        TYPE.POSITION);
106

  
107
        this.radius
108
                = new DefaultEditingServiceParameter("radius", "radius",
109
                        TYPE.VALUE);
110
    }
111

  
112
    public DefaultDrawingStatus getDrawingStatus(Point mousePosition)
113
            throws DrawServiceException {
114
        DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus();
115
        EditingProviderManager editingProviderManager
116
                = EditingProviderLocator.getProviderManager();
117
        ISymbol polygonSymbolEditing = editingProviderManager.getSymbol("polygon-symbol-editing");
118
        ISymbol auxiliaryLineSymbolEditing = editingProviderManager.getSymbol("auxiliary-line-symbol-editing");
119
        ISymbol auxiliaryPointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing");
120

  
121
        EuclideanManager euclideanManager = ToolsUtilLocator.getEuclideanManager();
122
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
123

  
124
        EditingProviderServices editingProviderServices
125
                = (EditingProviderServices) getProviderServices();
126
        
127
        if (values != null) {
128

  
129
            Point firstPointValue = (Point) values.get(firstPoint);
130
            Point secondPointValue = (Point) values.get(secondPoint);
131
            Double radiusValue = (Double) values.get(radius);
132

  
133

  
134
            if (firstPointValue != null && secondPointValue == null) {
135

  
136
                try {
137

  
138
                    int subtype = editingProviderServices.getSubType(featureStore);
139

  
140
                    drawingStatus.addStatus(firstGeometry.toLines(), auxiliaryLineSymbolEditing, "");
141
                    drawingStatus.addStatus(firstPointValue, auxiliaryPointSymbolEditing, "");
142

  
143
                } catch (Exception e) {
144
                    throw new DrawServiceException(e);
145
                }
146

  
147
            } else if (firstPointValue != null && secondPointValue != null && radiusValue == null) {
148

  
149
                try {
150

  
151
                    int subtype = editingProviderServices.getSubType(featureStore);
152

  
153
                    drawingStatus.addStatus(firstGeometry.toLines(), auxiliaryLineSymbolEditing, "");
154
                    drawingStatus.addStatus(firstPointValue, auxiliaryPointSymbolEditing, "");
155
                    drawingStatus.addStatus(secondGeometry.toLines(), auxiliaryLineSymbolEditing, "");
156
                    drawingStatus.addStatus(secondPointValue, auxiliaryPointSymbolEditing, "");
157

  
158
                } catch (Exception e) {
159
                    throw new DrawServiceException(e);
160
                }
161
            }
162
        }
163
        return drawingStatus;
164
    }
165

  
166
    public EditingServiceParameter next() {
167
        if (values != null) {
168
            if (values.get(firstPoint) == null) {
169
                return firstPoint;
170
            } else if (values.get(secondPoint) == null) {
171
                return secondPoint;
172
            } else if (values.get(radius) == null) {
173
                return radius;
174
            }
175
        }
176
        return null;
177
    }
178

  
179
    public void stop() {
180
        values.clear();
181
    }
182

  
183
    private void validateAndInsertValue(EditingServiceParameter param,
184
            Object value) throws InvalidEntryException {
185
        if (param == firstPoint) {
186
            if (value instanceof Point) {
187
                firstGeometry = getGeometry((Point)value);
188
                if(firstGeometry != null) {
189
                    values.put(param, value);
190
                    return;
191
                }
192
            }
193
        } else if (param == secondPoint) {
194
            if (value instanceof Point) {
195
                secondGeometry = getGeometry((Point)value);
196
                if(secondGeometry != null) {
197
                    values.put(param, value);
198
                }
199
                return;
200
            }
201
        } else if (value instanceof Double) {
202
            double radius = (Double) value;
203
            if ((radius - 0.01) > 0 && validateRadius(radius)) {
204
                values.put(param, value);
205
                return;
206
            }
207
        }
208
        throw new InvalidEntryException(null);
209
    }
210
    
211
    protected Geometry getGeometry(Point point){
212
        
213
        EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices();
214

  
215
        MapContext mapContext = (MapContext) this.parameters.getDynValue(EditingProviderFactory.MAPCONTEXT_FIELD);
216
        Geometry geometry = editingProviderServices.getGeometryOfVisibleLayers(point, featureStore, mapContext);
217
//        Geometry geometry = editingProviderServices.getGeometry(point, this.featureStore, mapContext);
218
//        if(geometry == null){
219
//            FLayer[] visibleLayers = mapContext.getLayers().getVisibles();//.getActives();
220
//            for (FLayer visibleLayer : visibleLayers) {
221
//                if(visibleLayer instanceof FLyrVect){
222
//                    if(((FLyrVect) visibleLayer).getFeatureStore()!=this.featureStore){
223
//                        geometry  = editingProviderServices.getGeometry(point, ((FLyrVect)visibleLayer).getFeatureStore(), mapContext);
224
//                        if(geometry != null){
225
//                            break;
226
//                        }
227
//                    }
228
//                }
229
//            }
230
//        }
231
        return geometry;
232
    }
233
    
234
    private boolean validateRadius(double radius) {
235
        try {
236
            Point firstPointValue = (Point) values.get(firstPoint);
237
            Point secondPointValue = (Point) values.get(secondPoint);
238
            
239
            EditingProviderServices editingProviderServices
240
                    = (EditingProviderServices) getProviderServices();
241
            
242
            int subtype = editingProviderServices.getSubType(featureStore);
243

  
244
            Geometry geometry
245
                    = editingProviderServices.createCircle(firstGeometry, secondGeometry, radius, firstPointValue, secondPointValue, subtype);
246
            return geometry != null;
247
        } catch (DataException | CreateGeometryException ex) {
248
            LOGGER.warn("Can't create circle with radius "+radius, ex);
249
        }
250
        return false;
251
    }
252

  
253
    @Override
254
    public List<EditingServiceParameter> getParameters() {
255
        List<EditingServiceParameter> list
256
                = new ArrayList<>();
257
        list.add(firstPoint);
258
        list.add(secondPoint);
259
        list.add(radius);
260
        return list;
261
    }
262

  
263
    @Override
264
    public void setValue(Object value) throws InvalidEntryException {
265
        EditingServiceParameter param = next();
266
        validateAndInsertValue(param, value);
267
    }
268

  
269
    @Override
270
    public void finishAndStore() throws FinishServiceException {
271
        EditingProviderServices editingProviderServices
272
                = (EditingProviderServices) getProviderServices();
273
        Geometry geometry = finish();
274
        if(geometry!=null){
275
            editingProviderServices.insertGeometryIntoFeatureStore(geometry,
276
                featureStore);
277
        }
278
    }
279

  
280
    public Geometry finish() throws FinishServiceException {
281

  
282
        final GeometryManager geomManager = GeometryLocator.getGeometryManager();
283
                
284
        Point firstPointValue = (Point) values.get(firstPoint);
285
        Point secondPointValue = (Point) values.get(secondPoint);
286
        double radiusValue = (double) values.get(radius);
287

  
288
        EditingProviderServices editingProviderServices
289
                = (EditingProviderServices) getProviderServices();
290

  
291
        try {
292
            int subtype = editingProviderServices.getSubType(featureStore);
293
            GeometryType storeGeomType
294
                    = editingProviderServices.getGeomType(featureStore);
295
            Geometry geometry
296
                    = editingProviderServices.createCircle(firstGeometry, secondGeometry, radiusValue, firstPointValue, secondPointValue, subtype);
297

  
298
            
299
            if (storeGeomType.isTypeOf(MULTISURFACE)) {
300
                MultiSurface multisurface = null;
301
                if(geometry != null) {
302
                    multisurface
303
                        = geomManager.createMultiSurface(
304
                                storeGeomType.getSubType());
305
                    multisurface.addSurface((Circle) geometry);
306
                }
307
                return multisurface;
308
            }
309

  
310
            return geometry;
311
        } catch (Exception e) {
312
            throw new FinishServiceException(e);
313
        }
314
    }
315
    
316
    @Override
317
    public void start() throws StartServiceException {
318
        this.values = new HashMap<>();
319
    }
320

  
321
    @Override
322
    public String getName() {
323
        return CircleTanTanRadiusEditingProviderFactory.PROVIDER_NAME;
324
    }
325

  
326
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.ellipse/src/main/java/org/gvsig/vectorediting/lib/prov/ellipse/EllipseCenterAxesEditingProvider.java
21 21
 * For any additional information, do not hesitate to contact us
22 22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23 23
 */
24

  
25 24
package org.gvsig.vectorediting.lib.prov.ellipse;
26 25

  
26
import org.gvsig.fmap.dal.exception.DataException;
27 27
import org.gvsig.fmap.geom.Geometry;
28 28
import org.gvsig.fmap.geom.GeometryLocator;
29 29
import org.gvsig.fmap.geom.aggregate.MultiCurve;
......
33 33
import org.gvsig.fmap.geom.type.GeometryType;
34 34
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
35 35
import org.gvsig.tools.dynobject.DynObject;
36
import org.gvsig.tools.locator.LocatorException;
36 37
import org.gvsig.tools.service.spi.ProviderServices;
37 38
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException;
38 39
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus;
......
42 43
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
43 44

  
44 45
public class EllipseCenterAxesEditingProvider extends FilledEllipseCenterAxesEditingProvider implements
45
EditingProvider {
46
        EditingProvider {
46 47

  
47 48
    public EllipseCenterAxesEditingProvider(ProviderServices services,
48
        DynObject parameters) {
49
            DynObject parameters) {
49 50
        super(services, parameters);
50 51
    }
51 52

  
52
        public Geometry finish() throws FinishServiceException {
53
    @Override
54
    public Geometry finish() throws FinishServiceException {
53 55
        if (values != null) {
54 56

  
55
            EditingProviderServices editingProviderServices =
56
                (EditingProviderServices) getProviderServices();
57
            EditingProviderServices editingProviderServices
58
                    = (EditingProviderServices) getProviderServices();
57 59

  
58 60
            Point centerValue = (Point) values.get(center);
59 61
            Point pointAxis1Value = (Point) values.get(pointAxisA);
60
            double lengthAxis2Value = (Double) values.get(lengthAxisB);
62
            double lengthSemiaxis2Value = (Double) values.get(lengthSemiaxisB);
61 63

  
62 64
            if ((center != null)
63
                && (pointAxis1Value != null) && (lengthAxis2Value > 0)) {
65
                    && (pointAxis1Value != null) && (lengthSemiaxis2Value > 0)) {
64 66

  
65

  
66 67
                try {
67 68
                    int subtype = editingProviderServices.getSubType(featureStore);
68 69
                    GeometryType storeGeomType = editingProviderServices.getGeomType(featureStore);
69 70

  
70
                    PeriEllipse periEllipse =
71
                        (PeriEllipse) GeometryLocator.getGeometryManager().create(Geometry.TYPES.PERIELLIPSE, subtype);
72
                    
73
                    
71
                    PeriEllipse periEllipse
72
                            = (PeriEllipse) GeometryLocator.getGeometryManager().create(Geometry.TYPES.PERIELLIPSE, subtype);
73

  
74 74
                    Point firstPointAxis = calculateOpositePointAxis(centerValue, pointAxis1Value, subtype);
75
                    
76
                    periEllipse.setPoints(firstPointAxis, pointAxis1Value, lengthAxis2Value / 2);
77 75

  
76
                    periEllipse.setPoints(firstPointAxis, pointAxis1Value, lengthSemiaxis2Value);
77

  
78 78
                    if (storeGeomType.isTypeOf(MULTICURVE)) {
79 79
                        MultiCurve multicurve;
80
                        multicurve =
81
                            GeometryLocator.getGeometryManager().createMultiCurve(
82
                                storeGeomType.getSubType());
80
                        multicurve
81
                                = GeometryLocator.getGeometryManager().createMultiCurve(
82
                                        storeGeomType.getSubType());
83 83
                        multicurve.addCurve((PeriEllipse) periEllipse);
84 84
                        return multicurve;
85 85
                    }
86 86

  
87 87
                    return periEllipse;
88
                } catch (Exception e) {
88
                } catch (DataException | CreateGeometryException | LocatorException e) {
89 89
                    throw new FinishServiceException(e);
90 90
                }
91 91
            }
......
93 93
        return null;
94 94
    }
95 95

  
96

  
96
    @Override
97 97
    public String getName() {
98 98
        return EllipseCenterAxesEditingProviderFactory.PROVIDER_NAME;
99 99
    }
......
108 108
     */
109 109
    @Override
110 110
    protected void addTemporaryGeometryToDrawingStatus(DefaultDrawingStatus drawingStatus, Point firstPointAxis1Value,
111
        Point secondPointAxis1Value, int subtype, double distance) throws CreateGeometryException {
111
            Point secondPointAxis1Value, int subtype, double distance) throws CreateGeometryException {
112 112
        PeriEllipse periEllipse = (PeriEllipse) GeometryLocator.getGeometryManager().create(Geometry.TYPES.PERIELLIPSE, subtype);
113 113
        periEllipse.setPoints(firstPointAxis1Value, secondPointAxis1Value, distance);
114 114

  
......
117 117
        drawingStatus.addStatus(periEllipse, lineSymbolEditing, "");
118 118
    }
119 119

  
120

  
121 120
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.ellipse/src/main/java/org/gvsig/vectorediting/lib/prov/ellipse/FilledEllipseCenterAxesEditingProvider.java
31 31
import java.util.Map;
32 32
import org.gvsig.euclidean.EuclideanLine2D;
33 33
import org.gvsig.euclidean.EuclideanManager;
34
import org.gvsig.fmap.dal.exception.DataException;
34 35

  
35 36
import org.gvsig.fmap.dal.feature.FeatureStore;
36 37
import org.gvsig.fmap.geom.Geometry;
......
70 71

  
71 72
    protected EditingServiceParameter pointAxisA;
72 73

  
73
    protected EditingServiceParameter lengthAxisB;
74
    protected EditingServiceParameter lengthSemiaxisB;
74 75

  
75 76
    protected Map<EditingServiceParameter, Object> values;
76 77

  
......
92 93
            new DefaultEditingServiceParameter("point_A_axis",
93 94
                "point_A_axis", EditingServiceParameter.TYPE.POSITION);
94 95

  
95
        this.lengthAxisB =
96
            new DefaultEditingServiceParameter("length_of_B_axis",
97
                "length_of_B_axis", EditingServiceParameter.TYPE.POSITION,
96
        this.lengthSemiaxisB =
97
            new DefaultEditingServiceParameter("length_of_B_semiaxis",
98
                "length_of_B_semiaxis", EditingServiceParameter.TYPE.POSITION,
98 99
                EditingServiceParameter.TYPE.VALUE);
99 100
    }
100 101

  
102
    @Override
101 103
    public EditingServiceParameter next() {
102 104
        if (values.get(center) == null) {
103 105
            return center;
104 106
        } else if (values.get(pointAxisA) == null) {
105 107
            return pointAxisA;
106
        } else if (values.get(lengthAxisB) == null) {
107
            return lengthAxisB;
108
        } else if (values.get(lengthSemiaxisB) == null) {
109
            return lengthSemiaxisB;
108 110
        }
109 111
        return null;
110 112
    }
111 113

  
114
    @Override
112 115
    public DrawingStatus getDrawingStatus(Point mousePosition)
113 116
        throws DrawServiceException {
114 117
        DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus();
......
216 219
        drawingStatus.addStatus(ellipse, polygonSymbolEditing, "");
217 220
    }
218 221

  
222
    @Override
219 223
    public void stop() throws StopServiceException {
220 224
        if (values != null) {
221 225
            values.clear();
......
223 227

  
224 228
    }
225 229

  
230
    @Override
226 231
    public List<EditingServiceParameter> getParameters() {
227
        List<EditingServiceParameter> list =
228
            new ArrayList<EditingServiceParameter>();
232
        List<EditingServiceParameter> list = new ArrayList<>();
229 233
        list.add(center);
230 234
        list.add(pointAxisA);
231
        list.add(lengthAxisB);
235
        list.add(lengthSemiaxisB);
232 236
        return list;
233 237
    }
234 238

  
239
    @Override
235 240
    public void setValue(Object value) throws InvalidEntryException {
236 241
        EditingServiceParameter parameter = this.next();
237 242
        validateAndInsertValue(parameter, value);
......
240 245
    private void validateAndInsertValue(EditingServiceParameter param,
241 246
        Object value) throws InvalidEntryException {
242 247

  
248
        EuclideanManager euclideanManager = ToolsUtilLocator.getEuclideanManager();
249

  
243 250
        if ((param == center) || (param == pointAxisA)) {
244 251
            if (value instanceof Point) {
245 252
                values.put(param, value);
246
                return;
247 253
            }
248

  
249
        } else if (param == lengthAxisB) {
254
        } else if (param == lengthSemiaxisB) {
250 255
            if (value instanceof Point) {
251 256
                Double length = null;
252 257

  
......
254 259
                    EditingProviderServices editingProviderServices =
255 260
                        (EditingProviderServices) getProviderServices();
256 261

  
257
                    Point firstPointAxis1Value =
262
                    Point centerValue =
258 263
                        (Point) values.get(center);
259
                    Point firstPointAxis2Value =
264
                    Point pointAxisAValue =
260 265
                        (Point) values.get(pointAxisA);
261 266
                    int subtype =
262 267
                        editingProviderServices.getSubType(featureStore);
263
                    Point center =
264
                        editingProviderServices
265
                        .getMidPoint(firstPointAxis1Value,
266
                            firstPointAxis2Value, subtype);
267
                    length = ((Point) value).distance(center) * 2;
268
                    
269
                    EuclideanLine2D lineAxisA = euclideanManager.createLine2D(
270
                            centerValue.getX(),
271
                            centerValue.getY(),
272
                            pointAxisAValue.getX(),
273
                            pointAxisAValue.getY()
274
                    );
275
                        
276
                    length = lineAxisA.getDistance(((Point)value).getX(), ((Point)value).getY());
268 277

  
269
                } catch (Exception e) {
278
                } catch (DataException e) {
270 279
                    throw new InvalidEntryException(e);
271 280
                }
272 281

  
273
                if (length != null) {
274
                    values.put(param, length);
275
                    return;
276
                }
282
                values.put(param, length);
277 283

  
278 284
            } else if (value instanceof Double) {
279 285

  
280 286
                if ((((Double) value) - 0.01) > 0) {
281 287
                    values.put(param, value);
282
                    return;
283 288
                }
284 289
            }
285 290
        }
286 291
    }
287 292

  
293
    @Override
288 294
    public Geometry finish() throws FinishServiceException {
289 295
        if (values != null) {
290 296

  
......
293 299

  
294 300
            Point centerValue = (Point) values.get(center);
295 301
            Point pointAxis1Value = (Point) values.get(pointAxisA);
296
            double lengthAxis2Value = (Double) values.get(lengthAxisB);
302
            double lengthSemiaxis2Value = (Double) values.get(lengthSemiaxisB);
297 303

  
298 304
            if ((center != null)
299
                && (pointAxis1Value != null) && (lengthAxis2Value > 0)) {
305
                && (pointAxis1Value != null) && (lengthSemiaxis2Value > 0)) {
300 306

  
301 307

  
302 308
                try {
......
309 315
                    
310 316
                    Point firstPointAxis = calculateOpositePointAxis(centerValue, pointAxis1Value, subtype);
311 317
                    
312
                    ellipse.setPoints(firstPointAxis, pointAxis1Value, lengthAxis2Value / 2);
318
                    ellipse.setPoints(firstPointAxis, pointAxis1Value, lengthSemiaxis2Value);
313 319

  
314 320
                    if (storeGeomType.isTypeOf(MULTISURFACE)) {
315 321
                        MultiSurface multisurface;
......
336 342
        return oppositePointAxis;
337 343
    }
338 344

  
345
    @Override
339 346
    public void finishAndStore() throws FinishServiceException {
340 347
        EditingProviderServices editingProviderServices =
341 348
            (EditingProviderServices) getProviderServices();
......
344 351
            featureStore);
345 352
    }
346 353

  
354
    @Override
347 355
    public void start() throws StartServiceException {
348
        values = new HashMap<EditingServiceParameter, Object>();
356
        values = new HashMap<>();
349 357
    }
350 358

  
359
    @Override
351 360
    public String getName() {
352 361
        return FilledEllipseCenterAxesEditingProviderFactory.PROVIDER_NAME;
353 362
    }
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.spi/src/main/java/org/gvsig/vectorediting/lib/spi/EditingProviderServices.java
45 45
import org.gvsig.fmap.geom.primitive.Point;
46 46
import org.gvsig.fmap.geom.primitive.Spline;
47 47
import org.gvsig.fmap.geom.type.GeometryType;
48
import org.gvsig.fmap.mapcontext.MapContext;
48 49
import org.gvsig.tools.exception.BaseException;
49 50
import org.gvsig.tools.service.spi.ProviderServices;
50 51

  
......
126 127

  
127 128
    /**
128 129
     * Creates a circle as of center and radius.
130
     * @deprecated
131
     * Use same method in GeometryUtils
129 132
     *
130 133
     * @param center
131 134
     *            of new circle
......
136 139
     * @return The circle created with center and radius
137 140
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
138 141
     */
142
    @Deprecated
139 143
    public Circle createCircle(Point center, double radius, int subtype)
140 144
        throws CreateGeometryException;
141 145

  
142 146
    /**
143 147
     * Creates a circle from three points.
148
     * @deprecated
149
     * Use same method in GeometryUtils
144 150
     *
145 151
     * @param firstPoint
146 152
     *            of circle
......
153 159
     * @return The circle created from three points received as parameters.
154 160
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
155 161
     */
162
    @Deprecated
156 163
    public Circle createCircle(Point firstPoint, Point secondPoint,
157 164
        Point thirdPoint, int subtype) throws CreateGeometryException;
158 165

  
159 166
    /**
160 167
     * Creates a circle from five points.The first two points are two points on a tangent to the circle.The next two are two points on another tangent to the circle.The last one is a point near the center of the circle.
168
     * @deprecated
169
     * Use same method in GeometryUtils
161 170
     *
162 171
     * @param firstPoint
163 172
     * @param secondPoint
......
169 178
     * @return The circle created from three points received as parameters.
170 179
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
171 180
     */
181
    @Deprecated
172 182
    public Circle createCircle(Point firstPoint, Point secondPoint,
173 183
        Point thirdPoint, Point fourthPoint, Point fifthPoint, int subtype) throws CreateGeometryException;
174 184

  
175
        /**
185
    /**
176 186
     * Creates a circle from two tangents and one point.
187
     * @deprecated
188
     * Use same method in GeometryUtils
177 189
     *
178 190
     * @param line1
179 191
     *            A tangent line
......
186 198
     * @return The circle created from two tangents and one point received as parameters.
187 199
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
188 200
     */
201
    @Deprecated
189 202
    public Circle createCircle(EuclideanLine2D line1, EuclideanLine2D line2,
190 203
        Point point, int subtype) throws CreateGeometryException;
191 204

  
192 205
    /**
206
     * Creates a circle from two tangent geometries and the radius.
207
     * @deprecated
208
     * Use same method in GeometryUtils
209
     *
210
     * @param geometry1
211
     *            A tangent geometry
212
     * @param geometry2
213
     *            Another tangent geometry
214
     * @param radius
215
     *            the radius of the cicle.
216
     * @param firstPoint
217
     *            a point near tangent point of geometry1
218
     * @param secondPoint
219
     *            a point near tangent point of geometry2
220
     * @param subtype
221
     *            subtype of circle. See {@link Geometry.SUBTYPES}
222
     * @return The circle created from two tangent geometries and the radius received as parameters.
223
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
224
     */
225
    @Deprecated
226
    public Circle createCircle(Geometry geometry1, Geometry geometry2,
227
        double radius, Point firstPoint, Point secondPoint, int subtype) throws CreateGeometryException;
228

  
229
    /**
193 230
     * Creates an arc as of center, radius, start angle and extension angle.
231
     * @deprecated
232
     * Use same method in GeometryUtils
194 233
     *
195 234
     * @param center
196 235
     *            center of arc.
......
206 245
     *         angle.
207 246
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
208 247
     */
248
    @Deprecated
209 249
    public Arc createArc(Point center, double radius, double startAngle,
210 250
        double angleExt, int subtype) throws CreateGeometryException;
211 251

  
212 252
    /**
213 253
     * Creates an arc as of three points.
254
     * @deprecated
255
     * Use same method in GeometryUtils
214 256
     *
215 257
     * @param start
216 258
     *            point of arc
......
224 266
     *         point and end at end point.
225 267
     * @throws org.gvsig.tools.exception.BaseException
226 268
     */
269
    @Deprecated
227 270
    public Arc createArc(Point start, Point middle, Point end, int subtype)
228 271
        throws BaseException;
229 272

  
230 273
    /**
231 274
     * Creates an ellipse from start and end point of A axis and half length
232 275
     * of B axis.
276
     * @deprecated
277
     * Use same method in GeometryUtils
233 278
     *
234 279
     * @param firstPointAxisA
235 280
     *            first point of A axis
......
242 287
     * @return The ellipse created
243 288
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
244 289
     */
290
    @Deprecated
245 291
    public Arc createEllipse(Point firstPointAxisA,
246 292
        Point secondPointAxisA, double halfLengthAxisB, int subtype)
247 293
        throws CreateGeometryException;
......
249 295
    /**
250 296
     * Creates a filled ellipse from start and end point of A axis and half length
251 297
     * of B axis.
298
     * @deprecated
299
     * Use same method in GeometryUtils
252 300
     *
253 301
     * @param firstPointAxisA
254 302
     *            first point of A axis
......
261 309
     * @return The ellipse created
262 310
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
263 311
     */
312
    @Deprecated
264 313
    public Ellipse createFilledEllipse(Point firstPointAxisA,
265 314
        Point secondPointAxisA, double halfLengthAxisB, int subtype)
266 315
        throws CreateGeometryException;
......
268 317

  
269 318
    /**
270 319
     * Creates point with x and y values.
320
     * @deprecated
321
     * Use createPoint from GeometryManager
271 322
     *
272 323
     * @param x
273 324
     *            The X coordinate
......
278 329
     * @return The Point created.
279 330
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
280 331
     */
332
    @Deprecated
281 333
    public Point createPoint(double x, double y, int subtype)
282 334
        throws CreateGeometryException;
283 335

  
284 336
    /**
285 337
     * Creates line as of two point coordinates.
338
     * @deprecated
339
     * Use same method in GeometryUtils
286 340
     *
287 341
     * @param x1
288 342
     *            The X1 coordinate
......
297 351
     * @return The Line created.
298 352
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
299 353
     */
354
    @Deprecated
300 355
    public Line createLine(double x1, double y1, double x2, double y2,
301 356
        int subtype) throws CreateGeometryException;
302 357

  
303 358
    /**
304 359
     * Creates line as of two point objects.
360
     * @deprecated
361
     * Use same method in GeometryUtils
305 362
     *
306 363
     * @param p1
307 364
     *            First point
......
312 369
     * @return The Line created.
313 370
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
314 371
     */
372
    @Deprecated
315 373
    public Line createLine(Point p1, Point p2, int subtype)
316 374
        throws CreateGeometryException;
317 375

  
318 376
    /**
377
     * Create Spline from point list
378
     * @deprecated
379
     * Use same method in GeometryUtils
319 380
     *
320 381
     * @param points
321 382
     * @param subtype
322 383
     * @return
323 384
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
324 385
     */
386
    @Deprecated
325 387
    public Spline createSpline(List<Point> points, int subtype)
326 388
        throws CreateGeometryException;
327 389

  
......
360 422

  
361 423
    /**
362 424
     * Gets center point of three points.
425
     * @deprecated
426
     * Use same method in GeometryUtils
363 427
     *
364 428
     * @param a
365 429
     *            Point one
......
372 436
     * @return Point center.
373 437
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
374 438
     */
439
    @Deprecated
375 440
    public Point getCenter(Point a, Point b, Point c, int subtype)
376 441
        throws CreateGeometryException;
377 442

  
378 443
    /**
379 444
     * Gets midpoint of two points
445
     * @deprecated
446
     * Use same method in GeometryUtils
380 447
     *
381 448
     * @param a
382 449
     *            Point one
......
387 454
     * @return Mid point of points.
388 455
     * @throws org.gvsig.fmap.geom.exception.CreateGeometryException
389 456
     */
457
    @Deprecated
390 458
    public Point getMidPoint(Point a, Point b, int subtype)
391 459
        throws CreateGeometryException;
392 460

  
......
464 532
     * @return Distance of angles
465 533
     */
466 534
    public double angleDistance(double angle1, double angle2);
535
    
536
    /**
537
     * Return a geometry from store that intersects with the point.
538
     * 
539
     * @param point
540
     * @param store
541
     * @param mapContext
542
     * @return
543
     */
544
    public Geometry getGeometry(Point point, FeatureStore store, MapContext mapContext);
545

  
546
    /**
547
     * Return a geometry that intersects with the point from the visible layers 
548
     * if it can't be found in the feature store.
549
     * 
550
     * @param point
551
     * @param store
552
     * @param mapContext
553
     * @return
554
     */
555
    public Geometry getGeometryOfVisibleLayers(Point point, FeatureStore store, MapContext mapContext);
556

  
467 557
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderServices.java
23 23
 */
24 24
package org.gvsig.vectorediting.lib.impl;
25 25

  
26
import java.awt.geom.Point2D;
27 26
import java.util.Iterator;
28 27
import java.util.List;
29 28
import java.util.Map;
30
import java.util.Objects;
31 29
import org.gvsig.euclidean.EuclideanLine2D;
32
import org.gvsig.euclidean.EuclideanManager;
30
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
31
import org.gvsig.fmap.dal.DALLocator;
32
import org.gvsig.fmap.dal.DataManager;
33 33

  
34 34
import org.gvsig.fmap.dal.EditingNotification;
35 35
import org.gvsig.fmap.dal.EditingNotificationManager;
36 36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder;
37 38
import org.gvsig.fmap.dal.feature.EditableFeature;
38 39
import org.gvsig.fmap.dal.feature.Feature;
39 40
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
......
43 44
import org.gvsig.fmap.dal.swing.DALSwingLocator;
44 45
import org.gvsig.fmap.geom.Geometry;
45 46
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
46
import org.gvsig.fmap.geom.Geometry.TYPES;
47 47
import org.gvsig.fmap.geom.GeometryLocator;
48 48
import org.gvsig.fmap.geom.GeometryManager;
49
import org.gvsig.fmap.geom.GeometryUtils;
49 50
import org.gvsig.fmap.geom.exception.CreateGeometryException;
50 51
import org.gvsig.fmap.geom.operation.GeometryOperationException;
51 52
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
......
56 57
import org.gvsig.fmap.geom.primitive.Point;
57 58
import org.gvsig.fmap.geom.primitive.Spline;
58 59
import org.gvsig.fmap.geom.type.GeometryType;
60
import org.gvsig.fmap.mapcontext.MapContext;
59 61
import org.gvsig.fmap.mapcontext.layers.CancelationException;
62
import org.gvsig.fmap.mapcontext.layers.FLayer;
63
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
60 64
import org.gvsig.tools.ToolsLocator;
61 65
import org.gvsig.tools.exception.BaseException;
62 66
import org.gvsig.tools.i18n.I18nManager;
63 67
import org.gvsig.tools.service.spi.AbstractProviderServices;
64
import org.gvsig.tools.util.ToolsUtilLocator;
65 68
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
66 69
import org.slf4j.Logger;
67 70
import org.slf4j.LoggerFactory;
......
69 72
public class DefaultEditingProviderServices extends AbstractProviderServices
70 73
        implements EditingProviderServices {
71 74

  
72
    private static final Logger logger = LoggerFactory
75
    private static final Logger LOGGER = LoggerFactory
73 76
            .getLogger(DefaultEditingProviderServices.class);
74 77

  
75 78
    @Override
......
123 126
            String msg
124 127
                    = String.format("Can't insert %1$s into %2$s",
125 128
                            eFeature.toString(), featureStore.getName());
126
            logger.info(msg, e);
129
            LOGGER.info(msg, e);
127 130
        }
128 131
    }
129 132

  
......
177 180
            String msg
178 181
                    = String.format("Can't insert %1$s into %2$s",
179 182
                            eFeature.toString(), featureStore.getName());
180
            logger.info(msg, e);
183
            LOGGER.info(msg, e);
181 184
        }
182 185
    }
183 186

  
......
214 217
                    featureStore, feature);
215 218

  
216 219
        } catch (Exception e) {
217
            logger.warn(e.getMessage(), e);
220
            LOGGER.warn(e.getMessage(), e);
218 221
        }
219 222
    }
220 223

  
......
251 254
                    featureStore, feature);
252 255

  
253 256
        } catch (Exception e) {
254
            logger.warn(e.getMessage(), e);
257
            LOGGER.warn(e.getMessage(), e);
255 258
        }
256 259
    }
257 260

  
......
306 309
            String msg
307 310
                    = String.format("Can't update %1$s in %2$s", eFeature.toString(),
308 311
                            featureStore.getName());
309
            logger.info(msg, e);
312
            LOGGER.info(msg, e);
310 313
        }
311 314
    }
312 315

  
313 316
    @Override
314 317
    public Circle createCircle(Point center, double radius, int subtype)
315 318
            throws CreateGeometryException {
316
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
317
        Circle circle = (Circle) geomManager.create(TYPES.CIRCLE, subtype);
318
        circle.setPoints(center, radius);
319

  
320
        return circle;
319
        return GeometryUtils.createCircle(center, radius, subtype);
321 320
    }
322 321

  
323 322
    @Override
324 323
    public Circle createCircle(Point firstPoint, Point secondPoint,
325 324
            Point thridPoint, int subtype) throws CreateGeometryException {
326
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
327
        Circle circle = (Circle) geomManager.create(TYPES.CIRCLE, subtype);
328
        circle.setPoints(firstPoint, secondPoint, thridPoint);
329

  
330
        return circle;
325
        return GeometryUtils.createCircle(firstPoint, secondPoint, thridPoint, subtype);
331 326
    }
332 327

  
333 328
    @Override
334 329
    public Arc createArc(Point center, double radius, double startAngle,
335 330
            double angleExt, int subtype) throws CreateGeometryException {
336
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
337
        Arc arc = (Arc) geomManager.create(TYPES.ARC, subtype);
338
        arc.setPoints(center, radius, startAngle, angleExt);
339
        return arc;
331
        return GeometryUtils.createArc(center, radius, startAngle, angleExt, subtype);
340 332
    }
341 333

  
342 334
    @Override
343 335
    public Ellipse createFilledEllipse(Point firstPointAxisA,
344 336
            Point secondPointAxisA, double halfLengthAxisB, int subtype)
345 337
            throws CreateGeometryException {
346
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
347
        Ellipse ellipse = (Ellipse) geomManager.create(TYPES.ELLIPSE, subtype);
348
        ellipse.setPoints(firstPointAxisA, secondPointAxisA, halfLengthAxisB);
349
        return ellipse;
338
        return GeometryUtils.createFilledEllipse(firstPointAxisA, secondPointAxisA, halfLengthAxisB, subtype);
350 339
    }
351 340

  
352 341
    @Override
353 342
    public Arc createArc(Point start, Point middle, Point end, int subtype)
354 343
            throws BaseException {
355

  
356
        Arc arc = (Arc) GeometryLocator.getGeometryManager().create(Geometry.TYPES.ARC, subtype);
357
        arc.setPoints(start, middle, end);
358
        return arc;
359

  
344
        return GeometryUtils.createArc(start, middle, end, subtype);
360 345
    }
361 346

  
362 347
    @Override
363 348
    public Point createPoint(double x, double y, int subtype)
364 349
            throws CreateGeometryException {
365 350
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
366
        Point point = (Point) geomManager.create(TYPES.POINT, subtype);
367
        point.setX(x);
368
        point.setY(y);
369
        return point;
351
        return geomManager.createPoint(x, y, subtype);
370 352
    }
371 353

  
372 354
    @Override
373 355
    public Line createLine(double x1, double y1, double x2, double y2,
374 356
            int subtype) throws CreateGeometryException {
375
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
376
        Line line = (Line) geomManager.create(TYPES.CURVE, subtype);
377
        line.addVertex(x1, y1);
378
        line.addVertex(x2, y2);
379
        return line;
357
        return GeometryUtils.createLine(x1, y1, x2, y2, subtype);
380 358
    }
381 359

  
382 360
    @Override
......
426 404
    @Override
427 405
    public Point getCenter(Point a, Point b, Point c, int subtype)
428 406
            throws CreateGeometryException {
429

  
430
        Point midPointAC = getMidPoint(a, c, subtype);
431
        Double[] lineParamsAC = getLineParams(a, c);
432
        Point[] bisectorAC
433
                = getPerpendicular(lineParamsAC[0], lineParamsAC[1], midPointAC,
434
                        subtype);
435

  
436
        Point midPointBC = getMidPoint(b, c, subtype);
437
        Double[] lineParamsBC = getLineParams(c, b);
438
        Point[] bisectorBC
439
                = getPerpendicular(lineParamsBC[0], lineParamsBC[1], midPointBC,
440
                        subtype);
441

  
442
        return getIntersection(bisectorAC, bisectorBC, subtype);
407
        return GeometryUtils.getCenter(a, b, c, subtype);
443 408
    }
444 409

  
445 410
    @Override
446 411
    public Point getMidPoint(Point a, Point b, int subtype)
447 412
            throws CreateGeometryException {
448
        double x = (a.getX() + b.getX()) / 2;
449
        double y = (a.getY() + b.getY()) / 2;
450
        return createPoint(x, y, subtype);
413
        return GeometryUtils.getMidPoint(a, b, subtype);
451 414
    }
452 415

  
453 416
    @Override
......
589 552
    @Override
590 553
    public Line createLine(Point p1, Point p2, int subtype)
591 554
            throws CreateGeometryException {
592
        return this.createLine(p1.getX(), p1.getY(), p2.getX(), p2.getY(),
593
                subtype);
555
        return GeometryUtils.createLine(p1, p2, subtype);
594 556
    }
595 557

  
596 558
    @Override
597 559
    public Spline createSpline(List<Point> points, int subtype)
598 560
            throws CreateGeometryException {
599
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
600
        Spline spline = (Spline) geomManager.create(TYPES.SPLINE, subtype);
601

  
602
        points.forEach((point) -> {
603
            spline.addVertex(point);
604
        });
605

  
606
        return spline;
561
        return GeometryUtils.createSpline(points, subtype);
607 562
    }
608 563

  
609 564
    @Override
......
632 587
    @Override
633 588
    public Arc createEllipse(Point firstPointAxisA, Point secondPointAxisA,
634 589
            double halfLengthAxisB, int subtype) throws CreateGeometryException {
635
        try {
636
            double lengthAxisA = secondPointAxisA.distance(firstPointAxisA);
637

  
638
            Point origen = this.createPoint(0, 0, subtype);
639
            Arc ellipse = this.createArc(
640
                    origen,
641
                    lengthAxisA / 2,
642
                    0,
643
                    2 * Math.PI,
644
                    subtype);
645

  
646
            ellipse.scale(origen, 1, halfLengthAxisB * 2 / lengthAxisA);
647
            ellipse.rotate(this.getAngle(firstPointAxisA, secondPointAxisA), 0, 0);
648
            Point centerOfEllipse = this.getMidPoint(firstPointAxisA, secondPointAxisA, subtype);
649
            ellipse.move(centerOfEllipse.getX(), centerOfEllipse.getY());
650
            return ellipse;
651
        } catch (GeometryOperationNotSupportedException | GeometryOperationException e) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff