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