root / trunk / libraries / libCq_CMS_praster / src / org / cresques / px / gml / InsPoint.java @ 8026
History | View | Annotate | Download (7.47 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.px.gml; |
25 |
|
26 |
import org.cresques.cts.ICoordTrans; |
27 |
import org.cresques.cts.IProjection; |
28 |
|
29 |
import org.cresques.geo.Point3D; |
30 |
import org.cresques.geo.ViewPortData; |
31 |
|
32 |
import java.awt.Color; |
33 |
import java.awt.Graphics2D; |
34 |
import java.awt.geom.Line2D; |
35 |
import java.awt.geom.Point2D; |
36 |
|
37 |
import java.util.Vector; |
38 |
|
39 |
/**
|
40 |
* Punto de inserci?n. Se trata de un Point al que se le han a?adido los atributos
|
41 |
* necesarios para hacer referencia a un conjunto de objetos gr?ficos o bloque.
|
42 |
* Las funciones de gesti?n de bloques estan basadas en la clase DxfInsert.
|
43 |
* @author jmorell
|
44 |
*/
|
45 |
public class InsPoint extends Geometry { |
46 |
public static int pointNr = 0; |
47 |
public String text = null; |
48 |
String blockName;
|
49 |
Point3D scaleFactor; |
50 |
double rotAngle;
|
51 |
private FeatureCollection block = new FeatureCollection(proj); |
52 |
Vector blkList;
|
53 |
boolean blockFound = false; |
54 |
private Color fColor = null; //new Color(255,222,165,64); |
55 |
private Color color = new Color(255, 0, 0); //Color(255,214,132,255); |
56 |
|
57 |
/**
|
58 |
* Constructor de la clase.
|
59 |
*/
|
60 |
public InsPoint() {
|
61 |
super();
|
62 |
} |
63 |
|
64 |
/**
|
65 |
* Permite a?adir un punto.
|
66 |
* @param pt, Punto.
|
67 |
*/
|
68 |
public void add(Point2D pt) { |
69 |
pointNr++; |
70 |
super.add(pt);
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Devuelve el ?ngulo de rotaci?n que se aplica al bloque.
|
75 |
* @return double. ?ngulo de rotaci?n.
|
76 |
*/
|
77 |
public double getRotAngle() { |
78 |
return rotAngle;
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Devuelve el factor de escala que se aplica al bloque.
|
83 |
* @return Point3D. Contiene el factor de escala en X, en Y y en Z.
|
84 |
*/
|
85 |
public Point3D getScaleFactor() {
|
86 |
return scaleFactor;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* Devuelve la lista de bloques.
|
91 |
* @return Vector, la lista de bloques.
|
92 |
*/
|
93 |
public Vector getBlkList() { |
94 |
return blkList;
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* Informa sobre si el bloque ya ha sido encontrado.
|
99 |
* @return boolean, true si el bloque ya ha sido encontrado.
|
100 |
*/
|
101 |
public boolean getBlockFound() { |
102 |
return blockFound;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* Establece el bloque al que hace referencia este punto de inserci?n.
|
107 |
* @param block, bloque.
|
108 |
*/
|
109 |
public void setBlock(FeatureCollection block) { |
110 |
this.block = block;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* Establece si el bloque ya ha sido encontrado.
|
115 |
* @param found, true si el bloque ya ha sido encontrado.
|
116 |
*/
|
117 |
public void setBlockFound(boolean found) { |
118 |
blockFound = found; |
119 |
} |
120 |
|
121 |
/**
|
122 |
* Establece la lista de bloques.
|
123 |
* @param blkList, Vector con la lista de bloques.
|
124 |
*/
|
125 |
public void setBlkList(Vector blkList) { |
126 |
this.blkList = blkList;
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* Devuelve el bloque al que hace referencia el punto de inserci?n.
|
131 |
* @return FeatureCollection, el bloque.
|
132 |
*/
|
133 |
public FeatureCollection getBlock() {
|
134 |
return block;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Establece el nombre del bloque.
|
139 |
* @param blockName, nombre del bloque.
|
140 |
*/
|
141 |
public void setBlockName(String blockName) { |
142 |
this.blockName = blockName;
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Devuelve el nombre del bloque al que hace referencia el punto de inserci?n.
|
147 |
* @return String, nombre del bloque.
|
148 |
*/
|
149 |
public String getBlockName() { |
150 |
return blockName;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Establece el factor de escala para el bloque.
|
155 |
* @param scaleFactor, factor de escala en X, en Y y en Z.
|
156 |
*/
|
157 |
public void setScaleFactor(Point3D scaleFactor) { |
158 |
this.scaleFactor = scaleFactor;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Establece el ?ngulo de rotaci?n para el bloque.
|
163 |
* @param rotAngle, ?ngulo de rotaci?n.
|
164 |
*/
|
165 |
public void setRotAngle(double rotAngle) { |
166 |
this.rotAngle = rotAngle;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* M?todo para cargar el bloque al que hace referencia el punto de inserci?n, en el
|
171 |
* propio InsPoint.
|
172 |
* @param blockName, nombre del bloque que estamos buscando.
|
173 |
* @return boolean, true si hemos encontrado el bloque que buscabamos y ha sido
|
174 |
* cargado.
|
175 |
*/
|
176 |
public boolean encuentraBloque(String blockName) { |
177 |
int i = 0; |
178 |
|
179 |
while ((i < blkList.size()) && (blockFound == false)) { |
180 |
//System.out.println("encuentraBloque: ((DxfBlock)blkList.get(i)).getBlkName() = " + ((FeatureCollection)blkList.get(i)).getProp("blockName"));
|
181 |
//System.out.println("encuentraBloque: blockName = " + blockName);
|
182 |
if (((FeatureCollection) blkList.get(i)).getProp("blockName") |
183 |
.equals(blockName)) { |
184 |
//System.out.println("encuentraBloque: Bloque " + i + " encontrado.");
|
185 |
block = (FeatureCollection) blkList.get(i); |
186 |
blockFound = true;
|
187 |
} else {
|
188 |
//System.out.println("encuentraBloque: Bloque " + blockName + " no encontrado");
|
189 |
blockFound = false;
|
190 |
} |
191 |
|
192 |
i++; |
193 |
} |
194 |
|
195 |
return blockFound;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* Devuelve el color del punto de inserci?n.
|
200 |
* @return Color
|
201 |
*/
|
202 |
public Color c() { |
203 |
return color;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Establece el color del punto de inserci?n.
|
208 |
* @param color
|
209 |
* @return Color
|
210 |
*/
|
211 |
public Color c(Color color) { |
212 |
this.color = color;
|
213 |
|
214 |
return color;
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Devuelve el color del relleno.
|
219 |
* @return Color
|
220 |
*/
|
221 |
public Color fillColor() { |
222 |
return fColor;
|
223 |
} |
224 |
|
225 |
/**
|
226 |
* Establece el color de relleno.
|
227 |
* @param c, color.
|
228 |
* @return Color
|
229 |
*/
|
230 |
public Color fillColor(Color c) { |
231 |
fColor = c; |
232 |
|
233 |
return fColor;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* Devuelve la proyecci?n cartogr?fica en la que se encuentra el InsPoint.
|
238 |
* @return IProjection, proyecci?n cartogr?fica.
|
239 |
*/
|
240 |
public IProjection getProjection() {
|
241 |
return proj;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* Establece la proyecci?n cartogr?fica en la que se encuentra el InsPoint.
|
246 |
* @param p, proyecci?n cartogr?fica.
|
247 |
*/
|
248 |
public void setProjection(IProjection p) { |
249 |
proj = p; |
250 |
} |
251 |
|
252 |
/**
|
253 |
* Permite cambiar la proyecci?n cartogr?fica del InsPoint a trav?s de unas
|
254 |
* coordenadas de transformaci?n.
|
255 |
* @param rp, coordenadas de transformaci?n.
|
256 |
*/
|
257 |
public void reProject(ICoordTrans rp) { |
258 |
// TODO metodo reProject pendiente de implementar
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* Permite dibujar el InsPoint.
|
263 |
*/
|
264 |
public void draw(Graphics2D g, ViewPortData vp) { |
265 |
g.setColor(c()); |
266 |
|
267 |
Point2D pt = new Point2D.Double(0D, 0D); |
268 |
vp.mat.transform((Point2D) data.get(0), pt); |
269 |
g.draw(new Line2D.Double(pt, pt)); |
270 |
|
271 |
if (text != null) { |
272 |
g.drawString(text, (int) pt.getX(), (int) pt.getY()); |
273 |
} |
274 |
} |
275 |
} |