Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgMeshPolyline.java @ 10632

History | View | Annotate | Download (8.8 KB)

1
/*
2
 * Created on 03-feb-2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. 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
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: DwgMeshPolyline.java 10632 2007-03-06 19:39:38Z azabala $
47
* $Log$
48
* Revision 1.3  2007-03-06 19:39:38  azabala
49
* Changes to adapt dwg 12 to general architecture
50
*
51
* Revision 1.2  2007/03/02 20:31:22  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.1  2007/03/01 19:58:53  azabala
55
* refactor of pface and mesh names
56
*
57
* Revision 1.2  2007/02/07 12:44:27  fdiaz
58
* A?adido o modificado el metodo clone para que el DwgObject se encargue de las propiedades comunes a todos los objetos.
59
* A?adido el metodo fill.
60
*
61
* Revision 1.1  2007/02/05 07:03:22  azabala
62
* *** empty log message ***
63
*
64
*
65
*/
66
package com.iver.cit.jdwglib.dwg.objects;
67

    
68
import java.awt.geom.Point2D;
69
import java.util.ArrayList;
70
import java.util.List;
71

    
72
import com.iver.cit.gvsig.fmap.core.FShape;
73
import com.iver.cit.jdwglib.dwg.DwgFile;
74
import com.iver.cit.jdwglib.dwg.DwgHandleReference;
75
import com.iver.cit.jdwglib.dwg.DwgObject;
76
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
77
import com.iver.cit.jdwglib.dwg.IDwgPolyline;
78
import com.iver.cit.jdwglib.dwg.IDwgVertex;
79
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
80

    
81
/**
82
 * This class is a Mesh (polyline mesh), what is different of
83
 * a Polyface mesh (polyline pface).
84
 * 
85
 * 
86
 * */
