Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / px / dxf / DxfLine.java @ 8026

History | View | Annotate | Download (4.86 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 LINE de un fichero DXF.
43
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
44
 * @author jmorell
45
 */
46
public class DxfLine extends DxfEntity {
47
    final static Color baseColor = new Color(255, 106, 121);
48
    Point2D[] pts;
49
    GeneralPath gp = null;
50
    private Color color = baseColor; //Color(255,214,132,255);
51

    
52
    /**
53
     * Constructor de DxfLine.
54
     * @param proj, proyecci?n cartogr?fica en la que se encuentra la DxfLine.
55
     * @param layer, capa del DXF en la que se encuentra la DxfLine.
56
     * @param p1, punto inicial de la l?nea.
57
     * @param p2, punto final de la l?nea.
58
     */
59
    public DxfLine(IProjection proj, DxfLayer layer, Point2D p1, Point2D p2) {
60
        super(proj, layer);
61
        extent = new Extent(p1, p2);
62
        pts = new Point2D[2];
63
        pts[0] = p1;
64
        pts[1] = p2;
65
    }
66

    
67
    /**
68
     * Devuelve el color de la DxfLine.
69
     * @return Color
70
     */
71
    public Color c() {
72
        return color;
73
    }
74

    
75
    /**
76
     * Establece el color de la DxfLine.
77
     * @param color
78
     * @return Color
79
     */
80
    public Color c(Color color) {
81
        this.color = color;
82

    
83
        return color;
84
    }
85

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

    
93
        pts = new Point2D[2];
94
        extent = new Extent();
95

    
96
        Point2D ptDest = null;
97

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

    
105
        setProjection(rp.getPDest());
106
    }
107

    
108
    /**
109
     * Permite dibujar una DxfLine.
110
     */
111
    public void draw(Graphics2D g, ViewPortData vp) {
112
        if (dxfColor == AcadColor.BYLAYER) {
113
            g.setColor(layer.getColor());
114
        } else {
115
            g.setColor(AcadColor.getColor(dxfColor));
116
        }
117

    
118
        newGP(vp);
119
        g.draw(gp);
120
    }
121

    
122
    /**
123
     * Permite generar un GeneralPath partiendo del array de Point2D que conforma el
124
     * DxfLine.
125
     * @param vp
126
     */
127
    private void newGP(ViewPortData vp) {
128
        //if (gp != null) return;
129
        Point2D.Double pt0 = new Point2D.Double(0.0, 0.0);
130
        Point2D.Double pt1 = new Point2D.Double(0.0, 0.0);
131
        vp.mat.transform((Point2D) pts[0], pt0);
132
        vp.mat.transform((Point2D) pts[1], pt1);
133
        gp = new GeneralPath();
134
        gp.moveTo((float) pt0.getX(), (float) pt0.getY());
135
        gp.lineTo((float) pt1.getX(), (float) pt1.getY());
136
    }
137

    
138
    /**
139
     * Permite la escritura de entidades DxfLine en un fichero DXF2000.
140
     * @return String, la cadena que se escribir? en el fichero con la informaci?n
141
     * de la DxfLine.
142
     */
143
    public String toDxfString() {
144
        StringBuffer sb = null;
145
        sb = new StringBuffer(DxfGroup.toString(0, "LINE"));
146
        sb.append(DxfGroup.toString(5, getHandle()));
147
        sb.append(DxfGroup.toString(100, "AcDbEntity"));
148
        sb.append(DxfGroup.toString(8, layer.getName()));
149
        sb.append(DxfGroup.toString(62, dxfColor));
150
        sb.append(DxfGroup.toString(100, "AcDbLine"));
151
        sb.append(DxfGroup.toString(10, pts[0].getX(), 6));
152
        sb.append(DxfGroup.toString(20, pts[0].getY(), 6));
153
        sb.append(DxfGroup.toString(11, pts[1].getX(), 6));
154
        sb.append(DxfGroup.toString(21, pts[1].getY(), 6));
155

    
156
        return sb.toString();
157
    }
158

    
159
    /**
160
     * Devuelve el array de puntos que conforman el DxfLine.
161
     * @return Point2D[], puntos del DxfLine.
162
     */
163
    public Point2D[] getPts() {
164
        return pts;
165
    }
166
}