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 @ 2616
History | View | Annotate | Download (4.68 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.GeometryManager; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
31 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
32 |
import org.gvsig.fmap.geom.primitive.Circumference; |
33 |
import org.gvsig.fmap.geom.primitive.Point; |
34 |
import org.gvsig.fmap.geom.type.GeometryType; |
35 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
36 |
import org.gvsig.tools.dynobject.DynObject; |
37 |
import org.gvsig.tools.service.spi.ProviderServices; |
38 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
39 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
40 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
41 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
42 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
43 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
44 |
|
45 |
public class Circumference3PEditingProvider extends Circle3PEditingProvider |
46 |
implements EditingProvider {
|
47 |
|
48 |
public Circumference3PEditingProvider(ProviderServices providerServices,
|
49 |
DynObject parameters) { |
50 |
super(providerServices, parameters);
|
51 |
} |
52 |
|
53 |
@Override
|
54 |
public Geometry finish() throws FinishServiceException { |
55 |
|
56 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
57 |
|
58 |
EditingProviderServices editingProviderServices = |
59 |
(EditingProviderServices) getProviderServices(); |
60 |
|
61 |
Point firstPointValue = (Point) values.get(firstPoint); |
62 |
Point secondPointValue = (Point) values.get(secondPoint); |
63 |
Point thirdPointValue = (Point) values.get(thirdPoint); |
64 |
|
65 |
try {
|
66 |
int subtype = editingProviderServices.getSubType(featureStore);
|
67 |
|
68 |
Point center =
|
69 |
editingProviderServices.getCenter(firstPointValue, |
70 |
secondPointValue, thirdPointValue, subtype); |
71 |
double radius = center.distance(firstPointValue);
|
72 |
|
73 |
Circumference circumference = (Circumference)geomManager.create(CIRCUMFERENCE, subtype); |
74 |
circumference.setPoints(center, radius); |
75 |
|
76 |
GeometryType geomType = |
77 |
editingProviderServices.getGeomType(featureStore); |
78 |
|
79 |
if (geomType.isTypeOf(MULTICURVE)) {
|
80 |
MultiCurve multicurve; |
81 |
multicurve = |
82 |
GeometryLocator.getGeometryManager().createMultiCurve( |
83 |
geomType.getSubType()); |
84 |
multicurve.addCurve((Circumference) circumference); |
85 |
return multicurve;
|
86 |
} |
87 |
|
88 |
return circumference;
|
89 |
} catch (Exception e) { |
90 |
throw new FinishServiceException(e); |
91 |
} |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public String getName() { |
96 |
return Circumference3PEditingProviderFactory.PROVIDER_NAME;
|
97 |
} |
98 |
|
99 |
|
100 |
/**
|
101 |
* @param drawingStatus
|
102 |
* @param subtype
|
103 |
* @param center
|
104 |
* @param radius
|
105 |
* @throws CreateGeometryException
|
106 |
*/
|
107 |
@Override
|
108 |
protected void addTemporaryGeometryToDrawingStatus(DefaultDrawingStatus drawingStatus, int subtype, Point center, double radius) |
109 |
throws CreateGeometryException {
|
110 |
EditingProviderManager editingProviderManager = |
111 |
EditingProviderLocator.getProviderManager(); |
112 |
ISymbol lineSymbolEditing = editingProviderManager.getSymbol("line-symbol-editing");
|
113 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
114 |
Circumference circumference = (Circumference)geomManager.create(Geometry.TYPES.CIRCUMFERENCE, subtype); |
115 |
circumference.setPoints(center, radius); |
116 |
drawingStatus.addStatus(circumference, lineSymbolEditing, "");
|
117 |
drawingStatus.addStatus(circumference, drawingStatus.getPreviewSymbol(), "");
|
118 |
} |
119 |
|
120 |
} |