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