svn-gvsig-desktop / branches / v02_desarrollo / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfPolyline.java @ 1607
History | View | Annotate | Download (5.85 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 |
* jmorell: Implementaci?n extra de bulges necesaria para el piloto de CAD.
|
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 |
private Vector bulges; |
37 |
|
38 |
public DxfPolyline(IProjection proj, DxfLayer layer) {
|
39 |
super(proj, layer);
|
40 |
extent = new Extent();
|
41 |
pts = new Vector(); |
42 |
bulges = new Vector(); |
43 |
} |
44 |
|
45 |
public void add(Point2D pt) { |
46 |
pts.add(pt); |
47 |
extent.add(pt); |
48 |
} |
49 |
|
50 |
/**
|
51 |
* 050301, jmorell: Soluci?n provisional para implementar la lectura de polil?neas
|
52 |
* con arcos.
|
53 |
* @param pt
|
54 |
*/
|
55 |
public void addBulge(Double bulge) { |
56 |
bulges.add(bulge); |
57 |
} |
58 |
|
59 |
public void addFace(int [] face) { |
60 |
hasFaces = true;
|
61 |
if (faces == null) |
62 |
faces = new Vector(); |
63 |
faces.add(face); |
64 |
} |
65 |
|
66 |
private Color color = baseColor; //Color(255,214,132,255); |
67 |
|
68 |
public Color c() {return color;} |
69 |
public Color c(Color color) {this.color = color; return color;} |
70 |
|
71 |
public void reProject(ICoordTrans rp) { |
72 |
Vector savePts = pts;
|
73 |
|
74 |
pts = new Vector(); |
75 |
extent = new Extent();
|
76 |
Point2D ptDest = null; |
77 |
for (int i=0; i<savePts.size(); i++) { |
78 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
79 |
ptDest = rp.convert((Point2D) savePts.get(i), ptDest);
|
80 |
pts.add(ptDest); |
81 |
extent.add(ptDest); |
82 |
} |
83 |
setProjection(rp.getPDest()); |
84 |
} |
85 |
|
86 |
public void draw(Graphics2D g, ViewPortData vp) { |
87 |
//AffineTransform msave=g.getTransform();
|
88 |
//g.setTransform(vp.mat);
|
89 |
Color color = null; |
90 |
// pinto el poligono si es preciso
|
91 |
if (dxfColor == AcadColor.BYLAYER)
|
92 |
color = layer.getColor(); |
93 |
else
|
94 |
color = AcadColor.getColor(dxfColor); |
95 |
System.out.println("PLINE color="+color); |
96 |
newGP(vp); |
97 |
if (closed) {
|
98 |
g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x20)); |
99 |
g.fill(gp); |
100 |
} |
101 |
g.setColor(color); |
102 |
g.draw(gp); |
103 |
//g.setTransform(msave);
|
104 |
} |
105 |
|
106 |
private void newGP(ViewPortData vp) { |
107 |
//if (gp != null) return;
|
108 |
gp = new GeneralPath(); |
109 |
Point2D pt0 = null, pt=null, pt1=null; |
110 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
111 |
if (! hasFaces) {
|
112 |
Iterator iter = pts.iterator();
|
113 |
while (iter.hasNext()) {
|
114 |
pt1 = (Point2D) iter.next();
|
115 |
vp.mat.transform(pt1, ptTmp); |
116 |
if (pt0 == null) { |
117 |
pt0 = ptTmp; |
118 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
119 |
} else {
|
120 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
121 |
} |
122 |
} |
123 |
if (closed) {
|
124 |
gp.closePath(); |
125 |
} |
126 |
} else {
|
127 |
System.out.println("POLYLINE: caras=" +faces.size()+", puntos="+ pts.size()); |
128 |
int [] face; |
129 |
int i0, i1;
|
130 |
Iterator iter = faces.iterator();
|
131 |
while (iter.hasNext()) {
|
132 |
face = (int []) iter.next(); |
133 |
|
134 |
i0 = face[3];
|
135 |
for (int i=0; i<4; i++) { |
136 |
i1 = face[i]; |
137 |
if (i0 > 0) { |
138 |
pt0 = (Point2D) pts.get(i0-1); |
139 |
vp.mat.transform(pt0, ptTmp); |
140 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
141 |
pt1 = (Point2D) pts.get(Math.abs(i1)-1); |
142 |
vp.mat.transform(pt1, ptTmp); |
143 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
144 |
} |
145 |
i0 = i1; |
146 |
} |
147 |
} |
148 |
} |
149 |
} |
150 |
|
151 |
/**
|
152 |
* Convierte a DXF.
|
153 |
*
|
154 |
* @return Entity como String Dxf
|
155 |
*/
|
156 |
public String toDxfString() { |
157 |
StringBuffer sb = null; |
158 |
sb = new StringBuffer( DxfGroup.toString(0, "POLYLINE") ); |
159 |
sb.append( DxfGroup.toString(5, getHandle()) );
|
160 |
sb.append( DxfGroup.toString(100, "AcDbEntity") ); |
161 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
162 |
sb.append( DxfGroup.toString(62, dxfColor) );
|
163 |
sb.append( DxfGroup.toString(100, "AcDb2dPolyline") ); |
164 |
sb.append( DxfGroup.toString(70, flags) );
|
165 |
sb.append( DxfGroup.toString(66, 1) ); |
166 |
Point2D pt = null; |
167 |
Iterator iter = pts.iterator();
|
168 |
System.out.println("pts.size() = " + pts.size()); |
169 |
while (iter.hasNext()) {
|
170 |
pt = (Point2D) iter.next();
|
171 |
sb.append( DxfGroup.toString(0, "VERTEX") ); |
172 |
sb.append( DxfGroup.toString(5, getHandle()) );
|
173 |
sb.append( DxfGroup.toString(100, "AcDbEntity") ); |
174 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
175 |
sb.append( DxfGroup.toString(100, "AcDbVertex") ); |
176 |
sb.append( DxfGroup.toString(100, "AcDb2dVertex") ); |
177 |
sb.append( DxfGroup.toString(10, pt.getX(), 6) ); |
178 |
sb.append( DxfGroup.toString(20, pt.getY(), 6) ); |
179 |
sb.append( DxfGroup.toString(30, 0.0, 6) ); |
180 |
} |
181 |
sb.append( DxfGroup.toString(0, "SEQEND") ); |
182 |
sb.append( DxfGroup.toString(5, getHandle()) );
|
183 |
sb.append( DxfGroup.toString(100, "AcDbEntity") ); |
184 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
185 |
return sb.toString();
|
186 |
} |
187 |
/**
|
188 |
* @return
|
189 |
*/
|
190 |
public GeneralPath getGeneralPath(ViewPortData vp) { |
191 |
newGP(vp); |
192 |
return (GeneralPath) gp.clone(); |
193 |
} |
194 |
|
195 |
public int getFlags() { |
196 |
return flags;
|
197 |
} |
198 |
|
199 |
//public static DxfEntityList createArc(Point2D coord1, Point2D coord2, double bulge, Point3D xtru) {
|
200 |
public static Vector createArc(Point2D coord1, Point2D coord2, double bulge) { |
201 |
//return new DxfCalArcs(coord1, coord2, bulge).getPoints(1, xtru);
|
202 |
return new DxfCalArcs(coord1, coord2, bulge).getPoints(1); |
203 |
} |
204 |
|
205 |
/**
|
206 |
* @return Returns the pts.
|
207 |
*/
|
208 |
public Vector getPts() { |
209 |
return pts;
|
210 |
} |
211 |
/**
|
212 |
* @param pts The pts to set.
|
213 |
*/
|
214 |
public void setPts(Vector pts) { |
215 |
this.pts = pts;
|
216 |
} |
217 |
/**
|
218 |
* @return Returns the bulges.
|
219 |
*/
|
220 |
public Vector getBulges() { |
221 |
return bulges;
|
222 |
} |
223 |
/**
|
224 |
* @param bulges The bulges to set.
|
225 |
*/
|
226 |
public void setBulges(Vector bulges) { |
227 |
this.bulges = bulges;
|
228 |
} |
229 |
} |