Revision 28311

View differences:

branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControl.java
72 72
import org.gvsig.fmap.crs.CRSFactory;
73 73
import org.gvsig.fmap.dal.DataStoreNotification;
74 74
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
75
import org.gvsig.fmap.geom.Geometry;
75 76
import org.gvsig.fmap.geom.GeometryLocator;
76 77
import org.gvsig.fmap.geom.GeometryManager;
77 78
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
......
210 211
public class MapControl extends JComponent implements ComponentListener, Observer {
211 212
	private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
212 213
	private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
213
	
214

  
214 215
	/**
215 216
	 * <p>One of the possible status of <code>MapControl</code>. Determines that all visible information has been
216 217
	 * drawn and its updated.</p>
......
2153 2154
	 * @return distance from <code>point</code> to the adjusted one. If there is no
2154 2155
	 *  adjustment, returns <code>Double.MAX_VALUE</code>.
2155 2156
	 */
2156
	private double adjustToHandler(Point2D point,
2157
			Point2D mapHandlerAdjustedPoint) {
2158 2157

  
2159
		if (!isRefentEnabled()) {
2160
			return Double.MAX_VALUE;
2161
		}
2162 2158

  
2163
//		ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited();
2164
//		if (!(aux instanceof VectorialLayerEdited))
2165
//			return Double.MAX_VALUE;
2166
//		VectorialLayerEdited vle = (VectorialLayerEdited) aux;
2159
	private double adjustToHandler(Point2D point,
2160
            Point2D mapHandlerAdjustedPoint) {
2167 2161

  
2168
		ArrayList layersToSnap = getMapContext().getLayersToSnap();
2162
        if (!isRefentEnabled())
2163
            return Double.MAX_VALUE;
2169 2164

  
2170
		ArrayList snappers=new ArrayList(selected.keySet());
2165
        ArrayList snappers=new ArrayList(selected.keySet());
2166
        ArrayList layersToSnap = getMapContext().getLayersToSnap();
2171 2167

  
2172
		double mapTolerance = vp.toMapDistance(MapControl.tolerance);
2173
		double minDist = mapTolerance;
2174
//		double rw = getMapControl().getViewPort().toMapDistance(5);
2175
		Point2D mapPoint = point;
2176
		double middleTol=mapTolerance * 0.5;
2177
		org.gvsig.fmap.geom.primitive.Envelope r;
2168
        double mapTolerance = vp.toMapDistance(MapControl.tolerance);
2169
        double minDist = mapTolerance;
2170
        double middleTol=mapTolerance * 0.5;
2171
        Point2D mapPoint = point;
2172
        org.gvsig.fmap.geom.primitive.Envelope r;
2178 2173
		com.vividsolutions.jts.geom.Envelope e = null;
2179 2174
		try {
2180 2175
			r = geomManager.createEnvelope(mapPoint.getX() - middleTol,
......
2182 2177
					mapPoint.getX() + middleTol,
2183 2178
					mapPoint.getY() + middleTol,
2184 2179
					SUBTYPES.GEOM2D);
2185
			
2180

  
2186 2181
			e = Converter.convertEnvelopeToJTS(r);
2187 2182
		} catch (CreateEnvelopeException e1) {
2188 2183
			logger.error("Error creating the envelope", e1);
2189 2184
		}
2190 2185

  
2191
		
2186
        usedSnap = null;
2187
        Point2D lastPoint = null;
2188
        if (previousPoint != null)
2189
        {
2190
            lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]);
2191
        }
2192
        for (int j = 0; j < layersToSnap.size(); j++)
2193
        {
2194
            FLyrVect lyrVect = (FLyrVect) layersToSnap.get(j);
2195
            SpatialCache cache = lyrVect.getSpatialCache();
2196
            if (lyrVect.isVisible())
2197
            {
2198
                // La lista de snappers est? siempre ordenada por prioridad. Los de mayor
2199
                // prioridad est?n primero.
2200
                java.util.List geoms = cache.query(e);
2201
                for (int n=0; n < geoms.size(); n++) {
2202
                    Geometry geom = (Geometry) geoms.get(n);
2203
                    for (int i = 0; i < snappers.size(); i++)
2204
                    {
2205
                        ISnapper theSnapper = (ISnapper) snappers.get(i);
2192 2206

  
2193
		usedSnap = null;
2194
		Point2D lastPoint = null;
2195
		if (previousPoint != null)
2196
		{
2197
			lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]);
2198
		}
2199
		for (int j = 0; j < layersToSnap.size(); j++)
2200
		{
2201
			FLyrVect lyrVect = (FLyrVect) layersToSnap.get(j);
2202
			SpatialCache cache = lyrVect.getSpatialCache();
2203
			if (lyrVect.isVisible())
2204
			{
2205
				// La lista de snappers est? siempre ordenada por prioridad. Los de mayor
2206
				// prioridad est?n primero.
2207
				for (int i = 0; i < snappers.size(); i++)
2208
				{
2209
					ISnapper theSnapper = (ISnapper) snappers.get(i);
2207
                        if (usedSnap != null)
2208
                        {
2209
                            // Si ya tenemos un snap y es de alta prioridad, cogemos ese. (A no ser que en otra capa encontremos un snapper mejor)
2210
                            if (theSnapper.getPriority() > usedSnap.getPriority())
2211
                                break;
2212
                        }
2213
//                        SnappingVisitor snapVisitor = null;
2214
                        Point2D theSnappedPoint = null;
2215
                        if (theSnapper instanceof ISnapperVectorial)
2216
                        {
2217
                            theSnappedPoint = ((ISnapperVectorial) theSnapper).getSnapPoint(point, geom, mapTolerance, lastPoint);
2218
                        }
2219
                        if (theSnapper instanceof ISnapperRaster)
2220
                        {
2221
                            ISnapperRaster snapRaster = (ISnapperRaster) theSnapper;
2222
                            theSnappedPoint = snapRaster.getSnapPoint(this, point, mapTolerance, lastPoint);
2223
                        }
2210 2224

  
2211
					if (usedSnap != null)
2212
					{
2213
						// Si ya tenemos un snap y es de alta prioridad, cogemos ese. (A no ser que en otra capa encontremos un snapper mejor)
2214
						if (theSnapper.getPriority() < usedSnap.getPriority()) {
2215
							break;
2216
						}
2217
					}
2218
					SnappingVisitor snapVisitor = null;
2219
					Point2D theSnappedPoint = null;
2220 2225

  
2221
					if (theSnapper instanceof ISnapperVectorial)
2222
					{
2223
						if (theSnapper instanceof ISnapperGeometriesVectorial) {
2224
							snapVisitor=new GeometriesSnappingVisitor((ISnapperGeometriesVectorial) theSnapper,point,mapTolerance,lastPoint);
2225
						}else {
2226
							snapVisitor = new SnappingVisitor((ISnapperVectorial) theSnapper, point, mapTolerance, lastPoint);
2227
						}
2228
						// System.out.println("Cache size = " + cache.size());
2229
						cache.query(e, snapVisitor);
2230
						theSnappedPoint = snapVisitor.getSnapPoint();
2226
                        if (theSnappedPoint != null) {
2227
                            double distAux = theSnappedPoint.distance(point);
2228
                            if (minDist > distAux)
2229
                            {
2230
                                minDist = distAux;
2231
                                usedSnap = theSnapper;
2232
                                mapHandlerAdjustedPoint.setLocation(theSnappedPoint);
2233
                            }
2234
                        }
2235
                    }
2236
                } // for n
2237
            } // visible
2238
        }
2239
        if (usedSnap != null)
2240
            return minDist;
2241
        return Double.MAX_VALUE;
2231 2242

  
2232
					}
2233
					if (theSnapper instanceof ISnapperRaster)
2234
					{
2235
						ISnapperRaster snapRaster = (ISnapperRaster) theSnapper;
2236
						theSnappedPoint = snapRaster.getSnapPoint(this, point, mapTolerance, lastPoint);
2237
					}
2238

  
2239

  
2240
					if (theSnappedPoint != null) {
2241
						double distAux = theSnappedPoint.distance(point);
2242
						if (minDist > distAux)
2243
						{
2244
							minDist = distAux;
2245
							usedSnap = theSnapper;
2246
							mapHandlerAdjustedPoint.setLocation(theSnappedPoint);
2247
						}
2248
					}
2249
				}
2250
			} // visible
2251
		}
2252
		if (usedSnap != null) {
2253
			return minDist;
2254
		}
2255
		return Double.MAX_VALUE;
2256

  
2257
	}
2243
    }
2258 2244
	/**
2259 2245
	 * Determines if snap tools are enabled or disabled.
2260 2246
	 *

Also available in: Unified diff