Revision 3225
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/resources-plugin/config.xml | ||
---|---|---|
230 | 230 |
position="601003300" action-command="modify-join" icon="modify-join" |
231 | 231 |
accelerator="" /> |
232 | 232 |
|
233 |
<action name="modify-combine" label="modify_combine" tooltip="modify_combine" |
|
234 |
position="601003350" action-command="modify-combine" icon="modify-combine" |
|
235 |
accelerator="" /> |
|
236 |
|
|
233 | 237 |
<action name="insert-autopolygon" label="insert_autopolygon" |
234 | 238 |
tooltip="insert_autopolygon" position="601003400" action-command="insert-autopolygon" |
235 | 239 |
icon="insert-autopolygon" accelerator="" /> |
... | ... | |
333 | 337 |
<menu text="Layer/Modify/modify_scale" name="modify-scale" /> |
334 | 338 |
<menu text="Layer/Modify/modify_simplify" name="modify-simplify" /> |
335 | 339 |
<menu text="Layer/Modify/modify_join" name="modify-join" /> |
340 |
<menu text="Layer/Modify/modify_combine" name="modify-combine" /> |
|
336 | 341 |
<menu text="Layer/Modify/modify_stretch" name="modify-stretch" /> |
337 | 342 |
<menu text="Layer/Modify/modify_extend_line" name="modify-extend-line" /> |
338 | 343 |
<menu text="Layer/Modify/modify_trim_lines_by_cutting_edges" name="modify-trim-line" /> |
... | ... | |
391 | 396 |
<selectable-tool name="modify-simplify" /> |
392 | 397 |
<selectable-tool name="insert-autopolygon" /> |
393 | 398 |
<selectable-tool name="modify-join" /> |
399 |
<selectable-tool name="modify-combine" /> |
|
394 | 400 |
<selectable-tool name="modify-stretch" /> |
395 | 401 |
<selectable-tool name="modify-extend-line" /> |
396 | 402 |
<selectable-tool name="modify-trim-line" /> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/resources-plugin/i18n/text.properties | ||
---|---|---|
44 | 44 |
modify_scale = Escalar geometr\u00eda |
45 | 45 |
modify_simplify = Simplificar geometr\u00eda |
46 | 46 |
modify_join = Unir geometr\u00edas |
47 |
modify_combine = Combinar geometr\u00edas |
|
47 | 48 |
insert_autopolygon = Insertar autopol\u00edgono |
48 | 49 |
modify_stretch = Estirar geometr\u00eda |
49 | 50 |
modify_extend_line = Alargar l\u00ednea hasta objeto |
... | ... | |
266 | 267 |
_Short_angle=A |
267 | 268 |
_Delete_second_selected_geometry=Borrar la segunda geometr\u00eda seleccionada |
268 | 269 |
_First_segment=Primer segmento |
269 |
_Second_segment=Segundo segmento |
|
270 |
_Second_segment=Segundo segmento |
|
271 |
_The_resulting_geometry_is_not_valid_for_the_store=La geometr\u00eda resultado no es v\u00e1lida para la capa |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties | ||
---|---|---|
43 | 43 |
modify_simplify = Simplify geometry |
44 | 44 |
insert_autopolygon = Insert autopolygon |
45 | 45 |
modify_join = Join geometries |
46 |
modify_combine = Combine geometries |
|
46 | 47 |
modify_stretch = Stretch geometry |
47 | 48 |
modify_extend_line = Extend line to object |
48 | 49 |
modify_trim_lines_by_cutting_edges = Trim lines by cutting edges |
... | ... | |
264 | 265 |
_Short_angle=A |
265 | 266 |
_Delete_second_selected_geometry=Delete second selected geometry |
266 | 267 |
_First_segment=First segment |
267 |
_Second_segment=Second segment |
|
268 |
_Second_segment=Second segment |
|
269 |
_The_resulting_geometry_is_not_valid_for_the_store=The resulting geometry is not valid for the store |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/pom.xml | ||
---|---|---|
10 | 10 |
<parent> |
11 | 11 |
<groupId>org.gvsig</groupId> |
12 | 12 |
<artifactId>org.gvsig.desktop</artifactId> |
13 |
<version>2.0.363</version>
|
|
13 |
<version>2.0.364-SNAPSHOT</version>
|
|
14 | 14 |
</parent> |
15 | 15 |
<url>https://devel.gvsig.org/sites/org.gvsig.vectorediting/${project.version}</url> |
16 | 16 |
<scm> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.api/src/main/java/org/gvsig/vectorediting/lib/api/exceptions/FinishServiceException.java | ||
---|---|---|
40 | 40 |
public FinishServiceException(String message, Throwable ex) { |
41 | 41 |
super(message, ex, KEY, serialVersionUID); |
42 | 42 |
} |
43 |
|
|
44 |
public FinishServiceException(String message, String key, Throwable ex) { |
|
45 |
super(message, ex, key, serialVersionUID); |
|
46 |
} |
|
43 | 47 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.join/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 | 1 |
org.gvsig.vectorediting.lib.prov.join.JoinEditingLibrary |
2 |
org.gvsig.vectorediting.lib.prov.combine.CombineEditingLibrary |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.join/src/main/java/org/gvsig/vectorediting/lib/prov/combine/CombineEditingProviderFactory.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.combine; |
|
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 CombineEditingProviderFactory extends AbstractEditingProviderFactory { |
|
40 |
|
|
41 |
public final static String PROVIDER_NAME = "modify-combine"; |
|
42 |
|
|
43 |
public final static String PROVIDER_DESCRIPTION = |
|
44 |
"Combines geometries into one multigeometries"; |
|
45 |
|
|
46 |
public CombineEditingProviderFactory() { |
|
47 |
super(PROVIDER_NAME, PROVIDER_DESCRIPTION); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public EditingServiceInfo getServiceInfo() { |
|
52 |
EditingServiceInfo serviceInfo = |
|
53 |
new DefaultEditingServiceinfo(PROVIDER_NAME, "", false, null, |
|
54 |
new int[] { Geometry.TYPES.MULTIPOINT, |
|
55 |
Geometry.TYPES.LINE, Geometry.TYPES.POLYGON, |
|
56 |
Geometry.TYPES.CURVE, Geometry.TYPES.SURFACE, |
|
57 |
Geometry.TYPES.MULTILINE, Geometry.TYPES.MULTIPOLYGON, |
|
58 |
Geometry.TYPES.MULTICURVE, Geometry.TYPES.MULTISURFACE }); |
|
59 |
|
|
60 |
return serviceInfo; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
|
65 |
return new CombineEditingProvider(parameters, services); |
|
66 |
} |
|
67 |
|
|
68 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.join/src/main/java/org/gvsig/vectorediting/lib/prov/combine/CombineEditingLibrary.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.combine; |
|
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.spi.EditingProviderLocator; |
|
33 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* @author llmarques |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class CombineEditingLibrary extends AbstractLibrary implements Library { |
|
41 |
|
|
42 |
@Override |
|
43 |
protected void doInitialize() throws LibraryException { |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
protected void doPostInitialize() throws LibraryException { |
|
48 |
EditingProviderManager manager = |
|
49 |
EditingProviderLocator.getProviderManager(); |
|
50 |
|
|
51 |
manager.addProviderFactory(new CombineEditingProviderFactory()); |
|
52 |
|
|
53 |
manager.registerIcon("vectorediting-tools", "modify-combine", this |
|
54 |
.getClass().getClassLoader(), this.getClass().getName()); |
|
55 |
|
|
56 |
registerTranslations(); |
|
57 |
} |
|
58 |
|
|
59 |
private void registerTranslations() { |
|
60 |
I18nManager manager = ToolsLocator.getI18nManager(); |
|
61 |
manager.addResourceFamily("i18n/text", |
|
62 |
this.getClass().getClassLoader(), "modify-combine-editing"); |
|
63 |
} |
|
64 |
|
|
65 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.join/src/main/java/org/gvsig/vectorediting/lib/prov/combine/CombineEditingProvider.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.combine; |
|
26 |
|
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Iterator; |
|
29 |
import java.util.List; |
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
32 |
import org.gvsig.fmap.dal.feature.Feature; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
37 |
import org.gvsig.fmap.geom.Geometry; |
|
38 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
39 |
import org.gvsig.fmap.geom.GeometryManager; |
|
40 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
41 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
42 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
43 |
import org.gvsig.fmap.geom.complex.Complex; |
|
44 |
import org.gvsig.fmap.geom.primitive.Point; |
|
45 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
46 |
import org.gvsig.tools.ToolsLocator; |
|
47 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
48 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
49 |
import org.gvsig.tools.dynobject.DynObject; |
|
50 |
import org.gvsig.tools.exception.BaseException; |
|
51 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
52 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
53 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
54 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
55 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
|
56 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
57 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
58 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
59 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
|
60 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
|
61 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
|
62 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
63 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
64 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
65 |
|
|
66 |
/** |
|
67 |
* @author llmarques |
|
68 |
* |
|
69 |
*/ |
|
70 |
public class CombineEditingProvider extends AbstractEditingProvider implements EditingProvider { |
|
71 |
|
|
72 |
private static final int HAS_POINT = 1; |
|
73 |
private static final int HAS_CURVE = 2; |
|
74 |
private static final int HAS_SURFACE = 4; |
|
75 |
|
|
76 |
private final EditingServiceParameter selectionParameter; |
|
77 |
|
|
78 |
private final FeatureStore featureStore; |
|
79 |
|
|
80 |
private FeatureSelection featureSelection; |
|
81 |
|
|
82 |
/** |
|
83 |
* Default constructor. |
|
84 |
* |
|
85 |
* @param parameters |
|
86 |
* of this provider |
|
87 |
* @param services |
|
88 |
*/ |
|
89 |
public CombineEditingProvider(DynObject parameters, ProviderServices services) { |
|
90 |
super(services); |
|
91 |
|
|
92 |
this.featureStore = |
|
93 |
(FeatureStore) parameters |
|
94 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
|
95 |
|
|
96 |
this.selectionParameter = |
|
97 |
new DefaultEditingServiceParameter("selection", "selection", |
|
98 |
TYPE.SELECTION); |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public EditingServiceParameter next() { |
|
103 |
if (featureSelection == null) { |
|
104 |
return selectionParameter; |
|
105 |
} |
|
106 |
return null; |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
|
111 |
throws DrawServiceException { |
|
112 |
return null; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public void stop() throws StopServiceException { |
|
117 |
DisposeUtils.disposeQuietly(featureSelection); |
|
118 |
featureSelection = null; |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public List<EditingServiceParameter> getParameters() { |
|
123 |
List<EditingServiceParameter> parameters = |
|
124 |
new ArrayList<>(); |
|
125 |
parameters.add(selectionParameter); |
|
126 |
return parameters; |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException { |
|
131 |
validateAndInsertValue(parameter, value); |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public void setValue(Object value) throws InvalidEntryException { |
|
136 |
EditingServiceParameter parameter = next(); |
|
137 |
validateAndInsertValue(parameter, value); |
|
138 |
|
|
139 |
} |
|
140 |
|
|
141 |
private void validateAndInsertValue(EditingServiceParameter parameter, |
|
142 |
Object value) throws InvalidEntryException { |
|
143 |
|
|
144 |
if (parameter == selectionParameter) { |
|
145 |
|
|
146 |
if (value instanceof FeatureSelection) { |
|
147 |
FeatureSelection fSelection = (FeatureSelection) value; |
|
148 |
|
|
149 |
if (fSelection.getSelectedCount() > 1) { |
|
150 |
|
|
151 |
DisposableIterator it = null; |
|
152 |
|
|
153 |
try { |
|
154 |
it = fSelection.fastIterator(); |
|
155 |
|
|
156 |
Feature feature = (Feature) it.next(); |
|
157 |
// Gets geometry type of first selected feature |
|
158 |
GeometryType geometryType = |
|
159 |
feature.getDefaultGeometry().getGeometryType(); |
|
160 |
|
|
161 |
// Iterate over remaining selected features |
|
162 |
while (it.hasNext()) { |
|
163 |
feature = (Feature) it.next(); |
|
164 |
|
|
165 |
// Remaining selected features must be the same or |
|
166 |
// the equivalent multigeometry type of first |
|
167 |
// feature. If one of reamining geometries is |
|
168 |
// different, selection is not valid. |
|
169 |
if (geometryType.isTypeOf(CURVE) |
|
170 |
|| geometryType.isTypeOf(MULTICURVE)) { |
|
171 |
|
|
172 |
GeometryType featureGeoType = |
|
173 |
feature.getDefaultGeometry() |
|
174 |
.getGeometryType(); |
|
175 |
|
|
176 |
if (!(featureGeoType.isTypeOf(CURVE) || featureGeoType |
|
177 |
.isTypeOf(MULTICURVE))) { |
|
178 |
throw new InvalidEntryException(null); |
|
179 |
} |
|
180 |
|
|
181 |
} else if (geometryType.isTypeOf(SURFACE) |
|
182 |
|| geometryType.isTypeOf(SURFACE)) { |
|
183 |
|
|
184 |
GeometryType featureGeoType = |
|
185 |
feature.getDefaultGeometry() |
|
186 |
.getGeometryType(); |
|
187 |
|
|
188 |
if (!(featureGeoType.isTypeOf(SURFACE) || featureGeoType |
|
189 |
.isTypeOf(MULTISURFACE))) { |
|
190 |
throw new InvalidEntryException(null); |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 |
DisposeUtils.disposeQuietly(featureSelection); |
|
195 |
ToolsLocator.getDisposableManager().bind(fSelection); |
|
196 |
featureSelection = fSelection; |
|
197 |
return; |
|
198 |
} catch (DataException e) { |
|
199 |
throw new InvalidEntryException(e); |
|
200 |
} finally { |
|
201 |
DisposeUtils.disposeQuietly(it); |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
throw new InvalidEntryException(null); |
|
207 |
} |
|
208 |
|
|
209 |
@Override |
|
210 |
public Geometry finish() throws FinishServiceException { |
|
211 |
|
|
212 |
if (featureSelection != null) { |
|
213 |
Geometry combinedGeometry = null; |
|
214 |
DisposableIterator it = null; |
|
215 |
|
|
216 |
EditingProviderServices editingProviderServices |
|
217 |
= (EditingProviderServices) getProviderServices(); |
|
218 |
|
|
219 |
int resultType = 0; |
|
220 |
|
|
221 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
222 |
try { |
|
223 |
int subtype = editingProviderServices.getSubType(featureStore); |
|
224 |
MultiPoint multiPoint = geometryManager.createMultiPoint(subtype); |
|
225 |
MultiCurve multiCurve = geometryManager.createMultiCurve(subtype); |
|
226 |
MultiSurface multiSurface = geometryManager.createMultiSurface(subtype); |
|
227 |
|
|
228 |
it = featureSelection.fastIterator(); |
|
229 |
|
|
230 |
while (it.hasNext()) { |
|
231 |
Feature tmpFeature = (Feature) it.next(); |
|
232 |
Geometry geom = tmpFeature.getDefaultGeometry(); |
|
233 |
if(geom.getGeometryType().isTypeOf(POINT) || |
|
234 |
geom.getGeometryType().isTypeOf(MULTIPOINT) ) { |
|
235 |
multiPoint.addPrimitives(geom); |
|
236 |
resultType |= HAS_POINT; |
|
237 |
} else if(geom.getGeometryType().isTypeOf(CURVE) || |
|
238 |
geom.getGeometryType().isTypeOf(MULTICURVE) ) { |
|
239 |
multiCurve.addPrimitives(geom); |
|
240 |
resultType |= HAS_CURVE; |
|
241 |
} else if(geom.getGeometryType().isTypeOf(SURFACE) || |
|
242 |
geom.getGeometryType().isTypeOf(MULTISURFACE) ) { |
|
243 |
multiSurface.addPrimitives(geom); |
|
244 |
resultType |= HAS_SURFACE; |
|
245 |
} else if(geom.getGeometryType().isTypeOf(COMPLEX)) { |
|
246 |
Complex complex = (Complex)geom; |
|
247 |
Iterator<Geometry> complexIt = complex.iterator(); |
|
248 |
while (complexIt.hasNext()) { |
|
249 |
Geometry geom1 = complexIt.next(); |
|
250 |
if (geom1.getGeometryType().isTypeOf(POINT) |
|
251 |
|| geom1.getGeometryType().isTypeOf(MULTIPOINT)) { |
|
252 |
multiPoint.addPrimitives(geom1); |
|
253 |
resultType |= HAS_POINT; |
|
254 |
} else if (geom1.getGeometryType().isTypeOf(CURVE) |
|
255 |
|| geom1.getGeometryType().isTypeOf(MULTICURVE)) { |
|
256 |
multiCurve.addPrimitives(geom1); |
|
257 |
resultType |= HAS_CURVE; |
|
258 |
|
|
259 |
} else if (geom1.getGeometryType().isTypeOf(SURFACE) |
|
260 |
|| geom1.getGeometryType().isTypeOf(MULTISURFACE)) { |
|
261 |
multiSurface.addPrimitives(geom1); |
|
262 |
resultType |= HAS_SURFACE; |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
GeometryType storeGeomType = editingProviderServices.getGeomType(featureStore); |
|
269 |
if(resultType > 4 || resultType == 3){ //COMPLEX |
|
270 |
if(storeGeomType.getType()!=COMPLEX && storeGeomType.getType()!=GEOMETRY){ |
|
271 |
throw new FinishServiceException("_The_resulting_geometry_is_not_valid_for_the_store", null); |
|
272 |
} |
|
273 |
combinedGeometry = geometryManager.create(COMPLEX, subtype); |
|
274 |
Complex complex = (Complex)combinedGeometry; |
|
275 |
if((resultType & HAS_POINT) == HAS_POINT){ |
|
276 |
complex.addPrimitives(multiPoint.union()); |
|
277 |
} else if((resultType & HAS_CURVE) == HAS_CURVE){ |
|
278 |
complex.addPrimitives(multiCurve.dissolve()); |
|
279 |
} else if((resultType & HAS_SURFACE) == HAS_SURFACE){ |
|
280 |
complex.addPrimitives(multiSurface.union()); |
|
281 |
} |
|
282 |
} else { |
|
283 |
switch (resultType){ |
|
284 |
case HAS_POINT: |
|
285 |
if(!storeGeomType.isTypeOf(GEOMETRY) && |
|
286 |
!storeGeomType.isTypeOf(POINT) && |
|
287 |
!storeGeomType.isTypeOf(MULTIPOINT) ){ |
|
288 |
throw new FinishServiceException("The resulting geometry is not valid for the store.", "_The_resulting_geometry_is_not_valid_for_the_store", null); |
|
289 |
} |
|
290 |
combinedGeometry = multiPoint.union(); |
|
291 |
|
|
292 |
if(storeGeomType.isTypeOf(POINT) && combinedGeometry.getGeometryType().isTypeOf(MULTIPOINT)){ |
|
293 |
throw new FinishServiceException("The resulting geometry is not valid for the store.", "_The_resulting_geometry_is_not_valid_for_the_store", null); |
|
294 |
} |
|
295 |
if(storeGeomType.isTypeOf(MULTIPOINT) && combinedGeometry.getGeometryType().isTypeOf(POINT)){ |
|
296 |
MultiPoint tmpMultiPoint = geometryManager.createMultiPoint(subtype); |
|
297 |
tmpMultiPoint.addPrimitives(combinedGeometry); |
|
298 |
combinedGeometry = tmpMultiPoint; |
|
299 |
} |
|
300 |
break; |
|
301 |
case HAS_CURVE: |
|
302 |
if(!storeGeomType.isTypeOf(GEOMETRY) && |
|
303 |
!storeGeomType.isTypeOf(CURVE) && |
|
304 |
!storeGeomType.isTypeOf(MULTICURVE) ){ |
|
305 |
throw new FinishServiceException("The resulting geometry is not valid for the store.", "_The_resulting_geometry_is_not_valid_for_the_store", null); |
|
306 |
} |
|
307 |
combinedGeometry = multiCurve.dissolve(); |
|
308 |
|
|
309 |
if(storeGeomType.isTypeOf(CURVE) && combinedGeometry.getGeometryType().isTypeOf(MULTICURVE)){ |
|
310 |
throw new FinishServiceException("The resulting geometry is not valid for the store.", "_The_resulting_geometry_is_not_valid_for_the_store", null); |
|
311 |
} |
|
312 |
if(storeGeomType.isTypeOf(MULTICURVE) && combinedGeometry.getGeometryType().isTypeOf(CURVE)){ |
|
313 |
MultiCurve tmpMultiCurve = geometryManager.createMultiCurve(subtype); |
|
314 |
tmpMultiCurve.addPrimitives(combinedGeometry); |
|
315 |
combinedGeometry = tmpMultiCurve; |
|
316 |
} |
|
317 |
break; |
|
318 |
case HAS_SURFACE: |
|
319 |
if(!storeGeomType.isTypeOf(GEOMETRY) && |
|
320 |
!storeGeomType.isTypeOf(SURFACE) && |
|
321 |
!storeGeomType.isTypeOf(MULTISURFACE) ){ |
|
322 |
throw new FinishServiceException("The resulting geometry is not valid for the store.", "_The_resulting_geometry_is_not_valid_for_the_store", null); |
|
323 |
} |
|
324 |
combinedGeometry = multiSurface.union(); |
|
325 |
if(storeGeomType.isTypeOf(SURFACE) && combinedGeometry.getGeometryType().isTypeOf(MULTISURFACE)){ |
|
326 |
throw new FinishServiceException("The resulting geometry is not valid for the store.", "_The_resulting_geometry_is_not_valid_for_the_store", null); |
|
327 |
} |
|
328 |
if(storeGeomType.isTypeOf(MULTISURFACE) && combinedGeometry.getGeometryType().isTypeOf(SURFACE)){ |
|
329 |
MultiSurface tmpMultiSurface = geometryManager.createMultiSurface(subtype); |
|
330 |
tmpMultiSurface.addPrimitives(combinedGeometry); |
|
331 |
combinedGeometry = tmpMultiSurface; |
|
332 |
} |
|
333 |
break; |
|
334 |
} |
|
335 |
} |
|
336 |
} catch (FinishServiceException e) { |
|
337 |
throw e; |
|
338 |
} catch (BaseException e) { |
|
339 |
throw new FinishServiceException(e); |
|
340 |
} finally { |
|
341 |
DisposeUtils.disposeQuietly(it); |
|
342 |
} |
|
343 |
|
|
344 |
return combinedGeometry; |
|
345 |
} |
|
346 |
return null; |
|
347 |
} |
|
348 |
|
|
349 |
@SuppressWarnings("rawtypes") |
|
350 |
@Override |
|
351 |
public void finishAndStore() throws FinishServiceException { |
|
352 |
Geometry geometry = finish(); |
|
353 |
|
|
354 |
final EditingProviderServices editingProviderServices = |
|
355 |
(EditingProviderServices) getProviderServices(); |
|
356 |
|
|
357 |
FeatureType featureType = null; |
|
358 |
EditableFeature eFeature = null; |
|
359 |
|
|
360 |
try { |
|
361 |
eFeature = featureStore.createNewFeature(); |
|
362 |
featureType = featureStore.getDefaultFeatureType(); |
|
363 |
} catch (DataException e) { |
|
364 |
throw new FinishServiceException(e); |
|
365 |
} |
|
366 |
|
|
367 |
Iterator typeIterator = featureType.iterator(); |
|
368 |
// Iterate over feature type |
|
369 |
while (typeIterator.hasNext()) { |
|
370 |
boolean insertValue = true; |
|
371 |
FeatureAttributeDescriptor attribute = |
|
372 |
(FeatureAttributeDescriptor) typeIterator.next(); |
|
373 |
|
|
374 |
// If type is a primary key do nothing |
|
375 |
if (!attribute.isPrimaryKey()) { |
|
376 |
|
|
377 |
// int type = attribute.getType(); |
|
378 |
|
|
379 |
DisposableIterator featureIterator = null; |
|
380 |
try { |
|
381 |
featureIterator = featureSelection.fastIterator(); |
|
382 |
Feature feature = (Feature) featureIterator.next(); |
|
383 |
|
|
384 |
// Restart iterator and initilize it at second position |
|
385 |
featureIterator.dispose(); |
|
386 |
featureIterator = featureSelection.fastIterator(1); |
|
387 |
|
|
388 |
// Gets the type value of first feature |
|
389 |
Object value = feature.get(attribute.getName()); |
|
390 |
|
|
391 |
// Compare first value with the rest of features. If values |
|
392 |
// are different, break bucle and don't insert value at new |
|
393 |
// feature. |
|
394 |
if (value != null) { |
|
395 |
|
|
396 |
while (featureIterator.hasNext()) { |
|
397 |
Feature nextFeature = |
|
398 |
(Feature) featureIterator.next(); |
|
399 |
Object nextValue = |
|
400 |
nextFeature.get(attribute.getName()); |
|
401 |
|
|
402 |
if (nextValue == null || !value.equals(nextValue)) { |
|
403 |
insertValue = false; |
|
404 |
break; |
|
405 |
} |
|
406 |
} |
|
407 |
|
|
408 |
if (insertValue) { |
|
409 |
eFeature.set(attribute.getName(), value); |
|
410 |
} |
|
411 |
} |
|
412 |
} catch (DataException e) { |
|
413 |
throw new FinishServiceException(e); |
|
414 |
} finally { |
|
415 |
DisposeUtils.disposeQuietly(featureIterator); |
|
416 |
} |
|
417 |
} |
|
418 |
} |
|
419 |
|
|
420 |
// Inserts new feature |
|
421 |
eFeature.setDefaultGeometry(geometry); |
|
422 |
editingProviderServices.insertFeatureIntoFeatureStore(eFeature, |
|
423 |
featureStore); |
|
424 |
|
|
425 |
// Deletes selected features |
|
426 |
try { |
|
427 |
featureSelection.accept((Object obj) -> { |
|
428 |
Feature feature = (Feature) obj; |
|
429 |
editingProviderServices.deleteFeatureFromFeatureStore( |
|
430 |
feature, featureStore); |
|
431 |
}); |
|
432 |
featureStore.getFeatureSelection().deselectAll(); |
|
433 |
} catch (BaseException e) { |
|
434 |
throw new FinishServiceException(e); |
|
435 |
} |
|
436 |
} |
|
437 |
|
|
438 |
@Override |
|
439 |
public void start() throws StartServiceException, InvalidEntryException { |
|
440 |
FeatureSelection selected = null; |
|
441 |
if (featureStore != null) { |
|
442 |
try { |
|
443 |
selected = featureStore.getFeatureSelection(); |
|
444 |
} catch (DataException e) { |
|
445 |
throw new StartServiceException(e); |
|
446 |
} |
|
447 |
if (selected.getSelectedCount() > 1) { |
|
448 |
try { |
|
449 |
setValue(selected); |
|
450 |
} catch (InvalidEntryException e) { |
|
451 |
throw new InvalidEntryException(e); |
|
452 |
} |
|
453 |
} |
|
454 |
} |
|
455 |
} |
|
456 |
|
|
457 |
@Override |
|
458 |
public String getName() { |
|
459 |
return CombineEditingProviderFactory.PROVIDER_NAME; |
|
460 |
} |
|
461 |
|
|
462 |
@Override |
|
463 |
public Object getValue(EditingServiceParameter parameter) { |
|
464 |
if(parameter == selectionParameter){ |
|
465 |
return featureSelection; |
|
466 |
} |
|
467 |
return null; |
|
468 |
} |
|
469 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingContext.java | ||
---|---|---|
99 | 99 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
100 | 100 |
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException; |
101 | 101 |
import org.gvsig.vectorediting.lib.api.exceptions.EndEditingException; |
102 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
102 | 103 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
103 | 104 |
import org.gvsig.vectorediting.lib.api.exceptions.ParsePointException; |
104 | 105 |
import org.gvsig.vectorediting.lib.api.exceptions.ParseValueException; |
... | ... | |
820 | 821 |
changeSelectedTool(getActiveService().getName()); |
821 | 822 |
} |
822 | 823 |
|
824 |
} catch (FinishServiceException ex) { |
|
825 |
showConsoleMessage("\n"+ex.getLocalizedMessage()); |
|
826 |
cleanEditingContext(); |
|
827 |
return; |
|
823 | 828 |
} catch (InvalidEntryException ex) { |
824 | 829 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
825 | 830 |
showConsoleMessage("\n" |
Also available in: Unified diff