svn-gvsig-desktop / trunk / extensions / extDwg / src / es / iver / gvsig / drivers / dwg / DwgMemoryDriver.java @ 7138
History | View | Annotate | Download (46.3 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.Component; |
49 |
import java.awt.Font; |
50 |
import java.awt.geom.Point2D; |
51 |
import java.io.File; |
52 |
import java.io.IOException; |
53 |
import java.util.ArrayList; |
54 |
//import java.util.Vector;
|
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
import com.iver.cit.javacad.util.AcadColor; |
58 |
import com.iver.cit.javacad.util.GisModelCurveCalculator; |
59 |
import com.iver.cit.jdwglib.dwg.DwgFile; |
60 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
61 |
import com.iver.cit.jdwglib.dwg.DwgVersionNotSupportedException; |
62 |
import com.iver.cit.jdwglib.dwg.objects.DwgArc; |
63 |
import com.iver.cit.jdwglib.dwg.objects.DwgAttdef; |
64 |
import com.iver.cit.jdwglib.dwg.objects.DwgAttrib; |
65 |
import com.iver.cit.jdwglib.dwg.objects.DwgBlock; |
66 |
import com.iver.cit.jdwglib.dwg.objects.DwgBlockControl; |
67 |
import com.iver.cit.jdwglib.dwg.objects.DwgBlockHeader; |
68 |
import com.iver.cit.jdwglib.dwg.objects.DwgCircle; |
69 |
import com.iver.cit.jdwglib.dwg.objects.DwgEndblk; |
70 |
import com.iver.cit.jdwglib.dwg.objects.DwgInsert; |
71 |
import com.iver.cit.jdwglib.dwg.objects.DwgLine; |
72 |
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline; |
73 |
import com.iver.cit.jdwglib.dwg.objects.DwgMText; |
74 |
import com.iver.cit.jdwglib.dwg.objects.DwgPoint; |
75 |
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D; |
76 |
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D; |
77 |
import com.iver.cit.jdwglib.dwg.objects.DwgSolid; |
78 |
import com.iver.cit.jdwglib.dwg.objects.DwgSpline; |
79 |
import com.iver.cit.jdwglib.dwg.objects.DwgText; |
80 |
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse; |
81 |
|
82 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
83 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
84 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
85 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
86 |
import com.hardcode.gdbms.engine.values.IntValue; |
87 |
import com.hardcode.gdbms.engine.values.Value; |
88 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
89 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
90 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
91 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
92 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
93 |
import com.iver.cit.gvsig.fmap.core.FPolyline3D; |
94 |
import com.iver.cit.gvsig.fmap.core.FShape; |
95 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
96 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
97 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
98 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
99 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
100 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
101 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
102 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
103 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
104 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
105 |
|
106 |
/**
|
107 |
* Driver that allows gvSIG to read files in DWG format
|
108 |
* Using this driver, a gvSIG user can manipulate part of the information contained in
|
109 |
* a DWG file
|
110 |
* This driver load the Dwg file in memory
|
111 |
* This driver uses jdwglib
|
112 |
*
|
113 |
* @author jmorell
|
114 |
*/
|
115 |
public class DwgMemoryDriver extends MemoryDriver implements VectorialFileDriver, WithDefaultLegend { |
116 |
private final int ID_FIELD_ID=0; |
117 |
private final int ID_FIELD_FSHAPE=1; |
118 |
private final int ID_FIELD_ENTITY=2; |
119 |
private final int ID_FIELD_LAYER=3; |
120 |
private final int ID_FIELD_COLOR=4; |
121 |
private final int ID_FIELD_ELEVATION=5; |
122 |
private final int ID_FIELD_THICKNESS=6; |
123 |
private final int ID_FIELD_TEXT=7; |
124 |
private final int ID_FIELD_HEIGHTTEXT=8; |
125 |
private final int ID_FIELD_ROTATIONTEXT=9; |
126 |
|
127 |
VectorialUniqueValueLegend defaultLegend; |
128 |
|
129 |
private File m_Fich; |
130 |
|
131 |
private DwgFile dwg;
|
132 |
private ArrayList dwgObjects; |
133 |
private DriverAttributes attr = new DriverAttributes(); |
134 |
|
135 |
private boolean isInitialized = false; |
136 |
|
137 |
/* (non-Javadoc)
|
138 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
139 |
*/
|
140 |
public void open(File f) throws IOException { |
141 |
m_Fich = f; |
142 |
} |
143 |
|
144 |
/**
|
145 |
* This method load the DWG file in memory.
|
146 |
* First, it will be necessary to create a DwgFile object with the DWG file path
|
147 |
* as the argument.
|
148 |
* Second, the method read of DwgFile allows to read the objects inside the DWG
|
149 |
* file.
|
150 |
* Third, it will be necessary to process some DWG objects like Layers or Polylines
|
151 |
* Fourth, applyExtrusions() can change the location of the DWG objects through the
|
152 |
* extrusion parameters.
|
153 |
* Fifth, the testDwg3D method test if this DWG has elevation informacion.
|
154 |
* Sixth, we can extract the objects contained inside the blocks through the
|
155 |
* blockManagement method.
|
156 |
* And finally, we can read the objects Vector, and convert this objects to the FMap
|
157 |
* object model.
|
158 |
*/
|
159 |
public void initialize() throws IOException { |
160 |
if(isInitialized)
|
161 |
return;
|
162 |
else
|
163 |
isInitialized = true;
|
164 |
//System.out.println("Driver actualizado");
|
165 |
float heightText = 10; |
166 |
|
167 |
attr.setLoadedInMemory(true);
|
168 |
|
169 |
dwg = new DwgFile(m_Fich.getAbsolutePath());
|
170 |
long t1 = System.currentTimeMillis(); |
171 |
try {
|
172 |
dwg.read(); |
173 |
} catch (DwgVersionNotSupportedException e1) {
|
174 |
String autodeskUrl = "<html><a href=\"http://usa.autodesk.com/adsk/servlet/item" + |
175 |
"?siteID=123112&id=7024151\">"+
|
176 |
"http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151</a></html>";
|
177 |
String userText = PluginServices.getText(this, "The_version_of")+" "; |
178 |
userText += m_Fich.getName() + " (";
|
179 |
userText += e1.getDwgVersion() + " ) ";
|
180 |
userText += PluginServices.getText(this, "Is_not_supported"); |
181 |
userText +="\n";
|
182 |
userText += PluginServices.getText(this, "Probe_to_convert") + "\n"; |
183 |
userText += PluginServices.getText(this, "Autodesk_converter"); |
184 |
userText += " " + autodeskUrl;
|
185 |
String dialogTitle = PluginServices.getText(this, "Not_supported_version"); |
186 |
javax.swing.JOptionPane. |
187 |
showMessageDialog((Component)PluginServices.getMainFrame(),
|
188 |
userText, |
189 |
dialogTitle, |
190 |
javax.swing.JOptionPane.ERROR_MESSAGE); |
191 |
throw new IOException("Version de DWG no soportada por gvSIG"); |
192 |
|
193 |
|
194 |
} |
195 |
long t2 = System.currentTimeMillis(); |
196 |
System.out.println("Tiempo empleado por la librer?a en leer el fichero dwg = " + (t2-t1)); |
197 |
t1 = System.currentTimeMillis();
|
198 |
dwg.initializeLayerTable(); |
199 |
dwg.calculateGisModelDwgPolylines(); |
200 |
dwg.applyExtrusions(); |
201 |
dwg.testDwg3D(); |
202 |
dwg.blockManagement(); |
203 |
t2 = System.currentTimeMillis();
|
204 |
System.out.println("Tiempo empleado por la librer?a en tratar el fichero dwg = " + (t2-t1)); |
205 |
dwgObjects = dwg.getDwgObjects(); |
206 |
|
207 |
// TODO: Atributos extra de los objectos
|
208 |
//int nAtt = featureMaker.getAttributes().size();
|
209 |
|
210 |
// Campos de las MemoryLayer:
|
211 |
//Value[] auxRow = new Value[9+nAtt];
|
212 |
Value[] auxRow = new Value[10]; |
213 |
ArrayList arrayFields = new ArrayList(); |
214 |
arrayFields.add("ID");
|
215 |
arrayFields.add("FShape");
|
216 |
arrayFields.add("Entity");
|
217 |
arrayFields.add("Layer");
|
218 |
arrayFields.add("Color");
|
219 |
arrayFields.add("Elevation");
|
220 |
arrayFields.add("Thickness");
|
221 |
arrayFields.add("Text");
|
222 |
arrayFields.add("HeightText");
|
223 |
arrayFields.add("RotationText");
|
224 |
/*for (int i=0;i<nAtt;i++) {
|
225 |
String att[] = new String[2];
|
226 |
att = (String[])featureMaker.getAttributes().get(i);
|
227 |
arrayFields.add(att[0]);
|
228 |
}*/
|
229 |
|
230 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
231 |
|
232 |
t1 = System.currentTimeMillis();
|
233 |
|
234 |
//boolean addingToBlock = false;
|
235 |
|
236 |
for (int i=0;i<dwgObjects.size();i++) { |
237 |
|
238 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
|
239 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
|
240 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
241 |
|
242 |
DwgObject entity = (DwgObject)dwgObjects.get(i); |
243 |
if (entity instanceof DwgArc) {// && !addingToBlock) { |
244 |
//System.out.println("Encuentra un Arc ...");
|
245 |
double[] c = ((DwgArc)entity).getCenter(); |
246 |
Point2D center = new Point2D.Double(c[0], c[1]); |
247 |
double radius = ((DwgArc)entity).getRadius();
|
248 |
double initAngle = Math.toDegrees(((DwgArc)entity).getInitAngle()); |
249 |
double endAngle = Math.toDegrees(((DwgArc)entity).getEndAngle()); |
250 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelArc(center, radius, initAngle, endAngle); |
251 |
FPolyline2D arcc; |
252 |
if (dwg.isDwg3DFile()) {
|
253 |
double[][] arc3D = new double[arc.length][3]; |
254 |
for (int j=0;j<arc.length;j++) { |
255 |
arc3D[j][0] = arc[j].getX();
|
256 |
arc3D[j][1] = arc[j].getY();
|
257 |
arc3D[j][2] = c[2]; |
258 |
} |
259 |
arcc = points3DToFPolyline3D(arc3D); |
260 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
261 |
} else {
|
262 |
arcc = points2DToFPolyline2D(arc); |
263 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
264 |
} |
265 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
266 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Arc")); |
267 |
String layerName = dwg.getLayerName(entity);
|
268 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
269 |
int color = entity.getColor();
|
270 |
int colorByLayer = dwg.getColorByLayer(entity);
|
271 |
// TODO: if (color==0) color ByBlock
|
272 |
if (color==256) color = colorByLayer; |
273 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
274 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
|
275 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
276 |
// Attributes
|
277 |
/*for (int j=0;j<nAtt;j++) {
|
278 |
String[] attributes = new String[2];
|
279 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
280 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
281 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
282 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
283 |
}
|
284 |
}*/
|
285 |
addShape(arcc, auxRow); |
286 |
} else if (entity instanceof DwgEllipse) {// && !addingToBlock) { |
287 |
//System.out.println("Encuentra una Ellipse ...");
|
288 |
double[] c = ((DwgEllipse)entity).getCenter(); |
289 |
Point2D center = new Point2D.Double(c[0], c[1]); |
290 |
double[] majorAxisVector = ((DwgEllipse)entity).getMajorAxisVector(); |
291 |
Point2D mav = new Point2D.Double(majorAxisVector[0], majorAxisVector[1]); |
292 |
double axisRatio = ((DwgEllipse)entity).getAxisRatio();
|
293 |
double initAngle = Math.toDegrees(((DwgEllipse)entity).getInitAngle()); |
294 |
double endAngle = Math.toDegrees(((DwgEllipse)entity).getEndAngle()); |
295 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelEllipse(center, mav, axisRatio, initAngle, endAngle); |
296 |
FPolyline2D arcc; |
297 |
if (dwg.isDwg3DFile()) {
|
298 |
double[][] arc3D = new double[arc.length][3]; |
299 |
for (int j=0;j<arc.length;j++) { |
300 |
arc3D[j][0] = arc[j].getX();
|
301 |
arc3D[j][1] = arc[j].getY();
|
302 |
arc3D[j][2] = c[2]; |
303 |
} |
304 |
arcc = points3DToFPolyline3D(arc3D); |
305 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
306 |
} else {
|
307 |
arcc = points2DToFPolyline2D(arc); |
308 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
309 |
} |
310 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
311 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Ellipse")); |
312 |
String layerName = dwg.getLayerName(entity);
|
313 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
314 |
int color = entity.getColor();
|
315 |
int colorByLayer = dwg.getColorByLayer(entity);
|
316 |
// TODO: if (color==0) color ByBlock
|
317 |
if (color==256) color = colorByLayer; |
318 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
319 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
|
320 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
321 |
// Attributes
|
322 |
/*for (int j=0;j<nAtt;j++) {
|
323 |
String[] attributes = new String[2];
|
324 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
325 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
326 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
327 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
328 |
}
|
329 |
}*/
|
330 |
addShape(arcc, auxRow); |
331 |
} else if (entity instanceof DwgCircle) {// && !addingToBlock) { |
332 |
//System.out.println("Encuentra un Circle ...");
|
333 |
double[] c = ((DwgCircle)entity).getCenter(); |
334 |
Point2D center = new Point2D.Double(c[0], c[1]); |
335 |
double radius = ((DwgCircle)entity).getRadius();
|
336 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelCircle(center, radius); |
337 |
FPolyline2D arcc; |
338 |
if (dwg.isDwg3DFile()) {
|
339 |
double[][] arc3D = new double[arc.length][3]; |
340 |
for (int j=0;j<arc.length;j++) { |
341 |
arc3D[j][0] = arc[j].getX();
|
342 |
arc3D[j][1] = arc[j].getY();
|
343 |
arc3D[j][2] = c[2]; |
344 |
} |
345 |
arcc = points3DToFPolyline3D(arc3D); |
346 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
347 |
} else {
|
348 |
arcc = points2DToFPolyline2D(arc); |
349 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
350 |
} |
351 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
352 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Circle")); |
353 |
String layerName = dwg.getLayerName(entity);
|
354 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
355 |
int color = entity.getColor();
|
356 |
int colorByLayer = dwg.getColorByLayer(entity);
|
357 |
//if (color==0) color ByBlock
|
358 |
if (color==256) color = colorByLayer; |
359 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
360 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
|
361 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
362 |
// Attributes
|
363 |
/*for (int j=0;j<nAtt;j++) {
|
364 |
String[] attributes = new String[2];
|
365 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
366 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
367 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
368 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
369 |
}
|
370 |
}*/
|
371 |
addShape(arcc, auxRow); |
372 |
} else if (entity instanceof DwgPolyline2D) {// && !addingToBlock) { |
373 |
//System.out.println("Encuentra una Polyline2D ...");
|
374 |
Point2D[] points = ((DwgPolyline2D)entity).getPts(); |
375 |
double elev = ((DwgPolyline2D)entity).getElevation();
|
376 |
FPolyline2D pline; |
377 |
if (points!=null) { |
378 |
if (dwg.isDwg3DFile()) {
|
379 |
double[][] pline3D = new double[points.length][3]; |
380 |
for (int j=0;j<points.length;j++) { |
381 |
pline3D[j][0] = points[j].getX();
|
382 |
pline3D[j][1] = points[j].getY();
|
383 |
pline3D[j][2] = elev;
|
384 |
} |
385 |
pline = points3DToFPolyline3D(pline3D); |
386 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
387 |
} else {
|
388 |
pline = points2DToFPolyline2D(points); |
389 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
390 |
} |
391 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
392 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline2D")); |
393 |
String layerName = dwg.getLayerName(entity);
|
394 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
395 |
int color = entity.getColor();
|
396 |
int colorByLayer = dwg.getColorByLayer(entity);
|
397 |
//if (color==0) color ByBlock
|
398 |
if (color==256) color = colorByLayer; |
399 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
400 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
401 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
402 |
// Attributes
|
403 |
/*for (int j=0;j<nAtt;j++) {
|
404 |
String[] attributes = new String[2];
|
405 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
406 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
407 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
408 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
409 |
}
|
410 |
}*/
|
411 |
addShape(pline, auxRow); |
412 |
} |
413 |
} else if (entity instanceof DwgPolyline3D) {// && !addingToBlock) { |
414 |
//System.out.println("Encuentra una Polyline3D ...");
|
415 |
double[][] points3D = ((DwgPolyline3D)entity).getPts(); |
416 |
FPolyline2D pline; |
417 |
if (points3D!=null) { |
418 |
if (dwg.isDwg3DFile()) {
|
419 |
double[][] pline3D = new double[points3D.length][3]; |
420 |
pline = points3DToFPolyline3D(points3D); |
421 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
422 |
} else {
|
423 |
Point2D[] points2D = new Point2D[points3D.length]; |
424 |
for (int j=0;j<points3D.length;j++) { |
425 |
points2D[j] = new Point2D.Double(points3D[j][0], points3D[j][1]); |
426 |
} |
427 |
pline = points2DToFPolyline2D(points2D); |
428 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
429 |
} |
430 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
431 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline3D")); |
432 |
String layerName = dwg.getLayerName(entity);
|
433 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
434 |
int color = entity.getColor();
|
435 |
int colorByLayer = dwg.getColorByLayer(entity);
|
436 |
//if (color==0) color ByBlock
|
437 |
if (color==256) color = colorByLayer; |
438 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
439 |
boolean constantElevation = true; |
440 |
for (int j=0;j<points3D.length;j++) { |
441 |
if (points3D[j][2]!=points3D[0][2]) { |
442 |
constantElevation = false;
|
443 |
break;
|
444 |
} |
445 |
} |
446 |
if (constantElevation) auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(points3D[0][2]); |
447 |
else auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
448 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
449 |
// Attributes
|
450 |
/*for (int j=0;j<nAtt;j++) {
|
451 |
String[] attributes = new String[2];
|
452 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
453 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
454 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
455 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
456 |
}
|
457 |
}*/
|
458 |
addShape(pline, auxRow); |
459 |
} |
460 |
} else if (entity instanceof DwgLwPolyline) {// && !addingToBlock) { |
461 |
//System.out.println("Encuentra una Lwpolyline ...");
|
462 |
Point2D[] pts = ((DwgLwPolyline)entity).getVertices(); |
463 |
double elev = ((DwgLwPolyline)entity).getElevation();
|
464 |
if (pts!=null) { |
465 |
FPolyline2D lwpline; |
466 |
if (dwg.isDwg3DFile()) {
|
467 |
double[][] pline3D = new double[pts.length][3]; |
468 |
for (int j=0;j<pts.length;j++) { |
469 |
pline3D[j][0] = pts[j].getX();
|
470 |
pline3D[j][1] = pts[j].getY();
|
471 |
pline3D[j][2] = elev;
|
472 |
} |
473 |
lwpline = points3DToFPolyline3D(pline3D); |
474 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
475 |
} else {
|
476 |
lwpline = points2DToFPolyline2D(pts); |
477 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
478 |
} |
479 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
480 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("LwPolyline")); |
481 |
String layerName = dwg.getLayerName(entity);
|
482 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
483 |
int color = entity.getColor();
|
484 |
int colorByLayer = dwg.getColorByLayer(entity);
|
485 |
//if (color==0) color ByBlock
|
486 |
if (color==256) color = colorByLayer; |
487 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
488 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
489 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
490 |
// Attributes
|
491 |
/*for (int j=0;j<nAtt;j++) {
|
492 |
String[] attributes = new String[2];
|
493 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
494 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
495 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
496 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
497 |
}
|
498 |
}*/
|
499 |
addShape(lwpline, auxRow); |
500 |
} |
501 |
} else if (entity instanceof DwgSolid) {// && !addingToBlock) { |
502 |
//System.out.println("Encuentra un Solid ...");
|
503 |
double[] p1 = ((DwgSolid)entity).getCorner1(); |
504 |
double[] p2 = ((DwgSolid)entity).getCorner2(); |
505 |
double[] p3 = ((DwgSolid)entity).getCorner3(); |
506 |
double[] p4 = ((DwgSolid)entity).getCorner4(); |
507 |
double elev = ((DwgSolid)entity).getElevation();
|
508 |
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])}; |
509 |
FPolyline2D solid; |
510 |
if (dwg.isDwg3DFile()) {
|
511 |
double[][] pline3D = new double[pts.length][3]; |
512 |
for (int j=0;j<pts.length;j++) { |
513 |
pline3D[j][0] = pts[j].getX();
|
514 |
pline3D[j][1] = pts[j].getY();
|
515 |
pline3D[j][2] = elev;
|
516 |
} |
517 |
solid = points3DToFPolyline3D(pline3D); |
518 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
519 |
} else {
|
520 |
solid = points2DToFPolyline2D(pts); |
521 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
522 |
} |
523 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
524 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Solid")); |
525 |
String layerName = dwg.getLayerName(entity);
|
526 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
527 |
int color = entity.getColor();
|
528 |
int colorByLayer = dwg.getColorByLayer(entity);
|
529 |
//if (color==0) color ByBlock
|
530 |
if (color==256) color = colorByLayer; |
531 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
532 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
533 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
534 |
// Attributes
|
535 |
/*for (int j=0;j<nAtt;j++) {
|
536 |
String[] attributes = new String[2];
|
537 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
538 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
539 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
540 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
541 |
}
|
542 |
}*/
|
543 |
addShape(solid, auxRow); |
544 |
} else if (entity instanceof DwgLine) {// && !addingToBlock) { |
545 |
//System.out.println("Encuentra una Line ...");
|
546 |
double[] p1 = ((DwgLine)entity).getP1(); |
547 |
Point2D point1 = new Point2D.Double(p1[0], p1[1]); |
548 |
double[] p2 = ((DwgLine)entity).getP2(); |
549 |
Point2D point2 = new Point2D.Double(p2[0], p2[1]); |
550 |
Point2D[] lin = new Point2D[]{point1, point2}; |
551 |
FPolyline2D line; |
552 |
if (dwg.isDwg3DFile() && ((DwgLine)entity).isZflag()) {
|
553 |
double[][] lin3D = new double[2][3]; |
554 |
lin3D[0][0] = lin[0].getX(); |
555 |
lin3D[0][1] = lin[0].getY(); |
556 |
lin3D[0][2] = p1[2]; |
557 |
lin3D[1][0] = lin[1].getX(); |
558 |
lin3D[1][1] = lin[1].getY(); |
559 |
lin3D[1][2] = p2[2]; |
560 |
line = points3DToFPolyline3D(lin3D); |
561 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
562 |
} else if (dwg.isDwg3DFile() && !((DwgLine)entity).isZflag()) { |
563 |
double[][] lin3D = new double[2][3]; |
564 |
lin3D[0][0] = lin[0].getX(); |
565 |
lin3D[0][1] = lin[0].getY(); |
566 |
lin3D[0][2] = 0.0; |
567 |
lin3D[1][0] = lin[1].getX(); |
568 |
lin3D[1][1] = lin[1].getY(); |
569 |
lin3D[1][2] = 0.0; |
570 |
line = points3DToFPolyline3D(lin3D); |
571 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D")); |
572 |
} else {
|
573 |
line = points2DToFPolyline2D(lin); |
574 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D")); |
575 |
} |
576 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
577 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Line")); |
578 |
String layerName = dwg.getLayerName(entity);
|
579 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
580 |
int color = entity.getColor();
|
581 |
int colorByLayer = dwg.getColorByLayer(entity);
|
582 |
//if (color==0) color ByBlock
|
583 |
if (color==256) color = colorByLayer; |
584 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
585 |
if (((DwgLine)entity).isZflag()) {
|
586 |
if (p1[2]==p2[2]) auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p1[2]); |
587 |
else auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0); |
588 |
} else {
|
589 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
590 |
} |
591 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
592 |
// Attributes
|
593 |
/*for (int j=0;j<nAtt;j++) {
|
594 |
String[] attributes = new String[2];
|
595 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
596 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
597 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
598 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
599 |
}
|
600 |
}*/
|
601 |
addShape(line, auxRow); |
602 |
} else if (entity instanceof DwgPoint) {// && !addingToBlock) { |
603 |
//System.out.println("Encuentra un Point ...");
|
604 |
double[] p = ((DwgPoint)entity).getPoint(); |
605 |
FPoint2D point; |
606 |
if (dwg.isDwg3DFile()) {
|
607 |
point = new FPoint3D(p[0], p[1], p[2]); |
608 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
609 |
} else {
|
610 |
point = new FPoint2D(p[0], p[1]); |
611 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
612 |
} |
613 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
614 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Point")); |
615 |
String layerName = dwg.getLayerName(entity);
|
616 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
617 |
int color = entity.getColor();
|
618 |
int colorByLayer = dwg.getColorByLayer(entity);
|
619 |
//if (color==0) color ByBlock
|
620 |
if (color==256) color = colorByLayer; |
621 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
622 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
|
623 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
624 |
// Attributes
|
625 |
/*for (int j=0;j<nAtt;j++) {
|
626 |
String[] attributes = new String[2];
|
627 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
628 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
629 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
630 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
631 |
}
|
632 |
}*/
|
633 |
addShape(point, auxRow); |
634 |
} else if (entity instanceof DwgInsert) {// && !addingToBlock) { |
635 |
//System.out.println("Encuentra un Insert ...");
|
636 |
double[] p = ((DwgInsert)entity).getInsertionPoint(); |
637 |
Point2D point = new Point2D.Double(p[0], p[1]); |
638 |
FPoint2D fPoint; |
639 |
/*double[] scale = ((DwgInsert)entity).getScale();
|
640 |
double rot = ((DwgInsert)entity).getRotation();
|
641 |
int blockHandle = ((DwgInsert)entity).getBlockHeaderHandle();*/
|
642 |
//manageInsert(dwgObjects, point, scale, rot, blockHandle, i, auxRow);
|
643 |
if (dwg.isDwg3DFile()) {
|
644 |
fPoint = new FPoint3D(p[0], p[1], p[2]); |
645 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
646 |
} else {
|
647 |
fPoint = new FPoint2D(p[0], p[1]); |
648 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
649 |
} |
650 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
651 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Insert")); |
652 |
String layerName = dwg.getLayerName(entity);
|
653 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
654 |
int color = entity.getColor();
|
655 |
int colorByLayer = dwg.getColorByLayer(entity);
|
656 |
//if (color==0) color ByBlock
|
657 |
if (color==256) color = colorByLayer; |
658 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
659 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
|
660 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
661 |
// Attributes
|
662 |
/*for (int j=0;j<nAtt;j++) {
|
663 |
String[] attributes = new String[2];
|
664 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
665 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
666 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
667 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
668 |
}
|
669 |
}*/
|
670 |
addShape(fPoint, auxRow); |
671 |
} else if (entity instanceof DwgMText) {//) && !addingToBlock) { |
672 |
//System.out.println("Encuentra un MText ...");
|
673 |
double[] p = ((DwgMText)entity).getInsertionPoint(); |
674 |
FPoint2D fPoint; |
675 |
if (dwg.isDwg3DFile()) {
|
676 |
fPoint = new FPoint3D(p[0], p[1], p[2]); |
677 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
678 |
} else {
|
679 |
fPoint = new FPoint2D(p[0], p[1]); |
680 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
681 |
} |
682 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
683 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("MText")); |
684 |
String layerName = dwg.getLayerName(entity);
|
685 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
686 |
int color = entity.getColor();
|
687 |
int colorByLayer = dwg.getColorByLayer(entity);
|
688 |
//if (color==0) color ByBlock
|
689 |
if (color==256) color = colorByLayer; |
690 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
691 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
|
692 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
693 |
// Attributes
|
694 |
/*for (int j=0;j<nAtt;j++) {
|
695 |
String[] attributes = new String[2];
|
696 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
697 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
698 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
699 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
700 |
}
|
701 |
}*/
|
702 |
addShape(fPoint, auxRow); |
703 |
} else if (entity instanceof DwgAttrib) {// && !addingToBlock) { |
704 |
//System.out.println("Encuentra un Attrib ...");
|
705 |
} else if (entity instanceof DwgText) {// && !addingToBlock) { |
706 |
//System.out.println("Encuentra un Text ...");
|
707 |
Point2D p = ((DwgText)entity).getInsertionPoint();
|
708 |
int dflag = ((DwgText)entity).getDataFlag();
|
709 |
double elev = 0.0; |
710 |
if ((dflag & 0x1)==0) elev = ((DwgText)entity).getElevation(); |
711 |
FPoint2D point; |
712 |
if (dwg.isDwg3DFile()) {
|
713 |
point = new FPoint3D(p.getX(), p.getY(), elev);
|
714 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D")); |
715 |
} else {
|
716 |
point = new FPoint2D(p.getX(), p.getY());
|
717 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D")); |
718 |
} |
719 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
720 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Text")); |
721 |
String layerName = dwg.getLayerName(entity);
|
722 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
723 |
int color = entity.getColor();
|
724 |
int colorByLayer = dwg.getColorByLayer(entity);
|
725 |
//if (color==0) color ByBlock
|
726 |
if (color==256) color = colorByLayer; |
727 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
728 |
String text = ((DwgText)entity).getText();
|
729 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(text)); |
730 |
heightText = (float)((DwgText)entity).getHeight();
|
731 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText); |
732 |
if ((dflag & 0x8) == 0) { |
733 |
double textRot = ((DwgText)entity).getRotationAngle();
|
734 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(Math.toDegrees(textRot));
|
735 |
} else {
|
736 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
|
737 |
} |
738 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev); |
739 |
double thickness = ((DwgText)entity).getThickness();
|
740 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(thickness); |
741 |
// Attributes
|
742 |
/*for (int j=0;j<nAtt;j++) {
|
743 |
String[] attributes = new String[2];
|
744 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
745 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
746 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
747 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
748 |
}
|
749 |
}*/
|
750 |
addShape(point, auxRow); |
751 |
} else if (entity instanceof DwgBlock) { |
752 |
//System.out.println("Encuentra un Block ...");
|
753 |
//addingToBlock = true;
|
754 |
String blockName = ((DwgBlock)entity).getName();
|
755 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
756 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block")); |
757 |
String layerName = dwg.getLayerName(entity);
|
758 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
759 |
int color = entity.getColor();
|
760 |
int colorByLayer = dwg.getColorByLayer(entity);
|
761 |
//if (color==0) color ByBlock
|
762 |
if (color==256) color = colorByLayer; |
763 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
764 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
765 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
766 |
// Attributes
|
767 |
/*for (int j=0;j<nAtt;j++) {
|
768 |
String[] attributes = new String[2];
|
769 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
770 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
771 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
772 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
773 |
}
|
774 |
}*/
|
775 |
//addShape(point, auxRow);
|
776 |
} else if (entity instanceof DwgEndblk) { |
777 |
//System.out.println("Encuentra un Endblk ...");
|
778 |
//addingToBlock = false;
|
779 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
780 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("EndBlk")); |
781 |
String layerName = dwg.getLayerName(entity);
|
782 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
783 |
int color = entity.getColor();
|
784 |
int colorByLayer = dwg.getColorByLayer(entity);
|
785 |
//if (color==0) color ByBlock
|
786 |
if (color==256) color = colorByLayer; |
787 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
788 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
789 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
790 |
// Attributes
|
791 |
/*for (int j=0;j<nAtt;j++) {
|
792 |
String[] attributes = new String[2];
|
793 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
794 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
795 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
796 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
797 |
}
|
798 |
}*/
|
799 |
//addShape(point, auxRow);
|
800 |
} else if (entity instanceof DwgBlockControl) { |
801 |
//System.out.println("Encuentra un Block Control Object ...");
|
802 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
803 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Control Object")); |
804 |
String layerName = dwg.getLayerName(entity);
|
805 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
806 |
int color = entity.getColor();
|
807 |
int colorByLayer = dwg.getColorByLayer(entity);
|
808 |
//if (color==0) color ByBlock
|
809 |
if (color==256) color = colorByLayer; |
810 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
811 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
812 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
813 |
// Attributes
|
814 |
/*for (int j=0;j<nAtt;j++) {
|
815 |
String[] attributes = new String[2];
|
816 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
817 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
818 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
819 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
820 |
}
|
821 |
}*/
|
822 |
//addShape(point, auxRow);
|
823 |
} else if (entity instanceof DwgBlockHeader) { |
824 |
//System.out.println("Encuentra un Block Header ...");
|
825 |
//addingToBlock = true;
|
826 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
827 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Header")); |
828 |
String layerName = dwg.getLayerName(entity);
|
829 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
830 |
int color = entity.getColor();
|
831 |
int colorByLayer = dwg.getColorByLayer(entity);
|
832 |
//if (color==0) color ByBlock
|
833 |
if (color==256) color = colorByLayer; |
834 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
835 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
|
836 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
837 |
// Attributes
|
838 |
/*for (int j=0;j<nAtt;j++) {
|
839 |
String[] attributes = new String[2];
|
840 |
attributes = (String[])featureMaker.getAttributes().get(j);
|
841 |
auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
|
842 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
843 |
auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
|
844 |
}
|
845 |
}*/
|
846 |
//addShape(point, auxRow);
|
847 |
} else if (entity instanceof DwgAttdef) {// && !addingToBlock) { |
848 |
//System.out.println("Encuentra un Attdef ...");
|
849 |
} else {
|
850 |
//System.out.println("Detectado dwgObject pendiente de implementar");
|
851 |
} |
852 |
} |
853 |
t2 = System.currentTimeMillis();
|
854 |
System.out.println("Tiempo empleado por el driver en importar el contenido del dwg = " + (t2-t1)); |
855 |
|
856 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
857 |
defaultLegend.setFieldName("Color");
|
858 |
defaultLegend.setLabelField("Text");
|
859 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
|
860 |
defaultLegend.getDefaultSymbol().setShapeVisible(false);
|
861 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
|
862 |
defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9)); |
863 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
|
864 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
865 |
defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
866 |
defaultLegend.getDefaultSymbol().setSize(3);
|
867 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true);
|
868 |
|
869 |
defaultLegend.setLabelHeightField("HeightText");
|
870 |
defaultLegend.setLabelRotationField("RotationText");
|
871 |
|
872 |
ObjectDriver rs = this;
|
873 |
IntValue clave; |
874 |
FSymbol theSymbol = null;
|
875 |
|
876 |
try {
|
877 |
// Provisional hasta que cambiemos los s?mbolos.
|
878 |
/* BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
|
879 |
Graphics2D big = bi.createGraphics();
|
880 |
Color color=new Color(0,0,0,0);
|
881 |
big.setBackground(color);
|
882 |
big.clearRect(0, 0, 5, 5);
|
883 |
Paint fillProv = null;
|
884 |
Rectangle2D rProv = new Rectangle();
|
885 |
rProv.setFrame(0, 0,5,5);
|
886 |
fillProv = new TexturePaint(bi,rProv); */
|
887 |
|
888 |
for (long j = 0; j < rs.getRowCount(); j++) |
889 |
{ |
890 |
clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR); |
891 |
if (defaultLegend.getSymbolByValue(clave) == null) |
892 |
{ |
893 |
theSymbol = new FSymbol(getShapeType());
|
894 |
theSymbol.setDescription(clave.toString()); |
895 |
theSymbol.setColor(AcadColor.getColor(clave.getValue())); |
896 |
// theSymbol.setFill(fillProv);
|
897 |
// 050202, jmorell: Asigna los colores de Autocad a los bordes
|
898 |
// de los pol?gonos.
|
899 |
theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue())); |
900 |
|
901 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
902 |
theSymbol.setSize(3);
|
903 |
theSymbol.setSizeInPixels(true);
|
904 |
|
905 |
defaultLegend.addSymbol(clave, theSymbol); |
906 |
} |
907 |
} // for
|
908 |
} catch (DriverException e) {
|
909 |
e.printStackTrace(); |
910 |
throw new IOException("Error al poner la leyenda por defecto en el Dwg"); |
911 |
} |
912 |
} |
913 |
|
914 |
/**
|
915 |
* Method that changes a Point2D array to a FPolyline2D. Is useful to convert a
|
916 |
* polyline given by it points to a FPolyline2D, a polyline in the FMap model
|
917 |
* object
|
918 |
*
|
919 |
* @param pts Array of Point2D that defines the polyline that will be converted in
|
920 |
* a FPolyline2D
|
921 |
* @return FPolyline2D This FPolyline2D is build using the array of Point2D that
|
922 |
* is the argument of the method
|
923 |
*/
|
924 |
private FPolyline2D points2DToFPolyline2D(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 |
return new FPolyline2D(genPathX); |
931 |
} |
932 |
|
933 |
/**
|
934 |
* Method that changes a Point3D array to a FPolyline3D. Is useful to convert a
|
935 |
* polyline given by it points to a FPolyline3D, a polyline 3D in the FMap model
|
936 |
* object
|
937 |
*
|
938 |
* @param pts Array of Point3D that defines the polyline 3D that will be converted in
|
939 |
* a FPolyline3D
|
940 |
* @return FPolyline3D This FPolyline3D is build using the array of Point3D that
|
941 |
* is the argument of the method
|
942 |
*/
|
943 |
private FPolyline3D points3DToFPolyline3D(double[][] pts) { |
944 |
GeneralPathX genPathX = new GeneralPathX();
|
945 |
genPathX.moveTo(pts[0][0], pts[0][1]); |
946 |
for (int i=1; i<pts.length; i++) { |
947 |
genPathX.lineTo(pts[i][0], pts[i][1]); |
948 |
} |
949 |
double[] elevations = new double[pts.length]; |
950 |
for (int i=0;i<pts.length;i++) { |
951 |
elevations[i] = pts[i][2];
|
952 |
} |
953 |
return new FPolyline3D(genPathX, elevations); |
954 |
} |
955 |
|
956 |
/**
|
957 |
* Method that changes a Point2D array to a FPolygon2D. Is useful to convert a
|
958 |
* polygon given by it points to a FPolygon2D, a polygon in the FMap model
|
959 |
* object
|
960 |
*
|
961 |
* @param pts Array of Point2D that defines the polygon that will be converted in
|
962 |
* a FPolygon2D
|
963 |
* @return FPolygon2D This FPolygon2D is build using the array of Point2D that
|
964 |
* is the argument of the method
|
965 |
*/
|
966 |
private FPolygon2D points2DToFPolygon2D(Point2D[] pts) { |
967 |
GeneralPathX genPathX = new GeneralPathX();
|
968 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
969 |
for (int i=1; i<pts.length; i++) { |
970 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
971 |
} |
972 |
genPathX.closePath(); |
973 |
return new FPolygon2D(genPathX); |
974 |
} |
975 |
|
976 |
/* (non-Javadoc)
|
977 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
978 |
*/
|
979 |
public boolean accept(File f) { |
980 |
return f.getName().toUpperCase().endsWith("DWG"); |
981 |
} |
982 |
|
983 |
/* (non-Javadoc)
|
984 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
985 |
*/
|
986 |
public int getShapeType() { |
987 |
return FShape.MULTI;
|
988 |
} |
989 |
|
990 |
/* (non-Javadoc)
|
991 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
992 |
*/
|
993 |
public String getName() { |
994 |
return "gvSIG DWG Memory Driver"; |
995 |
} |
996 |
|
997 |
/* (non-Javadoc)
|
998 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
999 |
*/
|
1000 |
public Legend getDefaultLegend() {
|
1001 |
return defaultLegend;
|
1002 |
} |
1003 |
|
1004 |
/* (non-Javadoc)
|
1005 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
1006 |
*/
|
1007 |
public DriverAttributes getDriverAttributes() {
|
1008 |
return attr;
|
1009 |
} |
1010 |
|
1011 |
/* (non-Javadoc)
|
1012 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
1013 |
*/
|
1014 |
public int[] getPrimaryKeys() throws DriverException { |
1015 |
// TODO Auto-generated method stub
|
1016 |
return null; |
1017 |
} |
1018 |
|
1019 |
/* (non-Javadoc)
|
1020 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
1021 |
*/
|
1022 |
public void write(DataWare arg0) throws DriverException { |
1023 |
// TODO Auto-generated method stub
|
1024 |
|
1025 |
} |
1026 |
|
1027 |
public void setDataSourceFactory(DataSourceFactory arg0) { |
1028 |
// TODO Auto-generated method stub
|
1029 |
|
1030 |
} |
1031 |
|
1032 |
public void close() throws IOException { |
1033 |
// TODO Auto-generated method stub
|
1034 |
|
1035 |
} |
1036 |
|
1037 |
public File getFile() { |
1038 |
return m_Fich;
|
1039 |
} |
1040 |
|
1041 |
public boolean isWritable() { |
1042 |
return m_Fich.canWrite();
|
1043 |
} |
1044 |
} |