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.spline / src / main / java / org / gvsig / vectorediting / lib / prov / spline / FilledSplineEditingProvider.java @ 575

History | View | Annotate | Download (5.74 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.spline;
26

    
27
import java.util.Iterator;
28

    
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.GeometryLocator;
31
import org.gvsig.fmap.geom.GeometryManager;
32
import org.gvsig.fmap.geom.aggregate.MultiSurface;
33
import org.gvsig.fmap.geom.primitive.FilledSpline;
34
import org.gvsig.fmap.geom.primitive.Point;
35
import org.gvsig.fmap.geom.type.GeometryType;
36
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
37
import org.gvsig.tools.dynobject.DynObject;
38
import org.gvsig.tools.exception.BaseException;
39
import org.gvsig.tools.service.spi.ProviderServices;
40
import org.gvsig.vectorediting.lib.api.DrawingStatus;
41
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException;
42
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException;
43
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus;
44
import org.gvsig.vectorediting.lib.spi.EditingProvider;
45
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
46
import org.gvsig.vectorediting.lib.spi.EditingProviderManager;
47
import org.gvsig.vectorediting.lib.spi.EditingProviderServices;
48

    
49
/**
50
 * @author llmarques
51
 *
52
 */
53
public class FilledSplineEditingProvider extends SplineEditingProvider
54
    implements EditingProvider {
55

    
56
    /**
57
     * @param services
58
     * @param parameters
59
     */
60
    public FilledSplineEditingProvider(ProviderServices services,
61
        DynObject parameters) {
62
        super(services, parameters);
63
    }
64

    
65
    public DrawingStatus getDrawingStatus(Point mousePosition)
66
        throws DrawServiceException {
67

    
68
        DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus();
69
        EditingProviderManager editingProviderManager =
70
            EditingProviderLocator.getProviderManager();
71
        ISymbol polygonSymbolEditing = editingProviderManager.getSymbol("polygon-symbol-editing");
72
        ISymbol auxiliaryPointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing");
73
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
74

    
75
        if (values != null) {
76

    
77
            if (values.size() >= 1) {
78
                for (Iterator iterator = values.iterator(); iterator.hasNext();) {
79
                    Point point = (Point) iterator.next();
80
                    drawingStatus.addStatus(point, auxiliaryPointSymbolEditing, "");
81
                }
82

    
83
                EditingProviderServices editingProviderServices =
84
                    (EditingProviderServices) getProviderServices();
85

    
86
                try {
87
                    int subtype =
88
                        editingProviderServices.getSubType(featureStore);
89

    
90
                    FilledSpline filledSpline = (FilledSpline) geometryManager.create(Geometry.TYPES.FILLEDSPLINE, subtype);
91
                    for (int i = 0; i < values.size(); i++) {
92
                        filledSpline.addVertex(values.get(i));
93
                    }
94
                    filledSpline.addVertex(mousePosition);
95
                    filledSpline.addVertex(values.get(0));
96

    
97
                    drawingStatus.addStatus(mousePosition, auxiliaryPointSymbolEditing, "");
98
                    drawingStatus.addStatus(filledSpline, polygonSymbolEditing, "");
99

    
100
                } catch (BaseException e) {
101
                    throw new DrawServiceException(e);
102
                }
103
            }
104
        }
105
        return drawingStatus;
106
    }
107

    
108
    @Override
109
    public Geometry finish() throws FinishServiceException {
110
        if (values != null) {
111

    
112
            EditingProviderServices editingProviderServices =
113
                (EditingProviderServices) getProviderServices();
114
            GeometryManager geometryManager = GeometryLocator.getGeometryManager();
115

    
116
            try {
117
                int subtype = editingProviderServices.getSubType(featureStore);
118

    
119
                FilledSpline filledSpline = (FilledSpline) geometryManager.create(Geometry.TYPES.FILLEDSPLINE, subtype);
120
                for (int i = 0; i < values.size(); i++) {
121
                    filledSpline.addVertex(values.get(i));
122
                }
123
                filledSpline.addVertex(values.get(0));
124

    
125
                GeometryType geomType = editingProviderServices.getGeomType(featureStore);
126

    
127
                if (geomType.isTypeOf(MULTISURFACE)) {
128
                    MultiSurface multisurface;
129
                    multisurface =
130
                        GeometryLocator.getGeometryManager().createMultiSurface(
131
                            geomType.getSubType());
132
                    multisurface.addSurface((FilledSpline) filledSpline);
133
                    return multisurface;
134

    
135
                } else {
136
                    return filledSpline;
137
                }
138

    
139
            } catch (BaseException e) {
140
                throw new FinishServiceException(e);
141
            }
142
        }
143
        return null;
144
    }
145

    
146
    @Override
147
    public String getName() {
148
        return FilledSplineEditingProviderFactory.PROVIDER_NAME;
149
    }
150

    
151
}