root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dwg / DwgMemoryDriver.java @ 1853
History | View | Annotate | Download (42.7 KB)
1 |
/*
|
---|---|
2 |
* Created on 14-abr-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.fmap.drivers.dwg; |
45 |
|
46 |
import java.awt.Color; |
47 |
import java.awt.Font; |
48 |
import java.awt.geom.Point2D; |
49 |
import java.io.File; |
50 |
import java.io.IOException; |
51 |
import java.util.ArrayList; |
52 |
import java.util.Vector; |
53 |
|
54 |
import net.jmorell.jdwglib.dwg.DwgFile; |
55 |
import net.jmorell.jdwglib.dwg.DwgObject; |
56 |
import net.jmorell.jdwglib.dwg.DwgObjectSpecificDataItem; |
57 |
import net.jmorell.jdwglib.dwg.DxfName; |
58 |
|
59 |
import org.cresques.px.dxf.AcadColor; |
60 |
|
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 |
//int vertexNumber = (lastVertexHandle-firstVertexHandle)+1;
|
285 |
int vertexNumber = calculateVertexNumber(firstVertexHandle, lastVertexHandle);
|
286 |
//System.out.println("vertexNumber = " + vertexNumber);
|
287 |
Point2D[] pts = new Point2D[vertexNumber]; |
288 |
double[] pt = new double[2]; |
289 |
|
290 |
// Buscando el primer v?rtice ...
|
291 |
for (int j=0;j<dwgObjects.size();j++) { |
292 |
DwgObject obj = (DwgObject)dwgObjects.get(j); |
293 |
Vector handle = obj.getHandle();
|
294 |
if (handle.size()==firstVertexHandle.length) {
|
295 |
if (((Integer)handle.get(handle.size()-2)).intValue()==firstVertexHandle[handle.size()-2] && ((Integer)handle.get(handle.size()-1)).intValue()==firstVertexHandle[handle.size()-1]) { |
296 |
for (int k=0; k<vertexNumber; k++) { |
297 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k); |
298 |
data = vertex.getDwgObjectSpecificDataItem("POINT");
|
299 |
pt = (double[])data.getValue(); |
300 |
pts[k] = new Point2D.Double(pt[0], pt[1]); |
301 |
} |
302 |
} |
303 |
} |
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 |
pts[k] = new Point2D.Double(pt[0], pt[1]);
|
312 |
}
|
313 |
}
|
314 |
} else if (handle.size()==4) {
|
315 |
if (((Integer)handle.get(2)).intValue()==firstVertexHandle[2] && ((Integer)handle.get(3)).intValue()==firstVertexHandle[3]) {
|
316 |
for (int k=0; k<vertexNumber; k++) {
|
317 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
|
318 |
data = vertex.getDwgObjectSpecificDataItem("POINT");
|
319 |
pt = (double[])data.getValue();
|
320 |
pts[k] = new Point2D.Double(pt[0], pt[1]);
|
321 |
}
|
322 |
}
|
323 |
} else {
|
324 |
//
|
325 |
}
|
326 |
}*/
|
327 |
} |
328 |
Point2D[] newPts = new Point2D[pts.length]; |
329 |
if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) { |
330 |
newPts = pts; |
331 |
} else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) { |
332 |
newPts = new Point2D[pts.length+1]; |
333 |
for (int j=0;j<pts.length;j++) { |
334 |
newPts[j] = pts[j]; |
335 |
} |
336 |
newPts[pts.length] = pts[0];
|
337 |
} |
338 |
FPolyline2D pline = createPolyline2D(newPts); |
339 |
//pto = (Point2D.Double)point.get(0);
|
340 |
//FShape nuevoShp;
|
341 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
342 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
343 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
344 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
345 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
346 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
347 |
// Attributes
|
348 |
/*for (int j=0;j<nAtt;j++) {
|
349 |
String[] attributes = new String[2];
|
350 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
351 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
352 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
353 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
354 |
}
|
355 |
}*/
|
356 |
addShape(pline, auxRow); |
357 |
} else if (entity.getType()==0x10) { |
358 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CLOSED_FLAGS");
|
359 |
int flags = ((Integer)data.getValue()).intValue(); |
360 |
data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE");
|
361 |
int[] firstVertexHandle = (int[])data.getValue(); |
362 |
data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE");
|
363 |
int[] lastVertexHandle = (int[])data.getValue(); |
364 |
data = entity.getDwgObjectSpecificDataItem("SEQEND_HANDLE");
|
365 |
int[] seqendHandle = (int[])data.getValue(); |
366 |
//int vertexNumber = (lastVertexHandle-firstVertexHandle)+1;
|
367 |
int vertexNumber = calculateVertexNumber(firstVertexHandle, lastVertexHandle);
|
368 |
Point2D[] pts = new Point2D[vertexNumber]; |
369 |
double[] pt = new double[2]; |
370 |
|
371 |
// Buscando el primer v?rtice ...
|
372 |
for (int j=0;j<dwgObjects.size();j++) { |
373 |
DwgObject v = (DwgObject)dwgObjects.get(j); |
374 |
Vector handle = v.getHandle();
|
375 |
if (((Integer)handle.get(handle.size()-2)).intValue()==firstVertexHandle[handle.size()-2] && ((Integer)handle.get(handle.size()-1)).intValue()==firstVertexHandle[handle.size()-1]) { |
376 |
for (int k=0; k<vertexNumber; k++) { |
377 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k); |
378 |
data = vertex.getDwgObjectSpecificDataItem("POINT");
|
379 |
pt = (double[])data.getValue(); |
380 |
pts[k] = new Point2D.Double(pt[0], pt[1]); |
381 |
} |
382 |
} |
383 |
/*if (handle.size()==4) {
|
384 |
if (((Integer)handle.get(2)).intValue()==firstVertexHandle[2] && ((Integer)handle.get(3)).intValue()==firstVertexHandle[3]) {
|
385 |
for (int k=0; k<vertexNumber; k++) {
|
386 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
|
387 |
data = vertex.getDwgObjectSpecificDataItem("POINT");
|
388 |
pt = (double[])data.getValue();
|
389 |
pts[k] = new Point2D.Double(pt[0], pt[1]);
|
390 |
}
|
391 |
}
|
392 |
} else if (handle.size()==3) {
|
393 |
if (((Integer)handle.get(2)).intValue()==firstVertexHandle[2]) {
|
394 |
for (int k=0; k<vertexNumber; k++) {
|
395 |
DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
|
396 |
data = vertex.getDwgObjectSpecificDataItem("POINT");
|
397 |
pt = (double[])data.getValue();
|
398 |
pts[k] = new Point2D.Double(pt[0], pt[1]);
|
399 |
}
|
400 |
}
|
401 |
}*/
|
402 |
} |
403 |
Point2D[] newPts = new Point2D[pts.length]; |
404 |
if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) { |
405 |
newPts = pts; |
406 |
} else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) { |
407 |
newPts = new Point2D[pts.length+1]; |
408 |
for (int j=0;j<pts.length;j++) { |
409 |
newPts[j] = pts[j]; |
410 |
} |
411 |
newPts[pts.length] = pts[0];
|
412 |
} |
413 |
FPolyline2D pline3d = createPolyline2D(newPts); |
414 |
//pto = (Point2D.Double)point.get(0);
|
415 |
//FShape nuevoShp;
|
416 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
417 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
418 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
419 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
420 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
421 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
422 |
// Attributes
|
423 |
/*for (int j=0;j<nAtt;j++) {
|
424 |
String[] attributes = new String[2];
|
425 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
426 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
427 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
428 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
429 |
}
|
430 |
}*/
|
431 |
addShape(pline3d, auxRow); |
432 |
} else if (entity.getType()==0x1) { |
433 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
|
434 |
Point2D p = (Point2D)data.getValue(); |
435 |
FPoint2D point = createPoint(p); |
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(point, auxRow); |
454 |
} else if (entity.getType()==0x4) { |
455 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("NAME");
|
456 |
String blockName = (String)data.getValue(); |
457 |
//addingToBlock = true;
|
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()==0x5) { |
477 |
//addingToBlock = false;
|
478 |
//pto = (Point2D.Double)point.get(0);
|
479 |
//FShape nuevoShp;
|
480 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
481 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
482 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
483 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
484 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
485 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
486 |
// Attributes
|
487 |
/*for (int j=0;j<nAtt;j++) {
|
488 |
String[] attributes = new String[2];
|
489 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
490 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
491 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
492 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
493 |
}
|
494 |
}*/
|
495 |
//addShape(point, auxRow);
|
496 |
/*} else if (entity.getType()==0x30) {
|
497 |
//addingToBlock = false;
|
498 |
//pto = (Point2D.Double)point.get(0);
|
499 |
//FShape nuevoShp;
|
500 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
501 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
|
502 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
|
503 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
504 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
505 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/
|
506 |
// Attributes
|
507 |
/*for (int j=0;j<nAtt;j++) {
|
508 |
String[] attributes = new String[2];
|
509 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
510 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
511 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
512 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
513 |
}
|
514 |
}*/
|
515 |
//addShape(point, auxRow);
|
516 |
/*} else if (entity.getType()==0x31) {
|
517 |
//addingToBlock = false;
|
518 |
//pto = (Point2D.Double)point.get(0);
|
519 |
//FShape nuevoShp;
|
520 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
521 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
|
522 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
|
523 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
524 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
525 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/
|
526 |
// Attributes
|
527 |
/*for (int j=0;j<nAtt;j++) {
|
528 |
String[] attributes = new String[2];
|
529 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
530 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
531 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
532 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
533 |
}
|
534 |
}*/
|
535 |
//addShape(point, auxRow);
|
536 |
/*} else if (entity.getType()==0x7) {
|
537 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
|
538 |
Point2D p = (Point2D)data.getValue();
|
539 |
FPoint2D point = createPoint(p);
|
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()==0x2C) { |
559 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
|
560 |
double[] coord = (double[])data.getValue(); |
561 |
Point2D p = new Point2D.Double(coord[0], coord[1]); |
562 |
FPoint2D point = createPoint(p); |
563 |
//pto = (Point2D.Double)point.get(0);
|
564 |
//FShape nuevoShp;
|
565 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
566 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
567 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
568 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
569 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
570 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
571 |
// Attributes
|
572 |
/*for (int j=0;j<nAtt;j++) {
|
573 |
String[] attributes = new String[2];
|
574 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
575 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
576 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
577 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
578 |
}
|
579 |
}*/
|
580 |
addShape(point, auxRow); |
581 |
} else if (entity.getType()==0x1F) { |
582 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CORNER1");
|
583 |
double[] coord = (double[])data.getValue(); |
584 |
Point2D p1 = new Point2D.Double(coord[0], coord[1]); |
585 |
data = entity.getDwgObjectSpecificDataItem("CORNER2");
|
586 |
coord = (double[])data.getValue(); |
587 |
Point2D p2 = new Point2D.Double(coord[0], coord[1]); |
588 |
data = entity.getDwgObjectSpecificDataItem("CORNER3");
|
589 |
coord = (double[])data.getValue(); |
590 |
Point2D p3 = new Point2D.Double(coord[0], coord[1]); |
591 |
data = entity.getDwgObjectSpecificDataItem("CORNER4");
|
592 |
coord = (double[])data.getValue(); |
593 |
Point2D p4 = new Point2D.Double(coord[0], coord[1]); |
594 |
//FPolygon2D solid = createSolid(new Point2D[]{p1, p2, p3, p4});
|
595 |
FPolygon2D solid = createSolid(new Point2D[]{p1, p2, p4, p3}); |
596 |
//FPolyline2D solid = createLwPolyline(new Point2D[]{p1, p2, p3, p4, p1});
|
597 |
//pto = (Point2D.Double)point.get(0);
|
598 |
//FShape nuevoShp;
|
599 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
600 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
601 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
602 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
603 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
604 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
605 |
// Attributes
|
606 |
/*for (int j=0;j<nAtt;j++) {
|
607 |
String[] attributes = new String[2];
|
608 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
609 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
610 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
611 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
612 |
}
|
613 |
}*/
|
614 |
addShape(solid, auxRow); |
615 |
} else if (entity.getType()==0x24) { |
616 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("SCENARIO");
|
617 |
int sc = ((Integer)data.getValue()).intValue(); |
618 |
if (sc==1) { |
619 |
data = entity.getDwgObjectSpecificDataItem("CONTROL_POINTS");
|
620 |
} else if (sc==2) { |
621 |
data = entity.getDwgObjectSpecificDataItem("FIT_POINTS");
|
622 |
} |
623 |
double[][] vertices = (double[][])data.getValue(); |
624 |
Point2D[] pts = new Point2D[vertices.length]; |
625 |
double[] pt = new double[2]; |
626 |
for (int j=0; j<vertices.length; j++) { |
627 |
pt = (double[])vertices[j]; |
628 |
pts[j] = new Point2D.Double(pt[0], pt[1]); |
629 |
} |
630 |
FPolyline2D spline = createLwPolyline(pts); |
631 |
//pto = (Point2D.Double)point.get(0);
|
632 |
//FShape nuevoShp;
|
633 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
634 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
635 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
636 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
637 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
638 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
639 |
// Attributes
|
640 |
/*for (int j=0;j<nAtt;j++) {
|
641 |
String[] attributes = new String[2];
|
642 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
643 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
644 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
645 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
646 |
}
|
647 |
}*/
|
648 |
addShape(spline, auxRow); |
649 |
} else if (dwg.getDxfNames().size()>0) { |
650 |
int type = 0; |
651 |
for (int j=0; j<dwg.getDxfNames().size(); j++) { |
652 |
String dxfName = ((DxfName)dwg.getDxfNames().get(j)).getDxfName();
|
653 |
if (dxfName.equals("LWPOLYLINE")) { |
654 |
type = ((DxfName)dwg.getDxfNames().get(j)).getKey(); |
655 |
break;
|
656 |
} |
657 |
} |
658 |
if (entity.getType()==type) {
|
659 |
DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("VERTICES");
|
660 |
Vector vertices = (Vector)data.getValue(); |
661 |
Point2D[] pts = new Point2D[vertices.size()]; |
662 |
double[] pt = new double[2]; |
663 |
for (int j=0; j<vertices.size(); j++) { |
664 |
pt = (double[])vertices.get(j); |
665 |
pts[j] = new Point2D.Double(pt[0], pt[1]); |
666 |
} |
667 |
FPolyline2D lwpline = createLwPolyline(pts); |
668 |
//pto = (Point2D.Double)point.get(0);
|
669 |
//FShape nuevoShp;
|
670 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
671 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
672 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
673 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
674 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
675 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
676 |
// Attributes
|
677 |
/*for (int j=0;j<nAtt;j++) {
|
678 |
String[] attributes = new String[2];
|
679 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
680 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
681 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
682 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
683 |
}
|
684 |
}*/
|
685 |
addShape(lwpline, auxRow); |
686 |
} |
687 |
} else {
|
688 |
System.out.println("Detectado dwgObject pendiente de implementar"); |
689 |
} |
690 |
} |
691 |
|
692 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
693 |
defaultLegend.setFieldName("Color");
|
694 |
defaultLegend.setLabelField("Text");
|
695 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
|
696 |
defaultLegend.getDefaultSymbol().setShapeVisible(false);
|
697 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
|
698 |
defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9)); |
699 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
|
700 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
701 |
defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
702 |
defaultLegend.getDefaultSymbol().setSize(3);
|
703 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true);
|
704 |
|
705 |
defaultLegend.setLabelHeightField("HeightText");
|
706 |
defaultLegend.setLabelRotationField("RotationText");
|
707 |
|
708 |
ObjectDriver rs = this;
|
709 |
IntValue clave; |
710 |
FSymbol theSymbol = null;
|
711 |
|
712 |
try {
|
713 |
// TODO: Provisional hasta que cambiemos los s?mbolos.
|
714 |
/* BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
|
715 |
Graphics2D big = bi.createGraphics();
|
716 |
Color color=new Color(0,0,0,0);
|
717 |
big.setBackground(color);
|
718 |
big.clearRect(0, 0, 5, 5);
|
719 |
Paint fillProv = null;
|
720 |
Rectangle2D rProv = new Rectangle();
|
721 |
rProv.setFrame(0, 0,5,5);
|
722 |
fillProv = new TexturePaint(bi,rProv); */
|
723 |
|
724 |
for (long j = 0; j < rs.getRowCount(); j++) |
725 |
{ |
726 |
clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR); |
727 |
if (defaultLegend.getSymbolByValue(clave) == null) |
728 |
{ |
729 |
theSymbol = new FSymbol(getShapeType());
|
730 |
theSymbol.setDescription(clave.toString()); |
731 |
theSymbol.setColor(AcadColor.getColor(clave.getValue())); |
732 |
// theSymbol.setFill(fillProv);
|
733 |
// 050202, jmorell: Asigna los colores de Autocad a los bordes
|
734 |
// de los pol?gonos.
|
735 |
theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue())); |
736 |
|
737 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
738 |
theSymbol.setSize(3);
|
739 |
theSymbol.setSizeInPixels(true);
|
740 |
|
741 |
defaultLegend.addSymbol(clave, theSymbol); |
742 |
} |
743 |
} // for
|
744 |
} catch (DriverException e) {
|
745 |
e.printStackTrace(); |
746 |
throw new IOException("Error al poner la leyenda por defecto en el Dwg"); |
747 |
} |
748 |
} |
749 |
|
750 |
/**
|
751 |
* En principio exportamos a FPolyline2D, despues estudiaremos la conveniencia
|
752 |
* de exportar a FPolygon2D, o a las dos cosas ...
|
753 |
* Esta clase construye el circle del mismo modo que en DxfFeatureMaker.
|
754 |
* Se podr?a renombrar esta clase a createCircleFeature y a?adir otra
|
755 |
* createCircleEntity ...
|
756 |
* La parte de creaci?n de la FPolyline2D est? sacada del DxfMemoryDriver ...
|
757 |
* @param center
|
758 |
* @param radius
|
759 |
* @return
|
760 |
*/
|
761 |
private FPolyline2D createCircle(Point2D c, double r) { |
762 |
Point2D[] pts = new Point2D[360]; |
763 |
int angulo = 0; |
764 |
for (angulo=0; angulo<360; angulo++) { |
765 |
pts[angulo] = new Point2D.Double(c.getX(), c.getY()); |
766 |
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)); |
767 |
} |
768 |
GeneralPathX genPathX = new GeneralPathX();
|
769 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
770 |
for (int i=1; i<pts.length; i++) { |
771 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
772 |
} |
773 |
return new FPolyline2D(genPathX); |
774 |
} |
775 |
|
776 |
/**
|
777 |
* Como createCircle ...
|
778 |
* @param c
|
779 |
* @param r
|
780 |
* @param sa
|
781 |
* @param ea
|
782 |
* @return
|
783 |
*/
|
784 |
private FPolyline2D createArc(Point2D c, double r, double sa, double ea) { |
785 |
int isa = (int)sa; |
786 |
int iea = (int)ea; |
787 |
double angulo;
|
788 |
Point2D[] pts; |
789 |
if (sa <= ea) {
|
790 |
pts = new Point2D[(iea-isa)+2]; |
791 |
angulo = sa; |
792 |
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)); |
793 |
for (int i=1; i<=(iea-isa)+1; i++) { |
794 |
angulo = (double)(isa+i);
|
795 |
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)); |
796 |
} |
797 |
angulo = ea; |
798 |
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)); |
799 |
} else {
|
800 |
pts = new Point2D[(360-isa)+iea+2]; |
801 |
angulo = sa; |
802 |
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)); |
803 |
for (int i=1; i<=(360-isa); i++) { |
804 |
angulo = (double)(isa+i);
|
805 |
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)); |
806 |
} |
807 |
for (int i=(360-isa)+1; i<=(360-isa)+iea; i++) { |
808 |
angulo = (double)(i-(360-isa)); |
809 |
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)); |
810 |
} |
811 |
angulo = ea; |
812 |
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)); |
813 |
} |
814 |
GeneralPathX genPathX = new GeneralPathX();
|
815 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
816 |
for (int i=1; i<pts.length; i++) { |
817 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
818 |
} |
819 |
return new FPolyline2D(genPathX); |
820 |
} |
821 |
|
822 |
/**
|
823 |
* Los nombres de estos m?todos pueden cambiarse por otros m?s apropiados, por
|
824 |
* ejemplo:
|
825 |
* createLine --> dwgLineToFPolyline2D ... ?mejor as?? ...
|
826 |
* @param p1
|
827 |
* @param p2
|
828 |
* @return
|
829 |
*/
|
830 |
private FPolyline2D createLine(Point2D p1, Point2D p2) { |
831 |
Point2D[] pts = new Point2D[]{p1, p2}; |
832 |
GeneralPathX genPathX = new GeneralPathX();
|
833 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
834 |
for (int i=1; i<pts.length; i++) { |
835 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
836 |
} |
837 |
return new FPolyline2D(genPathX); |
838 |
} |
839 |
|
840 |
private FPoint2D createPoint(Point2D p) { |
841 |
return new FPoint2D(p.getX(), p.getY()); |
842 |
} |
843 |
|
844 |
private FPolyline2D createLwPolyline(Point2D[] pts) { |
845 |
GeneralPathX genPathX = new GeneralPathX();
|
846 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
847 |
for (int i=1; i<pts.length; i++) { |
848 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
849 |
} |
850 |
return new FPolyline2D(genPathX); |
851 |
} |
852 |
|
853 |
private FPolyline2D createPolyline2D(Point2D[] pts) { |
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 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 |
/*System.out.println("firstVertexHandle[0]" + firstVertexHandle[0]);
|
874 |
System.out.println("firstVertexHandle[1]" + firstVertexHandle[1]);
|
875 |
System.out.println("firstVertexHandle[2]" + firstVertexHandle[2]);
|
876 |
System.out.println("firstVertexHandle[3]" + firstVertexHandle[3]);
|
877 |
System.out.println("lastVertexHandle[0]" + lastVertexHandle[0]);
|
878 |
System.out.println("lastVertexHandle[1]" + lastVertexHandle[1]);
|
879 |
System.out.println("lastVertexHandle[2]" + lastVertexHandle[2]);
|
880 |
System.out.println("lastVertexHandle[3]" + lastVertexHandle[3]);*/
|
881 |
if (firstVertexHandle.length==lastVertexHandle.length) {
|
882 |
if (firstVertexHandle[firstVertexHandle.length-2]==lastVertexHandle[firstVertexHandle.length-2]) { |
883 |
return (lastVertexHandle[firstVertexHandle.length-1]-firstVertexHandle[firstVertexHandle.length-1]+1); |
884 |
} else {
|
885 |
int aux = 255-firstVertexHandle[firstVertexHandle.length-1]+1; |
886 |
int aux2 = lastVertexHandle[firstVertexHandle.length-1]+1; |
887 |
int aux3 = (lastVertexHandle[firstVertexHandle.length-2]-firstVertexHandle[firstVertexHandle.length-2]-1)*255; |
888 |
int vn = aux + aux2 + aux3;
|
889 |
return vn;
|
890 |
} |
891 |
// Fallar? en polil?neas de m?s de 500 v?rtices ...
|
892 |
} else if (firstVertexHandle.length==(lastVertexHandle.length-1)) { |
893 |
int aux = 255-firstVertexHandle[firstVertexHandle.length-1]+1; |
894 |
int aux2 = lastVertexHandle[firstVertexHandle.length]+1; |
895 |
int vn = aux + aux2;
|
896 |
return vn;
|
897 |
} else {
|
898 |
System.out.println("ERROR: firstVertexHandle y lastVertexHandle tienen tama?os inesperados"); |
899 |
return 0; |
900 |
} |
901 |
/*if (firstVertexHandle.length==3 && lastVertexHandle.length==3) {
|
902 |
return (lastVertexHandle[2]-firstVertexHandle[2]+1);
|
903 |
} else if (firstVertexHandle.length==4 && lastVertexHandle.length==4) {
|
904 |
if (firstVertexHandle[2]==lastVertexHandle[2]) {
|
905 |
return (lastVertexHandle[3]-firstVertexHandle[3]+1);
|
906 |
} else {
|
907 |
int vn = 0;
|
908 |
int aux = 255-firstVertexHandle[3]+1;
|
909 |
int aux2 = lastVertexHandle[3]+1;
|
910 |
int aux3 = (lastVertexHandle[2]-firstVertexHandle[2]-1)*255;
|
911 |
vn = aux + aux2 + aux3;
|
912 |
return vn;
|
913 |
}
|
914 |
} else if (firstVertexHandle.length==3 && lastVertexHandle.length==4) {
|
915 |
int vn = 0;
|
916 |
int aux = 255-firstVertexHandle[2]+1;
|
917 |
int aux2 = lastVertexHandle[3]+1;
|
918 |
vn = aux + aux2;
|
919 |
//System.out.println("vn = " + vn);
|
920 |
return vn;
|
921 |
} else {
|
922 |
System.out.println("ERROR: firstVertexHandle y lastVertexHandle tienen tama?os inesperados");
|
923 |
return 0;
|
924 |
}*/
|
925 |
} |
926 |
|
927 |
/* (non-Javadoc)
|
928 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
929 |
*/
|
930 |
public boolean accept(File f) { |
931 |
return f.getName().toUpperCase().endsWith("DWG"); |
932 |
} |
933 |
|
934 |
/* (non-Javadoc)
|
935 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
936 |
*/
|
937 |
public int getShapeType() { |
938 |
return FShape.MULTI;
|
939 |
} |
940 |
|
941 |
/* (non-Javadoc)
|
942 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
943 |
*/
|
944 |
public String getName() { |
945 |
return "gvSIG DWG Memory Driver"; |
946 |
} |
947 |
|
948 |
/* (non-Javadoc)
|
949 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
950 |
*/
|
951 |
public Legend getDefaultLegend() {
|
952 |
return defaultLegend;
|
953 |
} |
954 |
|
955 |
/* (non-Javadoc)
|
956 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
957 |
*/
|
958 |
public DriverAttributes getDriverAttributes() {
|
959 |
return attr;
|
960 |
} |
961 |
|
962 |
} |