Revision 46134
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/SpatialCache.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.mapcontext.layers; |
25 | 25 |
|
26 | 26 |
import java.util.ArrayList; |
27 |
import java.util.HashMap; |
|
27 | 28 |
import java.util.Iterator; |
28 | 29 |
import java.util.List; |
30 |
import java.util.Map; |
|
29 | 31 |
import org.gvsig.fmap.geom.Geometry; |
30 | 32 |
import org.gvsig.fmap.geom.GeometryLocator; |
31 | 33 |
import org.gvsig.fmap.geom.SpatialIndex; |
... | ... | |
34 | 36 |
import org.slf4j.Logger; |
35 | 37 |
import org.slf4j.LoggerFactory; |
36 | 38 |
|
37 |
public class SpatialCache {
|
|
38 |
|
|
39 |
public class SpatialCache { |
|
40 |
|
|
39 | 41 |
private static final Logger logger = LoggerFactory.getLogger(SpatialCache.class); |
40 | 42 |
private int maxFeatures = 1000; // Por defecto, pero se puede cambiar |
41 |
private int fastNumTotalRegs=0; |
|
42 |
private SpatialIndex index = null; |
|
43 |
private boolean overflown = false; |
|
44 |
|
|
45 |
private boolean enabled = false; |
|
43 |
private int fastNumTotalRegs = 0; |
|
44 |
private SpatialIndex index = null; |
|
45 |
private boolean overflown = false; |
|
46 |
private Map<String, Boolean> enabledContexts; |
|
46 | 47 |
|
47 |
public SpatialCache() { |
|
48 |
try { |
|
49 |
this.index = GeometryLocator.getGeometryManager().createDefaultMemorySpatialIndex(); |
|
50 |
} catch (Exception e) { |
|
51 |
logger.info("Can't create spatial index", e); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
public int getMaxFeatures() { |
|
56 |
return maxFeatures; |
|
57 |
} |
|
48 |
private boolean enabled = false; |
|
58 | 49 |
|
59 |
public void setMaxFeatures(int maxFeatures) { |
|
60 |
this.maxFeatures = maxFeatures; |
|
61 |
} |
|
50 |
public SpatialCache() { |
|
51 |
enabledContexts = new HashMap<>(); |
|
52 |
try { |
|
53 |
this.index = GeometryLocator.getGeometryManager().createDefaultMemorySpatialIndex(); |
|
54 |
} catch (Exception e) { |
|
55 |
logger.info("Can't create spatial index", e); |
|
56 |
} |
|
57 |
} |
|
62 | 58 |
|
63 |
public synchronized void insert(Envelope bounds, Geometry geom) { |
|
64 |
if (isEnabled()) { |
|
65 |
if (getMaxFeatures() >= size()) { |
|
66 |
this.index.insert(bounds, geom); |
|
67 |
fastNumTotalRegs++; |
|
68 |
} else { |
|
69 |
overflown = true; |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
59 |
public int getMaxFeatures() { |
|
60 |
return maxFeatures; |
|
61 |
} |
|
73 | 62 |
|
74 |
public synchronized void query(Envelope searchEnv, Visitor visitor) |
|
75 |
{ |
|
76 |
this.index.query(searchEnv, visitor); |
|
77 |
|
|
78 |
} |
|
79 |
public synchronized List query(Envelope searchEnv) |
|
80 |
{ |
|
81 |
List result = new ArrayList(); |
|
82 |
Iterator it = index.query(searchEnv); |
|
83 |
while( it.hasNext() ) { |
|
84 |
result.add( it.next()); |
|
85 |
} |
|
86 |
return result; |
|
87 |
} |
|
63 |
public void setMaxFeatures(int maxFeatures) { |
|
64 |
this.maxFeatures = maxFeatures; |
|
65 |
} |
|
88 | 66 |
|
89 |
public void insert(Envelope itemEnv, Object item) {
|
|
90 |
if (isEnabled()) {
|
|
91 |
if (getMaxFeatures() >= size()) {
|
|
92 |
this.index.insert(itemEnv, item);
|
|
93 |
fastNumTotalRegs++;
|
|
94 |
} else {
|
|
95 |
overflown = true;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
|
67 |
public synchronized void insert(Envelope bounds, Geometry geom) {
|
|
68 |
if (isEnabled()) {
|
|
69 |
if (getMaxFeatures() >= size()) { |
|
70 |
this.index.insert(bounds, geom);
|
|
71 |
fastNumTotalRegs++;
|
|
72 |
} else { |
|
73 |
overflown = true; |
|
74 |
} |
|
75 |
}
|
|
76 |
}
|
|
99 | 77 |
|
100 |
public boolean remove(Envelope itemEnv, Object item) { |
|
101 |
boolean resul = this.index.remove(itemEnv,item); |
|
102 |
if (resul) |
|
103 |
fastNumTotalRegs--; |
|
104 |
return resul; |
|
105 |
} |
|
78 |
public synchronized void query(Envelope searchEnv, Visitor visitor) { |
|
79 |
this.index.query(searchEnv, visitor); |
|
106 | 80 |
|
107 |
public int size() { |
|
108 |
return fastNumTotalRegs; |
|
109 |
} |
|
81 |
} |
|
110 | 82 |
|
111 |
public void clearAll() { |
|
112 |
index.removeAll(); |
|
113 |
fastNumTotalRegs = 0; |
|
114 |
overflown = false; |
|
115 |
} |
|
83 |
public synchronized List query(Envelope searchEnv) { |
|
84 |
List result = new ArrayList(); |
|
85 |
Iterator it = index.query(searchEnv); |
|
86 |
while (it.hasNext()) { |
|
87 |
result.add(it.next()); |
|
88 |
} |
|
89 |
return result; |
|
90 |
} |
|
116 | 91 |
|
117 |
public void remove(org.gvsig.fmap.geom.primitive.Envelope bounds, Geometry geom) { |
|
92 |
public void insert(Envelope itemEnv, Object item) { |
|
93 |
if (isEnabled()) { |
|
94 |
if (getMaxFeatures() >= size()) { |
|
95 |
this.index.insert(itemEnv, item); |
|
96 |
fastNumTotalRegs++; |
|
97 |
} else { |
|
98 |
overflown = true; |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
public boolean remove(Envelope itemEnv, Object item) { |
|
104 |
boolean resul = this.index.remove(itemEnv, item); |
|
105 |
if (resul) { |
|
106 |
fastNumTotalRegs--; |
|
107 |
} |
|
108 |
return resul; |
|
109 |
} |
|
110 |
|
|
111 |
public int size() { |
|
112 |
return fastNumTotalRegs; |
|
113 |
} |
|
114 |
|
|
115 |
public void removeAll() { |
|
116 |
index.removeAll(); |
|
117 |
fastNumTotalRegs = 0; |
|
118 |
overflown = false; |
|
119 |
} |
|
120 |
|
|
121 |
public void remove(org.gvsig.fmap.geom.primitive.Envelope bounds, Geometry geom) { |
|
118 | 122 |
index.remove(bounds, geom); |
119 |
}
|
|
123 |
}
|
|
120 | 124 |
|
121 |
public boolean isEnabled() { |
|
122 |
return enabled; |
|
123 |
} |
|
125 |
public boolean isEnabled() { |
|
126 |
if (enabled) { |
|
127 |
return true; |
|
128 |
} |
|
129 |
for (Boolean value : this.enabledContexts.values()) { |
|
130 |
if (value) { |
|
131 |
return true; |
|
132 |
} |
|
133 |
} |
|
134 |
return false; |
|
135 |
} |
|
124 | 136 |
|
125 |
public void setEnabled(boolean enabled) { |
|
126 |
this.enabled = enabled; |
|
127 |
} |
|
128 |
|
|
129 |
public boolean isOverflown() { |
|
130 |
return overflown; |
|
137 |
public boolean isEnabled(String contextId) { |
|
138 |
return this.enabledContexts.getOrDefault(contextId, false); |
|
139 |
} |
|
140 |
|
|
141 |
public void setEnabled(boolean enabled) { |
|
142 |
this.enabled = enabled; |
|
143 |
} |
|
144 |
|
|
145 |
public void setEnabled(String contextId, boolean enabled) { |
|
146 |
this.enabledContexts.put(contextId, enabled); |
|
147 |
} |
|
148 |
|
|
149 |
public boolean isOverflown() { |
|
150 |
return overflown; |
|
151 |
} |
|
152 |
|
|
153 |
public boolean isContextEnabled() { |
|
154 |
for (Boolean value : this.enabledContexts.values()) { |
|
155 |
if (value) { |
|
156 |
return true; |
|
157 |
} |
|
131 | 158 |
} |
159 |
return false; |
|
160 |
} |
|
132 | 161 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/vectorial/FLyrVect.java | ||
---|---|---|
321 | 321 |
} |
322 | 322 |
|
323 | 323 |
if (spatialCache.isEnabled()) { |
324 |
spatialCache.clearAll();
|
|
324 |
spatialCache.removeAll();
|
|
325 | 325 |
legend.addDrawingObserver(this); |
326 | 326 |
} |
327 | 327 |
|
... | ... | |
622 | 622 |
throw new StartEditionLayerException(getName(), e); |
623 | 623 |
} |
624 | 624 |
} |
625 |
setSpatialCacheEnabled(b);
|
|
625 |
getSpatialCache().setEnabled("editing", b);
|
|
626 | 626 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
627 | 627 |
} |
628 | 628 |
|
... | ... | |
630 | 630 |
* @deprecated Use {@link #getSpatialCache()} |
631 | 631 |
*/ |
632 | 632 |
public void clearSpatialCache() { |
633 |
spatialCache.clearAll();
|
|
633 |
spatialCache.removeAll();
|
|
634 | 634 |
} |
635 | 635 |
|
636 | 636 |
/** |
... | ... | |
1127 | 1127 |
this.updateDrawVersion(); |
1128 | 1128 |
|
1129 | 1129 |
} else if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING) { |
1130 |
getSpatialCache().setEnabled("editing", false); |
|
1130 | 1131 |
|
1131 |
setSpatialCacheEnabled(false); |
|
1132 | 1132 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
1133 | 1133 |
this.updateDrawVersion(); |
1134 | 1134 |
|
1135 | 1135 |
} else if (event.getType() == FeatureStoreNotification.AFTER_STARTEDITING) { |
1136 |
|
|
1137 |
setSpatialCacheEnabled(true); |
|
1136 |
getSpatialCache().setEnabled("editing", true); |
|
1137 |
|
|
1138 | 1138 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
1139 | 1139 |
|
1140 | 1140 |
} else if (event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE) { |
... | ... | |
1149 | 1149 |
this.setAvailable(false); |
1150 | 1150 |
} else if (event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) { |
1151 | 1151 |
this.setAvailable(true); |
1152 |
setSpatialCacheEnabled(false);
|
|
1152 |
getSpatialCache().setEnabled("editing", false);
|
|
1153 | 1153 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
1154 | 1154 |
this.updateDrawVersion(); |
1155 | 1155 |
} |
... | ... | |
1276 | 1276 |
@Override |
1277 | 1277 |
protected void doDispose() throws BaseException { |
1278 | 1278 |
dispose(featureStore); |
1279 |
spatialCache.clearAll();
|
|
1279 |
spatialCache.removeAll();
|
|
1280 | 1280 |
} |
1281 | 1281 |
|
1282 | 1282 |
/** |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.snapping.app/org.gvsig.snapping.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/gui/ViewSnappingInfoImpl.java | ||
---|---|---|
46 | 46 |
private final FLyrVect layer; |
47 | 47 |
private boolean selected; |
48 | 48 |
private int cacheFeatures; |
49 |
private final boolean contextEnabled; |
|
49 | 50 |
|
50 |
public TableRow(FLyrVect layer, boolean selected, int cacheFeatures) { |
|
51 |
public TableRow(FLyrVect layer, boolean selected, boolean contextEnabled, int cacheFeatures) {
|
|
51 | 52 |
this.layer = layer; |
52 | 53 |
this.selected = selected; |
54 |
this.contextEnabled = contextEnabled; |
|
53 | 55 |
this.cacheFeatures = cacheFeatures; |
54 | 56 |
} |
55 | 57 |
|
... | ... | |
129 | 131 |
case 0: |
130 | 132 |
return row.isSelected(); |
131 | 133 |
case 1: |
134 |
if(row.contextEnabled){ |
|
135 |
return "<html><b>"+row.getLayer().getName()+"</b></html>"; |
|
136 |
} |
|
132 | 137 |
return row.getLayer().getName(); |
133 | 138 |
case 2: |
134 | 139 |
return row.getCacheFeatures(); |
... | ... | |
179 | 184 |
TableRow row = new TableRow( |
180 | 185 |
layerVect, |
181 | 186 |
spatialCache.isEnabled(), |
187 |
spatialCache.isContextEnabled(), |
|
182 | 188 |
spatialCache.getMaxFeatures() |
183 | 189 |
); |
184 | 190 |
rows.add(row); |
Also available in: Unified diff