Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfLine.java @ 2323

History | View | Annotate | Download (3.54 KB)

1 2 luisw
/*
2 2312 igbrotru
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5 2 luisw
 *
6 2249 igbrotru
 * 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 2312 igbrotru
 *
22
 * cresques@gmail.com
23 2249 igbrotru
 */
24 2 luisw
25
package org.cresques.px.dxf;
26
27
import java.awt.Color;
28
import java.awt.Graphics2D;
29
import java.awt.geom.GeneralPath;
30
import java.awt.geom.Point2D;
31
32 94 luisw
import org.cresques.cts.ICoordTrans;
33
import org.cresques.cts.IProjection;
34 91 luisw
import org.cresques.geo.ViewPortData;
35 1607 jmorell
import org.cresques.io.DxfGroup;
36 2 luisw
import org.cresques.px.Extent;
37
38
/**
39
 * Linea de autocad (.dxf, .dwg)
40 1607 jmorell
 * jmorell: Actualizaci?n de la escritura de l?neas al formato DXF2000.
41 2 luisw
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
42
 */
43
44
public class DxfLine extends DxfEntity {
45
        final static Color baseColor = new Color(255, 106, 121);
46
        Point2D [] pts;
47
        GeneralPath gp = null;
48
49 94 luisw
        public DxfLine(IProjection proj, DxfLayer layer, Point2D p1, Point2D p2) {
50 2 luisw
                super(proj, layer);
51
                extent = new Extent(p1, p2);
52
                pts = new Point2D[2];
53
                pts[0] = p1; pts[1] = p2;
54
        }
55
56
        private Color color = baseColor; //Color(255,214,132,255);
57
58
        public Color c() {return color;}
59
        public Color c(Color color) {this.color = color; return color;}
60
61 94 luisw
        public void reProject(ICoordTrans rp) {
62 2 luisw
                Point2D [] savePts = pts;
63
64
                pts = new Point2D[2];
65
                extent = new Extent();
66
                Point2D ptDest = null;
67
                for (int i=0; i<savePts.length; i++) {
68
                        ptDest = rp.getPDest().createPoint(0.0,0.0);
69 95 luisw
                        ptDest = rp.convert((Point2D) savePts[i], ptDest);
70 2 luisw
                        pts[i] = ptDest;
71
                        extent.add(ptDest);
72
                }
73
                setProjection(rp.getPDest());
74
        }
75
76 91 luisw
        public void draw(Graphics2D g, ViewPortData vp) {
77 2 luisw
                if (dxfColor == AcadColor.BYLAYER)
78
                        g.setColor(layer.getColor());
79
                else
80
                        g.setColor(AcadColor.getColor(dxfColor));
81 32 luisw
                newGP(vp);
82 2 luisw
                g.draw(gp);
83
        }
84
85 91 luisw
        private void newGP(ViewPortData vp) {
86 32 luisw
                //if (gp != null) return;
87
                Point2D.Double pt0 = new Point2D.Double(0.0, 0.0);
88
                Point2D.Double pt1 = new Point2D.Double(0.0, 0.0);
89
                vp.mat.transform((Point2D) pts[0], pt0);
90
                vp.mat.transform((Point2D) pts[1], pt1);
91 2 luisw
                gp = new GeneralPath();
92 32 luisw
                gp.moveTo((float)pt0.getX(), (float)pt0.getY());
93
                gp.lineTo((float)pt1.getX(), (float)pt1.getY());
94 2 luisw
        }
95 1607 jmorell
96
        /**
97
         * 050222,jmorell: Escritura de l?neas en un DXF2000.
98 13 luisw
         */
99 14 luisw
        public String toDxfString() {
100 1607 jmorell
                StringBuffer sb = null;
101
                sb = new StringBuffer( DxfGroup.toString(0, "LINE") );
102
                sb.append( DxfGroup.toString(5, getHandle()) );
103
                sb.append( DxfGroup.toString(100, "AcDbEntity") );
104
                sb.append( DxfGroup.toString(8, layer.getName()) );
105
                sb.append( DxfGroup.toString(62, dxfColor) );
106
                sb.append( DxfGroup.toString(100, "AcDbLine") );
107
                sb.append( DxfGroup.toString(10, pts[0].getX(), 6) );
108
                sb.append( DxfGroup.toString(20, pts[0].getY(), 6) );
109
                sb.append( DxfGroup.toString(11, pts[1].getX(), 6) );
110
                sb.append( DxfGroup.toString(21, pts[1].getY(), 6) );
111
                return sb.toString();
112 13 luisw
        }
113 27 luisw
        /**
114
         * @return
115
         */
116
        public Point2D[] getPts() {
117
                return pts;
118
        }
119 2 luisw
}