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