root / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfPolyline.java @ 95
History | View | Annotate | Download (4.62 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.GeneralPath; |
12 |
import java.awt.geom.Point2D; |
13 |
import java.util.Iterator; |
14 |
import java.util.Vector; |
15 |
|
16 |
import org.cresques.cts.ICoordTrans; |
17 |
import org.cresques.cts.IProjection; |
18 |
import org.cresques.geo.ViewPortData; |
19 |
import org.cresques.io.DxfGroup; |
20 |
import org.cresques.px.Extent; |
21 |
|
22 |
/**
|
23 |
* Polilynea de autocad
|
24 |
*
|
25 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
26 |
*/
|
27 |
|
28 |
public class DxfPolyline extends DxfEntity { |
29 |
final static Color baseColor = new Color(69, 106, 121); |
30 |
Vector pts = null; |
31 |
Vector faces = null; |
32 |
GeneralPath gp = null; |
33 |
int flags = 0; |
34 |
boolean closed = false; |
35 |
boolean hasFaces = false; |
36 |
|
37 |
public DxfPolyline(IProjection proj, DxfLayer layer) {
|
38 |
super(proj, layer);
|
39 |
extent = new Extent();
|
40 |
pts = new Vector(); |
41 |
} |
42 |
|
43 |
public void add(Point2D pt) { |
44 |
pts.add(pt); |
45 |
extent.add(pt); |
46 |
} |
47 |
|
48 |
public void addFace(int [] face) { |
49 |
hasFaces = true;
|
50 |
if (faces == null) |
51 |
faces = new Vector(); |
52 |
faces.add(face); |
53 |
} |
54 |
|
55 |
private Color color = baseColor; //Color(255,214,132,255); |
56 |
|
57 |
public Color c() {return color;} |
58 |
public Color c(Color color) {this.color = color; return color;} |
59 |
|
60 |
public void reProject(ICoordTrans rp) { |
61 |
Vector savePts = pts;
|
62 |
|
63 |
pts = new Vector(); |
64 |
extent = new Extent();
|
65 |
Point2D ptDest = null; |
66 |
for (int i=0; i<savePts.size(); i++) { |
67 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
68 |
ptDest = rp.convert((Point2D) savePts.get(i), ptDest);
|
69 |
pts.add(ptDest); |
70 |
extent.add(ptDest); |
71 |
} |
72 |
setProjection(rp.getPDest()); |
73 |
} |
74 |
|
75 |
public void draw(Graphics2D g, ViewPortData vp) { |
76 |
//AffineTransform msave=g.getTransform();
|
77 |
//g.setTransform(vp.mat);
|
78 |
Color color = null; |
79 |
// pinto el poligono si es preciso
|
80 |
if (dxfColor == AcadColor.BYLAYER)
|
81 |
color = layer.getColor(); |
82 |
else
|
83 |
color = AcadColor.getColor(dxfColor); |
84 |
newGP(vp); |
85 |
if (closed) {
|
86 |
g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x20)); |
87 |
g.fill(gp); |
88 |
} |
89 |
g.setColor(color); |
90 |
g.draw(gp); |
91 |
//g.setTransform(msave);
|
92 |
} |
93 |
|
94 |
private void newGP(ViewPortData vp) { |
95 |
//if (gp != null) return;
|
96 |
gp = new GeneralPath(); |
97 |
Point2D pt0 = null, pt=null, pt1=null; |
98 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
99 |
if (! hasFaces) {
|
100 |
Iterator iter = pts.iterator();
|
101 |
while (iter.hasNext()) {
|
102 |
pt1 = (Point2D) iter.next();
|
103 |
vp.mat.transform(pt1, ptTmp); |
104 |
if (pt0 == null) { |
105 |
pt0 = ptTmp; |
106 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
107 |
} else {
|
108 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
109 |
} |
110 |
} |
111 |
if (closed) {
|
112 |
gp.closePath(); |
113 |
} |
114 |
} else {
|
115 |
System.out.println("POLYLINE: caras=" +faces.size()+", puntos="+ pts.size()); |
116 |
int [] face; |
117 |
int i0, i1;
|
118 |
Iterator iter = faces.iterator();
|
119 |
while (iter.hasNext()) {
|
120 |
face = (int []) iter.next(); |
121 |
|
122 |
i0 = face[3];
|
123 |
for (int i=0; i<4; i++) { |
124 |
i1 = face[i]; |
125 |
if (i0 > 0) { |
126 |
pt0 = (Point2D) pts.get(i0-1); |
127 |
vp.mat.transform(pt0, ptTmp); |
128 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
129 |
pt1 = (Point2D) pts.get(Math.abs(i1)-1); |
130 |
vp.mat.transform(pt1, ptTmp); |
131 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
132 |
} |
133 |
i0 = i1; |
134 |
} |
135 |
} |
136 |
} |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Convierte a DXF.
|
141 |
*
|
142 |
* @return Entity como String Dxf
|
143 |
*/
|
144 |
public String toDxfString() { |
145 |
StringBuffer sb = null; |
146 |
sb = new StringBuffer( DxfGroup.toString(0, "POLYLINE") ); |
147 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
148 |
sb.append( DxfGroup.toString(62, dxfColor) );
|
149 |
sb.append( DxfGroup.toString(70, flags) );
|
150 |
sb.append( DxfGroup.toString(66, 1) ); |
151 |
Point2D pt = null; |
152 |
Iterator iter = pts.iterator();
|
153 |
while (iter.hasNext()) {
|
154 |
pt = (Point2D) iter.next();
|
155 |
sb.append( DxfGroup.toString(0, "VERTEX") ); |
156 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
157 |
sb.append( DxfGroup.toString(10, pt.getX(), 6) ); |
158 |
sb.append( DxfGroup.toString(20, pt.getY(), 6) ); |
159 |
sb.append( DxfGroup.toString(30, 0.0, 6) ); |
160 |
} |
161 |
sb.append( DxfGroup.toString(0, "SEQEND") ); |
162 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
163 |
return sb.toString();
|
164 |
} |
165 |
/**
|
166 |
* @return
|
167 |
*/
|
168 |
public GeneralPath getGeneralPath(ViewPortData vp) { |
169 |
newGP(vp); |
170 |
return (GeneralPath) gp.clone(); |
171 |
} |
172 |
|
173 |
public int getFlags() { |
174 |
return flags;
|
175 |
} |
176 |
|
177 |
//public static DxfEntityList createArc(Point2D coord1, Point2D coord2, double bulge, Point3D xtru) {
|
178 |
public static Vector createArc(Point2D coord1, Point2D coord2, double bulge) { |
179 |
//return new DxfCalArcs(coord1, coord2, bulge).getPoints(1, xtru);
|
180 |
return new DxfCalArcs(coord1, coord2, bulge).getPoints(1); |
181 |
} |
182 |
|
183 |
} |