Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dwg / DwgMemoryDriver.java @ 1865

History | View | Annotate | Download (49.4 KB)

1
/*
2
 * Created on 14-abr-2005
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
package com.iver.cit.gvsig.fmap.drivers.dwg;
45

    
46
import java.awt.Color;
47
import java.awt.Font;
48
import java.awt.geom.Point2D;
49
import java.io.File;
50
import java.io.IOException;
51
import java.util.ArrayList;
52
import java.util.Vector;
53

    
54
import net.jmorell.jdwglib.dwg.DwgFile;
55
import net.jmorell.jdwglib.dwg.DwgObject;
56
import net.jmorell.jdwglib.dwg.DwgObjectSpecificDataItem;
57
import net.jmorell.jdwglib.dwg.DxfName;
58

    
59
import org.cresques.px.dxf.AcadColor;
60

    
61
import com.hardcode.gdbms.engine.data.driver.DriverException;
62
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
63
import com.hardcode.gdbms.engine.values.IntValue;
64
import com.hardcode.gdbms.engine.values.Value;
65
import com.hardcode.gdbms.engine.values.ValueFactory;
66
import com.iver.cit.gvsig.fmap.core.FPoint2D;
67
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
68
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
69
import com.iver.cit.gvsig.fmap.core.FShape;
70
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
71
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
72
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
73
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
74
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver;
75
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
76
import com.iver.cit.gvsig.fmap.rendering.Legend;
77
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
78
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
79

    
80
import com.iver.cit.gvsig.fmap.drivers.dgn.ByteUtils;
81

    
82
public class DwgMemoryDriver extends MemoryDriver implements WithDefaultLegend {
83
        private final int ID_FIELD_ID=0;
84
        private final int ID_FIELD_ENTITY=1;
85
        private final int ID_FIELD_LAYER=2;
86
        private final int ID_FIELD_COLOR=3;
87
        private final int ID_FIELD_ELEVATION=4;
88
        private final int ID_FIELD_THICKNESS=5;
89
        private final int ID_FIELD_TEXT=6;
90
        private final int ID_FIELD_HEIGHTTEXT=7;
91
        private final int ID_FIELD_ROTATIONTEXT=8;
92

    
93
        VectorialUniqueValueLegend defaultLegend;
94
        private String path;
95
        private File m_Fich;
96
        
97
        private DwgFile dwg;
98
        private Vector dwgObjects;
99
        private DriverAttributes attr = new DriverAttributes();
100

    
101
        /* (non-Javadoc)
102
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
103
         */
104
        public void open(File f) throws IOException {
105
            m_Fich = f;
106
        }
107
        
