Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgSpline.java @ 23100

History | View | Annotate | Download (7.7 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 com.iver.cit.jdwglib.dwg.objects;
36

    
37
import java.util.ArrayList;
38

    
39
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
40
import com.iver.cit.gvsig.fmap.core.IGeometry;
41
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
42
import com.iver.cit.jdwglib.dwg.DwgObject;
43
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
44
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
45
import com.iver.cit.jdwglib.util.FMapUtil;
46

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

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

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

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

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

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

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

    
299
                if (points != null) {
300
                        if (is3DFile) {
301
                                ArrayList pline3D = new ArrayList();
302
                                for (int j = 0; j < points.length; j++) {
303
                                        double[] point = new double[3];
304
                                        point[0] = points[j][0];
305
                                        point[1] = points[j][1];
306
                                        if (points[j].length == 3){
307
                                                point[2] = points[j][2];
308
                                        } else {
309
                                                point[2] = elev;
310
                                        }
311
                                        pline3D.add(point);
312
                                }
313
                                pline = FMapUtil.points3DToFPolyline3D(pline3D);
314
                        } else {
315
                                ArrayList lpoints = new ArrayList();
316
                                for (int i=0; i < points.length; i++){
317
                                        lpoints.add(points[i]);
318
                                }
319
                                pline = FMapUtil.points2DToFPolyline2D(lpoints);
320
                        }
321
                }
322
                return ShapeFactory.createGeometry(pline);
323
        }
324
        public String toFMapString(boolean is3DFile) {
325
                if(is3DFile)
326
                        return "FPolyline3D";
327
                else
328
                        return "FPolyline2D";
329
        }
330
        public String toString(){
331
                return "Spline";
332
        }
333
}