Statistics
| Revision:

root / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfCircle.java @ 95

History | View | Annotate | Download (2.78 KB)

1
/*
2
 * Created on 09-may-2004
3
 *
4
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
5
 */
6
package org.cresques.px.dxf;
7

    
8
import java.awt.Color;
9
import java.awt.Graphics2D;
10
import java.awt.geom.GeneralPath;
11
import java.awt.geom.Point2D;
12

    
13
import org.cresques.cts.ICoordTrans;
14
import org.cresques.cts.IProjection;
15
import org.cresques.geo.ViewPortData;
16
import org.cresques.px.Extent;
17

    
18
/**
19
 * Entidad TEXT de AutoCAD
20
 * 
21
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
22
 */
23
public class DxfCircle extends DxfEntity {
24
        final static Color baseColor = new Color(69, 106, 121);
25
        //Vector points = null;
26
        Point2D [] pts;
27
        GeneralPath gp = null;
28
        boolean closed = true;
29
        
30
        public DxfCircle(IProjection proj, DxfLayer layer, Point2D[] pts) {
31
                super(proj, layer);
32
                this.pts = pts;
33
                extent = new Extent();
34
                for (int i=0; i<pts.length; i++) {
35
                        extent.add(pts[i]);
36
                }
37
        }
38
        
39
        private Color color = baseColor; //Color(255,214,132,255);
40
        
41
        public Color c() {return color;}
42
        public Color c(Color color) {this.color = color; return color;}
43
        
44
        public void reProject(ICoordTrans rp) {
45
                Point2D [] savePts = pts;
46

    
47
                pts = new Point2D[savePts.length];
48
                extent = new Extent();
49
                Point2D ptDest = null;
50
                for (int i=0; i<savePts.length; i++) {
51
                        ptDest = rp.getPDest().createPoint(0.0,0.0);
52
                        ptDest = rp.convert((Point2D) savePts[i], ptDest);
53
                        this.pts[i] = ptDest;
54
                        extent.add(ptDest);
55
                }
56
                setProjection(rp.getPDest());
57
        }
58
        
59
        public void draw(Graphics2D g, ViewPortData vp) {
60
                //System.out.println("Va a pintar un circle");
61
                Color color = null;
62
                if (dxfColor == AcadColor.BYLAYER)
63
                        //g.setColor(layer.getColor());
64
                        color = layer.getColor();
65
                else
66
                        //g.setColor(AcadColor.getColor(dxfColor));
67
                        color = AcadColor.getColor(dxfColor);
68
                newGP(vp);
69
                if (closed) {
70
                        g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x80));
71
                        g.fill(gp);
72
                } 
73
                g.setColor(color);
74
                g.draw(gp);
75
        }
76
        
77
        private void newGP(ViewPortData vp) {
78
                //if (gp != null) return;
79
                gp = new GeneralPath();
80
                Point2D pt0 = null, pt=null, pt1=null;
81
                Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0);
82
                System.out.println("pts.length = " + pts.length);
83
                for (int i=0; i<pts.length; i++) {
84
                        pt1 = (Point2D)pts[i];
85
                        vp.mat.transform(pt1, ptTmp);
86
                        if (pt0 == null) { 
87
                                pt0 = ptTmp;
88
                                gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY());
89
                        } else {
90
                                gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY());
91
                        }                        
92
                }
93
                if (closed) {
94
                        gp.closePath();                        
95
                }
96
        }
97
        /* (non-Javadoc)
98
         * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
99
         */
100
        public String toDxfString() {
101
                // TODO Auto-generated method stub
102
                return "";
103
        }
104
        /**
105
         * @return
106
         */
107
        public Point2D[] getPts() {
108
                return pts;
109
        }
110
        
111
        /**
112
         * @return
113
         */
114
        /*public GeneralPath getGeneralPath(ViewPort vp) {
115
                newGP(vp);
116
                return (GeneralPath) gp.clone();
117
        }*/
118

    
119
}