Statistics
| Revision:

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

History | View | Annotate | Download (8.52 KB)

1 10588 azabala
/*
2
 * Created on 03-feb-2007
3
 *
4 23096 fdiaz
 * gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
5 10588 azabala
 *
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 23096 fdiaz
 *   Av. Blasco Ib��ez, 50
27 10588 azabala
 *   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$
47
* $Log$
48 10847 azabala
* Revision 1.4.2.1  2007-03-21 19:49:16  azabala
49
* implementation of dwg 12, 13, 14.
50
*
51
* Revision 1.4  2007/03/20 19:57:08  azabala
52 10820 azabala
* source code cleaning
53
*
54
* Revision 1.3  2007/03/06 19:39:38  azabala
55 10632 azabala
* Changes to adapt dwg 12 to general architecture
56
*
57
* Revision 1.2  2007/03/02 20:31:22  azabala
58 10599 azabala
* *** empty log message ***
59
*
60
* Revision 1.1  2007/03/01 19:58:53  azabala
61 10588 azabala
* refactor of pface and mesh names
62
*
63
* Revision 1.2  2007/02/07 12:44:27  fdiaz
64 23096 fdiaz
* A�adido o modificado el metodo clone para que el DwgObject se encargue de las propiedades comunes a todos los objetos.
65
* A�adido el metodo fill.
66 10588 azabala
*
67
* Revision 1.1  2007/02/05 07:03:22  azabala
68
* *** empty log message ***
69
*
70
*
71
*/
72 28969 jmvivo
package org.gvsig.dwg.lib.objects;
73 10588 azabala
74
import java.awt.geom.Point2D;
75
import java.util.ArrayList;
76 10632 azabala
import java.util.List;
77 10820 azabala
import java.util.Map;
78 10588 azabala
79 28969 jmvivo
import org.gvsig.dwg.lib.DwgFile;
80
import org.gvsig.dwg.lib.DwgHandleReference;
81
import org.gvsig.dwg.lib.DwgObject;
82
import org.gvsig.dwg.lib.IDwg2FMap;
83
import org.gvsig.dwg.lib.IDwgBlockMember;
84
import org.gvsig.dwg.lib.IDwgPolyline;
85
import org.gvsig.dwg.lib.IDwgVertex;
86 23234 fdiaz
import org.gvsig.fmap.geom.Geometry;
87 29001 jmvivo
import org.gvsig.fmap.geom.exception.CreateGeometryException;
88 10588 azabala
89
/**
90
 * This class is a Mesh (polyline mesh), what is different of
91
 * a Polyface mesh (polyline pface).
92 23096 fdiaz
 *
93
 *
94 10588 azabala
 * */
