Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / px / dxf / DxfSolid.java @ 8026

History | View | Annotate | Download (4.95 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.Color;
34
import java.awt.Graphics2D;
35
import java.awt.geom.GeneralPath;
36
import java.awt.geom.Point2D;
37

    
38

    
39
/**
40
 * Entidad SOLID de un fichero DXF.
41
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
42
 * @author jmorell
43
 */
44
public class DxfSolid extends DxfEntity {
45
    final static Color baseColor = new Color(69, 106, 121);
46

    
47
    //Vector points = null;
48
    Point2D[] pts;
49
    GeneralPath gp = null;
50
    boolean closed = true;
51
    private Color color = baseColor; //Color(255,214,132,255);
52

    
53
    /**
54
     * Constructor de DxfSolid.
55
     * @param proj, proyecci?n cartogr?fica en la que se encuentra el DxfSolid.
56
     * @param layer, capa del DXF en la que se encuentra el DxfSolid.
57
     * @param pts, puntos 2D que componen el DxfSolid.
58
     */
59
    public DxfSolid(IProjection proj, DxfLayer layer, Point2D[] pts) {
60
        super(proj, layer);
61

    
62
        Point2D aux = pts[2];
63
        pts[2] = pts[3];
64
        pts[3] = aux;
65
        this.pts = pts;
66
        extent = new Extent();
67

    
68
        for (int i = 0; i < pts.length; i++) {
69
            extent.add(pts[i]);
70
        }
71
    }
72

    
73
    /**
74
     * Devuelve el color del DxfSolid.
75
     * @return Color
76
     */
77
    public Color c() {
78
        return color;
79
    }
80

    
81
    /**
82
     * Establece el color del DxfSolid.
83
     * @param color
84
     * @return Color
85
     */
86
    public Color c(Color color) {
87
        this.color = color;
88

    
89
        return color;
90
    }
91

    
92
    /**
93
     * Permite reproyectar un DxfSolid dado un conjunto de coordenadas de transformaci?n.
94
     * @param rp, coordenadas de transformaci?n.
95
     */
96
    public void reProject(ICoordTrans rp) {
97
        Point2D[] savePts = pts;
98

    
99
        pts = new Point2D[savePts.length];
100
        extent = new Extent();
101

    
102
        Point2D ptDest = null;
103

    
104
        for (int i = 0; i < savePts.length; i++) {
105
            ptDest = rp.getPDest().createPoint(0.0, 0.0);
106
            ptDest = rp.convert((Point2D) savePts[i], ptDest);
107
            pts[i] = ptDest;
108
            extent.add(ptDest);
109
        }
110

    
111
        setProjection(rp.getPDest());
112
    }
113

    
114
    /**
115
     * Permite dibujar un DxfSolid.
116
     */
117
    public void draw(Graphics2D g, ViewPortData vp) {
118
        //System.out.println("Va a pintar un solid");
119
        Color color = null;
120

    
121
        if (dxfColor == AcadColor.BYLAYER) {
122
            //g.setColor(layer.getColor());
123
            color = layer.getColor();
124
        } else {
125
            //g.setColor(AcadColor.getColor(dxfColor));
126
            color = AcadColor.getColor(dxfColor);
127
        }
128

    
129
        newGP(vp);
130

    
131
        if (closed) {
132
            g.setColor(new Color(color.getRed(), color.getBlue(),
133
                                 color.getGreen(), 0x20));
134
            g.fill(gp);
135
        }
136

    
137
        g.setColor(color);
138
        g.draw(gp);
139
    }
140

    
141
    /**
142
     * Permite generar un GeneralPath partiendo del array de Point2D que conforma el
143
     * DxfSolid.
144
     * @param vp
145
     */
146
    private void newGP(ViewPortData vp) {
147
        //if (gp != null) return;
148
        gp = new GeneralPath();
149

    
150
        Point2D pt0 = null;
151
        Point2D pt = null;
152
        Point2D pt1 = null;
153
        Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0);
154

    
155
        //System.out.println("pts.length = " + pts.length);
156
        for (int i = 0; i < pts.length; i++) {
157
            pt1 = (Point2D) pts[i];
158
            vp.mat.transform(pt1, ptTmp);
159

    
160
            if (pt0 == null) {
161
                pt0 = ptTmp;
162
                gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY());
163
            } else {
164
                gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY());
165
            }
166
        }
167

    
168
        if (closed) {
169
            gp.closePath();
170
        }
171
    }
172

    
173
    /* (non-Javadoc)
174
     * @see org.cresques.px.dxf.DxfEntity#toDxfFileString()
175
     */
176
    public String toDxfString() {
177
        // TODO Auto-generated method stub
178
        return "";
179
    }
180

    
181
    /**
182
     * Devuelve el array de puntos que conforman el DxfSolid.
183
     * @return Point2D[], puntos del DxfSolid.
184
     */
185
    public Point2D[] getPts() {
186
        return pts;
187
    }
188
}