root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfText.java @ 2669
History | View | Annotate | Download (5.43 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.px.dxf; |
25 |
|
26 |
import org.cresques.cts.ICoordTrans; |
27 |
import org.cresques.cts.IProjection; |
28 |
|
29 |
import org.cresques.geo.ViewPortData; |
30 |
|
31 |
import org.cresques.px.Extent; |
32 |
|
33 |
import java.awt.Font; |
34 |
import java.awt.Graphics2D; |
35 |
import java.awt.geom.Point2D; |
36 |
|
37 |
|
38 |
/**
|
39 |
* Entidad TEXT de AutoCAD
|
40 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
41 |
*
|
42 |
* jmorell, 050406: El segundo punto es opcional.
|
43 |
*/
|
44 |
public class DxfText extends DxfEntity { |
45 |
public final static int ALIGN_LEFT = 0; |
46 |
public final static int ALIGN_CENTER = 1; |
47 |
public final static int ALIGN_RIGHT = 2; |
48 |
public final static int ALIGN_ALIGNED = 3; |
49 |
public final static int ALIGN_MIDDLE = 4; |
50 |
public final static int ALIGN_FIT = 5; |
51 |
private String text = null; |
52 |
Point2D[] pts; |
53 |
private Point2D pt; |
54 |
private double rot = 0.0; |
55 |
private double h = 1.0; |
56 |
int align = ALIGN_LEFT;
|
57 |
private boolean twoPointsFlag; |
58 |
|
59 |
public DxfText(IProjection proj, DxfLayer layer, String txt) { |
60 |
super(proj, layer);
|
61 |
|
62 |
//System.out.println("Dxf: TEXT '"+txt+"'.");
|
63 |
extent = new Extent();
|
64 |
text = txt; |
65 |
pts = new Point2D[2]; |
66 |
pt = new Point2D.Double(); |
67 |
twoPointsFlag = false;
|
68 |
} |
69 |
|
70 |
public void setPt(Point2D pt) { |
71 |
this.pt = pt;
|
72 |
} |
73 |
|
74 |
public Point2D getPt() { |
75 |
return pt;
|
76 |
} |
77 |
|
78 |
public void setTwoPointsFlag(boolean f) { |
79 |
twoPointsFlag = f; |
80 |
} |
81 |
|
82 |
public boolean getTwoPointsFlag() { |
83 |
return twoPointsFlag;
|
84 |
} |
85 |
|
86 |
public void setPt1(Point2D pt) { |
87 |
pts[0] = pt;
|
88 |
extent.add(pt); |
89 |
} |
90 |
|
91 |
public Point2D getPt1() { |
92 |
return pts[0]; |
93 |
} |
94 |
|
95 |
public void setPt2(Point2D pt) { |
96 |
pts[1] = pt;
|
97 |
extent.add(pt); |
98 |
} |
99 |
|
100 |
public Point2D getPt2() { |
101 |
return pts[1]; |
102 |
} |
103 |
|
104 |
public void setHeight(double h) { |
105 |
this.h = h;
|
106 |
} |
107 |
|
108 |
public void setRotation(double r) { |
109 |
rot = r; |
110 |
} |
111 |
|
112 |
public double getRotation() { |
113 |
return rot;
|
114 |
} |
115 |
|
116 |
public String getText() { |
117 |
return text;
|
118 |
} |
119 |
|
120 |
public void reProject(ICoordTrans rp) { |
121 |
Point2D[] savePts = pts; |
122 |
|
123 |
pts = new Point2D[2]; |
124 |
extent = new Extent();
|
125 |
|
126 |
Point2D ptDest = null; |
127 |
|
128 |
for (int i = 0; i < savePts.length; i++) { |
129 |
ptDest = rp.getPDest().createPoint(0.0, 0.0); |
130 |
|
131 |
if (savePts[i] == null) { |
132 |
ptDest = null;
|
133 |
} else {
|
134 |
ptDest = rp.convert((Point2D) savePts[i], ptDest);
|
135 |
extent.add(ptDest); |
136 |
} |
137 |
|
138 |
pts[i] = ptDest; |
139 |
} |
140 |
|
141 |
// Reproyecto la altura del texto
|
142 |
Point2D ptOrig = rp.getPOrig().createPoint(savePts[0].getX(), |
143 |
savePts[0].getY() + h);
|
144 |
ptDest = rp.getPDest().createPoint(0D, 0D); |
145 |
ptDest = rp.convert(ptOrig, ptDest); |
146 |
h = ptDest.getY() - pts[0].getY();
|
147 |
setProjection(rp.getPDest()); |
148 |
} |
149 |
|
150 |
public void draw(Graphics2D g, ViewPortData vp) { |
151 |
if (dxfColor == AcadColor.BYLAYER) {
|
152 |
g.setColor(layer.getColor()); |
153 |
} else {
|
154 |
g.setColor(AcadColor.getColor(dxfColor)); |
155 |
} |
156 |
|
157 |
Font fntSave = g.getFont();
|
158 |
Font fnt;
|
159 |
Point2D ptT0 = new Point2D.Double(pts[0].getX(), pts[0].getY()); |
160 |
Point2D ptT1 = new Point2D.Double(pts[0].getX() + h, pts[0].getY() + h); |
161 |
vp.mat.transform(ptT0, ptT0); |
162 |
vp.mat.transform(ptT1, ptT1); |
163 |
fnt = new Font(fntSave.getName(), fntSave.getStyle(), |
164 |
(int) (ptT1.getX() - ptT0.getX()));
|
165 |
g.setFont(fnt); |
166 |
ptT0.setLocation(pts[0].getX(), pts[0].getY()); |
167 |
vp.mat.transform(ptT0, ptT0); |
168 |
|
169 |
// Codigo para implementar rotacion de textos.
|
170 |
// Falta depurar.
|
171 |
/*System.out.println("040906: rot = " + rot);
|
172 |
//angle = pathLen.angleAtLength(midDistance);
|
173 |
rot = Math.toRadians(rot);
|
174 |
if (rot < 0) rot = rot + 2.0*Math.PI;
|
175 |
if ((rot > (Math.PI/2)) && (rot < (3 * Math.PI /2))) rot = rot - (Math.PI/2.0);
|
176 |
rot = Math.toDegrees(rot);
|
177 |
//theLabel.setRotation(Math.toDegrees(angle));
|
178 |
AffineTransform transfRot = AffineTransform.getRotateInstance(rot, ptT0.getX(), ptT0.getY());
|
179 |
AffineTransform ant = g.getTransform();
|
180 |
g.setTransform(transfRot);*/
|
181 |
g.drawString(text, (int) ptT0.getX(), (int) ptT0.getY()); |
182 |
g.setFont(fntSave); |
183 |
|
184 |
//g.setTransform(ant);
|
185 |
} |
186 |
|
187 |
/* (non-Javadoc)
|
188 |
* @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
|
189 |
*/
|
190 |
public String toDxfString() { |
191 |
// TODO Auto-generated method stub
|
192 |
return ""; |
193 |
} |
194 |
} |