Statistics
| Revision:

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

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