svn-gvsig-desktop / tags / v1_0_2_Build_905 / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfAttrib.java @ 10767
History | View | Annotate | Download (3.89 KB)
1 | 2809 | nacho | /*
|
---|---|---|---|
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 | * Entidad ATTRIB de un fichero DXF.
|
||
41 | * @author jmorell
|
||
42 | */
|
||
43 | public class DxfAttrib extends DxfEntity { |
||
44 | private Point2D pt; |
||
45 | |||
46 | /**
|
||
47 | * Constructor de DxfAttrib.
|
||
48 | * @param proj, proyecci?n cartogr?fica en la que se encuentra el DxfAttrib.
|
||
49 | * @param layer, capa del DXF en la que se encuentra el DxfAttrib.
|
||
50 | */
|
||
51 | public DxfAttrib(IProjection proj, DxfLayer layer) {
|
||
52 | super(proj, layer);
|
||
53 | extent = new Extent();
|
||
54 | pt = new Point2D.Double(); |
||
55 | } |
||
56 | |||
57 | /**
|
||
58 | * Establece el punto de inserci?n del DxfAttrib.
|
||
59 | * @param pt, punto de inserci?n.
|
||
60 | */
|
||
61 | public void setPt(Point2D pt) { |
||
62 | this.pt = pt;
|
||
63 | extent.add(pt); |
||
64 | } |
||
65 | |||
66 | /**
|
||
67 | * Permite reproyectar un DxfAttrib dado un conjunto de coordenadas de transformaci?n.
|
||
68 | * @param rp, coordenadas de transformaci?n.
|
||
69 | */
|
||
70 | public void reProject(ICoordTrans rp) { |
||
71 | Point2D savePt = pt;
|
||
72 | |||
73 | pt = new Point2D.Double(); |
||
74 | extent = new Extent();
|
||
75 | |||
76 | Point2D ptDest = rp.getPDest().createPoint(0.0, 0.0); |
||
77 | |||
78 | if (savePt == null) { |
||
79 | ptDest = null;
|
||
80 | } else {
|
||
81 | ptDest = rp.convert((Point2D) savePt, ptDest);
|
||
82 | extent.add(ptDest); |
||
83 | } |
||
84 | |||
85 | pt = ptDest; |
||
86 | setProjection(rp.getPDest()); |
||
87 | } |
||
88 | |||
89 | /**
|
||
90 | * Permite dibujar un DxfAttrib.
|
||
91 | */
|
||
92 | public void draw(Graphics2D g, ViewPortData vp) { |
||
93 | //AffineTransform msave=g.getTransform();
|
||
94 | //g.setTransform(vp.mat);
|
||
95 | if (dxfColor == AcadColor.BYLAYER) {
|
||
96 | g.setColor(layer.getColor()); |
||
97 | } else {
|
||
98 | g.setColor(AcadColor.getColor(dxfColor)); |
||
99 | } |
||
100 | |||
101 | Point2D ptT = new Point2D.Double(0, 0); |
||
102 | vp.mat.transform(ptT, ptT); |
||
103 | ptT.setLocation(pt.getX(), pt.getY()); |
||
104 | vp.mat.transform(ptT, ptT); |
||
105 | g.drawLine((int) ptT.getX(), (int) ptT.getY(), (int) ptT.getX(), |
||
106 | (int) ptT.getY());
|
||
107 | |||
108 | //g.setTransform(msave);
|
||
109 | } |
||
110 | |||
111 | /**
|
||
112 | * 050406, jmorell: Implementaci?n parcial. Est? para DxfPoint. Falta hacerlo
|
||
113 | * para un DxfAttrib ...
|
||
114 | */
|
||
115 | public String toDxfString() { |
||
116 | StringBuffer sb = null; |
||
117 | sb = new StringBuffer(DxfGroup.toString(0, "POINT")); |
||
118 | sb.append(DxfGroup.toString(5, getHandle()));
|
||
119 | sb.append(DxfGroup.toString(100, "AcDbEntity")); |
||
120 | sb.append(DxfGroup.toString(8, layer.getName()));
|
||
121 | sb.append(DxfGroup.toString(62, dxfColor));
|
||
122 | sb.append(DxfGroup.toString(100, "AcDbPoint")); |
||
123 | sb.append(DxfGroup.toString(10, pt.getX(), 6)); |
||
124 | sb.append(DxfGroup.toString(20, pt.getY(), 6)); |
||
125 | sb.append(DxfGroup.toString(30, 0.0, 6)); |
||
126 | |||
127 | return sb.toString();
|
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * @return Returns the pt.
|
||
132 | */
|
||
133 | public Point2D getPt() { |
||
134 | return pt;
|
||
135 | } |
||
136 | } |