95
public class DwgMeshPolyline extends DwgObject
96 10820 azabala
                implements IDwgPolyline, IDwg2FMap, IDwgBlockMember{
97 10588 azabala
98
        private int flags;
99
        /**
100 23096 fdiaz
         * Curves and smooth surface type (optional; default = 0);
101 10588 azabala
         * integer codes, not bit-coded:
102
                         0 = No smooth surface fitted
103
                         5 = Quadratic B-spline surface
104
                         6 = Cubic B-spline surface
105
                         8 = Bezier surface
106
         * */
107
        private int curveType;
108 23096 fdiaz
109 10588 azabala
        /**
110
         * Polygon mesh M vertex count
111 10599 azabala
         * (if curvetype is Spline, it has smooth M density)
112 10588 azabala
         */
113
        private int mVerticies;
114
        /**
115
         * Polygon mesh N vertex count
116 10599 azabala
         * (if curvetype is Spline, it has smooth n density)
117 10588 azabala
         * */
118
        private int nVerticies;
119
        /**
120 10599 azabala
         * If the mesh is closed in the M direction
121 10588 azabala
         * */
122 10599 azabala
        private boolean isClosedM;
123 10588 azabala
        /**
124 10599 azabala
         * If the mesh is closed in the N direction
125 10588 azabala
         * */
126 10599 azabala
        private boolean isClosedN;
127 23096 fdiaz
128 10588 azabala
        /**
129
         * handle of the first vertex of the mesh
130
         * */
131
        private DwgHandleReference firstVertexHandle;
132
        /**
133
         * handle of the last vertex of the mesh
134
         * */
135
        private DwgHandleReference lastVertexHandle;
136
        /**
137
         * handle of the seqend of the mesh
138
         * */
139
        private DwgHandleReference seqendHandle;
140
141
        /**
142
         * Vertices of the mesh
143
         * */
144 10632 azabala
        private List vertices;
145 23096 fdiaz
146 10588 azabala
        /**
147 23096 fdiaz
         * Owned Objects Handles of the mesh
148 10588 azabala
         * */
149 23096 fdiaz
        private ArrayList ownedObjectsHandles; //For R2004+
150
151
152
        /**
153
         * Constructor
154
         * */
155 10588 azabala
        public DwgMeshPolyline(int index) {
156
                super(index);
157 23096 fdiaz
                ownedObjectsHandles = new ArrayList();
158 10588 azabala
        }
159
160
        public void setFlags(int flags) {
161
                this.flags = flags;
162
        }
163
164
        public void setCurveType(int curveType) {
165
                this.curveType = curveType;
166
        }
167
168
        public void setMVerticies(int verticies) {
169
                this.mVerticies = verticies;
170
        }
171
172
        public void setNVerticies(int verticies) {
173
                this.nVerticies = verticies;
174
        }
175
176 23096 fdiaz
177 10588 azabala
        public void setFirstVertexHandle(DwgHandleReference handle) {
178
                this.firstVertexHandle = handle;
179
        }
180
181
        public void setLastVertexHandle(DwgHandleReference handle) {
182
                this.lastVertexHandle = handle;
183
        }
184
185
        public void setSeqendHandle(DwgHandleReference handle) {
186
                this.seqendHandle = handle;
187
        }
188
189
        public int getCurveType() {
190
                return curveType;
191
        }
192
193
        public DwgHandleReference getFirstVertexHandle() {
194
                return firstVertexHandle;
195
        }
196
197
        public int getFlags() {
198
                return flags;
199
        }
200
201
        public DwgHandleReference getLastVertexHandle() {
202
                return lastVertexHandle;
203
        }
204
205 23096 fdiaz
206 10588 azabala
        public int getMVerticies() {
207
                return mVerticies;
208
        }
209
210 23096 fdiaz
211 10588 azabala
        public int getNVerticies() {
212
                return nVerticies;
213
        }
214
215
        public DwgHandleReference getSeqendHandle() {
216
                return seqendHandle;
217
        }
218
        public Object clone(){
219
                DwgMeshPolyline obj = new DwgMeshPolyline(index);
220
                this.fill(obj);
221
                return obj;
222
        }
223 23096 fdiaz
224 10588 azabala
        protected void fill(DwgObject obj){
225
                super.fill(obj);
226
                DwgMeshPolyline myObj = (DwgMeshPolyline)obj;
227
228
                myObj.setCurveType(curveType);
229
                myObj.setFirstVertexHandle(firstVertexHandle);
230
                myObj.setFlags(flags);
231
                myObj.setLastVertexHandle(lastVertexHandle);
232
                myObj.setMVerticies(mVerticies);
233
                myObj.setNVerticies(nVerticies);
234
                myObj.setSeqendHandle(seqendHandle);
235
        }
236
237
        public void calculateGisModel(DwgFile dwgFile) {
238
        }
239
240 10820 azabala
         /*
241
     * By the moment, we consideer that PFacePolyline
242
     * is a Polyline3D TODO Implement real conversion
243
     * from a polyface mesh to a FMap geometry
244
     * */
245 29001 jmvivo
        public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException {
246 10820 azabala
                //TODO Implementar la conversion de DWG Mesh a
247
                //FMap (coleccion de poligonos??)
248 10588 azabala
                return null;
249
        }
250 10820 azabala
        /* (non-Javadoc)
251
         * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
252
         */
253 10588 azabala
        public String toFMapString(boolean is3DFile) {
254 29001 jmvivo
                if(is3DFile) {
255 10820 azabala
                        return "FPolyline3D";
256 29001 jmvivo
                } else {
257 10820 azabala
                        return "FPolyline2D";
258 29001 jmvivo
                }
259 10588 azabala
        }
260 23096 fdiaz
261 10820 azabala
        public String toString(){
262
                return "MeshPolyline";
263
        }
264 10588 azabala
265 10632 azabala
        public List getVertices() {
266 10588 azabala
                return vertices;
267
        }
268
269 10632 azabala
        public void setVertices(List vertices) {
270 10588 azabala
                this.vertices = vertices;
271
        }
272
273 10599 azabala
        public boolean isClosedM() {
274
                return isClosedM;
275
        }
276
277
        public void setClosedM(boolean isClosedM) {
278
                this.isClosedM = isClosedM;
279
        }
280
281
        public boolean isClosedN() {
282
                return isClosedN;
283
        }
284
285
        public void setClosedN(boolean isClosedN) {
286
                this.isClosedN = isClosedN;
287
        }
288
289
        public void setMDensity(int density) {
290 10820 azabala
                this.mVerticies = density;
291 10599 azabala
        }
292
293
        public void setNDensity(int density) {
294 10820 azabala
                this.nVerticies = density;
295 10599 azabala
        }
296
297 10632 azabala
        public void addVertex(IDwgVertex vertex) {
298
                vertices.add(vertex.getPoint());
299 23096 fdiaz
300 10632 azabala
        }
301
302 23096 fdiaz
        /**
303
         * @return Returns the owned objects handles.
304
         */
305
        public ArrayList getOwnedObjectsHandles() {
306
                return ownedObjectsHandles;
307
        }
308
        /**
309
         * @param objects The owned objects handles to set.
310
         */
311
        public void setOwnedObjectsHandles(ArrayList handles) {
312
                this.ownedObjectsHandles = handles;
313
        }
314
        /**
315
         * Add a handle to the ownedBbjectsHandle vector
316
         *
317
         * @param handle handle
318
         */
319
        public void addOwnedObjectHandle(DwgHandleReference handle) {
320
                this.ownedObjectsHandles.add(handle);
321
        }
322
323
        public void transform2Block(double[] bPoint, Point2D insPoint,
324
                        double[] scale, double rot,
325
                        List dwgObjectsWithoutBlocks,
326 10820 azabala
                        Map handleObjWithoutBlocks, DwgFile callBack) {
327 23096 fdiaz
328 10820 azabala
                DwgPolyline3D transformedEntity = null;
329
                List vertices = this.getVertices();
330 23096 fdiaz
331 10820 azabala
                if (vertices != null) {
332
                    List transformedVertices = new ArrayList();
333
                        for (int i=0;i < vertices.size();i++) {
334
                                double[] pointAux = null;
335
                            pointAux = new double[]{((double[]) vertices.get(i))[0] - bPoint[0],
336
                                            ((double[]) vertices.get(i))[1] - bPoint[1]};
337 23096 fdiaz
338 10820 azabala
                                double laX = insPoint.getX() + ((pointAux[0] * scale[0])*Math.cos(rot) + (pointAux[1]*scale[1])*(-1)*Math.sin(rot));
339
                                double laY = insPoint.getY() + ((pointAux[0]*scale[0])*Math.sin(rot) + (pointAux[1]*scale[1])*Math.cos(rot));
340
                                double laZ = ((double[]) vertices.get(i))[2] - bPoint[2];
341
                                transformedVertices.add(new double[]{laX, laY, laZ});
342
                        }//for
343
                        transformedEntity = (DwgPolyline3D)this.clone();
344
                        transformedEntity.setPts(transformedVertices);
345
                        dwgObjectsWithoutBlocks.add(transformedEntity);
346
                        handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity);
347
                }
348
        }
349 29001 jmvivo
350
351
        public int getGeometrySubType(boolean is3DFile) {
352
                if (is3DFile) {
353
                        return Geometry.SUBTYPES.GEOM3D;
354
                } else {
355
                        return Geometry.SUBTYPES.GEOM2D;
356
                }
357
        }
358
359
        public int getGeometryType() {
360
                return Geometry.TYPES.MULTICURVE;
361
        }
362
363 10588 azabala
}