Statistics
| Revision:

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

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

    
980
        /* (non-Javadoc)
981
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
982
         */
983
        public boolean accept(File f) {
984
                return f.getName().toUpperCase().endsWith("DWG");
985
        }
986

    
987
        /* (non-Javadoc)
988
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
989
         */
990
        public int getShapeType() {
991
                return FShape.MULTI;
992
        }
993

    
994
        /* (non-Javadoc)
995
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
996
         */
997
        public String getName() {
998
                return "gvSIG DWG Memory Driver";
999
        }
1000

    
1001
        /* (non-Javadoc)
1002
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
1003
         */
1004
        public Legend getDefaultLegend() {
1005
                return defaultLegend;
1006
        }
1007

    
1008
    /* (non-Javadoc)
1009
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
1010
     */
1011
    public DriverAttributes getDriverAttributes() {
1012
        return attr;
1013
    }
1014

    
1015
}