Statistics
| Revision:

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

History | View | Annotate | Download (6.67 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.dxf;
25

    
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.geom.GeneralPath;
29
import java.awt.geom.Point2D;
30

    
31
import org.gvsig.projection.cts.ICoordTrans;
32
import org.gvsig.projection.cts.IProjection;
33
import org.gvsig.projection.geo.ViewPortData;
34
import org.cresques.io.DxfGroup;
35
import org.gvsig.projection.px.Extent;
36

    
37

    
38
/**
39
 * Entidad CIRCLE de un fichero DXF.
40
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
41
 * @author jmorell
42
 */
43
public class DxfCircle extends DxfEntity {
44
    final static Color baseColor = new Color(69, 106, 121);
45

    
46
    //Vector points = null;
47
    Point2D[] pts;
48
    GeneralPath gp = null;
49
    boolean closed = true;
50
    private Point2D center;
51
    private double radius;
52
    private Color color = baseColor; //Color(255,214,132,255);
53
    
54
    /**
55
     * Constructor de DxfCircle.
56
     * @param proj, proyecci?n cartogr?fica en la que se encuentra el DxfCircle.
57
     * @param layer, capa del DXF en la que se encuentra el DxfCircle.
58
     * @param pts, puntos 2D que componen el DxfCircle.
59
     */
60
    public DxfCircle(IProjection proj, DxfLayer layer, Point2D[] pts) {
61
        super(proj, layer);
62
        this.pts = pts;
63
        extent = new Extent();
64

    
65
        for (int i = 0; i < pts.length; i++) {
66
            extent.add(pts[i]);
67
        }
68
    }
69
    
70
    /**
71
     * Devuelve el color del DxfCircle.
72
     * @return Color
73
     */
74
    public Color c() {
75
        return color;
76
    }
77
    
78
    /**
79
     * Establece el color del DxfCircle.
80
     * @param color
81
     * @return Color
82
     */
83
    public Color c(Color color) {
84
        this.color = color;
85

    
86
        return color;
87
    }
88
    
89
    /**
90
     * Permite reproyectar un DxfCircle dado un conjunto de coordenadas de transformaci?n.
91
     * @param rp, coordenadas de transformaci?n.
92
     */
93
    public void reProject(ICoordTrans rp) {
94
        Point2D[] savePts = pts;
95

    
96
        pts = new Point2D[savePts.length];
97
        extent = new Extent();
98

    
99
        Point2D ptDest = null;
100

    
101
        for (int i = 0; i < savePts.length; i++) {
102
            ptDest = rp.getPDest().createPoint(0.0, 0.0);
103
            ptDest = rp.convert((Point2D) savePts[i], ptDest);
104
            this.pts[i] = ptDest;
105
            extent.add(ptDest);
106
        }
107

    
108
        setProjection(rp.getPDest());
109
    }
110
    
111
    /**
112
     * Permite dibujar un DxfCircle.
113
     */
114
    public void draw(Graphics2D g, ViewPortData vp) {
115
        //System.out.println("Va a pintar un circle");
116
        Color color = null;
117

    
118
        if (dxfColor == AcadColor.BYLAYER) {
119
            //g.setColor(layer.getColor());
120
            color = layer.getColor();
121
        } else {
122
            //g.setColor(AcadColor.getColor(dxfColor));
123
            color = AcadColor.getColor(dxfColor);
124
        }
125

    
126
        newGP(vp);
127

    
128
        if (closed) {
129
            g.setColor(new Color(color.getRed(), color.getBlue(),
130
                                 color.getGreen(), 0x80));
131
            g.fill(gp);
132
        }
133

    
134
        g.setColor(color);
135
        g.draw(gp);
136
    }
137
    
138
    /**
139
     * Permite generar un GeneralPath partiendo del array de Point2D que conforma el
140
     * DxfCircle.
141
     * @param vp
142
     */
143
    private void newGP(ViewPortData vp) {
144
        //if (gp != null) return;
145
        gp = new GeneralPath();
146

    
147
        Point2D pt0 = null;
148
        Point2D pt = null;
149
        Point2D pt1 = null;
150
        Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0);
151

    
152
        //System.out.println("pts.length = " + pts.length);
153
        for (int i = 0; i < pts.length; i++) {
154
            pt1 = (Point2D) pts[i];
155
            vp.mat.transform(pt1, ptTmp);
156

    
157
            if (pt0 == null) {
158
                pt0 = ptTmp;
159
                gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY());
160
            } else {
161
                gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY());
162
            }
163
        }
164

    
165
        if (closed) {
166
            gp.closePath();
167
        }
168
    }
169

    
170
    /**
171
     * Permite la escritura de entidades DxfCircle en un fichero DXF2000.
172
     * @return String, la cadena que se escribir? en el fichero con la informaci?n
173
     * del DxfCircle.
174
     */
175
    public String toDxfString() {
176
        StringBuffer sb = null;
177
        sb = new StringBuffer(DxfGroup.toString(0, "CIRCLE"));
178
        sb.append(DxfGroup.toString(5, getHandle()));
179
        sb.append(DxfGroup.toString(100, "AcDbEntity"));
180
        sb.append(DxfGroup.toString(8, layer.getName()));
181
        sb.append(DxfGroup.toString(62, dxfColor));
182
        sb.append(DxfGroup.toString(100, "AcDbCircle"));
183
        sb.append(DxfGroup.toString(10, getCenter().getX(), 6));
184
        sb.append(DxfGroup.toString(20, getCenter().getY(), 6));
185
        // sb.append(DxfGroup.toString(30, 0.0, 1));
186
        sb.append(DxfGroup.toString(40, getRadius(), 6));
187

    
188
        return sb.toString();
189
    }
190

    
191
    /**
192
     * Devuelve el array de puntos que conforman el DxfCircle.
193
     * @return Point2D[], puntos del DxfCircle.
194
     */
195
    public Point2D[] getPts() {
196
        return pts;
197
    }
198

    
199
    /**
200
     * Devuelve el GeneralPath qie conforma el DxfCircle.
201
     * @return GeneralPath del DxfCircle.
202
     */
203
    /*public GeneralPath getGeneralPath(ViewPort vp) {
204
            newGP(vp);
205
            return (GeneralPath) gp.clone();
206
    }*/
207

    
208
    /**
209
     * @return Returns the radius.
210
     */
211
    public double getRadius() {
212
        return radius;
213
    }
214

    
215
    /**
216
     * @param radius The radius to set.
217
     */
218
    public void setRadius(double radius) {
219
        this.radius = radius;
220
    }
221

    
222
    /**
223
     * @return Returns the center.
224
     */
225
    public Point2D getCenter() {
226
        return center;
227
    }
228

    
229
    /**
230
     * @param center The center to set.
231
     */
232
    public void setCenter(Point2D center) {
233
        this.center = center;
234
    }
235
}