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