root / branches / pilotoDWG / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dxf / DXFCadDriver.java @ 2326
History | View | Annotate | Download (22.9 KB)
1 |
/*
|
---|---|
2 |
* @(#)DXFMemoryDriver 29-dic-2004
|
3 |
*
|
4 |
* @author jmorell (jose.morell@gmail.com)
|
5 |
*/
|
6 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
7 |
*
|
8 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
9 |
*
|
10 |
* This program is free software; you can redistribute it and/or
|
11 |
* modify it under the terms of the GNU General Public License
|
12 |
* as published by the Free Software Foundation; either version 2
|
13 |
* of the License, or (at your option) any later version.
|
14 |
*
|
15 |
* This program is distributed in the hope that it will be useful,
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
* GNU General Public License for more details.
|
19 |
*
|
20 |
* You should have received a copy of the GNU General Public License
|
21 |
* along with this program; if not, write to the Free Software
|
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
23 |
*
|
24 |
* For more information, contact:
|
25 |
*
|
26 |
* Generalitat Valenciana
|
27 |
* Conselleria d'Infraestructures i Transport
|
28 |
* Av. Blasco Ib??ez, 50
|
29 |
* 46010 VALENCIA
|
30 |
* SPAIN
|
31 |
*
|
32 |
* +34 963862235
|
33 |
* gvsig@gva.es
|
34 |
* www.gvsig.gva.es
|
35 |
*
|
36 |
* or
|
37 |
*
|
38 |
* IVER T.I. S.A
|
39 |
* Salamanca 50
|
40 |
* 46005 Valencia
|
41 |
* Spain
|
42 |
*
|
43 |
* +34 963163400
|
44 |
* dac@iver.es
|
45 |
*/
|
46 |
package com.iver.cit.gvsig.fmap.drivers.dxf; |
47 |
|
48 |
import java.awt.Color; |
49 |
import java.awt.Font; |
50 |
import java.awt.Graphics2D; |
51 |
import java.awt.Paint; |
52 |
import java.awt.Rectangle; |
53 |
import java.awt.TexturePaint; |
54 |
import java.awt.geom.AffineTransform; |
55 |
import java.awt.geom.Arc2D; |
56 |
import java.awt.geom.Point2D; |
57 |
import java.awt.geom.Rectangle2D; |
58 |
import java.awt.geom.Ellipse2D; |
59 |
import java.awt.image.BufferedImage; |
60 |
import java.io.File; |
61 |
import java.io.IOException; |
62 |
import java.util.ArrayList; |
63 |
import java.util.Vector; |
64 |
|
65 |
import javax.swing.plaf.OptionPaneUI; |
66 |
|
67 |
import org.cresques.cts.IProjection; |
68 |
import org.cresques.cts.ProjectionPool; |
69 |
import org.cresques.io.DxfFile; |
70 |
import org.cresques.px.IObjList; |
71 |
import org.cresques.px.dxf.AcadColor; |
72 |
import org.cresques.px.dxf.DxfCalArcs; |
73 |
import org.cresques.px.dxf.DxfArc; |
74 |
import org.cresques.px.dxf.DxfCalArcs; |
75 |
import org.cresques.px.dxf.DxfCircle; |
76 |
import org.cresques.px.dxf.DxfEllipse; |
77 |
import org.cresques.px.dxf.DxfEntity; |
78 |
import org.cresques.px.dxf.DxfEntityMaker; |
79 |
import org.cresques.px.dxf.DxfFeatureMaker; |
80 |
import org.cresques.px.dxf.DxfHeaderManager; |
81 |
import org.cresques.px.dxf.DxfLine; |
82 |
import org.cresques.px.dxf.DxfLwPolyline; |
83 |
import org.cresques.px.dxf.DxfPoint; |
84 |
import org.cresques.px.dxf.DxfPolyline; |
85 |
import org.cresques.px.gml.Feature; |
86 |
import org.cresques.px.gml.InsPoint; |
87 |
import org.cresques.px.gml.LineString; |
88 |
import org.cresques.px.gml.Point; |
89 |
import org.cresques.px.gml.Polygon; |
90 |
|
91 |
import com.hardcode.gdbms.engine.data.DriverException; |
92 |
import com.hardcode.gdbms.engine.data.ReadDriver; |
93 |
import com.hardcode.gdbms.engine.values.IntValue; |
94 |
import com.hardcode.gdbms.engine.values.Value; |
95 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
96 |
import com.iver.cit.gvsig.fmap.core.FArc2D; |
97 |
import com.iver.cit.gvsig.fmap.core.FCircle2D; |
98 |
import com.iver.cit.gvsig.fmap.core.FEllipse2D; |
99 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
100 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
101 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
102 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
103 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
104 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
105 |
import com.iver.cit.gvsig.fmap.core.FShape; |
106 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
107 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
108 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
109 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
110 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
111 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
112 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
113 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
114 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
115 |
import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
116 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
117 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
118 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
119 |
|
120 |
/**
|
121 |
* Lector de entidades procedentes de un DXF. Las convierte al modelo de objetos CAD
|
122 |
* del piloto de CAD.
|
123 |
*
|
124 |
* @author jmorell (jose.morell@gmail.com)
|
125 |
* @version 29-dic-2004
|
126 |
*/
|
127 |
public class DXFCadDriver extends MemoryDriver implements WithDefaultLegend { |
128 |
private final int ID_FIELD_ID=0; |
129 |
private final int ID_FIELD_ENTITY=1; |
130 |
private final int ID_FIELD_LAYER=2; |
131 |
private final int ID_FIELD_COLOR=3; |
132 |
private final int ID_FIELD_ELEVATION=4; |
133 |
private final int ID_FIELD_THICKNESS=5; |
134 |
private final int ID_FIELD_TEXT=6; |
135 |
private final int ID_FIELD_HEIGHTTEXT=7; |
136 |
private final int ID_FIELD_ROTATIONTEXT=8; |
137 |
|
138 |
VectorialUniqueValueLegend defaultLegend; |
139 |
private String path; |
140 |
private File m_Fich; |
141 |
|
142 |
//private DxfFile.EntityFactory featureMaker;
|
143 |
private DxfFile.EntityFactory entityMaker;
|
144 |
private DxfFile dxfEntityFile;
|
145 |
private IObjList.vector entities;
|
146 |
private DriverAttributes attr = new DriverAttributes(); |
147 |
|
148 |
/**
|
149 |
* Habilita la utilizaci?n del lector del HEADER del DXF.
|
150 |
*/
|
151 |
private DxfFile.VarSettings headerManager;
|
152 |
|
153 |
/* (non-Javadoc)
|
154 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
155 |
*/
|
156 |
public void open(File f) throws IOException { |
157 |
m_Fich = f; |
158 |
} |
159 |
|
160 |
public void initialize() throws DriverIOException { |
161 |
try{
|
162 |
clearGeometryArray(); |
163 |
|
164 |
float heightText = 10; |
165 |
|
166 |
attr.setLoadedInMemory(true);
|
167 |
|
168 |
IProjection proj = ProjectionPool.get("EPSG:23030");
|
169 |
/*featureMaker = new DxfFeatureMaker(proj);
|
170 |
dxfFeatureFile = new DxfFile(proj, m_Fich.getAbsolutePath(), featureMaker);
|
171 |
dxfFeatureFile.load();
|
172 |
features = (IObjList.vector)((DxfFeatureMaker)featureMaker).getObjects();*/
|
173 |
entityMaker = new DxfEntityMaker(proj);
|
174 |
dxfEntityFile = new DxfFile(proj, m_Fich.getAbsolutePath(), entityMaker);
|
175 |
dxfEntityFile.load(); |
176 |
entities = (IObjList.vector)((DxfEntityMaker)entityMaker).getObjects(); |
177 |
|
178 |
//String acadVersion = (String)((DxfHeaderManager)headerManager).getAcadVersion();
|
179 |
//System.out.println("initialize(): acadVersion = " + acadVersion);
|
180 |
|
181 |
//int nAtt = featureMaker.getAttributes().size();
|
182 |
//int nAtt = entityMaker.getAttributes().size();
|
183 |
|
184 |
// Campos de las MemoryLayer:
|
185 |
//Value[] auxRow = new Value[9+nAtt];
|
186 |
Value[] auxRow = new Value[9]; |
187 |
ArrayList arrayFields = new ArrayList(); |
188 |
arrayFields.add("ID");
|
189 |
arrayFields.add("Entity");
|
190 |
arrayFields.add("Layer");
|
191 |
arrayFields.add("Color");
|
192 |
arrayFields.add("Elevation");
|
193 |
arrayFields.add("Thickness");
|
194 |
arrayFields.add("Text");
|
195 |
arrayFields.add("HeightText");
|
196 |
arrayFields.add("RotationText");
|
197 |
/*for (int i=0;i<nAtt;i++) {
|
198 |
String att[] = new String[2];
|
199 |
att = (String[])entityMaker.getAttributes().get(i);
|
200 |
arrayFields.add(att[0]);
|
201 |
}*/
|
202 |
|
203 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
204 |
|
205 |
for (int i=0;i<entities.size();i++) { |
206 |
|
207 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
|
208 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
|
209 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
210 |
|
211 |
//Feature fea = (Feature)entities.get(i);
|
212 |
DxfEntity ent = (DxfEntity)entities.get(i); |
213 |
if (ent instanceof DxfPoint) { |
214 |
DxfPoint point = (DxfPoint)ent; |
215 |
Point2D pto = new Point2D.Double(); |
216 |
pto = (Point2D.Double)point.getPt();
|
217 |
FShape nuevoShp; |
218 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
219 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
220 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
221 |
int auxInt = Integer.parseInt("0"); |
222 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
223 |
double auxE = Double.parseDouble("0.0"); |
224 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
225 |
double auxT = Double.parseDouble("0.0"); |
226 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
227 |
nuevoShp = new FPoint2D(pto.getX(),pto.getY());
|
228 |
addShape(nuevoShp, auxRow); |
229 |
} else if (ent instanceof DxfLine) { |
230 |
DxfLine dxfLine = (DxfLine)ent; |
231 |
Point2D init = dxfLine.getPts()[0]; |
232 |
Point2D end = dxfLine.getPts()[1]; |
233 |
GeneralPathX gp = new GeneralPathX();
|
234 |
gp.moveTo(init.getX(), init.getY()); |
235 |
gp.lineTo(end.getX(), end.getY()); |
236 |
FPolyline2D fLine = new FPolyline2D(gp);
|
237 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
238 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
239 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
240 |
int auxInt = Integer.parseInt("0"); |
241 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
242 |
double auxE = Double.parseDouble("0.0"); |
243 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
244 |
double auxT = Double.parseDouble("0.0"); |
245 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
246 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
247 |
addShape(fLine, auxRow); |
248 |
} else if (ent instanceof DxfPolyline) { |
249 |
DxfPolyline dxfPolyline = (DxfPolyline)ent; |
250 |
int vertexNumber = dxfPolyline.getPts().size();
|
251 |
//System.out.println("DxfCadDriver.initialize(): vertexNumber = " + vertexNumber);
|
252 |
int flag = dxfPolyline.getFlags();
|
253 |
int geomNumber = 0; |
254 |
// jmorell, 050406: correcci?n de un bug que imped?a cargar polil?neas
|
255 |
// 3D en el piloto ...
|
256 |
if (flag==0 || flag==2 || flag==4 || flag==8 || flag==16 || flag==32 || flag==64 || flag==128) { |
257 |
geomNumber = vertexNumber-1;
|
258 |
} else if (flag==1 || flag==3 || flag==5 || flag==9 || flag==17 || flag==33 || flag==65 || flag==129) { |
259 |
geomNumber = vertexNumber; |
260 |
} |
261 |
//System.out.println("DxfCadDriver.initialize(): geomNumber = " + geomNumber);
|
262 |
IGeometry[] geoms = new IGeometry[geomNumber]; |
263 |
//System.out.println("DxfCadDriver.initialize(): geomNumber = " + geomNumber);
|
264 |
//System.out.println("i = " + i);
|
265 |
for (int j=0;j<geomNumber;j++) { |
266 |
Point2D init = (Point2D)dxfPolyline.getPts().get(j); |
267 |
Point2D end = new Point2D.Double(); |
268 |
if (j==geomNumber-1 && (flag==1 || flag==3 || flag==5 || flag==9 || flag==17 || flag==33 || flag==65 || flag==129)) { |
269 |
end = (Point2D)dxfPolyline.getPts().get(0); |
270 |
} else {
|
271 |
end = (Point2D)dxfPolyline.getPts().get(j+1); |
272 |
} |
273 |
//System.out.println("DxfCadDriver.initialize(): dxfPolyline.getBulges().size() = " + dxfPolyline.getBulges().size());
|
274 |
if (((Double)dxfPolyline.getBulges().get(j)).doubleValue()==0 || (init.getX()==end.getX() && init.getY()==end.getY())) { |
275 |
GeneralPathX gp = new GeneralPathX();
|
276 |
gp.moveTo(init.getX(), init.getY()); |
277 |
gp.lineTo(end.getX(), end.getY()); |
278 |
//System.out.println("flag = " + flag);
|
279 |
//if (j==geomNumber-1 && flag==1) {
|
280 |
/*Point2D first = (Point2D)dxfPolyline.getPts().get(0);
|
281 |
gp.lineTo(first.getX(), first.getY());*/
|
282 |
/*System.out.println("Polyline: Cierra el gp.");
|
283 |
gp.closePath();
|
284 |
}*/
|
285 |
geoms[j] = (IGeometry)ShapeFactory.createPolyline2D(gp); |
286 |
} else if (((Double)dxfPolyline.getBulges().get(j)).doubleValue()>0 && !(init.getX()==end.getX() && init.getY()==end.getY())) { |
287 |
//IGeometry arc = (IGeometry)ShapeFactory.createArc();
|
288 |
DxfCalArcs dxfCalArcs = new DxfCalArcs(init, end, ((Double)dxfPolyline.getBulges().get(j)).doubleValue()); |
289 |
Vector arc = (Vector)dxfCalArcs.getCentralPoint(); |
290 |
Point2D cent = (Point2D)arc.get(0); |
291 |
//System.out.println("init = " + init);
|
292 |
//System.out.println("cent = " + cent);
|
293 |
//System.out.println("end = " + end);
|
294 |
geoms[j] = (IGeometry)ShapeFactory.createArc(init, cent, end); |
295 |
} else if (((Double)dxfPolyline.getBulges().get(j)).doubleValue()<0 && !(init.getX()==end.getX() && init.getY()==end.getY())) { |
296 |
//IGeometry arc = (IGeometry)ShapeFactory.createArc();
|
297 |
DxfCalArcs dxfCalArcs = new DxfCalArcs(init, end, ((Double)dxfPolyline.getBulges().get(j)).doubleValue()); |
298 |
Vector arc = (Vector)dxfCalArcs.getCentralPoint(); |
299 |
Point2D cent = (Point2D)arc.get(0); |
300 |
//System.out.println("init = " + init);
|
301 |
//System.out.println("cent = " + cent);
|
302 |
//System.out.println("end = " + end);
|
303 |
geoms[j] = (IGeometry)ShapeFactory.createArc(init, cent, end); |
304 |
//((FArc2D)geoms[j].getShapes()[0]).setNegativeBulgeFlag(true);
|
305 |
} |
306 |
} |
307 |
FGeometryCollection gc = new FGeometryCollection(geoms);
|
308 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
309 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
310 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
311 |
int auxInt = Integer.parseInt("0"); |
312 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
313 |
double auxE = Double.parseDouble("0.0"); |
314 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
315 |
double auxT = Double.parseDouble("0.0"); |
316 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
317 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
318 |
//System.out.println("DxfCadDriver.initialize(): gc.getBounds2D() = " + gc.getBounds2D());
|
319 |
addGeometry(gc, auxRow); |
320 |
/*} else if (ent instanceof DxfLwPolyline) {
|
321 |
DxfLwPolyline dxfLwPolyline = (DxfLwPolyline)ent;
|
322 |
int vertexNumber = dxfLwPolyline.getPts().size();
|
323 |
int geomNumber = vertexNumber-1;
|
324 |
int flag = dxfLwPolyline.getFlags();
|
325 |
IGeometry[] geoms = new IGeometry[geomNumber];
|
326 |
GeneralPathX gp = new GeneralPathX();
|
327 |
for (int j=0;j<geomNumber;j++) {
|
328 |
// lines
|
329 |
Point2D init = (Point2D)dxfLwPolyline.getPts().get(j);
|
330 |
Point2D end = (Point2D)dxfLwPolyline.getPts().get(j+1);
|
331 |
gp = new GeneralPathX();
|
332 |
gp.moveTo(init.getX(), init.getY());
|
333 |
gp.lineTo(end.getX(), end.getY());
|
334 |
System.out.println("flag = " + flag);
|
335 |
if (j==geomNumber-1 && flag==1) {
|
336 |
/*Point2D first = (Point2D)dxfLwPolyline.getPts().get(0);
|
337 |
gp.lineTo(first.getX(), first.getY());*/
|
338 |
/*System.out.println("LwPolyline: Cierra el gp.");
|
339 |
gp.closePath();
|
340 |
}
|
341 |
geoms[j] = (IGeometry)ShapeFactory.createPolyline2D(gp);
|
342 |
//IGeometry arc = (IGeometry)ShapeFactory.createArc();
|
343 |
}
|
344 |
FGeometryCollection gc = new FGeometryCollection(geoms);
|
345 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
346 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
|
347 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
|
348 |
int auxInt = Integer.parseInt("0");
|
349 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
350 |
double auxE = Double.parseDouble("0.0");
|
351 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
352 |
double auxT = Double.parseDouble("0.0");
|
353 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
354 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
355 |
addGeometry(gc, auxRow);*/
|
356 |
} else if (ent instanceof DxfArc) { |
357 |
DxfArc arc = (DxfArc)ent; |
358 |
Point2D pc = arc.getCentralPoint();
|
359 |
Point2D in = arc.getInit();
|
360 |
Point2D e = arc.getEnd();
|
361 |
// jmorell, 050405: Cuando el ?ngulo es menor que 2 grados
|
362 |
if (pc.getX()==e.getX() && pc.getY()==e.getY()) {
|
363 |
Point2D c = arc.getCenter();
|
364 |
double r = arc.getRadius();
|
365 |
double ia = arc.getInitAngle();
|
366 |
double ea = arc.getEndAngle();
|
367 |
double middleAngle = (ia+ea)/2; |
368 |
if (ia>ea) {
|
369 |
ea = ea + 360;
|
370 |
double a = ea - ia;
|
371 |
double mangle = a/2; |
372 |
middleAngle = ia + mangle; |
373 |
} |
374 |
pc = new Point2D.Double(c.getX()+r*Math.sin(middleAngle), c.getY()+r*Math.cos(middleAngle)); |
375 |
} |
376 |
//System.out.println("in = " + in);
|
377 |
//System.out.println("pc = " + pc);
|
378 |
//System.out.println("e = " + e);
|
379 |
Arc2D arco = TrigonometricalFunctions.createArc(in, pc, e);
|
380 |
FArc2D fArc = new FArc2D(new GeneralPathX(arco),in,pc,e); |
381 |
//FArc2D fArc = new FArc2D(gp, c, in, e);
|
382 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
383 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
384 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
385 |
int auxInt = Integer.parseInt("0"); |
386 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
387 |
double auxE = Double.parseDouble("0.0"); |
388 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
389 |
double auxT = Double.parseDouble("0.0"); |
390 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
391 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
392 |
addShape(fArc, auxRow); |
393 |
} else if (ent instanceof DxfCircle) { |
394 |
DxfCircle circle = (DxfCircle)ent; |
395 |
Point2D c = circle.getCenter();
|
396 |
double r = circle.getRadius();
|
397 |
//System.out.println("r = " + r);
|
398 |
//System.out.println("c = " + c);
|
399 |
Arc2D.Double arc = new Arc2D.Double(c.getX()-r , c.getY()-r , 2*r , 2*r , 0 , 360 , Arc2D.OPEN); |
400 |
FCircle2D fCircle = new FCircle2D(new GeneralPathX(arc),c,r); |
401 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
402 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
403 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
404 |
int auxInt = Integer.parseInt("0"); |
405 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
406 |
double auxE = Double.parseDouble("0.0"); |
407 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
408 |
double auxT = Double.parseDouble("0.0"); |
409 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
410 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
411 |
addShape(fCircle, auxRow); |
412 |
} else if (ent instanceof DxfEllipse) { |
413 |
DxfEllipse elip = (DxfEllipse)ent; |
414 |
Point2D pt1 = elip.getPts()[0]; |
415 |
Point2D pt2 = elip.getPts()[1]; |
416 |
double semiMinorAxisL = elip.getMinorAxisLength()/2.0; |
417 |
//System.out.println("semiMinorAxisL = " + semiMinorAxisL);
|
418 |
|
419 |
double xAxis = pt1.distance(pt2);
|
420 |
|
421 |
Arc2D.Double arc = new Arc2D.Double(pt1.getX(), |
422 |
pt1.getY() - semiMinorAxisL, xAxis, 2 * semiMinorAxisL, 0, 360, Arc2D.OPEN); |
423 |
Point2D rotationPoint = new Point2D.Double(pt1.getX() + xAxis /2, pt1.getY()); |
424 |
|
425 |
// double angle = Math.atan2(axis1End.getX() - axis1Start.getX(),
|
426 |
// axis1End.getY() - axis1Start.getY());
|
427 |
double angle = TrigonometricalFunctions.getAngle(pt1, pt2);
|
428 |
// double distortedAngle = Math.atan2(Math.sin(angle) * xAxis, Math.cos(angle) * 2 * axis2Length);
|
429 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, pt1.getX(), pt1.getY()); |
430 |
GeneralPathX gp = new GeneralPathX(arc);
|
431 |
gp.transform(mT); |
432 |
|
433 |
FEllipse2D fEllipse = new FEllipse2D(new GeneralPathX(gp),pt1,pt2,semiMinorAxisL); |
434 |
|
435 |
//FEllipse2D fEllipse = (IGeometry)ShapeFactory.createEllipse(pt1,pt2,semiMinorAxisL);
|
436 |
|
437 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
438 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
439 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
440 |
int auxInt = Integer.parseInt("0"); |
441 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
442 |
double auxE = Double.parseDouble("0.0"); |
443 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
444 |
double auxT = Double.parseDouble("0.0"); |
445 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
446 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
447 |
addShape(fEllipse, auxRow); |
448 |
} else {
|
449 |
System.out.println("Detectada entidad desconocida"); |
450 |
} |
451 |
} |
452 |
|
453 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
454 |
defaultLegend.setFieldName("Color");
|
455 |
defaultLegend.setLabelField("Text");
|
456 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
|
457 |
defaultLegend.getDefaultSymbol().setShapeVisible(false);
|
458 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
|
459 |
defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9)); |
460 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
|
461 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
462 |
defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
463 |
defaultLegend.getDefaultSymbol().setSize(3);
|
464 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true);
|
465 |
|
466 |
defaultLegend.setLabelHeightField("HeightText");
|
467 |
defaultLegend.setLabelRotationField("RotationText");
|
468 |
|
469 |
ReadDriver rs = this;
|
470 |
IntValue clave; |
471 |
FSymbol theSymbol = null;
|
472 |
|
473 |
try {
|
474 |
// TODO: Provisional hasta que cambiemos los s?mbolos.
|
475 |
/*BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
|
476 |
Graphics2D big = bi.createGraphics();
|
477 |
Color color=new Color(0,0,0,0);
|
478 |
big.setBackground(color);
|
479 |
big.clearRect(0, 0, 5, 5);
|
480 |
Paint fillProv = null;
|
481 |
Rectangle2D rProv = new Rectangle();
|
482 |
rProv.setFrame(0, 0,5,5);
|
483 |
fillProv = new TexturePaint(bi,rProv);*/
|
484 |
|
485 |
for (long j = 0; j < rs.getRowCount(); j++) |
486 |
{ |
487 |
clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR); |
488 |
if (defaultLegend.getSymbolByValue(clave) == null) |
489 |
{ |
490 |
theSymbol = new FSymbol(getShapeType());
|
491 |
theSymbol.setDescription(clave.toString()); |
492 |
theSymbol.setColor(AcadColor.getColor(clave.getValue())); |
493 |
//theSymbol.setFill(fillProv);
|
494 |
// 050202, jmorell: Asigna los colores de Autocad a los bordes
|
495 |
// de los pol?gonos.
|
496 |
theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue())); |
497 |
|
498 |
//theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
|
499 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
500 |
theSymbol.setSize(3);
|
501 |
theSymbol.setSizeInPixels(true);
|
502 |
|
503 |
defaultLegend.addSymbol(clave, theSymbol); |
504 |
} |
505 |
} // for
|
506 |
} catch (DriverException e) {
|
507 |
e.printStackTrace(); |
508 |
throw new IOException("Error al poner la leyenda por defecto en el DXF"); |
509 |
} |
510 |
}catch (Exception e){ ///TODO Esta excepci?n es solo para el piloto. |
511 |
throw new DriverIOException(e); |
512 |
//e.printStackTrace();
|
513 |
//throw new DXFFormatException(e);
|
514 |
} |
515 |
} |
516 |
|
517 |
/* (non-Javadoc)
|
518 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
519 |
*/
|
520 |
public boolean accept(File f) { |
521 |
return f.getName().toUpperCase().endsWith("DXF"); |
522 |
} |
523 |
|
524 |
/* (non-Javadoc)
|
525 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
526 |
*/
|
527 |
public int getShapeType() { |
528 |
return FShape.MULTI;
|
529 |
} |
530 |
|
531 |
/* (non-Javadoc)
|
532 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
533 |
*/
|
534 |
public String getName() { |
535 |
return "gvSIG DXF CAD Model Driver"; |
536 |
} |
537 |
|
538 |
/* (non-Javadoc)
|
539 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
540 |
*/
|
541 |
public Legend getDefaultLegend() {
|
542 |
return defaultLegend;
|
543 |
} |
544 |
|
545 |
/* (non-Javadoc)
|
546 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
547 |
*/
|
548 |
public DriverAttributes getDriverAttributes() {
|
549 |
return attr;
|
550 |
} |
551 |
|
552 |
} |