gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.rectangle / src / main / java / org / gvsig / vectorediting / lib / prov / rectangle / FilledRectangleEditingProvider.java @ 575
History | View | Annotate | Download (4.5 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.rectangle; |
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.MultiSurface; |
31 |
import org.gvsig.fmap.geom.primitive.Point; |
32 |
import org.gvsig.fmap.geom.primitive.Polygon; |
33 |
import org.gvsig.fmap.geom.type.GeometryType; |
34 |
import org.gvsig.tools.dynobject.DynObject; |
35 |
import org.gvsig.tools.exception.BaseException; |
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 |
/**
|
42 |
* @author llmarques
|
43 |
*
|
44 |
*/
|
45 |
public class FilledRectangleEditingProvider extends RectangleEditingProvider |
46 |
implements EditingProvider {
|
47 |
|
48 |
/**
|
49 |
* Default constructor.
|
50 |
*
|
51 |
* @param parameters
|
52 |
* of service.
|
53 |
* @param providerServices
|
54 |
* available services. See {@link EditingProviderServices}.
|
55 |
*/
|
56 |
public FilledRectangleEditingProvider(ProviderServices providerServices,
|
57 |
DynObject parameters) { |
58 |
super(providerServices, parameters);
|
59 |
} |
60 |
|
61 |
@Override
|
62 |
public Geometry finish() throws FinishServiceException { |
63 |
|
64 |
if (values != null) { |
65 |
Point firstPointValue = (Point) values.get(firstPoint); |
66 |
Point oppistePointValue = (Point) values.get(oppositePoint); |
67 |
|
68 |
if ((firstPointValue != null) && (oppistePointValue != null)) { |
69 |
|
70 |
EditingProviderServices editingProviderServices = |
71 |
(EditingProviderServices) getProviderServices(); |
72 |
GeometryManager geometryManager = |
73 |
GeometryLocator.getGeometryManager(); |
74 |
|
75 |
try {
|
76 |
int subtype =
|
77 |
editingProviderServices.getSubType(featureStore); |
78 |
Polygon rectangle = geometryManager.createPolygon(subtype);
|
79 |
|
80 |
rectangle.addVertex(firstPointValue); |
81 |
|
82 |
Point secondPoint =
|
83 |
editingProviderServices.createPoint( |
84 |
oppistePointValue.getX(), firstPointValue.getY(), |
85 |
subtype); |
86 |
|
87 |
rectangle.addVertex(secondPoint); |
88 |
|
89 |
rectangle.addVertex(oppistePointValue); |
90 |
|
91 |
Point thirdPoint =
|
92 |
editingProviderServices.createPoint( |
93 |
firstPointValue.getX(), oppistePointValue.getY(), |
94 |
subtype); |
95 |
|
96 |
rectangle.addVertex(thirdPoint); |
97 |
|
98 |
rectangle.addVertex((Point)firstPointValue.cloneGeometry());
|
99 |
|
100 |
rectangle.ensureOrientation(false);
|
101 |
|
102 |
GeometryType geomType = |
103 |
editingProviderServices.getGeomType(featureStore); |
104 |
|
105 |
if (geomType.isTypeOf(MULTISURFACE)) {
|
106 |
MultiSurface multisurface; |
107 |
multisurface = |
108 |
GeometryLocator.getGeometryManager() |
109 |
.createMultiSurface(geomType.getSubType()); |
110 |
multisurface.addSurface(rectangle); |
111 |
return multisurface;
|
112 |
} |
113 |
|
114 |
return rectangle;
|
115 |
} catch (BaseException e) {
|
116 |
throw new FinishServiceException(e); |
117 |
} |
118 |
} |
119 |
} |
120 |
return null; |
121 |
} |
122 |
|
123 |
public String getName() { |
124 |
return FilledRectangleEditingProviderFactory.PROVIDER_NAME;
|
125 |
} |
126 |
} |