gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.circlecr / src / main / java / org / gvsig / vectorediting / lib / prov / circlecr / CircumferenceCREditingProvider.java @ 2109
History | View | Annotate | Download (5.26 KB)
1 | 159 | llmarques | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 88 | fdiaz | *
|
4 | 159 | llmarques | * 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 | 88 | fdiaz | */
|
24 | 159 | llmarques | |
25 | 88 | fdiaz | package org.gvsig.vectorediting.lib.prov.circlecr; |
26 | |||
27 | import org.gvsig.fmap.geom.Geometry; |
||
28 | 99 | fdiaz | import org.gvsig.fmap.geom.GeometryLocator; |
29 | 575 | fdiaz | import org.gvsig.fmap.geom.GeometryManager; |
30 | 88 | fdiaz | import org.gvsig.fmap.geom.aggregate.MultiCurve; |
31 | 575 | fdiaz | import org.gvsig.fmap.geom.primitive.Circumference; |
32 | import org.gvsig.fmap.geom.primitive.Curve; |
||
33 | 88 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
34 | import org.gvsig.fmap.geom.type.GeometryType; |
||
35 | 575 | fdiaz | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
36 | 88 | fdiaz | import org.gvsig.tools.dynobject.DynObject; |
37 | import org.gvsig.tools.service.spi.ProviderServices; |
||
38 | 575 | fdiaz | import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
39 | 88 | fdiaz | import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
40 | 575 | fdiaz | import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
41 | 88 | fdiaz | import org.gvsig.vectorediting.lib.spi.EditingProvider; |
42 | 575 | fdiaz | import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
43 | import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
||
44 | 88 | fdiaz | import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
45 | |||
46 | 138 | llmarques | public class CircumferenceCREditingProvider extends CircleCREditingProvider |
47 | 227 | llmarques | implements EditingProvider {
|
48 | 88 | fdiaz | |
49 | 138 | llmarques | public CircumferenceCREditingProvider(ProviderServices providerServices,
|
50 | DynObject parameters) { |
||
51 | super(providerServices, parameters);
|
||
52 | } |
||
53 | 88 | fdiaz | |
54 | 575 | fdiaz | public DefaultDrawingStatus getDrawingStatus(Point mousePosition) throws DrawServiceException { |
55 | DefaultDrawingStatus geometries = new DefaultDrawingStatus();
|
||
56 | EditingProviderManager editingProviderManager = EditingProviderLocator.getProviderManager(); |
||
57 | GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
||
58 | ISymbol lineSymbolEditing = editingProviderManager.getSymbol("line-symbol-editing");
|
||
59 | ISymbol auxiliaryLineSymbolEditing = editingProviderManager.getSymbol("auxiliary-line-symbol-editing");
|
||
60 | ISymbol auxiliaryPointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing");
|
||
61 | |||
62 | if ((values != null) && (values.get(center) != null) |
||
63 | && (values.get(radius) == null)) {
|
||
64 | Point centerPoint = (Point) values.get(center); |
||
65 | EditingProviderServices editingProviderServices = |
||
66 | (EditingProviderServices) getProviderServices(); |
||
67 | |||
68 | try {
|
||
69 | int subtype = editingProviderServices.getSubType(featureStore);
|
||
70 | Curve line = editingProviderServices.createLine(centerPoint, mousePosition, subtype); |
||
71 | Circumference circumference = (Circumference) geomManager.create(CIRCUMFERENCE, subtype); |
||
72 | circumference.setPoints(centerPoint, mousePosition.distance(centerPoint)); |
||
73 | |||
74 | geometries.addStatus(centerPoint, auxiliaryPointSymbolEditing, "");
|
||
75 | geometries.addStatus(line, auxiliaryLineSymbolEditing, "");
|
||
76 | geometries.addStatus(circumference, lineSymbolEditing, "");
|
||
77 | |||
78 | } catch (Exception e) { |
||
79 | throw new DrawServiceException(e); |
||
80 | } |
||
81 | |||
82 | return geometries;
|
||
83 | } |
||
84 | |||
85 | return null; |
||
86 | |||
87 | } |
||
88 | |||
89 | |||
90 | 227 | llmarques | @Override
|
91 | 138 | llmarques | public Geometry finish() throws FinishServiceException { |
92 | 575 | fdiaz | GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
93 | 138 | llmarques | Point centerPoint = (Point) values.get(center); |
94 | double radiusValue = (Double) values.get(radius); |
||
95 | EditingProviderServices editingProviderServices = |
||
96 | (EditingProviderServices) getProviderServices(); |
||
97 | try {
|
||
98 | 178 | llmarques | int subtype = editingProviderServices.getSubType(featureStore);
|
99 | 138 | llmarques | GeometryType storeGeomType = |
100 | editingProviderServices.getGeomType(featureStore); |
||
101 | 575 | fdiaz | Circumference circumference = (Circumference) geomManager.create(CIRCUMFERENCE, subtype); |
102 | circumference.setPoints(centerPoint, radiusValue); |
||
103 | 88 | fdiaz | |
104 | 138 | llmarques | if (storeGeomType.isTypeOf(MULTICURVE)) {
|
105 | MultiCurve multicurve; |
||
106 | multicurve = |
||
107 | GeometryLocator.getGeometryManager().createMultiCurve( |
||
108 | storeGeomType.getSubType()); |
||
109 | 575 | fdiaz | multicurve.addCurve((Circumference) circumference); |
110 | 138 | llmarques | return multicurve;
|
111 | } |
||
112 | 174 | llmarques | |
113 | 575 | fdiaz | return circumference;
|
114 | 138 | llmarques | } catch (Exception e) { |
115 | throw new FinishServiceException(e); |
||
116 | } |
||
117 | } |
||
118 | 88 | fdiaz | |
119 | 227 | llmarques | @Override
|
120 | 138 | llmarques | public String getName() { |
121 | return CircumferenceCREditingProviderFactory.PROVIDER_NAME;
|
||
122 | 88 | fdiaz | } |
123 | |||
124 | } |