root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfAttrib.java @ 2669
History | View | Annotate | Download (3.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.io.DxfGroup; |
32 |
|
33 |
import org.cresques.px.Extent; |
34 |
|
35 |
import java.awt.Graphics2D; |
36 |
import java.awt.geom.Point2D; |
37 |
|
38 |
|
39 |
/**
|
40 |
* @author jmorell
|
41 |
*
|
42 |
* TODO To change the template for this generated type comment go to
|
43 |
* Window - Preferences - Java - Code Style - Code Templates
|
44 |
*/
|
45 |
public class DxfAttrib extends DxfEntity { |
46 |
private Point2D pt; |
47 |
|
48 |
public DxfAttrib(IProjection proj, DxfLayer layer) {
|
49 |
super(proj, layer);
|
50 |
extent = new Extent();
|
51 |
pt = new Point2D.Double(); |
52 |
} |
53 |
|
54 |
public void setPt(Point2D pt) { |
55 |
this.pt = pt;
|
56 |
extent.add(pt); |
57 |
} |
58 |
|
59 |
public void reProject(ICoordTrans rp) { |
60 |
Point2D savePt = pt;
|
61 |
|
62 |
pt = new Point2D.Double(); |
63 |
extent = new Extent();
|
64 |
|
65 |
Point2D ptDest = rp.getPDest().createPoint(0.0, 0.0); |
66 |
|
67 |
if (savePt == null) { |
68 |
ptDest = null;
|
69 |
} else {
|
70 |
ptDest = rp.convert((Point2D) savePt, ptDest);
|
71 |
extent.add(ptDest); |
72 |
} |
73 |
|
74 |
pt = ptDest; |
75 |
setProjection(rp.getPDest()); |
76 |
} |
77 |
|
78 |
public void draw(Graphics2D g, ViewPortData vp) { |
79 |
//AffineTransform msave=g.getTransform();
|
80 |
//g.setTransform(vp.mat);
|
81 |
if (dxfColor == AcadColor.BYLAYER) {
|
82 |
g.setColor(layer.getColor()); |
83 |
} else {
|
84 |
g.setColor(AcadColor.getColor(dxfColor)); |
85 |
} |
86 |
|
87 |
Point2D ptT = new Point2D.Double(0, 0); |
88 |
vp.mat.transform(ptT, ptT); |
89 |
ptT.setLocation(pt.getX(), pt.getY()); |
90 |
vp.mat.transform(ptT, ptT); |
91 |
g.drawLine((int) ptT.getX(), (int) ptT.getY(), (int) ptT.getX(), |
92 |
(int) ptT.getY());
|
93 |
|
94 |
//g.setTransform(msave);
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* 050406, jmorell: Est? para DxfPoint. Falta hacerlo para un DxfAttrib ...
|
99 |
*/
|
100 |
public String toDxfString() { |
101 |
StringBuffer sb = null; |
102 |
sb = new StringBuffer(DxfGroup.toString(0, "POINT")); |
103 |
sb.append(DxfGroup.toString(5, getHandle()));
|
104 |
sb.append(DxfGroup.toString(100, "AcDbEntity")); |
105 |
sb.append(DxfGroup.toString(8, layer.getName()));
|
106 |
sb.append(DxfGroup.toString(62, dxfColor));
|
107 |
sb.append(DxfGroup.toString(100, "AcDbPoint")); |
108 |
sb.append(DxfGroup.toString(10, pt.getX(), 6)); |
109 |
sb.append(DxfGroup.toString(20, pt.getY(), 6)); |
110 |
sb.append(DxfGroup.toString(30, 0.0, 6)); |
111 |
|
112 |
return sb.toString();
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* @return Returns the pt.
|
117 |
*/
|
118 |
public Point2D getPt() { |
119 |
return pt;
|
120 |
} |
121 |
} |