root / org.gvsig.dxf / trunk / org.gvsig.dxf / org.gvsig.dxf.lib / src / main / java / org / gvsig / dxf / px / dxf / DxfPoint.java @ 6
History | View | Annotate | Download (4.11 KB)
1 | 6 | jldominguez | /*
|
---|---|---|---|
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.gvsig.dxf.px.dxf; |
||
25 | |||
26 | import java.awt.Graphics2D; |
||
27 | import java.awt.geom.Point2D; |
||
28 | |||
29 | import org.cresques.cts.ICoordTrans; |
||
30 | import org.cresques.cts.IProjection; |
||
31 | import org.cresques.geo.ViewPortData; |
||
32 | import org.cresques.px.Extent; |
||
33 | import org.gvsig.dxf.io.DxfGroup; |
||
34 | |||
35 | |||
36 | /**
|
||
37 | * Entidad POINT de un fichero DXF.
|
||
38 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
||
39 | * @author jmorell
|
||
40 | */
|
||
41 | public class DxfPoint extends DxfEntity { |
||
42 | private Point2D pt; |
||
43 | |||
44 | /**
|
||
45 | * Constructor de DxfPoint.
|
||
46 | * @param proj, proyecci?n cartogr?fica en la que se encuentra el DxfPoint.
|
||
47 | * @param layer, capa del DXF en la que se encuentra el DxfPoint.
|
||
48 | */
|
||
49 | public DxfPoint(IProjection proj, DxfLayer layer) {
|
||
50 | super(proj, layer);
|
||
51 | extent = new Extent();
|
||
52 | pt = new Point2D.Double(); |
||
53 | } |
||
54 | |||
55 | /**
|
||
56 | * Establece el punto de inserci?n del DxfPoint.
|
||
57 | * @param pt, punto de inserci?n.
|
||
58 | */
|
||
59 | public void setPt(Point2D pt) { |
||
60 | this.pt = pt;
|
||
61 | extent.add(pt); |
||
62 | } |
||
63 | |||
64 | /**
|
||
65 | * Permite reproyectar un DxfPoint dado un conjunto de coordenadas de transformaci?n.
|
||
66 | * @param rp, coordenadas de transformaci?n.
|
||
67 | */
|
||
68 | public void reProject(ICoordTrans rp) { |
||
69 | Point2D savePt = pt;
|
||
70 | |||
71 | pt = new Point2D.Double(); |
||
72 | extent = new Extent();
|
||
73 | |||
74 | Point2D ptDest = rp.getPDest().createPoint(0.0, 0.0); |
||
75 | |||
76 | if (savePt == null) { |
||
77 | ptDest = null;
|
||
78 | } else {
|
||
79 | ptDest = rp.convert((Point2D) savePt, ptDest);
|
||
80 | extent.add(ptDest); |
||
81 | } |
||
82 | |||
83 | pt = ptDest; |
||
84 | setProjection(rp.getPDest()); |
||
85 | } |
||
86 | |||
87 | /**
|
||
88 | * Permite dibujar un DxfPoint.
|
||
89 | */
|
||
90 | public void draw(Graphics2D g, ViewPortData vp) { |
||
91 | //AffineTransform msave=g.getTransform();
|
||
92 | //g.setTransform(vp.mat);
|
||
93 | if (dxfColor == AcadColor.BYLAYER) {
|
||
94 | g.setColor(layer.getColor()); |
||
95 | } else {
|
||
96 | g.setColor(AcadColor.getColor(dxfColor)); |
||
97 | } |
||
98 | |||
99 | Point2D ptT = new Point2D.Double(0, 0); |
||
100 | vp.mat.transform(ptT, ptT); |
||
101 | ptT.setLocation(pt.getX(), pt.getY()); |
||
102 | vp.mat.transform(ptT, ptT); |
||
103 | g.drawLine((int) ptT.getX(), (int) ptT.getY(), (int) ptT.getX(), |
||
104 | (int) ptT.getY());
|
||
105 | |||
106 | //g.setTransform(msave);
|
||
107 | } |
||
108 | |||
109 | /**
|
||
110 | * Permite la escritura de entidades DxfPoint en un fichero DXF2000.
|
||
111 | * @return String, la cadena que se escribir? en el fichero con la informaci?n
|
||
112 | * del DxfPoint.
|
||
113 | */
|
||
114 | public String toDxfString() { |
||
115 | StringBuffer sb = null; |
||
116 | sb = new StringBuffer(DxfGroup.toString(0, "POINT")); |
||
117 | sb.append(DxfGroup.toString(5, getHandle()));
|
||
118 | sb.append(DxfGroup.toString(100, "AcDbEntity")); |
||
119 | sb.append(DxfGroup.toString(8, layer.getName()));
|
||
120 | sb.append(DxfGroup.toString(62, dxfColor));
|
||
121 | sb.append(DxfGroup.toString(100, "AcDbPoint")); |
||
122 | sb.append(DxfGroup.toString(10, pt.getX(), 6)); |
||
123 | sb.append(DxfGroup.toString(20, pt.getY(), 6)); |
||
124 | sb.append(DxfGroup.toString(30, 0.0, 6)); |
||
125 | |||
126 | return sb.toString();
|
||
127 | } |
||
128 | |||
129 | /**
|
||
130 | * @return Returns the pt.
|
||
131 | */
|
||
132 | public Point2D getPt() { |
||
133 | return pt;
|
||
134 | } |
||
135 | } |