108
        public void initialize() throws IOException {
109
                float heightText = 10;
110
                
111
                attr.setLoadedInMemory(true);
112
                
113
                dwg = new DwgFile();
114
                long time = System.currentTimeMillis();
115
                dwg.read(m_Fich.getAbsolutePath());
116
                long timeElapsed = System.currentTimeMillis()-time;
117
                System.out.println("Tiempo empleado en leer el fichero dwg = " + timeElapsed);
118
                dwgObjects = dwg.getDwgObjects();
119
                
120
                //int nAtt = featureMaker.getAttributes().size();
121
                
122
                // Campos de las MemoryLayer:
123
            //Value[] auxRow = new Value[9+nAtt];
124
            Value[] auxRow = new Value[9];
125
                ArrayList arrayFields = new ArrayList();
126
                arrayFields.add("ID");
127
                arrayFields.add("Entity");
128
                arrayFields.add("Layer");
129
                arrayFields.add("Color");
130
                arrayFields.add("Elevation");
131
                arrayFields.add("Thickness");
132
                arrayFields.add("Text");
133
                arrayFields.add("HeightText");
134
                arrayFields.add("RotationText");
135
                /*for (int i=0;i<nAtt;i++) {
136
                        String att[] = new String[2];
137
                        att = (String[])featureMaker.getAttributes().get(i);
138
                        arrayFields.add(att[0]);
139
                }*/
140
                
141
            getTableModel().setColumnIdentifiers(arrayFields.toArray());
142
                
143
                time = System.currentTimeMillis();
144
                for (int i=0;i<dwgObjects.size();i++) {
145
                        
146
            auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
147
            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
148
            auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
149
                        
150
                        DwgObject entity = (DwgObject)dwgObjects.get(i);
151
                        if (entity.getType()==0x11) {
152
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
153
                                double[] coord = (double[])data.getValue();
154
                                Point2D center = new Point2D.Double(coord[0], coord[1]);
155
                                data = entity.getDwgObjectSpecificDataItem("RADIUS");
156
                                double radius = ((Double)data.getValue()).doubleValue();
157
                                data = entity.getDwgObjectSpecificDataItem("START_ANGLE");
158
                                double startAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
159
                                data = entity.getDwgObjectSpecificDataItem("END_ANGLE");
160
                                double endAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
161
                                FPolyline2D arc = createArc(center, radius, startAngle, endAngle);
162
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
163
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
164
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
165
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
166
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
167
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
168
                    // Attributes
169
                    /*for (int j=0;j<nAtt;j++) {
170
                                    String[] attributes = new String[2];
171
                                    attributes = (String[])featureMaker.getAttributes().get(j);
172
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
173
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
174
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
175
                        }
176
                    }*/
177
                                addShape(arc, auxRow);
178
                        } else if (entity.getType()==0x12) {
179
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
180
                                double[] coord = (double[])data.getValue();
181
                                Point2D center = new Point2D.Double(coord[0], coord[1]);
182
                                data = entity.getDwgObjectSpecificDataItem("RADIUS");
183
                                double radius = ((Double)data.getValue()).doubleValue();
184
                                FPolyline2D circle = createCircle(center, radius);
185
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
186
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
187
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
188
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
189
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
190
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
191
                    // Attributes
192
                    /*for (int j=0;j<nAtt;j++) {
193
                                    String[] attributes = new String[2];
194
                                    attributes = (String[])featureMaker.getAttributes().get(j);
195
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
196
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
197
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
198
                        }
199
                    }*/
200
                                addShape(circle, auxRow);
201
                        } else if (entity.getType()==0x13) {
202
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("P1");
203
                                double[] coord = (double[])data.getValue();
204
                                Point2D p1 = new Point2D.Double(coord[0], coord[1]);
205
                                data = entity.getDwgObjectSpecificDataItem("P2");
206
                                coord = (double[])data.getValue();
207
                                Point2D p2 = new Point2D.Double(coord[0], coord[1]);
208
                                FPolyline2D line = createLine(p1, p2);
209
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
210
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
211
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
212
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
213
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
214
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
215
                    // Attributes
216
                    /*for (int j=0;j<nAtt;j++) {
217
                                    String[] attributes = new String[2];
218
                                    attributes = (String[])featureMaker.getAttributes().get(j);
219
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
220
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
221
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
222
                        }
223
                    }*/
224
                                addShape(line, auxRow);
225
                        } else if (entity.getType()==0x1B) {
226
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("POINT");
227
                                double[] coord = (double[])data.getValue();
228
                                Point2D p = new Point2D.Double(coord[0], coord[1]);
229
                                FPoint2D point = createPoint(p);
230
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
231
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
232
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
233
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
234
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
235
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
236
                    // Attributes
237
                    /*for (int j=0;j<nAtt;j++) {
238
                                    String[] attributes = new String[2];
239
                                    attributes = (String[])featureMaker.getAttributes().get(j);
240
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
241
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
242
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
243
                        }
244
                    }*/
245
                                addShape(point, auxRow);
246
                        } else if (entity.getType()==0x0F) {
247
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("FLAGS");
248
                                int flags = ((Integer)data.getValue()).intValue();
249
                                data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE");
250
                                int[] firstVertexHandle = (int[])data.getValue();
251
                                byte[] firstHandleBytes = new byte[]{0,0,0,0};
252
                                if (firstVertexHandle.length>2) firstHandleBytes[3] = (byte)firstVertexHandle[2];
253
                                if (firstVertexHandle.length>3) firstHandleBytes[2] = (byte)firstVertexHandle[3];
254
                                if (firstVertexHandle.length>4) firstHandleBytes[1] = (byte)firstVertexHandle[4];
255
                                if (firstVertexHandle.length>5) firstHandleBytes[0] = (byte)firstVertexHandle[5];
256
                                int firstHandle = ByteUtils.bytesToInt(firstHandleBytes, new int[]{0});
257
                                data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE");
258
                                int[] lastVertexHandle = (int[])data.getValue();
259
                                byte[] lastHandleBytes = new byte[]{0,0,0,0};
260
                                if (lastVertexHandle.length>2) lastHandleBytes[3] = (byte)lastVertexHandle[2];
261
                                if (lastVertexHandle.length>3) lastHandleBytes[2] = (byte)lastVertexHandle[3];
262
                                if (lastVertexHandle.length>4) lastHandleBytes[1] = (byte)lastVertexHandle[4];
263
                                if (lastVertexHandle.length>5) lastHandleBytes[0] = (byte)lastVertexHandle[5];
264
                                int lastHandle = ByteUtils.bytesToInt(lastHandleBytes, new int[]{0});
265
                                Vector pts = new Vector();
266
                                double[] pt = new double[2];
267
                                
268
                                for (int j=0;j<dwgObjects.size();j++) {
269
                                        DwgObject obj = (DwgObject)dwgObjects.get(j);
270
                                        Vector handle = obj.getHandle();
271
                                        byte[] handleBytes = new byte[]{0,0,0,0};
272
                                        if (handle.size()>2) handleBytes[3] = ((Integer)handle.get(2)).byteValue();
273
                                        if (handle.size()>3) handleBytes[2] = ((Integer)handle.get(3)).byteValue();
274
                                        if (handle.size()>4) handleBytes[1] = ((Integer)handle.get(4)).byteValue();
275
                                        if (handle.size()>5) handleBytes[0] = ((Integer)handle.get(5)).byteValue();
276
                                        int objHandle = ByteUtils.bytesToInt(handleBytes, new int[]{0});
277
                                        if (objHandle==firstHandle && ((Integer)handle.get(1)).intValue()==firstVertexHandle[1]) {
278
                                                int k=0;
279
                                                while (true) {
280
                                                        DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
281
                                                        Vector vertexHandle = vertex.getHandle();
282
                                                        byte[] vHandleBytes = new byte[]{0,0,0,0};
283
                                                        if (vertexHandle.size()>2) vHandleBytes[3] = ((Integer)vertexHandle.get(2)).byteValue();
284
                                                        if (vertexHandle.size()>3) vHandleBytes[2] = ((Integer)vertexHandle.get(3)).byteValue();
285
                                                        if (vertexHandle.size()>4) vHandleBytes[1] = ((Integer)vertexHandle.get(4)).byteValue();
286
                                                        if (vertexHandle.size()>5) vHandleBytes[0] = ((Integer)vertexHandle.get(5)).byteValue();
287
                                                        int vHandle = ByteUtils.bytesToInt(vHandleBytes, new int[]{0});
288
                                                        data = vertex.getDwgObjectSpecificDataItem("POINT");
289
                                                        pt = (double[])data.getValue();
290
                                                        pts.add(new Point2D.Double(pt[0], pt[1]));
291
                                                        k++;
292
                                                        if (vHandle==lastHandle && ((Integer)vertexHandle.get(1)).intValue()==lastVertexHandle[1]) {
293
                                                                break;
294
                                                        }
295
                                                }
296
                                        }
297
                                }
298
                                
299
                                Point2D[] newPts = new Point2D[pts.size()];
300
                                if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) {
301
                                        for (int j=0;j<pts.size();j++) {
302
                                                newPts[j] = (Point2D)pts.get(j);
303
                                        }
304
                                } else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) {
305
                                        newPts = new Point2D[pts.size()+1];
306
                                        for (int j=0;j<pts.size();j++) {
307
                                                newPts[j] = (Point2D)pts.get(j);
308
                                        }
309
                                        newPts[pts.size()] = (Point2D)pts.get(0);
310
                                }
311
                                FPolyline2D pline = createPolyline2D(newPts);
312
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
313
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
314
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
315
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
316
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
317
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
318
                    // Attributes
319
                    /*for (int j=0;j<nAtt;j++) {
320
                                    String[] attributes = new String[2];
321
                                    attributes = (String[])featureMaker.getAttributes().get(j);
322
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
323
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
324
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
325
                        }
326
                    }*/
327
                                addShape(pline, auxRow);
328
                        } else if (entity.getType()==0x10) {
329
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CLOSED_FLAGS");
330
                                int flags = ((Integer)data.getValue()).intValue();
331
                                data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE");
332
                                int[] firstVertexHandle = (int[])data.getValue();
333
                                data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE");
334
                                int[] lastVertexHandle = (int[])data.getValue();
335
                                data = entity.getDwgObjectSpecificDataItem("SEQEND_HANDLE");
336
                                int[] seqendHandle = (int[])data.getValue();
337
                                int vertexNumber = calculateVertexNumber(firstVertexHandle, lastVertexHandle);
338
                                Point2D[] pts = new Point2D[vertexNumber];
339
                                double[] pt = new double[2];
340
                                
341
                                for (int j=0;j<dwgObjects.size();j++) {
342
                                        DwgObject v = (DwgObject)dwgObjects.get(j);
343
                                        Vector handle = v.getHandle();
344
                                        if (((Integer)handle.get(handle.size()-2)).intValue()==firstVertexHandle[handle.size()-2] && ((Integer)handle.get(handle.size()-1)).intValue()==firstVertexHandle[handle.size()-1]) {
345
                                                for (int k=0; k<vertexNumber; k++) {
346
                                                        DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
347
                                                        data = vertex.getDwgObjectSpecificDataItem("POINT");
348
                                                        pt = (double[])data.getValue();
349
                                                        pts[k] = new Point2D.Double(pt[0], pt[1]);
350
                                                }
351
                                        }
352
                                }
353
                                Point2D[] newPts = new Point2D[pts.length];
354
                                if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) {
355
                                        newPts = pts;
356
                                } else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) {
357
                                        newPts = new Point2D[pts.length+1];
358
                                        for (int j=0;j<pts.length;j++) {
359
                                                newPts[j] = pts[j];
360
                                        }
361
                                        newPts[pts.length] = pts[0];
362
                                }
