root / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfInsert.java @ 60
History | View | Annotate | Download (5.18 KB)
1 |
package org.cresques.px.dxf; |
---|---|
2 |
|
3 |
import java.awt.Graphics2D; |
4 |
import java.awt.geom.Point2D; |
5 |
|
6 |
import org.cresques.geo.Point3D; |
7 |
import org.cresques.geo.Projection; |
8 |
import org.cresques.geo.ReProjection; |
9 |
import org.cresques.geo.ViewPort; |
10 |
import org.cresques.px.Extent; |
11 |
import java.awt.Color; |
12 |
import java.awt.geom.GeneralPath; |
13 |
|
14 |
public class DxfInsert extends DxfEntity { |
15 |
|
16 |
Point2D pt;
|
17 |
Point3D scaleFactor; |
18 |
double rotAngle;
|
19 |
DxfBlock block = new DxfBlock(proj);
|
20 |
|
21 |
public DxfInsert(Projection proj, DxfLayer layer, DxfBlock block) {
|
22 |
super(proj, layer);
|
23 |
extent = new Extent();
|
24 |
pt = new Point2D.Double(); |
25 |
this.block = block;
|
26 |
} |
27 |
|
28 |
public void setPt(Point2D pt) { |
29 |
this.pt = pt;
|
30 |
extent.add(pt); |
31 |
} |
32 |
|
33 |
public void setScaleFactor(Point3D scaleFactor) { |
34 |
this.scaleFactor = scaleFactor;
|
35 |
} |
36 |
|
37 |
public void setRotAngle(double rotAngle) { |
38 |
this.rotAngle = rotAngle;
|
39 |
} |
40 |
|
41 |
public void reProject(ReProjection rp) { |
42 |
Point2D savePt = pt;
|
43 |
|
44 |
pt = new Point2D.Double(); |
45 |
extent = new Extent();
|
46 |
Point2D ptDest = null; |
47 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
48 |
if (savePt == null) |
49 |
ptDest = null;
|
50 |
else {
|
51 |
rp.convert((Point2D) savePt, ptDest);
|
52 |
extent.add(ptDest); |
53 |
} |
54 |
pt = ptDest; |
55 |
setProjection(rp.getPDest()); |
56 |
} |
57 |
|
58 |
public void draw(Graphics2D g, ViewPort vp) { |
59 |
GeneralPath gp = null; |
60 |
|
61 |
for (int i=0; i<block.blkElements.size(); i++) { |
62 |
if (block.blkElements.get(i) instanceof DxfPoint) { |
63 |
Point2D point2D = new Point2D.Double(); |
64 |
point2D = ((DxfPoint)block.blkElements.get(i)).pt; |
65 |
|
66 |
//AffineTransform msave=g.getTransform();
|
67 |
//g.setTransform(vp.mat);
|
68 |
if (dxfColor == AcadColor.BYLAYER)
|
69 |
g.setColor(layer.getColor()); |
70 |
else {
|
71 |
dxfColor = ((DxfPoint)block.blkElements.get(i)).dxfColor; |
72 |
g.setColor(AcadColor.getColor(dxfColor)); |
73 |
} |
74 |
Point2D ptT = new Point2D.Double(0, 0); |
75 |
vp.mat.transform(ptT, ptT); |
76 |
ptT.setLocation(point2D.getX(), point2D.getY()); |
77 |
vp.mat.transform(ptT, ptT); |
78 |
g.drawLine((int) ptT.getX(), (int)ptT.getY(), (int) ptT.getX(), (int)ptT.getY()); |
79 |
//g.setTransform(msave);
|
80 |
} else if (block.blkElements.get(i) instanceof DxfLine) { |
81 |
Point2D p1 = new Point2D.Double(); |
82 |
Point2D p2 = new Point2D.Double(); |
83 |
p1 = ((DxfLine)block.blkElements.get(i)).pts[0];
|
84 |
p2 = ((DxfLine)block.blkElements.get(i)).pts[1];
|
85 |
extent = new Extent(p1, p2);
|
86 |
if (dxfColor == AcadColor.BYLAYER)
|
87 |
g.setColor(layer.getColor()); |
88 |
else {
|
89 |
dxfColor = ((DxfPoint)block.blkElements.get(i)).dxfColor; |
90 |
g.setColor(AcadColor.getColor(dxfColor)); |
91 |
} |
92 |
|
93 |
Point2D.Double pt0 = new Point2D.Double(0.0, 0.0); |
94 |
Point2D.Double pt1 = new Point2D.Double(0.0, 0.0); |
95 |
vp.mat.transform((Point2D) p1, pt0);
|
96 |
vp.mat.transform((Point2D) p2, pt1);
|
97 |
gp = new GeneralPath(); |
98 |
gp.moveTo((float)pt0.getX(), (float)pt0.getY()); |
99 |
gp.lineTo((float)pt1.getX(), (float)pt1.getY()); |
100 |
|
101 |
g.draw(gp); |
102 |
} else if (block.blkElements.get(i) instanceof DxfPolyline) { |
103 |
|
104 |
} |
105 |
} |
106 |
|
107 |
} |
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
|
111 |
*/
|
112 |
public String toDxfString() { |
113 |
// TODO Auto-generated method stub
|
114 |
return ""; |
115 |
} |
116 |
|
117 |
/*public static DxfEntity[] moveGeometryCollection(DxfEntityList gc, Point2D pt, Point3D scale, double rotation) {
|
118 |
DxfEntity g;
|
119 |
DxfEntity geos[] = new DxfEntity[gc.entities.size()];
|
120 |
String typeGeo;
|
121 |
|
122 |
for (int i=0; i<gc.entities.size(); i++) {
|
123 |
g = (DxfEntity) gc.entities.get(i);
|
124 |
//typeGeo = g.getGeometryType();
|
125 |
if (g instanceof DxfPoint) {
|
126 |
geos[i] = moveDxfPoint((DxfPoint)g, pt, scale, rotation);
|
127 |
}
|
128 |
if (g instanceof DxfLine) {
|
129 |
geos[i] = moveDxfLine((DxfLine)g, pt, scale, rotation);
|
130 |
}
|
131 |
if (g instanceof DxfPolyline) {
|
132 |
geos[i] = moveDxfPolyline((DxfPolyline)g, pt, scale, rotation);
|
133 |
}
|
134 |
//else if (g instanceof DxfEntityList) {
|
135 |
// geos[i] = moveGeometryCollection((DxfEntityList)g, pt, scale, rotation);
|
136 |
//}
|
137 |
else {
|
138 |
System.out.println("NO CONTEMPLA " + typeGeo + " en "+ i );
|
139 |
}
|
140 |
}
|
141 |
return geos;
|
142 |
}
|
143 |
|
144 |
public static DxfPoint moveDxfPoint(DxfPoint g, Point2D pt, Point3D scale, double rotation) {
|
145 |
Point2D c, c2;
|
146 |
double x,y,z;
|
147 |
double alfa = rotation*Math.PI/180.0;
|
148 |
c2 = g.pt;
|
149 |
|
150 |
x = (c2.getX()*Math.cos(alfa) + c2.getY()*(-1)*Math.sin(alfa)) * scale.getX();
|
151 |
y = (c2.getX()*Math.sin(alfa) + c2.getY()*Math.cos(alfa)) * scale.getY();
|
152 |
//z = c2.z * scale.z;
|
153 |
|
154 |
c = new Point2D.Double(pt.getX() + x, pt.getY() + y);
|
155 |
DxfPoint p_out = g;
|
156 |
p_out.pt.setLocation(c);
|
157 |
return p_out;
|
158 |
}
|
159 |
|
160 |
public static DxfPolyline moveDxfPolyline(DxfPolyline g, Point2D pt, Point3D scale, double rotation) {
|
161 |
Point2D c[] = new Point2D[ g.pts.size()], c2;
|
162 |
double x,y,z;
|
163 |
|
164 |
double alfa = rotation*Math.PI/180.0;
|
165 |
|
166 |
for (int i=0; i<c.length; i++) {
|
167 |
c2 = (Point2D)g.pts.get(i);
|
168 |
|
169 |
x = ((c2.getX()*scale.getX())*Math.cos(alfa) + (c2.getY()*scale.getY())*(-1)*Math.sin(alfa));
|
170 |
y = ((c2.getX()*scale.getX())*Math.sin(alfa) + (c2.getY()*scale.getY())*Math.cos(alfa));
|
171 |
//z = c2.z*scale.z;
|
172 |
|
173 |
double X = pt.getX() + x; //+ins.x;
|
174 |
double Y = pt.getY() + y; // +ins.y;
|
175 |
//double Z = pt.z + z; // +ins.z;
|
176 |
|
177 |
c[i] = new Point2D.Double(X, Y);
|
178 |
}
|
179 |
DxfPolyline pol_out = g;
|
180 |
//pol_out.
|
181 |
return pol_out;
|
182 |
}*/
|
183 |
|
184 |
} |