svn-gvsig-desktop / branches / pilotoDWG / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dxf / DXFCadDriver.java @ 1725
History | View | Annotate | Download (21 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 org.cresques.cts.IProjection; |
66 |
import org.cresques.cts.ProjectionPool; |
67 |
import org.cresques.io.DxfFile; |
68 |
import org.cresques.px.IObjList; |
69 |
import org.cresques.px.dxf.AcadColor; |
70 |
import org.cresques.px.dxf.DxfCalArcs; |
71 |
import org.cresques.px.dxf.DxfArc; |
72 |
import org.cresques.px.dxf.DxfCalArcs; |
73 |
import org.cresques.px.dxf.DxfCircle; |
74 |
import org.cresques.px.dxf.DxfEllipse; |
75 |
import org.cresques.px.dxf.DxfEntity; |
76 |
import org.cresques.px.dxf.DxfEntityMaker; |
77 |
import org.cresques.px.dxf.DxfFeatureMaker; |
78 |
import org.cresques.px.dxf.DxfHeaderManager; |
79 |
import org.cresques.px.dxf.DxfLine; |
80 |
import org.cresques.px.dxf.DxfLwPolyline; |
81 |
import org.cresques.px.dxf.DxfPoint; |
82 |
import org.cresques.px.dxf.DxfPolyline; |
83 |
import org.cresques.px.gml.Feature; |
84 |
import org.cresques.px.gml.InsPoint; |
85 |
import org.cresques.px.gml.LineString; |
86 |
import org.cresques.px.gml.Point; |
87 |
import org.cresques.px.gml.Polygon; |
88 |
|
89 |
import com.hardcode.gdbms.engine.data.DriverException; |
90 |
import com.hardcode.gdbms.engine.data.ReadDriver; |
91 |
import com.hardcode.gdbms.engine.values.IntValue; |
92 |
import com.hardcode.gdbms.engine.values.Value; |
93 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
94 |
import com.iver.cit.gvsig.fmap.core.FArc2D; |
95 |
import com.iver.cit.gvsig.fmap.core.FCircle2D; |
96 |
import com.iver.cit.gvsig.fmap.core.FEllipse2D; |
97 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
98 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
99 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
100 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
101 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
102 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
103 |
import com.iver.cit.gvsig.fmap.core.FShape; |
104 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
105 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
106 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
107 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
108 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
109 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
110 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
111 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
112 |
import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
113 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
114 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
115 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
116 |
|
117 |
/**
|
118 |
* Lector de entidades procedentes de un DXF. Las convierte al modelo de objetos CAD
|
119 |
* del piloto de CAD.
|
120 |
*
|
121 |
* @author jmorell (jose.morell@gmail.com)
|
122 |
* @version 29-dic-2004
|
123 |
*/
|
124 |
public class DXFCadDriver extends MemoryDriver implements WithDefaultLegend { |
125 |
private final int ID_FIELD_ID=0; |
126 |
private final int ID_FIELD_ENTITY=1; |
127 |
private final int ID_FIELD_LAYER=2; |
128 |
private final int ID_FIELD_COLOR=3; |
129 |
private final int ID_FIELD_ELEVATION=4; |
130 |
private final int ID_FIELD_THICKNESS=5; |
131 |
private final int ID_FIELD_TEXT=6; |
132 |
private final int ID_FIELD_HEIGHTTEXT=7; |
133 |
private final int ID_FIELD_ROTATIONTEXT=8; |
134 |
|
135 |
VectorialUniqueValueLegend defaultLegend; |
136 |
private String path; |
137 |
private File m_Fich; |
138 |
|
139 |
//private DxfFile.EntityFactory featureMaker;
|
140 |
private DxfFile.EntityFactory entityMaker;
|
141 |
private DxfFile dxfEntityFile;
|
142 |
private IObjList.vector entities;
|
143 |
private DriverAttributes attr = new DriverAttributes(); |
144 |
|
145 |
/**
|
146 |
* Habilita la utilizaci?n del lector del HEADER del DXF.
|
147 |
*/
|
148 |
private DxfFile.VarSettings headerManager;
|
149 |
|
150 |
/* (non-Javadoc)
|
151 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
152 |
*/
|
153 |
public void open(File f) throws IOException { |
154 |
m_Fich = f; |
155 |
} |
156 |
|
157 |
public void initialize() throws IOException { |
158 |
clearGeometryArray(); |
159 |
|
160 |
float heightText = 10; |
161 |
|
162 |
attr.setLoadedInMemory(true);
|
163 |
|
164 |
IProjection proj = ProjectionPool.get("EPSG:23030");
|
165 |
/*featureMaker = new DxfFeatureMaker(proj);
|
166 |
dxfFeatureFile = new DxfFile(proj, m_Fich.getAbsolutePath(), featureMaker);
|
167 |
dxfFeatureFile.load();
|
168 |
features = (IObjList.vector)((DxfFeatureMaker)featureMaker).getObjects();*/
|
169 |
entityMaker = new DxfEntityMaker(proj);
|
170 |
dxfEntityFile = new DxfFile(proj, m_Fich.getAbsolutePath(), entityMaker);
|
171 |
dxfEntityFile.load(); |
172 |
entities = (IObjList.vector)((DxfEntityMaker)entityMaker).getObjects(); |
173 |
|
174 |
//String acadVersion = (String)((DxfHeaderManager)headerManager).getAcadVersion();
|
175 |
//System.out.println("initialize(): acadVersion = " + acadVersion);
|
176 |
|
177 |
//int nAtt = featureMaker.getAttributes().size();
|
178 |
//int nAtt = entityMaker.getAttributes().size();
|
179 |
|
180 |
// Campos de las MemoryLayer:
|
181 |
//Value[] auxRow = new Value[9+nAtt];
|
182 |
Value[] auxRow = new Value[9]; |
183 |
ArrayList arrayFields = new ArrayList(); |
184 |
arrayFields.add("ID");
|
185 |
arrayFields.add("Entity");
|
186 |
arrayFields.add("Layer");
|
187 |
arrayFields.add("Color");
|
188 |
arrayFields.add("Elevation");
|
189 |
arrayFields.add("Thickness");
|
190 |
arrayFields.add("Text");
|
191 |
arrayFields.add("HeightText");
|
192 |
arrayFields.add("RotationText");
|
193 |
/*for (int i=0;i<nAtt;i++) {
|
194 |
String att[] = new String[2];
|
195 |
att = (String[])entityMaker.getAttributes().get(i);
|
196 |
arrayFields.add(att[0]);
|
197 |
}*/
|
198 |
|
199 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
200 |
|
201 |
for (int i=0;i<entities.size();i++) { |
202 |
|
203 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
|
204 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
|
205 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
206 |
|
207 |
//Feature fea = (Feature)entities.get(i);
|
208 |
DxfEntity ent = (DxfEntity)entities.get(i); |
209 |
if (ent instanceof DxfPoint) { |
210 |
DxfPoint point = (DxfPoint)ent; |
211 |
Point2D pto = new Point2D.Double(); |
212 |
pto = (Point2D.Double)point.getPt();
|
213 |
FShape nuevoShp; |
214 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
215 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
216 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
217 |
int auxInt = Integer.parseInt("0"); |
218 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
219 |
double auxE = Double.parseDouble("0.0"); |
220 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
221 |
double auxT = Double.parseDouble("0.0"); |
222 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
223 |
nuevoShp = new FPoint2D(pto.getX(),pto.getY());
|
224 |
addShape(nuevoShp, auxRow); |
225 |
} else if (ent instanceof DxfLine) { |
226 |
DxfLine dxfLine = (DxfLine)ent; |
227 |
Point2D init = dxfLine.getPts()[0]; |
228 |
Point2D end = dxfLine.getPts()[1]; |
229 |
GeneralPathX gp = new GeneralPathX();
|
230 |
gp.moveTo(init.getX(), init.getY()); |
231 |
gp.lineTo(end.getX(), end.getY()); |
232 |
FPolyline2D fLine = new FPolyline2D(gp);
|
233 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
234 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
235 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
236 |
int auxInt = Integer.parseInt("0"); |
237 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
238 |
double auxE = Double.parseDouble("0.0"); |
239 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
240 |
double auxT = Double.parseDouble("0.0"); |
241 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
242 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
243 |
addShape(fLine, auxRow); |
244 |
} else if (ent instanceof DxfPolyline) { |
245 |
DxfPolyline dxfPolyline = (DxfPolyline)ent; |
246 |
int vertexNumber = dxfPolyline.getPts().size();
|
247 |
int flag = dxfPolyline.getFlags();
|
248 |
int geomNumber = 0; |
249 |
if (flag==0 || flag==128) { |
250 |
geomNumber = vertexNumber-1;
|
251 |
} else if (flag==1 || flag==129){ |
252 |
geomNumber = vertexNumber; |
253 |
} |
254 |
IGeometry[] geoms = new IGeometry[geomNumber]; |
255 |
for (int j=0;j<geomNumber;j++) { |
256 |
Point2D init = (Point2D)dxfPolyline.getPts().get(j); |
257 |
Point2D end = new Point2D.Double(); |
258 |
if (j==geomNumber-1 && (flag==1 || flag==129)) { |
259 |
end = (Point2D)dxfPolyline.getPts().get(0); |
260 |
} else {
|
261 |
end = (Point2D)dxfPolyline.getPts().get(j+1); |
262 |
} |
263 |
if (((Double)dxfPolyline.getBulges().get(j)).doubleValue()==0) { |
264 |
GeneralPathX gp = new GeneralPathX();
|
265 |
gp.moveTo(init.getX(), init.getY()); |
266 |
gp.lineTo(end.getX(), end.getY()); |
267 |
//System.out.println("flag = " + flag);
|
268 |
//if (j==geomNumber-1 && flag==1) {
|
269 |
/*Point2D first = (Point2D)dxfPolyline.getPts().get(0);
|
270 |
gp.lineTo(first.getX(), first.getY());*/
|
271 |
/*System.out.println("Polyline: Cierra el gp.");
|
272 |
gp.closePath();
|
273 |
}*/
|
274 |
geoms[j] = (IGeometry)ShapeFactory.createPolyline2D(gp); |
275 |
} else if (((Double)dxfPolyline.getBulges().get(j)).doubleValue()>0) { |
276 |
//IGeometry arc = (IGeometry)ShapeFactory.createArc();
|
277 |
DxfCalArcs dxfCalArcs = new DxfCalArcs(init, end, ((Double)dxfPolyline.getBulges().get(j)).doubleValue()); |
278 |
Vector arc = (Vector)dxfCalArcs.getCentralPoint(); |
279 |
Point2D cent = (Point2D)arc.get(0); |
280 |
//System.out.println("init = " + init);
|
281 |
//System.out.println("cent = " + cent);
|
282 |
//System.out.println("end = " + end);
|
283 |
geoms[j] = (IGeometry)ShapeFactory.createArc(init, cent, end); |
284 |
} else if (((Double)dxfPolyline.getBulges().get(j)).doubleValue()<0) { |
285 |
//IGeometry arc = (IGeometry)ShapeFactory.createArc();
|
286 |
DxfCalArcs dxfCalArcs = new DxfCalArcs(init, end, ((Double)dxfPolyline.getBulges().get(j)).doubleValue()); |
287 |
Vector arc = (Vector)dxfCalArcs.getCentralPoint(); |
288 |
Point2D cent = (Point2D)arc.get(0); |
289 |
//System.out.println("init = " + init);
|
290 |
//System.out.println("cent = " + cent);
|
291 |
//System.out.println("end = " + end);
|
292 |
geoms[j] = (IGeometry)ShapeFactory.createArc(init, cent, end); |
293 |
//((FArc2D)geoms[j].getShapes()[0]).setNegativeBulgeFlag(true);
|
294 |
} |
295 |
} |
296 |
FGeometryCollection gc = new FGeometryCollection(geoms);
|
297 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
298 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
299 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
300 |
int auxInt = Integer.parseInt("0"); |
301 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
302 |
double auxE = Double.parseDouble("0.0"); |
303 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
304 |
double auxT = Double.parseDouble("0.0"); |
305 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
306 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
307 |
addGeometry(gc, auxRow); |
308 |
/*} else if (ent instanceof DxfLwPolyline) {
|
309 |
DxfLwPolyline dxfLwPolyline = (DxfLwPolyline)ent;
|
310 |
int vertexNumber = dxfLwPolyline.getPts().size();
|
311 |
int geomNumber = vertexNumber-1;
|
312 |
int flag = dxfLwPolyline.getFlags();
|
313 |
IGeometry[] geoms = new IGeometry[geomNumber];
|
314 |
GeneralPathX gp = new GeneralPathX();
|
315 |
for (int j=0;j<geomNumber;j++) {
|
316 |
// lines
|
317 |
Point2D init = (Point2D)dxfLwPolyline.getPts().get(j);
|
318 |
Point2D end = (Point2D)dxfLwPolyline.getPts().get(j+1);
|
319 |
gp = new GeneralPathX();
|
320 |
gp.moveTo(init.getX(), init.getY());
|
321 |
gp.lineTo(end.getX(), end.getY());
|
322 |
System.out.println("flag = " + flag);
|
323 |
if (j==geomNumber-1 && flag==1) {
|
324 |
/*Point2D first = (Point2D)dxfLwPolyline.getPts().get(0);
|
325 |
gp.lineTo(first.getX(), first.getY());*/
|
326 |
/*System.out.println("LwPolyline: Cierra el gp.");
|
327 |
gp.closePath();
|
328 |
}
|
329 |
geoms[j] = (IGeometry)ShapeFactory.createPolyline2D(gp);
|
330 |
//IGeometry arc = (IGeometry)ShapeFactory.createArc();
|
331 |
}
|
332 |
FGeometryCollection gc = new FGeometryCollection(geoms);
|
333 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
334 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
|
335 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
|
336 |
int auxInt = Integer.parseInt("0");
|
337 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
338 |
double auxE = Double.parseDouble("0.0");
|
339 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
340 |
double auxT = Double.parseDouble("0.0");
|
341 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
342 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
343 |
addGeometry(gc, auxRow);*/
|
344 |
} else if (ent instanceof DxfArc) { |
345 |
DxfArc arc = (DxfArc)ent; |
346 |
Point2D pc = arc.getCentralPoint();
|
347 |
Point2D in = arc.getInit();
|
348 |
Point2D e = arc.getEnd();
|
349 |
Arc2D arco = TrigonometricalFunctions.createArc(in, pc, e);
|
350 |
FArc2D fArc = new FArc2D(new GeneralPathX(arco),in,pc,e); |
351 |
//FArc2D fArc = new FArc2D(gp, c, in, e);
|
352 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
353 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
354 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
355 |
int auxInt = Integer.parseInt("0"); |
356 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
357 |
double auxE = Double.parseDouble("0.0"); |
358 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
359 |
double auxT = Double.parseDouble("0.0"); |
360 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
361 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
362 |
addShape(fArc, auxRow); |
363 |
} else if (ent instanceof DxfCircle) { |
364 |
DxfCircle circle = (DxfCircle)ent; |
365 |
Point2D c = circle.getCenter();
|
366 |
double r = circle.getRadius();
|
367 |
//System.out.println("r = " + r);
|
368 |
//System.out.println("c = " + c);
|
369 |
Arc2D.Double arc = new Arc2D.Double(c.getX()-r , c.getY()-r , 2*r , 2*r , 0 , 360 , Arc2D.OPEN); |
370 |
FCircle2D fCircle = new FCircle2D(new GeneralPathX(arc),c,r); |
371 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
372 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
373 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
374 |
int auxInt = Integer.parseInt("0"); |
375 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
376 |
double auxE = Double.parseDouble("0.0"); |
377 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
378 |
double auxT = Double.parseDouble("0.0"); |
379 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
380 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
381 |
addShape(fCircle, auxRow); |
382 |
} else if (ent instanceof DxfEllipse) { |
383 |
DxfEllipse elip = (DxfEllipse)ent; |
384 |
Point2D pt1 = elip.getPts()[0]; |
385 |
Point2D pt2 = elip.getPts()[1]; |
386 |
double semiMinorAxisL = elip.getMinorAxisLength()/2.0; |
387 |
//System.out.println("semiMinorAxisL = " + semiMinorAxisL);
|
388 |
|
389 |
double xAxis = pt1.distance(pt2);
|
390 |
|
391 |
Arc2D.Double arc = new Arc2D.Double(pt1.getX(), |
392 |
pt1.getY() - semiMinorAxisL, xAxis, 2 * semiMinorAxisL, 0, 360, Arc2D.OPEN); |
393 |
Point2D rotationPoint = new Point2D.Double(pt1.getX() + xAxis /2, pt1.getY()); |
394 |
|
395 |
// double angle = Math.atan2(axis1End.getX() - axis1Start.getX(),
|
396 |
// axis1End.getY() - axis1Start.getY());
|
397 |
double angle = TrigonometricalFunctions.getAngle(pt1, pt2);
|
398 |
// double distortedAngle = Math.atan2(Math.sin(angle) * xAxis, Math.cos(angle) * 2 * axis2Length);
|
399 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, pt1.getX(), pt1.getY()); |
400 |
GeneralPathX gp = new GeneralPathX(arc);
|
401 |
gp.transform(mT); |
402 |
|
403 |
FEllipse2D fEllipse = new FEllipse2D(new GeneralPathX(gp),pt1,pt2,semiMinorAxisL); |
404 |
|
405 |
//FEllipse2D fEllipse = (IGeometry)ShapeFactory.createEllipse(pt1,pt2,semiMinorAxisL);
|
406 |
|
407 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
408 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity")); |
409 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer")); |
410 |
int auxInt = Integer.parseInt("0"); |
411 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
412 |
double auxE = Double.parseDouble("0.0"); |
413 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
414 |
double auxT = Double.parseDouble("0.0"); |
415 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
416 |
//FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),0);
|
417 |
addShape(fEllipse, auxRow); |
418 |
} else {
|
419 |
System.out.println("Detectada entidad desconocida"); |
420 |
} |
421 |
} |
422 |
|
423 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
424 |
defaultLegend.setFieldName("Color");
|
425 |
defaultLegend.setLabelField("Text");
|
426 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
|
427 |
defaultLegend.getDefaultSymbol().setShapeVisible(false);
|
428 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
|
429 |
defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9)); |
430 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
|
431 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
432 |
defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
433 |
defaultLegend.getDefaultSymbol().setSize(3);
|
434 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true);
|
435 |
|
436 |
defaultLegend.setLabelHeightField("HeightText");
|
437 |
defaultLegend.setLabelRotationField("RotationText");
|
438 |
|
439 |
ReadDriver rs = this;
|
440 |
IntValue clave; |
441 |
FSymbol theSymbol = null;
|
442 |
|
443 |
try {
|
444 |
// TODO: Provisional hasta que cambiemos los s?mbolos.
|
445 |
/*BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
|
446 |
Graphics2D big = bi.createGraphics();
|
447 |
Color color=new Color(0,0,0,0);
|
448 |
big.setBackground(color);
|
449 |
big.clearRect(0, 0, 5, 5);
|
450 |
Paint fillProv = null;
|
451 |
Rectangle2D rProv = new Rectangle();
|
452 |
rProv.setFrame(0, 0,5,5);
|
453 |
fillProv = new TexturePaint(bi,rProv);*/
|
454 |
|
455 |
for (long j = 0; j < rs.getRowCount(); j++) |
456 |
{ |
457 |
clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR); |
458 |
if (defaultLegend.getSymbolByValue(clave) == null) |
459 |
{ |
460 |
theSymbol = new FSymbol(getShapeType());
|
461 |
theSymbol.setDescription(clave.toString()); |
462 |
theSymbol.setColor(AcadColor.getColor(clave.getValue())); |
463 |
//theSymbol.setFill(fillProv);
|
464 |
// 050202, jmorell: Asigna los colores de Autocad a los bordes
|
465 |
// de los pol?gonos.
|
466 |
theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue())); |
467 |
|
468 |
//theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
|
469 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
470 |
theSymbol.setSize(3);
|
471 |
theSymbol.setSizeInPixels(true);
|
472 |
|
473 |
defaultLegend.addSymbol(clave, theSymbol); |
474 |
} |
475 |
} // for
|
476 |
} catch (DriverException e) {
|
477 |
e.printStackTrace(); |
478 |
throw new IOException("Error al poner la leyenda por defecto en el DXF"); |
479 |
} |
480 |
} |
481 |
|
482 |
/* (non-Javadoc)
|
483 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
484 |
*/
|
485 |
public boolean accept(File f) { |
486 |
return f.getName().toUpperCase().endsWith("DXF"); |
487 |
} |
488 |
|
489 |
/* (non-Javadoc)
|
490 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
491 |
*/
|
492 |
public int getShapeType() { |
493 |
return FShape.MULTI;
|
494 |
} |
495 |
|
496 |
/* (non-Javadoc)
|
497 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
498 |
*/
|
499 |
public String getName() { |
500 |
return "gvSIG DXF CAD Model Driver"; |
501 |
} |
502 |
|
503 |
/* (non-Javadoc)
|
504 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
505 |
*/
|
506 |
public Legend getDefaultLegend() {
|
507 |
return defaultLegend;
|
508 |
} |
509 |
|
510 |
/* (non-Javadoc)
|
511 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
512 |
*/
|
513 |
public DriverAttributes getDriverAttributes() {
|
514 |
return attr;
|
515 |
} |
516 |
|
517 |
} |