363
                                FPolyline2D pline3d = createPolyline2D(newPts);
364
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
365
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
366
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
367
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
368
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
369
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
370
                    // Attributes
371
                    /*for (int j=0;j<nAtt;j++) {
372
                                    String[] attributes = new String[2];
373
                                    attributes = (String[])featureMaker.getAttributes().get(j);
374
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
375
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
376
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
377
                        }
378
                    }*/
379
                                addShape(pline3d, auxRow);
380
                        } else if (entity.getType()==0x1) {
381
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
382
                                Point2D p = (Point2D)data.getValue();
383
                                FPoint2D point = createPoint(p);
384
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
385
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
386
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
387
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
388
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
389
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
390
                    // Attributes
391
                    /*for (int j=0;j<nAtt;j++) {
392
                                    String[] attributes = new String[2];
393
                                    attributes = (String[])featureMaker.getAttributes().get(j);
394
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
395
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
396
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
397
                        }
398
                    }*/
399
                                addShape(point, auxRow);
400
                        } else if (entity.getType()==0x4) {
401
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("NAME");
402
                                //String blockName = (String)data.getValue();
403
                                //addingToBlock = true;
404
                                //pto = (Point2D.Double)point.get(0);
405
                                //FShape nuevoShp;
406
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
407
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
408
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
409
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
410
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
411
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
412
                    // Attributes
413
                    /*for (int j=0;j<nAtt;j++) {
414
                                    String[] attributes = new String[2];
415
                                    attributes = (String[])featureMaker.getAttributes().get(j);
416
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
417
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
418
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
419
                        }
420
                    }*/
421
                                //addShape(point, auxRow);
422
                        } else if (entity.getType()==0x5) {
423
                                //addingToBlock = false;
424
                                //pto = (Point2D.Double)point.get(0);
425
                                //FShape nuevoShp;
426
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
427
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
428
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
429
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
430
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
431
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
432
                    // Attributes
433
                    /*for (int j=0;j<nAtt;j++) {
434
                                    String[] attributes = new String[2];
435
                                    attributes = (String[])featureMaker.getAttributes().get(j);
436
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
437
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
438
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
439
                        }
440
                    }*/
441
                                //addShape(point, auxRow);
442
                        } else if (entity.getType()==0x30) {
443
                                //addingToBlock = false;
444
                                //pto = (Point2D.Double)point.get(0);
445
                                //FShape nuevoShp;
446
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
447
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
448
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
449
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
450
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
451
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
452
                    // Attributes
453
                    /*for (int j=0;j<nAtt;j++) {
454
                                    String[] attributes = new String[2];
455
                                    attributes = (String[])featureMaker.getAttributes().get(j);
456
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
457
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
458
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
459
                        }
460
                    }*/
461
                                //addShape(point, auxRow);
462
                        } else if (entity.getType()==0x31) {
463
                                //addingToBlock = false;
464
                                //pto = (Point2D.Double)point.get(0);
465
                                //FShape nuevoShp;
466
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
467
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
468
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
469
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
470
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
471
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
472
                    // Attributes
473
                    /*for (int j=0;j<nAtt;j++) {
474
                                    String[] attributes = new String[2];
475
                                    attributes = (String[])featureMaker.getAttributes().get(j);
476
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
477
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
478
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
479
                        }
480
                    }*/
481
                                //addShape(point, auxRow);
482
                        } else if (entity.getType()==0x7) {
483
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
484
                                double[] p = (double[])data.getValue();
485
                                Point2D point = new Point2D.Double(p[0], p[1]);
486
                                data = entity.getDwgObjectSpecificDataItem("SCALE");
487
                                double[] scale = (double[])data.getValue();
488
                                data = entity.getDwgObjectSpecificDataItem("ROTATION");
489
                double rot = ((Double)data.getValue()).doubleValue();
490
                                data = entity.getDwgObjectSpecificDataItem("BLOCK_HEADER_HANDLE");
491
                                int[] blockHandle = (int[])data.getValue();
492
                                byte[] blockHandleBytes = new byte[]{0,0,0,0};
493
                                if (blockHandle.length>2) blockHandleBytes[3] = (byte)blockHandle[2];
494
                                if (blockHandle.length>3) blockHandleBytes[2] = (byte)blockHandle[3];
495
                                if (blockHandle.length>4) blockHandleBytes[1] = (byte)blockHandle[4];
496
                                if (blockHandle.length>5) blockHandleBytes[0] = (byte)blockHandle[5];
497
                                int bHandle = ByteUtils.bytesToInt(blockHandleBytes, new int[]{0});
498
                                
499
                                for (int j=0;j<dwgObjects.size();j++) {
500
                                        DwgObject obj = (DwgObject)dwgObjects.get(j);
501
                                        Vector handle = obj.getHandle();
502
                                        byte[] handleBytes = new byte[]{0,0,0,0};
503
                                        if (handle.size()>2) handleBytes[3] = ((Integer)handle.get(2)).byteValue();
504
                                        if (handle.size()>3) handleBytes[2] = ((Integer)handle.get(3)).byteValue();
505
                                        if (handle.size()>4) handleBytes[1] = ((Integer)handle.get(4)).byteValue();
506
                                        if (handle.size()>5) handleBytes[0] = ((Integer)handle.get(5)).byteValue();
507
                                        int objHandle = ByteUtils.bytesToInt(handleBytes, new int[]{0});
508
                                        if (objHandle==bHandle && ((Integer)handle.get(1)).intValue()==blockHandle[1]) {
509
                                                
510
                                                data = entity.getDwgObjectSpecificDataItem("BASE_POINT");
511
                                                double[] bPoint = (double[])data.getValue();
512
                                                data = entity.getDwgObjectSpecificDataItem("FIRST_ENTITY_HANDLE");
513
                                                int[] firstEntityHandle = (int[])data.getValue();
514
                                                byte[] firstEntityBytes = new byte[]{0,0,0,0};
515
                                                if (firstEntityHandle.length>2) firstEntityBytes[3] = (byte)firstEntityHandle[2];
516
                                                if (firstEntityHandle.length>3) firstEntityBytes[2] = (byte)firstEntityHandle[3];
517
                                                if (firstEntityHandle.length>4) firstEntityBytes[1] = (byte)firstEntityHandle[4];
518
                                                if (firstEntityHandle.length>5) firstEntityBytes[0] = (byte)firstEntityHandle[5];
519
                                                int firstHandle = ByteUtils.bytesToInt(firstEntityBytes, new int[]{0});
520
                                                data = entity.getDwgObjectSpecificDataItem("LAST_ENTITY_HANDLE");
521
                                                int[] lastEntityHandle = (int[])data.getValue();
522
                                                byte[] lastEntityBytes = new byte[]{0,0,0,0};
523
                                                if (lastEntityHandle.length>2) lastEntityBytes[3] = (byte)lastEntityHandle[2];
524
                                                if (lastEntityHandle.length>3) lastEntityBytes[2] = (byte)lastEntityHandle[3];
525
                                                if (lastEntityHandle.length>4) lastEntityBytes[1] = (byte)lastEntityHandle[4];
526
                                                if (lastEntityHandle.length>5) lastEntityBytes[0] = (byte)lastEntityHandle[5];
527
                                                int lastHandle = ByteUtils.bytesToInt(lastEntityBytes, new int[]{0});
528
                                                
529
                                                for (int k=0;k<dwgObjects.size();k++) {
530
                                                        DwgObject ent = (DwgObject)dwgObjects.get(k);
531
                                                        Vector entHandle = ent.getHandle();
532
                                                        byte[] entHandleBytes = new byte[]{0,0,0,0};
533
                                                        if (entHandle.size()>2) entHandleBytes[3] = ((Integer)entHandle.get(2)).byteValue();
534
                                                        if (entHandle.size()>3) entHandleBytes[2] = ((Integer)entHandle.get(3)).byteValue();
535
                                                        if (entHandle.size()>4) entHandleBytes[1] = ((Integer)entHandle.get(4)).byteValue();
536
                                                        if (entHandle.size()>5) entHandleBytes[0] = ((Integer)entHandle.get(5)).byteValue();
537
                                                        int eHandle = ByteUtils.bytesToInt(entHandleBytes, new int[]{0});
538
                                                        if (eHandle==firstHandle && ((Integer)entHandle.get(1)).intValue()==firstEntityHandle[1]) {
539
                                                                int l=0;
540
                                                                while (true) {
541
                                                                        DwgObject blockEntity = (DwgObject)dwgObjects.get(k+l);
542
                                                                        Vector blockEntityHandle = blockEntity.getHandle();
543
                                                                        byte[] blockEntityHandleBytes = new byte[]{0,0,0,0};
544
                                                                        if (blockEntityHandle.size()>2) blockEntityHandleBytes[3] = ((Integer)blockEntityHandle.get(2)).byteValue();
545
                                                                        if (blockEntityHandle.size()>3) blockEntityHandleBytes[2] = ((Integer)blockEntityHandle.get(3)).byteValue();
546
                                                                        if (blockEntityHandle.size()>4) blockEntityHandleBytes[1] = ((Integer)blockEntityHandle.get(4)).byteValue();
547
                                                                        if (blockEntityHandle.size()>5) blockEntityHandleBytes[0] = ((Integer)blockEntityHandle.get(5)).byteValue();
548
                                                                        int bEntityHandle = ByteUtils.bytesToInt(blockEntityHandleBytes, new int[]{0});
549
                                                                        manageBlockEntity(blockEntity, bPoint, point, scale, rot, auxRow);
550
                                                                        l++;
551
                                                                        if (bEntityHandle==lastHandle && ((Integer)entHandle.get(1)).intValue()==lastEntityHandle[1]) {
552
                                                                                break;
553
                                                                        }
554
                                                                }
555
                                                        }
556
                                                }
557
                                        }
558
                                }
559
                                
560
                                /*auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
561
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
562
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
563
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
564
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
565
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/
566
                    // Attributes
567
                    /*for (int j=0;j<nAtt;j++) {
568
                                    String[] attributes = new String[2];
569
                                    attributes = (String[])featureMaker.getAttributes().get(j);
570
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
571
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
572
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
573
                        }
574
                    }*/
575
                                //addShape(point, auxRow);
576
                        } else if (entity.getType()==0x2C) {
577
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
578
                                double[] coord = (double[])data.getValue();
579
                                Point2D p = new Point2D.Double(coord[0], coord[1]);
580
                                FPoint2D point = createPoint(p);
581
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
582
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
583
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
584
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
585
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
586
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
587
                    // Attributes
588
                    /*for (int j=0;j<nAtt;j++) {
589
                                    String[] attributes = new String[2];
590
                                    attributes = (String[])featureMaker.getAttributes().get(j);
591
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
592
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
593
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
594
                        }
595
                    }*/
596
                                addShape(point, auxRow);
597
                        } else if (entity.getType()==0x1F) {
598
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CORNER1");
599
                                double[] coord = (double[])data.getValue();
600
                                Point2D p1 = new Point2D.Double(coord[0], coord[1]);
601
                                data = entity.getDwgObjectSpecificDataItem("CORNER2");
602
                                coord = (double[])data.getValue();
603
                                Point2D p2 = new Point2D.Double(coord[0], coord[1]);
604
                                data = entity.getDwgObjectSpecificDataItem("CORNER3");
605
                                coord = (double[])data.getValue();
606
                                Point2D p3 = new Point2D.Double(coord[0], coord[1]);
607
                                data = entity.getDwgObjectSpecificDataItem("CORNER4");
608
                                coord = (double[])data.getValue();
609
                                Point2D p4 = new Point2D.Double(coord[0], coord[1]);
610
                                FPolygon2D solid = createSolid(new Point2D[]{p1, p2, p4, p3});
611
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
612
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
613
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
614
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
615
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
616
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
617
                    // Attributes
618
                    /*for (int j=0;j<nAtt;j++) {
619
                                    String[] attributes = new String[2];
620
                                    attributes = (String[])featureMaker.getAttributes().get(j);
621
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
622
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
623
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
624
                        }
625
                    }*/
626
                                addShape(solid, auxRow);
627
                        } else if (entity.getType()==0x24) {
628
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("SCENARIO");
629
                                int sc = ((Integer)data.getValue()).intValue();
630
                                if (sc==1) {
631
                                        data = entity.getDwgObjectSpecificDataItem("CONTROL_POINTS");
632
                                } else if (sc==2) {
633
                                        data = entity.getDwgObjectSpecificDataItem("FIT_POINTS");
634
                                }
635
                                double[][] vertices = (double[][])data.getValue();
636
                                Point2D[] pts = new Point2D[vertices.length];
637
                                double[] pt = new double[2];
638
                                for (int j=0; j<vertices.length; j++) {
639
                                         pt = (double[])vertices[j];
640
                                         pts[j] = new Point2D.Double(pt[0], pt[1]);
641
                                }
642
                                FPolyline2D spline = createLwPolyline(pts);
643
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
644
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
645
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
646
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
647
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
648
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
649
                    // Attributes
650
                    /*for (int j=0;j<nAtt;j++) {
651
                                    String[] attributes = new String[2];
652
                                    attributes = (String[])featureMaker.getAttributes().get(j);
653
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
654
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
655
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
656
                        }
657
                    }*/
658
                                addShape(spline, auxRow);
659
                        } else if (dwg.getDxfNames().size()>0) {
660
                                int type = 0;
661
                                for (int j=0; j<dwg.getDxfNames().size(); j++) {
662
                                        String dxfName = ((DxfName)dwg.getDxfNames().get(j)).getDxfName();
663
                                        if (dxfName.equals("LWPOLYLINE")) {
664
                                                type = ((DxfName)dwg.getDxfNames().get(j)).getKey();
665
                                                break;
666
                                        }
667
                                }
668
                                if (entity.getType()==type) {
669
                                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("VERTICES");
670
                                        Vector vertices = (Vector)data.getValue();
671
                                        Point2D[] pts = new Point2D[vertices.size()];
672
                                        double[] pt = new double[2];
673
                                        for (int j=0; j<vertices.size(); j++) {
674
                                                 pt = (double[])vertices.get(j);
675
                                                 pts[j] = new Point2D.Double(pt[0], pt[1]);
676
                                        }
677
                                        FPolyline2D lwpline = createLwPolyline(pts);
678
                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
679
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
680
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
681
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
682
                            auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
683
                            auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
684
                            // Attributes
685
                            /*for (int j=0;j<nAtt;j++) {
686
                                            String[] attributes = new String[2];
687
                                            attributes = (String[])featureMaker.getAttributes().get(j);
688
                                auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
689
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
690
                                        auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
691
                                }
692
                            }*/
693
                                        addShape(lwpline, auxRow);
694
                                }
695
                        } else {
696
                                System.out.println("Detectado dwgObject pendiente de implementar");
697
                        }
