Revision 1584

View differences:

branches/pilotoDWG/applications/appgvSIG/src/com/iver/cit/gvsig/gui/cad/CADToolAdapter.java
49 49
	private int lastY;
50 50
	private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED);
51 51
	private JConsole console;
52
	private int gridSize = 20;
53 52
	private Point2D mapAdjustedPoint;
54 53
	private CadMapControl cadMapControl;
55 54
	private boolean questionAsked = false;
56 55
	private CadGrid grid = new CadGrid();
57 56
	private Point adjustedPoint;
58
	private boolean adjustGrid;
59

  
57
	
60 58
	/**
61 59
	 * Pinta de alguna manera especial las geometrias seleccionadas para la
62 60
	 * edici?n. En caso de que el snapping est? activado, pintar? el efecto
......
84 82
		 */
85 83
		grid.drawGrid(g);
86 84
		drawCursor(g);
87

  
85
		if (adjustedPoint!=null){
88 86
		Point2D p = getMapControl().getViewPort().toMapPoint((int) adjustedPoint.getX(),
89 87
				(int) adjustedPoint.getY());
90 88
		((CadTool) cadToolStack.peek()).drawOperation(g, editableFeatureSource,
91 89
			selection, p.getX(), p.getY());
90
		}
92 91
	}
93 92

  
94 93
	/**
......
227 226
	 */
228 227
	private void drawCursor(Graphics g) {
229 228
		Point p = adjustedPoint;
229
		if (p==null) grid.setViewPort(cadMapControl.getMapControl().getViewPort());
230
		
230 231
		int size1 = 15;
231 232
		int size2 = 3;
232 233
		g.drawLine((int) (p.getX() - size1), (int) (p.getY()),
......
552 553
	 * @param b
553 554
	 */
554 555
	public void setAdjustGrid(boolean b) {
555
		adjustGrid = b;
556
		grid.setAdjustGrid(b);
556 557
	}
557 558
}
branches/pilotoDWG/applications/appgvSIG/src/com/iver/cit/gvsig/gui/cad/CadGrid.java
40 40
 */
41 41
package com.iver.cit.gvsig.gui.cad;
42 42

  
43
import com.iver.cit.gvsig.fmap.ViewPort;
44

  
43 45
import java.awt.Graphics;
44 46
import java.awt.Point;
47
import java.awt.geom.Point2D;
48
import java.awt.geom.Rectangle2D;
45 49

  
46 50

  
47 51
/**
48
 * DOCUMENT ME!
52
 * Clase encargada de gestionar las diferentes operaciones que se realizan
53
 * sobre el grid.
49 54
 *
50 55
 * @author Vicente Caballero Navarro
51 56
 */
52 57
public class CadGrid {
53 58
	private boolean grid = false;
54
	private int gridSize = 20;
55
	private CadMapControl cadmapcontrol;
59
	private int gridSize = 1000;
60
	private ViewPort viewport;
61
	private boolean adjustGrid;
56 62

  
57 63
	/**
58
	 * Crea un nuevo CadGrid.
64
	 * Inserta el viewPort.
59 65
	 *
60
	 * @param cmc DOCUMENT ME!
66
	 * @param vp
61 67
	 */
62
	public CadGrid() {
68
	public void setViewPort(ViewPort vp) {
69
		viewport = vp;
63 70
	}
64
public void setCadMapControl(CadMapControl cmc){
65
	cadmapcontrol=cmc;
66
}
71

  
67 72
	/**
68 73
	 * Ajusta un punto de la imagen que se pasa como  par?metro al handler m?s
69 74
	 * cercano si se encuentra lo suficientemente  cerca y devuelve la
......
75 80
	 */
76 81
	public double adjustToGrid(Point point) {
77 82
		if (grid) {
78
			Point p = new Point(point);
79
			point.x = (((int) point.getX() + (gridSize / 2)) / gridSize) * gridSize;
80
			point.y = (((int) point.getY() + (gridSize / 2)) / gridSize) * gridSize;
83
			Point2D auxp = new Point2D.Double(0, 0);
84
			Point2D po = viewport.toMapPoint(point);
85
			Rectangle2D extent = viewport.getAdjustedExtent();
86
			double x = ((po.getX() + gridSize) % gridSize) -
87
				((auxp.getX()) % gridSize);
88
			double y = ((po.getY() + gridSize) % gridSize) -
89
				((auxp.getY()) % gridSize);
90
			Point2D p = new Point(point);
91
			point.x = (int) (p.getX() - viewport.fromMapDistance(x));
92
			point.y = (int) (p.getY() + viewport.fromMapDistance(y));
81 93

  
82 94
			return p.distance(point);
83 95
		}
......
95 107
			return;
96 108
		}
97 109

  
98
		for (int x = 0; x < cadmapcontrol.getWidth(); x += gridSize) {
99
			for (int y = 0; y < cadmapcontrol.getHeight(); y += gridSize) {
100
				g.drawRect(x, y, 1, 1);
110
		Rectangle2D extent = viewport.getAdjustedExtent();
111
		Point2D auxp = new Point2D.Double(0, 0);
112

  
113
		for (int i = (int) extent.getMinX(); i < (extent.getMaxX() + gridSize);
114
				i += gridSize) {
115
			for (int j = (int) extent.getMinY();
116
					j < (extent.getMaxY() + gridSize); j += gridSize) {
117
				Point2D po = new Point2D.Double(i, j);
118
				Point2D point = viewport.fromMapPoint(po);
119
				double x = ((po.getX() + gridSize) % gridSize) -
120
					((auxp.getX()) % gridSize);
121
				double y = ((po.getY() + gridSize) % gridSize) -
122
					((auxp.getY()) % gridSize);
123
				x = (int) (point.getX() - viewport.fromMapDistance(x));
124
				y = (int) (point.getY() + viewport.fromMapDistance(y));
125
				g.drawOval((int) x, (int) y, 1, 1);
101 126
			}
102 127
		}
103 128
	}
104
	public void setUseGrid(boolean b){
105
		grid=b;
129

  
130
	/**
131
	 * Inserta un boolean que indica si se utiliza o no el grid y de esta forma
132
	 * dibujarse.
133
	 *
134
	 * @param b boolean
135
	 */
136
	public void setUseGrid(boolean b) {
137
		grid = b;
106 138
	}
139

  
140
	/**
141
	 * Inserta un boolean que indica si se ajusta o no al grid y de esta forma
142
	 * dibujarse.
143
	 *
144
	 * @param b boolean
145
	 */
146
	public void setAdjustGrid(boolean b) {
147
		adjustGrid = b;
148
	}
107 149
}

Also available in: Unified diff