Revision 1552
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.duplicate/src/main/java/org/gvsig/vectorediting/lib/prov/duplicate/DuplicateEditingProvider.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.duplicate; |
|
26 |
|
|
27 |
import java.awt.geom.AffineTransform; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Map; |
|
32 |
|
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
35 |
import org.gvsig.fmap.dal.feature.Feature; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
|
42 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
43 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
44 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
45 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
46 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
47 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
48 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
49 |
import org.gvsig.fmap.geom.primitive.Line; |
|
50 |
import org.gvsig.fmap.geom.primitive.Point; |
|
51 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
53 |
import org.gvsig.tools.ToolsLocator; |
|
54 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
55 |
import org.gvsig.tools.dynobject.DynObject; |
|
56 |
import org.gvsig.tools.exception.BaseException; |
|
57 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
58 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
59 |
import org.gvsig.tools.visitor.Visitor; |
|
60 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
61 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
62 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
63 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
|
64 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
65 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
66 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
67 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
|
68 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
|
69 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
|
70 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
|
71 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
72 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
73 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
74 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
75 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
76 |
|
|
77 |
/** |
|
78 |
* @author llmarques |
|
79 |
* |
|
80 |
*/ |
|
81 |
public class DuplicateEditingProvider extends AbstractEditingProvider implements |
|
82 |
EditingProvider { |
|
83 |
|
|
84 |
private EditingServiceParameter selection; |
|
85 |
|
|
86 |
private EditingServiceParameter firstPoint; |
|
87 |
|
|
88 |
private EditingServiceParameter secondPoint; |
|
89 |
|
|
90 |
private FeatureStore featureStore; |
|
91 |
|
|
92 |
private Map<EditingServiceParameter, Object> values; |
|
93 |
|
|
94 |
/** |
|
95 |
* Default constructor. |
|
96 |
* |
|
97 |
* @param providerServices |
|
98 |
* available services for this provider |
|
99 |
* @param parameters |
|
100 |
* of this provider |
|
101 |
*/ |
|
102 |
public DuplicateEditingProvider(DynObject parameters, |
|
103 |
ProviderServices services) { |
|
104 |
super(services); |
|
105 |
|
|
106 |
this.featureStore = |
|
107 |
(FeatureStore) parameters |
|
108 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
|
109 |
|
|
110 |
this.selection = |
|
111 |
new DefaultEditingServiceParameter("selection", "selection", |
|
112 |
TYPE.SELECTION); |
|
113 |
|
|
114 |
this.firstPoint = |
|
115 |
new DefaultEditingServiceParameter("first_point", "first_point", |
|
116 |
TYPE.POSITION); |
|
117 |
|
|
118 |
this.secondPoint = |
|
119 |
new DefaultEditingServiceParameter("second_point", "second_point", |
|
120 |
TYPE.POSITION); |
|
121 |
} |
|
122 |
|
|
123 |
public EditingServiceParameter next() { |
|
124 |
if (values.get(selection) == null) { |
|
125 |
return selection; |
|
126 |
} else if (values.get(firstPoint) == null) { |
|
127 |
return firstPoint; |
|
128 |
} else if (values.get(secondPoint) == null) { |
|
129 |
return secondPoint; |
|
130 |
} |
|
131 |
return null; |
|
132 |
} |
|
133 |
|
|
134 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
|
135 |
throws DrawServiceException { |
|
136 |
DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus(); |
|
137 |
|
|
138 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
139 |
EditingProviderManager editingProviderManager = |
|
140 |
EditingProviderLocator.getProviderManager(); |
|
141 |
EditingProviderServices editingProviderServices = |
|
142 |
(EditingProviderServices) getProviderServices(); |
|
143 |
int subtype; |
|
144 |
try { |
|
145 |
subtype = editingProviderServices.getSubType(featureStore); |
|
146 |
} catch (DataException e2) { |
|
147 |
throw new DrawServiceException(e2); |
|
148 |
} |
|
149 |
ISymbol lineSymbolEditing = editingProviderManager.getSymbol("line-symbol-editing"); |
|
150 |
ISymbol auxiliarylineSymbolEditing = editingProviderManager.getSymbol("auxiliary-line-symbol-editing"); |
|
151 |
ISymbol polygonSymbolEditing = editingProviderManager.getSymbol("polygon-symbol-editing"); |
|
152 |
ISymbol auxiliaryPointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing"); |
|
153 |
|
|
154 |
if (values != null) { |
|
155 |
|
|
156 |
FeatureSelection featureSelection = |
|
157 |
(FeatureSelection) values.get(selection); |
|
158 |
Point firstPointValue = (Point) values.get(firstPoint); |
|
159 |
|
|
160 |
if (featureSelection != null && firstPointValue != null) { |
|
161 |
drawingStatus.addStatus(firstPointValue, auxiliaryPointSymbolEditing, ""); |
|
162 |
Line auxLine; |
|
163 |
try { |
|
164 |
auxLine = geometryManager.createLine(subtype); |
|
165 |
} catch (CreateGeometryException e1) { |
|
166 |
throw new DrawServiceException(e1); |
|
167 |
} |
|
168 |
auxLine.setPoints(firstPointValue, mousePosition); |
|
169 |
drawingStatus.addStatus(auxLine, auxiliarylineSymbolEditing, ""); |
|
170 |
|
|
171 |
DisposableIterator it = null; |
|
172 |
try { |
|
173 |
it = featureSelection.fastIterator(); |
|
174 |
while (it.hasNext()) { |
|
175 |
Feature feature = (Feature) it.next(); |
|
176 |
|
|
177 |
Geometry geometry = |
|
178 |
feature.getDefaultGeometry().cloneGeometry(); |
|
179 |
|
|
180 |
AffineTransform at = |
|
181 |
getMoveAffineTransform(firstPointValue, |
|
182 |
mousePosition); |
|
183 |
geometry.transform(at); |
|
184 |
ISymbol symbol=null; |
|
185 |
if(geometry instanceof Curve || geometry instanceof MultiCurve){ |
|
186 |
symbol = lineSymbolEditing; |
|
187 |
} else if(geometry instanceof Surface || geometry instanceof MultiSurface){ |
|
188 |
symbol = polygonSymbolEditing; |
|
189 |
} else if(geometry instanceof Point || geometry instanceof MultiPoint){ |
|
190 |
symbol = auxiliaryPointSymbolEditing; |
|
191 |
} |
|
192 |
if(geometry instanceof Aggregate){ |
|
193 |
int primitivesNumber = ((Aggregate)geometry).getPrimitivesNumber(); |
|
194 |
for (int i = 0; i < primitivesNumber; i++) { |
|
195 |
drawingStatus.addStatus(((Aggregate)geometry).getPrimitiveAt(i), symbol, ""); |
|
196 |
} |
|
197 |
} else { |
|
198 |
drawingStatus.addStatus(geometry, symbol, ""); |
|
199 |
} |
|
200 |
// drawingStatus.addGeometry(geometry); |
|
201 |
} |
|
202 |
} catch (BaseException e) { |
|
203 |
throw new DrawServiceException(e); |
|
204 |
} finally { |
|
205 |
it.dispose(); |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
return drawingStatus; |
|
210 |
} |
|
211 |
|
|
212 |
private AffineTransform getMoveAffineTransform(Point p1, Point p2) |
|
213 |
throws GeometryOperationNotSupportedException, |
|
214 |
GeometryOperationException { |
|
215 |
|
|
216 |
AffineTransform translate = |
|
217 |
AffineTransform.getTranslateInstance(p2.getX() - p1.getX(), |
|
218 |
p2.getY() - p1.getY()); |
|
219 |
|
|
220 |
return translate; |
|
221 |
} |
|
222 |
|
|
223 |
public void stop() throws StopServiceException { |
|
224 |
if (values != null) { |
|
225 |
values.clear(); |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
public List<EditingServiceParameter> getParameters() { |
|
230 |
List<EditingServiceParameter> parameters = |
|
231 |
new ArrayList<EditingServiceParameter>(); |
|
232 |
parameters.add(selection); |
|
233 |
parameters.add(firstPoint); |
|
234 |
parameters.add(secondPoint); |
|
235 |
return parameters; |
|
236 |
} |
|
237 |
|
|
238 |
public void setValue(Object value) throws InvalidEntryException { |
|
239 |
EditingServiceParameter parameter = next(); |
|
240 |
validateAndInsertValue(parameter, value); |
|
241 |
} |
|
242 |
|
|
243 |
private void validateAndInsertValue(EditingServiceParameter parameter, |
|
244 |
Object value) { |
|
245 |
|
|
246 |
if (parameter == selection) { |
|
247 |
if (value instanceof FeatureSelection) { |
|
248 |
if (((FeatureSelection) value).getSelectedCount() > 0) { |
|
249 |
values.put(selection, value); |
|
250 |
} |
|
251 |
} |
|
252 |
} else if (parameter == firstPoint || parameter == secondPoint) { |
|
253 |
if (value instanceof Point) { |
|
254 |
values.put(parameter, value); |
|
255 |
return; |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
public Geometry finish() throws FinishServiceException { |
|
261 |
return null; |
|
262 |
} |
|
263 |
|
|
264 |
public void finishAndStore() throws FinishServiceException { |
|
265 |
if (values != null) { |
|
266 |
|
|
267 |
final Point p1 = (Point) values.get(firstPoint); |
|
268 |
final Point p2 = (Point) values.get(secondPoint); |
|
269 |
|
|
270 |
FeatureSelection featureSelection = |
|
271 |
(FeatureSelection) values.get(selection); |
|
272 |
ToolsLocator.getDisposableManager().bind(featureSelection); |
|
273 |
|
|
274 |
try { |
|
275 |
featureSelection.accept(new Visitor() { |
|
276 |
|
|
277 |
public void visit(Object obj) |
|
278 |
throws VisitCanceledException, BaseException { |
|
279 |
Feature feature = (Feature) obj; |
|
280 |
|
|
281 |
EditingProviderServices editingProviderServices = |
|
282 |
(EditingProviderServices) getProviderServices(); |
|
283 |
|
|
284 |
EditableFeature editable = |
|
285 |
editingProviderServices.getFeatureCopyWithoutPK( |
|
286 |
featureStore, feature); |
|
287 |
|
|
288 |
Geometry geometry = |
|
289 |
feature.getDefaultGeometry().cloneGeometry(); |
|
290 |
geometry.transform(getMoveAffineTransform(p1, p2)); |
|
291 |
|
|
292 |
editable.setDefaultGeometry(geometry); |
|
293 |
editingProviderServices.insertFeatureIntoFeatureStore( |
|
294 |
editable, featureStore); |
|
295 |
} |
|
296 |
}); |
|
297 |
|
|
298 |
featureStore.getFeatureSelection().deselectAll(); |
|
299 |
featureSelection.dispose(); |
|
300 |
|
|
301 |
} catch (BaseException e) { |
|
302 |
throw new FinishServiceException(e); |
|
303 |
} |
|
304 |
} |
|
305 |
} |
|
306 |
|
|
307 |
public void start() throws StartServiceException, InvalidEntryException { |
|
308 |
values = new HashMap<EditingServiceParameter, Object>(); |
|
309 |
FeatureSelection selected = null; |
|
310 |
if (featureStore != null) { |
|
311 |
try { |
|
312 |
selected = featureStore.getFeatureSelection(); |
|
313 |
} catch (DataException e) { |
|
314 |
throw new StartServiceException(e); |
|
315 |
} |
|
316 |
try { |
|
317 |
setValue(selected); |
|
318 |
} catch (InvalidEntryException e) { |
|
319 |
throw new InvalidEntryException(e); |
|
320 |
} |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
324 |
public String getName() { |
|
325 |
return DuplicateEditingProviderFactory.PROVIDER_NAME; |
|
326 |
} |
|
327 |
|
|
328 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.duplicate/src/main/java/org/gvsig/vectorediting/lib/prov/duplicate/DuplicateEditingProviderFactory.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.duplicate; |
|
26 |
|
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.tools.ToolsLocator; |
|
29 |
import org.gvsig.tools.dynobject.DynClass; |
|
30 |
import org.gvsig.tools.dynobject.DynObject; |
|
31 |
import org.gvsig.tools.service.spi.AbstractProviderFactory; |
|
32 |
import org.gvsig.tools.service.spi.Provider; |
|
33 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
34 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
35 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceinfo; |
|
36 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
37 |
|
|
38 |
/** |
|
39 |
* @author llmarques |
|
40 |
* |
|
41 |
*/ |
|
42 |
public class DuplicateEditingProviderFactory extends AbstractProviderFactory |
|
43 |
implements EditingProviderFactory { |
|
44 |
|
|
45 |
public static final String PROVIDER_NAME = "modify-duplicate"; |
|
46 |
|
|
47 |
private final static String PROVIDER_DESCRIPTION = "Duplicates geometries"; |
|
48 |
|
|
49 |
public void initialize() { |
|
50 |
} |
|
51 |
|
|
52 |
public EditingServiceInfo getServiceInfo() { |
|
53 |
EditingServiceInfo serviceInfo = |
|
54 |
new DefaultEditingServiceinfo(PROVIDER_NAME, "", false, null, |
|
55 |
new int[] { Geometry.TYPES.POINT, Geometry.TYPES.MULTIPOINT, |
|
56 |
Geometry.TYPES.CURVE, Geometry.TYPES.MULTICURVE, |
|
57 |
Geometry.TYPES.LINE, Geometry.TYPES.MULTILINE, |
|
58 |
Geometry.TYPES.POLYGON, Geometry.TYPES.MULTIPOLYGON, |
|
59 |
Geometry.TYPES.SURFACE, Geometry.TYPES.MULTISURFACE }); |
|
60 |
|
|
61 |
return serviceInfo; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
|
66 |
return new DuplicateEditingProvider(parameters, services); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public DynObject createParameters() { |
|
71 |
DynObject parameters = super.createParameters(); |
|
72 |
parameters.setDynValue(PROVIDER_NAME_FIELD, PROVIDER_NAME); |
|
73 |
return parameters; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
protected DynClass createParametersDynClass() { |
|
78 |
DynClass dynclass = |
|
79 |
ToolsLocator.getDynObjectManager().createDynClass(PROVIDER_NAME, |
|
80 |
PROVIDER_DESCRIPTION); |
|
81 |
|
|
82 |
dynclass.addDynFieldString(PROVIDER_NAME_FIELD); |
|
83 |
dynclass.addDynFieldObject(FEATURE_STORE_FIELD); |
|
84 |
dynclass.addDynFieldObject(MAPCONTEXT_FIELD); |
|
85 |
return dynclass; |
|
86 |
} |
|
87 |
|
|
88 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.duplicate/src/main/java/org/gvsig/vectorediting/lib/prov/duplicate/DuplicateEditingLibrary.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.duplicate; |
|
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 |
/** |
|
38 |
* @author llmarques |
|
39 |
* |
|
40 |
*/ |
|
41 |
public class DuplicateEditingLibrary extends AbstractLibrary implements 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 DuplicateEditingProviderFactory()); |
|
58 |
|
|
59 |
manager.registerIcon("vectorediting-tools", "modify-duplicate", this |
|
60 |
.getClass().getClassLoader(), this.getClass().getName()); |
|
61 |
|
|
62 |
registerTranslations(); |
|
63 |
} |
|
64 |
|
|
65 |
private void registerTranslations() { |
|
66 |
I18nManager manager = ToolsLocator.getI18nManager(); |
|
67 |
manager.addResourceFamily("i18n/text", |
|
68 |
this.getClass().getClassLoader(), "modify-duplicate"); |
|
69 |
} |
|
70 |
|
|
71 |
|
|
72 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.duplicate/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.lib.prov.duplicate.DuplicateEditingLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.duplicate/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.84</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.vectorediting.lib.prov.duplicate</artifactId> |
|
9 |
<name>org.gvsig.vectorediting.lib.prov.duplicate</name> |
|
10 |
</project> |
|
0 | 11 |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/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.84</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.vectorediting.lib.prov.stretch</artifactId> |
|
9 |
<name>org.gvsig.vectorediting.lib.prov.stretch</name> |
|
10 |
</project> |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.lib.prov.stretch.StretchEditingLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/StretchEditingProviderFactory.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.lib.prov.stretch; |
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
import org.gvsig.fmap.geom.Geometry; |
|
6 |
import org.gvsig.tools.ToolsLocator; |
|
7 |
import org.gvsig.tools.dynobject.DynClass; |
|
8 |
import org.gvsig.tools.dynobject.DynObject; |
|
9 |
import org.gvsig.tools.service.spi.AbstractProviderFactory; |
|
10 |
import org.gvsig.tools.service.spi.Provider; |
|
11 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
12 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
13 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceinfo; |
|
14 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
15 |
|
|
16 |
public class StretchEditingProviderFactory extends AbstractProviderFactory |
|
17 |
implements EditingProviderFactory { |
|
18 |
|
|
19 |
public static final String PROVIDER_NAME = "modify-stretch"; |
|
20 |
|
|
21 |
private final static String PROVIDER_DESCRIPTION = |
|
22 |
"Stretch selected geometries"; |
|
23 |
|
|
24 |
public void initialize() { |
|
25 |
|
|
26 |
} |
|
27 |
|
|
28 |
public EditingServiceInfo getServiceInfo() { |
|
29 |
EditingServiceInfo serviceInfo = |
|
30 |
new DefaultEditingServiceinfo(PROVIDER_NAME, "", false, null, |
|
31 |
new int[] { Geometry.TYPES.POINT, Geometry.TYPES.MULTIPOINT, |
|
32 |
Geometry.TYPES.SURFACE, Geometry.TYPES.MULTISURFACE, |
|
33 |
Geometry.TYPES.LINE, Geometry.TYPES.MULTILINE, |
|
34 |
Geometry.TYPES.POLYGON, Geometry.TYPES.MULTIPOLYGON, |
|
35 |
Geometry.TYPES.CURVE, Geometry.TYPES.MULTICURVE }); |
|
36 |
|
|
37 |
return serviceInfo; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
|
42 |
return new StretchEditingProvider(services, parameters); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public DynObject createParameters() { |
|
47 |
DynObject dynobject = super.createParameters(); |
|
48 |
dynobject.setDynValue(PROVIDER_NAME_FIELD, PROVIDER_NAME); |
|
49 |
return dynobject; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
protected DynClass createParametersDynClass() { |
|
54 |
DynClass dynclass = |
|
55 |
ToolsLocator.getDynObjectManager().createDynClass(PROVIDER_NAME, |
|
56 |
PROVIDER_DESCRIPTION); |
|
57 |
|
|
58 |
dynclass.addDynFieldString(PROVIDER_NAME_FIELD); |
|
59 |
dynclass.addDynFieldObject(FEATURE_STORE_FIELD); |
|
60 |
dynclass.addDynFieldObject(MAPCONTEXT_FIELD); |
|
61 |
|
|
62 |
return dynclass; |
|
63 |
} |
|
64 |
|
|
65 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/StretchEditingLibrary.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 |
package org.gvsig.vectorediting.lib.prov.stretch; |
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
import org.gvsig.fmap.geom.Geometry; |
|
29 |
import org.gvsig.tools.ToolsLocator; |
|
30 |
import org.gvsig.tools.i18n.I18nManager; |
|
31 |
import org.gvsig.tools.library.AbstractLibrary; |
|
32 |
import org.gvsig.tools.library.LibraryException; |
|
33 |
import org.gvsig.vectorediting.lib.api.EditingLibrary; |
|
34 |
import org.gvsig.vectorediting.lib.prov.stretch.operation.CurveStretchOperation; |
|
35 |
import org.gvsig.vectorediting.lib.prov.stretch.operation.PointStretchOperation; |
|
36 |
import org.gvsig.vectorediting.lib.prov.stretch.operation.SurfaceStretchOperation; |
|
37 |
import org.gvsig.vectorediting.lib.prov.stretch.operation.LineStretchOperation; |
|
38 |
import org.gvsig.vectorediting.lib.prov.stretch.operation.PolygonStretchOperation; |
|
39 |
import org.gvsig.vectorediting.lib.prov.stretch.operation.StretchOperationUtils; |
|
40 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
41 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
42 |
|
|
43 |
/** |
|
44 |
* Library for default implementation initialization and configuration. |
|
45 |
* |
|
46 |
* @author gvSIG team |
|
47 |
* @version $Id$ |
|
48 |
*/ |
|
49 |
public class StretchEditingLibrary extends AbstractLibrary { |
|
50 |
|
|
51 |
@Override |
|
52 |
public void doRegistration() { |
|
53 |
registerAsServiceOf(EditingLibrary.class); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
protected void doInitialize() throws LibraryException { |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
protected void doPostInitialize() throws LibraryException { |
|
62 |
EditingProviderManager manager = |
|
63 |
EditingProviderLocator.getProviderManager(); |
|
64 |
|
|
65 |
manager.addProviderFactory(new StretchEditingProviderFactory()); |
|
66 |
|
|
67 |
manager.registerIcon("vectorediting-tools", "modify-stretch", this |
|
68 |
.getClass().getClassLoader(), this.getClass().getName()); |
|
69 |
|
|
70 |
StretchOperationUtils.register(new PointStretchOperation(), Geometry.TYPES.POINT); |
|
71 |
|
|
72 |
StretchOperationUtils.register(new LineStretchOperation(), Geometry.TYPES.LINE); |
|
73 |
StretchOperationUtils.register(new CurveStretchOperation(), Geometry.TYPES.ARC); |
|
74 |
StretchOperationUtils.register(new CurveStretchOperation(), Geometry.TYPES.SPLINE); |
|
75 |
|
|
76 |
StretchOperationUtils.register(new PolygonStretchOperation(), Geometry.TYPES.POLYGON); |
|
77 |
StretchOperationUtils.register(new SurfaceStretchOperation(), Geometry.TYPES.ELLIPSE); |
|
78 |
StretchOperationUtils.register(new SurfaceStretchOperation(), Geometry.TYPES.CIRCLE); |
|
79 |
StretchOperationUtils.register(new SurfaceStretchOperation(), Geometry.TYPES.ELLIPTICARC); |
|
80 |
registerTranslations(); |
|
81 |
} |
|
82 |
|
|
83 |
private void registerTranslations() { |
|
84 |
I18nManager manager = ToolsLocator.getI18nManager(); |
|
85 |
manager.addResourceFamily("i18n.text", |
|
86 |
this.getClass().getClassLoader(), "stretch-editing"); |
|
87 |
} |
|
88 |
|
|
89 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/StretchEditingProvider.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.lib.prov.stretch; |
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
import java.awt.geom.AffineTransform; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.HashMap; |
|
9 |
import java.util.Iterator; |
|
10 |
import java.util.List; |
|
11 |
import java.util.Map; |
|
12 |
|
|
13 |
import org.slf4j.Logger; |
|
14 |
import org.slf4j.LoggerFactory; |
|
15 |
|
|
16 |
import org.gvsig.fmap.dal.exception.DataException; |
|
17 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
18 |
import org.gvsig.fmap.dal.feature.Feature; |
|
19 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
20 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
21 |
import org.gvsig.fmap.geom.Geometry; |
|
22 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
23 |
import org.gvsig.fmap.geom.GeometryManager; |
|
24 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
|
25 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
26 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
27 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
|
28 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
29 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
30 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
31 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
32 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
33 |
import org.gvsig.fmap.geom.primitive.Point; |
|
34 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
35 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
36 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
37 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
38 |
import org.gvsig.tools.ToolsLocator; |
|
39 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
40 |
import org.gvsig.tools.dynobject.DynObject; |
|
41 |
import org.gvsig.tools.exception.BaseException; |
|
42 |
import org.gvsig.tools.i18n.I18nManager; |
|
43 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
44 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
45 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
46 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
47 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
|
48 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
49 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
50 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
51 |
import org.gvsig.vectorediting.lib.prov.stretch.operation.StretchOperation; |
|
52 |
import org.gvsig.vectorediting.lib.prov.stretch.operation.StretchOperationUtils; |
|
53 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
|
54 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
|
55 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
|
56 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
57 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
58 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
59 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
60 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
61 |
|
|
62 |
public class StretchEditingProvider extends AbstractEditingProvider implements |
|
63 |
EditingProvider { |
|
64 |
|
|
65 |
private static Logger logger = LoggerFactory.getLogger(StretchEditingProvider.class); |
|
66 |
|
|
67 |
private I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
68 |
|
|
69 |
private EditingServiceParameter selectionParameter; |
|
70 |
|
|
71 |
private EditingServiceParameter geometryParameter; |
|
72 |
|
|
73 |
private EditingServiceParameter firstPointParameter; |
|
74 |
|
|
75 |
private EditingServiceParameter secondPointParameter; |
|
76 |
|
|
77 |
private Map<EditingServiceParameter, Object> values; |
|
78 |
|
|
79 |
private FeatureStore featureStore; |
|
80 |
|
|
81 |
public StretchEditingProvider(ProviderServices providerServices, |
|
82 |
DynObject parameters) { |
|
83 |
super(providerServices); |
|
84 |
this.featureStore = |
|
85 |
(FeatureStore) parameters |
|
86 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
|
87 |
|
|
88 |
this.selectionParameter = |
|
89 |
new DefaultEditingServiceParameter("selection", |
|
90 |
i18nManager.getTranslation("selection"), TYPE.SELECTION); |
|
91 |
|
|
92 |
this.geometryParameter = |
|
93 |
new DefaultEditingServiceParameter("Draw geometry", |
|
94 |
"draw_geometry_to_select_vertex", Geometry.TYPES.MULTISURFACE, TYPE.GEOMETRY); |
|
95 |
|
|
96 |
this.firstPointParameter = |
|
97 |
new DefaultEditingServiceParameter("first_point", |
|
98 |
i18nManager.getTranslation("first_point"), TYPE.VALUE, TYPE.POSITION); |
|
99 |
|
|
100 |
this.secondPointParameter = |
|
101 |
new DefaultEditingServiceParameter("second_point", |
|
102 |
i18nManager.getTranslation("second_point"), TYPE.VALUE, TYPE.POSITION); |
|
103 |
|
|
104 |
} |
|
105 |
|
|
106 |
public List<EditingServiceParameter> getParameters() { |
|
107 |
List<EditingServiceParameter> list = |
|
108 |
new ArrayList<EditingServiceParameter>(); |
|
109 |
list.add(selectionParameter); |
|
110 |
list.add(geometryParameter); |
|
111 |
list.add(firstPointParameter); |
|
112 |
list.add(secondPointParameter); |
|
113 |
return list; |
|
114 |
} |
|
115 |
|
|
116 |
private void validateAndInsertValue(EditingServiceParameter param, |
|
117 |
Object value) throws InvalidEntryException { |
|
118 |
if (param == selectionParameter) { |
|
119 |
if (value instanceof FeatureSelection) { |
|
120 |
values.put(param, value); |
|
121 |
return; |
|
122 |
} |
|
123 |
} else if (param == firstPointParameter) { |
|
124 |
if (value instanceof Point) { |
|
125 |
values.put(param, value); |
|
126 |
return; |
|
127 |
} |
|
128 |
} else if (param == secondPointParameter) { |
|
129 |
if (value instanceof Point) { |
|
130 |
values.put(param, value); |
|
131 |
return; |
|
132 |
} |
|
133 |
} else if (param == geometryParameter) { |
|
134 |
if (value instanceof Geometry) { |
|
135 |
|
|
136 |
// Before set value checks if some geometry intersects the |
|
137 |
// geometry received as parameter. |
|
138 |
Geometry geometry = (Geometry) value; |
|
139 |
FeatureSelection selection = |
|
140 |
(FeatureSelection) values.get(selectionParameter); |
|
141 |
DisposableIterator it = null; |
|
142 |
|
|
143 |
try { |
|
144 |
it = selection.fastIterator(); |
|
145 |
|
|
146 |
while (it.hasNext()) { |
|
147 |
Feature feature = (Feature) it.next(); |
|
148 |
|
|
149 |
Geometry defaultGeometry = feature.getDefaultGeometry(); |
|
150 |
if (defaultGeometry.intersects(geometry) || defaultGeometry.contains(geometry)) { |
|
151 |
values.put(param, value); |
|
152 |
return; |
|
153 |
} |
|
154 |
} |
|
155 |
throw new InvalidEntryException(null); |
|
156 |
} catch (BaseException e) { |
|
157 |
throw new InvalidEntryException(e); |
|
158 |
} finally { |
|
159 |
it.dispose(); |
|
160 |
} |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
public EditingServiceParameter next() { |
|
166 |
if (values.get(selectionParameter) == null) { |
|
167 |
return this.selectionParameter; |
|
168 |
} else if (values.get(geometryParameter) == null) { |
|
169 |
return this.geometryParameter; |
|
170 |
} else if (values.get(firstPointParameter) == null) { |
|
171 |
return this.firstPointParameter; |
|
172 |
} else if (values.get(secondPointParameter) == null) { |
|
173 |
return this.secondPointParameter; |
|
174 |
} |
|
175 |
return null; |
|
176 |
} |
|
177 |
|
|
178 |
public static Geometry applyTransform(Geometry geometry, AffineTransform at, |
|
179 |
Geometry roi) throws CreateGeometryException, |
|
180 |
GeometryOperationNotSupportedException, GeometryOperationException { |
|
181 |
if (geometry instanceof MultiPrimitive) { |
|
182 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
183 |
MultiPrimitive aggregate = (MultiPrimitive)geometry; |
|
184 |
GeometryType geometryType = aggregate.getGeometryType(); |
|
185 |
MultiPrimitive newAggregate = (MultiPrimitive) geometryManager.create(geometryType.getType(), geometryType.getSubType()); |
|
186 |
for (int i = 0; i < aggregate.getPrimitivesNumber(); i++) { |
|
187 |
Primitive primitive = aggregate.getPrimitiveAt(i); |
|
188 |
StretchOperation operation = StretchOperationUtils.getOperation(primitive); |
|
189 |
if (operation != null) { |
|
190 |
Geometry element = operation.transform(at, primitive, roi); |
|
191 |
if (element instanceof MultiPrimitive) { |
|
192 |
for (int j = 0; j < ((MultiPrimitive)element).getPrimitivesNumber(); j++) { |
|
193 |
newAggregate.addPrimitive(((MultiPrimitive)element).getPrimitiveAt(j)); |
|
194 |
} |
|
195 |
} else if(element instanceof Primitive){ |
|
196 |
newAggregate.addPrimitive((Primitive)element); |
|
197 |
} else { |
|
198 |
logger.warn("StretchOperation has returned a not-supported geometry type. "+operation.toString()+" "+element.getClass().getName()); |
|
199 |
} |
|
200 |
} else { |
|
201 |
newAggregate.addPrimitive(primitive); |
|
202 |
} |
|
203 |
} |
|
204 |
return newAggregate; |
|
205 |
} else if (geometry instanceof Primitive) { |
|
206 |
StretchOperation operation = StretchOperationUtils.getOperation((Primitive)geometry); |
|
207 |
if (operation != null) { |
|
208 |
return operation.transform(at, (Primitive)geometry, roi); |
|
209 |
} |
|
210 |
} |
|
211 |
return geometry; |
|
212 |
} |
|
213 |
|
|
214 |
|
|
215 |
public static List<Point> getSelectedVertex(Geometry geometry, |
|
216 |
Geometry roi) throws CreateGeometryException, |
|
217 |
GeometryOperationNotSupportedException, GeometryOperationException { |
|
218 |
List<Point> selectedVertex = new ArrayList<Point>(); |
|
219 |
if (geometry instanceof MultiPrimitive) { |
|
220 |
MultiPrimitive aggregate = (MultiPrimitive)geometry; |
|
221 |
for (int i = 0; i < aggregate.getPrimitivesNumber(); i++) { |
|
222 |
Primitive primitive = aggregate.getPrimitiveAt(i); |
|
223 |
StretchOperation operation = StretchOperationUtils.getOperation(primitive); |
|
224 |
if (operation != null) { |
|
225 |
selectedVertex.addAll(operation.getSelectedVertex(primitive, roi)); |
|
226 |
} |
|
227 |
} |
|
228 |
} else if (geometry instanceof Primitive) { |
|
229 |
Primitive primitive = (Primitive)geometry; |
|
230 |
StretchOperation operation = StretchOperationUtils.getOperation(primitive); |
|
231 |
if (operation != null) { |
|
232 |
selectedVertex.addAll(operation.getSelectedVertex(primitive, roi)); |
|
233 |
} |
|
234 |
} |
|
235 |
return selectedVertex; |
|
236 |
} |
|
237 |
|
|
238 |
|
|
239 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
|
240 |
throws DrawServiceException { |
|
241 |
DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus(); |
|
242 |
EditingProviderManager editingProviderManager = |
|
243 |
EditingProviderLocator.getProviderManager(); |
|
244 |
ISymbol selectedVertexEditingSymbol = editingProviderManager.getSymbol("selected-vertex-symbol-editing"); |
|
245 |
ISymbol lineSymbolEditing = editingProviderManager.getSymbol("line-symbol-editing"); |
|
246 |
ISymbol polygonSymbolEditing = editingProviderManager.getSymbol("polygon-symbol-editing"); |
|
247 |
ISymbol auxiliaryPointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing"); |
|
248 |
|
|
249 |
FeatureSelection selection = |
|
250 |
(FeatureSelection) values.get(this.selectionParameter); |
|
251 |
try { |
|
252 |
if ((selection != null) && !selection.isEmpty()) { |
|
253 |
Geometry geometry = (Geometry) values.get(this.geometryParameter); |
|
254 |
if (geometry != null) { |
|
255 |
// |
|
256 |
List<Point> selectedVertex = new ArrayList<Point>(); |
|
257 |
DisposableIterator it = null; |
|
258 |
|
|
259 |
try { |
|
260 |
it = selection.fastIterator(); |
|
261 |
|
|
262 |
while (it.hasNext()) { |
|
263 |
Feature feature = (Feature) it.next(); |
|
264 |
Geometry featureGeometry = feature.getDefaultGeometry(); |
|
265 |
List<Point> vertex = getSelectedVertex(featureGeometry, geometry); |
|
266 |
if(vertex != null){ |
|
267 |
selectedVertex.addAll(vertex); |
|
268 |
} |
|
269 |
} |
|
270 |
} catch (BaseException e) { |
|
271 |
throw new InvalidEntryException(e); |
|
272 |
} finally { |
|
273 |
it.dispose(); |
|
274 |
} |
|
275 |
|
|
276 |
if(!selectedVertex.isEmpty()){ |
|
277 |
for (Iterator<Point> iterator = selectedVertex.iterator(); iterator.hasNext();) { |
|
278 |
Point point = (Point) iterator.next(); |
|
279 |
drawingStatus.addStatus(point, selectedVertexEditingSymbol, ""); |
|
280 |
} |
|
281 |
} |
|
282 |
|
|
283 |
Point firstPoint = (Point) values.get(this.firstPointParameter); |
|
284 |
if (firstPoint != null){ |
|
285 |
AffineTransform at = getMoveAffineTransform(firstPoint, mousePosition); |
|
286 |
|
|
287 |
if(!selectedVertex.isEmpty()){ |
|
288 |
for (Iterator<Point> iterator = selectedVertex.iterator(); iterator.hasNext();) { |
|
289 |
Point point = (Point) ((Point) iterator.next()).cloneGeometry(); |
|
290 |
point.transform(at); |
|
291 |
drawingStatus.addStatus(point, selectedVertexEditingSymbol, ""); |
|
292 |
} |
|
293 |
} |
|
294 |
|
|
295 |
it = null; |
|
296 |
try { |
|
297 |
it = selection.fastIterator(); |
|
298 |
|
|
299 |
while (it.hasNext()) { |
|
300 |
Feature feature = (Feature) it.next(); |
|
301 |
Geometry featureGeometry = feature.getDefaultGeometry(); |
|
302 |
Geometry transformedGeometry = applyTransform(featureGeometry, at, geometry); |
|
303 |
ISymbol symbol=null; |
|
304 |
if(transformedGeometry instanceof Curve || transformedGeometry instanceof MultiCurve){ |
|
305 |
symbol = lineSymbolEditing; |
|
306 |
} else if(transformedGeometry instanceof Surface || transformedGeometry instanceof MultiSurface){ |
|
307 |
symbol = polygonSymbolEditing; |
|
308 |
} else if(transformedGeometry instanceof Point || transformedGeometry instanceof MultiPoint){ |
|
309 |
symbol = auxiliaryPointSymbolEditing; |
|
310 |
} |
|
311 |
if(transformedGeometry instanceof Aggregate){ |
|
312 |
int primitivesNumber = ((Aggregate)transformedGeometry).getPrimitivesNumber(); |
|
313 |
for (int i = 0; i < primitivesNumber; i++) { |
|
314 |
drawingStatus.addStatus(((Aggregate)transformedGeometry).getPrimitiveAt(i), symbol, ""); |
|
315 |
} |
|
316 |
} else { |
|
317 |
drawingStatus.addStatus(transformedGeometry, symbol, ""); |
|
318 |
} |
|
319 |
} |
|
320 |
} catch (BaseException e) { |
|
321 |
throw new InvalidEntryException(e); |
|
322 |
} finally { |
|
323 |
it.dispose(); |
|
324 |
} |
|
325 |
} |
|
326 |
} |
|
327 |
return drawingStatus; |
|
328 |
} |
|
329 |
} catch (Exception e) { |
|
330 |
throw new DrawServiceException(e); |
|
331 |
} |
|
332 |
return null; |
|
333 |
} |
|
334 |
|
|
335 |
private AffineTransform getMoveAffineTransform(Point p1, Point p2) { |
|
336 |
|
|
337 |
AffineTransform translate = |
|
338 |
AffineTransform.getTranslateInstance(p2.getX() - p1.getX(), |
|
339 |
p2.getY() - p1.getY()); |
|
340 |
|
|
341 |
return translate; |
|
342 |
} |
|
343 |
|
|
344 |
public void stop() { |
|
345 |
values.clear(); |
|
346 |
} |
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
public void setValue(Object value) throws InvalidEntryException { |
|
351 |
EditingServiceParameter param = next(); |
|
352 |
validateAndInsertValue(param, value); |
|
353 |
} |
|
354 |
|
|
355 |
public void finishAndStore() throws FinishServiceException { |
|
356 |
|
|
357 |
FeatureSelection selection = |
|
358 |
(FeatureSelection) values.get(selectionParameter); |
|
359 |
|
|
360 |
try { |
|
361 |
if ((selection != null) && !selection.isEmpty()) { |
|
362 |
Geometry geometry = (Geometry) values.get(this.geometryParameter); |
|
363 |
if (geometry != null) { |
|
364 |
Point firstPoint = |
|
365 |
(Point) values.get(this.firstPointParameter); |
|
366 |
if (firstPoint != null) { |
|
367 |
Point secondPoint = |
|
368 |
(Point) values.get(this.secondPointParameter); |
|
369 |
if (secondPoint != null) { |
|
370 |
AffineTransform at = |
|
371 |
getMoveAffineTransform(firstPoint, secondPoint); |
|
372 |
|
|
373 |
DisposableIterator it = null; |
|
374 |
|
|
375 |
try { |
|
376 |
it = selection.fastIterator(); |
|
377 |
|
|
378 |
while (it.hasNext()) { |
|
379 |
Feature feature = (Feature) it.next(); |
|
380 |
Geometry featureGeometry = |
|
381 |
feature.getDefaultGeometry(); |
|
382 |
|
|
383 |
Geometry geom = |
|
384 |
applyTransform(featureGeometry, at, |
|
385 |
geometry); |
|
386 |
|
|
387 |
EditableFeature editableFeature = |
|
388 |
feature.getEditable(); |
|
389 |
editableFeature.setDefaultGeometry(geom); |
|
390 |
((EditingProviderServices) getProviderServices()) |
|
391 |
.updateFeatureInFeatureStore( |
|
392 |
editableFeature, featureStore); |
|
393 |
} |
|
394 |
} catch (BaseException e) { |
|
395 |
throw new FinishServiceException(e); |
|
396 |
} finally { |
|
397 |
it.dispose(); |
|
398 |
} |
|
399 |
} |
|
400 |
} |
|
401 |
} |
|
402 |
} |
|
403 |
} catch (DataException e) { |
|
404 |
throw new FinishServiceException(e); |
|
405 |
} |
|
406 |
} |
|
407 |
|
|
408 |
public Geometry finish() throws FinishServiceException { |
|
409 |
return null; |
|
410 |
} |
|
411 |
|
|
412 |
public void start() throws StartServiceException { |
|
413 |
this.values = new HashMap<EditingServiceParameter, Object>(); |
|
414 |
FeatureSelection selected = null; |
|
415 |
if (featureStore != null) { |
|
416 |
try { |
|
417 |
selected = |
|
418 |
(FeatureSelection) featureStore.getFeatureSelection() |
|
419 |
.clone(); |
|
420 |
} catch (DataException e) { |
|
421 |
throw new StartServiceException(e); |
|
422 |
} catch (CloneNotSupportedException e) { |
|
423 |
// Do nothing |
|
424 |
} |
|
425 |
if ((selected != null) && (selected.getSelectedCount() > 0)) { |
|
426 |
values.put(selectionParameter, selected); |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 |
|
|
431 |
public String getName() { |
|
432 |
return StretchEditingProviderFactory.PROVIDER_NAME; |
|
433 |
} |
|
434 |
|
|
435 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/operation/StretchOperation.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.lib.prov.stretch.operation; |
|
2 |
|
|
3 |
import java.awt.geom.AffineTransform; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.gvsig.fmap.geom.Geometry; |
|
7 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
8 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
9 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
10 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
11 |
import org.gvsig.fmap.geom.primitive.Point; |
|
12 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
13 |
|
|
14 |
|
|
15 |
public interface StretchOperation { |
|
16 |
|
|
17 |
Geometry transform(AffineTransform at, |
|
18 |
Primitive geom, Geometry roi) throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException ; |
|
19 |
|
|
20 |
public List<Point> getSelectedVertex(Primitive geom, Geometry roi) throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException; |
|
21 |
|
|
22 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/operation/StretchOperationUtils.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.lib.prov.stretch.operation; |
|
2 |
|
|
3 |
|
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
import org.slf4j.Logger; |
|
8 |
import org.slf4j.LoggerFactory; |
|
9 |
|
|
10 |
import org.gvsig.fmap.geom.Geometry; |
|
11 |
import org.gvsig.fmap.geom.primitive.Arc; |
|
12 |
import org.gvsig.fmap.geom.primitive.Circle; |
|
13 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
14 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
|
15 |
import org.gvsig.fmap.geom.primitive.EllipticArc; |
|
16 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
|
17 |
import org.gvsig.fmap.geom.primitive.Point; |
|
18 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
19 |
import org.gvsig.fmap.geom.primitive.Spline; |
|
20 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
21 |
|
|
22 |
|
|
23 |
public class StretchOperationUtils { |
|
24 |
|
|
25 |
private static Logger logger = LoggerFactory.getLogger(StretchOperationUtils.class); |
|
26 |
|
|
27 |
private static Map<Integer, StretchOperation> operations = new HashMap<Integer, StretchOperation>(); |
|
28 |
|
|
29 |
private StretchOperationUtils() { |
|
30 |
} |
|
31 |
|
|
32 |
public static void register(StretchOperation operation, int geometryType){ |
|
33 |
operations.put(geometryType, operation); |
|
34 |
} |
|
35 |
|
|
36 |
public static StretchOperation getOperation(Primitive geom) { |
|
37 |
Integer type = geom.getGeometryType().getType(); |
|
38 |
|
|
39 |
if(isPolygon(geom)){ |
|
40 |
type = Geometry.TYPES.POLYGON; |
|
41 |
} else if(isLine(geom)){ |
|
42 |
type = Geometry.TYPES.LINE; |
|
43 |
} |
|
44 |
StretchOperation operation = operations.get(type); |
|
45 |
|
|
46 |
return operation; |
|
47 |
} |
|
48 |
|
|
49 |
private static boolean isPolygon(Geometry geometry) { |
|
50 |
|
|
51 |
if(!(geometry instanceof Surface)){ |
|
52 |
return false; |
|
53 |
} |
|
54 |
if (geometry instanceof Ellipse) { |
|
55 |
return false; |
|
56 |
} |
|
57 |
if (geometry instanceof EllipticArc) { |
|
58 |
return false; |
|
59 |
} |
|
60 |
if (geometry instanceof Circle) { |
|
61 |
return false; |
|
62 |
} |
|
63 |
return true; |
|
64 |
} |
|
65 |
|
|
66 |
private static boolean isLine(Geometry geometry) { |
|
67 |
|
|
68 |
if(!(geometry instanceof Curve)){ |
|
69 |
return false; |
|
70 |
} |
|
71 |
if (geometry instanceof Arc) { |
|
72 |
return false; |
|
73 |
} |
|
74 |
if (geometry instanceof Spline) { |
|
75 |
return false; |
|
76 |
} |
|
77 |
return true; |
|
78 |
} |
|
79 |
|
|
80 |
public static void setVertex(OrientablePrimitive geom, int index, Point p) { |
|
81 |
Point point = geom.getVertex(index); |
|
82 |
int min = p.getDimension() < point.getDimension()?p.getDimension():point.getDimension(); |
|
83 |
for(int i=0; i<min; i++){ |
|
84 |
point.setCoordinateAt(i, p.getCoordinateAt(i)); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/operation/CurveStretchOperation.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.lib.prov.stretch.operation; |
|
2 |
|
|
3 |
import java.awt.geom.AffineTransform; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.gvsig.fmap.geom.Geometry; |
|
8 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
9 |
import org.gvsig.fmap.geom.GeometryManager; |
|
10 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
11 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
12 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
13 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
14 |
import org.gvsig.fmap.geom.primitive.Line; |
|
15 |
import org.gvsig.fmap.geom.primitive.Point; |
|
16 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
17 |
|
|
18 |
|
|
19 |
public class CurveStretchOperation implements StretchOperation{ |
|
20 |
|
|
21 |
public CurveStretchOperation() { |
|
22 |
// TODO Auto-generated constructor stub |
|
23 |
} |
|
24 |
|
|
25 |
public Geometry transform(AffineTransform at, Primitive geom, Geometry roi) |
|
26 |
throws GeometryOperationNotSupportedException, |
|
27 |
GeometryOperationException, CreateGeometryException { |
|
28 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
29 |
Line line = geometryManager.createLine(geom.getGeometryType().getSubType()); |
|
30 |
line.setGeneralPath((GeneralPathX) geom.getGeneralPath().clone()); |
|
31 |
for (int j = 0; j < line.getNumVertices(); j++) { |
|
32 |
Point point = line.getVertex(j); |
|
33 |
if (roi.intersects(point) || roi.contains(point)) { |
|
34 |
point.transform(at); |
|
35 |
StretchOperationUtils.setVertex(line, j, point); |
|
36 |
} |
|
37 |
} |
|
38 |
return line; |
|
39 |
} |
|
40 |
|
|
41 |
public List<Point> getSelectedVertex(Primitive geom, Geometry roi) throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException { |
|
42 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
43 |
List<Point> vertexList = new ArrayList<Point>(); |
|
44 |
Line line = geometryManager.createLine(geom.getGeometryType().getSubType()); |
|
45 |
line.setGeneralPath(geom.getGeneralPath()); |
|
46 |
for (int j = 0; j < line.getNumVertices(); j++) { |
|
47 |
Point point = line.getVertex(j); |
|
48 |
if (roi.intersects(point) || roi.contains(point)) { |
|
49 |
vertexList.add(point); |
|
50 |
} |
|
51 |
} |
|
52 |
return vertexList; |
|
53 |
} |
|
54 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/operation/LineStretchOperation.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.lib.prov.stretch.operation; |
|
2 |
|
|
3 |
import java.awt.geom.AffineTransform; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.gvsig.fmap.geom.Geometry; |
|
8 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
9 |
import org.gvsig.fmap.geom.GeometryManager; |
|
10 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
11 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
12 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
13 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
14 |
import org.gvsig.fmap.geom.primitive.Line; |
|
15 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
|
16 |
import org.gvsig.fmap.geom.primitive.Point; |
|
17 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
18 |
|
|
19 |
|
|
20 |
public class LineStretchOperation implements StretchOperation{ |
|
21 |
|
|
22 |
public LineStretchOperation() { |
|
23 |
// TODO Auto-generated constructor stub |
|
24 |
} |
|
25 |
|
|
26 |
public Geometry transform(AffineTransform at, Primitive geom, Geometry roi) |
|
27 |
throws GeometryOperationNotSupportedException, |
|
28 |
GeometryOperationException { |
|
29 |
OrientablePrimitive primitive = (OrientablePrimitive)(geom.cloneGeometry()); |
|
30 |
for (int j = 0; j < primitive.getNumVertices(); j++) { |
|
31 |
Point point = primitive.getVertex(j); |
|
32 |
if (roi.intersects(point) || roi.contains(point)) { |
|
33 |
point.transform(at); |
|
34 |
StretchOperationUtils.setVertex(primitive, j, point); |
|
35 |
|
|
36 |
} |
|
37 |
} |
|
38 |
return primitive; |
|
39 |
} |
|
40 |
|
|
41 |
public List<Point> getSelectedVertex(Primitive geom, Geometry roi) |
|
42 |
throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException { |
|
43 |
OrientablePrimitive primitive = (OrientablePrimitive)(geom.cloneGeometry()); |
|
44 |
List<Point> vertexList = new ArrayList<Point>(); |
|
45 |
for (int j = 0; j < primitive.getNumVertices(); j++) { |
|
46 |
Point point = primitive.getVertex(j); |
|
47 |
if (roi.intersects(point) || roi.contains(point)) { |
|
48 |
vertexList.add(point); |
|
49 |
} |
|
50 |
} |
|
51 |
return vertexList; |
|
52 |
} |
|
53 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/operation/PolygonStretchOperation.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.lib.prov.stretch.operation; |
|
2 |
|
|
3 |
import java.awt.geom.AffineTransform; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.gvsig.fmap.geom.Geometry; |
|
8 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
9 |
import org.gvsig.fmap.geom.GeometryManager; |
|
10 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
11 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
12 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
13 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
14 |
import org.gvsig.fmap.geom.primitive.Line; |
|
15 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
|
16 |
import org.gvsig.fmap.geom.primitive.Point; |
|
17 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
18 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
19 |
|
|
20 |
|
|
21 |
public class PolygonStretchOperation implements StretchOperation{ |
|
22 |
|
|
23 |
public PolygonStretchOperation() { |
|
24 |
// TODO Auto-generated constructor stub |
|
25 |
} |
|
26 |
|
|
27 |
public Geometry transform(AffineTransform at, Primitive geom, Geometry roi) |
|
28 |
throws GeometryOperationNotSupportedException, |
|
29 |
GeometryOperationException { |
|
30 |
OrientablePrimitive primitive = (OrientablePrimitive)(geom.cloneGeometry()); |
|
31 |
for (int j = 0; j < primitive.getNumVertices(); j++) { |
|
32 |
Point point = primitive.getVertex(j); |
|
33 |
if (roi.intersects(point) || roi.contains(point)) { |
|
34 |
point.transform(at); |
|
35 |
StretchOperationUtils.setVertex(primitive, j, point); |
|
36 |
} |
|
37 |
} |
|
38 |
return primitive; |
|
39 |
} |
|
40 |
|
|
41 |
public List<Point> getSelectedVertex(Primitive geom, Geometry roi) |
|
42 |
throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException { |
|
43 |
OrientablePrimitive primitive = (OrientablePrimitive)(geom.cloneGeometry()); |
|
44 |
List<Point> vertexList = new ArrayList<Point>(); |
|
45 |
for (int j = 0; j < primitive.getNumVertices(); j++) { |
|
46 |
Point point = primitive.getVertex(j); |
|
47 |
if (roi.intersects(point) || roi.contains(point)) { |
|
48 |
vertexList.add(point); |
|
49 |
} |
|
50 |
} |
|
51 |
return vertexList; |
|
52 |
} |
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.84/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.stretch/src/main/java/org/gvsig/vectorediting/lib/prov/stretch/operation/SurfaceStretchOperation.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.lib.prov.stretch.operation; |
|
2 |
|
|
3 |
import java.awt.geom.AffineTransform; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.gvsig.fmap.geom.Geometry; |
|
8 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
9 |
import org.gvsig.fmap.geom.GeometryManager; |
|
10 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
11 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
12 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
13 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
14 |
import org.gvsig.fmap.geom.primitive.Point; |
|
15 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
16 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
17 |
|
|
18 |
|
|
19 |
public class SurfaceStretchOperation implements StretchOperation{ |
Also available in: Unified diff