698
                }
699
                timeElapsed = System.currentTimeMillis()-time;
700
                System.out.println("Tiempo empleado por el driver en importar el contenido del dwg = " + timeElapsed);
701
                
702
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
703
                defaultLegend.setFieldName("Color");
704
                defaultLegend.setLabelField("Text");
705
                defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
706
                defaultLegend.getDefaultSymbol().setShapeVisible(false);
707
                defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
708
                defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9));
709
                defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
710
                defaultLegend.getDefaultSymbol().setFontSize(heightText);
711
                defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
712
                defaultLegend.getDefaultSymbol().setSize(3);
713
                defaultLegend.getDefaultSymbol().setSizeInPixels(true);
714
                
715
                defaultLegend.setLabelHeightField("HeightText");
716
                defaultLegend.setLabelRotationField("RotationText");
717
                
718
        ObjectDriver rs = this;
719
                IntValue clave;
720
                FSymbol theSymbol = null;
721
                
722
                try {
723
                    // TODO: Provisional hasta que cambiemos los s?mbolos.
724
                   /*  BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
725
                   Graphics2D big = bi.createGraphics();
726
                   Color color=new Color(0,0,0,0);
727
                   big.setBackground(color);
728
                   big.clearRect(0, 0, 5, 5);
729
                   Paint fillProv = null; 
730
                   Rectangle2D rProv = new Rectangle();
731
                   rProv.setFrame(0, 0,5,5);
732
                   fillProv = new TexturePaint(bi,rProv); */                    
733
                    
734
                        for (long j = 0; j < rs.getRowCount(); j++)
735
                        {
736
                                clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR);
737
                                if (defaultLegend.getSymbolByValue(clave) == null)
738
                                {
739
                                        theSymbol = new FSymbol(getShapeType());
740
                                        theSymbol.setDescription(clave.toString());
741
                                        theSymbol.setColor(AcadColor.getColor(clave.getValue()));
742
                                        // theSymbol.setFill(fillProv);
743
                                        // 050202, jmorell: Asigna los colores de Autocad a los bordes
744
                                        //                                        de los pol?gonos.
745
                                        theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue()));
