Statistics
| Revision:

gvsig-vectorediting / 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 / EllipseEditingProvider.java @ 2109

History | View | Annotate | Download (4.7 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

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

    
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.GeometryLocator;
29
import org.gvsig.fmap.geom.aggregate.MultiCurve;
30
import org.gvsig.fmap.geom.exception.CreateGeometryException;
31
import org.gvsig.fmap.geom.primitive.PeriEllipse;
32
import org.gvsig.fmap.geom.primitive.Point;
33
import org.gvsig.fmap.geom.type.GeometryType;
34
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
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.DefaultDrawingStatus;
39
import org.gvsig.vectorediting.lib.spi.EditingProvider;
40
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
41
import org.gvsig.vectorediting.lib.spi.EditingProviderManager;
42
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
43

    
44
public class EllipseEditingProvider extends FilledEllipseEditingProvider implements
45
EditingProvider {
46

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

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

    
55
            EditingProviderServices editingProviderService =
56
                (EditingProviderServices) getProviderServices();
57

    
58
            Point firstPointAxis1Value = (Point) values.get(firstPointAxisA);
59
            Point secondPointAxis1Value = (Point) values.get(secondPointAxisA);
60
            double lengthSemiaxis2Value = (Double) values.get(lengthSemiAxisB);
61

    
62
            if ((firstPointAxis1Value != null)
63
                && (secondPointAxis1Value != null) && (lengthSemiaxis2Value > 0)) {
64

    
65
                try {
66
                    GeometryType storeGeomType = editingProviderService.getGeomType(featureStore);
67
                    int subtype = storeGeomType.getSubType();
68

    
69
                    PeriEllipse periEllipse = (PeriEllipse) GeometryLocator.getGeometryManager().create(Geometry.TYPES.PERIELLIPSE, subtype);
70
                    periEllipse.setPoints(firstPointAxis1Value, secondPointAxis1Value, lengthSemiaxis2Value);
71

    
72
                    if (storeGeomType.isTypeOf(MULTICURVE)) {
73
                        MultiCurve multicurve;
74
                        multicurve =
75
                            GeometryLocator.getGeometryManager().createMultiCurve(
76
                                storeGeomType.getSubType());
77
                        multicurve.addCurve((PeriEllipse) periEllipse);
78
                        return multicurve;
79
                    }
80

    
81
                    return periEllipse;
82
                } catch (Exception e) {
83
                    throw new FinishServiceException(e);
84
                }
85
            }
86
        }
87
        return null;
88
    }
89

    
90
    @Override
91
    public String getName() {
92
        return EllipseEditingProviderFactory.PROVIDER_NAME;
93
    }
94

    
95
    /**
96
     * @param drawingStatus
97
     * @param firstPointAxis1Value
98
     * @param secondPointAxis1Value
99
     * @param subtype
100
     * @param distance
101
     * @throws CreateGeometryException
102
     */
103
    @Override
104
    protected void addTemporaryGeometryToDrawingStatus(DefaultDrawingStatus drawingStatus, Point firstPointAxis1Value,
105
        Point secondPointAxis1Value, int subtype, double distance) throws CreateGeometryException {
106
        PeriEllipse periEllipse = (PeriEllipse) GeometryLocator.getGeometryManager().create(Geometry.TYPES.PERIELLIPSE, subtype);
107
        periEllipse.setPoints(firstPointAxis1Value, secondPointAxis1Value, distance);
108

    
109
        EditingProviderManager editingProviderManager = EditingProviderLocator.getProviderManager();
110
        ISymbol lineSymbolEditing = editingProviderManager.getSymbol("line-symbol-editing");
111
        drawingStatus.addStatus(periEllipse, lineSymbolEditing, "");
112
    }
113

    
114

    
115
}