Statistics
| Revision:

root / trunk / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / DwgMemoryDriver.java @ 11061

History | View | Annotate | Download (20.5 KB)

1
/*
2
 * Created on 14-abr-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 * DwgMemoryDriver 0.2. Driver del formato DWG para gvSIG
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id: DwgMemoryDriver.java 11061 2007-04-04 17:49:06Z azabala $
48
 * $Log$
49
 * Revision 1.11  2007-04-04 17:49:06  azabala
50
 * Dependencies of libDwg with libFMap removed
51
 *
52
 * Revision 1.10  2007/03/22 19:56:12  azabala
53
 * changes in exceptinos api
54
 *
55
 * Revision 1.9  2007/03/20 20:21:19  azabala
56
 * added roi filtering, reordering of code
57
 *
58
 * Revision 1.7  2007/02/27 17:18:03  azabala
59
 * solved bug with text orientation
60
 *
61
 * Revision 1.6  2007/02/14 16:17:22  azabala
62
 * *** empty log message ***
63
 *
64
 * Revision 1.5  2007/01/20 18:30:37  azabala
65
 * refactoring of blocks
66
 *
67
 * Revision 1.4  2007/01/18 19:59:10  azabala
68
 * refactoring to optimize and simplify the code
69
 *
70
 * Revision 1.3  2007/01/18 13:36:42  azabala
71
 * Refactoring general para evitar dar tantas pasadas en la carga, y para incrementar
72
 * la legibilidad del codigo (demasiados if-else-if en vez de usar polimorfismo)
73
 *
74
 * Revision 1.2  2007/01/12 19:57:44  azabala
75
 * *** empty log message ***
76
 *
77
 * Revision 1.1  2007/01/11 20:31:05  azabala
78
 * *** empty log message ***
79
 *
80
 *
81
 */
82
package com.iver.cit.gvsig.drivers.dwg;
83

    
84
import java.awt.Color;
85
import java.awt.Font;
86
import java.awt.geom.Rectangle2D;
87
import java.io.File;
88
import java.io.IOException;
89
import java.util.ArrayList;
90
import java.util.HashMap;
91
import java.util.List;
92
import java.util.Map;
93

    
94
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
95
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
96
import com.hardcode.gdbms.driver.exceptions.UnsupportedVersionDriverException;
97
import com.hardcode.gdbms.engine.data.DataSourceFactory;
98
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
99
import com.hardcode.gdbms.engine.data.edition.DataWare;
100
import com.hardcode.gdbms.engine.values.IntValue;
101
import com.hardcode.gdbms.engine.values.Value;
102
import com.hardcode.gdbms.engine.values.ValueFactory;
103
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgArc2FMapConverter;
104
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgCircle2FMapConverter;
105
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgEllipse2FMapConverter;
106
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgLine2FMapConverter;
107
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgLwPline2FMapConverter;
108
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgMText2FMapConverter;
109
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPFacePline2FMapConverter;
110
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPoint2FMapConverter;
111
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPolyline2D2FMapConverter;
112
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPolyline3D2FMapConverter;
113
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgSolid2FMapConverter;
114
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgText2FMapConverter;
115
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.IDwg2FMap;
116
import com.iver.cit.gvsig.fmap.core.FShape;
117
import com.iver.cit.gvsig.fmap.core.IGeometry;
118
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
119
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
120
import com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver;
121
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
122
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
123
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
124
import com.iver.cit.gvsig.fmap.rendering.Legend;
125
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
126
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
127
import com.iver.cit.gvsig.fmap.rendering.styling.AttrInTableLabeling;
128
import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingStrategy;
129
import com.iver.cit.jdwglib.dwg.DwgFile;
130
import com.iver.cit.jdwglib.dwg.DwgObject;
131
import com.iver.cit.jdwglib.dwg.DwgVersionNotSupportedException;
132
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
133
import com.iver.cit.jdwglib.dwg.objects.DwgArc;
134
import com.iver.cit.jdwglib.dwg.objects.DwgCircle;
135
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse;
136
import com.iver.cit.jdwglib.dwg.objects.DwgLine;
137
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline;
138
import com.iver.cit.jdwglib.dwg.objects.DwgMText;
139
import com.iver.cit.jdwglib.dwg.objects.DwgPFacePolyline;
140
import com.iver.cit.jdwglib.dwg.objects.DwgPoint;
141
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D;
142
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D;
143
import com.iver.cit.jdwglib.dwg.objects.DwgSolid;
144
import com.iver.cit.jdwglib.dwg.objects.DwgText;
145
import com.iver.cit.jdwglib.util.AcadColor;
146

    
147
/**
148
 * Driver that allows gvSIG to read files in DWG format Using this driver, a
149
 * gvSIG user can manipulate part of the information contained in a DWG file
150
 * This driver load the Dwg file in memory This driver uses jdwglib
151
 * 
152
 * @author jmorell
153
 * @author azabala
154
 */