746
                                        
747
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
748
                                        theSymbol.setSize(3);
749
                                        theSymbol.setSizeInPixels(true);
750
                                        
751
                                        defaultLegend.addSymbol(clave, theSymbol);
752
                                }
753
                        } // for
754
                } catch (DriverException e) {
755
                        e.printStackTrace();
756
                        throw new IOException("Error al poner la leyenda por defecto en el Dwg");
757
                }
758
        }
759
        
760
        /**
761
         * En principio exportamos a FPolyline2D, despues estudiaremos la conveniencia
762
         * de exportar a FPolygon2D, o a las dos cosas ...
763
         * Esta clase construye el circle del mismo modo que en DxfFeatureMaker.
764
         * Se podr?a renombrar esta clase a createCircleFeature y a?adir otra
765
         * createCircleEntity ...
766
         * La parte de creaci?n de la FPolyline2D est? sacada del DxfMemoryDriver ...
767
         * @param center
768
         * @param radius
769
         * @return
770
         */
771
        private FPolyline2D createCircle(Point2D c, double r) {
772
                Point2D[] pts = new Point2D[360];
773
                int angulo = 0;
774
                for (angulo=0; angulo<360; angulo++) {
775
                        pts[angulo] = new Point2D.Double(c.getX(), c.getY());
776
                        pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0));
