Revision 1843
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dwg/DwgMemoryDriver.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 14-abr-2005 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
package com.iver.cit.gvsig.fmap.drivers.dwg; |
|
45 |
|
|
46 |
import java.awt.Color; |
|
47 |
import java.awt.Font; |
|
48 |
import java.awt.geom.Point2D; |
|
49 |
import java.io.File; |
|
50 |
import java.io.IOException; |
|
51 |
import java.util.ArrayList; |
|
52 |
import java.util.Vector; |
|
53 |
|
|
54 |
import net.jmorell.jdwglib.dwg.DwgFile; |
|
55 |
import net.jmorell.jdwglib.dwg.DwgObject; |
|
56 |
import net.jmorell.jdwglib.dwg.DwgObjectSpecificDataItem; |
|
57 |
import net.jmorell.jdwglib.dwg.DxfName; |
|
58 |
|
|
59 |
import org.cresques.px.dxf.AcadColor; |
|
60 |
|
|
61 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
62 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
|
63 |
import com.hardcode.gdbms.engine.values.IntValue; |
|
64 |
import com.hardcode.gdbms.engine.values.Value; |
|
65 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
66 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
67 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
|
68 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
|
69 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
70 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
71 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
|
72 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
73 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
|
74 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
|
75 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
|
76 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
|
77 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
|
78 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
|
79 |
|
|
80 |
public class DwgMemoryDriver extends MemoryDriver implements WithDefaultLegend { |
|
81 |
private final int ID_FIELD_ID=0; |
|
82 |
private final int ID_FIELD_ENTITY=1; |
|
83 |
private final int ID_FIELD_LAYER=2; |
|
84 |
private final int ID_FIELD_COLOR=3; |
|
85 |
private final int ID_FIELD_ELEVATION=4; |
|
86 |
private final int ID_FIELD_THICKNESS=5; |
|
87 |
private final int ID_FIELD_TEXT=6; |
|
88 |
private final int ID_FIELD_HEIGHTTEXT=7; |
|
89 |
private final int ID_FIELD_ROTATIONTEXT=8; |
|
90 |
|
|
91 |
VectorialUniqueValueLegend defaultLegend; |
|
92 |
private String path; |
|
93 |
private File m_Fich; |
|
94 |
|
|
95 |
private DwgFile dwg; |
|
96 |
private Vector dwgObjects; |
|
97 |
private DriverAttributes attr = new DriverAttributes(); |
|
98 |
|
|
99 |
/* (non-Javadoc) |
|
100 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File) |
|
101 |
*/ |
|
102 |
public void open(File f) throws IOException { |
|
103 |
m_Fich = f; |
|
104 |
} |
|
105 |
|
|
106 |
public void initialize() throws IOException { |
|
107 |
float heightText = 10; |
|
108 |
|
|
109 |
attr.setLoadedInMemory(true); |
|
110 |
|
|
111 |
dwg = new DwgFile(); |
|
112 |
dwg.read(m_Fich.getAbsolutePath()); |
|
113 |
dwgObjects = dwg.getDwgObjects(); |
|
114 |
|
|
115 |
/*for (int i=0;i<dwgObjects.size();i++) { |
|
116 |
DwgObject ob = (DwgObject)dwgObjects.get(i); |
|
117 |
int type = ob.getType(); |
|
118 |
if (type==0x0F) { |
|
119 |
DwgObjectSpecificDataItem dataa = ob.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE"); |
|
120 |
int firstHandle = ((Integer)dataa.getValue()).intValue(); |
|
121 |
System.out.println("firstHandle = " + firstHandle); |
|
122 |
for (int j=0;j<dwgObjects.size();j++) { |
|
123 |
DwgObject v = (DwgObject)dwgObjects.get(j); |
|
124 |
int handle = v.getHandle(); |
|
125 |
System.out.println("handle = " + handle); |
|
126 |
if (handle==firstHandle) { |
|
127 |
System.out.println("Encontrado primer vertice! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); |
|
128 |
} |
|
129 |
} |
|
130 |
//DwgObject v = (DwgObject)dwgObjects.get(i+2); |
|
131 |
//System.out.println("v.getType() = " + v.getType()); |
|
132 |
//DwgObjectSpecificDataItem dataa = v.getDwgObjectSpecificDataItem("POINT"); |
|
133 |
//System.out.println("((double[])dataa.getValue())[0] = " + ((double[])dataa.getValue())[0] + "++++++++++++++++++++++++++++++++++"); |
|
134 |
} |
|
135 |
}*/ |
|
136 |
|
|
137 |
//int nAtt = featureMaker.getAttributes().size(); |
|
138 |
|
|
139 |
// Campos de las MemoryLayer: |
|
140 |
//Value[] auxRow = new Value[9+nAtt]; |
|
141 |
Value[] auxRow = new Value[9]; |
|
142 |
ArrayList arrayFields = new ArrayList(); |
|
143 |
arrayFields.add("ID"); |
|
144 |
arrayFields.add("Entity"); |
|
145 |
arrayFields.add("Layer"); |
|
146 |
arrayFields.add("Color"); |
|
147 |
arrayFields.add("Elevation"); |
|
148 |
arrayFields.add("Thickness"); |
|
149 |
arrayFields.add("Text"); |
|
150 |
arrayFields.add("HeightText"); |
|
151 |
arrayFields.add("RotationText"); |
|
152 |
/*for (int i=0;i<nAtt;i++) { |
|
153 |
String att[] = new String[2]; |
|
154 |
att = (String[])featureMaker.getAttributes().get(i); |
|
155 |
arrayFields.add(att[0]); |
|
156 |
}*/ |
|
157 |
|
|
158 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
|
159 |
|
|
160 |
for (int i=0;i<dwgObjects.size();i++) { |
|
161 |
|
|
162 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0); |
|
163 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0); |
|
164 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
|
165 |
|
|
166 |
DwgObject entity = (DwgObject)dwgObjects.get(i); |
|
167 |
if (entity.getType()==0x11) { |
|
168 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER"); |
|
169 |
double[] coord = (double[])data.getValue(); |
|
170 |
Point2D center = new Point2D.Double(coord[0], coord[1]); |
|
171 |
//System.out.println("center.getX() = " + center.getX()); |
|
172 |
//System.out.println("center.getY() = " + center.getY()); |
|
173 |
data = entity.getDwgObjectSpecificDataItem("RADIUS"); |
|
174 |
double radius = ((Double)data.getValue()).doubleValue(); |
|
175 |
//System.out.println("radius = " + radius); |
|
176 |
data = entity.getDwgObjectSpecificDataItem("START_ANGLE"); |
|
177 |
double startAngle = Math.toDegrees(((Double)data.getValue()).doubleValue()); |
|
178 |
//System.out.println("startAngle = " + startAngle); |
|
179 |
data = entity.getDwgObjectSpecificDataItem("END_ANGLE"); |
|
180 |
double endAngle = Math.toDegrees(((Double)data.getValue()).doubleValue()); |
|
181 |
//System.out.println("endAngle = " + endAngle); |
|
182 |
FPolyline2D arc = createArc(center, radius, startAngle, endAngle); |
|
183 |
//pto = (Point2D.Double)point.get(0); |
|
184 |
//FShape nuevoShp; |
|
185 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
186 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
187 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
188 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
189 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
190 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
191 |
// Attributes |
|
192 |
/*for (int j=0;j<nAtt;j++) { |
|
193 |
String[] attributes = new String[2]; |
|
194 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
195 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
196 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
197 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
198 |
} |
|
199 |
}*/ |
|
200 |
addShape(arc, auxRow); |
|
201 |
} else if (entity.getType()==0x12) { |
|
202 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER"); |
|
203 |
double[] coord = (double[])data.getValue(); |
|
204 |
Point2D center = new Point2D.Double(coord[0], coord[1]); |
|
205 |
data = entity.getDwgObjectSpecificDataItem("RADIUS"); |
|
206 |
double radius = ((Double)data.getValue()).doubleValue(); |
|
207 |
FPolyline2D circle = createCircle(center, radius); |
|
208 |
//pto = (Point2D.Double)point.get(0); |
|
209 |
//FShape nuevoShp; |
|
210 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
211 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
212 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
213 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
214 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
215 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
216 |
// Attributes |
|
217 |
/*for (int j=0;j<nAtt;j++) { |
|
218 |
String[] attributes = new String[2]; |
|
219 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
220 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
221 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
222 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
223 |
} |
|
224 |
}*/ |
|
225 |
addShape(circle, auxRow); |
|
226 |
} else if (entity.getType()==0x13) { |
|
227 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("P1"); |
|
228 |
double[] coord = (double[])data.getValue(); |
|
229 |
Point2D p1 = new Point2D.Double(coord[0], coord[1]); |
|
230 |
data = entity.getDwgObjectSpecificDataItem("P2"); |
|
231 |
coord = (double[])data.getValue(); |
|
232 |
Point2D p2 = new Point2D.Double(coord[0], coord[1]); |
|
233 |
FPolyline2D line = createLine(p1, p2); |
|
234 |
//pto = (Point2D.Double)point.get(0); |
|
235 |
//FShape nuevoShp; |
|
236 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
237 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
238 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
239 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
240 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
241 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
242 |
// Attributes |
|
243 |
/*for (int j=0;j<nAtt;j++) { |
|
244 |
String[] attributes = new String[2]; |
|
245 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
246 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
247 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
248 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
249 |
} |
|
250 |
}*/ |
|
251 |
addShape(line, auxRow); |
|
252 |
} else if (entity.getType()==0x1B) { |
|
253 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("POINT"); |
|
254 |
double[] coord = (double[])data.getValue(); |
|
255 |
Point2D p = new Point2D.Double(coord[0], coord[1]); |
|
256 |
FPoint2D point = createPoint(p); |
|
257 |
//pto = (Point2D.Double)point.get(0); |
|
258 |
//FShape nuevoShp; |
|
259 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
260 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
261 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
262 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
263 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
264 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
265 |
// Attributes |
|
266 |
/*for (int j=0;j<nAtt;j++) { |
|
267 |
String[] attributes = new String[2]; |
|
268 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
269 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
270 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
271 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
272 |
} |
|
273 |
}*/ |
|
274 |
addShape(point, auxRow); |
|
275 |
} else if (entity.getType()==0x0F) { |
|
276 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("FLAGS"); |
|
277 |
int flags = ((Integer)data.getValue()).intValue(); |
|
278 |
data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE"); |
|
279 |
int[] firstVertexHandle = (int[])data.getValue(); |
|
280 |
data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE"); |
|
281 |
int[] lastVertexHandle = (int[])data.getValue(); |
|
282 |
data = entity.getDwgObjectSpecificDataItem("SEQEND_HANDLE"); |
|
283 |
int[] seqendHandle = (int[])data.getValue(); |
|
284 |
if (firstVertexHandle.length==4) { |
|
285 |
//System.out.println("firstVertexHandle[3] = " + firstVertexHandle[3]); |
|
286 |
//System.out.println("lastVertexHandle[3] = " + lastVertexHandle[3]); |
|
287 |
} else if (firstVertexHandle.length==3) { |
|
288 |
//System.out.println("firstVertexHandle[2] = " + firstVertexHandle[2]); |
|
289 |
//System.out.println("lastVertexHandle[2] = " + lastVertexHandle[2]); |
|
290 |
} |
|
291 |
//int vertexNumber = (lastVertexHandle-firstVertexHandle)+1; |
|
292 |
int vertexNumber = calculateVertexNumber(firstVertexHandle, lastVertexHandle); |
|
293 |
// Este if es para evitar algunas poil?neas raras. Luego habr? que |
|
294 |
// quitarlo y afrontar el problema ... |
|
295 |
if (vertexNumber>0) { |
|
296 |
System.out.println("vertexNumber = " + vertexNumber); |
|
297 |
Point2D[] pts = new Point2D[vertexNumber]; |
|
298 |
double[] pt = new double[2]; |
|
299 |
|
|
300 |
// Buscando el primer v?rtice ... |
|
301 |
for (int j=0;j<dwgObjects.size();j++) { |
|
302 |
DwgObject obj = (DwgObject)dwgObjects.get(j); |
|
303 |
Vector handle = obj.getHandle(); |
|
304 |
if (handle.size()==firstVertexHandle.length) { |
|
305 |
if (handle.size()==3) { |
|
306 |
if (((Integer)handle.get(2)).intValue()==firstVertexHandle[2]) { |
|
307 |
for (int k=0; k<vertexNumber; k++) { |
|
308 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k); |
|
309 |
data = vertex.getDwgObjectSpecificDataItem("POINT"); |
|
310 |
pt = (double[])data.getValue(); |
|
311 |
// Este if es para evitar algunas poil?neas raras. Luego habr? que |
|
312 |
// quitarlo y afrontar el problema ... |
|
313 |
/*if (data==null) { |
|
314 |
pt = new double[]{0.0, 0.0}; |
|
315 |
} else { |
|
316 |
pt = (double[])data.getValue(); |
|
317 |
}*/ |
|
318 |
pts[k] = new Point2D.Double(pt[0], pt[1]); |
|
319 |
} |
|
320 |
} |
|
321 |
} else if (handle.size()==4) { |
|
322 |
if (((Integer)handle.get(2)).intValue()==firstVertexHandle[2] && ((Integer)handle.get(3)).intValue()==firstVertexHandle[3]) { |
|
323 |
for (int k=0; k<vertexNumber; k++) { |
|
324 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k); |
|
325 |
data = vertex.getDwgObjectSpecificDataItem("POINT"); |
|
326 |
pt = (double[])data.getValue(); |
|
327 |
// Este if es para evitar algunas poil?neas raras. Luego habr? que |
|
328 |
// quitarlo y afrontar el problema ... |
|
329 |
/*if (data==null) { |
|
330 |
pt = new double[]{0.0, 0.0}; |
|
331 |
} else { |
|
332 |
pt = (double[])data.getValue(); |
|
333 |
}*/ |
|
334 |
pts[k] = new Point2D.Double(pt[0], pt[1]); |
|
335 |
} |
|
336 |
} |
|
337 |
} else { |
|
338 |
// |
|
339 |
} |
|
340 |
} |
|
341 |
} |
|
342 |
Point2D[] newPts = new Point2D[pts.length]; |
|
343 |
if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) { |
|
344 |
newPts = pts; |
|
345 |
} else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) { |
|
346 |
newPts = new Point2D[pts.length+1]; |
|
347 |
for (int j=0;j<pts.length;j++) { |
|
348 |
newPts[j] = pts[j]; |
|
349 |
} |
|
350 |
newPts[pts.length] = pts[0]; |
|
351 |
} |
|
352 |
FPolyline2D pline = createPolyline2D(newPts); |
|
353 |
//pto = (Point2D.Double)point.get(0); |
|
354 |
//FShape nuevoShp; |
|
355 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
356 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
357 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
358 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
359 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
360 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
361 |
// Attributes |
|
362 |
/*for (int j=0;j<nAtt;j++) { |
|
363 |
String[] attributes = new String[2]; |
|
364 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
365 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
366 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
367 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
368 |
} |
|
369 |
}*/ |
|
370 |
addShape(pline, auxRow); |
|
371 |
} |
|
372 |
} else if (entity.getType()==0x10) { |
|
373 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CLOSED_FLAGS"); |
|
374 |
int flags = ((Integer)data.getValue()).intValue(); |
|
375 |
data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE"); |
|
376 |
int[] firstVertexHandle = (int[])data.getValue(); |
|
377 |
data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE"); |
|
378 |
int[] lastVertexHandle = (int[])data.getValue(); |
|
379 |
data = entity.getDwgObjectSpecificDataItem("SEQEND_HANDLE"); |
|
380 |
int[] seqendHandle = (int[])data.getValue(); |
|
381 |
if (firstVertexHandle.length==4) { |
|
382 |
//System.out.println("firstVertexHandle[3] = " + firstVertexHandle[3]); |
|
383 |
//System.out.println("lastVertexHandle[3] = " + lastVertexHandle[3]); |
|
384 |
} else if (firstVertexHandle.length==3) { |
|
385 |
//System.out.println("firstVertexHandle[2] = " + firstVertexHandle[2]); |
|
386 |
//System.out.println("lastVertexHandle[2] = " + lastVertexHandle[2]); |
|
387 |
} |
|
388 |
//int vertexNumber = (lastVertexHandle-firstVertexHandle)+1; |
|
389 |
int vertexNumber = calculateVertexNumber(firstVertexHandle, lastVertexHandle); |
|
390 |
Point2D[] pts = new Point2D[vertexNumber]; |
|
391 |
double[] pt = new double[2]; |
|
392 |
|
|
393 |
// Buscando el primer v?rtice ... |
|
394 |
for (int j=0;j<dwgObjects.size();j++) { |
|
395 |
DwgObject v = (DwgObject)dwgObjects.get(j); |
|
396 |
Vector handle = v.getHandle(); |
|
397 |
if (handle.size()==4) { |
|
398 |
if (((Integer)handle.get(2)).intValue()==firstVertexHandle[2] && ((Integer)handle.get(3)).intValue()==firstVertexHandle[3]) { |
|
399 |
for (int k=0; k<vertexNumber; k++) { |
|
400 |
//System.out.println("k = " + k); |
|
401 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k); |
|
402 |
data = vertex.getDwgObjectSpecificDataItem("POINT"); |
|
403 |
//System.out.println("pt = " + pt); |
|
404 |
//System.out.println("data = " + data); |
|
405 |
//System.out.println("(double[])data.getValue() = " + (double[])data.getValue()); |
|
406 |
pt = (double[])data.getValue(); |
|
407 |
pts[k] = new Point2D.Double(pt[0], pt[1]); |
|
408 |
} |
|
409 |
} |
|
410 |
} else if (handle.size()==3) { |
|
411 |
if (((Integer)handle.get(2)).intValue()==firstVertexHandle[2]) { |
|
412 |
for (int k=0; k<vertexNumber; k++) { |
|
413 |
//System.out.println("k = " + k); |
|
414 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k); |
|
415 |
data = vertex.getDwgObjectSpecificDataItem("POINT"); |
|
416 |
//System.out.println("pt = " + pt); |
|
417 |
//System.out.println("data = " + data); |
|
418 |
//System.out.println("(double[])data.getValue() = " + (double[])data.getValue()); |
|
419 |
pt = (double[])data.getValue(); |
|
420 |
pts[k] = new Point2D.Double(pt[0], pt[1]); |
|
421 |
} |
|
422 |
} |
|
423 |
} |
|
424 |
} |
|
425 |
Point2D[] newPts = new Point2D[pts.length]; |
|
426 |
if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) { |
|
427 |
newPts = pts; |
|
428 |
} else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) { |
|
429 |
newPts = new Point2D[pts.length+1]; |
|
430 |
for (int j=0;j<pts.length;j++) { |
|
431 |
newPts[j] = pts[j]; |
|
432 |
} |
|
433 |
newPts[pts.length] = pts[0]; |
|
434 |
} |
|
435 |
FPolyline2D pline3d = createPolyline2D(newPts); |
|
436 |
//pto = (Point2D.Double)point.get(0); |
|
437 |
//FShape nuevoShp; |
|
438 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
439 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
440 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
441 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
442 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
443 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
444 |
// Attributes |
|
445 |
/*for (int j=0;j<nAtt;j++) { |
|
446 |
String[] attributes = new String[2]; |
|
447 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
448 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
449 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
450 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
451 |
} |
|
452 |
}*/ |
|
453 |
addShape(pline3d, auxRow); |
|
454 |
} else if (entity.getType()==0x1) { |
|
455 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT"); |
|
456 |
Point2D p = (Point2D)data.getValue(); |
|
457 |
FPoint2D point = createPoint(p); |
|
458 |
//pto = (Point2D.Double)point.get(0); |
|
459 |
//FShape nuevoShp; |
|
460 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
461 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
462 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
463 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
464 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
465 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
466 |
// Attributes |
|
467 |
/*for (int j=0;j<nAtt;j++) { |
|
468 |
String[] attributes = new String[2]; |
|
469 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
470 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
471 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
472 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
473 |
} |
|
474 |
}*/ |
|
475 |
addShape(point, auxRow); |
|
476 |
} else if (entity.getType()==0x4) { |
|
477 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("NAME"); |
|
478 |
String blockName = (String)data.getValue(); |
|
479 |
//addingToBlock = true; |
|
480 |
//pto = (Point2D.Double)point.get(0); |
|
481 |
//FShape nuevoShp; |
|
482 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
483 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
484 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
485 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
486 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
487 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
488 |
// Attributes |
|
489 |
/*for (int j=0;j<nAtt;j++) { |
|
490 |
String[] attributes = new String[2]; |
|
491 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
492 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
493 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
494 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
495 |
} |
|
496 |
}*/ |
|
497 |
//addShape(point, auxRow); |
|
498 |
} else if (entity.getType()==0x5) { |
|
499 |
//addingToBlock = false; |
|
500 |
//pto = (Point2D.Double)point.get(0); |
|
501 |
//FShape nuevoShp; |
|
502 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
503 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
504 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
505 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
506 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
507 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
508 |
// Attributes |
|
509 |
/*for (int j=0;j<nAtt;j++) { |
|
510 |
String[] attributes = new String[2]; |
|
511 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
512 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
513 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
514 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
515 |
} |
|
516 |
}*/ |
|
517 |
//addShape(point, auxRow); |
|
518 |
/*} else if (entity.getType()==0x30) { |
|
519 |
//addingToBlock = false; |
|
520 |
//pto = (Point2D.Double)point.get(0); |
|
521 |
//FShape nuevoShp; |
|
522 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
523 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
524 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
525 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
526 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
527 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/ |
|
528 |
// Attributes |
|
529 |
/*for (int j=0;j<nAtt;j++) { |
|
530 |
String[] attributes = new String[2]; |
|
531 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
532 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
533 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
534 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
535 |
} |
|
536 |
}*/ |
|
537 |
//addShape(point, auxRow); |
|
538 |
/*} else if (entity.getType()==0x31) { |
|
539 |
//addingToBlock = false; |
|
540 |
//pto = (Point2D.Double)point.get(0); |
|
541 |
//FShape nuevoShp; |
|
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()==0x7) { |
|
559 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT"); |
|
560 |
Point2D p = (Point2D)data.getValue(); |
|
561 |
FPoint2D point = createPoint(p); |
|
562 |
//pto = (Point2D.Double)point.get(0); |
|
563 |
//FShape nuevoShp; |
|
564 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
565 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
566 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
567 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
568 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
569 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/ |
|
570 |
// Attributes |
|
571 |
/*for (int j=0;j<nAtt;j++) { |
|
572 |
String[] attributes = new String[2]; |
|
573 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
574 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
575 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
576 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
577 |
} |
|
578 |
}*/ |
|
579 |
//addShape(point, auxRow); |
|
580 |
} else if (entity.getType()==0x2C) { |
|
581 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT"); |
|
582 |
double[] coord = (double[])data.getValue(); |
|
583 |
Point2D p = new Point2D.Double(coord[0], coord[1]); |
|
584 |
FPoint2D point = createPoint(p); |
|
585 |
//pto = (Point2D.Double)point.get(0); |
|
586 |
//FShape nuevoShp; |
|
587 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
588 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
589 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
590 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
591 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
592 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
593 |
// Attributes |
|
594 |
/*for (int j=0;j<nAtt;j++) { |
|
595 |
String[] attributes = new String[2]; |
|
596 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
597 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
598 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
599 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
600 |
} |
|
601 |
}*/ |
|
602 |
addShape(point, auxRow); |
|
603 |
} else if (entity.getType()==0x1F) { |
|
604 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CORNER1"); |
|
605 |
double[] coord = (double[])data.getValue(); |
|
606 |
Point2D p1 = new Point2D.Double(coord[0], coord[1]); |
|
607 |
data = entity.getDwgObjectSpecificDataItem("CORNER2"); |
|
608 |
coord = (double[])data.getValue(); |
|
609 |
Point2D p2 = new Point2D.Double(coord[0], coord[1]); |
|
610 |
data = entity.getDwgObjectSpecificDataItem("CORNER3"); |
|
611 |
coord = (double[])data.getValue(); |
|
612 |
Point2D p3 = new Point2D.Double(coord[0], coord[1]); |
|
613 |
data = entity.getDwgObjectSpecificDataItem("CORNER4"); |
|
614 |
coord = (double[])data.getValue(); |
|
615 |
Point2D p4 = new Point2D.Double(coord[0], coord[1]); |
|
616 |
//FPolygon2D solid = createSolid(new Point2D[]{p1, p2, p3, p4}); |
|
617 |
FPolygon2D solid = createSolid(new Point2D[]{p1, p2, p4, p3}); |
|
618 |
//FPolyline2D solid = createLwPolyline(new Point2D[]{p1, p2, p3, p4, p1}); |
|
619 |
//pto = (Point2D.Double)point.get(0); |
|
620 |
//FShape nuevoShp; |
|
621 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
622 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
623 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
624 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
625 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
626 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
627 |
// Attributes |
|
628 |
/*for (int j=0;j<nAtt;j++) { |
|
629 |
String[] attributes = new String[2]; |
|
630 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
631 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
632 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
633 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
634 |
} |
|
635 |
}*/ |
|
636 |
addShape(solid, auxRow); |
|
637 |
} else if (entity.getType()==0x24) { |
|
638 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("SCENARIO"); |
|
639 |
int sc = ((Integer)data.getValue()).intValue(); |
|
640 |
if (sc==1) { |
|
641 |
data = entity.getDwgObjectSpecificDataItem("CONTROL_POINTS"); |
|
642 |
} else if (sc==2) { |
|
643 |
data = entity.getDwgObjectSpecificDataItem("FIT_POINTS"); |
|
644 |
} |
|
645 |
double[][] vertices = (double[][])data.getValue(); |
|
646 |
Point2D[] pts = new Point2D[vertices.length]; |
|
647 |
double[] pt = new double[2]; |
|
648 |
for (int j=0; j<vertices.length; j++) { |
|
649 |
pt = (double[])vertices[j]; |
|
650 |
pts[j] = new Point2D.Double(pt[0], pt[1]); |
|
651 |
} |
|
652 |
FPolyline2D spline = createLwPolyline(pts); |
|
653 |
//pto = (Point2D.Double)point.get(0); |
|
654 |
//FShape nuevoShp; |
|
655 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
656 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
657 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
658 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
659 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
660 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
661 |
// Attributes |
|
662 |
/*for (int j=0;j<nAtt;j++) { |
|
663 |
String[] attributes = new String[2]; |
|
664 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
665 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
666 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
667 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
668 |
} |
|
669 |
}*/ |
|
670 |
addShape(spline, auxRow); |
|
671 |
} else if (dwg.getDxfNames().size()>0) { |
|
672 |
int type = 0; |
|
673 |
for (int j=0; j<dwg.getDxfNames().size(); j++) { |
|
674 |
String dxfName = ((DxfName)dwg.getDxfNames().get(j)).getDxfName(); |
|
675 |
if (dxfName.equals("LWPOLYLINE")) { |
|
676 |
type = ((DxfName)dwg.getDxfNames().get(j)).getKey(); |
|
677 |
break; |
|
678 |
} |
|
679 |
} |
|
680 |
if (entity.getType()==type) { |
|
681 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("VERTICES"); |
|
682 |
Vector vertices = (Vector)data.getValue(); |
|
683 |
Point2D[] pts = new Point2D[vertices.size()]; |
|
684 |
double[] pt = new double[2]; |
|
685 |
for (int j=0; j<vertices.size(); j++) { |
|
686 |
pt = (double[])vertices.get(j); |
|
687 |
pts[j] = new Point2D.Double(pt[0], pt[1]); |
|
688 |
} |
|
689 |
FPolyline2D lwpline = createLwPolyline(pts); |
|
690 |
//pto = (Point2D.Double)point.get(0); |
|
691 |
//FShape nuevoShp; |
|
692 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
693 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
|
694 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
|
695 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0); |
|
696 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
|
697 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
698 |
// Attributes |
|
699 |
/*for (int j=0;j<nAtt;j++) { |
|
700 |
String[] attributes = new String[2]; |
|
701 |
attributes = (String[])featureMaker.getAttributes().get(j); |
|
702 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1])); |
|
703 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
|
704 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0]))); |
|
705 |
} |
|
706 |
}*/ |
|
707 |
addShape(lwpline, auxRow); |
|
708 |
} |
|
709 |
} else { |
|
710 |
System.out.println("Detectado dwgObject pendiente de implementar"); |
|
711 |
} |
|
712 |
} |
|
713 |
|
|
714 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
|
715 |
defaultLegend.setFieldName("Color"); |
|
716 |
defaultLegend.setLabelField("Text"); |
|
717 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType())); |
|
718 |
defaultLegend.getDefaultSymbol().setShapeVisible(false); |
|
719 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false); |
|
720 |
defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9)); |
|
721 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK); |
|
722 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
|
723 |
defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
|
724 |
defaultLegend.getDefaultSymbol().setSize(3); |
|
725 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true); |
|
726 |
|
|
727 |
defaultLegend.setLabelHeightField("HeightText"); |
|
728 |
defaultLegend.setLabelRotationField("RotationText"); |
|
729 |
|
|
730 |
ObjectDriver rs = this; |
|
731 |
IntValue clave; |
|
732 |
FSymbol theSymbol = null; |
|
733 |
|
|
734 |
try { |
|
735 |
// TODO: Provisional hasta que cambiemos los s?mbolos. |
|
736 |
/* BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB); |
|
737 |
Graphics2D big = bi.createGraphics(); |
|
738 |
Color color=new Color(0,0,0,0); |
|
739 |
big.setBackground(color); |
|
740 |
big.clearRect(0, 0, 5, 5); |
|
741 |
Paint fillProv = null; |
|
742 |
Rectangle2D rProv = new Rectangle(); |
|
743 |
rProv.setFrame(0, 0,5,5); |
|
744 |
fillProv = new TexturePaint(bi,rProv); */ |
|
745 |
|
|
746 |
for (long j = 0; j < rs.getRowCount(); j++) |
|
747 |
{ |
|
748 |
clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR); |
|
749 |
if (defaultLegend.getSymbolByValue(clave) == null) |
|
750 |
{ |
|
751 |
theSymbol = new FSymbol(getShapeType()); |
|
752 |
theSymbol.setDescription(clave.toString()); |
|
753 |
theSymbol.setColor(AcadColor.getColor(clave.getValue())); |
|
754 |
// theSymbol.setFill(fillProv); |
|
755 |
// 050202, jmorell: Asigna los colores de Autocad a los bordes |
|
756 |
// de los pol?gonos. |
|
757 |
theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue())); |
|
758 |
|
|
759 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
|
760 |
theSymbol.setSize(3); |
|
761 |
theSymbol.setSizeInPixels(true); |
|
762 |
|
|
763 |
defaultLegend.addSymbol(clave, theSymbol); |
|
764 |
} |
|
765 |
} // for |
|
766 |
} catch (DriverException e) { |
|
767 |
e.printStackTrace(); |
|
768 |
throw new IOException("Error al poner la leyenda por defecto en el Dwg"); |
|
769 |
} |
|
770 |
} |
|
771 |
|
|
772 |
/** |
|
773 |
* En principio exportamos a FPolyline2D, despues estudiaremos la conveniencia |
|
774 |
* de exportar a FPolygon2D, o a las dos cosas ... |
|
775 |
* Esta clase construye el circle del mismo modo que en DxfFeatureMaker. |
|
776 |
* Se podr?a renombrar esta clase a createCircleFeature y a?adir otra |
|
777 |
* createCircleEntity ... |
|
778 |
* La parte de creaci?n de la FPolyline2D est? sacada del DxfMemoryDriver ... |
|
779 |
* @param center |
|
780 |
* @param radius |
|
781 |
* @return |
|
782 |
*/ |
|
783 |
private FPolyline2D createCircle(Point2D c, double r) { |
|
784 |
Point2D[] pts = new Point2D[360]; |
|
785 |
int angulo = 0; |
|
786 |
for (angulo=0; angulo<360; angulo++) { |
|
787 |
pts[angulo] = new Point2D.Double(c.getX(), c.getY()); |
|
788 |
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)); |
|
789 |
} |
|
790 |
GeneralPathX genPathX = new GeneralPathX(); |
|
791 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
|
792 |
for (int i=1; i<pts.length; i++) { |
|
793 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
|
794 |
} |
|
795 |
return new FPolyline2D(genPathX); |
|
796 |
} |
|
797 |
|
|
798 |
/** |
|
799 |
* Como createCircle ... |
|
800 |
* @param c |
|
801 |
* @param r |
|
802 |
* @param sa |
|
803 |
* @param ea |
|
804 |
* @return |
|
805 |
*/ |
|
806 |
private FPolyline2D createArc(Point2D c, double r, double sa, double ea) { |
|
807 |
int isa = (int)sa; |
|
808 |
int iea = (int)ea; |
|
809 |
double angulo; |
|
810 |
Point2D[] pts; |
|
811 |
if (sa <= ea) { |
|
812 |
pts = new Point2D[(iea-isa)+2]; |
|
813 |
angulo = sa; |
|
814 |
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)); |
|
815 |
for (int i=1; i<=(iea-isa)+1; i++) { |
|
816 |
angulo = (double)(isa+i); |
|
817 |
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)); |
|
818 |
} |
|
819 |
angulo = ea; |
|
820 |
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)); |
|
821 |
} else { |
|
822 |
pts = new Point2D[(360-isa)+iea+2]; |
|
823 |
angulo = sa; |
|
824 |
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)); |
|
825 |
for (int i=1; i<=(360-isa); i++) { |
|
826 |
angulo = (double)(isa+i); |
|
827 |
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)); |
|
828 |
} |
|
829 |
for (int i=(360-isa)+1; i<=(360-isa)+iea; i++) { |
|
830 |
angulo = (double)(i-(360-isa)); |
|
831 |
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)); |
|
832 |
} |
|
833 |
angulo = ea; |
|
834 |
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)); |
|
835 |
} |
|
836 |
GeneralPathX genPathX = new GeneralPathX(); |
|
837 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
|
838 |
for (int i=1; i<pts.length; i++) { |
|
839 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
|
840 |
} |
|
841 |
return new FPolyline2D(genPathX); |
|
842 |
} |
|
843 |
|
|
844 |
/** |
|
845 |
* Los nombres de estos m?todos pueden cambiarse por otros m?s apropiados, por |
|
846 |
* ejemplo: |
|
847 |
* createLine --> dwgLineToFPolyline2D ... ?mejor as?? ... |
|
848 |
* @param p1 |
|
849 |
* @param p2 |
|
850 |
* @return |
|
851 |
*/ |
|
852 |
private FPolyline2D createLine(Point2D p1, Point2D p2) { |
|
853 |
Point2D[] pts = new Point2D[]{p1, p2}; |
|
854 |
GeneralPathX genPathX = new GeneralPathX(); |
|
855 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
|
856 |
for (int i=1; i<pts.length; i++) { |
|
857 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
|
858 |
} |
|
859 |
return new FPolyline2D(genPathX); |
|
860 |
} |
|
861 |
|
|
862 |
private FPoint2D createPoint(Point2D p) { |
|
863 |
return new FPoint2D(p.getX(), p.getY()); |
|
864 |
} |
|
865 |
|
|
866 |
private FPolyline2D createLwPolyline(Point2D[] pts) { |
|
867 |
GeneralPathX genPathX = new GeneralPathX(); |
|
868 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
|
869 |
for (int i=1; i<pts.length; i++) { |
|
870 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
|
871 |
} |
|
872 |
return new FPolyline2D(genPathX); |
|
873 |
} |
|
874 |
|
|
875 |
private FPolyline2D createPolyline2D(Point2D[] pts) { |
|
876 |
//System.out.println("pts.length = " + pts.length); |
|
877 |
GeneralPathX genPathX = new GeneralPathX(); |
|
878 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
|
879 |
for (int i=1; i<pts.length; i++) { |
|
880 |
//System.out.println("pts[i].getX() = " + pts[i].getX()); |
|
881 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
|
882 |
} |
|
883 |
return new FPolyline2D(genPathX); |
|
884 |
} |
|
885 |
|
|
886 |
private FPolygon2D createSolid(Point2D[] pts) { |
|
887 |
GeneralPathX genPathX = new GeneralPathX(); |
|
888 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
|
889 |
for (int i=1; i<pts.length; i++) { |
|
890 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
|
891 |
} |
|
892 |
genPathX.closePath(); |
|
893 |
return new FPolygon2D(genPathX); |
|
894 |
} |
|
895 |
|
|
896 |
private int calculateVertexNumber(int[] firstVertexHandle, int[] lastVertexHandle) { |
|
897 |
if (firstVertexHandle.length==3 && lastVertexHandle.length==3) { |
|
898 |
return (lastVertexHandle[2]-firstVertexHandle[2]+1); |
|
899 |
} else if (firstVertexHandle.length==4 && lastVertexHandle.length==4) { |
|
900 |
if (firstVertexHandle[2]==lastVertexHandle[2]) { |
|
901 |
System.out.println("firstVertexHandle[2]" + firstVertexHandle[2]); |
|
902 |
System.out.println("firstVertexHandle[3]" + firstVertexHandle[3]); |
|
903 |
System.out.println("lastVertexHandle[2]" + lastVertexHandle[2]); |
|
904 |
System.out.println("lastVertexHandle[3]" + lastVertexHandle[3]); |
|
905 |
System.out.println("lastVertexHandle[3]-firstVertexHandle[3]+1 = " + (lastVertexHandle[3]-firstVertexHandle[3]+1)); |
|
906 |
return (lastVertexHandle[3]-firstVertexHandle[3]+1); |
|
907 |
} else { |
|
908 |
int vn = 0; |
|
909 |
int aux = 255-firstVertexHandle[3]; |
|
910 |
int aux2 = lastVertexHandle[3]; |
|
911 |
int aux3 = (lastVertexHandle[2]-firstVertexHandle[2]-1)*255; |
|
912 |
vn = aux + aux2 + aux3; |
|
913 |
System.out.println("vn = " + vn); |
|
914 |
return vn-1; |
|
915 |
} |
|
916 |
} else if (firstVertexHandle.length==3 && lastVertexHandle.length==4) { |
|
917 |
int vn = 0; |
|
918 |
int aux = 255-firstVertexHandle[2]; |
|
919 |
int aux2 = lastVertexHandle[3]; |
|
920 |
vn = aux + aux2; |
|
921 |
return vn-1; |
|
922 |
} else { |
|
923 |
System.out.println("ERROR: firstVertexHandle y lastVertexHandle tienen tama?os inesperados"); |
|
924 |
return 0; |
|
925 |
} |
|
926 |
} |
|
927 |
|
|
928 |
/* (non-Javadoc) |
|
929 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File) |
|
930 |
*/ |
|
931 |
public boolean accept(File f) { |
|
932 |
return f.getName().toUpperCase().endsWith("DWG"); |
|
933 |
} |
|
934 |
|
|
935 |
/* (non-Javadoc) |
|
936 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType() |
|
937 |
*/ |
|
938 |
public int getShapeType() { |
|
939 |
return FShape.MULTI; |
|
940 |
} |
|
941 |
|
|
942 |
/* (non-Javadoc) |
|
943 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName() |
|
944 |
*/ |
|
945 |
public String getName() { |
|
946 |
return "gvSIG DWG Memory Driver"; |
|
947 |
} |
|
948 |
|
|
949 |
/* (non-Javadoc) |
|
950 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend() |
|
951 |
*/ |
|
952 |
public Legend getDefaultLegend() { |
|
953 |
return defaultLegend; |
|
954 |
} |
|
955 |
|
|
956 |
/* (non-Javadoc) |
|
957 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes() |
|
958 |
*/ |
|
959 |
public DriverAttributes getDriverAttributes() { |
|
960 |
return attr; |
|
961 |
} |
|
962 |
|
|
963 |
} |
|
0 | 964 |
Also available in: Unified diff