155
public class DwgMemoryDriver extends AbstractCadMemoryDriver implements
156
                VectorialFileDriver, WithDefaultLegend {
157
        
158
        static Map convertersRegistry = new HashMap();
159

    
160
        /*
161
         * this process of registration of the 2FMapConverters could be
162
         * automathic (by java reflection), but the number of dwg entities
163
         * is finited, and some converters could exists but dont work well
164
         * (so thats the reason we mantain a "manual" registering process.
165
         * */
166
        static{
167
                registerFMapConverter(DwgArc.class, new DwgArc2FMapConverter());
168
                registerFMapConverter(DwgCircle.class, new DwgCircle2FMapConverter());
169
                registerFMapConverter(DwgEllipse.class, new DwgEllipse2FMapConverter());
170
                registerFMapConverter(DwgLine.class, new DwgLine2FMapConverter());
171
                registerFMapConverter(DwgLwPolyline.class, new DwgLwPline2FMapConverter());
172
                registerFMapConverter(DwgMText.class, new DwgMText2FMapConverter());
173
                registerFMapConverter(DwgPFacePolyline.class, new DwgPFacePline2FMapConverter());
174
                registerFMapConverter(DwgPoint.class, new DwgPoint2FMapConverter());
175
                registerFMapConverter(DwgPolyline2D.class, new DwgPolyline2D2FMapConverter());
176
                registerFMapConverter(DwgPolyline3D.class, new DwgPolyline3D2FMapConverter());
177
                registerFMapConverter(DwgSolid.class, new DwgSolid2FMapConverter());
178
                registerFMapConverter(DwgText.class, new DwgText2FMapConverter());
179
                try {
180
                        Class.forName("com.iver.cit.gvsig.drivers.dwg.fmapconverters.FMapUtil");
181
                } catch (ClassNotFoundException e) {
182
                        e.printStackTrace();
183
                }
184
        }
185

    
186
        public static void registerFMapConverter (Class clazz, IDwg2FMap converter){
187
                if(! DwgObject.class.isAssignableFrom(clazz))
188
                        return;
189
                convertersRegistry.put(clazz, converter);
190
        }
191

    
192
        public static IDwg2FMap getConverter(Class clazz){
193
                if(! DwgObject.class.isAssignableFrom(clazz))
194
                        return null;
195
                return (IDwg2FMap) convertersRegistry.get(clazz);
196
        }
197
        
198
        VectorialUniqueValueLegend defaultLegend;
199
        private File m_Fich;
200
        private String fileVersion;
201
        private DriverAttributes attr = new DriverAttributes();
202
        private boolean isInitialized = false;
203
        float heightText = 10;        
204
        
205
        //new WithDefaultLegend API
206
        private AttrInTableLabeling labeling;
207

    
208
        private boolean debug = false;
209
        /**
210
         * entities of the dwg file (once applied many transformation,
211
         * including block insertion) that are IDwgToFMap.
212
         * */
213
        ArrayList entities = new ArrayList();
214
        
215
        /**
216
         * Saves an original DWG entity associated to a FMap entity
217
         * by their index.
218
         * Only available in debug mode (if debug is false, doesnt save anything)
219
         * */
220
        private void saveEntity(DwgObject entity) {
221
                if(debug)
222
                        entities.add(entity);
223
        }
224
        
225
        public DwgObject getEntity(int i){
226
                if(debug)
227
                        return (DwgObject) entities.get(i);
228
                else
229
                        return null;
230
        }
231

    
232
        /*
233
         * (non-Javadoc)
234
         * 
235
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
236
         */
237
        public void open(File f) {
238
                m_Fich = f;
239
        }
240

    
241
        /**
242
         * Allows recovering of the DWG Drawing entity associated to the FMap
243
         * feature whose position is index.
244
         * If debug mode is false, it always returns null.
245
         * 
246
         * @param index
247
         *            position of the fmap feature whose dwg entity is required
248
         * 
249
         */
250
        public Object getCadSource(int index) {
251
                if(debug)
252
                        return getEntity(index);
253
                else
254
                        return null;
255
        }
256

    
257
        /**
258
         * This method load the DWG file in memory. First, it will be necessary to
259
         * create a DwgFile object with the DWG file path as the argument. Second,
260
         * the method read of DwgFile allows to read the objects inside the DWG
261
         * file. Third, it will be necessary to process some DWG objects like Layers
262
         * or Polylines Fourth, applyExtrusions() can change the location of the DWG
263
         * objects through the extrusion parameters. Fifth, the testDwg3D method
264
         * test if this DWG has elevation informacion. Sixth, we can extract the
265
         * objects contained inside the blocks through the blockManagement method.
266
         * And finally, we can read the objects Vector, and convert this objects to
267
         * the FMap object model.
268
         */
269
        public void initialize() throws InitializeDriverException {
270
                if (isInitialized)
271
                        return;
272
                else
273
                        isInitialized = true;
274
                attr.setLoadedInMemory(true);
275
                DwgFile dwg = new DwgFile(m_Fich.getAbsolutePath());
276

    
277
                try {
278
                        dwg.read();
279
                } catch (DwgVersionNotSupportedException e1) {
280

    
281
                        String autodeskUrl = "<a href=\"http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151\">"
282
                                        + "http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151</a>";
283
//                        throw new InitializeDriverException(
284
//                                        formatString(
285
//                                                        "La version (%s) del fichero DWG '%s' no esta soportada por gvSIG.\n%s\n%s\n%s",
286
//                                                        new String[] { e1.getDwgVersion().toString(),
287
//                                                                        m_Fich.getName(),
288
//                                                                        Messages.getText("Probe_to_convert"),
289
//                                                                        Messages.getText("Autodesk_converter"),
290
//                                                                        autodeskUrl }));
291
                        String description=formatString(
292
                                        "La version (%s) del fichero DWG '%s' no esta soportada por gvSIG.\n%s\n%s\n%s",
293
                                        new String[] { e1.getDwgVersion().toString(),
294
                                                        m_Fich.getName(),
295
                                                        Messages.getText("Probe_to_convert"),
296
                                                        Messages.getText("Autodesk_converter"),
297
                                                        autodeskUrl });
298
                        throw new UnsupportedVersionDriverException(getName(),e1,description);
299
                } catch (IOException e) {
300
                        throw new InitializeDriverException(getName(),e);
301
                }
302

    
303
                fileVersion = dwg.getDwgVersion();
304
                dwg.calculateGisModelDwgPolylines();
305
                dwg.blockManagement2();
306
                List dwgObjects = dwg.getDwgObjects();
307
                
308
                //Each dwg file has two headers vars, EXTMIN and EXTMAX
309
                //that marks bounds of the file.
310
                //Also, it could have spureus entities (deleted objects
311
                //dont removed from the DWG database)
312
                double[] extMin = (double[]) dwg.getHeader("MSPACE_EXTMIN");
313
                double[] extMax = (double[]) dwg.getHeader("MSPACE_EXTMAX");
314
                if(extMin != null && extMax != null){
315
                        if(extMin.length >= 2 && extMax.length >= 2){
316
                                double xmin = extMin[0];
317
                                double ymin = extMin[1];
318
                                double xmax = extMax[0];
319
                                double ymax = extMax[1];
320
                                Rectangle2D roi = new 
321
                                        Rectangle2D.Double(xmin-100, ymin-100, 
322
                                                        (xmax-xmin)+100, (ymax-ymin)+100);
323
                                addRegionOfInterest(roi);
324
                        }
325
                }
326
                // Campos de las MemoryLayer:
327
                Value[] auxRow = new Value[10];
328
                ArrayList arrayFields = new ArrayList();
329
                arrayFields.add("ID");
330
                arrayFields.add("FShape");
331
                arrayFields.add("Entity");
332
                arrayFields.add("Layer");
333
                arrayFields.add("Color");
334
                arrayFields.add("Elevation");
335
                arrayFields.add("Thickness");
336
                arrayFields.add("Text");
337
                arrayFields.add("HeightText");
338
                arrayFields.add("RotationText");
339
                getTableModel().setColumnIdentifiers(arrayFields.toArray());
340
                
341
                labeling = new AttrInTableLabeling();
342
                ((AttrInTableLabeling) labeling).setTextFieldId(arrayFields.indexOf("Text"));
343
                ((AttrInTableLabeling) labeling).setRotationFieldId(arrayFields.indexOf("RotationText"));
344
                ((AttrInTableLabeling) labeling).setHeightFieldId(arrayFields.indexOf("HeightText"));
345

    
346
                boolean is3dFile = dwg.isDwg3DFile();
347
                try {
348
                        for (int i = 0; i < dwgObjects.size(); i++) {
349
                                DwgObject entity = (DwgObject) dwgObjects.get(i);
350
                                Class clazz = entity.getClass();
351
                                IDwg2FMap converter = getConverter(clazz);
352
                                try {
353
                                        if(converter != null){
354
                                                IGeometry geometry = converter.toFMapGeometry(entity, is3dFile);
355
                                                if (geometry == null)
356
                                                        continue;
357
                                                //we check for Region of Interest of the CAD file
358
                                                if(! checkRois(geometry))
359
                                                        continue;
360
                                                
361
                                                String fmapStr = converter.toFMapString(is3dFile);
362
                                                // nombre del tipo de geometria fmap
363
                                                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(fmapStr);
364
                                                
365
                                                // indice del registro
366
                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
367
                                                
368
                                                // nombre de entidad dwg
369
                                                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(entity.toString());
370
                                                String layerName = dwg.getLayerName(entity);
371
                                                auxRow[ID_FIELD_LAYER] = ValueFactory
372
                                                                .createValue(layerName);
373
                                                int colorByLayer = dwg.getColorByLayer(entity);
374
                                                
375
                                                int color = entity.getColor();
376
                                                if(color < 0)
377
                                                        color = Math.abs(color);
378
                                                if(color > 255)
379
                                                        color = colorByLayer;                                        
380
                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
381

    
382
                                                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
383
                                                auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory
384
                                                                .createValue(0.0);
385
                                                auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
386
                                                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
387

    
388
                                                if (entity instanceof IDwg3DTestable) {
389
                                                        auxRow[ID_FIELD_ELEVATION] = ValueFactory
390
                                                                        .createValue(((IDwg3DTestable) entity).getZ());
391
                                                }
392

    
393
                                                if (entity instanceof DwgMText) {
394
                                                        DwgMText mtext = (DwgMText) entity;
395
                                                        auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(mtext
396
                                                                        .getText());
397
                                                        auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
398
                                                                        .createValue(mtext.getHeight());
399
                                                } else if (entity instanceof DwgText) {
400
                                                        DwgText text = (DwgText) entity;
401
                                                        auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(text
402
                                                                        .getText());
403
                                                        auxRow[ID_FIELD_THICKNESS] = ValueFactory
404
                                                                        .createValue(text.getThickness());
405
                                                        auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
406
                                                                        .createValue(text.getHeight());
407
                                                        auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory
408
                                                                        .createValue(Math.toDegrees(text
409
                                                                                        .getRotationAngle()));
410
                                                }// if-else
411
                                                addGeometry(geometry, auxRow);
412
                                                
413
                                                if(debug)
414
                                                        saveEntity(entity);
415

    
416
                                        }
417
                                } catch (Exception e) {
418
                                        // TODO Auto-generated catch block
419
                                        e.printStackTrace();
420
                                        continue;
421
                                }
422
                        }// for
423

    
424
                } catch (Throwable t) {
425
                        t.printStackTrace();
426
                }
427
                dwgObjects = null;
428
                dwg = null;
429
                if(! debug)
430
                        dwg = null;
431
                System.gc();
432
                setSymbols();
433
        }
434
        
435
        /**
436
         * Sets a symbol for each dwg entity's derived feature based in
437
         * the DWG symbology info.
438
         * */
439
        private void setSymbols() throws InitializeDriverException{
440
                FSymbol myDefaultSymbol = new FSymbol(getShapeType());
441
                myDefaultSymbol.setShapeVisible(false);
442
                myDefaultSymbol.setFontSizeInPixels(false);
443
                myDefaultSymbol.setFont(new Font("SansSerif", Font.PLAIN, 9));
444
                myDefaultSymbol.setFontColor(Color.BLACK);
445
                myDefaultSymbol.setFontSize(heightText);
446
                myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
447
                myDefaultSymbol.setSize(3);
448
                myDefaultSymbol.setSizeInPixels(true);
449

    
450
                defaultLegend = LegendFactory
451
                                .createVectorialUniqueValueLegend(getShapeType());
452
                defaultLegend.setFieldName("Color");
453
                defaultLegend.setLabelField("Text");
454
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
455
                defaultLegend.setLabelHeightField("HeightText");
456
                defaultLegend.setLabelRotationField("RotationText");
457

    
458
                ObjectDriver rs = this;
459
                IntValue clave;
460
                FSymbol theSymbol = null;
461
                try {
462
                        for (long j = 0; j < rs.getRowCount(); j++) {
463
                                clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR);
464
                                if (defaultLegend.getSymbolByValue(clave) == null) {
465
                                        theSymbol = new FSymbol(getShapeType());
466
                                        theSymbol.setDescription(clave.toString());
467
                                        theSymbol.setColor(AcadColor.getColor(clave.getValue()));
468
                                        // theSymbol.setFill(fillProv);
469
                                        // 050202, jmorell: Asigna los colores de Autocad a los
470
                                        // bordes
471
                                        // de los pol?gonos.
472
                                        theSymbol.setOutlineColor(AcadColor.getColor(clave
473
                                                        .getValue()));
474

    
475
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
476
                                        theSymbol.setSize(3);
477
                                        theSymbol.setSizeInPixels(true);
478
                                        defaultLegend.addSymbol(clave, theSymbol);
479
                                }// if
480
                        } // for
481
                } catch (ReadDriverException e) {
482
                        throw new InitializeDriverException(getName(),e);
483
                }
484
        }
