root / branches / v2_0_0_prep / libraries / libDXF / src / org / gvsig / dxf / px / dxf / DxfLine.java @ 29630
History | View | Annotate | Download (4.85 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.gvsig.dxf.px.dxf; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.geom.GeneralPath; |
29 |
import java.awt.geom.Point2D; |
30 |
|
31 |
import org.cresques.cts.ICoordTrans; |
32 |
import org.cresques.cts.IProjection; |
33 |
import org.cresques.geo.ViewPortData; |
34 |
import org.cresques.px.Extent; |
35 |
import org.gvsig.dxf.io.DxfGroup; |
36 |
|
37 |
|
38 |
/**
|
39 |
* Entidad LINE de un fichero DXF.
|
40 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
41 |
* @author jmorell
|
42 |
*/
|
43 |
public class DxfLine extends DxfEntity { |
44 |
final static Color baseColor = new Color(255, 106, 121); |
45 |
Point2D[] pts; |
46 |
GeneralPath gp = null; |
47 |
private Color color = baseColor; //Color(255,214,132,255); |
48 |
|
49 |
/**
|
50 |
* Constructor de DxfLine.
|
51 |
* @param proj, proyecci?n cartogr?fica en la que se encuentra la DxfLine.
|
52 |
* @param layer, capa del DXF en la que se encuentra la DxfLine.
|
53 |
* @param p1, punto inicial de la l?nea.
|
54 |
* @param p2, punto final de la l?nea.
|
55 |
*/
|
56 |
public DxfLine(IProjection proj, DxfLayer layer, Point2D p1, Point2D p2) { |
57 |
super(proj, layer);
|
58 |
extent = new Extent(p1, p2);
|
59 |
pts = new Point2D[2]; |
60 |
pts[0] = p1;
|
61 |
pts[1] = p2;
|
62 |
} |
63 |
|
64 |
/**
|
65 |
* Devuelve el color de la DxfLine.
|
66 |
* @return Color
|
67 |
*/
|
68 |
public Color c() { |
69 |
return color;
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* Establece el color de la DxfLine.
|
74 |
* @param color
|
75 |
* @return Color
|
76 |
*/
|
77 |
public Color c(Color color) { |
78 |
this.color = color;
|
79 |
|
80 |
return color;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Permite reproyectar una DxfLine dado un conjunto de coordenadas de transformaci?n.
|
85 |
* @param rp, coordenadas de transformaci?n.
|
86 |
*/
|
87 |
public void reProject(ICoordTrans rp) { |
88 |
Point2D[] savePts = pts; |
89 |
|
90 |
pts = new Point2D[2]; |
91 |
extent = new Extent();
|
92 |
|
93 |
Point2D ptDest = null; |
94 |
|
95 |
for (int i = 0; i < savePts.length; i++) { |
96 |
ptDest = rp.getPDest().createPoint(0.0, 0.0); |
97 |
ptDest = rp.convert((Point2D) savePts[i], ptDest);
|
98 |
pts[i] = ptDest; |
99 |
extent.add(ptDest); |
100 |
} |
101 |
|
102 |
setProjection(rp.getPDest()); |
103 |
} |
104 |
|
105 |
/**
|
106 |
* Permite dibujar una DxfLine.
|
107 |
*/
|
108 |
public void draw(Graphics2D g, ViewPortData vp) { |
109 |
if (dxfColor == AcadColor.BYLAYER) {
|
110 |
g.setColor(layer.getColor()); |
111 |
} else {
|
112 |
g.setColor(AcadColor.getColor(dxfColor)); |
113 |
} |
114 |
|
115 |
newGP(vp); |
116 |
g.draw(gp); |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Permite generar un GeneralPath partiendo del array de Point2D que conforma el
|
121 |
* DxfLine.
|
122 |
* @param vp
|
123 |
*/
|
124 |
private void newGP(ViewPortData vp) { |
125 |
//if (gp != null) return;
|
126 |
Point2D.Double pt0 = new Point2D.Double(0.0, 0.0); |
127 |
Point2D.Double pt1 = new Point2D.Double(0.0, 0.0); |
128 |
vp.mat.transform((Point2D) pts[0], pt0); |
129 |
vp.mat.transform((Point2D) pts[1], pt1); |
130 |
gp = new GeneralPath(); |
131 |
gp.moveTo((float) pt0.getX(), (float) pt0.getY()); |
132 |
gp.lineTo((float) pt1.getX(), (float) pt1.getY()); |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Permite la escritura de entidades DxfLine en un fichero DXF2000.
|
137 |
* @return String, la cadena que se escribir? en el fichero con la informaci?n
|
138 |
* de la DxfLine.
|
139 |
*/
|
140 |
public String toDxfString() { |
141 |
StringBuffer sb = null; |
142 |
sb = new StringBuffer(DxfGroup.toString(0, "LINE")); |
143 |
sb.append(DxfGroup.toString(5, getHandle()));
|
144 |
sb.append(DxfGroup.toString(100, "AcDbEntity")); |
145 |
sb.append(DxfGroup.toString(8, layer.getName()));
|
146 |
sb.append(DxfGroup.toString(62, dxfColor));
|
147 |
sb.append(DxfGroup.toString(100, "AcDbLine")); |
148 |
sb.append(DxfGroup.toString(10, pts[0].getX(), 6)); |
149 |
sb.append(DxfGroup.toString(20, pts[0].getY(), 6)); |
150 |
sb.append(DxfGroup.toString(11, pts[1].getX(), 6)); |
151 |
sb.append(DxfGroup.toString(21, pts[1].getY(), 6)); |
152 |
|
153 |
return sb.toString();
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Devuelve el array de puntos que conforman el DxfLine.
|
158 |
* @return Point2D[], puntos del DxfLine.
|
159 |
*/
|
160 |
public Point2D[] getPts() { |
161 |
return pts;
|
162 |
} |
163 |
} |