777
                }
778
                GeneralPathX genPathX = new GeneralPathX();
779
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
780
                for (int i=1; i<pts.length; i++) {
781
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
782
                }
783
                return new FPolyline2D(genPathX);
784
        }
785
        
786
        /**
787
         * Como createCircle ...
788
         * @param c
789
         * @param r
790
         * @param sa
791
         * @param ea
792
         * @return
793
         */
794
        private FPolyline2D createArc(Point2D c, double r, double sa, double ea) {
795
                int isa = (int)sa;
796
                int iea = (int)ea;
797
                double angulo;
798
                Point2D[] pts;
799
                if (sa <= ea) {
800
                        pts = new Point2D[(iea-isa)+2];
801
                        angulo = sa;
802
                        pts[0] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
803
                        for (int i=1; i<=(iea-isa)+1; i++) {
804
                                angulo = (double)(isa+i);
805
                                pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
806
                        }
807
                        angulo = ea;
808
                        pts[(iea-isa)+1] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
809
                } else {
810
                        pts = new Point2D[(360-isa)+iea+2];
811
                        angulo = sa;
812
                        pts[0] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
813
                        for (int i=1; i<=(360-isa); i++) {
814
                                angulo = (double)(isa+i);
815
                                pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
816
                        }
817
                        for (int i=(360-isa)+1; i<=(360-isa)+iea; i++) {
818
                                angulo = (double)(i-(360-isa));
819
                                pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
820
                        }
821
                        angulo = ea;
822
                        pts[(360-isa)+iea+1] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
823
                }
824
                GeneralPathX genPathX = new GeneralPathX();
825
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
826
                for (int i=1; i<pts.length; i++) {
827
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
828
                }
829
                return new FPolyline2D(genPathX);
830
        }
