root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / DwgFile.java @ 10240
History | View | Annotate | Download (36.2 KB)
1 | 2896 | jmorell | /* jdwglib. Java Library for reading Dwg files.
|
---|---|---|---|
2 | *
|
||
3 | * Author: Jose Morell Rama (jose.morell@gmail.com).
|
||
4 | * Port from the Pythoncad Dwg library by Art Haas.
|
||
5 | *
|
||
6 | * Copyright (C) 2005 Jose Morell, IVER TI S.A. 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 | * Jose Morell (jose.morell@gmail.com)
|
||
25 | *
|
||
26 | * or
|
||
27 | *
|
||
28 | * IVER TI S.A.
|
||
29 | * C/Salamanca, 50
|
||
30 | * 46005 Valencia
|
||
31 | * Spain
|
||
32 | * +34 963163400
|
||
33 | * dac@iver.es
|
||
34 | */
|
||
35 | package com.iver.cit.jdwglib.dwg; |
||
36 | |||
37 | import java.awt.geom.Point2D; |
||
38 | import java.io.File; |
||
39 | import java.io.FileInputStream; |
||
40 | import java.io.IOException; |
||
41 | import java.nio.ByteBuffer; |
||
42 | import java.nio.channels.FileChannel; |
||
43 | 9830 | azabala | import java.util.ArrayList; |
44 | 7116 | azabala | import java.util.HashMap; |
45 | 9992 | fdiaz | import java.util.Iterator; |
46 | 9843 | azabala | import java.util.LinkedList; |
47 | 9825 | azabala | import java.util.List; |
48 | 9843 | azabala | import java.util.Map; |
49 | 2896 | jmorell | |
50 | import com.iver.cit.jdwglib.dwg.objects.DwgArc; |
||
51 | import com.iver.cit.jdwglib.dwg.objects.DwgAttdef; |
||
52 | import com.iver.cit.jdwglib.dwg.objects.DwgAttrib; |
||
53 | import com.iver.cit.jdwglib.dwg.objects.DwgBlock; |
||
54 | import com.iver.cit.jdwglib.dwg.objects.DwgBlockHeader; |
||
55 | import com.iver.cit.jdwglib.dwg.objects.DwgCircle; |
||
56 | import com.iver.cit.jdwglib.dwg.objects.DwgEllipse; |
||
57 | import com.iver.cit.jdwglib.dwg.objects.DwgEndblk; |
||
58 | import com.iver.cit.jdwglib.dwg.objects.DwgInsert; |
||
59 | import com.iver.cit.jdwglib.dwg.objects.DwgLayer; |
||
60 | import com.iver.cit.jdwglib.dwg.objects.DwgLine; |
||
61 | import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline; |
||
62 | import com.iver.cit.jdwglib.dwg.objects.DwgMText; |
||
63 | import com.iver.cit.jdwglib.dwg.objects.DwgPoint; |
||
64 | import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D; |
||
65 | import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D; |
||
66 | import com.iver.cit.jdwglib.dwg.objects.DwgSeqend; |
||
67 | import com.iver.cit.jdwglib.dwg.objects.DwgSolid; |
||
68 | import com.iver.cit.jdwglib.dwg.objects.DwgText; |
||
69 | import com.iver.cit.jdwglib.dwg.objects.DwgVertex2D; |
||
70 | 10148 | azabala | import com.iver.cit.jdwglib.dwg.readers.DwgFileV14Reader; |
71 | 9910 | azabala | import com.iver.cit.jdwglib.dwg.readers.IDwgFileReader; |
72 | 9602 | azabala | import com.iver.cit.jdwglib.dwg.readers.DwgFileV15Reader; |
73 | 2896 | jmorell | |
74 | /**
|
||
75 | * The DwgFile class provides a revision-neutral interface for reading and handling
|
||
76 | * DWG files
|
||
77 | * Reading methods are useful for reading DWG files, and handling methods like
|
||
78 | * calculateDwgPolylines() are useful for handling more complex
|
||
79 | * objects in the DWG file
|
||
80 | *
|
||
81 | * @author jmorell
|
||
82 | 9602 | azabala | * @author azabala
|
83 | 2896 | jmorell | */
|
84 | public class DwgFile { |
||
85 | 7116 | azabala | /**
|
86 | * It has all known DWG version's header.
|
||
87 | * Extracted from Autodesk web.
|
||
88 | */
|
||
89 | private static HashMap acadVersions = new HashMap(); |
||
90 | static{
|
||
91 | acadVersions.put("AC1004", "Autocad R9"); |
||
92 | acadVersions.put("AC1006", "Autocad R10"); |
||
93 | acadVersions.put("AC1007", "Autocad pre-R11"); |
||
94 | acadVersions.put("AC1007", "Autocad pre-R11"); |
||
95 | acadVersions.put("AC1008", "Autocad pre-R11b"); |
||
96 | acadVersions.put("AC1009", "Autocad R12"); |
||
97 | acadVersions.put("AC1010", "Autocad pre-R13 a"); |
||
98 | acadVersions.put("AC1011", "Autocad pre-R13 b"); |
||
99 | acadVersions.put("AC1012", "Autocad R13"); |
||
100 | acadVersions.put("AC1013", "Autocad pre-R14"); |
||
101 | acadVersions.put("AC1014", "Autocad R14"); |
||
102 | acadVersions.put("AC1500", "Autocad pre-2000"); |
||
103 | acadVersions.put("AC1015", "Autocad R2000, R2000i, R2002"); |
||
104 | acadVersions.put("AC402a", "Autocad pre-2004a"); |
||
105 | acadVersions.put("AC402b", "Autocad pre-2004b"); |
||
106 | acadVersions.put("AC1018", "Autocad R2004, R2005, R2006"); |
||
107 | acadVersions.put("AC1021", "Autocad R2007"); |
||
108 | |||
109 | } |
||
110 | |||
111 | 2896 | jmorell | private String fileName; |
112 | private String dwgVersion; |
||
113 | 9602 | azabala | |
114 | 9825 | azabala | /**
|
115 | * Offsets to the DWG sections
|
||
116 | */
|
||
117 | 7178 | azabala | private ArrayList dwgSectionOffsets; |
118 | 9872 | azabala | /**
|
119 | * Header vars readed from the HEADER section of the DWG file
|
||
120 | * */
|
||
121 | private Map headerVars; |
||
122 | 9602 | azabala | |
123 | /**
|
||
124 | * This list contains what in OpenDWG specification is called
|
||
125 | * the object map ( a collection of entries where each entry contains
|
||
126 | * the seek of each object, and its size)
|
||
127 | * */
|
||
128 | 7178 | azabala | private ArrayList dwgObjectOffsets; |
129 | 9602 | azabala | |
130 | /**
|
||
131 | * For each entry in dwgObjectOffsets, we have an instance of
|
||
132 | * DwgObject in the dwgObjects collection
|
||
133 | *
|
||
134 | * */
|
||
135 | 9843 | azabala | private LinkedList dwgObjects; |
136 | 9840 | azabala | private HashMap handle_objects; |
137 | 9602 | azabala | |
138 | 9889 | azabala | |
139 | 7178 | azabala | private ArrayList dwgClasses; |
140 | 9602 | azabala | |
141 | |||
142 | /**
|
||
143 | * hash map that indexes all DwgLayer objects
|
||
144 | * by its handle property
|
||
145 | * */
|
||
146 | private HashMap layerTable; |
||
147 | |||
148 | 9825 | azabala | /**
|
149 | * Specific reader of the DWG file version (12, 13, 14, 2000, etc., each
|
||
150 | * version will have an specific reader)
|
||
151 | * */
|
||
152 | 9910 | azabala | private IDwgFileReader dwgReader;
|
153 | 2896 | jmorell | private boolean dwg3DFile; |
154 | /**
|
||
155 | 9602 | azabala | * Memory mapped byte buffer of the whole DWG file
|
156 | * */
|
||
157 | private ByteBuffer bb; |
||
158 | |||
159 | 9825 | azabala | /*
|
160 | * Optimizaciones para evitar leer el fichero completo en cada
|
||
161 | * pasada.
|
||
162 | * */
|
||
163 | 9602 | azabala | /**
|
164 | 9825 | azabala | * Contains all IDwgPolyline implementations
|
165 | * */
|
||
166 | private List dwgPolylines; |
||
167 | |||
168 | /**
|
||
169 | 9843 | azabala | * Constructor.
|
170 | 2896 | jmorell | * @param fileName an absolute path to the DWG file
|
171 | */
|
||
172 | public DwgFile(String fileName) { |
||
173 | this.fileName = fileName;
|
||
174 | 9602 | azabala | |
175 | 7178 | azabala | dwgSectionOffsets = new ArrayList(); |
176 | dwgObjectOffsets = new ArrayList(); |
||
177 | 9872 | azabala | headerVars = new HashMap(); |
178 | 9719 | azabala | |
179 | 9602 | azabala | //TODO Si finalmente no se leen las clases, quitar
|
180 | //dwgClasses
|
||
181 | dwgClasses = new ArrayList(); |
||
182 | 9719 | azabala | |
183 | 9843 | azabala | dwgObjects = new LinkedList(); |
184 | 9840 | azabala | handle_objects = new HashMap(); |
185 | 9602 | azabala | |
186 | layerTable = new HashMap(); |
||
187 | 9830 | azabala | |
188 | dwgPolylines = new ArrayList(); |
||
189 | 2896 | jmorell | } |
190 | |||
191 | 9305 | jjdelcerro | public String getDwgVersion() { |
192 | return dwgVersion;
|
||
193 | } |
||
194 | |||
195 | 2896 | jmorell | /**
|
196 | * Reads a DWG file and put its objects in the dwgObjects Vector
|
||
197 | * This method is version independent
|
||
198 | *
|
||
199 | * @throws IOException If the file location is wrong
|
||
200 | */
|
||
201 | 7116 | azabala | public void read() throws IOException, |
202 | DwgVersionNotSupportedException |
||
203 | { |
||
204 | 2896 | jmorell | setDwgVersion(); |
205 | 10179 | fdiaz | //System.out.println("VERSION = "+dwgVersion);
|
206 | 7116 | azabala | if (dwgVersion.equalsIgnoreCase("Autocad R2000, R2000i, R2002")) { |
207 | 2896 | jmorell | dwgReader = new DwgFileV15Reader();
|
208 | 10221 | azabala | }else if (dwgVersion.equalsIgnoreCase("Autocad pre-R14")|| |
209 | dwgVersion.equalsIgnoreCase("Autocad R14") ||
|
||
210 | dwgVersion.equalsIgnoreCase("Autocad R13")) {
|
||
211 | 10148 | azabala | dwgReader = new DwgFileV14Reader();
|
212 | 10179 | fdiaz | } else {
|
213 | 7116 | azabala | DwgVersionNotSupportedException exception = |
214 | new DwgVersionNotSupportedException("Version de DWG no soportada"); |
||
215 | exception.setDwgVersion(dwgVersion); |
||
216 | throw exception;
|
||
217 | 2896 | jmorell | } |
218 | 10148 | azabala | dwgReader.read(this, bb);
|
219 | 2896 | jmorell | } |
220 | 9602 | azabala | |
221 | private void setDwgVersion() throws IOException { |
||
222 | File file = new File(fileName); |
||
223 | FileInputStream fileInputStream = new FileInputStream(file); |
||
224 | FileChannel fileChannel = fileInputStream.getChannel();
|
||
225 | long channelSize = fileChannel.size();
|
||
226 | bb = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, channelSize); |
||
227 | byte[] versionBytes = {bb.get(0), |
||
228 | bb.get(1),
|
||
229 | bb.get(2),
|
||
230 | bb.get(3),
|
||
231 | bb.get(4),
|
||
232 | bb.get(5)};
|
||
233 | ByteBuffer versionByteBuffer = ByteBuffer.wrap(versionBytes); |
||
234 | String[] bs = new String[versionByteBuffer.capacity()]; |
||
235 | String versionString = ""; |
||
236 | for (int i=0; i<versionByteBuffer.capacity(); i++) { |
||
237 | bs[i] = new String(new byte[]{(byte)(versionByteBuffer.get(i))}); |
||
238 | versionString = versionString + bs[i]; |
||
239 | } |
||
240 | String version = (String) acadVersions.get(versionString); |
||
241 | if(version == null) |
||
242 | version = "Unknown Dwg format";
|
||
243 | this.dwgVersion = version;
|
||
244 | } |
||
245 | |||
246 | 9872 | azabala | public void setHeader(String key, Object value){ |
247 | headerVars.put(key, value); |
||
248 | } |
||
249 | 9602 | azabala | |
250 | |||
251 | 9872 | azabala | |
252 | 9602 | azabala | /**
|
253 | * Initialize a new Vector that contains the DWG file layers.
|
||
254 | * Each layer have three parameters.
|
||
255 | * These parameters are handle, name and color
|
||
256 | */
|
||
257 | // public void initializeLayerTable() {
|
||
258 | // layerTable = new ArrayList();
|
||
259 | // for (int i=0;i<dwgObjects.size();i++) {
|
||
260 | // DwgObject obj = (DwgObject)dwgObjects.get(i);
|
||
261 | // if (obj instanceof DwgLayer) {
|
||
262 | // ArrayList layerTableRecord = new ArrayList();
|
||
263 | // layerTableRecord.add(new Integer(obj.getHandle()));
|
||
264 | // layerTableRecord.add(((DwgLayer)obj).getName());
|
||
265 | // layerTableRecord.add(new Integer(((DwgLayer)obj).getColor()));
|
||
266 | // layerTable.add(layerTableRecord);
|
||
267 | // }
|
||
268 | // }
|
||
269 | // }
|
||
270 | |||
271 | 9719 | azabala | /*
|
272 | * A DwgLayer is a DWG drawing entity, so all DwgLayer objects are
|
||
273 | * saved in dwgObjects collection.
|
||
274 | * Instead of iterate over the full collection, is faster check every object
|
||
275 | * and save all the DwgLayer instances in their own collection.
|
||
276 | *
|
||
277 | */
|
||
278 | 9602 | azabala | public void addDwgLayer(DwgLayer dwgLayer){ |
279 | 10014 | fdiaz | layerTable.put(new Integer(dwgLayer.getHandle().getOffset()), |
280 | 9602 | azabala | dwgLayer); |
281 | } |
||
282 | |||
283 | 10179 | fdiaz | private void printInfoOfAObject (DwgObject entity){ |
284 | // TODO: Eliminar este metodo cuando terminemos de depurar
|
||
285 | System.out.println("index = "+entity.getIndex() + " entity.type = " + entity.type + " entityClassName = "+ entity.getClass().getName()); |
||
286 | |||
287 | System.out.println ("handleCode = "+entity.getHandle().getCode()); |
||
288 | System.out.println ("entityLayerHandle = "+entity.getHandle().getOffset()); |
||
289 | if(entity.hasLayerHandle()){
|
||
290 | System.out.println ("layerHandleCode = "+entity.getLayerHandle().getCode()); |
||
291 | System.out.println ("layerHandle = "+entity.getLayerHandle().getOffset()); |
||
292 | } |
||
293 | if(entity.hasSubEntityHandle()){
|
||
294 | System.out.println ("subEntityHandleCode = "+entity.getSubEntityHandle().getCode()); |
||
295 | System.out.println ("subEntityHandle = "+entity.getSubEntityHandle().getOffset()); |
||
296 | } |
||
297 | if(entity.hasNextHandle()){
|
||
298 | System.out.println ("nextHandleCode = "+entity.getNextHandle().getCode()); |
||
299 | System.out.println ("nextHandle = "+entity.getNextHandle().getOffset()); |
||
300 | } |
||
301 | if(entity.hasPreviousHandle()){
|
||
302 | System.out.println ("previousHandleCode = "+entity.getPreviousHandle().getCode()); |
||
303 | System.out.println ("previousHandle = "+entity.getPreviousHandle().getOffset()); |
||
304 | } |
||
305 | if(entity.hasXDicObjHandle()){
|
||
306 | System.out.println ("xDicObjHandleCode = "+entity.getXDicObjHandle()); |
||
307 | System.out.println ("xDicObjHandle = "+entity.getXDicObjHandle()); |
||
308 | } |
||
309 | if(entity.hasReactorsHandles()){
|
||
310 | ArrayList reactorsHandles = entity.getReactorsHandles();
|
||
311 | int size = reactorsHandles.size();
|
||
312 | System.out.print ("NUMERO DE reactors = "+size); |
||
313 | DwgHandleReference hr; |
||
314 | for(int i=0; i<size; i++){ |
||
315 | hr=(DwgHandleReference)reactorsHandles.get(i); |
||
316 | System.out.print ("reactorHandleCode = "+hr.getCode()); |
||
317 | System.out.println (" reactorHandle = "+hr.getOffset()); |
||
318 | } |
||
319 | } |
||
320 | |||
321 | } |
||
322 | 9602 | azabala | public DwgLayer getDwgLayer(DwgObject entity){
|
323 | 10054 | azabala | DwgHandleReference handle = entity.getLayerHandle(); |
324 | if(handle == null){ |
||
325 | 10221 | azabala | // System.out.print("Entidad con layer handle a null (debe ser una LwPolyline) ==> ");
|
326 | // System.out.println(entity.getClass().getName());
|
||
327 | 10054 | azabala | //TODO Ver que hacemos con estas entidades (lanzan excepcion antes de hacer readTailer)
|
328 | return null; |
||
329 | } |
||
330 | 10179 | fdiaz | int handleCode = handle.getCode();
|
331 | int entityLayerHandle = entity.getLayerHandle().getOffset();
|
||
332 | 9719 | azabala | int layerHandle = -1; |
333 | |||
334 | int entityRecord;
|
||
335 | DwgObject object; |
||
336 | |||
337 | |||
338 | /*
|
||
339 | * OpenDWG spec, v3, page 11. HANDLE REFERENCES
|
||
340 | *
|
||
341 | * A handle is formed by this fields:
|
||
342 | * a) CODE (4 bits)
|
||
343 | * b) COUNTER (4 bits)
|
||
344 | * c) OFFSET of the object (handle itself).
|
||
345 | *
|
||
346 | * CODE could take these values:
|
||
347 | * 1) 0x2, 0x3, 0x4, 0x5 -> offset is the handle of the layer
|
||
348 | * 2) 0x6 -> offset is the next object handle
|
||
349 | * 3) 0x8 -> offset is the previous object handle
|
||
350 | * 4) 0xA -> result is reference handle plus offset
|
||
351 | * 5) 0xC -> result is reference handle minus offset
|
||
352 | *
|
||
353 | * */
|
||
354 | |||
355 | 10179 | fdiaz | // FIXME: Esto no esta terminado. Falta considerar los codigo
|
356 | // 0x2, 0x3, 0x6, 0xA que no han aparecido en los archivos de prueba.
|
||
357 | 9992 | fdiaz | switch(handleCode){
|
358 | 10179 | fdiaz | case 0x4: |
359 | if (entity.hasNextHandle()){
|
||
360 | int nextHandleCode = entity.getNextHandle().getCode();
|
||
361 | if (nextHandleCode == 0x5) { |
||
362 | layerHandle = entity.getNextHandle().getOffset(); |
||
363 | } else {
|
||
364 | //TODO: No se han previsto nextHandleCode != 0x5
|
||
365 | 10221 | azabala | // System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+
|
366 | // " con nextHandleCode "+ nextHandleCode +" no implementado.");
|
||
367 | 9992 | fdiaz | } |
368 | 10179 | fdiaz | } else {
|
369 | layerHandle = entity.getLayerHandle().getOffset(); |
||
370 | 9992 | fdiaz | } |
371 | break;
|
||
372 | 10179 | fdiaz | case 0x5: |
373 | layerHandle = entity.getLayerHandle().getOffset(); |
||
374 | break;
|
||
375 | 9992 | fdiaz | case 0x8: |
376 | if (entity.hasNextHandle()){
|
||
377 | 10014 | fdiaz | int nextHandleCode = entity.getNextHandle().getCode();
|
378 | 9992 | fdiaz | if (nextHandleCode == 0x5) { |
379 | 10014 | fdiaz | layerHandle = entity.getNextHandle().getOffset(); |
380 | 9992 | fdiaz | } else {
|
381 | //TODO No se han previsto nextHandleCode != 0x5
|
||
382 | 10221 | azabala | // System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+
|
383 | // " con nextHandleCode "+ nextHandleCode +" no implementado.");
|
||
384 | 9992 | fdiaz | } |
385 | 10179 | fdiaz | } else {
|
386 | layerHandle = entity.getHandle().getOffset() - 1;
|
||
387 | 9992 | fdiaz | } |
388 | break;
|
||
389 | case 0xC: |
||
390 | if (entity.hasNextHandle()){
|
||
391 | 10014 | fdiaz | int nextHandleCode = entity.getNextHandle().getCode();
|
392 | 9992 | fdiaz | if (nextHandleCode == 0x5) { |
393 | 10014 | fdiaz | layerHandle = entity.getNextHandle().getOffset(); |
394 | 9992 | fdiaz | } else {
|
395 | 10179 | fdiaz | //TODO: No se han previsto nextHandleCode != 0x5
|
396 | 10221 | azabala | // System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+
|
397 | // " con nextHandleCode "+ nextHandleCode +" no implementado.");
|
||
398 | 9992 | fdiaz | } |
399 | } else {
|
||
400 | 10014 | fdiaz | layerHandle = entity.getHandle().getOffset() - entity.getLayerHandle().getOffset() + 1;
|
401 | 9992 | fdiaz | } |
402 | break;
|
||
403 | default:
|
||
404 | 10221 | azabala | // System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+" no implementado. entityLayerHandle="+entityLayerHandle);
|
405 | 9992 | fdiaz | } |
406 | 9719 | azabala | |
407 | 9992 | fdiaz | if(layerHandle != -1){ |
408 | Iterator lyrIterator = layerTable.values().iterator();
|
||
409 | while(lyrIterator.hasNext()){
|
||
410 | DwgLayer lyr = (DwgLayer) lyrIterator.next(); |
||
411 | 10014 | fdiaz | int lyrHdl = lyr.getHandle().getOffset();
|
412 | 9992 | fdiaz | if (lyrHdl == layerHandle){
|
413 | return lyr;
|
||
414 | } |
||
415 | } |
||
416 | } |
||
417 | 10221 | azabala | // System.out.println("NO SE HA ENCONTRADO UNA CAPA CON HANDLE " + layerHandle);
|
418 | // printInfoOfAObject(entity);
|
||
419 | 9992 | fdiaz | return null; |
420 | 9602 | azabala | } |
421 | |||
422 | 9830 | azabala | |
423 | 9719 | azabala | public String getLayerName(DwgObject entity) { |
424 | 9602 | azabala | DwgLayer dwgLayer = getDwgLayer(entity); |
425 | 9719 | azabala | if(dwgLayer == null){//TODO Puede haber entidades sin layer??? |
426 | 9602 | azabala | return ""; |
427 | 10179 | fdiaz | }else{
|
428 | 9602 | azabala | return dwgLayer.getName();
|
429 | 10179 | fdiaz | } |
430 | 9602 | azabala | } |
431 | |||
432 | /**
|
||
433 | * Returns the color of the layer of a DWG object
|
||
434 | *
|
||
435 | * @param entity DWG object which we want to know its layer color
|
||
436 | * @return int Layer color of the DWG object in the Autocad color code
|
||
437 | */
|
||
438 | public int getColorByLayer(DwgObject entity) { |
||
439 | int colorByLayer;
|
||
440 | DwgLayer dwgLyr = getDwgLayer(entity); |
||
441 | if(dwgLyr == null) |
||
442 | colorByLayer = 0;
|
||
443 | else
|
||
444 | colorByLayer = dwgLyr.getColor(); |
||
445 | return colorByLayer;
|
||
446 | } |
||
447 | |||
448 | 9872 | azabala | |
449 | 9843 | azabala | //azabala: esto ahora se hace conforme se van creando los objetos
|
450 | //(y no al final en una segunda pasada
|
||
451 | // public void applyExtrusions() {
|
||
452 | // for (int i=0;i<dwgObjects.size();i++) {
|
||
453 | // DwgObject dwgObject = (DwgObject)dwgObjects.get(i);
|
||
454 | // if(dwgObject instanceof IDwgExtrusionable){
|
||
455 | // ((IDwgExtrusionable)dwgObject).applyExtrussion();
|
||
456 | // }
|
||
457 | // // Seems that Autocad don't apply the extrusion to Ellipses
|
||
458 | // /*} else if (dwgObject instanceof DwgEllipse) {
|
||
459 | // double[] ellipseCenter = ((DwgEllipse)dwgObject).getCenter();
|
||
460 | // double[] ellipseExt = ((DwgEllipse)dwgObject).getExtrusion();
|
||
461 | // ellipseCenter = AcadExtrusionCalculator.CalculateAcadExtrusion(ellipseCenter, ellipseExt);
|
||
462 | // ((DwgEllipse)dwgObject).setCenter(ellipseCenter);*/
|
||
463 | // }//for
|
||
464 | // }
|
||
465 | 2896 | jmorell | |
466 | /**
|
||
467 | * Configure the geometry of the polylines in a DWG file from the vertex list in
|
||
468 | * this DWG file. This geometry is given by an array of Points.
|
||
469 | * Besides, manage closed polylines and polylines with bulges in a GIS Data model.
|
||
470 | * It means that the arcs of the polylines will be done through a set of points and
|
||
471 | * a distance between these points.
|
||
472 | */
|
||
473 | public void calculateGisModelDwgPolylines() { |
||
474 | 9825 | azabala | /*
|
475 | * Ahora mismo esto se est? haciendo al final (en una segunda pasada)
|
||
476 | * porque posiblemente una Linea requiera de vertices que vengan
|
||
477 | * despues, lo que complicar?a bastante todo....
|
||
478 | * */
|
||
479 | |||
480 | // for (int i=0;i<dwgObjects.size();i++) {
|
||
481 | for (int i = 0; i < dwgPolylines.size(); i++){ |
||
482 | // DwgObject pol = (DwgObject)dwgObjects.get(i);
|
||
483 | DwgObject pol = (DwgObject)dwgPolylines.get(i); |
||
484 | if (pol instanceof IDwgPolyline) { |
||
485 | 9977 | azabala | // ((IDwgPolyline)pol).calculateGisModel(dwgObjects);
|
486 | ((IDwgPolyline)pol).calculateGisModel(this);
|
||
487 | 9825 | azabala | } |
488 | 2896 | jmorell | } |
489 | } |
||
490 | |||
491 | /**
|
||
492 | * Configure the geometry of the polylines in a DWG file from the vertex list in
|
||
493 | * this DWG file. This geometry is given by an array of Points
|
||
494 | * Besides, manage closed polylines and polylines with bulges in a GIS Data model.
|
||
495 | * It means that the arcs of the polylines will be done through a curvature
|
||
496 | * parameter called bulge associated with the points of the polyline.
|
||
497 | */
|
||
498 | 9843 | azabala | //TODO Refactorizar para que solo se aplique a las Polilineas
|
499 | 2896 | jmorell | public void calculateCadModelDwgPolylines() { |
500 | for (int i=0;i<dwgObjects.size();i++) { |
||
501 | DwgObject pol = (DwgObject)dwgObjects.get(i); |
||
502 | if (pol instanceof DwgPolyline2D) { |
||
503 | int flags = ((DwgPolyline2D)pol).getFlags();
|
||
504 | 10014 | fdiaz | int firstHandle = ((DwgPolyline2D)pol).getFirstVertexHandle().getOffset();
|
505 | int lastHandle = ((DwgPolyline2D)pol).getLastVertexHandle().getOffset();
|
||
506 | 7178 | azabala | ArrayList pts = new ArrayList(); |
507 | ArrayList bulges = new ArrayList(); |
||
508 | 2896 | jmorell | double[] pt = new double[3]; |
509 | for (int j=0;j<dwgObjects.size();j++) { |
||
510 | DwgObject firstVertex = (DwgObject)dwgObjects.get(j); |
||
511 | if (firstVertex instanceof DwgVertex2D) { |
||
512 | 10014 | fdiaz | int vertexHandle = firstVertex.getHandle().getOffset();
|
513 | 2896 | jmorell | if (vertexHandle==firstHandle) {
|
514 | int k=0; |
||
515 | while (true) { |
||
516 | DwgObject vertex = (DwgObject)dwgObjects.get(j+k); |
||
517 | 10014 | fdiaz | int vHandle = vertex.getHandle().getOffset();
|
518 | 2896 | jmorell | if (vertex instanceof DwgVertex2D) { |
519 | pt = ((DwgVertex2D)vertex).getPoint(); |
||
520 | pts.add(new Point2D.Double(pt[0], pt[1])); |
||
521 | double bulge = ((DwgVertex2D)vertex).getBulge();
|
||
522 | bulges.add(new Double(bulge)); |
||
523 | k++; |
||
524 | if (vHandle==lastHandle && vertex instanceof DwgVertex2D) { |
||
525 | break;
|
||
526 | } |
||
527 | } else if (vertex instanceof DwgSeqend) { |
||
528 | break;
|
||
529 | } |
||
530 | } |
||
531 | } |
||
532 | } |
||
533 | } |
||
534 | if (pts.size()>0) { |
||
535 | /*Point2D[] newPts = new Point2D[pts.size()];
|
||
536 | if ((flags & 0x1)==0x1) {
|
||
537 | newPts = new Point2D[pts.size()+1];
|
||
538 | for (int j=0;j<pts.size();j++) {
|
||
539 | newPts[j] = (Point2D)pts.get(j);
|
||
540 | }
|
||
541 | newPts[pts.size()] = (Point2D)pts.get(0);
|
||
542 | bulges.add(new Double(0));
|
||
543 | } else {
|
||
544 | for (int j=0;j<pts.size();j++) {
|
||
545 | newPts[j] = (Point2D)pts.get(j);
|
||
546 | }
|
||
547 | }*/
|
||
548 | double[] bs = new double[bulges.size()]; |
||
549 | for (int j=0;j<bulges.size();j++) { |
||
550 | bs[j] = ((Double)bulges.get(j)).doubleValue();
|
||
551 | } |
||
552 | ((DwgPolyline2D)pol).setBulges(bs); |
||
553 | //Point2D[] points = GisModelCurveCalculator.calculateGisModelBulge(newPts, bs);
|
||
554 | Point2D[] points = new Point2D[pts.size()]; |
||
555 | for (int j=0;j<pts.size();j++) { |
||
556 | points[j] = (Point2D)pts.get(j);
|
||
557 | } |
||
558 | ((DwgPolyline2D)pol).setPts(points); |
||
559 | } else {
|
||
560 | 7178 | azabala | // System.out.println("Encontrada polil?nea sin puntos ...");
|
561 | 2896 | jmorell | // TODO: No se debe mandar nunca una polil?nea sin puntos, si esto
|
562 | // ocurre es porque existe un error que hay que corregir ...
|
||
563 | } |
||
564 | } else if (pol instanceof DwgPolyline3D) { |
||
565 | } else if (pol instanceof DwgLwPolyline && ((DwgLwPolyline)pol).getVertices()!=null) { |
||
566 | } |
||
567 | } |
||
568 | } |
||
569 | 10240 | azabala | /*
|
570 | public void blockManagement2(){
|
||
571 | LinkedList dwgObjectsWithoutBlocks = new LinkedList();
|
||
572 | boolean addingToBlock = false;
|
||
573 | try{
|
||
574 | for (int i=0; i < dwgObjects.size(); i++) {
|
||
575 | DwgObject entity = (DwgObject)dwgObjects.get(i);
|
||
576 | if (entity instanceof DwgArc && !addingToBlock) {
|
||
577 | dwgObjectsWithoutBlocks.add(entity);
|
||
578 | } else if (entity instanceof DwgEllipse && !addingToBlock) {
|
||
579 | dwgObjectsWithoutBlocks.add(entity);
|
||
580 | } else if (entity instanceof DwgCircle && !addingToBlock) {
|
||
581 | dwgObjectsWithoutBlocks.add(entity);
|
||
582 | } else if (entity instanceof DwgPolyline2D && !addingToBlock) {
|
||
583 | dwgObjectsWithoutBlocks.add(entity);
|
||
584 | } else if (entity instanceof DwgPolyline3D && !addingToBlock) {
|
||
585 | dwgObjectsWithoutBlocks.add(entity);
|
||
586 | } else if (entity instanceof DwgLwPolyline && !addingToBlock) {
|
||
587 | dwgObjectsWithoutBlocks.add(entity);
|
||
588 | } else if (entity instanceof DwgSolid && !addingToBlock) {
|
||
589 | dwgObjectsWithoutBlocks.add(entity);
|
||
590 | } else if (entity instanceof DwgLine && !addingToBlock) {
|
||
591 | dwgObjectsWithoutBlocks.add(entity);
|
||
592 | } else if (entity instanceof DwgPoint && !addingToBlock) {
|
||
593 | dwgObjectsWithoutBlocks.add(entity);
|
||
594 | } else if (entity instanceof DwgMText && !addingToBlock) {
|
||
595 | dwgObjectsWithoutBlocks.add(entity);
|
||
596 | } else if (entity instanceof DwgText && !addingToBlock) {
|
||
597 | dwgObjectsWithoutBlocks.add(entity);
|
||
598 | } else if (entity instanceof DwgAttrib && !addingToBlock) {
|
||
599 | dwgObjectsWithoutBlocks.add(entity);
|
||
600 | } else if (entity instanceof DwgAttdef && !addingToBlock) {
|
||
601 | dwgObjectsWithoutBlocks.add(entity);
|
||
602 | } else if (entity instanceof DwgBlock) {
|
||
603 | addingToBlock = true;
|
||
604 | } else if (entity instanceof DwgEndblk) {
|
||
605 | addingToBlock = false;
|
||
606 | } else if (entity instanceof DwgBlockHeader) {
|
||
607 | addingToBlock = true;
|
||
608 | }
|
||
609 | //Segun esto, un insert solo se procesa dentro de un Block (o BlockHeader)
|
||
610 | //?Puede haber INSERT fuera de BLOCK-ENDBLK?
|
||
611 | else if (entity instanceof DwgInsert && !addingToBlock) {
|
||
612 | double[] p = ((DwgInsert)entity).getInsertionPoint();
|
||
613 | Point2D point = new Point2D.Double(p[0], p[1]);
|
||
614 | double[] scale = ((DwgInsert)entity).getScale();
|
||
615 | double rot = ((DwgInsert)entity).getRotation();
|
||
616 | int blockHandle = ((DwgInsert)entity).getBlockHeaderHandle().getOffset();
|
||
617 | manageInsert(point, scale, rot, blockHandle, dwgObjectsWithoutBlocks);
|
||
618 | } else {
|
||
619 | // System.out.println(entity.getClass().getName() +" en un bloque");
|
||
620 | //Se ha encontrado una entidad rara, o forma parte de un bloque
|
||
621 | //y ser? procesada despu?s (con los punteros del propio bloque)
|
||
622 | |||
623 | //TODO No se podr?a hacer mas rapido, quitando de la lista original
|
||
624 | //las entidades que forman parte de bloque??
|
||
625 | }
|
||
626 | }
|
||
627 | }catch(RuntimeException re){
|
||
628 | re.printStackTrace();
|
||
629 | }
|
||
630 | dwgObjects = dwgObjectsWithoutBlocks;
|
||
631 | }
|
||
632 | */
|
||
633 | 2896 | jmorell | /**
|
634 | * Modify the geometry of the objects contained in the blocks of a DWG file and
|
||
635 | * add these objects to the DWG object list.
|
||
636 | 9969 | azabala | *
|
637 | 10103 | azabala | * TODO Revisar los bloques que son XREF
|
638 | 2896 | jmorell | */
|
639 | 9974 | azabala | public void blockManagement() { |
640 | 9843 | azabala | LinkedList dwgObjectsWithoutBlocks = new LinkedList(); |
641 | 10240 | azabala | HashMap handle_objectsWithoutBlocks = new HashMap(); |
642 | 2896 | jmorell | boolean addingToBlock = false; |
643 | 9977 | azabala | try{
|
644 | for (int i=0; i < dwgObjects.size(); i++) { |
||
645 | DwgObject entity = (DwgObject)dwgObjects.get(i); |
||
646 | if (entity instanceof DwgArc && !addingToBlock) { |
||
647 | dwgObjectsWithoutBlocks.add(entity); |
||
648 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
649 | 9977 | azabala | } else if (entity instanceof DwgEllipse && !addingToBlock) { |
650 | dwgObjectsWithoutBlocks.add(entity); |
||
651 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
652 | 9977 | azabala | } else if (entity instanceof DwgCircle && !addingToBlock) { |
653 | dwgObjectsWithoutBlocks.add(entity); |
||
654 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
655 | 9977 | azabala | } else if (entity instanceof DwgPolyline2D && !addingToBlock) { |
656 | dwgObjectsWithoutBlocks.add(entity); |
||
657 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
658 | 9977 | azabala | } else if (entity instanceof DwgPolyline3D && !addingToBlock) { |
659 | dwgObjectsWithoutBlocks.add(entity); |
||
660 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
661 | 9977 | azabala | } else if (entity instanceof DwgLwPolyline && !addingToBlock) { |
662 | dwgObjectsWithoutBlocks.add(entity); |
||
663 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
664 | 9977 | azabala | } else if (entity instanceof DwgSolid && !addingToBlock) { |
665 | dwgObjectsWithoutBlocks.add(entity); |
||
666 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
667 | 9977 | azabala | } else if (entity instanceof DwgLine && !addingToBlock) { |
668 | dwgObjectsWithoutBlocks.add(entity); |
||
669 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
670 | 9977 | azabala | } else if (entity instanceof DwgPoint && !addingToBlock) { |
671 | dwgObjectsWithoutBlocks.add(entity); |
||
672 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
673 | 9977 | azabala | } else if (entity instanceof DwgMText && !addingToBlock) { |
674 | dwgObjectsWithoutBlocks.add(entity); |
||
675 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
676 | 9977 | azabala | } else if (entity instanceof DwgText && !addingToBlock) { |
677 | dwgObjectsWithoutBlocks.add(entity); |
||
678 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
679 | 9977 | azabala | } else if (entity instanceof DwgAttrib && !addingToBlock) { |
680 | dwgObjectsWithoutBlocks.add(entity); |
||
681 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
682 | 9977 | azabala | } else if (entity instanceof DwgAttdef && !addingToBlock) { |
683 | dwgObjectsWithoutBlocks.add(entity); |
||
684 | 10240 | azabala | handle_objectsWithoutBlocks.put(new Integer(entity.getHandle().getOffset()), entity); |
685 | 9992 | fdiaz | } else if (entity instanceof DwgBlock) { |
686 | 9977 | azabala | addingToBlock = true;
|
687 | 9992 | fdiaz | } else if (entity instanceof DwgEndblk) { |
688 | 9977 | azabala | addingToBlock = false;
|
689 | 9992 | fdiaz | } else if (entity instanceof DwgBlockHeader) { |
690 | addingToBlock = true;
|
||
691 | 9986 | azabala | } |
692 | //Segun esto, un insert solo se procesa dentro de un Block (o BlockHeader)
|
||
693 | //?Puede haber INSERT fuera de BLOCK-ENDBLK?
|
||
694 | 9977 | azabala | else if (entity instanceof DwgInsert && !addingToBlock) { |
695 | double[] p = ((DwgInsert)entity).getInsertionPoint(); |
||
696 | Point2D point = new Point2D.Double(p[0], p[1]); |
||
697 | double[] scale = ((DwgInsert)entity).getScale(); |
||
698 | double rot = ((DwgInsert)entity).getRotation();
|
||
699 | 10014 | fdiaz | int blockHandle = ((DwgInsert)entity).getBlockHeaderHandle().getOffset();
|
700 | 10240 | azabala | manageInsert(point, scale, rot, blockHandle, dwgObjectsWithoutBlocks, handle_objectsWithoutBlocks); |
701 | 9977 | azabala | } else {
|
702 | // System.out.println(entity.getClass().getName() +" en un bloque");
|
||
703 | //Se ha encontrado una entidad rara, o forma parte de un bloque
|
||
704 | //y ser? procesada despu?s (con los punteros del propio bloque)
|
||
705 | |||
706 | //TODO No se podr?a hacer mas rapido, quitando de la lista original
|
||
707 | //las entidades que forman parte de bloque??
|
||
708 | } |
||
709 | 2896 | jmorell | } |
710 | 9977 | azabala | }catch(RuntimeException re){ |
711 | re.printStackTrace(); |
||
712 | } |
||
713 | 2896 | jmorell | dwgObjects = dwgObjectsWithoutBlocks; |
714 | 10240 | azabala | this.handle_objects = (HashMap) handle_objectsWithoutBlocks; |
715 | 2896 | jmorell | } |
716 | |||
717 | /**
|
||
718 | * Manages an INSERT of a DWG file. This object is the insertion point of a DWG
|
||
719 | 9830 | azabala | * block.
|
720 | *
|
||
721 | 2896 | jmorell | * @param insPoint, coordinates of the insertion point.
|
722 | * @param scale, scale of the elements of the block that will be inserted.
|
||
723 | * @param rot, rotation angle of the elements of the block.
|
||
724 | 9830 | azabala | *
|
725 | 2896 | jmorell | * @param bHandle, offset for the coordinates of the elements of the block.
|
726 | * @param id, count that serves as a id.
|
||
727 | * @param dwgObjectsWithoutBlocks, a object list with the elements extracted from
|
||
728 | * the blocks.
|
||
729 | */
|
||
730 | 9977 | azabala | public void manageInsert(Point2D insPoint, double[] scale, |
731 | 9843 | azabala | double rot, int bHandle, |
732 | 10240 | azabala | List dwgObjectsWithoutBlocks,
|
733 | Map handleObjectsWithoutBlocks) {
|
||
734 | 9830 | azabala | |
735 | 9843 | azabala | DwgObject object = (DwgObject) handle_objects.get(new Integer(bHandle)); |
736 | 10156 | azabala | if(object == null){ |
737 | 10221 | azabala | // System.out.println("No hemos encontrado el BlockHeader cuyo handle es "+bHandle);
|
738 | 10156 | azabala | return;
|
739 | }else if(! (object instanceof DwgBlockHeader)){ |
||
740 | 9840 | azabala | //Hay un problema con la asignaci?n de handle
|
741 | //Un INSERT tiene como handle de Block una entidad que no es block
|
||
742 | 10221 | azabala | // System.out.println("handle incorrecto." + object.getClass().getName() + " no es un blockheader");
|
743 | 9840 | azabala | return;
|
744 | } |
||
745 | DwgBlockHeader blockHeader = (DwgBlockHeader)object; |
||
746 | double[] bPoint = blockHeader.getBasePoint(); |
||
747 | String bname = blockHeader.getName();
|
||
748 | if (bname.startsWith("*")) |
||
749 | return;
|
||
750 | |||
751 | 10054 | azabala | DwgHandleReference firstHdl = blockHeader.getFirstEntityHandle(); |
752 | DwgHandleReference lastHdl = blockHeader.getLastEntityHandle(); |
||
753 | if(firstHdl == null || lastHdl == null){ |
||
754 | 10221 | azabala | // System.out.println("Problemas en el bloque "+bname);
|
755 | // System.out.println("1er obj="+firstHdl+" 2o obj="+lastHdl);
|
||
756 | 10054 | azabala | return;
|
757 | } |
||
758 | |||
759 | |||
760 | |||
761 | int firstObjectHandle = firstHdl.getOffset();
|
||
762 | int lastObjectHandle = lastHdl.getOffset();
|
||
763 | |||
764 | 9843 | azabala | //TODO Ver que hacia el metodo antiguo cuando llegaban handles a 0
|
765 | //como extremos de un bloque (sera bloque vacio, supongo)
|
||
766 | 9974 | azabala | if(firstObjectHandle == 0 || lastObjectHandle == 0){ |
767 | 10221 | azabala | // System.out.println("Problemas en el bloque "+bname);
|
768 | // System.out.println("1er obj="+firstObjectHandle+" 2o obj="+lastObjectHandle);
|
||
769 | 9843 | azabala | return;
|
770 | 9974 | azabala | } |
771 | 9843 | azabala | |
772 | 9840 | azabala | /*
|
773 | 9843 | azabala | * Ahora localiza la primera entidad del bloque,
|
774 | * y a partir de ah?, a?ade
|
||
775 | * al bloque todas las entidades que encuentre hasta la
|
||
776 | * ?ltima entidad del bloque
|
||
777 | 9840 | azabala | *
|
778 | * */
|
||
779 | 9843 | azabala | DwgObject firstObj = (DwgObject) handle_objects. |
780 | get(new Integer(firstObjectHandle)); |
||
781 | DwgObject lastObj = (DwgObject) handle_objects. |
||
782 | get(new Integer(lastObjectHandle)); |
||
783 | |||
784 | int firstObjIdx = dwgObjects.indexOf(firstObj);
|
||
785 | int lastObjIdx = dwgObjects.indexOf(lastObj);
|
||
786 | 9986 | azabala | if(firstObjIdx == -1){ |
787 | 10221 | azabala | // System.out.println("El primer objeto del bloque "+
|
788 | // blockHeader.getName()+
|
||
789 | // " no ha sido localizado a partir del handle "+
|
||
790 | // firstObjectHandle);
|
||
791 | 9986 | azabala | return;
|
792 | } |
||
793 | 9992 | fdiaz | |
794 | 9986 | azabala | if(lastObjIdx == -1){ |
795 | 10221 | azabala | // System.out.println("El ultimo objeto del bloque "+
|
796 | // blockHeader.getName()+
|
||
797 | // " no ha sido localizado a partir del handle "+
|
||
798 | // lastObjectHandle);
|
||
799 | 9977 | azabala | |
800 | 9986 | azabala | //Intentamos ver si como delimitador final de bloque aparece EndBlk
|
801 | LinkedList tempDwgObj = new LinkedList(); |
||
802 | 10240 | azabala | HashMap tempHdlObj = new HashMap(); |
803 | 9986 | azabala | DwgObject scannedEntity = (DwgObject) dwgObjects.get(firstObjIdx); |
804 | while(! (scannedEntity instanceof DwgEndblk)){ |
||
805 | manageBlockEntity(scannedEntity, bPoint, |
||
806 | insPoint, scale, rot, |
||
807 | 10240 | azabala | tempDwgObj, |
808 | tempHdlObj); |
||
809 | 9986 | azabala | firstObjIdx++; |
810 | scannedEntity = (DwgObject) dwgObjects.get(firstObjIdx); |
||
811 | if( (scannedEntity instanceof DwgBlock) || |
||
812 | (scannedEntity instanceof DwgBlockHeader)){
|
||
813 | //No puede haber bloques anidados
|
||
814 | //Descartar
|
||
815 | 10221 | azabala | // System.out.println("Error, aparecen bloques anidados");
|
816 | 9992 | fdiaz | return;
|
817 | } |
||
818 | 9986 | azabala | }//while
|
819 | 10240 | azabala | if(tempDwgObj.size() > 0){ |
820 | 9986 | azabala | dwgObjectsWithoutBlocks.addAll(tempDwgObj); |
821 | 10240 | azabala | handleObjectsWithoutBlocks.putAll(tempHdlObj); |
822 | } |
||
823 | 9986 | azabala | return;
|
824 | 9977 | azabala | |
825 | 9986 | azabala | }//if
|
826 | 9843 | azabala | for(int i = firstObjIdx; i <= lastObjIdx; i++){ |
827 | DwgObject obj = (DwgObject) dwgObjects.get(i); |
||
828 | 9974 | azabala | manageBlockEntity(obj, bPoint, |
829 | 9843 | azabala | insPoint, scale, |
830 | 10240 | azabala | rot, dwgObjectsWithoutBlocks, handleObjectsWithoutBlocks); |
831 | 9843 | azabala | }//for
|
832 | 2896 | jmorell | } |
833 | |||
834 | 9977 | azabala | public int getIndexOf(DwgObject dwgObject){ |
835 | return dwgObjects.indexOf(dwgObject);
|
||
836 | |||
837 | |||
838 | } |
||
839 | 9969 | azabala | |
840 | |||
841 | 9977 | azabala | |
842 | 2896 | jmorell | /**
|
843 | * Changes the location of an object extracted from a block. This location will be
|
||
844 | * obtained through the insertion parameters from the block and the corresponding
|
||
845 | * insert.
|
||
846 | * @param entity, the entity extracted from the block.
|
||
847 | * @param bPoint, offset for the coordinates of the entity.
|
||
848 | * @param insPoint, coordinates of the insertion point for the entity.
|
||
849 | * @param scale, scale for the entity.
|
||
850 | * @param rot, rotation angle for the entity.
|
||
851 | * @param id, a count as a id.
|
||
852 | * @param dwgObjectsWithoutBlocks, a object list with the elements extracted from
|
||
853 | * the blocks.
|
||
854 | */
|
||
855 | 9977 | azabala | private void manageBlockEntity(DwgObject entity, |
856 | 9843 | azabala | double[] bPoint, |
857 | Point2D insPoint,
|
||
858 | double[] scale, |
||
859 | double rot,
|
||
860 | 10240 | azabala | List dwgObjectsWithoutBlocks,
|
861 | Map handleObjectsWithoutBlocks) {
|
||
862 | 9840 | azabala | |
863 | 9843 | azabala | if(entity instanceof IDwgBlockMember){ |
864 | IDwgBlockMember blockMember = (IDwgBlockMember)entity; |
||
865 | 10240 | azabala | blockMember.transform2Block(bPoint, insPoint, scale, rot, |
866 | dwgObjectsWithoutBlocks, |
||
867 | handleObjectsWithoutBlocks,this);
|
||
868 | 9977 | azabala | }else{
|
869 | //TODO REIMPLEMENTAR ENTIDADES QUE PUEDEN FORMAR PARTE DE BLOQUES.
|
||
870 | //POR EJEMPLO: DwgText y DwgMText pueden formar parte
|
||
871 | //de bloques, y de hecho, est?n apareciendo
|
||
872 | |||
873 | // System.out.println(entity.getClass().getName()+" dentro de un bloque");
|
||
874 | 9840 | azabala | } |
875 | 2896 | jmorell | } |
876 | |||
877 | |||
878 | 9843 | azabala | /*
|
879 | * azabala: Esto ahora se hace mientras las entidades dwg
|
||
880 | * se van creando, y no en una segunda pasada
|
||
881 | * */
|
||
882 | /*
|
||
883 | 2896 | jmorell | public void testDwg3D() {
|
884 | for (int i=0;i<dwgObjects.size();i++) {
|
||
885 | DwgObject obj = (DwgObject)dwgObjects.get(i);
|
||
886 | 9825 | azabala | |
887 | if(obj instanceof IDwg3DTestable){
|
||
888 | if(((IDwg3DTestable)obj).has3DData())
|
||
889 | dwg3DFile = true;
|
||
890 | return;
|
||
891 | }
|
||
892 | |||
893 | 2896 | jmorell | //} else if (obj instanceof DwgLinearDimension) {
|
894 | // z = ((DwgLinearDimension)obj).getElevation();
|
||
895 | 9825 | azabala | // if (z!=0.0) dwg3DFile = true;
|
896 | }//for
|
||
897 | dwg3DFile = false;
|
||
898 | 2896 | jmorell | }
|
899 | 9843 | azabala | */
|
900 | 2896 | jmorell | |
901 | /**
|
||
902 | * Add a DWG section offset to the dwgSectionOffsets vector
|
||
903 | *
|
||
904 | * @param key Define the DWG section
|
||
905 | * @param seek Offset of the section
|
||
906 | * @param size Size of the section
|
||
907 | */
|
||
908 | public void addDwgSectionOffset(String key, int seek, int size) { |
||
909 | DwgSectionOffset dso = new DwgSectionOffset(key, seek, size);
|
||
910 | dwgSectionOffsets.add(dso); |
||
911 | } |
||
912 | |||
913 | /**
|
||
914 | * Returns the offset of DWG section given by its key
|
||
915 | *
|
||
916 | * @param key Define the DWG section
|
||
917 | * @return int Offset of the section in the DWG file
|
||
918 | */
|
||
919 | public int getDwgSectionOffset(String key) { |
||
920 | int offset = 0; |
||
921 | for (int i=0; i<dwgSectionOffsets.size(); i++) { |
||
922 | DwgSectionOffset dso = (DwgSectionOffset)dwgSectionOffsets.get(i); |
||
923 | String ikey = dso.getKey();
|
||
924 | if (key.equals(ikey)) {
|
||
925 | offset = dso.getSeek(); |
||
926 | break;
|
||
927 | } |
||
928 | } |
||
929 | return offset;
|
||
930 | } |
||
931 | |||
932 | /**
|
||
933 | * Add a DWG object offset to the dwgObjectOffsets vector
|
||
934 | *
|
||
935 | * @param handle Object handle
|
||
936 | * @param offset Offset of the object data in the DWG file
|
||
937 | */
|
||
938 | public void addDwgObjectOffset(int handle, int offset) { |
||
939 | DwgObjectOffset doo = new DwgObjectOffset(handle, offset);
|
||
940 | dwgObjectOffsets.add(doo); |
||
941 | } |
||
942 | |||
943 | /**
|
||
944 | *
|
||
945 | * Add a DWG object to the dwgObject vector
|
||
946 | *
|
||
947 | * @param dwgObject DWG object
|
||
948 | */
|
||
949 | public void addDwgObject(DwgObject dwgObject){ |
||
950 | 9825 | azabala | //TODO Ver si puedo inicializar las listas especificas
|
951 | //(IDwgPolyline, etc) aqu?
|
||
952 | 2896 | jmorell | dwgObjects.add(dwgObject); |
953 | 10014 | fdiaz | handle_objects.put(new Integer(dwgObject.getHandle().getOffset()), dwgObject); |
954 | 9843 | azabala | /*
|
955 | * TODO Quitar todos estos if-then y sustituirlos por un metodo callbackj
|
||
956 | *
|
||
957 | *
|
||
958 | * (dwgObject.init(this), y que cada objeto haga lo que tenga que hacer
|
||
959 | * */
|
||
960 | 9602 | azabala | if(dwgObject instanceof DwgLayer){ |
961 | this.addDwgLayer((DwgLayer) dwgObject);
|
||
962 | } |
||
963 | 9825 | azabala | if(dwgObject instanceof IDwgExtrusionable){ |
964 | ((IDwgExtrusionable)dwgObject).applyExtrussion(); |
||
965 | } |
||
966 | if(dwgObject instanceof IDwgPolyline){ |
||
967 | dwgPolylines.add(dwgObject); |
||
968 | } |
||
969 | if(dwgObject instanceof IDwg3DTestable){ |
||
970 | if(! dwg3DFile){//if its true, we dont check again |
||
971 | dwg3DFile = ((IDwg3DTestable)dwgObject).has3DData(); |
||
972 | } |
||
973 | } |
||
974 | 10240 | azabala | //checks if it is a subentity of a block
|
975 | DwgObject superEntity = dwgObject.getSuperEntity(); |
||
976 | if(superEntity instanceof DwgBlock || superEntity instanceof DwgBlockHeader){ |
||
977 | System.out.println(dwgObject.getClass().getName()+" pertenece a "+superEntity.getClass().getName()); |
||
978 | 9843 | azabala | } |
979 | 2896 | jmorell | } |
980 | |||
981 | 9840 | azabala | /**
|
982 | * Returns dwgObjects from its insertion order (position
|
||
983 | * in the dwg file)
|
||
984 | *
|
||
985 | * @param index order in the dwg file
|
||
986 | * @return position
|
||
987 | * */
|
||
988 | 9719 | azabala | public DwgObject getDwgObject(int index){ |
989 | return (DwgObject) dwgObjects.get(index);
|
||
990 | } |
||
991 | |||
992 | 9840 | azabala | public DwgObject getDwgObjectFromHandle(int handle){ |
993 | return (DwgObject) handle_objects.get(new Integer(handle)); |
||
994 | } |
||
995 | |||
996 | 2896 | jmorell | /**
|
997 | * Add a DWG class to the dwgClasses vector
|
||
998 | *
|
||
999 | * @param dwgClass DWG class
|
||
1000 | */
|
||
1001 | public void addDwgClass(DwgClass dwgClass){ |
||
1002 | dwgClasses.add(dwgClass); |
||
1003 | } |
||
1004 | |||
1005 | 10221 | azabala | public void printClasses(){ |
1006 | System.out.println("#### CLASSES ####"); |
||
1007 | for(int i = 0; i < dwgClasses.size(); i++){ |
||
1008 | DwgClass clazz = (DwgClass) dwgClasses.get(i); |
||
1009 | System.out.println(clazz.toString());
|
||
1010 | } |
||
1011 | System.out.println("#############"); |
||
1012 | } |
||
1013 | |||
1014 | 9889 | azabala | public List getDwgClasses(){ |
1015 | return dwgClasses;
|
||
1016 | } |
||
1017 | |||
1018 | 2896 | jmorell | /**
|
1019 | * @return Returns the dwgObjectOffsets.
|
||
1020 | */
|
||
1021 | 7178 | azabala | public ArrayList getDwgObjectOffsets() { |
1022 | 2896 | jmorell | return dwgObjectOffsets;
|
1023 | } |
||
1024 | /**
|
||
1025 | * @return Returns the dwgObjects.
|
||
1026 | */
|
||
1027 | 9843 | azabala | public LinkedList getDwgObjects() { |
1028 | 2896 | jmorell | return dwgObjects;
|
1029 | } |
||
1030 | /**
|
||
1031 | * @return Returns the fileName.
|
||
1032 | */
|
||
1033 | public String getFileName() { |
||
1034 | return fileName;
|
||
1035 | } |
||
1036 | /**
|
||
1037 | * @return Returns the dwg3DFile.
|
||
1038 | */
|
||
1039 | public boolean isDwg3DFile() { |
||
1040 | return dwg3DFile;
|
||
1041 | } |
||
1042 | /**
|
||
1043 | * @param dwg3DFile The dwg3DFile to set.
|
||
1044 | */
|
||
1045 | public void setDwg3DFile(boolean dwg3DFile) { |
||
1046 | this.dwg3DFile = dwg3DFile;
|
||
1047 | } |
||
1048 | } |