Revision 4376
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.explode/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.lib.prov.explode.ExplodeEditingLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.explode/src/main/java/org/gvsig/vectorediting/lib/prov/explode/ExplodeEditingProviderFactory.java | ||
---|---|---|
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.explode; |
|
26 |
|
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.tools.dynobject.DynObject; |
|
29 |
import org.gvsig.tools.service.spi.Provider; |
|
30 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
31 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
32 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProviderFactory; |
|
33 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceinfo; |
|
34 |
|
|
35 |
/** |
|
36 |
* @author llmarques |
|
37 |
* |
|
38 |
*/ |
|
39 |
public class ExplodeEditingProviderFactory extends AbstractEditingProviderFactory { |
|
40 |
|
|
41 |
public static final String PROVIDER_NAME = "modify-explode-geometry"; |
|
42 |
|
|
43 |
private final static String PROVIDER_DESCRIPTION = |
|
44 |
"Explodes aggregate geometry in single geometries"; |
|
45 |
|
|
46 |
public ExplodeEditingProviderFactory() { |
|
47 |
super(PROVIDER_NAME, PROVIDER_DESCRIPTION); |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
@Override |
|
52 |
public EditingServiceInfo getServiceInfo() { |
|
53 |
EditingServiceInfo serviceInfo = |
|
54 |
new DefaultEditingServiceinfo(PROVIDER_NAME, "", false, null, |
|
55 |
new int[] { Geometry.TYPES.MULTIPOINT, |
|
56 |
Geometry.TYPES.MULTILINE, Geometry.TYPES.MULTIPOLYGON, |
|
57 |
Geometry.TYPES.MULTICURVE, Geometry.TYPES.MULTISURFACE |
|
58 |
}); |
|
59 |
|
|
60 |
return serviceInfo; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
|
65 |
return new ExplodeEditingProvider(services, parameters); |
|
66 |
} |
|
67 |
|
|
68 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.explode/src/main/java/org/gvsig/vectorediting/lib/prov/explode/ExplodeEditingLibrary.java | ||
---|---|---|
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.explode; |
|
26 |
|
|
27 |
import org.gvsig.tools.ToolsLocator; |
|
28 |
import org.gvsig.tools.i18n.I18nManager; |
|
29 |
import org.gvsig.tools.library.AbstractLibrary; |
|
30 |
import org.gvsig.tools.library.LibraryException; |
|
31 |
import org.gvsig.vectorediting.lib.api.EditingLibrary; |
|
32 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
33 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
* @author llmarques |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class ExplodeEditingLibrary extends AbstractLibrary { |
|
41 |
|
|
42 |
@Override |
|
43 |
public void doRegistration() { |
|
44 |
registerAsServiceOf(EditingLibrary.class); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void doInitialize() throws LibraryException { |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
protected void doPostInitialize() throws LibraryException { |
|
53 |
EditingProviderManager manager = |
|
54 |
EditingProviderLocator.getProviderManager(); |
|
55 |
|
|
56 |
manager.addProviderFactory(new ExplodeEditingProviderFactory()); |
|
57 |
|
|
58 |
manager.registerIcon("vectorediting-tools", "modify-explode-geometry", |
|
59 |
this.getClass().getClassLoader(), this.getClass().getName()); |
|
60 |
|
|
61 |
registerTranslations(); |
|
62 |
} |
|
63 |
|
|
64 |
private void registerTranslations() { |
|
65 |
I18nManager manager = ToolsLocator.getI18nManager(); |
|
66 |
manager.addResourceFamily("i18n/text", |
|
67 |
this.getClass().getClassLoader(), "modidy-explode-geometry"); |
|
68 |
} |
|
69 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.explode/src/main/java/org/gvsig/vectorediting/lib/prov/explode/ExplodeEditingProvider.java | ||
---|---|---|
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.explode; |
|
26 |
|
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.List; |
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
|
30 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
31 |
import org.gvsig.fmap.dal.feature.Feature; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
34 |
import org.gvsig.fmap.geom.Geometry; |
|
35 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
36 |
import org.gvsig.fmap.geom.GeometryManager; |
|
37 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
38 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
39 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
|
40 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
41 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
42 |
import org.gvsig.fmap.geom.primitive.Point; |
|
43 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
44 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
45 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
46 |
import org.gvsig.tools.dynobject.DynObject; |
|
47 |
import org.gvsig.tools.exception.BaseException; |
|
48 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
49 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
50 |
import org.gvsig.tools.visitor.Visitor; |
|
51 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
52 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
53 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
54 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
|
55 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
56 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
57 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
58 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
|
59 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
|
60 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
|
61 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
62 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
63 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
64 |
|
|
65 |
/** |
|
66 |
* @author llmarques |
|
67 |
* |
|
68 |
*/ |
|
69 |
public class ExplodeEditingProvider extends AbstractEditingProvider implements |
|
70 |
EditingProvider { |
|
71 |
|
|
72 |
private final EditingServiceParameter selectionParameter; |
|
73 |
|
|
74 |
private final FeatureStore featureStore; |
|
75 |
|
|
76 |
private FeatureSelection value; |
|
77 |
|
|
78 |
/** |
|
79 |
* Default constructor. |
|
80 |
* |
|
81 |
* @param providerServices |
|
82 |
* available services for this provider |
|
83 |
* @param parameters |
|
84 |
*/ |
|
85 |
public ExplodeEditingProvider(ProviderServices providerServices, |
|
86 |
DynObject parameters) { |
|
87 |
super(providerServices); |
|
88 |
|
|
89 |
this.featureStore = |
|
90 |
(FeatureStore) parameters |
|
91 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
|
92 |
|
|
93 |
this.selectionParameter = |
|
94 |
new DefaultEditingServiceParameter("selection", "selection", |
|
95 |
TYPE.SELECTION); |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public EditingServiceParameter next() { |
|
100 |
if (value == null) { |
|
101 |
return selectionParameter; |
|
102 |
} |
|
103 |
return null; |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public boolean mustRestartAtFinish() { |
|
108 |
return false; |
|
109 |
} |
|
110 |
|
|
111 |
@Override |
|
112 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
|
113 |
throws DrawServiceException { |
|
114 |
return null; |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public void stop() throws StopServiceException { |
|
119 |
value = null; |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public List<EditingServiceParameter> getParameters() { |
|
124 |
List<EditingServiceParameter> parameters = |
|
125 |
new ArrayList<>(); |
|
126 |
parameters.add(selectionParameter); |
|
127 |
return parameters; |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException { |
|
132 |
validateAndInsertValue(parameter, value); |
|
133 |
} |
|
134 |
|
|
135 |
@Override |
|
136 |
public void setValue(Object value) throws InvalidEntryException { |
|
137 |
EditingServiceParameter parameter = next(); |
|
138 |
validateAndInsertValue(parameter, value); |
|
139 |
} |
|
140 |
|
|
141 |
private void validateAndInsertValue(EditingServiceParameter parameter, |
|
142 |
Object object) throws InvalidEntryException { |
|
143 |
|
|
144 |
if (parameter == selectionParameter) { |
|
145 |
|
|
146 |
if (object instanceof FeatureSelection) { |
|
147 |
|
|
148 |
final FeatureSelection selection = (FeatureSelection) object; |
|
149 |
|
|
150 |
try { |
|
151 |
|
|
152 |
selection.accept((Object obj) -> { |
|
153 |
Feature feature = (Feature) obj; |
|
154 |
Geometry defaultGeometry = |
|
155 |
feature.getDefaultGeometry(); |
|
156 |
|
|
157 |
if (defaultGeometry instanceof MultiPrimitive) { |
|
158 |
|
|
159 |
MultiPrimitive multiPrimitive = |
|
160 |
(MultiPrimitive) defaultGeometry; |
|
161 |
if (multiPrimitive.getPrimitivesNumber() > 1) { |
|
162 |
value = selection; |
|
163 |
return; |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
throw new InvalidEntryException(null); |
|
168 |
}); |
|
169 |
|
|
170 |
} catch (BaseException e) { |
|
171 |
throw new InvalidEntryException(e); |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
@Override |
|
178 |
public Geometry finish() throws FinishServiceException { |
|
179 |
return null; |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public void finishAndStore() throws FinishServiceException { |
|
184 |
if (value != null) { |
|
185 |
|
|
186 |
try { |
|
187 |
final EditingProviderServices editingProviderServices = |
|
188 |
(EditingProviderServices) getProviderServices(); |
|
189 |
|
|
190 |
value.accept((Object obj) -> { |
|
191 |
Feature feature = (Feature) obj; |
|
192 |
MultiPrimitive defaultGeometry = |
|
193 |
(MultiPrimitive) feature.getDefaultGeometry(); |
|
194 |
GeometryType geomType = defaultGeometry.getGeometryType(); |
|
195 |
|
|
196 |
for (int i = 0; i < defaultGeometry |
|
197 |
.getPrimitivesNumber(); i++) { |
|
198 |
|
|
199 |
Primitive primitive = |
|
200 |
defaultGeometry.getPrimitiveAt(i); |
|
201 |
|
|
202 |
GeometryManager geometryManager = |
|
203 |
GeometryLocator.getGeometryManager(); |
|
204 |
|
|
205 |
int subtype = |
|
206 |
editingProviderServices |
|
207 |
.getSubType(featureStore); |
|
208 |
|
|
209 |
Geometry geometry = null; |
|
210 |
|
|
211 |
if (geomType.isTypeOf(MULTIPOINT)) { |
|
212 |
|
|
213 |
MultiPoint multiPoint = |
|
214 |
geometryManager.createMultiPoint(subtype); |
|
215 |
multiPoint.addPoint((Point) primitive); |
|
216 |
|
|
217 |
geometry = multiPoint; |
|
218 |
|
|
219 |
} else if (geomType.isTypeOf(MULTICURVE)) { |
|
220 |
|
|
221 |
MultiCurve multiCurve = |
|
222 |
geometryManager.createMultiCurve(subtype); |
|
223 |
multiCurve.addCurve((Curve) primitive); |
|
224 |
|
|
225 |
geometry = multiCurve; |
|
226 |
|
|
227 |
} else if (geomType.isTypeOf(MULTISURFACE)) { |
|
228 |
|
|
229 |
MultiSurface multiSurface = |
|
230 |
geometryManager.createMultiSurface(subtype); |
|
231 |
multiSurface.addSurface((Surface) primitive); |
|
232 |
|
|
233 |
geometry = multiSurface; |
|
234 |
} |
|
235 |
|
|
236 |
if (geometry != null) { |
|
237 |
EditableFeature newFeature = |
|
238 |
editingProviderServices |
|
239 |
.getFeatureCopyWithoutUniqueIndex(featureStore, |
|
240 |
feature); |
|
241 |
|
|
242 |
newFeature.setDefaultGeometry(geometry); |
|
243 |
|
|
244 |
editingProviderServices |
|
245 |
.insertFeatureIntoFeatureStore(newFeature, |
|
246 |
featureStore); |
|
247 |
|
|
248 |
} |
|
249 |
} |
|
250 |
|
|
251 |
editingProviderServices |
|
252 |
.deleteFeatureFromFeatureStore(feature, |
|
253 |
featureStore); |
|
254 |
}); |
|
255 |
|
|
256 |
featureStore.getFeatureSelection().deselectAll(); |
|
257 |
value.dispose(); |
|
258 |
|
|
259 |
} catch (BaseException e) { |
|
260 |
throw new FinishServiceException(e); |
|
261 |
} |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
@Override |
|
266 |
public void start() throws StartServiceException, InvalidEntryException { |
|
267 |
this.value = null; |
|
268 |
FeatureSelection selected = null; |
|
269 |
if (featureStore != null) { |
|
270 |
try { |
|
271 |
selected = featureStore.getFeatureSelection(); |
|
272 |
} catch (DataException e) { |
|
273 |
throw new StartServiceException(e); |
|
274 |
} |
|
275 |
try { |
|
276 |
setValue(selected); |
|
277 |
} catch (InvalidEntryException e) { |
|
278 |
throw new InvalidEntryException(e); |
|
279 |
} |
|
280 |
} |
|
281 |
} |
|
282 |
|
|
283 |
@Override |
|
284 |
public String getName() { |
|
285 |
return ExplodeEditingProviderFactory.PROVIDER_NAME; |
|
286 |
} |
|
287 |
|
|
288 |
@Override |
|
289 |
public Object getValue(EditingServiceParameter parameter) { |
|
290 |
if(parameter == this.selectionParameter){ |
|
291 |
return value; |
|
292 |
} |
|
293 |
return null; |
|
294 |
} |
|
295 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.explode/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.vectorediting.lib.prov</artifactId> |
|
6 |
<version>1.0.265</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.vectorediting.lib.prov.explode</artifactId> |
|
9 |
<name>org.gvsig.vectorediting.lib.prov.explode</name> |
|
10 |
</project> |
|
0 | 11 |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.polarmatrix/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.vectorediting.lib.prov</artifactId> |
|
6 |
<version>1.0.265</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.vectorediting.lib.prov.polarmatrix</artifactId> |
|
9 |
<name>org.gvsig.vectorediting.lib.prov.polarmatrix</name> |
|
10 |
</project> |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.polarmatrix/src/main/java/org/gvsig/vectorediting/lib/prov/polarmatrix/PolarMatrixEditingLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2015 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.polarmatrix; |
|
26 |
|
|
27 |
import org.gvsig.tools.ToolsLocator; |
|
28 |
import org.gvsig.tools.i18n.I18nManager; |
|
29 |
import org.gvsig.tools.library.AbstractLibrary; |
|
30 |
import org.gvsig.tools.library.Library; |
|
31 |
import org.gvsig.tools.library.LibraryException; |
|
32 |
import org.gvsig.vectorediting.lib.api.EditingLibrary; |
|
33 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
34 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
35 |
|
|
36 |
/** |
|
37 |
* @author llmarques |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class PolarMatrixEditingLibrary extends AbstractLibrary implements |
|
41 |
Library { |
|
42 |
|
|
43 |
@Override |
|
44 |
public void doRegistration() { |
|
45 |
registerAsServiceOf(EditingLibrary.class); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doInitialize() throws LibraryException { |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
protected void doPostInitialize() throws LibraryException { |
|
54 |
EditingProviderManager manager = |
|
55 |
EditingProviderLocator.getProviderManager(); |
|
56 |
|
|
57 |
manager.addProviderFactory(new PolarMatrixEditingProviderFactory()); |
|
58 |
|
|
59 |
manager.registerIcon("vectorediting-tools", "insert-polar-matrix", this |
|
60 |
.getClass().getClassLoader(), this.getClass().getName()); |
|
61 |
|
|
62 |
registerTranslations(); |
|
63 |
|
|
64 |
} |
|
65 |
|
|
66 |
private void registerTranslations() { |
|
67 |
I18nManager manager = ToolsLocator.getI18nManager(); |
|
68 |
manager.addResourceFamily("i18n/text", |
|
69 |
this.getClass().getClassLoader(), "insert-polar-matrix-editing"); |
|
70 |
} |
|
71 |
|
|
72 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.polarmatrix/src/main/java/org/gvsig/vectorediting/lib/prov/polarmatrix/PolarMatrixEditingProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2015 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.polarmatrix; |
|
26 |
|
|
27 |
import java.awt.geom.AffineTransform; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Collections; |
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.List; |
|
32 |
import java.util.Map; |
|
33 |
import org.apache.commons.collections4.CollectionUtils; |
|
34 |
import org.gvsig.fmap.dal.exception.DataException; |
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
36 |
import org.gvsig.fmap.dal.feature.Feature; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
|
40 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
41 |
import org.gvsig.fmap.geom.GeometryManager; |
|
42 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
43 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
|
44 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
45 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
46 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
47 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
48 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
49 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
50 |
import org.gvsig.fmap.geom.primitive.Arc; |
|
51 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
52 |
import org.gvsig.fmap.geom.primitive.Line; |
|
53 |
import org.gvsig.fmap.geom.primitive.Point; |
|
54 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
55 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
56 |
import org.gvsig.symbology.SymbologyLocator; |
|
57 |
import org.gvsig.symbology.SymbologyManager; |
|
58 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol; |
|
59 |
import org.gvsig.tools.ToolsLocator; |
|
60 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
61 |
import org.gvsig.tools.dynobject.DynObject; |
|
62 |
import org.gvsig.tools.exception.BaseException; |
|
63 |
import org.gvsig.tools.i18n.I18nManager; |
|
64 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
65 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
66 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
67 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
68 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
|
69 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
70 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
71 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
72 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
|
73 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
|
74 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
|
75 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
|
76 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameterOptions; |
|
77 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
78 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
79 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
80 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
81 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
82 |
import org.slf4j.Logger; |
|
83 |
import org.slf4j.LoggerFactory; |
|
84 |
|
|
85 |
/** |
|
86 |
* @author llmarques |
|
87 |
* |
|
88 |
*/ |
|
89 |
public class PolarMatrixEditingProvider extends AbstractEditingProvider |
|
90 |
implements EditingProvider { |
|
91 |
|
|
92 |
private static final Logger LOGGER = LoggerFactory.getLogger(PolarMatrixEditingProvider.class); |
|
93 |
|
|
94 |
private final FeatureStore featureStore; |
|
95 |
|
|
96 |
private Map<EditingServiceParameter, Object> values; |
|
97 |
|
|
98 |
private final EditingServiceParameter selection; |
|
99 |
|
|
100 |
private final EditingServiceParameter elementsNumber; |
|
101 |
|
|
102 |
private final EditingServiceParameter centerPoint; |
|
103 |
|
|
104 |
private final EditingServiceParameter elementAngle; |
|
105 |
|
|
106 |
private final EditingServiceParameter rotateElements; |
|
107 |
|
|
108 |
private List<Feature> selectedFeatures; |
|
109 |
|
|
110 |
/** |
|
111 |
* Default constructor. |
|
112 |
* |
|
113 |
* @param services |
|
114 |
* available services for this provider |
|
115 |
* @param parameters |
|
116 |
* of this provider |
|
117 |
*/ |
|
118 |
public PolarMatrixEditingProvider(DynObject parameters, |
|
119 |
ProviderServices services) { |
|
120 |
super(services); |
|
121 |
|
|
122 |
this.featureStore = |
|
123 |
(FeatureStore) parameters |
|
124 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
|
125 |
|
|
126 |
this.selection = |
|
127 |
new DefaultEditingServiceParameter("selection", "selection", |
|
128 |
TYPE.SELECTION); |
|
129 |
|
|
130 |
this.elementsNumber = |
|
131 |
new DefaultEditingServiceParameter("number_of_total_elements", |
|
132 |
"number_of_total_elements", TYPE.VALUE); |
|
133 |
|
|
134 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
135 |
EditingProviderServices editingProviderServices = |
|
136 |
(EditingProviderServices) getProviderServices(); |
|
137 |
|
|
138 |
DefaultEditingServiceParameterOptions options = new DefaultEditingServiceParameterOptions() |
|
139 |
.add(i18nManager.getTranslation("_yes"), true, i18nManager.getTranslation("_yes")) |
|
140 |
.add(i18nManager.getTranslation("_no"), false, i18nManager.getTranslation("_no")); |
|
141 |
|
|
142 |
String consoleMsg |
|
143 |
= editingProviderServices.makeConsoleMessage( |
|
144 |
"rotate_elements", options); |
|
145 |
|
|
146 |
this.rotateElements = |
|
147 |
new DefaultEditingServiceParameter( |
|
148 |
"rotate_elements", |
|
149 |
consoleMsg, |
|
150 |
options, |
|
151 |
false, |
|
152 |
TYPE.OPTION).setDataType(DataTypes.BOOLEAN); |
|
153 |
|
|
154 |
this.centerPoint = |
|
155 |
new DefaultEditingServiceParameter("center", "center", |
|
156 |
TYPE.POSITION); |
|
157 |
|
|
158 |
this.elementAngle = |
|
159 |
new DefaultEditingServiceParameter("angle_between_elements", |
|
160 |
"angle_between_elements", EditingServiceParameter.TYPE.VALUE, |
|
161 |
TYPE.POSITION); |
|
162 |
} |
|
163 |
|
|
164 |
@Override |
|
165 |
public EditingServiceParameter next() { |
|
166 |
if (values.get(selection) == null) { |
|
167 |
return selection; |
|
168 |
} else if (values.get(elementsNumber) == null) { |
|
169 |
return elementsNumber; |
|
170 |
} else if (values.get(rotateElements) == null) { |
|
171 |
return rotateElements; |
|
172 |
} else if (values.get(centerPoint) == null) { |
|
173 |
return centerPoint; |
|
174 |
} else if (values.get(elementAngle) == null) { |
|
175 |
return elementAngle; |
|
176 |
} |
|
177 |
return null; |
|
178 |
} |
|
179 |
|
|
180 |
@Override |
|
181 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
|
182 |
throws DrawServiceException { |
|
183 |
|
|
184 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
185 |
DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus(); |
|
186 |
EditingProviderServices editingProviderServices = |
|
187 |
(EditingProviderServices) getProviderServices(); |
|
188 |
|
|
189 |
Integer elementsNumberValue = (Integer) values.get(elementsNumber); |
|
190 |
Boolean rotateElementsValue = (Boolean) values.get(rotateElements); |
|
191 |
Point centerPointValue = (Point) values.get(centerPoint); |
|
192 |
|
|
193 |
if (CollectionUtils.isNotEmpty(selectedFeatures) && elementsNumberValue != null |
|
194 |
&& rotateElementsValue != null && centerPointValue != null) { |
|
195 |
|
|
196 |
Double angle = (Double) values.get(elementAngle); |
|
197 |
if (angle == null) { |
|
198 |
angle = GeometryUtils.calculateAngle(centerPointValue, mousePosition); |
|
199 |
|
|
200 |
Integer elements = (Integer) values.get(elementsNumber); |
|
201 |
if(elements != null){ |
|
202 |
if(angle > 2*Math.PI/(elements-1)){ |
|
203 |
angle = 2*Math.PI/(elements-1); |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
// try { |
|
209 |
// angle = |
|
210 |
// editingProviderServices.getAngle(centerPointValue, |
|
211 |
// mousePosition); |
|
212 |
// } catch (BaseException e) { |
|
213 |
// throw new DrawServiceException(e); |
|
214 |
// } |
|
215 |
} |
|
216 |
|
|
217 |
// Creation of symbology |
|
218 |
EditingProviderManager editingProviderManager = |
|
219 |
EditingProviderLocator.getProviderManager(); |
|
220 |
ISymbol auxiliaryPointSymbolEditing = |
|
221 |
editingProviderManager |
|
222 |
.getSymbol("auxiliary-point-symbol-editing"); |
|
223 |
ISymbol ruleAxisSymbol = |
|
224 |
editingProviderManager.getSymbol("rule-axis-symbol"); |
|
225 |
ISymbol auxiliaryLineSymbolEditing = |
|
226 |
editingProviderManager |
|
227 |
.getSymbol("auxiliary-line-symbol-editing"); |
|
228 |
|
|
229 |
try { |
|
230 |
|
|
231 |
LOGGER.info("centerPoint: "+centerPointValue.toString()); |
|
232 |
drawingStatus.addStatus(centerPointValue, |
|
233 |
auxiliaryPointSymbolEditing, ""); |
|
234 |
|
|
235 |
// Grade indicator creation |
|
236 |
int subtype = centerPointValue.getGeometryType().getSubType(); |
|
237 |
double textDistance = |
|
238 |
3 * centerPointValue.distance(mousePosition) / 4; |
|
239 |
Geometry pointText = |
|
240 |
geometryManager.createPoint( |
|
241 |
centerPointValue.getX() + textDistance |
|
242 |
* Math.cos(angle / 2), |
|
243 |
centerPointValue.getY() + textDistance |
|
244 |
* Math.sin(angle / 2), subtype); |
|
245 |
LOGGER.info("pointText: "+pointText.toString()); |
|
246 |
drawingStatus.addStatus(pointText, getTextSymbol(), |
|
247 |
degToDms(Math.toDegrees(angle))); |
|
248 |
|
|
249 |
// Horizontal line of angle indicator creation |
|
250 |
Line horizontalLine = geometryManager.createLine(subtype); |
|
251 |
horizontalLine.setPoints(centerPointValue, geometryManager |
|
252 |
.createPoint( |
|
253 |
centerPointValue.getX() |
|
254 |
+ centerPointValue.distance(mousePosition), |
|
255 |
centerPointValue.getY(), subtype)); |
|
256 |
LOGGER.info("horizontalLine: "+horizontalLine.toString()); |
|
257 |
drawingStatus.addStatus(horizontalLine, ruleAxisSymbol, ""); |
|
258 |
|
|
259 |
// Vertical line of angle indicator creation |
|
260 |
Line verticalLine = geometryManager.createLine(subtype); |
|
261 |
verticalLine.setPoints(centerPointValue, mousePosition); |
|
262 |
LOGGER.info("verticalLine: "+verticalLine.toString()); |
|
263 |
drawingStatus.addStatus(verticalLine, ruleAxisSymbol, ""); |
|
264 |
|
|
265 |
// Arc angle indicator creation |
|
266 |
// Double ext = (2 * Math.PI) - angle; |
|
267 |
// Arc arc = |
|
268 |
// editingProviderServices.createArc(centerPointValue, |
|
269 |
// centerPointValue.distance(mousePosition) / 2, 0, ext, |
|
270 |
// subtype); |
|
271 |
Arc arc = GeometryUtils.createArc( |
|
272 |
centerPointValue, |
|
273 |
centerPointValue.distance(mousePosition) / 2, |
|
274 |
0, |
|
275 |
angle, |
|
276 |
subtype |
|
277 |
); |
|
278 |
|
|
279 |
LOGGER.info("arc: "+arc.toString()); |
|
280 |
drawingStatus.addStatus(arc, auxiliaryLineSymbolEditing, ""); |
|
281 |
|
|
282 |
} catch (BaseException e) { |
|
283 |
throw new DrawServiceException(e); |
|
284 |
} |
|
285 |
|
|
286 |
try { |
|
287 |
for (Feature feature : selectedFeatures) { |
|
288 |
ISymbol previewSymbol = this.getPreviewSymbol(feature); |
|
289 |
Geometry geometry = feature.getDefaultGeometry(); |
|
290 |
Geometry[] matrix =createPolarMatrix( |
|
291 |
geometry, |
|
292 |
elementsNumberValue, |
|
293 |
rotateElementsValue, |
|
294 |
centerPointValue, |
|
295 |
angle |
|
296 |
); |
|
297 |
for (Geometry element : matrix) { |
|
298 |
// LOGGER.info("element: "+element.toString()); |
|
299 |
ISymbol symbol = getSymbol(element); |
|
300 |
if (element instanceof Aggregate) { |
|
301 |
int primitivesNumber = ((Aggregate) element).getPrimitivesNumber(); |
|
302 |
for (int j = 0; j < primitivesNumber; j++) { |
|
303 |
// LOGGER.info("primitive: "+j); |
|
304 |
drawingStatus.addStatus(((Aggregate) element).getPrimitiveAt(j), symbol, ""); |
|
305 |
drawingStatus.addStatus(((Aggregate) element).getPrimitiveAt(j), previewSymbol, ""); |
|
306 |
} |
|
307 |
} else { |
|
308 |
drawingStatus.addStatus(element, symbol, ""); |
|
309 |
drawingStatus.addStatus(element, previewSymbol, ""); |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
} catch (BaseException e) { |
|
314 |
throw new DrawServiceException(e); |
|
315 |
} |
|
316 |
} |
|
317 |
return drawingStatus; |
|
318 |
} |
|
319 |
|
|
320 |
private ISymbol getSymbol(Geometry geometry) { |
|
321 |
|
|
322 |
EditingProviderManager editingProviderManager = |
|
323 |
EditingProviderLocator.getProviderManager(); |
|
324 |
ISymbol auxiliaryPointSymbolEditing = |
|
325 |
editingProviderManager.getSymbol("auxiliary-point-symbol-editing"); |
|
326 |
ISymbol lineSymbolEditing = |
|
327 |
editingProviderManager.getSymbol("line-symbol-editing"); |
|
328 |
ISymbol polygonSymbolEditing = |
|
329 |
editingProviderManager.getSymbol("polygon-symbol-editing"); |
|
330 |
|
|
331 |
if (geometry instanceof Curve || geometry instanceof MultiCurve) { |
|
332 |
return lineSymbolEditing; |
|
333 |
} else if (geometry instanceof Surface |
|
334 |
|| geometry instanceof MultiSurface) { |
|
335 |
return polygonSymbolEditing; |
|
336 |
} else if (geometry instanceof Point || geometry instanceof MultiPoint) { |
|
337 |
return auxiliaryPointSymbolEditing; |
|
338 |
} |
|
339 |
return null; |
|
340 |
} |
|
341 |
|
|
342 |
private ISimpleTextSymbol getTextSymbol() { |
|
343 |
SymbologyManager symbologyManager = |
|
344 |
SymbologyLocator.getSymbologyManager(); |
|
345 |
ISimpleTextSymbol textSymbol = |
|
346 |
symbologyManager.createSimpleTextSymbol(); |
|
347 |
textSymbol.setFontSize(10); |
|
348 |
return textSymbol; |
|
349 |
} |
|
350 |
|
|
351 |
private String degToDms(double deg) { |
|
352 |
int d = (int) Math.floor(deg); |
|
353 |
double minfloat = (deg - d) * 60; |
|
354 |
int m = (int) Math.floor(minfloat); |
|
355 |
double secfloat = (minfloat - m) * 60; |
|
356 |
int s = (int) Math.round(secfloat); |
|
357 |
// After rounding, the seconds might become 60. These two |
|
358 |
// if-tests are not necessary if no rounding is done. |
|
359 |
if (s == 60) { |
|
360 |
m++; |
|
361 |
s = 0; |
|
362 |
} |
|
363 |
if (m == 60) { |
|
364 |
d++; |
|
365 |
m = 0; |
|
366 |
} |
|
367 |
return ("" + d + "\u00B0" + m + "\u2032" + s + "\u2033"); |
|
368 |
} |
|
369 |
|
|
370 |
private Geometry[] createPolarMatrix(Geometry geometry, |
|
371 |
Integer elementsNumberValue, Boolean rotateElementsValue, |
|
372 |
Point centerPointValue, Double angle) |
|
373 |
throws GeometryOperationNotSupportedException, |
|
374 |
GeometryOperationException, CreateGeometryException { |
|
375 |
|
|
376 |
Geometry[] geometryMatrix = new Geometry[elementsNumberValue-1]; |
|
377 |
|
|
378 |
for (int i = 0; i < elementsNumberValue-1; i++) { |
|
379 |
|
|
380 |
AffineTransform at = new AffineTransform(); |
|
381 |
if (rotateElementsValue) { |
|
382 |
at = getRotateAffineTransform(centerPointValue, angle * (i+1)); |
|
383 |
} else { |
|
384 |
at = getRotateAffineTransform(centerPointValue, angle * (i+1)); |
|
385 |
|
|
386 |
double centerX = geometry.getEnvelope().getCenter(0); |
|
387 |
double centerY = geometry.getEnvelope().getCenter(1); |
|
388 |
GeometryManager geometryManager = |
|
389 |
GeometryLocator.getGeometryManager(); |
|
390 |
Point geometryCenter = |
|
391 |
geometryManager.createPoint(centerX, centerY, GEOM2D); |
|
392 |
|
|
393 |
Point geometryCenterCloned = (Point) geometryCenter.cloneGeometry(); |
|
394 |
geometryCenterCloned.transform(at); |
|
395 |
at = getMoveAffineTransform(geometryCenter, geometryCenterCloned); |
|
396 |
} |
|
397 |
|
|
398 |
Geometry clonedGeometry = geometry.cloneGeometry(); |
|
399 |
clonedGeometry.transform(at); |
|
400 |
geometryMatrix[i] = clonedGeometry; |
|
401 |
} |
|
402 |
|
|
403 |
return geometryMatrix; |
|
404 |
} |
|
405 |
|
|
406 |
@Override |
|
407 |
public void stop() throws StopServiceException { |
|
408 |
values.clear(); |
|
409 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
410 |
} |
|
411 |
|
|
412 |
@Override |
|
413 |
public List<EditingServiceParameter> getParameters() { |
|
414 |
List<EditingServiceParameter> parameters = |
|
415 |
new ArrayList<>(); |
|
416 |
parameters.add(selection); |
|
417 |
parameters.add(elementsNumber); |
|
418 |
parameters.add(rotateElements); |
|
419 |
parameters.add(centerPoint); |
|
420 |
parameters.add(elementAngle); |
|
421 |
return parameters; |
|
422 |
} |
|
423 |
|
|
424 |
@Override |
|
425 |
public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException { |
|
426 |
validateAndInsertValue(parameter, value); |
|
427 |
} |
|
428 |
|
|
429 |
@Override |
|
430 |
public void setValue(Object value) throws InvalidEntryException { |
|
431 |
EditingServiceParameter parameter = next(); |
|
432 |
validateAndInsertValue(parameter, value); |
|
433 |
} |
|
434 |
|
|
435 |
private void validateAndInsertValue(EditingServiceParameter parameter, |
|
436 |
Object value) throws InvalidEntryException { |
|
437 |
|
|
438 |
boolean insertedValue = false; |
|
439 |
|
|
440 |
if (parameter.equals(selection) && value instanceof FeatureSelection) { |
|
441 |
FeatureSelection featureSelection = (FeatureSelection) value; |
|
442 |
|
|
443 |
if (featureSelection.getSelectedCount() > 0) { |
|
444 |
values.put(parameter, featureSelection); |
|
445 |
this.selectedFeatures = this.getSelectedFeaturesCopy(featureSelection); |
|
446 |
insertedValue = true; |
|
447 |
} |
|
448 |
|
|
449 |
} else if (parameter.equals(elementsNumber) && value instanceof Number) { |
|
450 |
|
|
451 |
int number = ((Number) value).intValue(); |
|
452 |
|
|
453 |
Number angle = ((Number) values.get(elementAngle)); |
|
454 |
if(angle != null){ |
|
455 |
double radians = Math.toRadians(angle.doubleValue()); |
|
456 |
if(radians > 2*Math.PI/(number-1)){ |
|
457 |
throw new InvalidEntryException(null); |
|
458 |
} |
|
459 |
} |
|
460 |
|
|
461 |
values.put(parameter, number); |
|
462 |
insertedValue = true; |
|
463 |
|
|
464 |
} else if (parameter.equals(rotateElements)) { |
|
465 |
|
|
466 |
values.put(parameter, parameter.getOptions2().getValue(value, parameter.getDefaultValue())); |
|
467 |
insertedValue = true; |
|
468 |
|
|
469 |
} else if (parameter.equals(centerPoint) && value instanceof Point) { |
|
470 |
|
|
471 |
values.put(centerPoint, value); |
|
472 |
insertedValue = true; |
|
473 |
|
|
474 |
} else if (parameter.equals(elementAngle)) { |
|
475 |
|
|
476 |
if (value instanceof Double) { |
|
477 |
// LOGGER.info("value Double:"+value.toString()); |
|
478 |
|
|
479 |
Integer elements = (Integer) values.get(elementsNumber); |
|
480 |
double radians = Math.toRadians((Double) value); |
|
481 |
if(elements != null){ |
|
482 |
if(radians > 2*Math.PI/(elements-1)){ |
|
483 |
throw new InvalidEntryException(null); |
|
484 |
} |
|
485 |
} |
|
486 |
values.put(elementAngle, radians); |
|
487 |
insertedValue = true; |
|
488 |
|
|
489 |
} else if (value instanceof Point) { |
|
490 |
// LOGGER.info("value Point:"+value.toString()); |
|
491 |
Point centerPointValue = (Point) values.get(centerPoint); |
|
492 |
Point valuePoint = (Point) value; |
|
493 |
double angle = GeometryUtils.calculateAngle(centerPointValue, valuePoint); |
|
494 |
Integer elements = (Integer) values.get(elementsNumber); |
|
495 |
if(elements != null){ |
|
496 |
if(angle > 2*Math.PI/(elements-1)){ |
|
497 |
throw new InvalidEntryException(null); |
|
498 |
} |
|
499 |
} |
|
500 |
values.put(elementAngle, angle); |
|
501 |
insertedValue = true; |
|
502 |
// try { |
|
503 |
// double angle = |
|
504 |
// editingProviderServices.getAngle(centerPointValue, |
|
505 |
// valuePoint); |
|
506 |
// } catch (BaseException e) { |
|
507 |
// throw new InvalidEntryException(e); |
|
508 |
// } |
|
509 |
} |
|
510 |
} |
|
511 |
|
|
512 |
if (!insertedValue) { |
|
513 |
throw new InvalidEntryException(null); |
|
514 |
} |
|
515 |
} |
|
516 |
|
|
517 |
@Override |
|
518 |
public Geometry finish() throws FinishServiceException { |
|
519 |
return null; |
|
520 |
} |
|
521 |
|
|
522 |
@Override |
|
523 |
public void finishAndStore() throws FinishServiceException { |
|
524 |
|
|
525 |
final EditingProviderServices editingProviderServices = |
|
526 |
(EditingProviderServices) getProviderServices(); |
|
527 |
|
|
528 |
FeatureSelection featureSelection = |
|
529 |
(FeatureSelection) values.get(selection); |
|
530 |
final Integer elementsNumberValue = |
|
531 |
(Integer) values.get(elementsNumber); |
|
532 |
final Boolean rotateElementsValue = |
|
533 |
(Boolean) values.get(rotateElements); |
|
534 |
final Point centerPointValue = (Point) values.get(centerPoint); |
|
535 |
final Double elementAngleValue = (Double) values.get(elementAngle); |
|
536 |
|
|
537 |
if ( CollectionUtils.isNotEmpty(selectedFeatures) && elementsNumberValue != null |
|
538 |
&& rotateElementsValue != null && centerPointValue != null |
|
539 |
&& elementAngleValue != null) { |
|
540 |
|
|
541 |
try { |
|
542 |
for (Feature feature : selectedFeatures) { |
|
543 |
Geometry geometry = feature.getDefaultGeometry(); |
|
544 |
LOGGER.info("elementAngleValue:"+elementAngleValue); |
|
545 |
|
|
546 |
Geometry[] matrix = |
|
547 |
createPolarMatrix(geometry, elementsNumberValue, |
|
548 |
rotateElementsValue, centerPointValue, |
|
549 |
elementAngleValue); |
|
550 |
|
|
551 |
for (Geometry matrix1 : matrix) { |
|
552 |
EditableFeature eFeature = |
|
553 |
editingProviderServices |
|
554 |
.getFeatureCopyWithoutUniqueIndex(featureStore, |
|
555 |
feature); |
|
556 |
eFeature.setDefaultGeometry(matrix1); |
|
557 |
editingProviderServices |
|
558 |
.insertFeatureIntoFeatureStore(eFeature, |
|
559 |
featureStore); |
|
560 |
} |
|
561 |
} |
|
562 |
} catch (BaseException e) { |
|
563 |
throw new FinishServiceException(e); |
|
564 |
} |
|
565 |
} |
|
566 |
} |
|
567 |
|
|
568 |
@Override |
|
569 |
public void start() throws StartServiceException, InvalidEntryException { |
|
570 |
values = new HashMap<>(); |
|
571 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
572 |
|
|
573 |
if (featureStore != null) { |
|
574 |
FeatureSelection selected = null; |
|
575 |
try { |
|
576 |
selected = (FeatureSelection) featureStore.getFeatureSelection().clone(); |
|
577 |
} catch (DataException e) { |
|
578 |
throw new StartServiceException(e); |
|
579 |
} catch (CloneNotSupportedException ex) { |
|
580 |
LOGGER.debug("Can't init selection",ex); |
|
581 |
} |
|
582 |
if ((selected != null) && (selected.getSelectedCount() > 0)) { |
|
583 |
values.put(selection, selected); |
|
584 |
this.selectedFeatures = this.getSelectedFeaturesCopy(selected); |
|
585 |
} |
|
586 |
} |
|
587 |
|
|
588 |
} |
|
589 |
|
|
590 |
@Override |
|
591 |
public String getName() { |
|
592 |
return PolarMatrixEditingProviderFactory.PROVIDER_NAME; |
|
593 |
} |
|
594 |
|
|
595 |
private AffineTransform getMoveAffineTransform(Point p1, Point p2) |
|
596 |
throws GeometryOperationNotSupportedException, |
|
597 |
GeometryOperationException { |
|
598 |
|
|
599 |
AffineTransform translate = |
|
600 |
AffineTransform.getTranslateInstance(p2.getX() - p1.getX(), |
|
601 |
p2.getY() - p1.getY()); |
|
602 |
|
|
603 |
return translate; |
|
604 |
} |
|
605 |
|
|
606 |
private AffineTransform getRotateAffineTransform(Point axisP1, Double angle) |
|
607 |
throws GeometryOperationNotSupportedException, |
|
608 |
GeometryOperationException { |
|
609 |
|
|
610 |
AffineTransform translate = |
|
611 |
AffineTransform |
|
612 |
.getTranslateInstance(-axisP1.getX(), -axisP1.getY()); |
|
613 |
|
|
614 |
AffineTransform rotate = AffineTransform.getRotateInstance(angle); |
|
615 |
|
|
616 |
AffineTransform inverseTranslate = |
|
617 |
AffineTransform.getTranslateInstance(axisP1.getX(), axisP1.getY()); |
|
618 |
AffineTransform at = new AffineTransform(translate); |
|
619 |
|
|
620 |
at.preConcatenate(rotate); |
|
621 |
at.preConcatenate(inverseTranslate); |
|
622 |
return at; |
|
623 |
} |
|
624 |
@Override |
|
625 |
public Object getValue(EditingServiceParameter parameter) { |
|
626 |
return values!=null?values.get(parameter):null; |
|
627 |
} |
|
628 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.polarmatrix/src/main/java/org/gvsig/vectorediting/lib/prov/polarmatrix/PolarMatrixEditingProviderFactory.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2015 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.polarmatrix; |
|
26 |
|
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.tools.dynobject.DynObject; |
|
29 |
import org.gvsig.tools.service.spi.Provider; |
|
30 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
31 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
32 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProviderFactory; |
|
33 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceinfo; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* @author llmarques |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class PolarMatrixEditingProviderFactory extends AbstractEditingProviderFactory { |
|
41 |
|
|
42 |
public final static String PROVIDER_NAME = "insert-polar-matrix"; |
|
43 |
|
|
44 |
public final static String PROVIDER_DESCRIPTION = |
|
45 |
"Creates a polar matrix of geometries"; |
|
46 |
|
|
47 |
public PolarMatrixEditingProviderFactory() { |
|
48 |
super(PROVIDER_NAME, PROVIDER_DESCRIPTION); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public EditingServiceInfo getServiceInfo() { |
|
53 |
EditingServiceInfo serviceInfo = |
|
54 |
new DefaultEditingServiceinfo(PROVIDER_NAME, PROVIDER_DESCRIPTION, true, null, |
|
55 |
new int[] { |
|
56 |
Geometry.TYPES.POINT, Geometry.TYPES.MULTIPOINT, |
|
57 |
Geometry.TYPES.CURVE, Geometry.TYPES.LINE, |
|
58 |
Geometry.TYPES.MULTICURVE, Geometry.TYPES.MULTILINE, |
|
59 |
Geometry.TYPES.SURFACE, Geometry.TYPES.POLYGON, |
|
60 |
Geometry.TYPES.MULTISURFACE, Geometry.TYPES.MULTIPOLYGON }); |
|
61 |
|
|
62 |
return serviceInfo; |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
|
67 |
return new PolarMatrixEditingProvider(parameters,services); |
|
68 |
} |
|
69 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.polarmatrix/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.lib.prov.polarmatrix.PolarMatrixEditingLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.splitline/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.lib.prov.splitline.SplitLineEditingLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.splitline/src/main/java/org/gvsig/vectorediting/lib/prov/splitline/SplitLineEditingProviderFactory.java | ||
---|---|---|
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.splitline; |
|
26 |
|
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.tools.dynobject.DynObject; |
|
29 |
import org.gvsig.tools.service.spi.Provider; |
|
30 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
31 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
32 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProviderFactory; |
|
33 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceinfo; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* @author llmarques |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class SplitLineEditingProviderFactory extends AbstractEditingProviderFactory { |
|
41 |
|
|
42 |
public final static String PROVIDER_NAME = "modify-split-line"; |
|
43 |
|
|
44 |
public final static String PROVIDER_DESCRIPTION = |
|
45 |
"Splits provider by a point"; |
|
46 |
|
|
47 |
public SplitLineEditingProviderFactory() { |
|
48 |
super(PROVIDER_NAME, PROVIDER_DESCRIPTION); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public EditingServiceInfo getServiceInfo() { |
|
53 |
EditingServiceInfo serviceInfo = |
|
54 |
new DefaultEditingServiceinfo(PROVIDER_NAME, "", false, null, |
|
55 |
new int[] { |
|
56 |
Geometry.TYPES.LINE, Geometry.TYPES.MULTILINE, |
|
57 |
Geometry.TYPES.CURVE, Geometry.TYPES.MULTICURVE |
|
58 |
}); |
|
59 |
|
|
60 |
return serviceInfo; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
|
65 |
return new SplitLineEditingProvider(parameters, services); |
|
66 |
} |
|
67 |
|
|
68 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.splitline/src/main/java/org/gvsig/vectorediting/lib/prov/splitline/SplitLineEditingLibrary.java | ||
---|---|---|
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.splitline; |
|
26 |
|
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.tools.ToolsLocator; |
|
29 |
import org.gvsig.tools.i18n.I18nManager; |
|
30 |
import org.gvsig.tools.library.AbstractLibrary; |
|
31 |
import org.gvsig.tools.library.Library; |
|
32 |
import org.gvsig.tools.library.LibraryException; |
|
33 |
import org.gvsig.vectorediting.lib.api.EditingLibrary; |
|
34 |
import org.gvsig.vectorediting.lib.prov.splitline.operation.ArcSplitLineOperation; |
|
35 |
import org.gvsig.vectorediting.lib.prov.splitline.operation.CurveSplitLineOperation; |
|
36 |
import org.gvsig.vectorediting.lib.prov.splitline.operation.SplitLineOperationUtils; |
|
37 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
38 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
39 |
|
|
40 |
/** |
|
41 |
* @author llmarques |
|
42 |
* |
|
43 |
*/ |
|
44 |
public class SplitLineEditingLibrary extends AbstractLibrary implements Library { |
|
45 |
|
|
46 |
@Override |
|
47 |
public void doRegistration() { |
|
48 |
registerAsServiceOf(EditingLibrary.class); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
protected void doInitialize() throws LibraryException { |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void doPostInitialize() throws LibraryException { |
|
57 |
EditingProviderManager manager = |
|
58 |
EditingProviderLocator.getProviderManager(); |
|
59 |
|
|
60 |
manager.addProviderFactory(new SplitLineEditingProviderFactory()); |
|
61 |
|
|
62 |
manager.registerIcon("vectorediting-tools", "modify-split-line", this |
|
63 |
.getClass().getClassLoader(), this.getClass().getName()); |
|
64 |
|
|
65 |
SplitLineOperationUtils.register(new CurveSplitLineOperation(), |
|
66 |
Geometry.TYPES.CURVE); |
|
67 |
//Dejamos que la operacion para los ARC sea la de la CURVE porque |
|
68 |
//no se puede hacer con ARC transformados (elipses) |
|
69 |
SplitLineOperationUtils.register(new ArcSplitLineOperation(), |
|
70 |
Geometry.TYPES.ARC); |
|
71 |
SplitLineOperationUtils.register(new CurveSplitLineOperation(), |
|
72 |
Geometry.TYPES.LINE); |
|
73 |
//FIXME: Comprobar si el comportamiento de la operaci?n SplineSplitLineOperation es el deseado |
|
74 |
// y si s?, registrarla en lugar de CurveSpliLineOperation para Splines |
|
75 |
SplitLineOperationUtils.register(new CurveSplitLineOperation(), |
|
76 |
Geometry.TYPES.SPLINE); |
|
77 |
|
|
78 |
registerTranslations(); |
|
79 |
|
|
80 |
} |
|
81 |
|
|
82 |
private void registerTranslations() { |
|
83 |
I18nManager manager = ToolsLocator.getI18nManager(); |
|
84 |
manager.addResourceFamily("i18n/text", |
|
85 |
this.getClass().getClassLoader(), "split-line-editing"); |
|
86 |
} |
|
87 |
|
|
88 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.265/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.splitline/src/main/java/org/gvsig/vectorediting/lib/prov/splitline/operation/SplineSplitLineOperation.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
Also available in: Unified diff