Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / org / gvsig / dwg / lib / objects / DwgSpline.java @ 28969

History | View | Annotate | Download (7.44 KB)

1
/* jdwglib. Java Library for reading Dwg files.
2
 *
3
 * Author: Jose Morell Rama (jose.morell@gmail.com).
4
 * Port from the Pythoncad Dwg library by Art Haas.
5
 *
6
 * Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 * Jose Morell (jose.morell@gmail.com)
25
 *
26
 * or
27
 *
28
 * IVER TI S.A.
29
 *  C/Salamanca, 50
30
 *  46005 Valencia
31
 *  Spain
32
 *  +34 963163400
33
 *  dac@iver.es
34
 */
35
package org.gvsig.dwg.lib.objects;
36

    
37
import java.awt.geom.Point2D;
38
import java.util.ArrayList;
39

    
40
import org.gvsig.dwg.lib.DwgObject;
41
import org.gvsig.dwg.lib.IDwg2FMap;
42
import org.gvsig.dwg.lib.IDwg3DTestable;
43
import org.gvsig.dwg.lib.util.FMapUtil;
44
import org.gvsig.fmap.geom.Geometry;
45
import org.gvsig.fmap.geom.GeometryFactory;
46
import org.gvsig.fmap.geom.GeometryManager;
47

    
48

    
49
/**
50
 * The DwgSpline class represents a DWG Spline
51
 *
52
 * @author jmorell
53
 */