485
        
486
        /**
487
         * checks if the given geometry intersects or its
488
         * contained in one of the driver regions of interest.
489
         * 
490
         * @param geometry feature geometry we want to check
491
         * against the drivers rois.
492
         * 
493
         *  @return true if feature is contained in any ROI.
494
         *  false if not.
495
         * */
496
        private boolean checkRois(IGeometry geometry){
497
                Rectangle2D rect = geometry.getBounds2D();
498
                int numRois = this.getNumOfRois();
499
                for(int i = 0; i < numRois; i++){
500
                        Rectangle2D roi = getRegionOfInterest(i);
501
                        if( checkIntersect(rect.getMinX(), rect.getMaxX(), rect.getMinY(), rect.getMaxY(),
502
                                        roi.getMinX(), roi.getMaxX(), roi.getMinY(),roi.getMaxY()) ||
503
                                checkContains(rect.getMinX(), rect.getMaxX(), rect.getMinY(), rect.getMaxY(),
504
                                                roi.getMinX(), roi.getMaxX(), roi.getMinY(),roi.getMaxY())
505
                        ){
506
                                return true;
507
                        }
508
//                        if(roi.intersects(rect) || roi.contains(rect))
509
//                                return true;
510
                }
511
                return false;
512
        }
513
        
514
        private boolean checkContains(double x1, double x2, double y1, double y2, 
515
                        double ax1, double ax2, double ay1, double ay2){
516
                 boolean solution = ( x1 >= ax1 &&
517
                x2 <= ax2 &&
518
                y1 >= ay1 &&
519
                y2 <= ay2);
520
                 return solution;
521
        }
