Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libDXF / src / org / cresques / px / gml / InsPoint.java @ 21930

History | View | Annotate | Download (7.76 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 java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.geom.Line2D;
29
import java.awt.geom.Point2D;
30
import java.util.Vector;
31

    
32
import org.gvsig.projection.cts.ICoordTrans;
33
import org.gvsig.projection.cts.IProjection;
34
import org.cresques.geo.Point2DZ;
35
import org.gvsig.projection.geo.ViewPortData;
36

    
37
/**
38
 * Punto de inserci?n. Se trata de un Point al que se le han a?adido los atributos
39
 * necesarios para hacer referencia a un conjunto de objetos gr?ficos o bloque.
40
 * Las funciones de gesti?n de bloques estan basadas en la clase DxfInsert.
41
 * @author jmorell
42
 */
43
public class InsPoint extends Geometry {
44
    public static int pointNr = 0;
45
    public String text = null;
46
    String blockName;
47
    Point2DZ scaleFactor;
48
    double rotAngle;
49
    private FeatureCollection block = new FeatureCollection(proj);
50
    Vector blkList;
51
    boolean blockFound = false;
52
    private Color fColor = null; //new Color(255,222,165,64);
53
    private Color color = new Color(255, 0, 0); //Color(255,214,132,255);
54
    
55
    /**
56
     * Constructor de la clase.
57
     */
58
    public InsPoint() {
59
        super();
60
    }
61
    
62
    /**
63
     * Permite a?adir un punto.
64
     * @param pt, Punto.
65
     */
66
    public void add(Point2D pt) {
67
        pointNr++;
68
        super.add(pt);
69
    }
70
    
71
    /**
72
     * Devuelve el ?ngulo de rotaci?n que se aplica al bloque.
73
     * @return double. ?ngulo de rotaci?n.
74
     */
75
    public double getRotAngle() {
76
        return rotAngle;
77
    }
78
    
79
    /**
80
     * Devuelve el factor de escala que se aplica al bloque.
81
     * @return Point3D. Contiene el factor de escala en X, en Y y en Z.
82
     */
83
    public Point2DZ getScaleFactor() {
84
        return scaleFactor;
85
    }
86
    
87
    /**
88
     * Devuelve la lista de bloques.
89
     * @return Vector, la lista de bloques.
90
     */
91
    public Vector getBlkList() {
92
        return blkList;
93
    }
94
    
95
    /**
96
     * Informa sobre si el bloque ya ha sido encontrado.
97
     * @return boolean, true si el bloque ya ha sido encontrado.
98
     */
99
    public boolean getBlockFound() {
100
        return blockFound;
101
    }
102
    
103
    /**
104
     * Establece el bloque al que hace referencia este punto de inserci?n.
105
     * @param block, bloque.
106
     */
107
    public void setBlock(FeatureCollection block) {
108
        this.block = block;
109
    }
110
    
111
    /**
112
     * Establece si el bloque ya ha sido encontrado.
113
     * @param found, true si el bloque ya ha sido encontrado.
114
     */
115
    public void setBlockFound(boolean found) {
116
        blockFound = found;
117
    }
118
    
119
    /**
120
     * Establece la lista de bloques.
121
     * @param blkList, Vector con la lista de bloques.
122
     */
123
    public void setBlkList(Vector blkList) {
124
        this.blkList = blkList;
125
    }
126
    
127
    /**
128
     * Devuelve el bloque al que hace referencia el punto de inserci?n.
129
     * @return FeatureCollection, el bloque.
130
     */
131
    public FeatureCollection getBlock() {
132
        return block;
133
    }
134
    
135
    /**
136
     * Establece el nombre del bloque.
137
     * @param blockName, nombre del bloque.
138
     */
139
    public void setBlockName(String blockName) {
140
        this.blockName = blockName;
141
    }
142
    
143
    /**
144
     * Devuelve el nombre del bloque al que hace referencia el punto de inserci?n.
145
     * @return String, nombre del bloque.
146
     */
147
    public String getBlockName() {
148
        return blockName;
149
    }
150
    
151
    /**
152
     * Establece el factor de escala para el bloque.
153
     * @param scaleFactor, factor de escala en X, en Y y en Z.
154
     */
155
    public void setScaleFactor(Point2DZ scaleFactor) {
156
        this.scaleFactor = scaleFactor;
157
    }
158
    
159
    /**
160
     * Establece el ?ngulo de rotaci?n para el bloque.
161
     * @param rotAngle, ?ngulo de rotaci?n.
162
     */
163
    public void setRotAngle(double rotAngle) {
164
        this.rotAngle = rotAngle;
165
    }
166
    
167
    /**
168
     * M?todo para cargar el bloque al que hace referencia el punto de inserci?n, en el
169
     * propio InsPoint.
170
     * @param blockName, nombre del bloque que estamos buscando.
171
     * @return boolean, true si hemos encontrado el bloque que buscabamos y ha sido
172
     * cargado.
173
     */
174
    public boolean encuentraBloque(String blockName) {
175
        int i = 0;
176

    
177
        while ((i < blkList.size()) && (blockFound == false)) {
178
            //System.out.println("encuentraBloque: ((DxfBlock)blkList.get(i)).getBlkName() = " + ((FeatureCollection)blkList.get(i)).getProp("blockName"));
179
            //System.out.println("encuentraBloque: blockName = " + blockName);
180
            if (((FeatureCollection) blkList.get(i)).getProp("blockName")
181
                     .equals(blockName)) {
182
                //System.out.println("encuentraBloque: Bloque " + i + " encontrado.");
183
                block = (FeatureCollection) blkList.get(i);
184
                blockFound = true;
185
            } else {
186
                //System.out.println("encuentraBloque: Bloque " + blockName + " no encontrado");
187
                blockFound = false;
188
            }
189

    
190
            i++;
191
        }
192

    
193
        return blockFound;
194
    }
195
    
196
    /**
197
     * Devuelve el color del punto de inserci?n.
198
     * @return Color
199
     */
200
    public Color c() {
201
        return color;
202
    }
203
    
204
    /**
205
     * Establece el color del punto de inserci?n.
206
     * @param color
207
     * @return Color
208
     */
209
    public Color c(Color color) {
210
        this.color = color;
211

    
212
        return color;
213
    }
214
    
215
    /**
216
     * Devuelve el color del relleno.
217
     * @return Color
218
     */
219
    public Color fillColor() {
220
        return fColor;
221
    }
222
    
223
    /**
224
     * Establece el color de relleno.
225
     * @param c, color.
226
     * @return Color
227
     */
228
    public Color fillColor(Color c) {
229
        fColor = c;
230

    
231
        return fColor;
232
    }
233
    
234
    /**
235
     * Devuelve la proyecci?n cartogr?fica en la que se encuentra el InsPoint.
236
     * @return IProjection, proyecci?n cartogr?fica.
237
     */
238
    public IProjection getProjection() {
239
        return proj;
240
    }
241
    
242
    /**
243
     * Establece la proyecci?n cartogr?fica en la que se encuentra el InsPoint.
244
     * @param p, proyecci?n cartogr?fica.
245
     */
246
    public void setProjection(IProjection p) {
247
        proj = p;
248
    }
249
    
250
    /**
251
     * Permite cambiar la proyecci?n cartogr?fica del InsPoint a trav?s de unas
252
     * coordenadas de transformaci?n.
253
     * @param rp, coordenadas de transformaci?n.
254
     */
255
    public void reProject(ICoordTrans rp) {
256
        // TODO metodo reProject pendiente de implementar
257
    }
258
    
259
    /**
260
     * Permite dibujar el InsPoint.
261
     */
262
    public void draw(Graphics2D g, ViewPortData vp) {
263
        g.setColor(c());
264

    
265
        Point2D pt = new Point2D.Double(0D, 0D);
266
        vp.mat.transform((Point2D) data.get(0), pt);
267
        g.draw(new Line2D.Double(pt, pt));
268

    
269
        if (text != null) {
270
            g.drawString(text, (int) pt.getX(), (int) pt.getY());
271
        }
272
    }
273
}