Revision 4523
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/VectorialEditableAdapter.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.35 2006-02-28 18:15:22 fjp |
|
48 |
* Revision 1.36 2006-03-22 11:46:29 caballero |
|
49 |
* Editar capa de anotaciones |
|
50 |
* |
|
51 |
* Revision 1.35 2006/02/28 18:15:22 fjp |
|
49 | 52 |
* Consola de CAD |
50 | 53 |
* |
51 | 54 |
* Revision 1.34 2006/02/24 11:30:32 fjp |
... | ... | |
176 | 179 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
177 | 180 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
178 | 181 |
import com.vividsolutions.jts.geom.Envelope; |
182 |
import com.vividsolutions.jts.index.SpatialIndex; |
|
179 | 183 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
180 | 184 |
|
181 | 185 |
/** |
... | ... | |
186 | 190 |
protected VectorialAdapter ova; |
187 | 191 |
//private VectorialDriver driver; |
188 | 192 |
protected Quadtree index; |
189 |
|
|
193 |
|
|
190 | 194 |
protected Rectangle2D fullExtent; |
191 |
|
|
192 |
|
|
195 |
//private SpatialIndex spatialIndex; |
|
196 |
|
|
197 |
|
|
193 | 198 |
/* private class MyFeatureIterator implements IFeatureIterator |
194 | 199 |
{ |
195 | 200 |
int numReg = 0; |
... | ... | |
197 | 202 |
String epsg; |
198 | 203 |
IFeatureIterator origFeatIt; |
199 | 204 |
boolean bHasNext = true; |
200 |
|
|
205 |
|
|
201 | 206 |
public MyFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException |
202 | 207 |
{ |
203 | 208 |
rect = r; |
... | ... | |
214 | 219 |
} |
215 | 220 |
|
216 | 221 |
public void closeIterator() throws DriverException { |
217 |
|
|
222 |
|
|
218 | 223 |
} |
219 |
|
|
224 |
|
|
220 | 225 |
} */ |
221 |
|
|
226 |
|
|
222 | 227 |
public VectorialEditableAdapter(){ |
223 | 228 |
super(); |
224 | 229 |
} |
... | ... | |
306 | 311 |
* @throws EditionException DOCUMENT ME! |
307 | 312 |
*/ |
308 | 313 |
public void startEdition() throws EditionException { |
309 |
super.startEdition();
|
|
314 |
isEditing = true;
|
|
310 | 315 |
|
311 | 316 |
try { |
312 | 317 |
expansionFile.open(); |
313 |
|
|
318 |
if (index==null || fullExtent==null){ |
|
314 | 319 |
// TODO: Si la capa dispone de un ?ndice espacial, hacer |
315 | 320 |
// algo aqu? para que se use ese ?ndice espacial. |
316 | 321 |
index = new Quadtree(); |
... | ... | |
341 | 346 |
fullExtent = fullExtent.createUnion(r); |
342 | 347 |
} |
343 | 348 |
} |
349 |
} |
|
344 | 350 |
} catch (DriverIOException e) { |
345 | 351 |
throw new EditionException(e); |
346 | 352 |
} catch (IOException e) { |
... | ... | |
358 | 364 |
int calculatedIndex=getCalculatedIndex(index); |
359 | 365 |
Integer integer = new Integer(calculatedIndex); |
360 | 366 |
//Si no est? en el fichero de expansi?n |
361 |
DefaultRowEdited edRow=null;
|
|
367 |
DefaultRowEdited edRow=null; |
|
362 | 368 |
if (!relations.containsKey(integer)) { |
363 | 369 |
try { |
364 | 370 |
edRow = new DefaultRowEdited(ova.getFeature(calculatedIndex), |
... | ... | |
378 | 384 |
edRow = new DefaultRowEdited(aux.getLinkedRow().cloneRow(), aux.getStatus(), index); |
379 | 385 |
return edRow; |
380 | 386 |
} |
381 |
}
|
|
387 |
} |
|
382 | 388 |
/** |
383 | 389 |
* Elimina una geometria. Si es una geometr?a original de la capa en |
384 | 390 |
* edici?n se marca como eliminada (haya sido modificada o no). Si es una |
... | ... | |
593 | 599 |
Rectangle2D r = g.getBounds2D(); |
594 | 600 |
index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(), |
595 | 601 |
r.getY() + r.getHeight()), new Integer(calculatedIndex)); |
596 |
|
|
602 |
|
|
597 | 603 |
return calculatedIndex; |
598 | 604 |
} |
599 | 605 |
/** |
... | ... | |
675 | 681 |
*/ |
676 | 682 |
public Rectangle2D getFullExtent() throws DriverIOException { |
677 | 683 |
/* if (fullExtent == null) |
678 |
{
|
|
684 |
{ |
|
679 | 685 |
fullExtent = ova.getFullExtent(); |
680 | 686 |
} |
681 | 687 |
else |
... | ... | |
766 | 772 |
} |
767 | 773 |
/** |
768 | 774 |
* Usar solo cuando est?s seguro de que puedes |
769 |
* gastar memoria. Nosotros lo usamos para las
|
|
775 |
* gastar memoria. Nosotros lo usamos para las |
|
770 | 776 |
* b?squedas por ?ndice espacial con el handle. |
771 |
* La idea es usarlo una vez, guardar las geometr?as que
|
|
777 |
* La idea es usarlo una vez, guardar las geometr?as que |
|
772 | 778 |
* necesitas en ese extent y trabajar con ellas |
773 | 779 |
* hasta el siguiente cambio de extent. |
774 | 780 |
* @param r |
... | ... | |
794 | 800 |
} catch (IOException e1) { |
795 | 801 |
throw new DriverException(e1); |
796 | 802 |
} |
797 |
|
|
803 |
|
|
798 | 804 |
return feats; |
799 | 805 |
} |
800 |
|
|
806 |
public void setSpatialIndex(SpatialIndex spatialIndex) { |
|
807 |
index=(Quadtree)spatialIndex; |
|
808 |
} |
|
809 |
public void setFullExtent(Rectangle2D fullExtent2) { |
|
810 |
fullExtent=fullExtent2; |
|
811 |
} |
|
801 | 812 |
|
813 |
|
|
802 | 814 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/AnnotationEditableAdapter.java | ||
---|---|---|
18 | 18 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
19 | 19 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
20 | 20 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
21 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
|
21 | 22 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
22 | 23 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
23 | 24 |
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation; |
24 | 25 |
import com.vividsolutions.jts.geom.Envelope; |
26 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
|
25 | 27 |
|
26 | 28 |
public class AnnotationEditableAdapter extends VectorialEditableAdapter{ |
27 | 29 |
private ArrayList labels; |
... | ... | |
32 | 34 |
} |
33 | 35 |
|
34 | 36 |
public int doModifyRow(int calculatedIndex, IRow feat) throws IOException, DriverIOException { |
37 |
FLabel label=(FLabel)labels.get(calculatedIndex); |
|
35 | 38 |
Value value=feat.getAttribute(mapping.getColumnText()); |
36 |
((FLabel)labels.get(calculatedIndex)).setString(value.toString()); |
|
39 |
Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone(); |
|
40 |
Rectangle2D rLabel=(Rectangle2D)label.getBoundBox(); |
|
41 |
label.setString(value.toString()); |
|
42 |
|
|
37 | 43 |
if (mapping.getColumnRotate()==mapping.getColumnText()){ |
38 |
((FLabel)labels.get(calculatedIndex)).setRotation(((NumericValue)value).doubleValue());
|
|
44 |
label.setRotation(((NumericValue)value).doubleValue());
|
|
39 | 45 |
} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto. |
40 |
return super.doModifyRow(calculatedIndex, feat); |
|
46 |
|
|
47 |
|
|
48 |
int posAnteriorInExpansionFile = -1; |
|
49 |
Integer integer = new Integer(calculatedIndex); |
|
50 |
|
|
51 |
IFeature featAnt = null; |
|
52 |
System.err.println("Modifica una Row en la posici?n: " |
|
53 |
+ calculatedIndex); |
|
54 |
// Si la geometr?a no ha sido modificada |
|
55 |
if (!relations.containsKey(integer)) { |
|
56 |
int newPosition = expansionFile.addRow(feat); |
|
57 |
relations.put(integer, new Integer(newPosition)); |
|
58 |
|
|
59 |
// Se actualiza el ?ndice espacial |
|
60 |
try { |
|
61 |
featAnt = (DefaultFeature) (ova.getFeature(calculatedIndex)); |
|
62 |
} catch (DriverException e) { |
|
63 |
throw new DriverIOException(e); |
|
64 |
} |
|
65 |
|
|
66 |
Rectangle2D rAntAux = featAnt.getGeometry().getBounds2D(); |
|
67 |
Rectangle2D rAnt=label.getBoundBox(); |
|
68 |
rAnt.setFrame(rAntAux.getX(),rAntAux.getY(),rAnt.getWidth(),rAnt.getHeight()); |
|
69 |
Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D(); |
|
70 |
double difX=r.getX()-rAnt.getX(); |
|
71 |
double difY=r.getY()-rAnt.getY(); |
|
72 |
Point2D p=new Point2D.Double(rLabel.getX()+difX,rLabel.getY()+difY); |
|
73 |
label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabel.getWidth(),rLabel.getHeight())); |
|
74 |
label.setOrig(p); |
|
75 |
index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX() |
|
76 |
+ rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY() |
|
77 |
+ rLabelAnt.getHeight()), new Integer(calculatedIndex)); |
|
78 |
index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel |
|
79 |
.getY(), rLabel.getY() + rLabel.getHeight()), new Integer( |
|
80 |
calculatedIndex)); |
|
81 |
} else { |
|
82 |
// Obtenemos el ?ndice en el fichero de expansi?n |
|
83 |
int num = ((Integer) relations.get(integer)).intValue(); |
|
84 |
posAnteriorInExpansionFile = num; |
|
85 |
|
|
86 |
// Obtenemos la geometr?a para actualiza el ?ndice |
|
87 |
// espacialposteriormente |
|
88 |
featAnt = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
|
89 |
|
|
90 |
/* |
|
91 |
* Se modifica la geometr?a y nos guardamos el ?ndice dentro del |
|
92 |
* fichero de expansi?n en el que se encuentra la geometr?a |
|
93 |
* modificada |
|
94 |
*/ |
|
95 |
num = expansionFile.modifyRow(num, feat); |
|
96 |
|
|
97 |
/* |
|
98 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el |
|
99 |
* fichero de expansi?n. |
|
100 |
*/ |
|
101 |
relations.put(integer, new Integer(num)); |
|
102 |
|
|
103 |
// Se modifica el ?ndice espacial |
|
104 |
Rectangle2D rAnt = featAnt.getGeometry().getBounds2D(); |
|
105 |
Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D(); |
|
106 |
|
|
107 |
double difX=r.getX()-rAnt.getX(); |
|
108 |
double difY=r.getY()-rAnt.getY(); |
|
109 |
Point2D p=new Point2D.Double(rLabel.getX()+difX,rLabel.getY()+difY); |
|
110 |
|
|
111 |
label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabel.getWidth(),rLabel.getHeight())); |
|
112 |
label.setOrig(p); |
|
113 |
index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX() |
|
114 |
+ rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY() |
|
115 |
+ rLabelAnt.getHeight()), new Integer(calculatedIndex)); |
|
116 |
index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel |
|
117 |
.getY(), rLabel.getY() + rLabel.getHeight()), new Integer( |
|
118 |
calculatedIndex)); |
|
119 |
} |
|
120 |
return posAnteriorInExpansionFile; |
|
41 | 121 |
} |
42 | 122 |
|
43 | 123 |
public IRow doRemoveRow(int index) throws DriverIOException, IOException { |
... | ... | |
139 | 219 |
} |
140 | 220 |
return ShapeFactory.createPolygon2D(resul); |
141 | 221 |
} |
222 |
public void startEdition() throws EditionException { |
|
223 |
isEditing = true; |
|
224 |
try { |
|
225 |
expansionFile.open(); |
|
226 |
index = new Quadtree(); |
|
227 |
|
|
228 |
for (int i = 0; i < labels.size(); i++) { |
|
229 |
Rectangle2D r=((FLabel)labels.get(i)).getBoundBox(); |
|
230 |
Envelope e = new Envelope(r.getX(), |
|
231 |
r.getX() + r.getWidth(), r.getY(), r.getY() |
|
232 |
+ r.getHeight()); |
|
233 |
index.insert(e, new Integer(i)); |
|
234 |
if (fullExtent == null) { |
|
235 |
fullExtent = r; |
|
236 |
} else { |
|
237 |
fullExtent = fullExtent.createUnion(r); |
|
238 |
} |
|
239 |
} |
|
240 |
} catch (IOException e) { |
|
241 |
throw new EditionException(e); |
|
242 |
} |
|
243 |
|
|
244 |
System.err.println("Se han metido en el ?ndice " |
|
245 |
+ index.queryAll().size() + " labels"); |
|
246 |
} |
|
247 |
|
|
248 |
public Rectangle2D getShapeBounds(int index) throws IOException { |
|
249 |
//Solo se utiliza cuando el driver es BoundedShapes |
|
250 |
// Si no est? en el fichero de expansi?n |
|
251 |
Integer integer = new Integer((int) index); |
|
252 |
if (!relations.containsKey(integer)) { |
|
253 |
if (ova.getDriver() instanceof BoundedShapes){ |
|
254 |
BoundedShapes bs = (BoundedShapes) ova.getDriver(); |
|
255 |
return bs.getShapeBounds(index); |
|
256 |
}else{ |
|
257 |
return ova.getDriver().getShape(index).getBounds2D(); |
|
258 |
} |
|
259 |
|
|
260 |
} else { |
|
261 |
int num = ((Integer) relations.get(integer)).intValue(); |
|
262 |
DefaultRowEdited feat; |
|
263 |
feat = (DefaultRowEdited) expansionFile.getRow(num); |
|
264 |
if (feat.getStatus() == IRowEdited.STATUS_DELETED) |
|
265 |
return null; |
|
266 |
IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry(); |
|
267 |
return geom.getBounds2D();//getGeometry(); |
|
268 |
} |
|
269 |
|
|
270 |
} |
|
142 | 271 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrVect.java | ||
---|---|---|
791 | 791 |
|
792 | 792 |
sds = ds; |
793 | 793 |
sds.setSelectionSupport(selectionSupport); |
794 |
|
|
794 |
|
|
795 | 795 |
} catch (DriverLoadException e) { |
796 | 796 |
throw new DriverException(e); |
797 | 797 |
} |
798 | 798 |
} |
799 | 799 |
return sds; |
800 |
}
|
|
801 |
|
|
800 |
} |
|
801 |
|
|
802 | 802 |
/* (non-Javadoc) |
803 | 803 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setEditing(boolean) |
804 | 804 |
*/ |
... | ... | |
821 | 821 |
} |
822 | 822 |
vea.setOriginalVectorialAdapter(getSource()); |
823 | 823 |
try{ |
824 |
///vea.setSpatialIndex(getSpatialIndex()); |
|
825 |
///vea.setFullExtent(getFullExtent()); |
|
824 | 826 |
vea.startEdition(); |
825 | 827 |
setSource(vea); |
826 | 828 |
getRecordset().setSelectionSupport(vea.getOriginalAdapter().getRecordset().getSelectionSupport()); |
... | ... | |
833 | 835 |
// TODO Auto-generated catch block |
834 | 836 |
e.printStackTrace(); |
835 | 837 |
} |
836 |
|
|
837 | 838 |
|
839 |
|
|
838 | 840 |
} |
839 | 841 |
else |
840 | 842 |
{ |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/AnnotationStrategy.java | ||
---|---|---|
80 | 80 |
FSymbol theSymbol = l.getDefaultSymbol(); |
81 | 81 |
theSymbol.setFontSizeInPixels(inPixels); |
82 | 82 |
System.out.println("Dibujando Anotaciones..."); |
83 |
ViewPort vp=capa.getFMap().getViewPort(); |
|
83 |
ViewPort vp=viewPort;//capa.getFMap().getViewPort();
|
|
84 | 84 |
AffineTransform at=vp.getAffineTransform(); |
85 | 85 |
try { |
86 | 86 |
long numRows=lyrAnnotation.getRecordset().getRowCount(); |
Also available in: Unified diff