Revision 2109 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

View differences:

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
    }

Also available in: Unified diff