522
        
523
        private boolean checkIntersect(double x1, double x2, double y1, double y2, 
524
                                                                double ax1, double ax2, double ay1, double ay2){
525
                
526
                 return !(x1 > ax2 ||
527
                        x2 < ax1 ||
528
                        y1 > ay2 ||
529
                        y2 < ay1);
530
                 
531
        }
532

    
533
        public String getFileVersion() {
534
                return fileVersion;
535
        }
536

    
537
        private String formatString(String fmt, String[] params) {
538
                String ret = fmt;
539
                for (int i = 0; i < params.length; i++) {
540
                        ret = ret.replaceFirst("%s", params[i]);
541
                }
542
                return ret;
543
        }
544

    
545
        
546
        /*
547
         * (non-Javadoc)
548
         * 
549
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
550
         */
551
        public boolean accept(File f) {
552
                return f.getName().toUpperCase().endsWith("DWG");
553
        }
554

    
555
        /*
556
         * (non-Javadoc)
557
         * 
558
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
559
         */
560
        public int getShapeType() {
561
                return FShape.MULTI;
562
        }
563

    
564
        /*
565
         * (non-Javadoc)
566
         * 
567
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
568
         */
569
        public String getName() {
570
                return "gvSIG DWG Memory Driver";
571
        }
572

    
573
        /*
574
         * (non-Javadoc)
575
         * 
576
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
577
         */
