Statistics
| Revision:

svn-gvsig-desktop / branches / v02_desarrollo / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfLine.java @ 1607

History | View | Annotate | Download (2.77 KB)

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

    
9
import java.awt.Color;
10
import java.awt.Graphics2D;
11
import java.awt.geom.GeneralPath;
12
import java.awt.geom.Point2D;
13
import java.util.Iterator;
14

    
15
import org.cresques.cts.ICoordTrans;
16
import org.cresques.cts.IProjection;
17
import org.cresques.geo.ViewPortData;
18
import org.cresques.io.DxfGroup;
19
import org.cresques.px.Extent;
20

    
21
/**
22
 * Linea de autocad (.dxf, .dwg)
23
 * jmorell: Actualizaci?n de la escritura de l?neas al formato DXF2000.
24
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
25
 */
26

    
27
public class DxfLine extends DxfEntity {
28
        final static Color baseColor = new Color(255, 106, 121);
29
        Point2D [] pts;
30
        GeneralPath gp = null;
31
        
32
        public DxfLine(IProjection proj, DxfLayer layer, Point2D p1, Point2D p2) {
33
                super(proj, layer);
34
                extent = new Extent(p1, p2);
35
                pts = new Point2D[2];
36
                pts[0] = p1; pts[1] = p2;
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[2];
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
                        pts[i] = ptDest;
54
                        extent.add(ptDest);
55
                }
56
                setProjection(rp.getPDest());
57
        }
58

    
59
        public void draw(Graphics2D g, ViewPortData vp) {
60
                if (dxfColor == AcadColor.BYLAYER)
61
                        g.setColor(layer.getColor());
62
                else
63
                        g.setColor(AcadColor.getColor(dxfColor));
64
                newGP(vp);
65
                g.draw(gp);
66
        }
67
        
68
        private void newGP(ViewPortData vp) {
69
                //if (gp != null) return;
70
                Point2D.Double pt0 = new Point2D.Double(0.0, 0.0);
71
                Point2D.Double pt1 = new Point2D.Double(0.0, 0.0);
72
                vp.mat.transform((Point2D) pts[0], pt0);
73
                vp.mat.transform((Point2D) pts[1], pt1);
74
                gp = new GeneralPath();
75
                gp.moveTo((float)pt0.getX(), (float)pt0.getY());
76
                gp.lineTo((float)pt1.getX(), (float)pt1.getY());
77
        }
78
        
79
        /**
80
         * 050222,jmorell: Escritura de l?neas en un DXF2000.
81
         */
82
        public String toDxfString() {
83
                StringBuffer sb = null;
84
                sb = new StringBuffer( DxfGroup.toString(0, "LINE") );
85
                sb.append( DxfGroup.toString(5, getHandle()) );
86
                sb.append( DxfGroup.toString(100, "AcDbEntity") );
87
                sb.append( DxfGroup.toString(8, layer.getName()) );
88
                sb.append( DxfGroup.toString(62, dxfColor) );
89
                sb.append( DxfGroup.toString(100, "AcDbLine") );
90
                sb.append( DxfGroup.toString(10, pts[0].getX(), 6) );
91
                sb.append( DxfGroup.toString(20, pts[0].getY(), 6) );
92
                sb.append( DxfGroup.toString(11, pts[1].getX(), 6) );
93
                sb.append( DxfGroup.toString(21, pts[1].getY(), 6) );
94
                return sb.toString();
95
        }
96
        /**
97
         * @return
98
         */
99
        public Point2D[] getPts() {
100
                return pts;
101
        }
102
}