gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.circle3p / src / main / java / org / gvsig / vectorediting / lib / prov / circle3p / Circumference3PEditingProvider.java @ 333
History | View | Annotate | Download (3.46 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.circle3p; |
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.primitive.Arc; |
31 |
import org.gvsig.fmap.geom.primitive.Circle; |
32 |
import org.gvsig.fmap.geom.primitive.Point; |
33 |
import org.gvsig.fmap.geom.type.GeometryType; |
34 |
import org.gvsig.tools.dynobject.DynObject; |
35 |
import org.gvsig.tools.service.spi.ProviderServices; |
36 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
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 Circumference3PEditingProvider extends Circle3PEditingProvider |
42 |
implements EditingProvider {
|
43 |
|
44 |
public Circumference3PEditingProvider(ProviderServices providerServices,
|
45 |
DynObject parameters) { |
46 |
super(providerServices, parameters);
|
47 |
} |
48 |
|
49 |
@Override
|
50 |
public Geometry finish() throws FinishServiceException { |
51 |
|
52 |
Point thridPointValue = (Point) values.get(thirdPoint); |
53 |
EditingProviderServices editingProviderServices = |
54 |
(EditingProviderServices) getProviderServices(); |
55 |
|
56 |
Point firstPointValue = (Point) values.get(firstPoint); |
57 |
Point secondPointValue = (Point) values.get(secondPoint); |
58 |
Point thirdPointValue = (Point) values.get(thirdPoint); |
59 |
|
60 |
try {
|
61 |
int subtype = editingProviderServices.getSubType(featureStore);
|
62 |
|
63 |
Point center =
|
64 |
editingProviderServices.getCenter(firstPointValue, |
65 |
secondPointValue, thirdPointValue, subtype); |
66 |
double radius = center.distance(firstPointValue);
|
67 |
|
68 |
Arc circumference = |
69 |
editingProviderServices.createArc(center, radius, 0,
|
70 |
2 * Math.PI, subtype); |
71 |
|
72 |
GeometryType geomType = |
73 |
editingProviderServices.getGeomType(featureStore); |
74 |
|
75 |
if (geomType.isTypeOf(MULTICURVE)) {
|
76 |
|
77 |
MultiCurve multiCurve; |
78 |
multiCurve = |
79 |
GeometryLocator.getGeometryManager().createMultiCurve( |
80 |
geomType.getSubType()); |
81 |
multiCurve.addCurve(circumference); |
82 |
return multiCurve;
|
83 |
} |
84 |
|
85 |
return circumference;
|
86 |
} catch (Exception e) { |
87 |
throw new FinishServiceException(e); |
88 |
} |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public String getName() { |
93 |
return Circumference3PEditingProviderFactory.PROVIDER_NAME;
|
94 |
} |
95 |
|
96 |
} |