Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfSolid.java @ 83

History | View | Annotate | Download (2.9 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
import java.util.Iterator;
13
import java.util.Vector;
14

    
15
import org.cresques.geo.Projection;
16
import org.cresques.geo.ReProjection;
17
import org.cresques.geo.ViewPort;
18
import org.cresques.io.DxfGroup;
19
import org.cresques.px.Extent;
20

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

    
53
                pts = new Point2D[savePts.length];
54
                extent = new Extent();
55
                Point2D ptDest = null;
56
                for (int i=0; i<savePts.length; i++) {
57
                        ptDest = rp.getPDest().createPoint(0.0,0.0);
58
                        rp.convert((Point2D) savePts[i], ptDest);
59
                        this.pts[i] = ptDest;
60
                        extent.add(ptDest);
61
                }
62
                setProjection(rp.getPDest());
63
        }
64

    
65
        public void draw(Graphics2D g, ViewPort vp) {
66
                System.out.println("Va a pintar un solid");
67
                Color color = null;
68
                if (dxfColor == AcadColor.BYLAYER)
69
                        //g.setColor(layer.getColor());
70
                        color = layer.getColor();
71
                else
72
                        //g.setColor(AcadColor.getColor(dxfColor));
73
                        color = AcadColor.getColor(dxfColor);
74
                newGP(vp);
75
                if (closed) {
76
                        g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x80));
77
                        g.fill(gp);
78
                } 
79
                g.setColor(color);
80
                g.draw(gp);
81
        }
82
        
83
        private void newGP(ViewPort vp) {
84
                //if (gp != null) return;
85
                gp = new GeneralPath();
86
                Point2D pt0 = null, pt=null, pt1=null;
87
                Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0);
88
                System.out.println("pts.length = " + pts.length);
89
                for (int i=0; i<pts.length; i++) {
90
                        pt1 = (Point2D)pts[i];
91
                        vp.mat.transform(pt1, ptTmp);
92
                        if (pt0 == null) { 
93
                                pt0 = ptTmp;
94
                                gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY());
95
                        } else {
96
                                gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY());
97
                        }                        
98
                }
99
                if (closed) {
100
                        gp.closePath();                        
101
                }
102
        }
103
        /* (non-Javadoc)
104
         * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
105
         */
106
        public String toDxfString() {
107
                // TODO Auto-generated method stub
108
                return "";
109
        }
110
        /**
111
         * @return
112
         */
113
        public Point2D[] getPts() {
114
                return pts;
115
        }
116
        
117
        /**
118
         * @return
119
         */
120
        /*public GeneralPath getGeneralPath(ViewPort vp) {
121
                newGP(vp);
122
                return (GeneralPath) gp.clone();
123
        }*/
124

    
125
}