Revision 81
trunk/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfEntityMaker.java | ||
---|---|---|
532 | 532 |
} |
533 | 533 |
} |
534 | 534 |
public void createSolid(DxfGroupVector grp) throws Exception { |
535 |
double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0, z3 = 0.0, z4 = 0.0; |
|
536 |
DxfGroup g = null; |
|
537 |
//Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null; |
|
538 |
Point2D[] pts = new Point2D[4]; |
|
535 | 539 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8)); |
540 |
|
|
541 |
x = grp.getDataAsDouble(10); |
|
542 |
y = grp.getDataAsDouble(20); |
|
543 |
if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30); |
|
544 |
pts[0] = proj.createPoint(x, y); |
|
545 |
x = grp.getDataAsDouble(11); |
|
546 |
y = grp.getDataAsDouble(21); |
|
547 |
if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31); |
|
548 |
pts[1] = proj.createPoint(x, y); |
|
549 |
x = grp.getDataAsDouble(12); |
|
550 |
y = grp.getDataAsDouble(22); |
|
551 |
if (grp.hasCode(32)) z3 = grp.getDataAsDouble(32); |
|
552 |
pts[2] = proj.createPoint(x, y); |
|
553 |
x = grp.getDataAsDouble(13); |
|
554 |
y = grp.getDataAsDouble(23); |
|
555 |
if (grp.hasCode(33)) z2 = grp.getDataAsDouble(33); |
|
556 |
pts[3] = proj.createPoint(x, y); |
|
557 |
if (grp.hasCode(210)) |
|
558 |
xtruX = grp.getDataAsDouble(210); |
|
559 |
if (grp.hasCode(220)) |
|
560 |
xtruY = grp.getDataAsInt(220); |
|
561 |
if (grp.hasCode(230)) |
|
562 |
xtruZ = grp.getDataAsInt(230); |
|
563 |
Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1); |
|
564 |
Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2); |
|
565 |
Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3); |
|
566 |
Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4); |
|
567 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ); |
|
568 |
Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru); |
|
569 |
Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru); |
|
570 |
Point2D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru); |
|
571 |
Point2D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru); |
|
572 |
pts[0].setLocation(point_out1); |
|
573 |
pts[1].setLocation(point_out2); |
|
574 |
pts[2].setLocation(point_out3); |
|
575 |
pts[3].setLocation(point_out4); |
|
576 |
DxfSolid entity = new DxfSolid(proj, layer, pts); |
|
577 |
if (grp.hasCode(62)) { |
|
578 |
entity.dxfColor = grp.getDataAsInt(62); |
|
579 |
} else { |
|
580 |
//entity.dxfColor = 0; |
|
581 |
} |
|
582 |
if (addingToBlock == false) { |
|
583 |
System.out.println("createLine(): A?adimos una linea a la lista de entidades"); |
|
584 |
entities.add(entity); |
|
585 |
} else { |
|
586 |
System.out.println("createLine(): A?adimos una linea al bloque " + iterator); |
|
587 |
blk.add(entity); |
|
588 |
} |
|
589 |
|
|
536 | 590 |
} |
537 | 591 |
public void createBlock(DxfGroupVector grp) throws Exception { |
538 | 592 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8)); |
... | ... | |
645 | 699 |
DxfLwPolyline dxfLwPolyline = null; |
646 | 700 |
DxfPoint dxfPoint = null; |
647 | 701 |
DxfText dxfText = null; |
702 |
DxfSolid dxfSolid = null; |
|
648 | 703 |
for (int i=0; i<entity.block.blkElements.size(); i++) { |
649 | 704 |
System.out.println("gestionaInserts: entity.block.blkElements.size() = " + entity.block.blkElements.size()); |
650 | 705 |
dxfEntity = (DxfEntity)entity.block.blkElements.get(i); |
... | ... | |
766 | 821 |
dxfTextt.pts[0] = point11; |
767 | 822 |
dxfTextt.pts[1] = point22; |
768 | 823 |
if (addingToBlock == false) entities.add(dxfTextt); |
824 |
} else if (dxfEntity instanceof DxfSolid) { |
|
825 |
dxfSolid = (DxfSolid)dxfEntity; |
|
826 |
Point2D[] points = new Point2D[dxfSolid.pts.length]; |
|
827 |
Point2D aux = dxfSolid.pts[2]; |
|
828 |
dxfSolid.pts[2] = dxfSolid.pts[3]; |
|
829 |
dxfSolid.pts[3] = aux; |
|
830 |
Point2D[] pointss = new Point2D[dxfSolid.pts.length]; |
|
831 |
for (int j=0; j<dxfSolid.pts.length; j++) { |
|
832 |
points[j] = (Point2D)dxfSolid.pts[j]; |
|
833 |
pointss[j] = new Point2D.Double(); |
|
834 |
//pointss[j].setLocation(entity.pt.getX() - entity.block.bPoint.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() - entity.block.bPoint.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
|
835 |
pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
|
836 |
//pointss[j].setLocation(entity.pt.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
|
837 |
} |
|
838 |
DxfSolid dxfSolidd = new DxfSolid(proj, layer, pointss); |
|
839 |
if (addingToBlock == false) entities.add(dxfSolidd); |
|
769 | 840 |
} else { |
770 | 841 |
System.out.println("gestionaInserts: Encontrado elemento desconocido"); |
771 | 842 |
} |
trunk/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfCalArcs.java | ||
---|---|---|
35 | 35 |
Point2D center; |
36 | 36 |
double radio, empieza, acaba; |
37 | 37 |
double z; |
38 |
|
|
39 |
double bulge; |
|
38 | 40 |
|
39 | 41 |
/** |
40 | 42 |
* Crea un Arc a partir de dos puntos y un pandeo. Se usa en POLYLINE |
... | ... | |
56 | 58 |
* @return El arco (this) |
57 | 59 |
*/ |
58 | 60 |
DxfCalArcs calculate(double bulge) { |
61 |
|
|
62 |
this.bulge = bulge; |
|
63 |
|
|
59 | 64 |
//Coordinate coordAux = new Coordinate(); |
60 | 65 |
Point2D coordAux = new Point2D.Double(); |
61 | 66 |
double d,aci,alfa,beta,landa,dd,aci2; |
... | ... | |
91 | 96 |
radio = (d/2.0)/(Math.sin(landa)); |
92 | 97 |
|
93 | 98 |
calculateEA(alfa); |
94 |
return this;
|
|
95 |
} else {
|
|
99 |
}
|
|
100 |
if (bulge < 0.0) {
|
|
96 | 101 |
// Aqui hay que tocar para que en vez del bulge negativo, saque el |
97 | 102 |
// positivo pero en el sentido de las agujas del reloj. |
98 |
beta = Math.atan(bulge); // * (-1));
|
|
103 |
beta = Math.atan((bulge) * (-1));
|
|
99 | 104 |
alfa = beta*4.0; |
100 | 105 |
landa = alfa/2.0; |
101 | 106 |
dd = (d/2.0)/(Math.tan(landa)); |
102 | 107 |
|
103 | 108 |
aci2 = aci; |
104 | 109 |
|
105 |
center.setLocation(coordAux.getX() + dd*Math.sin(aci2+(Math.PI/2.0)), coordAux.getY() + dd*Math.cos(aci2+(Math.PI/2.0)));
|
|
110 |
center.setLocation(coordAux.getX() + dd*Math.sin(aci2-(Math.PI/2.0)), coordAux.getY() + dd*Math.cos(aci2-(Math.PI/2.0)));
|
|
106 | 111 |
//center.z = coordAux.z; |
107 | 112 |
|
108 | 113 |
if (debug) System.out.println("CENTRO = " + center); |
... | ... | |
110 | 115 |
// Calculo del Radio |
111 | 116 |
radio = (d/2.0)/(Math.sin(landa)); |
112 | 117 |
|
113 |
calculateEA(alfa); |
|
114 |
return this; |
|
118 |
calculateEAInverse(alfa); |
|
115 | 119 |
} |
116 |
|
|
120 |
return this; |
|
117 | 121 |
} |
118 | 122 |
|
119 | 123 |
/** |
... | ... | |
129 | 133 |
if (debug) System.out.println("empieza = " + empieza + "\nacaba = " + acaba); |
130 | 134 |
} |
131 | 135 |
|
136 |
void calculateEAInverse(double alfa){ |
|
137 |
empieza = Math.atan2(coord2.getY()-center.getY(), coord2.getX()-center.getX()); |
|
138 |
acaba = (empieza + alfa); |
|
139 |
empieza = empieza*180.0/Math.PI; |
|
140 |
acaba = acaba*180.0/Math.PI; |
|
141 |
|
|
142 |
if (debug) System.out.println("empieza = " + empieza + "\nacaba = " + acaba); |
|
143 |
} |
|
144 |
|
|
132 | 145 |
/** |
133 | 146 |
* Genera los puntos que corresponden al arco. |
134 | 147 |
* @param inc Incremento (en grados) |
... | ... | |
203 | 216 |
Vector arc = new Vector(); |
204 | 217 |
//DxfEntityList arc = null; |
205 | 218 |
double angulo; |
219 |
|
|
220 |
/*if (bulge < 0.0) { |
|
221 |
empieza = acaba; |
|
222 |
acaba = empieza; |
|
223 |
}*/ |
|
206 | 224 |
|
207 | 225 |
int iempieza = (int) empieza + 1; // ojo aqui !! |
208 | 226 |
int iacaba = (int) acaba; |
... | ... | |
214 | 232 |
addNode(arc, angulo, z, "POS "); |
215 | 233 |
} |
216 | 234 |
//angulo = acaba; |
217 |
addNode(arc, acaba, z, "POS acaba "); |
|
218 | 235 |
|
236 |
if (bulge > 0.0) { |
|
237 |
addNode(arc, acaba, z, "POS acaba "); |
|
238 |
} |
|
239 |
if (bulge < 0.0){ |
|
240 |
addNode(arc, empieza, z, "POS acaba "); |
|
241 |
} |
|
242 |
//addNode(arc, acaba, z, "POS acaba "); |
|
243 |
|
|
219 | 244 |
//Coordinate aux = new Coordinate(); |
220 | 245 |
Point2D aux = new Point2D.Double(); |
221 | 246 |
//aux = arc.getCoordinate(arc.size()-1); |
222 | 247 |
aux = (Point2D)arc.get(arc.size()-1); |
248 |
|
|
223 | 249 |
double aux1 = Math.abs(aux.getX()-coord2.getX()); |
224 | 250 |
double aux2 = Math.abs(aux.getY()-coord2.getY()); |
225 | 251 |
if (aux1<=0.000005 && aux2<=0.000005) { |
... | ... | |
227 | 253 |
arc.remove(arc.size()-1); |
228 | 254 |
//arc.add(coord2); |
229 | 255 |
arc.add(coord2); |
230 |
} |
|
256 |
} |
|
257 |
|
|
231 | 258 |
} else { |
232 | 259 |
//acaba = 360-(alfa-empieza); |
233 | 260 |
//angulo = empieza; |
... | ... | |
238 | 265 |
for (angulo = 1; angulo <= iacaba; angulo += inc) { |
239 | 266 |
addNode(arc, angulo, z, "NEG "); |
240 | 267 |
} |
241 |
angulo = acaba; |
|
242 |
addNode(arc, angulo, z, "NEG "); |
|
243 | 268 |
|
269 |
if (bulge > 0.0) { |
|
270 |
angulo = acaba; |
|
271 |
addNode(arc, angulo, z, "NEG "); |
|
272 |
} |
|
273 |
if (bulge < 0.0) { |
|
274 |
angulo = empieza; |
|
275 |
addNode(arc, angulo, z, "NEG "); |
|
276 |
} |
|
277 |
//angulo = acaba; |
|
278 |
//addNode(arc, angulo, z, "NEG "); |
|
279 |
|
|
244 | 280 |
//Coordinate aux = new Coordinate(); |
245 | 281 |
Point2D aux = new Point2D.Double(); |
246 | 282 |
//aux = arc.getCoordinate(arc.size()-1); |
trunk/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfSolid.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.cresques.px.dxf; |
7 | 7 |
|
8 |
import java.awt.Color; |
|
8 | 9 |
import java.awt.Graphics2D; |
10 |
import java.awt.geom.GeneralPath; |
|
9 | 11 |
import java.awt.geom.Point2D; |
12 |
import java.util.Iterator; |
|
13 |
import java.util.Vector; |
|
10 | 14 |
|
11 | 15 |
import org.cresques.geo.Projection; |
12 | 16 |
import org.cresques.geo.ReProjection; |
13 | 17 |
import org.cresques.geo.ViewPort; |
18 |
import org.cresques.io.DxfGroup; |
|
14 | 19 |
import org.cresques.px.Extent; |
15 | 20 |
|
16 | 21 |
/** |
17 |
* Entidad TEXT de AutoCAD
|
|
22 |
* Entidad SOLID de AutoCAD
|
|
18 | 23 |
* |
19 | 24 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador |
20 | 25 |
*/ |
21 | 26 |
public class DxfSolid extends DxfEntity { |
27 |
final static Color baseColor = new Color(69, 106, 121); |
|
28 |
//Vector points = null; |
|
29 |
Point2D[] pts; |
|
30 |
GeneralPath gp = null; |
|
31 |
boolean closed = true; |
|
22 | 32 |
|
23 |
Point2D pt; |
|
24 |
|
|
25 |
public DxfSolid(Projection proj, DxfLayer layer) { |
|
33 |
public DxfSolid(Projection proj, DxfLayer layer, Point2D[] pts) { |
|
26 | 34 |
super(proj, layer); |
35 |
Point2D aux = pts[2]; |
|
36 |
pts[2] = pts[3]; |
|
37 |
pts[3] = aux; |
|
38 |
this.pts = pts; |
|
27 | 39 |
extent = new Extent(); |
28 |
pt = new Point2D.Double(); |
|
40 |
for (int i=0; i<pts.length; i++) { |
|
41 |
extent.add(pts[i]); |
|
42 |
} |
|
29 | 43 |
} |
30 | 44 |
|
31 |
public void setPt(Point2D pt) { |
|
32 |
this.pt = pt; |
|
33 |
extent.add(pt); |
|
34 |
} |
|
45 |
private Color color = baseColor; //Color(255,214,132,255); |
|
35 | 46 |
|
47 |
public Color c() {return color;} |
|
48 |
public Color c(Color color) {this.color = color; return color;} |
|
49 |
|
|
36 | 50 |
public void reProject(ReProjection rp) { |
37 |
Point2D savePt = pt;
|
|
51 |
Point2D [] savePts = pts;
|
|
38 | 52 |
|
39 |
pt = new Point2D.Double();
|
|
53 |
pts = new Point2D[savePts.length];
|
|
40 | 54 |
extent = new Extent(); |
41 | 55 |
Point2D ptDest = null; |
56 |
for (int i=0; i<savePts.length; i++) { |
|
42 | 57 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
43 |
if (savePt == null) |
|
44 |
ptDest = null; |
|
45 |
else { |
|
46 |
rp.convert((Point2D) savePt, ptDest); |
|
47 |
extent.add(ptDest); |
|
48 |
} |
|
49 |
pt = ptDest; |
|
58 |
rp.convert((Point2D) savePts[i], ptDest); |
|
59 |
this.pts[i] = ptDest; |
|
60 |
extent.add(ptDest); |
|
61 |
} |
|
50 | 62 |
setProjection(rp.getPDest()); |
51 | 63 |
} |
52 | 64 |
|
53 | 65 |
public void draw(Graphics2D g, ViewPort vp) { |
54 |
//AffineTransform msave=g.getTransform();
|
|
55 |
//g.setTransform(vp.mat);
|
|
66 |
System.out.println("Va a pintar un solid");
|
|
67 |
Color color = null;
|
|
56 | 68 |
if (dxfColor == AcadColor.BYLAYER) |
57 |
g.setColor(layer.getColor()); |
|
69 |
//g.setColor(layer.getColor()); |
|
70 |
color = layer.getColor(); |
|
58 | 71 |
else |
59 |
g.setColor(AcadColor.getColor(dxfColor)); |
|
60 |
Point2D ptT = new Point2D.Double(0, 0); |
|
61 |
vp.mat.transform(ptT, ptT); |
|
62 |
ptT.setLocation(pt.getX(), pt.getY()); |
|
63 |
vp.mat.transform(ptT, ptT); |
|
64 |
g.drawLine((int) ptT.getX(), (int)ptT.getY(), (int) ptT.getX(), (int)ptT.getY()); |
|
65 |
//g.setTransform(msave); |
|
72 |
//g.setColor(AcadColor.getColor(dxfColor)); |
|
73 |
color = AcadColor.getColor(dxfColor); |
|
74 |
newGP(vp); |
|
75 |
if (closed) { |
|
76 |
g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x80)); |
|
77 |
g.fill(gp); |
|
78 |
} |
|
79 |
g.setColor(color); |
|
80 |
g.draw(gp); |
|
66 | 81 |
} |
67 |
|
|
82 |
|
|
83 |
private void newGP(ViewPort vp) { |
|
84 |
//if (gp != null) return; |
|
85 |
gp = new GeneralPath(); |
|
86 |
Point2D pt0 = null, pt=null, pt1=null; |
|
87 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
|
88 |
System.out.println("pts.length = " + pts.length); |
|
89 |
for (int i=0; i<pts.length; i++) { |
|
90 |
pt1 = (Point2D)pts[i]; |
|
91 |
vp.mat.transform(pt1, ptTmp); |
|
92 |
if (pt0 == null) { |
|
93 |
pt0 = ptTmp; |
|
94 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
|
95 |
} else { |
|
96 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
|
97 |
} |
|
98 |
} |
|
99 |
if (closed) { |
|
100 |
gp.closePath(); |
|
101 |
} |
|
102 |
} |
|
68 | 103 |
/* (non-Javadoc) |
69 | 104 |
* @see org.cresques.px.dxf.DxfEntity#toDxfFileString() |
70 | 105 |
*/ |
... | ... | |
72 | 107 |
// TODO Auto-generated method stub |
73 | 108 |
return ""; |
74 | 109 |
} |
110 |
/** |
|
111 |
* @return |
|
112 |
*/ |
|
113 |
public Point2D[] getPts() { |
|
114 |
return pts; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* @return |
|
119 |
*/ |
|
120 |
/*public GeneralPath getGeneralPath(ViewPort vp) { |
|
121 |
newGP(vp); |
|
122 |
return (GeneralPath) gp.clone(); |
|
123 |
}*/ |
|
124 |
|
|
75 | 125 |
} |
Also available in: Unified diff