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