svn-gvsig-desktop / branches / CqCMSGisPlanet / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfSolid.java @ 1932
History | View | Annotate | Download (2.83 KB)
1 |
/*
|
---|---|
2 |
* Created on 09-may-2004
|
3 |
*
|
4 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
5 |
*/
|
6 |
package org.cresques.px.dxf; |
7 |
|
8 |
import java.awt.Color; |
9 |
import java.awt.Graphics2D; |
10 |
import java.awt.geom.GeneralPath; |
11 |
import java.awt.geom.Point2D; |
12 |
|
13 |
import org.cresques.cts.ICoordTrans; |
14 |
import org.cresques.cts.IProjection; |
15 |
import org.cresques.geo.ViewPortData; |
16 |
import org.cresques.px.Extent; |
17 |
|
18 |
/**
|
19 |
* Entidad SOLID de AutoCAD
|
20 |
*
|
21 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
22 |
*/
|
23 |
public class DxfSolid extends DxfEntity { |
24 |
final static Color baseColor = new Color(69, 106, 121); |
25 |
//Vector points = null;
|
26 |
Point2D[] pts; |
27 |
GeneralPath gp = null; |
28 |
boolean closed = true; |
29 |
|
30 |
public DxfSolid(IProjection proj, DxfLayer layer, Point2D[] pts) { |
31 |
super(proj, layer);
|
32 |
Point2D aux = pts[2]; |
33 |
pts[2] = pts[3]; |
34 |
pts[3] = aux;
|
35 |
this.pts = pts;
|
36 |
extent = new Extent();
|
37 |
for (int i=0; i<pts.length; i++) { |
38 |
extent.add(pts[i]); |
39 |
} |
40 |
} |
41 |
|
42 |
private Color color = baseColor; //Color(255,214,132,255); |
43 |
|
44 |
public Color c() {return color;} |
45 |
public Color c(Color color) {this.color = color; return color;} |
46 |
|
47 |
public void reProject(ICoordTrans rp) { |
48 |
Point2D [] savePts = pts; |
49 |
|
50 |
pts = new Point2D[savePts.length]; |
51 |
extent = new Extent();
|
52 |
Point2D ptDest = null; |
53 |
for (int i=0; i<savePts.length; i++) { |
54 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
55 |
ptDest = rp.convert((Point2D) savePts[i], ptDest);
|
56 |
pts[i] = ptDest; |
57 |
extent.add(ptDest); |
58 |
} |
59 |
setProjection(rp.getPDest()); |
60 |
} |
61 |
|
62 |
public void draw(Graphics2D g, ViewPortData vp) { |
63 |
//System.out.println("Va a pintar un solid");
|
64 |
Color color = null; |
65 |
if (dxfColor == AcadColor.BYLAYER)
|
66 |
//g.setColor(layer.getColor());
|
67 |
color = layer.getColor(); |
68 |
else
|
69 |
//g.setColor(AcadColor.getColor(dxfColor));
|
70 |
color = AcadColor.getColor(dxfColor); |
71 |
newGP(vp); |
72 |
if (closed) {
|
73 |
g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x20)); |
74 |
g.fill(gp); |
75 |
} |
76 |
g.setColor(color); |
77 |
g.draw(gp); |
78 |
} |
79 |
|
80 |
private void newGP(ViewPortData vp) { |
81 |
//if (gp != null) return;
|
82 |
gp = new GeneralPath(); |
83 |
Point2D pt0 = null, pt=null, pt1=null; |
84 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
85 |
//System.out.println("pts.length = " + pts.length);
|
86 |
for (int i=0; i<pts.length; i++) { |
87 |
pt1 = (Point2D)pts[i];
|
88 |
vp.mat.transform(pt1, ptTmp); |
89 |
if (pt0 == null) { |
90 |
pt0 = ptTmp; |
91 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
92 |
} else {
|
93 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
94 |
} |
95 |
} |
96 |
if (closed) {
|
97 |
gp.closePath(); |
98 |
} |
99 |
} |
100 |
/* (non-Javadoc)
|
101 |
* @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
|
102 |
*/
|
103 |
public String toDxfString() { |
104 |
// TODO Auto-generated method stub
|
105 |
return ""; |
106 |
} |
107 |
/**
|
108 |
* @return
|
109 |
*/
|
110 |
public Point2D[] getPts() { |
111 |
return pts;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* @return
|
116 |
*/
|
117 |
/*public GeneralPath getGeneralPath(ViewPort vp) {
|
118 |
newGP(vp);
|
119 |
return (GeneralPath) gp.clone();
|
120 |
}*/
|
121 |
|
122 |
} |