gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.ellipse / src / main / java / org / gvsig / vectorediting / lib / prov / ellipse / EllipseCenterAxesEditingProvider.java @ 2109
History | View | Annotate | Download (5.03 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 |
package org.gvsig.vectorediting.lib.prov.ellipse; |
25 |
|
26 |
import org.gvsig.fmap.dal.exception.DataException; |
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.exception.CreateGeometryException; |
31 |
import org.gvsig.fmap.geom.primitive.PeriEllipse; |
32 |
import org.gvsig.fmap.geom.primitive.Point; |
33 |
import org.gvsig.fmap.geom.type.GeometryType; |
34 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
35 |
import org.gvsig.tools.dynobject.DynObject; |
36 |
import org.gvsig.tools.locator.LocatorException; |
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 EllipseCenterAxesEditingProvider extends FilledEllipseCenterAxesEditingProvider implements |
46 |
EditingProvider { |
47 |
|
48 |
public EllipseCenterAxesEditingProvider(ProviderServices services,
|
49 |
DynObject parameters) { |
50 |
super(services, parameters);
|
51 |
} |
52 |
|
53 |
@Override
|
54 |
public Geometry finish() throws FinishServiceException { |
55 |
if (values != null) { |
56 |
|
57 |
EditingProviderServices editingProviderServices |
58 |
= (EditingProviderServices) getProviderServices(); |
59 |
|
60 |
Point centerValue = (Point) values.get(center); |
61 |
Point pointAxis1Value = (Point) values.get(pointAxisA); |
62 |
double lengthSemiaxis2Value = (Double) values.get(lengthSemiaxisB); |
63 |
|
64 |
if ((center != null) |
65 |
&& (pointAxis1Value != null) && (lengthSemiaxis2Value > 0)) { |
66 |
|
67 |
try {
|
68 |
int subtype = editingProviderServices.getSubType(featureStore);
|
69 |
GeometryType storeGeomType = editingProviderServices.getGeomType(featureStore); |
70 |
|
71 |
PeriEllipse periEllipse |
72 |
= (PeriEllipse) GeometryLocator.getGeometryManager().create(Geometry.TYPES.PERIELLIPSE, subtype); |
73 |
|
74 |
Point firstPointAxis = calculateOpositePointAxis(centerValue, pointAxis1Value, subtype);
|
75 |
|
76 |
periEllipse.setPoints(firstPointAxis, pointAxis1Value, lengthSemiaxis2Value); |
77 |
|
78 |
if (storeGeomType.isTypeOf(MULTICURVE)) {
|
79 |
MultiCurve multicurve; |
80 |
multicurve |
81 |
= GeometryLocator.getGeometryManager().createMultiCurve( |
82 |
storeGeomType.getSubType()); |
83 |
multicurve.addCurve((PeriEllipse) periEllipse); |
84 |
return multicurve;
|
85 |
} |
86 |
|
87 |
return periEllipse;
|
88 |
} catch (DataException | CreateGeometryException | LocatorException e) {
|
89 |
throw new FinishServiceException(e); |
90 |
} |
91 |
} |
92 |
} |
93 |
return null; |
94 |
} |
95 |
|
96 |
@Override
|
97 |
public String getName() { |
98 |
return EllipseCenterAxesEditingProviderFactory.PROVIDER_NAME;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* @param drawingStatus
|
103 |
* @param firstPointAxis1Value
|
104 |
* @param secondPointAxis1Value
|
105 |
* @param subtype
|
106 |
* @param distance
|
107 |
* @throws CreateGeometryException
|
108 |
*/
|
109 |
@Override
|
110 |
protected void addTemporaryGeometryToDrawingStatus(DefaultDrawingStatus drawingStatus, Point firstPointAxis1Value, |
111 |
Point secondPointAxis1Value, int subtype, double distance) throws CreateGeometryException { |
112 |
PeriEllipse periEllipse = (PeriEllipse) GeometryLocator.getGeometryManager().create(Geometry.TYPES.PERIELLIPSE, subtype); |
113 |
periEllipse.setPoints(firstPointAxis1Value, secondPointAxis1Value, distance); |
114 |
|
115 |
EditingProviderManager editingProviderManager = EditingProviderLocator.getProviderManager(); |
116 |
ISymbol lineSymbolEditing = editingProviderManager.getSymbol("line-symbol-editing");
|
117 |
drawingStatus.addStatus(periEllipse, lineSymbolEditing, "");
|
118 |
} |
119 |
|
120 |
} |