Revision 37138 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/InternalPolygonCADTool.java
InternalPolygonCADTool.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
|
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
|
2 | 2 |
* |
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
5 | 6 |
* This program is free software; you can redistribute it and/or |
6 | 7 |
* modify it under the terms of the GNU General Public License |
7 | 8 |
* as published by the Free Software Foundation; either version 2 |
8 | 9 |
* of the License, or (at your option) any later version. |
9 |
* |
|
10 |
*
|
|
10 | 11 |
* This program is distributed in the hope that it will be useful, |
11 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | 14 |
* GNU General Public License for more details. |
14 |
* |
|
15 |
*
|
|
15 | 16 |
* You should have received a copy of the GNU General Public License |
16 | 17 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
40 | 21 |
*/ |
41 | 22 |
package org.gvsig.editing.gui.cad.tools; |
42 | 23 |
|
... | ... | |
44 | 25 |
import java.awt.event.InputEvent; |
45 | 26 |
import java.awt.event.MouseEvent; |
46 | 27 |
import java.awt.geom.PathIterator; |
47 |
import java.awt.geom.Point2D; |
|
48 | 28 |
import java.util.ArrayList; |
49 | 29 |
import java.util.List; |
50 | 30 |
|
... | ... | |
68 | 48 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
69 | 49 |
import org.gvsig.fmap.geom.Geometry; |
70 | 50 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
71 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
72 |
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive; |
|
73 | 51 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
74 | 52 |
import org.gvsig.fmap.geom.primitive.Point; |
75 | 53 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
76 | 54 |
import org.gvsig.tools.dispose.DisposableIterator; |
77 | 55 |
import org.gvsig.tools.dispose.DisposeUtils; |
78 | 56 |
|
79 |
|
|
80 | 57 |
/** |
81 | 58 |
* DOCUMENT ME! |
82 |
* |
|
59 |
*
|
|
83 | 60 |
* @author Vicente Caballero Navarro |
84 | 61 |
*/ |
85 | 62 |
public class InternalPolygonCADTool extends DefaultCADTool { |
86 |
protected InternalPolygonCADToolContext _fsm; |
|
87 |
protected List<Point> points = new ArrayList<Point>(); |
|
88 |
protected Geometry geometry = null; |
|
89 | 63 |
|
90 |
/** |
|
91 |
* Crea un nuevo PolylineCADTool. |
|
92 |
*/ |
|
93 |
public InternalPolygonCADTool() { |
|
94 |
} |
|
64 |
protected InternalPolygonCADToolContext _fsm; |
|
65 |
protected List<Point> points = new ArrayList<Point>(); |
|
66 |
protected Geometry geometry = null; |
|
95 | 67 |
|
96 |
/** |
|
97 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una |
|
98 |
* carga previa a la utilizaci?n de la herramienta. |
|
99 |
*/ |
|
100 |
public void init() { |
|
101 |
_fsm = new InternalPolygonCADToolContext(this); |
|
102 |
points.clear(); |
|
103 |
} |
|
68 |
/** |
|
69 |
* Crea un nuevo PolylineCADTool. |
|
70 |
*/ |
|
71 |
public InternalPolygonCADTool() { |
|
72 |
} |
|
104 | 73 |
|
105 |
/* (non-Javadoc) |
|
106 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double) |
|
107 |
*/ |
|
108 |
public void transition(double x, double y, InputEvent event) { |
|
109 |
_fsm.addPoint(x, y, event); |
|
110 |
} |
|
74 |
/** |
|
75 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una |
|
76 |
* carga previa a la utilizaci?n de la herramienta. |
|
77 |
*/ |
|
78 |
public void init() { |
|
79 |
_fsm = new InternalPolygonCADToolContext(this); |
|
80 |
points.clear(); |
|
81 |
} |
|
111 | 82 |
|
112 |
/* (non-Javadoc) |
|
113 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double) |
|
114 |
*/ |
|
115 |
public void transition(double d) { |
|
116 |
_fsm.addValue(d); |
|
117 |
} |
|
83 |
/* |
|
84 |
* (non-Javadoc) |
|
85 |
* |
|
86 |
* @see |
|
87 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
88 |
* .layers.FBitSet, double, double) |
|
89 |
*/ |
|
90 |
public void transition(double x, double y, InputEvent event) { |
|
91 |
_fsm.addPoint(x, y, event); |
|
92 |
} |
|
118 | 93 |
|
119 |
/* (non-Javadoc) |
|
120 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String) |
|
121 |
*/ |
|
122 |
public void transition(String s) throws CommandException { |
|
123 |
if (!super.changeCommand(s)){ |
|
124 |
_fsm.addOption(s); |
|
125 |
} |
|
126 |
} |
|
94 |
/* |
|
95 |
* (non-Javadoc) |
|
96 |
* |
|
97 |
* @see |
|
98 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
99 |
* .layers.FBitSet, double) |
|
100 |
*/ |
|
101 |
public void transition(double d) { |
|
102 |
_fsm.addValue(d); |
|
103 |
} |
|
127 | 104 |
|
128 |
/** |
|
129 |
* DOCUMENT ME! |
|
130 |
*/ |
|
131 |
public void selection() { |
|
132 |
FeatureSet selection=null; |
|
133 |
try { |
|
134 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
|
105 |
/* |
|
106 |
* (non-Javadoc) |
|
107 |
* |
|
108 |
* @see |
|
109 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
110 |
* .layers.FBitSet, java.lang.String) |
|
111 |
*/ |
|
112 |
public void transition(String s) throws CommandException { |
|
113 |
if (!super.changeCommand(s)) { |
|
114 |
_fsm.addOption(s); |
|
115 |
} |
|
116 |
} |
|
135 | 117 |
|
136 |
if (selection.getSize() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
137 |
CADExtension.setCADTool("_selection",false); |
|
138 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
|
139 |
"_internalpolygon"); |
|
140 |
} |
|
141 |
} catch (ReadException e) { |
|
142 |
// TODO Auto-generated catch block |
|
143 |
e.printStackTrace(); |
|
144 |
} catch (DataException e) { |
|
145 |
// TODO Auto-generated catch block |
|
146 |
e.printStackTrace(); |
|
147 |
} |
|
148 |
} |
|
118 |
/** |
|
119 |
* DOCUMENT ME! |
|
120 |
*/ |
|
121 |
public void selection() { |
|
122 |
FeatureSet selection = null; |
|
123 |
try { |
|
124 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
|
149 | 125 |
|
150 |
/** |
|
151 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el |
|
152 |
* editableFeatureSource que ya estar? creado. |
|
153 |
* |
|
154 |
* @param x par?metro x del punto que se pase en esta transici?n. |
|
155 |
* @param y par?metro y del punto que se pase en esta transici?n. |
|
156 |
*/ |
|
157 |
public void addPoint(double x, double y,InputEvent event) { |
|
158 |
if (((MouseEvent)event).getClickCount()==2){ |
|
159 |
addOption(PluginServices.getText(this,"InternalPolygonCADTool.end")); |
|
160 |
return; |
|
161 |
} |
|
162 |
VectorialLayerEdited vle=getVLE(); |
|
163 |
FeatureSet featureCollection=null; |
|
164 |
DisposableIterator iterator = null; |
|
165 |
try { |
|
166 |
featureCollection = (FeatureSet)vle.getFeatureStore().getSelection(); |
|
167 |
if (featureCollection.getSize()==1){ |
|
168 |
iterator = featureCollection.iterator(); |
|
169 |
Feature feature = (Feature) iterator.next(); |
|
170 |
geometry=(feature.getDefaultGeometry()).cloneGeometry(); |
|
171 |
if (geometry.contains(x,y)){ |
|
172 |
points.add(createPoint(x, y)); |
|
173 |
}else{ |
|
174 |
JOptionPane.showMessageDialog(((Component)PluginServices.getMainFrame()),PluginServices.getText(this,"debe_insertar_el_punto_dentro_de_los_limites_de_la_geometria")); |
|
175 |
} |
|
176 |
} |
|
177 |
} catch (ReadException e) { |
|
178 |
NotificationManager.addError(e.getMessage(),e); |
|
179 |
} catch (DataException e) { |
|
180 |
NotificationManager.addError(e.getMessage(),e); |
|
181 |
} finally { |
|
182 |
DisposeUtils.dispose(iterator); |
|
183 |
} |
|
184 |
} |
|
126 |
if (selection.getSize() == 0 |
|
127 |
&& !CADExtension |
|
128 |
.getCADTool() |
|
129 |
.getClass() |
|
130 |
.getName() |
|
131 |
.equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
132 |
CADExtension.setCADTool("_selection", false); |
|
133 |
((SelectionCADTool) CADExtension.getCADTool()) |
|
134 |
.setNextTool("_internalpolygon"); |
|
135 |
} |
|
136 |
} catch (ReadException e) { |
|
137 |
// TODO Auto-generated catch block |
|
138 |
e.printStackTrace(); |
|
139 |
} catch (DataException e) { |
|
140 |
// TODO Auto-generated catch block |
|
141 |
e.printStackTrace(); |
|
142 |
} |
|
143 |
} |
|
185 | 144 |
|
186 |
/** |
|
187 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
|
188 |
* encontremos. |
|
189 |
* |
|
190 |
* @param g Graphics sobre el que dibujar. |
|
191 |
* @param x par?metro x del punto que se pase para dibujar. |
|
192 |
* @param y par?metro x del punto que se pase para dibujar. |
|
193 |
*/ |
|
194 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
|
195 |
GeneralPathX gpx = new GeneralPathX(); |
|
196 |
GeneralPathX gpx1 = new GeneralPathX(); |
|
145 |
/** |
|
146 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el |
|
147 |
* editableFeatureSource que ya estar? creado. |
|
148 |
* |
|
149 |
* @param x |
|
150 |
* par?metro x del punto que se pase en esta transici?n. |
|
151 |
* @param y |
|
152 |
* par?metro y del punto que se pase en esta transici?n. |
|
153 |
*/ |
|
154 |
public void addPoint(double x, double y, InputEvent event) { |
|
155 |
if (((MouseEvent) event).getClickCount() == 2) { |
|
156 |
addOption(PluginServices |
|
157 |
.getText(this, "InternalPolygonCADTool.end")); |
|
158 |
return; |
|
159 |
} |
|
160 |
VectorialLayerEdited vle = getVLE(); |
|
161 |
FeatureSet featureCollection = null; |
|
162 |
DisposableIterator iterator = null; |
|
163 |
try { |
|
164 |
featureCollection = |
|
165 |
(FeatureSet) vle.getFeatureStore().getSelection(); |
|
166 |
if (featureCollection.getSize() == 1) { |
|
167 |
iterator = featureCollection.iterator(); |
|
168 |
Feature feature = (Feature) iterator.next(); |
|
169 |
geometry = (feature.getDefaultGeometry()).cloneGeometry(); |
|
170 |
if (geometry.contains(x, y)) { |
|
171 |
points.add(createPoint(x, y)); |
|
172 |
} else { |
|
173 |
JOptionPane |
|
174 |
.showMessageDialog( |
|
175 |
((Component) PluginServices.getMainFrame()), |
|
176 |
PluginServices |
|
177 |
.getText(this, |
|
178 |
"debe_insertar_el_punto_dentro_de_los_limites_de_la_geometria")); |
|
179 |
} |
|
180 |
} |
|
181 |
} catch (ReadException e) { |
|
182 |
NotificationManager.addError(e.getMessage(), e); |
|
183 |
} catch (DataException e) { |
|
184 |
NotificationManager.addError(e.getMessage(), e); |
|
185 |
} finally { |
|
186 |
DisposeUtils.dispose(iterator); |
|
187 |
} |
|
188 |
} |
|
197 | 189 |
|
198 |
if (points.size()>0){ |
|
199 |
for (int i=0 ; i<points.size() ; i++){ |
|
200 |
if (i==0){ |
|
201 |
gpx.moveTo(points.get(i)); |
|
202 |
gpx1.moveTo(points.get(i)); |
|
203 |
}else{ |
|
204 |
gpx.lineTo(points.get(i)); |
|
205 |
gpx1.lineTo(points.get(i)); |
|
206 |
} |
|
190 |
/** |
|
191 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
|
192 |
* encontremos. |
|
193 |
* |
|
194 |
* @param g |
|
195 |
* Graphics sobre el que dibujar. |
|
196 |
* @param x |
|
197 |
* par?metro x del punto que se pase para dibujar. |
|
198 |
* @param y |
|
199 |
* par?metro x del punto que se pase para dibujar. |
|
200 |
*/ |
|
201 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
|
202 |
GeneralPathX gpx = new GeneralPathX(); |
|
203 |
GeneralPathX gpx1 = new GeneralPathX(); |
|
207 | 204 |
|
208 |
} |
|
209 |
gpx.lineTo(createPoint(x,y)); |
|
210 |
gpx.closePath(); |
|
211 |
gpx1.closePath(); |
|
205 |
if (points.size() > 0) { |
|
206 |
for (int i = 0; i < points.size(); i++) { |
|
207 |
if (i == 0) { |
|
208 |
gpx.moveTo(points.get(i)); |
|
209 |
gpx1.moveTo(points.get(i)); |
|
210 |
} else { |
|
211 |
gpx.lineTo(points.get(i)); |
|
212 |
gpx1.lineTo(points.get(i)); |
|
213 |
} |
|
212 | 214 |
|
213 |
Geometry geom = createSurface(gpx); |
|
214 |
Geometry geom1 = createSurface(gpx1); |
|
215 |
} |
|
216 |
gpx.lineTo(createPoint(x, y)); |
|
217 |
gpx.closePath(); |
|
218 |
gpx1.closePath(); |
|
215 | 219 |
|
216 |
renderer.draw(geom1, mapControlManager.getSelectionSymbol()); |
|
217 |
renderer.draw(geom,mapControlManager.getGeometrySelectionSymbol()); |
|
218 |
} |
|
219 |
} |
|
220 |
Geometry geom = createSurface(gpx); |
|
221 |
Geometry geom1 = createSurface(gpx1); |
|
220 | 222 |
|
221 |
/** |
|
222 |
* Add a diferent option. |
|
223 |
* |
|
224 |
* @param s Diferent option. |
|
225 |
*/ |
|
226 |
public void addOption(String s) { |
|
227 |
VectorialLayerEdited vle=getVLE(); |
|
228 |
FeatureStore featureStore=null; |
|
229 |
try { |
|
230 |
featureStore = vle.getFeatureStore(); |
|
231 |
} catch (ReadException e1) { |
|
232 |
// TODO Auto-generated catch block |
|
233 |
e1.printStackTrace(); |
|
234 |
} |
|
235 |
DisposableIterator iterator = null; |
|
236 |
try { |
|
237 |
iterator = ((FeatureSelection) featureStore.getSelection()) |
|
238 |
.iterator(); |
|
239 |
if (s.equals(PluginServices.getText(this, "end")) |
|
240 |
|| s.equalsIgnoreCase(PluginServices.getText(this, |
|
241 |
"InternalPolygonCADTool.end"))) { |
|
242 |
if (points.size() > 0) { |
|
243 |
Feature feature = (Feature) iterator.next(); |
|
244 |
geometry = (feature.getDefaultGeometry()).cloneGeometry(); |
|
245 |
if (geometry instanceof GeometryCollection) { |
|
246 |
MultiPrimitive gc = (MultiPrimitive) geometry; |
|
247 |
geometry = createNewPolygonGC(gc, points); |
|
248 |
} else { |
|
249 |
geometry = createNewPolygon(geometry, points); |
|
250 |
} |
|
251 |
try { |
|
252 |
EditableFeature eFeature = feature.getEditable(); |
|
253 |
eFeature.setGeometry(featureStore |
|
254 |
.getDefaultFeatureType() |
|
255 |
.getDefaultGeometryAttributeName(), geometry); |
|
256 |
featureStore.update(eFeature); |
|
257 |
} catch (ReadException e) { |
|
258 |
NotificationManager.addError(e.getMessage(), e); |
|
259 |
} catch (DataException e) { |
|
260 |
NotificationManager.addError(e.getMessage(), e); |
|
261 |
} |
|
262 |
ArrayList rows = new ArrayList(); |
|
263 |
rows.add(feature); |
|
264 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, |
|
265 |
// rows); |
|
266 |
} |
|
267 |
points.clear(); |
|
268 |
refresh(); |
|
223 |
renderer.draw(geom1, mapControlManager.getSelectionSymbol()); |
|
224 |
renderer.draw(geom, mapControlManager.getGeometrySelectionSymbol()); |
|
225 |
} |
|
226 |
} |
|
269 | 227 |
|
270 |
} else if (s.equals(PluginServices.getText(this, "cancel"))) { |
|
271 |
points.clear(); |
|
272 |
} |
|
273 |
} catch (DataException e1) { |
|
274 |
e1.printStackTrace(); |
|
275 |
} finally { |
|
276 |
if (iterator != null) { |
|
277 |
iterator.dispose(); |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
/* (non-Javadoc) |
|
282 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
|
283 |
*/ |
|
284 |
public void addValue(double d) { |
|
285 |
} |
|
286 |
private Geometry createNewPolygon(Geometry geometry, List<Point> points) { |
|
287 |
GeneralPathX newGp = new GeneralPathX(); |
|
288 |
double[] theData = new double[6]; |
|
228 |
/** |
|
229 |
* Add a diferent option. |
|
230 |
* |
|
231 |
* @param s |
|
232 |
* Diferent option. |
|
233 |
*/ |
|
234 |
public void addOption(String s) { |
|
235 |
VectorialLayerEdited vle = getVLE(); |
|
236 |
FeatureStore featureStore = null; |
|
237 |
try { |
|
238 |
featureStore = vle.getFeatureStore(); |
|
239 |
} catch (ReadException e1) { |
|
240 |
// TODO Auto-generated catch block |
|
241 |
e1.printStackTrace(); |
|
242 |
} |
|
243 |
DisposableIterator iterator = null; |
|
244 |
try { |
|
245 |
iterator = |
|
246 |
((FeatureSelection) featureStore.getSelection()).iterator(); |
|
247 |
if (s.equals(PluginServices.getText(this, "end")) |
|
248 |
|| s.equalsIgnoreCase(PluginServices.getText(this, |
|
249 |
"InternalPolygonCADTool.end"))) { |
|
250 |
if (points.size() > 0) { |
|
251 |
Feature feature = (Feature) iterator.next(); |
|
252 |
geometry = (feature.getDefaultGeometry()).cloneGeometry(); |
|
253 |
if (geometry instanceof GeometryCollection) { |
|
254 |
MultiPrimitive gc = (MultiPrimitive) geometry; |
|
255 |
geometry = createNewPolygonGC(gc, points); |
|
256 |
} else { |
|
257 |
geometry = createNewPolygon(geometry, points); |
|
258 |
} |
|
259 |
try { |
|
260 |
EditableFeature eFeature = feature.getEditable(); |
|
261 |
eFeature.setGeometry(featureStore |
|
262 |
.getDefaultFeatureType() |
|
263 |
.getDefaultGeometryAttributeName(), geometry); |
|
264 |
featureStore.update(eFeature); |
|
265 |
} catch (ReadException e) { |
|
266 |
NotificationManager.addError(e.getMessage(), e); |
|
267 |
} catch (DataException e) { |
|
268 |
NotificationManager.addError(e.getMessage(), e); |
|
269 |
} |
|
270 |
ArrayList rows = new ArrayList(); |
|
271 |
rows.add(feature); |
|
272 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, |
|
273 |
// rows); |
|
274 |
} |
|
275 |
points.clear(); |
|
276 |
refresh(); |
|
289 | 277 |
|
290 |
PathIterator theIterator; |
|
291 |
int theType; |
|
292 |
int numParts = 0; |
|
278 |
} else |
|
279 |
if (s.equals(PluginServices.getText(this, "cancel"))) { |
|
280 |
points.clear(); |
|
281 |
} |
|
282 |
} catch (DataException e1) { |
|
283 |
e1.printStackTrace(); |
|
284 |
} finally { |
|
285 |
if (iterator != null) { |
|
286 |
iterator.dispose(); |
|
287 |
} |
|
288 |
} |
|
289 |
} |
|
293 | 290 |
|
294 |
theIterator = geometry.getPathIterator(null, geomManager.getFlatness()); |
|
295 |
while (!theIterator.isDone()) { |
|
296 |
theType = theIterator.currentSegment(theData); |
|
297 |
switch (theType) { |
|
291 |
/* |
|
292 |
* (non-Javadoc) |
|
293 |
* |
|
294 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
|
295 |
*/ |
|
296 |
public void addValue(double d) { |
|
297 |
} |
|
298 | 298 |
|
299 |
case PathIterator.SEG_MOVETO: |
|
300 |
numParts++; |
|
301 |
newGp.moveTo(theData[0], theData[1]); |
|
302 |
break; |
|
299 |
private Geometry createNewPolygon(Geometry geometry, List<Point> points) { |
|
300 |
GeneralPathX newGp = new GeneralPathX(); |
|
301 |
double[] theData = new double[6]; |
|
303 | 302 |
|
304 |
case PathIterator.SEG_LINETO:
|
|
305 |
newGp.lineTo(theData[0], theData[1]);
|
|
306 |
break;
|
|
303 |
PathIterator theIterator;
|
|
304 |
int theType;
|
|
305 |
int numParts = 0;
|
|
307 | 306 |
|
308 |
case PathIterator.SEG_QUADTO: |
|
309 |
newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
|
310 |
break; |
|
307 |
theIterator = geometry.getPathIterator(null, geomManager.getFlatness()); |
|
308 |
while (!theIterator.isDone()) { |
|
309 |
theType = theIterator.currentSegment(theData); |
|
310 |
switch (theType) { |
|
311 | 311 |
|
312 |
case PathIterator.SEG_CUBICTO: |
|
313 |
newGp.curveTo(theData[0], theData[1], theData[2], theData[3], theData[4], theData[5]); |
|
314 |
break; |
|
312 |
case PathIterator.SEG_MOVETO: |
|
313 |
numParts++; |
|
314 |
newGp.moveTo(theData[0], theData[1]); |
|
315 |
break; |
|
315 | 316 |
|
316 |
case PathIterator.SEG_CLOSE: |
|
317 |
newGp.closePath(); |
|
318 |
break; |
|
319 |
} //end switch |
|
317 |
case PathIterator.SEG_LINETO: |
|
318 |
newGp.lineTo(theData[0], theData[1]); |
|
319 |
break; |
|
320 | 320 |
|
321 |
theIterator.next(); |
|
322 |
} //end while loop |
|
323 |
GeneralPathX gpxInternal=new GeneralPathX(); |
|
324 |
gpxInternal.moveTo(points.get(points.size()-1)); |
|
325 |
for (int i=points.size()-2 ; i>=0 ; i--){ |
|
326 |
gpxInternal.lineTo(points.get(i)); |
|
327 |
} |
|
328 |
gpxInternal.closePath(); |
|
329 |
|
|
330 |
if (!gpxInternal.isCCW()) { |
|
331 |
gpxInternal.flip(); |
|
332 |
} |
|
333 |
newGp.append(gpxInternal.getPathIterator(null),false); |
|
321 |
case PathIterator.SEG_QUADTO: |
|
322 |
newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
|
323 |
break; |
|
334 | 324 |
|
335 |
return createSurface(newGp); |
|
336 |
} |
|
337 |
|
|
338 |
private Geometry createNewPolygonGC(MultiPrimitive multiPrimitive, List<Point> points) { |
|
339 |
MultiPrimitive multiPrimitiveAux = createMultiPrimitive(); |
|
340 |
|
|
341 |
for (int i = 0 ; i<multiPrimitive.getPrimitivesNumber() ; i++) { |
|
342 |
multiPrimitiveAux.addPrimitive(multiPrimitive.getPrimitiveAt(i)); |
|
343 |
} |
|
344 |
|
|
345 |
GeneralPathX gpx=new GeneralPathX(); |
|
346 |
gpx.moveTo(points.get(points.size()-1)); |
|
347 |
for (int i=points.size()-2 ; i>=0 ; i--){ |
|
348 |
gpx.lineTo(points.get(i)); |
|
349 |
multiPrimitiveAux.addPrimitive(createCurve(gpx)); |
|
350 |
gpx = new GeneralPathX(); |
|
351 |
gpx.moveTo(points.get(i)); |
|
352 |
} |
|
353 |
gpx.closePath(); |
|
354 |
multiPrimitiveAux.addPrimitive(createCurve(gpx)); |
|
355 |
|
|
356 |
return multiPrimitiveAux; |
|
357 |
} |
|
358 |
|
|
359 |
public String getName() { |
|
360 |
return PluginServices.getText(this,"internal_polygon_"); |
|
361 |
} |
|
325 |
case PathIterator.SEG_CUBICTO: |
|
326 |
newGp.curveTo(theData[0], theData[1], theData[2], theData[3], |
|
327 |
theData[4], theData[5]); |
|
328 |
break; |
|
362 | 329 |
|
363 |
public String toString() { |
|
364 |
return "_internalpolygon"; |
|
365 |
} |
|
330 |
case PathIterator.SEG_CLOSE: |
|
331 |
newGp.closePath(); |
|
332 |
break; |
|
333 |
} // end switch |
|
366 | 334 |
|
367 |
public boolean isApplicable(int shapeType) { |
|
368 |
switch (shapeType) { |
|
369 |
case Geometry.TYPES.POINT: |
|
370 |
case Geometry.TYPES.CURVE: |
|
371 |
case Geometry.TYPES.MULTIPOINT: |
|
372 |
return false; |
|
373 |
} |
|
374 |
return true; |
|
375 |
} |
|
335 |
theIterator.next(); |
|
336 |
} // end while loop |
|
337 |
GeneralPathX gpxInternal = new GeneralPathX(); |
|
338 |
gpxInternal.moveTo(points.get(points.size() - 1)); |
|
339 |
for (int i = points.size() - 2; i >= 0; i--) { |
|
340 |
gpxInternal.lineTo(points.get(i)); |
|
341 |
} |
|
342 |
gpxInternal.closePath(); |
|
343 |
|
|
344 |
if (!gpxInternal.isCCW()) { |
|
345 |
gpxInternal.flip(); |
|
346 |
} |
|
347 |
newGp.append(gpxInternal.getPathIterator(null), false); |
|
348 |
|
|
349 |
return createSurface(newGp); |
|
350 |
} |
|
351 |
|
|
352 |
private Geometry createNewPolygonGC(MultiPrimitive multiPrimitive, |
|
353 |
List<Point> points) { |
|
354 |
MultiPrimitive multiPrimitiveAux = createMultiPrimitive(); |
|
355 |
|
|
356 |
for (int i = 0; i < multiPrimitive.getPrimitivesNumber(); i++) { |
|
357 |
multiPrimitiveAux.addPrimitive(multiPrimitive.getPrimitiveAt(i)); |
|
358 |
} |
|
359 |
|
|
360 |
GeneralPathX gpx = new GeneralPathX(); |
|
361 |
gpx.moveTo(points.get(points.size() - 1)); |
|
362 |
for (int i = points.size() - 2; i >= 0; i--) { |
|
363 |
gpx.lineTo(points.get(i)); |
|
364 |
multiPrimitiveAux.addPrimitive(createCurve(gpx)); |
|
365 |
gpx = new GeneralPathX(); |
|
366 |
gpx.moveTo(points.get(i)); |
|
367 |
} |
|
368 |
gpx.closePath(); |
|
369 |
multiPrimitiveAux.addPrimitive(createCurve(gpx)); |
|
370 |
|
|
371 |
return multiPrimitiveAux; |
|
372 |
} |
|
373 |
|
|
374 |
public String getName() { |
|
375 |
return PluginServices.getText(this, "internal_polygon_"); |
|
376 |
} |
|
377 |
|
|
378 |
public String toString() { |
|
379 |
return "_internalpolygon"; |
|
380 |
} |
|
381 |
|
|
382 |
public boolean isApplicable(int shapeType) { |
|
383 |
switch (shapeType) { |
|
384 |
case Geometry.TYPES.POINT: |
|
385 |
case Geometry.TYPES.CURVE: |
|
386 |
case Geometry.TYPES.MULTIPOINT: |
|
387 |
return false; |
|
388 |
} |
|
389 |
return true; |
|
390 |
} |
|
376 | 391 |
} |
Also available in: Unified diff