87
public class DwgMeshPolyline extends DwgObject
88
                implements IDwgPolyline, IDwg2FMap{
89

    
90
        private int flags;
91
        /**
92
         * Curves and smooth surface type (optional; default = 0); 
93
         * integer codes, not bit-coded:
94
                         0 = No smooth surface fitted
95
                         5 = Quadratic B-spline surface
96
                         6 = Cubic B-spline surface
97
                         8 = Bezier surface
98
         * */
99
        private int curveType;
100
        
101
        /**
102
         * Polygon mesh M vertex count
103
         * (if curvetype is Spline, it has smooth M density)
104
         */
105
        private int mVerticies;
106
        /**
107
         * Polygon mesh N vertex count
108
         * (if curvetype is Spline, it has smooth n density)
109
         * */
110
        private int nVerticies;
111
        /**
112
         * If the mesh is closed in the M direction
113
         * */
114
        private boolean isClosedM;
115
        /**
116
         * If the mesh is closed in the N direction
117
         * */
118
        private boolean isClosedN;
119
        
120
        /**
121
         * handle of the first vertex of the mesh
122
         * */
123
        private DwgHandleReference firstVertexHandle;
124
        /**
125
         * handle of the last vertex of the mesh
126
         * */
127
        private DwgHandleReference lastVertexHandle;
128
        /**
129
         * handle of the seqend of the mesh
130
         * */
131
        private DwgHandleReference seqendHandle;
132

    
133
        /**
134
         * Vertices of the mesh
135
         * */
136
        private List vertices;
137
        
138
        
139
        
140
        
141
        /**
142
         * Constructor 
143
         * */
144
        public DwgMeshPolyline(int index) {
145
                super(index);
146
        }
147

    
148
        public void setFlags(int flags) {
149
                this.flags = flags;
150
        }
151

    
152
        public void setCurveType(int curveType) {
153
                this.curveType = curveType;
154
        }
155

    
156
        public void setMVerticies(int verticies) {
157
                this.mVerticies = verticies;
158
        }
159

    
160
        public void setNVerticies(int verticies) {
161
                this.nVerticies = verticies;
162
        }
163

    
164
        
165
        public void setFirstVertexHandle(DwgHandleReference handle) {
166
                this.firstVertexHandle = handle;
167
        }
168

    
169
        public void setLastVertexHandle(DwgHandleReference handle) {
170
                this.lastVertexHandle = handle;
171
        }
172

    
173
        public void setSeqendHandle(DwgHandleReference handle) {
174
                this.seqendHandle = handle;
175
        }
176

    
177
        public int getCurveType() {
178
                return curveType;
179
        }
180

    
181
        public DwgHandleReference getFirstVertexHandle() {
182
                return firstVertexHandle;
183
        }
184

    
185
        public int getFlags() {
186
                return flags;
187
        }
188

    
189
        public DwgHandleReference getLastVertexHandle() {
190
                return lastVertexHandle;
191
        }
192

    
193
        
194
        public int getMVerticies() {
195
                return mVerticies;
196
        }
197

    
198
        
199
        public int getNVerticies() {
200
                return nVerticies;
201
        }
202

    
203
        public DwgHandleReference getSeqendHandle() {
204
                return seqendHandle;
205
        }
206
        public Object clone(){
207
                DwgMeshPolyline obj = new DwgMeshPolyline(index);
208
                this.fill(obj);
209
                return obj;
210
        }
211
        
212
        protected void fill(DwgObject obj){
213
                super.fill(obj);
214
                DwgMeshPolyline myObj = (DwgMeshPolyline)obj;
215

    
216
                myObj.setCurveType(curveType);
217
                myObj.setFirstVertexHandle(firstVertexHandle);
218
                myObj.setFlags(flags);
219
                myObj.setLastVertexHandle(lastVertexHandle);
220
                myObj.setMVerticies(mVerticies);
221
                myObj.setNVerticies(nVerticies);
222
                myObj.setSeqendHandle(seqendHandle);
223
        }
224

    
225
        public void calculateGisModel(DwgFile dwgFile) {
226
        /*
227
         int flags = getFlags();
228
//                En estas dos lineas de abajo y en el resto del metodo
229
//                se mantiene el mecanismo anterior al refactoring.
230
//                TODO: Pensar si deberiamos coger el handle completo.
231
//                Tal vez deberiamos tomar el handle completo y evaluar
232
//                a donde apuntan (pueden haber 2 handles con codigo y offset
233
//                distintos y que, sin embargo apunten al mismo objeto).
234
                int firstHandle = getFirstVertexHandle().getOffset();
235
                int lastHandle = getLastVertexHandle().getOffset();
236
                ArrayList pts = new ArrayList();
237
                ArrayList bulges = new ArrayList();
238
                double[] pt = new double[3];
239
                double bulge = 0d;
240
                
241
                DwgObject first = dwgFile.getDwgObjectFromHandle(firstHandle);
242
                DwgObject last = dwgFile.getDwgObjectFromHandle(lastHandle);
243
                if(first == null || last == null){
244
                        System.out.println("Polyline2D con vertices inicial o final a null");
245
                        return;
246
                }
247
                
248
                if(!(first instanceof DwgVertex2D)){
249
                        System.out.println("El primer vertice de Polyline2D es "+
250
                                                        first.getClass().getName());
251
                        return;
252
                }
253
                
254
                if(!(last instanceof DwgVertex2D)){
255
                        System.out.println("El primer vertice de Polyline2D es "+
256
                                                        first.getClass().getName());
257
                        return;
258
                }
259
                
260
                 int firstObjIdx = dwgFile.getIndexOf(first);
261
                 int lastObjIdx =  dwgFile.getIndexOf(last);
262
                 if(firstObjIdx == -1 || lastObjIdx == -1){
263
                         System.out.println("Calculate GIS Model: Problemas en la LinkedList: 1?="+firstObjIdx+",Ultimo="+lastObjIdx);
264
                         return;
265
                 }
266
                 
267
//                 pt = ((DwgVertex2D)first).getPoint();
268
//                 pts.add(new Point2D.Double(pt[0], pt[1]));
269
//                 bulge = ((DwgVertex2D)first).getBulge();
270
//                 bulges.add(new Double(bulge));
271
                 
272
                 for(int i = firstObjIdx; i <= lastObjIdx; i++){
273
                         DwgObject obj = dwgFile.getDwgObject(i);
274
                         if(obj instanceof DwgVertex2D){
275
                                 DwgVertex2D vertex = (DwgVertex2D) obj;
276
                                 pt = vertex.getPoint();
277
                                pts.add(new Point2D.Double(pt[0], pt[1]));
278
                                bulge = vertex.getBulge();
279
                                bulges.add(new Double(bulge));
280
                         }else{
281
                                 System.out.println("Encontrado "+obj.getClass().getName()+" en la lista de vertices de Polyline2D");
282
                         }
283
                 }//for
284
                 
285
                if (pts.size()>0) {
286
                        Point2D[] newPts = new Point2D[pts.size()];
287
                        if ((flags & 0x1)==0x1) {
288
                                newPts = new Point2D[pts.size()+1];
289
                                for (int j=0;j<pts.size();j++) {
290
                                        newPts[j] = (Point2D)pts.get(j);
291
                                }
292
                                newPts[pts.size()] = (Point2D)pts.get(0);
293
                                bulges.add(new Double(0));
294
                        } else {
295
                                for (int j=0;j<pts.size();j++) {
296
                                        newPts[j] = (Point2D)pts.get(j);
297
                                }
298
                        }
299
                        double[] bs = new double[bulges.size()];
300
                        for (int j=0;j<bulges.size();j++) {
301
                                bs[j] = ((Double)bulges.get(j)).doubleValue();
302
                        }
303
                        setBulges(bs);
304
                        Point2D[] points = GisModelCurveCalculator.
305
                                        calculateGisModelBulge(newPts, bs);
306
                        setPts(points);
307
                } else {
308
                        System.out.println("Encontrada polil?nea sin puntos ...");
309
                        // TODO: No se debe mandar nunca una polil?nea sin puntos, si esto
310
                        // ocurre es porque existe un error que hay que corregir ...
311
                } 
312
          
313
         **/
314
        
315
        
316
        
317
        }
318

    
319
        public FShape toFMapGeometry(boolean is3DFile) {
320
                
321
                return null;
322
        }
323

    
324
        public String toFMapString(boolean is3DFile) {
325
                return "Polyline MESH";
326
        }
327

    
328
        public List getVertices() {
329
                return vertices;
330
        }
331

    
332
        public void setVertices(List vertices) {
333
                this.vertices = vertices;
334
        }
335

    
336
        public boolean isClosedM() {
337
                return isClosedM;
338
        }
339

    
340
        public void setClosedM(boolean isClosedM) {
341
                this.isClosedM = isClosedM;
342
        }
343

    
344
        public boolean isClosedN() {
345
                return isClosedN;
346
        }
347

    
348
        public void setClosedN(boolean isClosedN) {
349
                this.isClosedN = isClosedN;
350
        }
351

    
352
        public void setMDensity(int density) {
353
                // TODO Auto-generated method stub
354
                
355
        }
356

    
357
        public void setNDensity(int density) {
358
                // TODO Auto-generated method stub
359
                
360
        }
361

    
362
        public void addVertex(IDwgVertex vertex) {
363
                vertices.add(vertex.getPoint());
364
                
365
        }
366

    
367
}
368