831
        
832
        /**
833
         * Los nombres de estos m?todos pueden cambiarse por otros m?s apropiados, por
834
         * ejemplo:
835
         * createLine --> dwgLineToFPolyline2D ... ?mejor as?? ...
836
         * @param p1
837
         * @param p2
838
         * @return
839
         */
840
        private FPolyline2D createLine(Point2D p1, Point2D p2) {
841
                Point2D[] pts = new Point2D[]{p1, p2};
842
                GeneralPathX genPathX = new GeneralPathX();
843
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
844
                for (int i=1; i<pts.length; i++) {
845
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
846
                }
847
                return new FPolyline2D(genPathX);
848
        }
849
        
850
        private FPoint2D createPoint(Point2D p) {
851
                return new FPoint2D(p.getX(), p.getY());
852
        }
853
        
854
        private FPolyline2D createLwPolyline(Point2D[] pts) {
855
                GeneralPathX genPathX = new GeneralPathX();
856
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
857
                for (int i=1; i<pts.length; i++) {
858
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
859
                }
860
                return new FPolyline2D(genPathX);
861
        }
862
        
863
        private FPolyline2D createPolyline2D(Point2D[] pts) {
864
                GeneralPathX genPathX = new GeneralPathX();
865
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
866
                for (int i=1; i<pts.length; i++) {
867
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
868
                }
869
                return new FPolyline2D(genPathX);
870
        }
871
        
872
        private FPolygon2D createSolid(Point2D[] pts) {
873
                GeneralPathX genPathX = new GeneralPathX();
874
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
875
                for (int i=1; i<pts.length; i++) {
876
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
877
                }
878
                genPathX.closePath();
879
                return new FPolygon2D(genPathX);
880
        }
881
        
882
        private int calculateVertexNumber(int[] firstVertexHandle, int[] lastVertexHandle) {
883
                if (firstVertexHandle.length==lastVertexHandle.length) {
884
                        if (firstVertexHandle[firstVertexHandle.length-2]==lastVertexHandle[firstVertexHandle.length-2]) {
885
                                return (lastVertexHandle[firstVertexHandle.length-1]-firstVertexHandle[firstVertexHandle.length-1]+1);
886
                        } else {
887
                                int aux = 255-firstVertexHandle[firstVertexHandle.length-1]+1;
888
                                int aux2 = lastVertexHandle[firstVertexHandle.length-1]+1;
889
                                int aux3 = (lastVertexHandle[firstVertexHandle.length-2]-firstVertexHandle[firstVertexHandle.length-2]-1)*255;
890
                                int vn = aux + aux2 + aux3;
891
                                return vn;
892
                        }
893
                } else if (firstVertexHandle.length==(lastVertexHandle.length-1)) {
894
                        int aux = 255-firstVertexHandle[firstVertexHandle.length-1]+1;
895
                        int aux2 = lastVertexHandle[firstVertexHandle.length]+1;
896
                        int aux3 = (lastVertexHandle[lastVertexHandle.length-2]-1)*255;
897
                        int vn = aux + aux2 + aux3;
898
                        return vn;
899
                } else {
900
                        System.out.println("ERROR: firstVertexHandle y lastVertexHandle tienen tama?os inesperados");
901
                        return 0;
902
                }
903
        }
