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 |
}
|