svn-gvsig-desktop / trunk / extensions / extDwg / src / es / iver / gvsig / drivers / dwg / DwgMemoryDriver.java @ 2773
History | View | Annotate | Download (68.2 KB)
1 |
/*
|
---|---|
2 |
* Created on 14-abr-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
* DwgMemoryDriver 0.2. Driver del formato DWG para gvSIG
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package es.iver.gvsig.drivers.dwg; |
46 |
|
47 |
import java.awt.Color; |
48 |
import java.awt.Font; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.io.File; |
51 |
import java.io.IOException; |
52 |
import java.util.ArrayList; |
53 |
import java.util.Vector; |
54 |
|
55 |
import net.jmorell.javacad.util.AcadColor; |
56 |
import net.jmorell.javacad.util.GisModelCurveCalculator; |
57 |
import net.jmorell.jdwglib.dwg.DwgFile; |
58 |
import net.jmorell.jdwglib.dwg.DwgObject; |
59 |
import net.jmorell.jdwglib.dwg.objects.DwgArc; |
60 |
import net.jmorell.jdwglib.dwg.objects.DwgAttdef; |
61 |
import net.jmorell.jdwglib.dwg.objects.DwgAttrib; |
62 |
import net.jmorell.jdwglib.dwg.objects.DwgBlock; |
63 |
import net.jmorell.jdwglib.dwg.objects.DwgBlockControl; |
64 |
import net.jmorell.jdwglib.dwg.objects.DwgBlockHeader; |
65 |
import net.jmorell.jdwglib.dwg.objects.DwgCircle; |
66 |
import net.jmorell.jdwglib.dwg.objects.DwgEndblk; |
67 |
import net.jmorell.jdwglib.dwg.objects.DwgInsert; |
68 |
import net.jmorell.jdwglib.dwg.objects.DwgLine; |
69 |
import net.jmorell.jdwglib.dwg.objects.DwgLwPolyline; |
70 |
import net.jmorell.jdwglib.dwg.objects.DwgMText; |
71 |
import net.jmorell.jdwglib.dwg.objects.DwgPoint; |
72 |
import net.jmorell.jdwglib.dwg.objects.DwgPolyline2D; |
73 |
import net.jmorell.jdwglib.dwg.objects.DwgPolyline3D; |
74 |
import net.jmorell.jdwglib.dwg.objects.DwgSolid; |
75 |
import net.jmorell.jdwglib.dwg.objects.DwgSpline; |
76 |
import net.jmorell.jdwglib.dwg.objects.DwgText; |
77 |
import net.jmorell.jdwglib.dwg.objects.DwgEllipse; |
78 |
|
79 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
80 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
81 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
82 |
import com.hardcode.gdbms.engine.values.IntValue; |
83 |
import com.hardcode.gdbms.engine.values.Value; |
84 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
85 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
86 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
87 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
88 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
89 |
import com.iver.cit.gvsig.fmap.core.FPolyline3D; |
90 |
import com.iver.cit.gvsig.fmap.core.FShape; |
91 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
92 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
93 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
94 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
95 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
96 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
97 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
98 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
99 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
100 |
|
101 |
/**
|
102 |
* Driver that allows gvSig to read files in DWG format
|
103 |
* Using this driver, a gvSig user can manipulate part of the information contained in
|
104 |
* a DWG file
|
105 |
* This driver load the Dwg file in memory
|
106 |
* This driver uses jdwglib
|
107 |
*
|
108 |
* @author jmorell
|
109 |
*/
|
110 |
public class DwgMemoryDriver extends MemoryDriver implements WithDefaultLegend { |
111 |
private final int ID_FIELD_ID=0; |
112 |
private final int ID_FIELD_FSHAPE=1; |
113 |
private final int ID_FIELD_ENTITY=2; |
114 |
private final int ID_FIELD_LAYER=3; |
115 |
private final int ID_FIELD_COLOR=4; |
116 |
private final int ID_FIELD_ELEVATION=5; |
117 |
private final int ID_FIELD_THICKNESS=6; |
118 |
private final int ID_FIELD_TEXT=7; |
119 |
private final int ID_FIELD_HEIGHTTEXT=8; |
120 |
private final int ID_FIELD_ROTATIONTEXT=9; |
121 |
|
122 |
VectorialUniqueValueLegend defaultLegend; |
123 |
private String path; |
124 |
private File m_Fich; |
125 |
|
126 |
private DwgFile dwg;
|
127 |
private Vector dwgObjects; |
128 |
private DriverAttributes attr = new DriverAttributes(); |
129 |
|
130 |
/* (non-Javadoc)
|
131 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
132 |
*/
|
133 |
public void open(File f) throws IOException { |
134 |
m_Fich = f; |
135 |
} |
136 |
|
137 |
/**
|
138 |
* This method load the DWG file in memory.
|
139 |
* First, it will be necessary to create a DwgFile object with the DWG file path
|
140 |
* as the argument
|
141 |
* Second, the method read of DwgFile allows to read the objects inside the DWG
|
142 |
* file
|
143 |
* Third, it will be necessary to process some DWG objects like Layers or Polylines
|
144 |
* Fourth, we can read the objects Vector, and convert this objects to the FMap
|
145 |
* object model
|
146 |
* And finally, the testDwg3D method test if this DWG has elevation informacion
|
147 |
*/
|
148 |
public void initialize() throws IOException { |
149 |
//System.out.println("Driver actualizado");
|
150 |
float heightText = 10; |
151 |
|
152 |
attr.setLoadedInMemory(true);
|
153 |
|
154 |
dwg = new DwgFile(m_Fich.getAbsolutePath());
|
155 |
long t1 = System.currentTimeMillis(); |
156 |
dwg.read(); |
157 |
long t2 = System.currentTimeMillis(); |
158 |
System.out.println("Tiempo empleado por la librer?a en leer el fichero dwg = " + (t2-t1)); |
159 |
t1 = System.currentTimeMillis();
|
160 |
dwg.initializeLayerTable(); |
161 |
dwg.calculateGisModelDwgPolylines(); |
162 |
dwg.applyExtrusions(); |
163 |
t2 = System.currentTimeMillis();
|
164 |
System.out.println("Tiempo empleado por la librer?a en tratar el fichero dwg = " + (t2-t1)); |
165 |
dwgObjects = dwg.getDwgObjects(); |
166 |
dwg.testDwg3D(); |
167 |
|
168 |
// TODO: Atributos extra de los objectos
|
169 |
//int nAtt = featureMaker.getAttributes().size();
|
170 |
|
171 |
// Campos de las MemoryLayer:
|
172 |
//Value[] auxRow = new Value[9+nAtt];
|
173 |
Value[] auxRow = new Value[10]; |
174 |
ArrayList arrayFields = new ArrayList(); |
175 |
arrayFields.add("ID");
|
176 |
arrayFields.add("FShape");
|
177 |
arrayFields.add("Entity");
|
178 |
arrayFields.add("Layer");
|
179 |
arrayFields.add("Color");
|
180 |
arrayFields.add("Elevation");
|
181 |
arrayFields.add("Thickness");
|
182 |
arrayFields.add("Text");
|
183 |
arrayFields.add("HeightText");
|
184 |
arrayFields.add("RotationText");
|
185 |
/*for (int i=0;i<nAtt;i++) {
|
186 |
String att[] = new String[2];
|
187 |
att = (String[])featureMaker.getAttributes().get(i);
|
188 |
arrayFields.add(att[0]);
|
189 |
}*/
|
190 |
|
191 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
192 |
|
193 |
t1 = System.currentTimeMillis();
|
194 |
|
195 |
boolean addingToBlock = false; |
196 |
|
197 |
for (int i=0;i<dwgObjects.size();i++) { |
198 |
|
199 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
|
200 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
|
201 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
202 |
|
203 |
DwgObject entity = (DwgObject)dwgObjects.get(i); |
204 |
if (entity instanceof DwgArc && !addingToBlock) { |
205 |
//System.out.println("Encuentra un Arc ...");
|
206 |
double[] c = ((DwgArc)entity).getCenter(); |
207 |
Point2D center = new Point2D.Double(c[0], c[1]); |
208 |
double radius = ((DwgArc)entity).getRadius();
|
209 |
double initAngle = Math.toDegrees(((DwgArc)entity).getInitAngle()); |
210 |
double endAngle = Math.toDegrees(((DwgArc)entity).getEndAngle()); |
211 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelArc(center, radius, initAngle, endAngle); |
212 |
FPolyline2D arcc; |
213 |
if (dwg.isDwg3DFile()) {
|
214 |
double[][] arc3D = new double[arc.length][3]; |
215 |
for (int j=0;j<arc.length;j++) { |
216 |
arc3D[j][0] = arc[j].getX();
|
217 |
arc3D[j][1] = arc[j].getY();
|
218 |
arc3D[j][2] = c[2]; |
219 |
} |
220 |
arcc = points3DToFPolyline3D(arc3D); |
221 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
222 |
} else {
|
223 |
arcc = points2DToFPolyline2D(arc); |
224 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
225 |
} |
226 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
227 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Arc")); |
228 |
String layerName = dwg.getLayerName(entity);
|
229 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
230 |
int color = entity.getColor();
|
231 |
int colorByLayer = dwg.getColorByLayer(entity);
|
232 |
// TODO: if (color==0) color ByBlock
|
233 |
if (color==256) color = colorByLayer; |
234 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
235 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
|
236 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
237 |
// Attributes
|
238 |
/*for (int j=0;j<nAtt;j++) {
|
239 |
String[] attributes = new String[2];
|
240 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
241 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
242 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
243 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
244 |
}
|
245 |
}*/
|
246 |
addShape(arcc, auxRow); |
247 |
} else if (entity instanceof DwgEllipse && !addingToBlock) { |
248 |
//System.out.println("Encuentra una Ellipse ...");
|
249 |
double[] c = ((DwgEllipse)entity).getCenter(); |
250 |
Point2D center = new Point2D.Double(c[0], c[1]); |
251 |
double[] majorAxisVector = ((DwgEllipse)entity).getMajorAxisVector(); |
252 |
Point2D mav = new Point2D.Double(majorAxisVector[0], majorAxisVector[1]); |
253 |
double axisRatio = ((DwgEllipse)entity).getAxisRatio();
|
254 |
double initAngle = Math.toDegrees(((DwgEllipse)entity).getInitAngle()); |
255 |
double endAngle = Math.toDegrees(((DwgEllipse)entity).getEndAngle()); |
256 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelEllipse(center, mav, axisRatio, initAngle, endAngle); |
257 |
FPolyline2D arcc; |
258 |
if (dwg.isDwg3DFile()) {
|
259 |
double[][] arc3D = new double[arc.length][3]; |
260 |
for (int j=0;j<arc.length;j++) { |
261 |
arc3D[j][0] = arc[j].getX();
|
262 |
arc3D[j][1] = arc[j].getY();
|
263 |
arc3D[j][2] = c[2]; |
264 |
} |
265 |
arcc = points3DToFPolyline3D(arc3D); |
266 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
267 |
} else {
|
268 |
arcc = points2DToFPolyline2D(arc); |
269 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
270 |
} |
271 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
272 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Ellipse")); |
273 |
String layerName = dwg.getLayerName(entity);
|
274 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
275 |
int color = entity.getColor();
|
276 |
int colorByLayer = dwg.getColorByLayer(entity);
|
277 |
// TODO: if (color==0) color ByBlock
|
278 |
if (color==256) color = colorByLayer; |
279 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
280 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
|
281 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
282 |
// Attributes
|
283 |
/*for (int j=0;j<nAtt;j++) {
|
284 |
String[] attributes = new String[2];
|
285 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
286 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
287 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
288 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
289 |
}
|
290 |
}*/
|
291 |
addShape(arcc, auxRow); |
292 |
} else if (entity instanceof DwgCircle && !addingToBlock) { |
293 |
//System.out.println("Encuentra un Circle ...");
|
294 |
double[] c = ((DwgCircle)entity).getCenter(); |
295 |
Point2D center = new Point2D.Double(c[0], c[1]); |
296 |
double radius = ((DwgCircle)entity).getRadius();
|
297 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelCircle(center, radius); |
298 |
FPolyline2D arcc; |
299 |
if (dwg.isDwg3DFile()) {
|
300 |
double[][] arc3D = new double[arc.length][3]; |
301 |
for (int j=0;j<arc.length;j++) { |
302 |
arc3D[j][0] = arc[j].getX();
|
303 |
arc3D[j][1] = arc[j].getY();
|
304 |
arc3D[j][2] = c[2]; |
305 |
} |
306 |
arcc = points3DToFPolyline3D(arc3D); |
307 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
308 |
} else {
|
309 |
arcc = points2DToFPolyline2D(arc); |
310 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
311 |
} |
312 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
313 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Circle")); |
314 |
String layerName = dwg.getLayerName(entity);
|
315 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
316 |
int color = entity.getColor();
|
317 |
int colorByLayer = dwg.getColorByLayer(entity);
|
318 |
//if (color==0) color ByBlock
|
319 |
if (color==256) color = colorByLayer; |
320 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
321 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
|
322 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
323 |
// Attributes
|
324 |
/*for (int j=0;j<nAtt;j++) {
|
325 |
String[] attributes = new String[2];
|
326 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
327 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
328 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
329 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
330 |
}
|
331 |
}*/
|
332 |
addShape(arcc, auxRow); |
333 |
} else if (entity instanceof DwgPolyline2D && !addingToBlock) { |
334 |
//System.out.println("Encuentra una Polyline2D ...");
|
335 |
Point2D[] points = ((DwgPolyline2D)entity).getPts(); |
336 |
double elev = ((DwgPolyline2D)entity).getElevation();
|
337 |
FPolyline2D pline; |
338 |
if (points!=null) { |
339 |
if (dwg.isDwg3DFile()) {
|
340 |
double[][] pline3D = new double[points.length][3]; |
341 |
for (int j=0;j<points.length;j++) { |
342 |
pline3D[j][0] = points[j].getX();
|
343 |
pline3D[j][1] = points[j].getY();
|
344 |
pline3D[j][2] = elev;
|
345 |
} |
346 |
pline = points3DToFPolyline3D(pline3D); |
347 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
348 |
} else {
|
349 |
pline = points2DToFPolyline2D(points); |
350 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
351 |
} |
352 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
353 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline2D")); |
354 |
String layerName = dwg.getLayerName(entity);
|
355 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
356 |
int color = entity.getColor();
|
357 |
int colorByLayer = dwg.getColorByLayer(entity);
|
358 |
//if (color==0) color ByBlock
|
359 |
if (color==256) color = colorByLayer; |
360 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
361 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
362 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
363 |
// Attributes
|
364 |
/*for (int j=0;j<nAtt;j++) {
|
365 |
String[] attributes = new String[2];
|
366 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
367 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
368 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
369 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
370 |
}
|
371 |
}*/
|
372 |
addShape(pline, auxRow); |
373 |
} |
374 |
} else if (entity instanceof DwgPolyline3D && !addingToBlock) { |
375 |
//System.out.println("Encuentra una Polyline3D ...");
|
376 |
double[][] points3D = ((DwgPolyline3D)entity).getPts(); |
377 |
FPolyline2D pline; |
378 |
if (points3D!=null) { |
379 |
if (dwg.isDwg3DFile()) {
|
380 |
double[][] pline3D = new double[points3D.length][3]; |
381 |
pline = points3DToFPolyline3D(points3D); |
382 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
383 |
} else {
|
384 |
Point2D[] points2D = new Point2D[points3D.length]; |
385 |
for (int j=0;j<points3D.length;j++) { |
386 |
points2D[j] = new Point2D.Double(points3D[j][0], points3D[j][1]); |
387 |
} |
388 |
pline = points2DToFPolyline2D(points2D); |
389 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
390 |
} |
391 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
392 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline3D")); |
393 |
String layerName = dwg.getLayerName(entity);
|
394 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
395 |
int color = entity.getColor();
|
396 |
int colorByLayer = dwg.getColorByLayer(entity);
|
397 |
//if (color==0) color ByBlock
|
398 |
if (color==256) color = colorByLayer; |
399 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
400 |
boolean constantElevation = true; |
401 |
for (int j=0;j<points3D.length;j++) { |
402 |
if (points3D[j][2]!=points3D[0][2]) { |
403 |
constantElevation = false;
|
404 |
break;
|
405 |
} |
406 |
} |
407 |
if (constantElevation) auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(points3D[0][2]); |
408 |
else auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
409 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
410 |
// Attributes
|
411 |
/*for (int j=0;j<nAtt;j++) {
|
412 |
String[] attributes = new String[2];
|
413 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
414 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
415 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
416 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
417 |
}
|
418 |
}*/
|
419 |
addShape(pline, auxRow); |
420 |
} |
421 |
} else if (entity instanceof DwgLwPolyline && !addingToBlock) { |
422 |
//System.out.println("Encuentra una Lwpolyline ...");
|
423 |
Point2D[] pts = ((DwgLwPolyline)entity).getVertices(); |
424 |
double elev = ((DwgLwPolyline)entity).getElevation();
|
425 |
if (pts!=null) { |
426 |
FPolyline2D lwpline; |
427 |
if (dwg.isDwg3DFile()) {
|
428 |
double[][] pline3D = new double[pts.length][3]; |
429 |
for (int j=0;j<pts.length;j++) { |
430 |
pline3D[j][0] = pts[j].getX();
|
431 |
pline3D[j][1] = pts[j].getY();
|
432 |
pline3D[j][2] = elev;
|
433 |
} |
434 |
lwpline = points3DToFPolyline3D(pline3D); |
435 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
436 |
} else {
|
437 |
lwpline = points2DToFPolyline2D(pts); |
438 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
439 |
} |
440 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
441 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("LwPolyline")); |
442 |
String layerName = dwg.getLayerName(entity);
|
443 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
444 |
int color = entity.getColor();
|
445 |
int colorByLayer = dwg.getColorByLayer(entity);
|
446 |
//if (color==0) color ByBlock
|
447 |
if (color==256) color = colorByLayer; |
448 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
449 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
450 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
451 |
// Attributes
|
452 |
/*for (int j=0;j<nAtt;j++) {
|
453 |
String[] attributes = new String[2];
|
454 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
455 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
456 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
457 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
458 |
}
|
459 |
}*/
|
460 |
addShape(lwpline, auxRow); |
461 |
} |
462 |
} else if (entity instanceof DwgSolid && !addingToBlock) { |
463 |
//System.out.println("Encuentra un Solid ...");
|
464 |
double[] p1 = ((DwgSolid)entity).getCorner1(); |
465 |
double[] p2 = ((DwgSolid)entity).getCorner2(); |
466 |
double[] p3 = ((DwgSolid)entity).getCorner3(); |
467 |
double[] p4 = ((DwgSolid)entity).getCorner4(); |
468 |
double elev = ((DwgSolid)entity).getElevation();
|
469 |
Point2D[] pts = new Point2D[]{new Point2D.Double(p1[0], p1[1]), new Point2D.Double(p2[0], p2[1]), new Point2D.Double(p4[0], p4[1]), new Point2D.Double(p3[0], p3[1]), new Point2D.Double(p1[0], p1[1])}; |
470 |
FPolyline2D solid; |
471 |
if (dwg.isDwg3DFile()) {
|
472 |
double[][] pline3D = new double[pts.length][3]; |
473 |
for (int j=0;j<pts.length;j++) { |
474 |
pline3D[j][0] = pts[j].getX();
|
475 |
pline3D[j][1] = pts[j].getY();
|
476 |
pline3D[j][2] = elev;
|
477 |
} |
478 |
solid = points3DToFPolyline3D(pline3D); |
479 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
480 |
} else {
|
481 |
solid = points2DToFPolyline2D(pts); |
482 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
483 |
} |
484 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
485 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Solid")); |
486 |
String layerName = dwg.getLayerName(entity);
|
487 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
488 |
int color = entity.getColor();
|
489 |
int colorByLayer = dwg.getColorByLayer(entity);
|
490 |
//if (color==0) color ByBlock
|
491 |
if (color==256) color = colorByLayer; |
492 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
493 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
494 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
495 |
// Attributes
|
496 |
/*for (int j=0;j<nAtt;j++) {
|
497 |
String[] attributes = new String[2];
|
498 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
499 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
500 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
501 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
502 |
}
|
503 |
}*/
|
504 |
addShape(solid, auxRow); |
505 |
} else if (entity instanceof DwgLine && !addingToBlock) { |
506 |
//System.out.println("Encuentra una Line ...");
|
507 |
double[] p1 = ((DwgLine)entity).getP1(); |
508 |
Point2D point1 = new Point2D.Double(p1[0], p1[1]); |
509 |
double[] p2 = ((DwgLine)entity).getP2(); |
510 |
Point2D point2 = new Point2D.Double(p2[0], p2[1]); |
511 |
Point2D[] lin = new Point2D[]{point1, point2}; |
512 |
FPolyline2D line; |
513 |
if (dwg.isDwg3DFile() && !((DwgLine)entity).isZflag()) {
|
514 |
double[][] lin3D = new double[2][3]; |
515 |
lin3D[0][0] = lin[0].getX(); |
516 |
lin3D[0][1] = lin[0].getY(); |
517 |
lin3D[0][2] = p1[2]; |
518 |
lin3D[1][0] = lin[1].getX(); |
519 |
lin3D[1][1] = lin[1].getY(); |
520 |
lin3D[1][2] = p2[2]; |
521 |
line = points3DToFPolyline3D(lin3D); |
522 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
523 |
} else if (dwg.isDwg3DFile() && ((DwgLine)entity).isZflag()) { |
524 |
double[][] lin3D = new double[2][3]; |
525 |
lin3D[0][0] = lin[0].getX(); |
526 |
lin3D[0][1] = lin[0].getY(); |
527 |
lin3D[0][2] = 0.0; |
528 |
lin3D[1][0] = lin[1].getX(); |
529 |
lin3D[1][1] = lin[1].getY(); |
530 |
lin3D[1][2] = 0.0; |
531 |
line = points3DToFPolyline3D(lin3D); |
532 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
533 |
} else {
|
534 |
line = points2DToFPolyline2D(lin); |
535 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
536 |
} |
537 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
538 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Line")); |
539 |
String layerName = dwg.getLayerName(entity);
|
540 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
541 |
int color = entity.getColor();
|
542 |
int colorByLayer = dwg.getColorByLayer(entity);
|
543 |
//if (color==0) color ByBlock
|
544 |
if (color==256) color = colorByLayer; |
545 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
546 |
if (!((DwgLine)entity).isZflag()) {
|
547 |
if (p1[2]==p2[2]) auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p1[2]); |
548 |
else auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
549 |
} else {
|
550 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
551 |
} |
552 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
553 |
// Attributes
|
554 |
/*for (int j=0;j<nAtt;j++) {
|
555 |
String[] attributes = new String[2];
|
556 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
557 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
558 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
559 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
560 |
}
|
561 |
}*/
|
562 |
addShape(line, auxRow); |
563 |
} else if (entity instanceof DwgPoint && !addingToBlock) { |
564 |
//System.out.println("Encuentra un Point ...");
|
565 |
double[] p = ((DwgPoint)entity).getPoint(); |
566 |
FPoint2D point; |
567 |
if (dwg.isDwg3DFile()) {
|
568 |
point = new FPoint3D(p[0], p[1], p[2]); |
569 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
570 |
} else {
|
571 |
point = new FPoint2D(p[0], p[1]); |
572 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
573 |
} |
574 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
575 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Point")); |
576 |
String layerName = dwg.getLayerName(entity);
|
577 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
578 |
int color = entity.getColor();
|
579 |
int colorByLayer = dwg.getColorByLayer(entity);
|
580 |
//if (color==0) color ByBlock
|
581 |
if (color==256) color = colorByLayer; |
582 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
583 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
|
584 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
585 |
// Attributes
|
586 |
/*for (int j=0;j<nAtt;j++) {
|
587 |
String[] attributes = new String[2];
|
588 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
589 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
590 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
591 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
592 |
}
|
593 |
}*/
|
594 |
addShape(point, auxRow); |
595 |
} else if (entity instanceof DwgInsert && !addingToBlock) { |
596 |
//System.out.println("Encuentra un Insert ...");
|
597 |
double[] p = ((DwgInsert)entity).getInsertionPoint(); |
598 |
Point2D point = new Point2D.Double(p[0], p[1]); |
599 |
FPoint2D fPoint; |
600 |
double[] scale = ((DwgInsert)entity).getScale(); |
601 |
double rot = ((DwgInsert)entity).getRotation();
|
602 |
int blockHandle = ((DwgInsert)entity).getBlockHeaderHandle();
|
603 |
manageInsert(dwgObjects, point, scale, rot, blockHandle, i, auxRow); |
604 |
if (dwg.isDwg3DFile()) {
|
605 |
fPoint = new FPoint3D(p[0], p[1], p[2]); |
606 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
607 |
} else {
|
608 |
fPoint = new FPoint2D(p[0], p[1]); |
609 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
610 |
} |
611 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
612 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Insert")); |
613 |
String layerName = dwg.getLayerName(entity);
|
614 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
615 |
int color = entity.getColor();
|
616 |
int colorByLayer = dwg.getColorByLayer(entity);
|
617 |
//if (color==0) color ByBlock
|
618 |
if (color==256) color = colorByLayer; |
619 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
620 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
|
621 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
622 |
// Attributes
|
623 |
/*for (int j=0;j<nAtt;j++) {
|
624 |
String[] attributes = new String[2];
|
625 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
626 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
627 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
628 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
629 |
}
|
630 |
}*/
|
631 |
addShape(fPoint, auxRow); |
632 |
} else if (entity instanceof DwgMText && !addingToBlock) { |
633 |
//System.out.println("Encuentra un MText ...");
|
634 |
double[] p = ((DwgMText)entity).getInsertionPoint(); |
635 |
FPoint2D fPoint; |
636 |
if (dwg.isDwg3DFile()) {
|
637 |
fPoint = new FPoint3D(p[0], p[1], p[2]); |
638 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
639 |
} else {
|
640 |
fPoint = new FPoint2D(p[0], p[1]); |
641 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
642 |
} |
643 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
644 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("MText")); |
645 |
String layerName = dwg.getLayerName(entity);
|
646 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
647 |
int color = entity.getColor();
|
648 |
int colorByLayer = dwg.getColorByLayer(entity);
|
649 |
//if (color==0) color ByBlock
|
650 |
if (color==256) color = colorByLayer; |
651 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
652 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
|
653 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
654 |
// Attributes
|
655 |
/*for (int j=0;j<nAtt;j++) {
|
656 |
String[] attributes = new String[2];
|
657 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
658 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
659 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
660 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
661 |
}
|
662 |
}*/
|
663 |
addShape(fPoint, auxRow); |
664 |
} else if (entity instanceof DwgAttrib && !addingToBlock) { |
665 |
//System.out.println("Encuentra un Attrib ...");
|
666 |
} else if (entity instanceof DwgText && !addingToBlock) { |
667 |
//System.out.println("Encuentra un Text ...");
|
668 |
Point2D p = ((DwgText)entity).getInsertionPoint();
|
669 |
int dflag = ((DwgText)entity).getDataFlag();
|
670 |
double elev = 0.0; |
671 |
if ((dflag & 0x1)==0) elev = ((DwgText)entity).getElevation(); |
672 |
FPoint2D point; |
673 |
if (dwg.isDwg3DFile()) {
|
674 |
point = new FPoint3D(p.getX(), p.getY(), elev);
|
675 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
676 |
} else {
|
677 |
point = new FPoint2D(p.getX(), p.getY());
|
678 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
679 |
} |
680 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
681 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Text")); |
682 |
String layerName = dwg.getLayerName(entity);
|
683 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
684 |
int color = entity.getColor();
|
685 |
int colorByLayer = dwg.getColorByLayer(entity);
|
686 |
//if (color==0) color ByBlock
|
687 |
if (color==256) color = colorByLayer; |
688 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
689 |
String text = ((DwgText)entity).getText();
|
690 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(text)); |
691 |
heightText = (float)((DwgText)entity).getHeight();
|
692 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText); |
693 |
if ((dflag & 0x8) == 0) { |
694 |
double textRot = ((DwgText)entity).getRotationAngle();
|
695 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(Math.toDegrees(textRot));
|
696 |
} else {
|
697 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
|
698 |
} |
699 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
700 |
double thickness = ((DwgText)entity).getThickness();
|
701 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(thickness); |
702 |
// Attributes
|
703 |
/*for (int j=0;j<nAtt;j++) {
|
704 |
String[] attributes = new String[2];
|
705 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
706 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
707 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
708 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
709 |
}
|
710 |
}*/
|
711 |
addShape(point, auxRow); |
712 |
} else if (entity instanceof DwgBlock) { |
713 |
//System.out.println("Encuentra un Block ...");
|
714 |
addingToBlock = true;
|
715 |
String blockName = ((DwgBlock)entity).getName();
|
716 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
717 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block")); |
718 |
String layerName = dwg.getLayerName(entity);
|
719 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
720 |
int color = entity.getColor();
|
721 |
int colorByLayer = dwg.getColorByLayer(entity);
|
722 |
//if (color==0) color ByBlock
|
723 |
if (color==256) color = colorByLayer; |
724 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
725 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
726 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
727 |
// Attributes
|
728 |
/*for (int j=0;j<nAtt;j++) {
|
729 |
String[] attributes = new String[2];
|
730 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
731 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
732 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
733 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
734 |
}
|
735 |
}*/
|
736 |
//addShape(point, auxRow);
|
737 |
} else if (entity instanceof DwgEndblk) { |
738 |
//System.out.println("Encuentra un Endblk ...");
|
739 |
addingToBlock = false;
|
740 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
741 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("EndBlk")); |
742 |
String layerName = dwg.getLayerName(entity);
|
743 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
744 |
int color = entity.getColor();
|
745 |
int colorByLayer = dwg.getColorByLayer(entity);
|
746 |
//if (color==0) color ByBlock
|
747 |
if (color==256) color = colorByLayer; |
748 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
749 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
750 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
751 |
// Attributes
|
752 |
/*for (int j=0;j<nAtt;j++) {
|
753 |
String[] attributes = new String[2];
|
754 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
755 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
756 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
757 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
758 |
}
|
759 |
}*/
|
760 |
//addShape(point, auxRow);
|
761 |
} else if (entity instanceof DwgBlockControl) { |
762 |
//System.out.println("Encuentra un Block Control Object ...");
|
763 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
764 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Control Object")); |
765 |
String layerName = dwg.getLayerName(entity);
|
766 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
767 |
int color = entity.getColor();
|
768 |
int colorByLayer = dwg.getColorByLayer(entity);
|
769 |
//if (color==0) color ByBlock
|
770 |
if (color==256) color = colorByLayer; |
771 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
772 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
773 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
774 |
// Attributes
|
775 |
/*for (int j=0;j<nAtt;j++) {
|
776 |
String[] attributes = new String[2];
|
777 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
778 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
779 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
780 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
781 |
}
|
782 |
}*/
|
783 |
//addShape(point, auxRow);
|
784 |
} else if (entity instanceof DwgBlockHeader) { |
785 |
//System.out.println("Encuentra un Block Header ...");
|
786 |
addingToBlock = true;
|
787 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
788 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Header")); |
789 |
String layerName = dwg.getLayerName(entity);
|
790 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
791 |
int color = entity.getColor();
|
792 |
int colorByLayer = dwg.getColorByLayer(entity);
|
793 |
//if (color==0) color ByBlock
|
794 |
if (color==256) color = colorByLayer; |
795 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
796 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
797 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
798 |
// Attributes
|
799 |
/*for (int j=0;j<nAtt;j++) {
|
800 |
String[] attributes = new String[2];
|
801 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
802 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
803 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
804 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
805 |
}
|
806 |
}*/
|
807 |
//addShape(point, auxRow);
|
808 |
} else if (entity instanceof DwgAttdef && !addingToBlock) { |
809 |
//System.out.println("Encuentra un Attdef ...");
|
810 |
} else {
|
811 |
//System.out.println("Detectado dwgObject pendiente de implementar");
|
812 |
} |
813 |
} |
814 |
t2 = System.currentTimeMillis();
|
815 |
System.out.println("Tiempo empleado por el driver en importar el contenido del dwg = " + (t2-t1)); |
816 |
|
817 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
818 |
defaultLegend.setFieldName("Color");
|
819 |
defaultLegend.setLabelField("Text");
|
820 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
|
821 |
defaultLegend.getDefaultSymbol().setShapeVisible(false);
|
822 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
|
823 |
defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9)); |
824 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
|
825 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
826 |
defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
827 |
defaultLegend.getDefaultSymbol().setSize(3);
|
828 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true);
|
829 |
|
830 |
defaultLegend.setLabelHeightField("HeightText");
|
831 |
defaultLegend.setLabelRotationField("RotationText");
|
832 |
|
833 |
ObjectDriver rs = this;
|
834 |
IntValue clave; |
835 |
FSymbol theSymbol = null;
|
836 |
|
837 |
try {
|
838 |
// Provisional hasta que cambiemos los s?mbolos.
|
839 |
/* BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
|
840 |
Graphics2D big = bi.createGraphics();
|
841 |
Color color=new Color(0,0,0,0);
|
842 |
big.setBackground(color);
|
843 |
big.clearRect(0, 0, 5, 5);
|
844 |
Paint fillProv = null;
|
845 |
Rectangle2D rProv = new Rectangle();
|
846 |
rProv.setFrame(0, 0,5,5);
|
847 |
fillProv = new TexturePaint(bi,rProv); */
|
848 |
|
849 |
for (long j = 0; j < rs.getRowCount(); j++) |
850 |
{ |
851 |
clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR); |
852 |
if (defaultLegend.getSymbolByValue(clave) == null) |
853 |
{ |
854 |
theSymbol = new FSymbol(getShapeType());
|
855 |
theSymbol.setDescription(clave.toString()); |
856 |
theSymbol.setColor(AcadColor.getColor(clave.getValue())); |
857 |
// theSymbol.setFill(fillProv);
|
858 |
// 050202, jmorell: Asigna los colores de Autocad a los bordes
|
859 |
// de los pol?gonos.
|
860 |
theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue())); |
861 |
|
862 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
863 |
theSymbol.setSize(3);
|
864 |
theSymbol.setSizeInPixels(true);
|
865 |
|
866 |
defaultLegend.addSymbol(clave, theSymbol); |
867 |
} |
868 |
} // for
|
869 |
} catch (DriverException e) {
|
870 |
e.printStackTrace(); |
871 |
throw new IOException("Error al poner la leyenda por defecto en el Dwg"); |
872 |
} |
873 |
} |
874 |
|
875 |
/**
|
876 |
* Method that changes a Point2D array to a FPolyline2D. Is useful to convert a
|
877 |
* polyline given by it points to a FPolyline2D, a polyline in the FMap model
|
878 |
* object
|
879 |
*
|
880 |
* @param pts Array of Point2D that defines the polyline that will be converted in
|
881 |
* a FPolyline2D
|
882 |
* @return FPolyline2D This FPolyline2D is build using the array of Point2D that
|
883 |
* is the argument of the method
|
884 |
*/
|
885 |
private FPolyline2D points2DToFPolyline2D(Point2D[] pts) { |
886 |
GeneralPathX genPathX = new GeneralPathX();
|
887 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
888 |
for (int i=1; i<pts.length; i++) { |
889 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
890 |
} |
891 |
return new FPolyline2D(genPathX); |
892 |
} |
893 |
|
894 |
/**
|
895 |
* Method that changes a Point3D array to a FPolyline3D. Is useful to convert a
|
896 |
* polyline given by it points to a FPolyline3D, a polyline 3D in the FMap model
|
897 |
* object
|
898 |
*
|
899 |
* @param pts Array of Point3D that defines the polyline 3D that will be converted in
|
900 |
* a FPolyline3D
|
901 |
* @return FPolyline3D This FPolyline3D is build using the array of Point3D that
|
902 |
* is the argument of the method
|
903 |
*/
|
904 |
private FPolyline3D points3DToFPolyline3D(double[][] pts) { |
905 |
GeneralPathX genPathX = new GeneralPathX();
|
906 |
genPathX.moveTo(pts[0][0], pts[0][1]); |
907 |
for (int i=1; i<pts.length; i++) { |
908 |
genPathX.lineTo(pts[i][0], pts[i][1]); |
909 |
} |
910 |
double[] elevations = new double[pts.length]; |
911 |
for (int i=0;i<pts.length;i++) { |
912 |
elevations[i] = pts[i][2];
|
913 |
} |
914 |
return new FPolyline3D(genPathX, elevations); |
915 |
} |
916 |
|
917 |
/**
|
918 |
* Method that changes a Point2D array to a FPolygon2D. Is useful to convert a
|
919 |
* polygon given by it points to a FPolygon2D, a polygon in the FMap model
|
920 |
* object
|
921 |
*
|
922 |
* @param pts Array of Point2D that defines the polygon that will be converted in
|
923 |
* a FPolygon2D
|
924 |
* @return FPolygon2D This FPolygon2D is build using the array of Point2D that
|
925 |
* is the argument of the method
|
926 |
*/
|
927 |
private FPolygon2D points2DToFPolygon2D(Point2D[] pts) { |
928 |
GeneralPathX genPathX = new GeneralPathX();
|
929 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
930 |
for (int i=1; i<pts.length; i++) { |
931 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
932 |
} |
933 |
genPathX.closePath(); |
934 |
return new FPolygon2D(genPathX); |
935 |
} |
936 |
|
937 |
private void manageInsert(Vector dwgObjects, Point2D insPoint, double[] scale, double rot, int bHandle, int id, Value[] auxRow) { |
938 |
for (int i=0;i<dwgObjects.size();i++) { |
939 |
DwgObject obj = (DwgObject)dwgObjects.get(i); |
940 |
if (obj instanceof DwgBlockHeader) { |
941 |
int objHandle = ((DwgBlockHeader)obj).getHandle();
|
942 |
if (objHandle==bHandle) {
|
943 |
//System.out.println("Encontrado DwgBlockHeader con handle = " + bHandle);
|
944 |
double[] bPoint = ((DwgBlockHeader)obj).getBasePoint(); |
945 |
String bname = ((DwgBlockHeader)obj).getName();
|
946 |
//System.out.println("Nombre del bloque = " + bname);
|
947 |
if (!bname.startsWith("*")) { |
948 |
int firstObjectHandle = ((DwgBlockHeader)obj).getFirstEntityHandle();
|
949 |
//System.out.println("firstObjectHandle = " + firstObjectHandle);
|
950 |
int lastObjectHandle = ((DwgBlockHeader)obj).getLastEntityHandle();
|
951 |
//System.out.println("lastObjectHandle = " + lastObjectHandle);
|
952 |
DwgBlock block = null;
|
953 |
for (int j=0;j<dwgObjects.size();j++) { |
954 |
DwgObject ent = (DwgObject)dwgObjects.get(j); |
955 |
if (ent instanceof DwgBlock) { |
956 |
String name = ((DwgBlock)ent).getName();
|
957 |
if (bname.equals(name)) {
|
958 |
block = (DwgBlock)ent; |
959 |
//System.out.println("Encontrado DwgBlock con bname = " + bname);
|
960 |
break;
|
961 |
} |
962 |
} |
963 |
} |
964 |
for (int j=0;j<dwgObjects.size();j++) { |
965 |
DwgObject fObj = (DwgObject)dwgObjects.get(j); |
966 |
if (fObj!=null) { |
967 |
int fObjHandle = fObj.getHandle();
|
968 |
if (fObjHandle==firstObjectHandle) {
|
969 |
int k=0; |
970 |
while (true) { |
971 |
//System.out.println("Encontrado elemento " + k + " del bloque");
|
972 |
DwgObject iObj = (DwgObject)dwgObjects.get(j+k); |
973 |
int iObjHandle = iObj.getHandle();
|
974 |
manageBlockEntity(iObj, bPoint, insPoint, scale, rot, block, id, auxRow); |
975 |
k++; |
976 |
if (iObjHandle==lastObjectHandle) break; |
977 |
} |
978 |
} |
979 |
} |
980 |
} |
981 |
break;
|
982 |
} |
983 |
} |
984 |
} |
985 |
} |
986 |
} |
987 |
|
988 |
private void manageBlockEntity(DwgObject entity, double[] bPoint, Point2D insPoint, double[] scale, double rot, DwgObject block, int id, Value[] auxRow) { |
989 |
if (entity instanceof DwgArc) { |
990 |
//System.out.println("Encuentra un arco dentro de un bloque ...");
|
991 |
double[] c = ((DwgArc)entity).getCenter(); |
992 |
Point2D center = new Point2D.Double(c[0], c[1]); |
993 |
double radius = ((DwgArc)entity).getRadius();
|
994 |
double initAngle = Math.toDegrees(((DwgArc)entity).getInitAngle()); |
995 |
double endAngle = Math.toDegrees(((DwgArc)entity).getEndAngle()); |
996 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelArc(center, radius, initAngle, endAngle); |
997 |
for (int i=0;i<arc.length;i++) { |
998 |
Point2D pointAux = new Point2D.Double(arc[i].getX() - bPoint[0], arc[i].getY() - bPoint[1]); |
999 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1000 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1001 |
arc[i] = new Point2D.Double(laX, laY); |
1002 |
} |
1003 |
FPolyline2D arcc; |
1004 |
if (dwg.isDwg3DFile()) {
|
1005 |
double[][] arc3D = new double[arc.length][3]; |
1006 |
for (int j=0;j<arc.length;j++) { |
1007 |
arc3D[j][0] = arc[j].getX();
|
1008 |
arc3D[j][1] = arc[j].getY();
|
1009 |
arc3D[j][2] = c[2]; |
1010 |
} |
1011 |
arcc = points3DToFPolyline3D(arc3D); |
1012 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
1013 |
} else {
|
1014 |
arcc = points2DToFPolyline2D(arc); |
1015 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
1016 |
} |
1017 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(id); |
1018 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Arc")); |
1019 |
String layerName = dwg.getLayerName(entity);
|
1020 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
1021 |
int color = entity.getColor();
|
1022 |
int colorByLayer = dwg.getColorByLayer(entity);
|
1023 |
// TODO: if (color==0) color ByBlock
|
1024 |
if (color==256) color = colorByLayer; |
1025 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
1026 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
|
1027 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
1028 |
// Attributes
|
1029 |
//for (int j=0;j<nAtt;j++) {
|
1030 |
// String[] attributes = new String[2];
|
1031 |
// attributes = (String[])featureMaker.getAttributes().get(j);
|
1032 |
// auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
1033 |
// if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
1034 |
// auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
1035 |
// }
|
1036 |
//}
|
1037 |
addShape(arcc, auxRow); |
1038 |
} else if (entity instanceof DwgCircle) { |
1039 |
//System.out.println("Encuentra un c?rculo dentro de un bloque ...");
|
1040 |
double[] c = ((DwgCircle)entity).getCenter(); |
1041 |
Point2D center = new Point2D.Double(c[0], c[1]); |
1042 |
double radius = ((DwgCircle)entity).getRadius();
|
1043 |
Point2D pointAux = new Point2D.Double(c[0] - bPoint[0], c[1] - bPoint[1]); |
1044 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*(-1)*Math.sin(Math.toRadians(rot))); |
1045 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*Math.cos(Math.toRadians(rot))); |
1046 |
Point2D cen = new Point2D.Double(laX, laY); |
1047 |
radius = radius * scale[0];
|
1048 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelCircle(new Point2D.Double(cen.getX(), cen.getY()), radius); |
1049 |
FPolyline2D arcc; |
1050 |
if (dwg.isDwg3DFile()) {
|
1051 |
double[][] arc3D = new double[arc.length][3]; |
1052 |
for (int j=0;j<arc.length;j++) { |
1053 |
arc3D[j][0] = arc[j].getX();
|
1054 |
arc3D[j][1] = arc[j].getY();
|
1055 |
arc3D[j][2] = c[2]; |
1056 |
} |
1057 |
arcc = points3DToFPolyline3D(arc3D); |
1058 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
1059 |
} else {
|
1060 |
arcc = points2DToFPolyline2D(arc); |
1061 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
1062 |
} |
1063 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(id); |
1064 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Circle")); |
1065 |
String layerName = dwg.getLayerName(entity);
|
1066 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
1067 |
int color = entity.getColor();
|
1068 |
int colorByLayer = dwg.getColorByLayer(entity);
|
1069 |
//if (color==0) color ByBlock
|
1070 |
if (color==256) color = colorByLayer; |
1071 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
1072 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
|
1073 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
1074 |
// Attributes
|
1075 |
/*for (int j=0;j<nAtt;j++) {
|
1076 |
String[] attributes = new String[2];
|
1077 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
1078 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
1079 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
1080 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
1081 |
}
|
1082 |
}*/
|
1083 |
addShape(arcc, auxRow); |
1084 |
} else if (entity instanceof DwgEllipse) { |
1085 |
double[] center = ((DwgEllipse)entity).getCenter(); |
1086 |
double[] majorAxisVector = ((DwgEllipse)entity).getMajorAxisVector(); |
1087 |
double axisRatio = ((DwgEllipse)entity).getAxisRatio();
|
1088 |
double initAngle = Math.toDegrees(((DwgEllipse)entity).getInitAngle()); |
1089 |
double endAngle = Math.toDegrees(((DwgEllipse)entity).getEndAngle()); |
1090 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelEllipse(new Point2D.Double(center[0], center[1]), new Point2D.Double(majorAxisVector[0], majorAxisVector[1]), axisRatio, initAngle, endAngle); |
1091 |
for (int i=0;i<arc.length;i++) { |
1092 |
Point2D pointAux = new Point2D.Double(arc[i].getX() - bPoint[0], arc[i].getY() - bPoint[1]); |
1093 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1094 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1095 |
arc[i] = new Point2D.Double(laX, laY); |
1096 |
} |
1097 |
FPolyline2D arcc; |
1098 |
if (dwg.isDwg3DFile()) {
|
1099 |
double[][] arc3D = new double[arc.length][3]; |
1100 |
for (int j=0;j<arc.length;j++) { |
1101 |
arc3D[j][0] = arc[j].getX();
|
1102 |
arc3D[j][1] = arc[j].getY();
|
1103 |
arc3D[j][2] = center[2]; |
1104 |
} |
1105 |
arcc = points3DToFPolyline3D(arc3D); |
1106 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
1107 |
} else {
|
1108 |
arcc = points2DToFPolyline2D(arc); |
1109 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
1110 |
} |
1111 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(id); |
1112 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Ellipse")); |
1113 |
String layerName = dwg.getLayerName(entity);
|
1114 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
1115 |
int color = entity.getColor();
|
1116 |
int colorByLayer = dwg.getColorByLayer(entity);
|
1117 |
// TODO: if (color==0) color ByBlock
|
1118 |
if (color==256) color = colorByLayer; |
1119 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
1120 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(center[2]);
|
1121 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
1122 |
// Attributes
|
1123 |
//for (int j=0;j<nAtt;j++) {
|
1124 |
// String[] attributes = new String[2];
|
1125 |
// attributes = (String[])featureMaker.getAttributes().get(j);
|
1126 |
// auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
1127 |
// if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
1128 |
// auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
1129 |
// }
|
1130 |
//}
|
1131 |
addShape(arcc, auxRow); |
1132 |
} else if (entity instanceof DwgLine) { |
1133 |
//System.out.println("Encuentra una l?nea dentro de un bloque ...");
|
1134 |
double[] p1 = ((DwgLine)entity).getP1(); |
1135 |
double[] p2 = ((DwgLine)entity).getP2(); |
1136 |
Point2D pointAux = new Point2D.Double(p1[0] - bPoint[0], p1[1] - bPoint[1]); |
1137 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1138 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1139 |
Point2D pp1 = new Point2D.Double(laX, laY); |
1140 |
pointAux = new Point2D.Double(p2[0] - bPoint[0], p2[1] - bPoint[1]); |
1141 |
laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1142 |
laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1143 |
Point2D pp2 = new Point2D.Double(laX, laY); |
1144 |
Point2D[] lin = new Point2D[]{pp1, pp2}; |
1145 |
FPolyline2D line; |
1146 |
if (dwg.isDwg3DFile() && !((DwgLine)entity).isZflag()) {
|
1147 |
double[][] lin3D = new double[2][3]; |
1148 |
lin3D[0][0] = lin[0].getX(); |
1149 |
lin3D[0][1] = lin[0].getY(); |
1150 |
lin3D[0][2] = p1[2]; |
1151 |
lin3D[1][0] = lin[1].getX(); |
1152 |
lin3D[1][1] = lin[1].getY(); |
1153 |
lin3D[1][2] = p2[2]; |
1154 |
line = points3DToFPolyline3D(lin3D); |
1155 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
1156 |
} else if (dwg.isDwg3DFile() && ((DwgLine)entity).isZflag()) { |
1157 |
double[][] lin3D = new double[2][3]; |
1158 |
lin3D[0][0] = lin[0].getX(); |
1159 |
lin3D[0][1] = lin[0].getY(); |
1160 |
lin3D[0][2] = 0.0; |
1161 |
lin3D[1][0] = lin[1].getX(); |
1162 |
lin3D[1][1] = lin[1].getY(); |
1163 |
lin3D[1][2] = 0.0; |
1164 |
line = points3DToFPolyline3D(lin3D); |
1165 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
1166 |
} else {
|
1167 |
line = points2DToFPolyline2D(lin); |
1168 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
1169 |
} |
1170 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(id); |
1171 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Line")); |
1172 |
String layerName = dwg.getLayerName(entity);
|
1173 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
1174 |
int color = entity.getColor();
|
1175 |
int colorByLayer = dwg.getColorByLayer(entity);
|
1176 |
//if (color==0) color ByBlock
|
1177 |
if (color==256) color = colorByLayer; |
1178 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
1179 |
if (!((DwgLine)entity).isZflag()) {
|
1180 |
if (p1[2]==p2[2]) auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p1[2]); |
1181 |
else auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
1182 |
} else {
|
1183 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
1184 |
} |
1185 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
1186 |
// Attributes
|
1187 |
/*for (int j=0;j<nAtt;j++) {
|
1188 |
String[] attributes = new String[2];
|
1189 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
1190 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
1191 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
1192 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
1193 |
}
|
1194 |
}*/
|
1195 |
addShape(line, auxRow); |
1196 |
} else if (entity instanceof DwgLwPolyline) { |
1197 |
//System.out.println("Encuentra una DwgLwPolyline dentro de un bloque ...");
|
1198 |
Point2D[] points = ((DwgLwPolyline)entity).getVertices(); |
1199 |
double elev = ((DwgLwPolyline)entity).getElevation();
|
1200 |
FPolyline2D pline; |
1201 |
if (points!=null) { |
1202 |
Point2D[] newPoints = new Point2D[points.length]; |
1203 |
for (int i=0;i<points.length;i++) { |
1204 |
Point2D pointAux = new Point2D.Double(points[i].getX() - bPoint[0], points[i].getY() - bPoint[1]); |
1205 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1206 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1207 |
newPoints[i] = new Point2D.Double(laX, laY); |
1208 |
} |
1209 |
if (dwg.isDwg3DFile()) {
|
1210 |
double[][] pline3D = new double[newPoints.length][3]; |
1211 |
for (int j=0;j<newPoints.length;j++) { |
1212 |
pline3D[j][0] = newPoints[j].getX();
|
1213 |
pline3D[j][1] = newPoints[j].getY();
|
1214 |
pline3D[j][2] = elev;
|
1215 |
} |
1216 |
pline = points3DToFPolyline3D(pline3D); |
1217 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
1218 |
} else {
|
1219 |
pline = points2DToFPolyline2D(newPoints); |
1220 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
1221 |
} |
1222 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(id); |
1223 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("LwPolyline")); |
1224 |
String layerName = dwg.getLayerName(entity);
|
1225 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
1226 |
int color = entity.getColor();
|
1227 |
int colorByLayer = dwg.getColorByLayer(entity);
|
1228 |
//if (color==0) color ByBlock
|
1229 |
if (color==256) color = colorByLayer; |
1230 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
1231 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
1232 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
1233 |
// Attributes
|
1234 |
/*for (int j=0;j<nAtt;j++) {
|
1235 |
String[] attributes = new String[2];
|
1236 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
1237 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
1238 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
1239 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
1240 |
}
|
1241 |
}*/
|
1242 |
addShape(pline, auxRow); |
1243 |
} |
1244 |
} else if (entity instanceof DwgMText) { |
1245 |
|
1246 |
} else if (entity instanceof DwgPoint) { |
1247 |
|
1248 |
} else if (entity instanceof DwgPolyline2D) { |
1249 |
//System.out.println("Encuentra una polil?nea dentro de un bloque ...");
|
1250 |
Point2D[] points = ((DwgPolyline2D)entity).getPts(); |
1251 |
double elev = ((DwgPolyline2D)entity).getElevation();
|
1252 |
FPolyline2D pline; |
1253 |
if (points!=null) { |
1254 |
Point2D[] newPoints = new Point2D[points.length]; |
1255 |
for (int i=0;i<points.length;i++) { |
1256 |
Point2D pointAux = new Point2D.Double(points[i].getX() - bPoint[0], points[i].getY() - bPoint[1]); |
1257 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1258 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1259 |
newPoints[i] = new Point2D.Double(laX, laY); |
1260 |
} |
1261 |
if (dwg.isDwg3DFile()) {
|
1262 |
double[][] pline3D = new double[newPoints.length][3]; |
1263 |
for (int j=0;j<newPoints.length;j++) { |
1264 |
pline3D[j][0] = newPoints[j].getX();
|
1265 |
pline3D[j][1] = newPoints[j].getY();
|
1266 |
pline3D[j][2] = elev;
|
1267 |
} |
1268 |
pline = points3DToFPolyline3D(pline3D); |
1269 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
1270 |
} else {
|
1271 |
pline = points2DToFPolyline2D(newPoints); |
1272 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
1273 |
} |
1274 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(id); |
1275 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline2D")); |
1276 |
String layerName = dwg.getLayerName(entity);
|
1277 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
1278 |
int color = entity.getColor();
|
1279 |
int colorByLayer = dwg.getColorByLayer(entity);
|
1280 |
//if (color==0) color ByBlock
|
1281 |
if (color==256) color = colorByLayer; |
1282 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
1283 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
1284 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
1285 |
// Attributes
|
1286 |
/*for (int j=0;j<nAtt;j++) {
|
1287 |
String[] attributes = new String[2];
|
1288 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
1289 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
1290 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
1291 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
1292 |
}
|
1293 |
}*/
|
1294 |
addShape(pline, auxRow); |
1295 |
} |
1296 |
} else if (entity instanceof DwgPolyline3D) { |
1297 |
|
1298 |
} else if (entity instanceof DwgSolid) { |
1299 |
double[] corner1 = ((DwgSolid)entity).getCorner1(); |
1300 |
double[] corner2 = ((DwgSolid)entity).getCorner2(); |
1301 |
double[] corner3 = ((DwgSolid)entity).getCorner3(); |
1302 |
double[] corner4 = ((DwgSolid)entity).getCorner4(); |
1303 |
double elev = ((DwgSolid)entity).getElevation();
|
1304 |
Point2D pointAux = new Point2D.Double(corner1[0] - bPoint[0], corner1[1] - bPoint[1]); |
1305 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1306 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1307 |
Point2D pp1 = new Point2D.Double(laX, laY); |
1308 |
pointAux = new Point2D.Double(corner2[0] - bPoint[0], corner2[1] - bPoint[1]); |
1309 |
laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1310 |
laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1311 |
Point2D pp2 = new Point2D.Double(laX, laY); |
1312 |
pointAux = new Point2D.Double(corner3[0] - bPoint[0], corner3[1] - bPoint[1]); |
1313 |
laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1314 |
laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1315 |
Point2D pp3 = new Point2D.Double(laX, laY); |
1316 |
pointAux = new Point2D.Double(corner4[0] - bPoint[0], corner4[1] - bPoint[1]); |
1317 |
laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1318 |
laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1319 |
Point2D pp4 = new Point2D.Double(laX, laY); |
1320 |
Point2D[] pts = new Point2D[]{pp1, pp2, pp4, pp3, pp1}; |
1321 |
FPolyline2D solid; |
1322 |
if (dwg.isDwg3DFile()) {
|
1323 |
double[][] pline3D = new double[pts.length][3]; |
1324 |
for (int j=0;j<pts.length;j++) { |
1325 |
pline3D[j][0] = pts[j].getX();
|
1326 |
pline3D[j][1] = pts[j].getY();
|
1327 |
pline3D[j][2] = elev;
|
1328 |
} |
1329 |
solid = points3DToFPolyline3D(pline3D); |
1330 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
1331 |
} else {
|
1332 |
solid = points2DToFPolyline2D(pts); |
1333 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
1334 |
} |
1335 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(id); |
1336 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Solid")); |
1337 |
String layerName = dwg.getLayerName(entity);
|
1338 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
1339 |
int color = entity.getColor();
|
1340 |
int colorByLayer = dwg.getColorByLayer(entity);
|
1341 |
//if (color==0) color ByBlock
|
1342 |
if (color==256) color = colorByLayer; |
1343 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
1344 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
1345 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
1346 |
// Attributes
|
1347 |
/*for (int j=0;j<nAtt;j++) {
|
1348 |
String[] attributes = new String[2];
|
1349 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
1350 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
1351 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
1352 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
1353 |
}
|
1354 |
}*/
|
1355 |
addShape(solid, auxRow); |
1356 |
} else if (entity instanceof DwgSpline) { |
1357 |
|
1358 |
} else if (entity instanceof DwgText) { |
1359 |
|
1360 |
} else if (entity instanceof DwgInsert) { |
1361 |
//System.out.println("Encuentra un insert dentro de un bloque ...");
|
1362 |
double[] p = ((DwgInsert)entity).getInsertionPoint(); |
1363 |
Point2D point = new Point2D.Double(p[0], p[1]); |
1364 |
double[] newScale = ((DwgInsert)entity).getScale(); |
1365 |
double newRot = ((DwgInsert)entity).getRotation();
|
1366 |
int newBlockHandle = ((DwgInsert)entity).getBlockHeaderHandle();
|
1367 |
Point2D pointAux = new Point2D.Double(point.getX() - bPoint[0], point.getY() - bPoint[1]); |
1368 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
1369 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
1370 |
Point2D newInsPoint = new Point2D.Double(laX, laY); |
1371 |
newScale = new double[]{scale[0]*newScale[0], scale[1]*newScale[1], scale[2]*newScale[2]}; |
1372 |
manageInsert(dwgObjects, newInsPoint, newScale, newRot, newBlockHandle, id, auxRow); |
1373 |
/*auxRow[ID_FIELD_ID] = ValueFactory.createValue(0);
|
1374 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
|
1375 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
|
1376 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
|
1377 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
1378 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/
|
1379 |
// Attributes
|
1380 |
/*for (int j=0;j<nAtt;j++) {
|
1381 |
String[] attributes = new String[2];
|
1382 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
1383 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
1384 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
1385 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
1386 |
}
|
1387 |
}*/
|
1388 |
/*FPoint2D fPoint = createPoint(newInsPoint);
|
1389 |
addShape(fPoint, auxRow);*/
|
1390 |
} |
1391 |
} |
1392 |
|
1393 |
/* (non-Javadoc)
|
1394 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
1395 |
*/
|
1396 |
public boolean accept(File f) { |
1397 |
return f.getName().toUpperCase().endsWith("DWG"); |
1398 |
} |
1399 |
|
1400 |
/* (non-Javadoc)
|
1401 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
1402 |
*/
|
1403 |
public int getShapeType() { |
1404 |
return FShape.MULTI;
|
1405 |
} |
1406 |
|
1407 |
/* (non-Javadoc)
|
1408 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
1409 |
*/
|
1410 |
public String getName() { |
1411 |
return "gvSIG DWG Memory Driver"; |
1412 |
} |
1413 |
|
1414 |
/* (non-Javadoc)
|
1415 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
1416 |
*/
|
1417 |
public Legend getDefaultLegend() {
|
1418 |
return defaultLegend;
|
1419 |
} |
1420 |
|
1421 |
/* (non-Javadoc)
|
1422 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
1423 |
*/
|
1424 |
public DriverAttributes getDriverAttributes() {
|
1425 |
return attr;
|
1426 |
} |
1427 |
|
1428 |
/* (non-Javadoc)
|
1429 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
1430 |
*/
|
1431 |
public int[] getPrimaryKeys() throws DriverException { |
1432 |
// TODO Auto-generated method stub
|
1433 |
return null; |
1434 |
} |
1435 |
|
1436 |
/* (non-Javadoc)
|
1437 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
1438 |
*/
|
1439 |
public void write(DataWare arg0) throws DriverException { |
1440 |
// TODO Auto-generated method stub
|
1441 |
|
1442 |
} |
1443 |
} |