54
public class DwgSpline extends DwgObject
55
        implements IDwg3DTestable,  IDwg2FMap {
56

    
57
        public DwgSpline(int index) {
58
                super(index);
59
        }
60
        private int scenario;
61
        private int degree;
62
        private double fitTolerance;
63
        private double[] beginTanVector;
64
        private double[] endTanVector;
65
        private boolean rational;
66
        private boolean closed;
67
        private boolean periodic;
68
        private double knotTolerance;
69
        private double controlTolerance;
70
        private double[] knotPoints;
71
        private double[][] controlPoints;
72
        private double[] weights;
73
        private double[][] fitPoints;
74

    
75
        /**
76
         * @return Returns the closed.
77
         */
78
        public boolean isClosed() {
79
                return closed;
80
        }
81
        /**
82
         * @param closed The closed to set.
83
         */
84
        public void setClosed(boolean closed) {
85
                this.closed = closed;
86
        }
87
        /**
88
         * @return Returns the controlPoints.
89
         */
90
        public double[][] getControlPoints() {
91
                return controlPoints;
92
        }
93
        /**
94
         * @param controlPoints The controlPoints to set.
95
         */
96
        public void setControlPoints(double[][] controlPoints) {
97
                this.controlPoints = controlPoints;
98
        }
99
        /**
100
         * @return Returns the fitPoints.
101
         */
102
        public double[][] getFitPoints() {
103
                return fitPoints;
104
        }
105
        /**
106
         * @param fitPoints The fitPoints to set.
107
         */
108
        public void setFitPoints(double[][] fitPoints) {
109
                this.fitPoints = fitPoints;
110
        }
111
        /**
112
         * @return Returns the knotPoints.
113
         */
114
        public double[] getKnotPoints() {
115
                return knotPoints;
116
        }
117
        /**
118
         * @param knotPoints The knotPoints to set.
119
         */
120
        public void setKnotPoints(double[] knotPoints) {
121
                this.knotPoints = knotPoints;
122
        }
123
        /**
124
         * @return Returns the scenario.
125
         */
126
        public int getScenario() {
127
                return scenario;
128
        }
129
        /**
130
         * @param scenario The scenario to set.
131
         */
132
        public void setScenario(int scenario) {
133
                this.scenario = scenario;
134
        }
135

    
136
        /**
137
         * @return Returns the beginTanVector.
138
         */
139
        public double[] getBeginTanVector() {
140
                return beginTanVector;
141
        }
142
        /**
143
         * @param beginTanVector The beginTanVector to set.
144
         */
145
        public void setBeginTanVector(double[] beginTanVector) {
146
                this.beginTanVector = beginTanVector;
147
        }
148
        /**
149
         * @return Returns the controlTolerance.
150
         */
151
        public double getControlTolerance() {
152
                return controlTolerance;
153
        }
154
        /**
155
         * @param controlTolerance The controlTolerance to set.
156
         */
157
        public void setControlTolerance(double controlTolerance) {
158
                this.controlTolerance = controlTolerance;
159
        }
160
        /**
161
         * @return Returns the degree.
162
         */
163
        public int getDegree() {
164
                return degree;
165
        }
166
        /**
167
         * @param degree The degree to set.
168
         */
169
        public void setDegree(int degree) {
170
                this.degree = degree;
171
        }
172
        /**
173
         * @return Returns the endTanVector.
174
         */
175
        public double[] getEndTanVector() {
176
                return endTanVector;
177
        }
178
        /**
179
         * @param endTanVector The endTanVector to set.
180
         */
181
        public void setEndTanVector(double[] endTanVector) {
182
                this.endTanVector = endTanVector;
183
        }
184
        /**
185
         * @return Returns the fitTolerance.
186
         */
187
        public double getFitTolerance() {
188
                return fitTolerance;
189
        }
190
        /**
191
         * @param fitTolerance The fitTolerance to set.
192
         */
193
        public void setFitTolerance(double fitTolerance) {
194
                this.fitTolerance = fitTolerance;
195
        }
196
        /**
197
         * @return Returns the knotTolerance.
198
         */
199
        public double getKnotTolerance() {
200
                return knotTolerance;
201
        }
202
        /**
203
         * @param knotTolerance The knotTolerance to set.
204
         */
205
        public void setKnotTolerance(double knotTolerance) {
206
                this.knotTolerance = knotTolerance;
207
        }
208
        /**
209
         * @return Returns the periodic.
210
         */
211
        public boolean isPeriodic() {
212
                return periodic;
213
        }
214
        /**
215
         * @param periodic The periodic to set.
216
         */
217
        public void setPeriodic(boolean periodic) {
218
                this.periodic = periodic;
219
        }
220
        /**
221
         * @return Returns the rational.
222
         */
223
        public boolean isRational() {
224
                return rational;
225
        }
226
        /**
227
         * @param rational The rational to set.
228
         */
229
        public void setRational(boolean rational) {
230
                this.rational = rational;
231
        }
232
        /**
233
         * @return Returns the weights.
234
         */
235
        public double[] getWeights() {
236
                return weights;
237
        }
238
        /**
239
         * @param weights The weights to set.
240
         */
241
        public void setWeights(double[] weights) {
242
                this.weights = weights;
243
        }
244
        /* (non-Javadoc)
245
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
246
         */
247
        public boolean has3DData() {
248
                double[][] pts = getControlPoints();
249
                if(pts == null)
250
                        return false;
251
                double z = 0d;
252
                for (int j=0;j<pts.length;j++) {
253
                                z = pts[j][2];
254
                                if (z != 0.0)
255
                                        return true;
256
                }//for
257
                return false;
258
        }
259
        public double getZ() {
260
                return 0d;
261
        }
262
        /* (non-Javadoc)
263
         * @see java.lang.Object#clone()
264
         */
265
        public Object clone(){
266
                DwgSpline obj = new DwgSpline(index);
267
                this.fill(obj);
268
                return obj;
269
        }
270

    
271
        protected void fill(DwgObject obj){
272
                super.fill(obj);
273
                DwgSpline myObj = (DwgSpline)obj;
274

    
275
                myObj.setBeginTanVector(beginTanVector);
276
                myObj.setClosed(closed);
277
                myObj.setControlPoints(controlPoints);
278
                myObj.setControlTolerance(controlTolerance);
279
                myObj.setDegree(degree);
280
                myObj.setEndTanVector(endTanVector);
281
                myObj.setFitPoints(fitPoints);
282
                myObj.setFitTolerance(fitTolerance);
283
                myObj.setKnotPoints(knotPoints);
284
                myObj.setKnotTolerance(knotTolerance);
285
                myObj.setPeriodic(periodic);
286
                myObj.setRational(rational);
287
                myObj.setScenario(scenario);
288
                myObj.setWeights(weights);
289

    
290
        }
291
        public Geometry toFMapGeometry(boolean is3DFile) {
292
                //FIXME: Implementación provisional para ver si podemos leer SPLINES
293
                //De momento creamos una polilinea cuando deberíamos crear un spline o un bspline
294
                GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory();
295
                Geometry pline = null;
296
                double elev = getZ();
297
                double[][] points = getFitPoints();
298
                if (points == null) {
299
                        points = getControlPoints();
300
                }
301

    
302
                Point2D[] aPoints = new Point2D[points.length];
303
                for (int i=0; i < points.length; i++){
304
                        aPoints[i] = new Point2D.Double(points[i][0],points[i][1]);
305
                }
306

    
307
                if (points != null) {
308
                        if (is3DFile) {
309
                                pline = gFactory.createSpline2DZ(aPoints, elev);
310
                        } else {
311
                                pline = gFactory.createSpline2D(aPoints);
312
                        }
313
                }
314
                return pline;
315
        }
316

    
317
        public String toFMapString(boolean is3DFile) {
318
                if(is3DFile)
319
                        return "FPolyline3D";
320
                else
321
                        return "FPolyline2D";
322
        }
323
        public String toString(){
324
                return "Spline";
325
        }
326
}