904
        
905
        private void manageBlockEntity(DwgObject entity, double[] bPoint, Point2D insPoint, double[] scale, double rot, Value[] auxRow) {
906
                if (entity.getType()==0x11) {
907
                        /*DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
908
                        double[] coord = (double[])data.getValue();
909
                        Point2D center = new Point2D.Double(coord[0], coord[1]);
910
                        data = entity.getDwgObjectSpecificDataItem("RADIUS");
911
                        double radius = ((Double)data.getValue()).doubleValue();
912
                        data = entity.getDwgObjectSpecificDataItem("START_ANGLE");
913
                        double startAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
914
                        data = entity.getDwgObjectSpecificDataItem("END_ANGLE");
915
                        double endAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
916
                        FPolyline2D arc = createArc(center, radius, startAngle, endAngle);
917
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(0);
918
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
919
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
920
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
921
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
922
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/
923
                // Attributes
924
                /*for (int j=0;j<nAtt;j++) {
925
                                String[] attributes = new String[2];
926
                                attributes = (String[])featureMaker.getAttributes().get(j);
927
                    auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
928
                    if (!fea.getProp(attributes[0]).equals(attributes[1])) {
929
                            auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
930
                    }
931
                }*/
932
                        //addShape(arc, auxRow);
933
                } else if (entity.getType()==0x12) {
934
                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
935
                        double[] coord = (double[])data.getValue();
936
                        Point2D center = new Point2D.Double(coord[0], coord[1]);
937
                        data = entity.getDwgObjectSpecificDataItem("RADIUS");
938
                        double radius = ((Double)data.getValue()).doubleValue();
939
                        
940
                        Point2D pointAux = new Point2D.Double(center.getX() - bPoint[0], center.getY() - bPoint[1]);
941
                        double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*(-1)*Math.sin(Math.toRadians(rot)));
942
                        double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*Math.cos(Math.toRadians(rot)));
943
                        center = new Point2D.Double(laX, laY);
944
                        // Escala en X = escala en Y ...
945
                        radius = radius * scale[0];
946
                        
947
                        FPolyline2D circle = createCircle(center, radius);
948
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(0);
949
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
950
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
951
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
952
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
953
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
954
                // Attributes
955
                /*for (int j=0;j<nAtt;j++) {
956
                                String[] attributes = new String[2];
957
                                attributes = (String[])featureMaker.getAttributes().get(j);
958
                    auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
959
                    if (!fea.getProp(attributes[0]).equals(attributes[1])) {
960
                            auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
961
                    }
962
                }*/
963
                        addShape(circle, auxRow);
964
                } else if (entity.getType()==0x13) {
965
                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("P1");
966
                        double[] coord = (double[])data.getValue();
967
                        Point2D p1 = new Point2D.Double(coord[0], coord[1]);
968
                        data = entity.getDwgObjectSpecificDataItem("P2");
969
                        coord = (double[])data.getValue();
970
                        Point2D p2 = new Point2D.Double(coord[0], coord[1]);
971
                        
972
                        Point2D pointAux = new Point2D.Double(p1.getX() - bPoint[0], p1.getY() - bPoint[1]);
973
                        double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*(-1)*Math.sin(Math.toRadians(rot)));
974
                        double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*Math.cos(Math.toRadians(rot)));
975
                        p1 = new Point2D.Double(laX, laY);
976
                        pointAux = new Point2D.Double(p2.getX() - bPoint[0], p2.getY() - bPoint[1]);
977
                        laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*(-1)*Math.sin(Math.toRadians(rot)));
978
                        laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*Math.cos(Math.toRadians(rot)));
979
                        p2 = new Point2D.Double(laX, laY);
980
                        
981
                        FPolyline2D line = createLine(p1, p2);
982
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(0);
983
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
984
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
985
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
986
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
987
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
988
                // Attributes
989
                /*for (int j=0;j<nAtt;j++) {
990
                                String[] attributes = new String[2];
991
                                attributes = (String[])featureMaker.getAttributes().get(j);
992
                    auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
993
                    if (!fea.getProp(attributes[0]).equals(attributes[1])) {
994
                            auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
995
                    }
996
                }*/
997
                        addShape(line, auxRow);
998
                }
999
        }
1000

    
1001
        /* (non-Javadoc)
1002
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
1003
         */
1004
        public boolean accept(File f) {
1005
                return f.getName().toUpperCase().endsWith("DWG");
1006
        }
1007

    
1008
        /* (non-Javadoc)
1009
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
1010
         */
1011
        public int getShapeType() {
1012
                return FShape.MULTI;
1013
        }
1014

    
1015
        /* (non-Javadoc)
1016
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
1017
         */
1018
        public String getName() {
1019
                return "gvSIG DWG Memory Driver";
1020
        }
1021

    
1022
        /* (non-Javadoc)
1023
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
1024
         */
1025
        public Legend getDefaultLegend() {
1026
                return defaultLegend;
1027
        }
1028

    
1029
    /* (non-Javadoc)
1030
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
1031
     */
1032
    public DriverAttributes getDriverAttributes() {
1033
        return attr;
1034
    }
1035

    
1036
}