578
        public Legend getDefaultLegend() {
579
                return defaultLegend;
580
        }
581

    
582
        /*
583
         * (non-Javadoc)
584
         * 
585
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
586
         */
587
        public DriverAttributes getDriverAttributes() {
588
                return attr;
589
        }
590

    
591
        /*
592
         * (non-Javadoc)
593
         * 
594
         * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
595
         */
596
        public int[] getPrimaryKeys() {
597
                // TODO Auto-generated method stub
598
                return null;
599
        }
600

    
601
        /*
602
         * (non-Javadoc)
603
         * 
604
         * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
605
         */
606
        public void write(DataWare arg0)  {
607
                // TODO Auto-generated method stub
608

    
609
        }
610

    
611
        public void setDataSourceFactory(DataSourceFactory arg0) {
612
                // TODO Auto-generated method stub
613

    
614
        }
615

    
616
        public void close()  {
617
                // TODO Auto-generated method stub
618

    
619
        }
620

    
621
        public File getFile() {
622
                return m_Fich;
623
        }
624

    
625
        public boolean isWritable() {
626
                return m_Fich.canWrite();
627
        }
628

    
629

    
630
        public boolean isDebug() {
631
                return debug;
632
        }
633

    
634

    
635
        public void setDebug(boolean debug) {
636
                this.debug = debug;
637
        }
638
        
639
        public ILabelingStrategy getDefaultLabelingStrategy() {
640
                return labeling;
641
        }
642
}
643

    
644

    
645

    
646

    
647

    
648