Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfCircle.java @ 2669

History | View | Annotate | Download (5.37 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 org.cresques.cts.ICoordTrans;
27
import org.cresques.cts.IProjection;
28

    
29
import org.cresques.geo.ViewPortData;
30

    
31
import org.cresques.io.DxfGroup;
32

    
33
import org.cresques.px.Extent;
34

    
35
import java.awt.Color;
36
import java.awt.Graphics2D;
37
import java.awt.geom.GeneralPath;
38
import java.awt.geom.Point2D;
39

    
40

    
41
/**
42
 * Entidad TEXT de AutoCAD
43
 * jmorell: Definici?n de atributos para el piloto de CAD e implementaci?n de
44
 * la escritura en formato DXF2000.
45
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
46
 */
47
public class DxfCircle extends DxfEntity {
48
    final static Color baseColor = new Color(69, 106, 121);
49

    
50
    //Vector points = null;
51
    Point2D[] pts;
52
    GeneralPath gp = null;
53
    boolean closed = true;
54
    private Point2D center;
55
    private double radius;
56
    private Color color = baseColor; //Color(255,214,132,255);
57

    
58
    public DxfCircle(IProjection proj, DxfLayer layer, Point2D[] pts) {
59
        super(proj, layer);
60
        this.pts = pts;
61
        extent = new Extent();
62

    
63
        for (int i = 0; i < pts.length; i++) {
64
            extent.add(pts[i]);
65
        }
66
    }
67

    
68
    public Color c() {
69
        return color;
70
    }
71

    
72
    public Color c(Color color) {
73
        this.color = color;
74

    
75
        return color;
76
    }
77

    
78
    public void reProject(ICoordTrans rp) {
79
        Point2D[] savePts = pts;
80

    
81
        pts = new Point2D[savePts.length];
82
        extent = new Extent();
83

    
84
        Point2D ptDest = null;
85

    
86
        for (int i = 0; i < savePts.length; i++) {
87
            ptDest = rp.getPDest().createPoint(0.0, 0.0);
88
            ptDest = rp.convert((Point2D) savePts[i], ptDest);
89
            this.pts[i] = ptDest;
90
            extent.add(ptDest);
91
        }
92

    
93
        setProjection(rp.getPDest());
94
    }
95

    
96
    public void draw(Graphics2D g, ViewPortData vp) {
97
        //System.out.println("Va a pintar un circle");
98
        Color color = null;
99

    
100
        if (dxfColor == AcadColor.BYLAYER) {
101
            //g.setColor(layer.getColor());
102
            color = layer.getColor();
103
        } else {
104
            //g.setColor(AcadColor.getColor(dxfColor));
105
            color = AcadColor.getColor(dxfColor);
106
        }
107

    
108
        newGP(vp);
109

    
110
        if (closed) {
111
            g.setColor(new Color(color.getRed(), color.getBlue(),
112
                                 color.getGreen(), 0x80));
113
            g.fill(gp);
114
        }
115

    
116
        g.setColor(color);
117
        g.draw(gp);
118
    }
119

    
120
    private void newGP(ViewPortData vp) {
121
        //if (gp != null) return;
122
        gp = new GeneralPath();
123

    
124
        Point2D pt0 = null;
125
        Point2D pt = null;
126
        Point2D pt1 = null;
127
        Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0);
128

    
129
        //System.out.println("pts.length = " + pts.length);
130
        for (int i = 0; i < pts.length; i++) {
131
            pt1 = (Point2D) pts[i];
132
            vp.mat.transform(pt1, ptTmp);
133

    
134
            if (pt0 == null) {
135
                pt0 = ptTmp;
136
                gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY());
137
            } else {
138
                gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY());
139
            }
140
        }
141

    
142
        if (closed) {
143
            gp.closePath();
144
        }
145
    }
146

    
147
    /**
148
     * Escritura de c?rculos en un DXF2000.
149
     */
150
    public String toDxfString() {
151
        StringBuffer sb = null;
152
        sb = new StringBuffer(DxfGroup.toString(0, "CIRCLE"));
153
        sb.append(DxfGroup.toString(5, getHandle()));
154
        sb.append(DxfGroup.toString(100, "AcDbEntity"));
155
        sb.append(DxfGroup.toString(8, layer.getName()));
156
        sb.append(DxfGroup.toString(62, dxfColor));
157
        sb.append(DxfGroup.toString(100, "AcDbCircle"));
158
        sb.append(DxfGroup.toString(10, getCenter().getX(), 6));
159
        sb.append(DxfGroup.toString(20, getCenter().getY(), 6));
160
        sb.append(DxfGroup.toString(40, getRadius(), 6));
161

    
162
        return sb.toString();
163
    }
164

    
165
    /**
166
     * @return
167
     */
168
    public Point2D[] getPts() {
169
        return pts;
170
    }
171

    
172
    /**
173
     * @return
174
     */
175

    
176
    /*public GeneralPath getGeneralPath(ViewPort vp) {
177
            newGP(vp);
178
            return (GeneralPath) gp.clone();
179
    }*/
180

    
181
    /**
182
     * @return Returns the radius.
183
     */
184
    public double getRadius() {
185
        return radius;
186
    }
187

    
188
    /**
189
     * @param radius The radius to set.
190
     */
191
    public void setRadius(double radius) {
192
        this.radius = radius;
193
    }
194

    
195
    /**
196
     * @return Returns the center.
197
     */
198
    public Point2D getCenter() {
199
        return center;
200
    }
201

    
202
    /**
203
     * @param center The center to set.
204
     */
205
    public void setCenter(Point2D center) {
206
        this.center = center;
207
    }
208
}