svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfPolyline.java @ 28
History | View | Annotate | Download (3.28 KB)
1 |
/*
|
---|---|
2 |
* Created on 30-abr-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.AffineTransform; |
12 |
import java.awt.geom.GeneralPath; |
13 |
import java.awt.geom.Point2D; |
14 |
import java.util.Iterator; |
15 |
import java.util.Vector; |
16 |
|
17 |
import org.cresques.geo.Projection; |
18 |
import org.cresques.geo.ReProjection; |
19 |
import org.cresques.geo.ViewPort; |
20 |
import org.cresques.io.DxfGroup; |
21 |
import org.cresques.px.Extent; |
22 |
|
23 |
/**
|
24 |
* Polilynea de autocad
|
25 |
*
|
26 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
27 |
*/
|
28 |
|
29 |
public class DxfPolyline extends DxfEntity { |
30 |
final static Color baseColor = new Color(69, 106, 121); |
31 |
Vector pts = null; |
32 |
GeneralPath gp = null; |
33 |
int flags = 0; |
34 |
boolean closed = false; |
35 |
|
36 |
public DxfPolyline(Projection proj, DxfLayer layer) {
|
37 |
super(proj, layer);
|
38 |
extent = new Extent();
|
39 |
pts = new Vector(); |
40 |
} |
41 |
|
42 |
public void add(Point2D pt) { |
43 |
pts.add(pt); |
44 |
extent.add(pt); |
45 |
} |
46 |
|
47 |
private Color color = baseColor; //Color(255,214,132,255); |
48 |
|
49 |
public Color c() {return color;} |
50 |
public Color c(Color color) {this.color = color; return color;} |
51 |
|
52 |
public void reProject(ReProjection rp) { |
53 |
Vector savePts = pts;
|
54 |
|
55 |
pts = new Vector(); |
56 |
extent = new Extent();
|
57 |
Point2D ptDest = null; |
58 |
for (int i=0; i<savePts.size(); i++) { |
59 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
60 |
rp.convert((Point2D) savePts.get(i), ptDest);
|
61 |
pts.add(ptDest); |
62 |
extent.add(ptDest); |
63 |
} |
64 |
setProjection(rp.getPDest()); |
65 |
} |
66 |
|
67 |
public void draw(Graphics2D g, ViewPort vp) { |
68 |
AffineTransform msave=g.getTransform();
|
69 |
g.setTransform(vp.mat); |
70 |
// pinto el poligono si es preciso
|
71 |
if (dxfColor == AcadColor.BYLAYER)
|
72 |
g.setColor(layer.getColor()); |
73 |
else
|
74 |
g.setColor(AcadColor.getColor(dxfColor)); |
75 |
newGP(); |
76 |
g.draw(gp); |
77 |
g.setTransform(msave); |
78 |
} |
79 |
|
80 |
private void newGP() { |
81 |
if (gp != null) return; |
82 |
gp = new GeneralPath(); |
83 |
Point2D pt0 = null, pt=null, pt1=null; |
84 |
Iterator iter = pts.iterator();
|
85 |
while (iter.hasNext()) {
|
86 |
pt1 = (Point2D) iter.next();
|
87 |
if (pt0 == null) { |
88 |
pt0 = pt1; |
89 |
gp.moveTo((float)pt1.getX(), (float)pt1.getY()); |
90 |
} else {
|
91 |
//g.draw(new Line2D.Double(pt,pt1));
|
92 |
gp.lineTo((float)pt1.getX(), (float)pt1.getY()); |
93 |
} |
94 |
//pt = pt1;
|
95 |
} |
96 |
if (closed) {
|
97 |
//gp.closePath();
|
98 |
} |
99 |
} |
100 |
|
101 |
/**
|
102 |
* Convierte a DXF.
|
103 |
*
|
104 |
* @return Entity como String Dxf
|
105 |
*/
|
106 |
public String toDxfString() { |
107 |
StringBuffer sb = null; |
108 |
sb = new StringBuffer( DxfGroup.toString(0, "POLYLINE") ); |
109 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
110 |
sb.append( DxfGroup.toString(62, dxfColor) );
|
111 |
sb.append( DxfGroup.toString(70, flags) );
|
112 |
sb.append( DxfGroup.toString(66, 1) ); |
113 |
Point2D pt = null; |
114 |
Iterator iter = pts.iterator();
|
115 |
while (iter.hasNext()) {
|
116 |
pt = (Point2D) iter.next();
|
117 |
sb.append( DxfGroup.toString(0, "VERTEX") ); |
118 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
119 |
sb.append( DxfGroup.toString(10, pt.getX(), 6) ); |
120 |
sb.append( DxfGroup.toString(20, pt.getY(), 6) ); |
121 |
sb.append( DxfGroup.toString(30, 0.0, 6) ); |
122 |
} |
123 |
sb.append( DxfGroup.toString(0, "SEQEND") ); |
124 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
125 |
return sb.toString();
|
126 |
} |
127 |
/**
|
128 |
* @return
|
129 |
*/
|
130 |
public GeneralPath getGeneralPath() { |
131 |
newGP(); |
132 |
return (GeneralPath) gp.clone(); |
133 |
} |
134 |
|
135 |
public int getFlags() { |
136 |
return flags;
|
137 |
} |
138 |
|
139 |
} |