svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfFeatureMaker.java @ 168
History | View | Annotate | Download (50.8 KB)
1 | 44 | jmorell | package org.cresques.px.dxf; |
---|---|---|---|
2 | |||
3 | 94 | luisw | import org.cresques.cts.ICoordTrans; |
4 | import org.cresques.cts.IProjection; |
||
5 | 44 | jmorell | import org.cresques.geo.Point3D; |
6 | import org.cresques.geo.Projected; |
||
7 | 91 | luisw | import org.cresques.geo.ViewPortData; |
8 | 44 | jmorell | import org.cresques.io.DxfFile; |
9 | import org.cresques.io.DxfGroup; |
||
10 | import org.cresques.io.DxfGroupVector; |
||
11 | import org.cresques.px.Extent; |
||
12 | 96 | luisw | import org.cresques.px.IObjList; |
13 | 44 | jmorell | import org.cresques.px.gml.Feature; |
14 | 73 | jmorell | import org.cresques.px.gml.FeatureCollection; |
15 | 107 | jmorell | import org.cresques.px.gml.Geometry; |
16 | 73 | jmorell | import org.cresques.px.gml.InsPoint; |
17 | 44 | jmorell | import org.cresques.px.gml.LineString; |
18 | import org.cresques.px.gml.Point; |
||
19 | import org.cresques.px.gml.Polygon; |
||
20 | import java.util.Iterator; |
||
21 | import java.util.Vector; |
||
22 | import java.awt.Graphics2D; |
||
23 | import java.awt.geom.Point2D; |
||
24 | |||
25 | public class DxfFeatureMaker implements DxfFile.EntityFactory, Projected { |
||
26 | 94 | luisw | IProjection proj = null;
|
27 | 139 | jmorell | //Feature lastFeature = null;
|
28 | 131 | jmorell | Feature lastFeaBordes = null;
|
29 | Feature lastFeaFondos = null;
|
||
30 | 136 | jmorell | boolean isDoubleFeatured = false; |
31 | 96 | luisw | FeatureCollection features = null;
|
32 | 44 | jmorell | double bulge = 0.0; |
33 | double xtruX=0.0, xtruY=0.0, xtruZ=1.0; |
||
34 | int polylineFlag = 0; |
||
35 | Point2D firstPt = new Point2D.Double(); |
||
36 | 57 | jmorell | |
37 | boolean addingToBlock = false; |
||
38 | 73 | jmorell | int iterator = 0; |
39 | FeatureCollection blk = null;
|
||
40 | Vector blkList = null; |
||
41 | 128 | jmorell | DxfTable layers = null;
|
42 | 57 | jmorell | |
43 | 125 | luisw | public DxfFeatureMaker(IProjection proj) {
|
44 | 44 | jmorell | this.proj = proj;
|
45 | 128 | jmorell | layers = new DxfTable();
|
46 | 96 | luisw | features = new FeatureCollection(proj);
|
47 | 73 | jmorell | blkList = new Vector(); |
48 | 44 | jmorell | } |
49 | |||
50 | 57 | jmorell | public void setAddingToBlock(boolean a) { addingToBlock = a; } |
51 | |||
52 | 44 | jmorell | public void createLayer(DxfGroupVector v) throws Exception { |
53 | 128 | jmorell | int color = v.getDataAsInt(62); |
54 | DxfLayer layer = new DxfLayer(v.getDataAsString(2), Math.abs(v.getDataAsInt(62))); |
||
55 | if (color < 0) { |
||
56 | layer.isOff = true;
|
||
57 | } |
||
58 | layer.lType = v.getDataAsString(6);
|
||
59 | layer.setFlags(v.getDataAsInt(70));
|
||
60 | // compruebo flags
|
||
61 | if ((layer.flags & 0x01) == 0x01) { |
||
62 | layer.frozen = true;
|
||
63 | } |
||
64 | if ((layer.flags & 0x02) == 0x02) { |
||
65 | layer.frozen = true;
|
||
66 | } |
||
67 | System.out.println("LAYER color="+layer.getColor()); |
||
68 | |||
69 | layers.add(layer); |
||
70 | 44 | jmorell | } |
71 | |||
72 | public void createPolyline(DxfGroupVector grp) throws Exception { |
||
73 | LineString lineString = new LineString();
|
||
74 | Polygon polygon = new Polygon(); |
||
75 | 139 | jmorell | //Feature feature= new Feature();
|
76 | 131 | jmorell | Feature feaBordes= new Feature();
|
77 | Feature feaFondos= new Feature();
|
||
78 | 44 | jmorell | double x = 0.0, y = 0.0, z = 0.0; |
79 | int flags = 0; |
||
80 | 54 | jmorell | |
81 | 139 | jmorell | //feature.setProp("dxfEntity", "Polyline");
|
82 | 133 | jmorell | feaBordes.setProp("dxfEntity", "Polyline"); |
83 | feaFondos.setProp("dxfEntity", "Polyline"); |
||
84 | 131 | jmorell | if (grp.hasCode(8)) { |
85 | 139 | jmorell | //feature.setProp("layer", grp.getDataAsString(8));
|
86 | 132 | jmorell | feaBordes.setProp("layer", grp.getDataAsString(8)); |
87 | feaFondos.setProp("layer", grp.getDataAsString(8)); |
||
88 | 131 | jmorell | } |
89 | 124 | jmorell | if (grp.hasCode(39)) { |
90 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
91 | String string = doub.toString();
|
||
92 | 139 | jmorell | //feature.setProp("thickness", string);
|
93 | 132 | jmorell | feaBordes.setProp("thickness", string);
|
94 | feaFondos.setProp("thickness", string);
|
||
95 | 124 | jmorell | } else {
|
96 | Double doub = new Double(0.0); |
||
97 | 139 | jmorell | //feature.setProp("thickness", doub.toString());
|
98 | 132 | jmorell | feaBordes.setProp("thickness", doub.toString());
|
99 | feaFondos.setProp("thickness", doub.toString());
|
||
100 | 124 | jmorell | } |
101 | 55 | jmorell | if (grp.hasCode(62)) { |
102 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
103 | String string = integer.toString();
|
||
104 | 139 | jmorell | //feature.setProp("color", string);
|
105 | 132 | jmorell | feaBordes.setProp("color", string);
|
106 | feaFondos.setProp("color", string);
|
||
107 | 166 | jmorell | feaBordes.setProp("colorByLayer", "false"); |
108 | feaFondos.setProp("colorByLayer", "false"); |
||
109 | 55 | jmorell | } else {
|
110 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
111 | int clr = layer.colorNumber;
|
||
112 | Integer integer = new Integer(clr); |
||
113 | String string = integer.toString();
|
||
114 | 139 | jmorell | //feature.setProp("color", string);
|
115 | 132 | jmorell | feaBordes.setProp("color", string);
|
116 | feaFondos.setProp("color", string);
|
||
117 | 166 | jmorell | feaBordes.setProp("colorByLayer", "true"); |
118 | feaFondos.setProp("colorByLayer", "true"); |
||
119 | 54 | jmorell | } |
120 | 44 | jmorell | if (grp.hasCode(10)) |
121 | x = grp.getDataAsDouble(10);
|
||
122 | if (grp.hasCode(20)) |
||
123 | y = grp.getDataAsDouble(20);
|
||
124 | 124 | jmorell | if (grp.hasCode(30)) { |
125 | 44 | jmorell | z = grp.getDataAsDouble(30);
|
126 | 124 | jmorell | Double doub = new Double(z); |
127 | String string = doub.toString();
|
||
128 | 139 | jmorell | //feature.setProp("elevation", string);
|
129 | 132 | jmorell | feaBordes.setProp("elevation", string);
|
130 | feaFondos.setProp("elevation", string);
|
||
131 | 124 | jmorell | } |
132 | 44 | jmorell | if (grp.hasCode(70)) |
133 | flags = grp.getDataAsInt(70);
|
||
134 | if (grp.hasCode(210)) |
||
135 | xtruX = grp.getDataAsDouble(210);
|
||
136 | if (grp.hasCode(220)) |
||
137 | xtruY = grp.getDataAsDouble(220);
|
||
138 | if (grp.hasCode(230)) |
||
139 | xtruZ = grp.getDataAsDouble(230);
|
||
140 | 77 | jmorell | if ((flags & 0x01) == 0x00) { |
141 | 139 | jmorell | feaBordes.setGeometry(lineString); |
142 | lastFeaBordes = feaBordes; |
||
143 | 136 | jmorell | isDoubleFeatured = false;
|
144 | 77 | jmorell | } else if ((flags & 0x01) == 0x01) { |
145 | 131 | jmorell | feaBordes.setGeometry(lineString); |
146 | feaFondos.setGeometry(polygon); |
||
147 | lastFeaBordes = feaBordes; |
||
148 | lastFeaFondos = feaFondos; |
||
149 | 136 | jmorell | isDoubleFeatured = true;
|
150 | 44 | jmorell | } else {
|
151 | 77 | jmorell | System.out.println("Detectada una Polyline Flag que no corresponde"); |
152 | System.out.println("a una Polyline corriente, ni a una Closed Polyline"); |
||
153 | 44 | jmorell | } |
154 | } |
||
155 | |||
156 | public void endSeq() throws Exception { |
||
157 | 136 | jmorell | if (isDoubleFeatured) {
|
158 | 131 | jmorell | Feature feaBordes = lastFeaBordes; |
159 | Feature feaFondos = lastFeaFondos; |
||
160 | LineString lineString = (LineString)feaBordes.getGeometry(); |
||
161 | 136 | jmorell | Polygon polygon = (Polygon)feaFondos.getGeometry(); |
162 | 137 | jmorell | lineString.add(firstPt); |
163 | 136 | jmorell | polygon.add(firstPt); |
164 | 131 | jmorell | if (!(bulge==0)) { |
165 | int cnt = lineString.pointNr();
|
||
166 | Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
||
167 | lineString.remove(cnt-1);
|
||
168 | 136 | jmorell | polygon.remove(cnt-1);
|
169 | 131 | jmorell | for (int i=0; i<arc.size(); i++) { |
170 | Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
||
171 | lineString.add(pt); |
||
172 | 136 | jmorell | polygon.add(pt); |
173 | 131 | jmorell | if (lineString.pointNr() == 1) firstPt = pt; |
174 | } |
||
175 | bulge = 0.0;
|
||
176 | } |
||
177 | lastFeaBordes.setGeometry(lineString); |
||
178 | 136 | jmorell | lastFeaFondos.setGeometry(polygon); |
179 | 131 | jmorell | if (addingToBlock == false) { |
180 | features.add(lastFeaBordes); |
||
181 | features.add(lastFeaFondos); |
||
182 | } else {
|
||
183 | blk.add(lastFeaBordes); |
||
184 | blk.add(lastFeaFondos); |
||
185 | } |
||
186 | lastFeaBordes = null;
|
||
187 | lastFeaFondos = null;
|
||
188 | } else {
|
||
189 | 139 | jmorell | Feature feaBordes = lastFeaBordes; |
190 | LineString lineString = (LineString)feaBordes.getGeometry(); |
||
191 | 131 | jmorell | if (!(bulge==0)) { |
192 | int cnt = lineString.pointNr();
|
||
193 | Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
||
194 | lineString.remove(cnt-1);
|
||
195 | for (int i=0; i<arc.size(); i++) { |
||
196 | Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
||
197 | lineString.add(pt); |
||
198 | if (lineString.pointNr() == 1) firstPt = pt; |
||
199 | } |
||
200 | bulge = 0.0;
|
||
201 | } |
||
202 | 139 | jmorell | lastFeaBordes.setGeometry(lineString); |
203 | 131 | jmorell | if (addingToBlock == false) { |
204 | 139 | jmorell | features.add(lastFeaBordes); |
205 | 131 | jmorell | } else {
|
206 | 139 | jmorell | blk.add(lastFeaBordes); |
207 | 131 | jmorell | } |
208 | 139 | jmorell | lastFeaBordes = null;
|
209 | 131 | jmorell | } |
210 | 44 | jmorell | xtruX = 0.0;
|
211 | xtruY = 0.0;
|
||
212 | xtruZ = 1.0;
|
||
213 | bulge = 0.0;
|
||
214 | 136 | jmorell | isDoubleFeatured = false;
|
215 | 44 | jmorell | } |
216 | |||
217 | public void addVertex(DxfGroupVector grp) throws Exception { |
||
218 | double x = 0.0, y = 0.0, z = 0.0; |
||
219 | 136 | jmorell | if (isDoubleFeatured) {
|
220 | 131 | jmorell | Feature feaBordes = lastFeaBordes; |
221 | Feature feaFondos = lastFeaFondos; |
||
222 | LineString lineString = (LineString)feaBordes.getGeometry(); |
||
223 | 135 | jmorell | Polygon polygon = (Polygon)feaFondos.getGeometry(); |
224 | 131 | jmorell | if (grp.hasCode(8)) |
225 | feaBordes.setProp("layer", grp.getDataAsString(8)); |
||
226 | 135 | jmorell | feaFondos.setProp("layer", grp.getDataAsString(8)); |
227 | 131 | jmorell | if (grp.hasCode(62)) { |
228 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
229 | String string = integer.toString();
|
||
230 | feaBordes.setProp("color", string);
|
||
231 | 135 | jmorell | feaFondos.setProp("color", string);
|
232 | 166 | jmorell | feaBordes.setProp("colorByLayer", "false"); |
233 | feaFondos.setProp("colorByLayer", "false"); |
||
234 | 131 | jmorell | } else {
|
235 | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
||
236 | int clr = layer.colorNumber;
|
||
237 | Integer integer = new Integer(clr); |
||
238 | String string = integer.toString();
|
||
239 | feaBordes.setProp("color", string);
|
||
240 | 135 | jmorell | feaFondos.setProp("color", string);
|
241 | 166 | jmorell | feaBordes.setProp("colorByLayer", "true"); |
242 | feaFondos.setProp("colorByLayer", "true"); |
||
243 | 131 | jmorell | } |
244 | x = grp.getDataAsDouble(10);
|
||
245 | y = grp.getDataAsDouble(20);
|
||
246 | if (grp.hasCode(30)) { |
||
247 | z = grp.getDataAsDouble(30);
|
||
248 | } |
||
249 | Point3D point_in = new Point3D(x, y, z);
|
||
250 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
251 | Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
||
252 | x = point_out.getX(); |
||
253 | y = point_out.getY(); |
||
254 | Point2D pt = proj.createPoint( x, y);
|
||
255 | lineString.add(pt); |
||
256 | 135 | jmorell | polygon.add(pt); |
257 | 131 | jmorell | if (lineString.pointNr() == 1) { |
258 | firstPt = pt; |
||
259 | } |
||
260 | if (bulge == 0.0) { |
||
261 | if (grp.hasCode(42)) { |
||
262 | bulge = grp.getDataAsDouble(42);
|
||
263 | } else { bulge = 0.0; } |
||
264 | } else {
|
||
265 | double bulge_aux = 0.0; |
||
266 | if (grp.hasCode(42)) { |
||
267 | bulge_aux = grp.getDataAsDouble(42);
|
||
268 | } else { bulge_aux = 0.0; } |
||
269 | int cnt = lineString.pointNr();
|
||
270 | Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
||
271 | lineString.remove(cnt-1);
|
||
272 | 135 | jmorell | polygon.remove(cnt-1);
|
273 | 131 | jmorell | for (int i=0; i<arc.size(); i++) { |
274 | pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
||
275 | lineString.add(pt); |
||
276 | 135 | jmorell | polygon.add(pt); |
277 | 131 | jmorell | if (lineString.pointNr() == 1) firstPt = pt; |
278 | } |
||
279 | bulge = bulge_aux; |
||
280 | } |
||
281 | } else {
|
||
282 | 139 | jmorell | Feature feaBordes = lastFeaBordes; |
283 | LineString lineString = (LineString)feaBordes.getGeometry(); |
||
284 | 131 | jmorell | if (grp.hasCode(8)) |
285 | 139 | jmorell | feaBordes.setProp("layer", grp.getDataAsString(8)); |
286 | 131 | jmorell | if (grp.hasCode(62)) { |
287 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
288 | String string = integer.toString();
|
||
289 | 139 | jmorell | feaBordes.setProp("color", string);
|
290 | 166 | jmorell | feaBordes.setProp("colorByLayer", "false"); |
291 | 131 | jmorell | } else {
|
292 | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
||
293 | int clr = layer.colorNumber;
|
||
294 | Integer integer = new Integer(clr); |
||
295 | String string = integer.toString();
|
||
296 | 139 | jmorell | feaBordes.setProp("color", string);
|
297 | 166 | jmorell | feaBordes.setProp("colorByLayer", "true"); |
298 | 131 | jmorell | } |
299 | x = grp.getDataAsDouble(10);
|
||
300 | y = grp.getDataAsDouble(20);
|
||
301 | if (grp.hasCode(30)) { |
||
302 | z = grp.getDataAsDouble(30);
|
||
303 | } |
||
304 | Point3D point_in = new Point3D(x, y, z);
|
||
305 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
306 | Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
||
307 | x = point_out.getX(); |
||
308 | y = point_out.getY(); |
||
309 | Point2D pt = proj.createPoint( x, y);
|
||
310 | lineString.add(pt); |
||
311 | if (lineString.pointNr() == 1) { |
||
312 | firstPt = pt; |
||
313 | } |
||
314 | 44 | jmorell | if (bulge == 0.0) { |
315 | 131 | jmorell | if (grp.hasCode(42)) { |
316 | bulge = grp.getDataAsDouble(42);
|
||
317 | } else { bulge = 0.0; } |
||
318 | } else {
|
||
319 | double bulge_aux = 0.0; |
||
320 | if (grp.hasCode(42)) { |
||
321 | bulge_aux = grp.getDataAsDouble(42);
|
||
322 | } else { bulge_aux = 0.0; } |
||
323 | int cnt = lineString.pointNr();
|
||
324 | Vector arc = createArc((Point2D)(lineString.get(cnt-2)), (Point2D)(lineString.get(cnt-1)), bulge); |
||
325 | lineString.remove(cnt-1);
|
||
326 | for (int i=0; i<arc.size(); i++) { |
||
327 | pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
||
328 | lineString.add(pt); |
||
329 | if (lineString.pointNr() == 1) firstPt = pt; |
||
330 | } |
||
331 | bulge = bulge_aux; |
||
332 | } |
||
333 | } |
||
334 | 44 | jmorell | } |
335 | |||
336 | public void createLwPolyline(DxfGroupVector grp) throws Exception { |
||
337 | 124 | jmorell | double x = 0.0, y = 0.0; |
338 | double elev = 0.0; |
||
339 | 44 | jmorell | DxfGroup g = null;
|
340 | 142 | jmorell | LineString lineString = new LineString();
|
341 | Polygon polygon = new Polygon(); |
||
342 | //Geometry geometria;
|
||
343 | //Feature feature= new Feature();
|
||
344 | Feature feaBordes= new Feature();
|
||
345 | Feature feaFondos= new Feature();
|
||
346 | 44 | jmorell | int flags = 0; |
347 | |||
348 | 142 | jmorell | //feature.setProp("dxfEntity", "LwPolyline");
|
349 | feaBordes.setProp("dxfEntity", "LwPolyline"); |
||
350 | feaFondos.setProp("dxfEntity", "LwPolyline"); |
||
351 | 55 | jmorell | if (grp.hasCode(8)) |
352 | 142 | jmorell | //feature.setProp("layer", grp.getDataAsString(8));
|
353 | feaBordes.setProp("layer", grp.getDataAsString(8)); |
||
354 | feaFondos.setProp("layer", grp.getDataAsString(8)); |
||
355 | 124 | jmorell | if (grp.hasCode(38)) { |
356 | elev = grp.getDataAsDouble(38);
|
||
357 | Double doub = new Double(elev); |
||
358 | String string = doub.toString();
|
||
359 | 142 | jmorell | //feature.setProp("elevation", string);
|
360 | feaBordes.setProp("elevation", string);
|
||
361 | feaFondos.setProp("elevation", string);
|
||
362 | 124 | jmorell | } else {
|
363 | Double doub = new Double(0.0); |
||
364 | 142 | jmorell | //feature.setProp("elevation", doub.toString());
|
365 | feaBordes.setProp("elevation", doub.toString());
|
||
366 | feaFondos.setProp("elevation", doub.toString());
|
||
367 | 124 | jmorell | } |
368 | if (grp.hasCode(39)) { |
||
369 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
370 | String string = doub.toString();
|
||
371 | 142 | jmorell | //feature.setProp("thickness", string);
|
372 | feaBordes.setProp("thickness", string);
|
||
373 | feaFondos.setProp("thickness", string);
|
||
374 | 124 | jmorell | } else {
|
375 | Double doub = new Double(0.0); |
||
376 | 142 | jmorell | //feature.setProp("thickness", doub.toString());
|
377 | feaBordes.setProp("thickness", doub.toString());
|
||
378 | feaFondos.setProp("thickness", doub.toString());
|
||
379 | 124 | jmorell | } |
380 | 55 | jmorell | if (grp.hasCode(62)) { |
381 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
382 | String string = integer.toString();
|
||
383 | 142 | jmorell | //feature.setProp("color", string);
|
384 | feaBordes.setProp("color", string);
|
||
385 | feaFondos.setProp("color", string);
|
||
386 | 166 | jmorell | feaBordes.setProp("colorByLayer", "false"); |
387 | feaFondos.setProp("colorByLayer", "false"); |
||
388 | 55 | jmorell | } else {
|
389 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
390 | int clr = layer.colorNumber;
|
||
391 | Integer integer = new Integer(clr); |
||
392 | String string = integer.toString();
|
||
393 | 142 | jmorell | //feature.setProp("color", string);
|
394 | feaBordes.setProp("color", string);
|
||
395 | feaFondos.setProp("color", string);
|
||
396 | 166 | jmorell | feaBordes.setProp("colorByLayer", "true"); |
397 | feaFondos.setProp("colorByLayer", "true"); |
||
398 | 54 | jmorell | } |
399 | 107 | jmorell | if (grp.hasCode(70)) |
400 | flags = grp.getDataAsInt(70);
|
||
401 | if ((flags & 0x01) == 0x01) { |
||
402 | 142 | jmorell | //geometria = new Polygon();
|
403 | feaBordes.setGeometry(lineString); |
||
404 | feaFondos.setGeometry(polygon); |
||
405 | isDoubleFeatured = true;
|
||
406 | 107 | jmorell | } else {
|
407 | 142 | jmorell | //geometria = new LineString();
|
408 | feaBordes.setGeometry(lineString); |
||
409 | isDoubleFeatured = false;
|
||
410 | 107 | jmorell | } |
411 | 106 | jmorell | |
412 | 107 | jmorell | int j = 0; |
413 | double firstX = 0.0; |
||
414 | double firstY = 0.0; |
||
415 | 44 | jmorell | for (int i=0; i<grp.size(); i++) { |
416 | g = (DxfGroup) grp.get(i); |
||
417 | 106 | jmorell | if (g.getCode() == 10) { |
418 | 107 | jmorell | j++; |
419 | 82 | jmorell | x = ((Double) g.getData()).doubleValue();
|
420 | 106 | jmorell | } else if (g.getCode() == 20) { |
421 | 82 | jmorell | y = ((Double) g.getData()).doubleValue();
|
422 | 107 | jmorell | //if (y <= 1.0) throw new Exception("Y == "+y);
|
423 | //lineString.add( proj.createPoint( x, y ) );
|
||
424 | //polygon.add( proj.createPoint( x, y ) );
|
||
425 | 142 | jmorell | //geometria.add( proj.createPoint( x, y ) );
|
426 | lineString.add( proj.createPoint( x, y ) ); |
||
427 | if (isDoubleFeatured) polygon.add( proj.createPoint( x, y ) );
|
||
428 | 107 | jmorell | if (j == 1) { |
429 | firstX = x; |
||
430 | 106 | jmorell | firstY = y; |
431 | 107 | jmorell | } |
432 | 44 | jmorell | x = 0.0; y = 0.0; |
433 | } |
||
434 | } |
||
435 | 142 | jmorell | if (isDoubleFeatured) {
|
436 | //geometria.add(proj.createPoint(firstX, firstY));
|
||
437 | lineString.add(proj.createPoint(firstX, firstY)); |
||
438 | polygon.add(proj.createPoint(firstX, firstY)); |
||
439 | 44 | jmorell | } |
440 | 107 | jmorell | |
441 | 142 | jmorell | lastFeaBordes = feaBordes; |
442 | if (isDoubleFeatured) lastFeaFondos = feaFondos;
|
||
443 | 74 | jmorell | //features.add(feature);
|
444 | if (addingToBlock == false) { |
||
445 | 142 | jmorell | features.add(feaBordes); |
446 | if (isDoubleFeatured) features.add(feaFondos);
|
||
447 | 74 | jmorell | } else {
|
448 | 102 | jmorell | //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
|
449 | 142 | jmorell | blk.add(feaBordes); |
450 | if (isDoubleFeatured) blk.add(feaFondos);
|
||
451 | 74 | jmorell | } |
452 | 142 | jmorell | isDoubleFeatured = false;
|
453 | 44 | jmorell | } |
454 | |||
455 | public void createLine(DxfGroupVector grp) throws Exception { |
||
456 | double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0; |
||
457 | 124 | jmorell | double elev = 0.0; |
458 | 44 | jmorell | DxfGroup g = null;
|
459 | Point2D pt1 = null, pt2 = null; |
||
460 | LineString lineString = new LineString();
|
||
461 | Feature feature = new Feature();
|
||
462 | |||
463 | 124 | jmorell | feature.setProp("dxfEntity", "Line"); |
464 | 55 | jmorell | if (grp.hasCode(8)) |
465 | 54 | jmorell | feature.setProp("layer", grp.getDataAsString(8)); |
466 | 124 | jmorell | if (grp.hasCode(39)) { |
467 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
468 | String string = doub.toString();
|
||
469 | feature.setProp("thickness", string);
|
||
470 | } else {
|
||
471 | Double doub = new Double(0.0); |
||
472 | feature.setProp("thickness", doub.toString());
|
||
473 | } |
||
474 | 55 | jmorell | if (grp.hasCode(62)) { |
475 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
476 | String string = integer.toString();
|
||
477 | feature.setProp("color", string);
|
||
478 | 166 | jmorell | feature.setProp("colorByLayer", "false"); |
479 | 55 | jmorell | } else {
|
480 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
481 | int clr = layer.colorNumber;
|
||
482 | Integer integer = new Integer(clr); |
||
483 | String string = integer.toString();
|
||
484 | feature.setProp("color", string);
|
||
485 | 166 | jmorell | feature.setProp("colorByLayer", "true"); |
486 | 54 | jmorell | } |
487 | 44 | jmorell | x = grp.getDataAsDouble(10);
|
488 | y = grp.getDataAsDouble(20);
|
||
489 | 124 | jmorell | if (grp.hasCode(30)) { |
490 | z1 = grp.getDataAsDouble(30);
|
||
491 | elev = z1; |
||
492 | Double doub = new Double(elev); |
||
493 | String string = doub.toString();
|
||
494 | feature.setProp("elevation", string);
|
||
495 | } |
||
496 | 44 | jmorell | pt1 = proj.createPoint(x, y); |
497 | x = grp.getDataAsDouble(11);
|
||
498 | y = grp.getDataAsDouble(21);
|
||
499 | 124 | jmorell | if (grp.hasCode(31)) { |
500 | z2 = grp.getDataAsDouble(31);
|
||
501 | } |
||
502 | 44 | jmorell | pt2 = proj.createPoint(x, y); |
503 | if (grp.hasCode(210)) |
||
504 | xtruX = grp.getDataAsDouble(210);
|
||
505 | if (grp.hasCode(220)) |
||
506 | 73 | jmorell | xtruY = grp.getDataAsDouble(220);
|
507 | 44 | jmorell | if (grp.hasCode(230)) |
508 | 73 | jmorell | xtruZ = grp.getDataAsDouble(230);
|
509 | 44 | jmorell | Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
|
510 | Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
|
||
511 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
512 | Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
|
||
513 | Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
|
||
514 | pt1.setLocation(point_out1); |
||
515 | pt2.setLocation(point_out2); |
||
516 | lineString.add(pt1); |
||
517 | lineString.add(pt2); |
||
518 | 57 | jmorell | |
519 | 44 | jmorell | feature.setGeometry(lineString); |
520 | 74 | jmorell | //features.add(feature);
|
521 | if (addingToBlock == false) { |
||
522 | 102 | jmorell | //System.out.println("createLine(): A?adimos una linea a la lista de entidades");
|
523 | 74 | jmorell | features.add(feature); |
524 | } else {
|
||
525 | 102 | jmorell | //System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
|
526 | 74 | jmorell | blk.add(feature); |
527 | } |
||
528 | 44 | jmorell | } |
529 | |||
530 | /* (non-Javadoc)
|
||
531 | * @see org.cresques.io.DxfFile.EntityFactory#createText(org.cresques.io.DxfGroupVector)
|
||
532 | */
|
||
533 | public void createText(DxfGroupVector grp) throws Exception { |
||
534 | double x = 0.0, y = 0.0, z = 0.0, h= 0.0, rot= 0.0; |
||
535 | DxfGroup g = null;
|
||
536 | Point2D pt1 = null, pt2 = null; |
||
537 | Point2D pt = null; |
||
538 | Point point = new Point(); |
||
539 | 122 | jmorell | |
540 | point.isText = true;
|
||
541 | |||
542 | 44 | jmorell | Feature feature = new Feature();
|
543 | |||
544 | 124 | jmorell | feature.setProp("dxfEntity", "Text"); |
545 | 55 | jmorell | if (grp.hasCode(8)) |
546 | 54 | jmorell | feature.setProp("layer", grp.getDataAsString(8)); |
547 | 124 | jmorell | if (grp.hasCode(39)) { |
548 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
549 | String string = doub.toString();
|
||
550 | feature.setProp("thickness", string);
|
||
551 | } else {
|
||
552 | Double doub = new Double(0.0); |
||
553 | feature.setProp("thickness", doub.toString());
|
||
554 | } |
||
555 | 55 | jmorell | if (grp.hasCode(62)) { |
556 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
557 | String string = integer.toString();
|
||
558 | feature.setProp("color", string);
|
||
559 | 166 | jmorell | feature.setProp("colorByLayer", "false"); |
560 | 55 | jmorell | } else {
|
561 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
562 | int clr = layer.colorNumber;
|
||
563 | Integer integer = new Integer(clr); |
||
564 | String string = integer.toString();
|
||
565 | feature.setProp("color", string);
|
||
566 | 166 | jmorell | feature.setProp("colorByLayer", "true"); |
567 | 54 | jmorell | } |
568 | 55 | jmorell | if (grp.hasCode(1)) { |
569 | 116 | jmorell | String strAux1 = grp.getDataAsString(1); |
570 | strAux1 = DxfConvTexts.ConvertText(strAux1); |
||
571 | feature.setProp("text", strAux1);
|
||
572 | 55 | jmorell | } else {
|
573 | 122 | jmorell | feature.setProp("text", "No Text Code"); |
574 | 55 | jmorell | } |
575 | 108 | jmorell | if (grp.hasCode(40)) { |
576 | Double heightD = new Double(grp.getDataAsDouble(40)); |
||
577 | String heightS = heightD.toString();
|
||
578 | feature.setProp("textHeight", heightS);
|
||
579 | } else {
|
||
580 | feature.setProp("textHeight", "20.0"); |
||
581 | } |
||
582 | if (grp.hasCode(50)) { |
||
583 | Double rotD = new Double(grp.getDataAsDouble(50)); |
||
584 | String rotS = rotD.toString();
|
||
585 | feature.setProp("textRotation", rotS);
|
||
586 | } else {
|
||
587 | feature.setProp("textRotation", "0.0"); |
||
588 | } |
||
589 | 44 | jmorell | x = grp.getDataAsDouble(10);
|
590 | y = grp.getDataAsDouble(20);
|
||
591 | 124 | jmorell | if (grp.hasCode(30)){ |
592 | z = grp.getDataAsDouble(30);
|
||
593 | Double doub = new Double(z); |
||
594 | String string = doub.toString();
|
||
595 | feature.setProp("elevation", string);
|
||
596 | } |
||
597 | 44 | jmorell | if (grp.hasCode(210)) |
598 | xtruX = grp.getDataAsDouble(210);
|
||
599 | if (grp.hasCode(220)) |
||
600 | xtruY = grp.getDataAsDouble(220);
|
||
601 | if (grp.hasCode(230)) |
||
602 | xtruZ = grp.getDataAsDouble(230);
|
||
603 | Point3D point_in = new Point3D(x, y, z);
|
||
604 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
605 | Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
||
606 | x = point_out.getX(); |
||
607 | y = point_out.getY(); |
||
608 | //entity.setPt1(proj.createPoint(x, y));
|
||
609 | //point.add(proj.createPoint(x, y));
|
||
610 | //lineText.add(proj.createPoint(x, y));
|
||
611 | /*if (grp.hasCode(11)) {
|
||
612 | x = grp.getDataAsDouble(11);
|
||
613 | y = grp.getDataAsDouble(21);
|
||
614 | //entity.setPt2(proj.createPoint(x, y));
|
||
615 | lineText.add(proj.createPoint(x, y));
|
||
616 | }
|
||
617 | entity.h = grp.getDataAsDouble(40);
|
||
618 | if (grp.hasCode(50))
|
||
619 | entity.rot = grp.getDataAsDouble(50);
|
||
620 | if (grp.hasCode(62))
|
||
621 | entity.dxfColor = grp.getDataAsInt(62);
|
||
622 | if (grp.hasCode(72))
|
||
623 | entity.align = grp.getDataAsInt(72);*/
|
||
624 | point.add(new Point2D.Double(x, y)); |
||
625 | feature.setGeometry(point); |
||
626 | //entities.add(entity);
|
||
627 | 74 | jmorell | //features.add(feature);
|
628 | if (addingToBlock == false) { |
||
629 | features.add(feature); |
||
630 | } else {
|
||
631 | 102 | jmorell | //System.out.println("createText(): A?adimos un text al bloque " + iterator);
|
632 | 74 | jmorell | blk.add(feature); |
633 | } |
||
634 | 44 | jmorell | } |
635 | |||
636 | public void createPoint(DxfGroupVector grp) throws Exception { |
||
637 | double x = 0.0, y = 0.0, z = 0.0; |
||
638 | DxfGroup g = null;
|
||
639 | Point2D pt = null; |
||
640 | Point point = new Point(); |
||
641 | Feature feature = new Feature();
|
||
642 | |||
643 | 124 | jmorell | feature.setProp("dxfEntity", "Point"); |
644 | 55 | jmorell | if (grp.hasCode(8)) |
645 | 54 | jmorell | feature.setProp("layer", grp.getDataAsString(8)); |
646 | 124 | jmorell | if (grp.hasCode(39)) { |
647 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
648 | String string = doub.toString();
|
||
649 | feature.setProp("thickness", string);
|
||
650 | } else {
|
||
651 | Double doub = new Double(0.0); |
||
652 | feature.setProp("thickness", doub.toString());
|
||
653 | } |
||
654 | 55 | jmorell | if (grp.hasCode(62)) { |
655 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
656 | String string = integer.toString();
|
||
657 | feature.setProp("color", string);
|
||
658 | 166 | jmorell | feature.setProp("colorByLayer", "false"); |
659 | 55 | jmorell | } else {
|
660 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
661 | int clr = layer.colorNumber;
|
||
662 | Integer integer = new Integer(clr); |
||
663 | String string = integer.toString();
|
||
664 | feature.setProp("color", string);
|
||
665 | 166 | jmorell | feature.setProp("colorByLayer", "true"); |
666 | 54 | jmorell | } |
667 | 44 | jmorell | x = grp.getDataAsDouble(10);
|
668 | y = grp.getDataAsDouble(20);
|
||
669 | 124 | jmorell | if (grp.hasCode(30)) { |
670 | z = grp.getDataAsDouble(30);
|
||
671 | Double doub = new Double(z); |
||
672 | String string = doub.toString();
|
||
673 | feature.setProp("elevation", string);
|
||
674 | } |
||
675 | 44 | jmorell | if (grp.hasCode(210)) |
676 | xtruX = grp.getDataAsDouble(210);
|
||
677 | if (grp.hasCode(220)) |
||
678 | xtruY = grp.getDataAsDouble(220);
|
||
679 | if (grp.hasCode(230)) |
||
680 | xtruZ = grp.getDataAsDouble(230);
|
||
681 | Point3D point_in = new Point3D(x, y, z);
|
||
682 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
683 | Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
||
684 | x = point_out.getX(); |
||
685 | y = point_out.getY(); |
||
686 | point.add(new Point2D.Double(x, y)); |
||
687 | 57 | jmorell | |
688 | 44 | jmorell | feature.setGeometry(point); |
689 | 74 | jmorell | //features.add(feature);
|
690 | if (addingToBlock == false) { |
||
691 | features.add(feature); |
||
692 | } else {
|
||
693 | 102 | jmorell | //System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
|
694 | 74 | jmorell | blk.add(feature); |
695 | } |
||
696 | 44 | jmorell | } |
697 | |||
698 | public void createCircle(DxfGroupVector grp) throws Exception { |
||
699 | double x = 0.0, y = 0.0, z = 0.0; |
||
700 | double r = 0.0; |
||
701 | DxfGroup g = null;
|
||
702 | 142 | jmorell | LineString lineString = new LineString();
|
703 | 44 | jmorell | Polygon polygon = new Polygon(); |
704 | 142 | jmorell | Feature feaBordes = new Feature();
|
705 | Feature feaFondos = new Feature();
|
||
706 | 44 | jmorell | |
707 | 142 | jmorell | feaBordes.setProp("dxfEntity", "Circle"); |
708 | feaFondos.setProp("dxfEntity", "Circle"); |
||
709 | 55 | jmorell | if (grp.hasCode(8)) |
710 | 142 | jmorell | feaBordes.setProp("layer", grp.getDataAsString(8)); |
711 | feaFondos.setProp("layer", grp.getDataAsString(8)); |
||
712 | 124 | jmorell | if (grp.hasCode(39)) { |
713 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
714 | String string = doub.toString();
|
||
715 | 142 | jmorell | feaBordes.setProp("thickness", string);
|
716 | feaFondos.setProp("thickness", string);
|
||
717 | 124 | jmorell | } else {
|
718 | Double doub = new Double(0.0); |
||
719 | 142 | jmorell | feaBordes.setProp("thickness", doub.toString());
|
720 | feaFondos.setProp("thickness", doub.toString());
|
||
721 | 124 | jmorell | } |
722 | 55 | jmorell | if (grp.hasCode(62)) { |
723 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
724 | String string = integer.toString();
|
||
725 | 142 | jmorell | feaBordes.setProp("color", string);
|
726 | feaFondos.setProp("color", string);
|
||
727 | 166 | jmorell | feaBordes.setProp("colorByLayer", "false"); |
728 | feaFondos.setProp("colorByLayer", "false"); |
||
729 | 55 | jmorell | } else {
|
730 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
731 | int clr = layer.colorNumber;
|
||
732 | Integer integer = new Integer(clr); |
||
733 | String string = integer.toString();
|
||
734 | 142 | jmorell | feaBordes.setProp("color", string);
|
735 | feaFondos.setProp("color", string);
|
||
736 | 166 | jmorell | feaBordes.setProp("colorByLayer", "true"); |
737 | feaFondos.setProp("colorByLayer", "true"); |
||
738 | 54 | jmorell | } |
739 | 44 | jmorell | x = grp.getDataAsDouble(10);
|
740 | y = grp.getDataAsDouble(20);
|
||
741 | 124 | jmorell | if (grp.hasCode(30)) { |
742 | z = grp.getDataAsDouble(30);
|
||
743 | Double doub = new Double(z); |
||
744 | String string = doub.toString();
|
||
745 | 142 | jmorell | feaBordes.setProp("elevation", string);
|
746 | feaFondos.setProp("elevation", string);
|
||
747 | 124 | jmorell | } |
748 | 44 | jmorell | if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
749 | if (grp.hasCode(210)) |
||
750 | xtruX = grp.getDataAsDouble(210);
|
||
751 | if (grp.hasCode(220)) |
||
752 | 73 | jmorell | xtruY = grp.getDataAsDouble(220);
|
753 | 44 | jmorell | if (grp.hasCode(230)) |
754 | 73 | jmorell | xtruZ = grp.getDataAsDouble(230);
|
755 | 44 | jmorell | Point3D point_in = new Point3D(x, y, z);
|
756 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
757 | Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
||
758 | x = point_out.getX(); |
||
759 | y = point_out.getY(); |
||
760 | |||
761 | Point2D center = proj.createPoint( x, y);
|
||
762 | Point2D[] pts = new Point2D[360]; |
||
763 | int angulo = 0; |
||
764 | for (angulo=0; angulo<360; angulo++) { |
||
765 | pts[angulo] = new Point2D.Double(center.getX(), center.getY()); |
||
766 | pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0)); |
||
767 | if (pts.length == 1) { |
||
768 | firstPt = pts[angulo]; |
||
769 | } |
||
770 | } |
||
771 | for (int i=0; i<pts.length; i++) { |
||
772 | 142 | jmorell | lineString.add(pts[i]); |
773 | 44 | jmorell | polygon.add(pts[i]); |
774 | } |
||
775 | 57 | jmorell | |
776 | 142 | jmorell | feaBordes.setGeometry(lineString); |
777 | feaFondos.setGeometry(polygon); |
||
778 | 74 | jmorell | //features.add(feature);
|
779 | if (addingToBlock == false) { |
||
780 | 102 | jmorell | //System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
|
781 | 142 | jmorell | features.add(feaBordes); |
782 | features.add(feaFondos); |
||
783 | 74 | jmorell | } else {
|
784 | 102 | jmorell | //System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
|
785 | 142 | jmorell | blk.add(feaBordes); |
786 | blk.add(feaFondos); |
||
787 | 74 | jmorell | } |
788 | 44 | jmorell | } |
789 | |||
790 | public void createArc(DxfGroupVector grp) throws Exception { |
||
791 | double x = 0.0, y = 0.0, z = 0.0; |
||
792 | double r = 0.0, empieza = 0.0, acaba = 0.0; |
||
793 | DxfGroup g = null;
|
||
794 | LineString lineString = new LineString();
|
||
795 | Feature feature = new Feature();
|
||
796 | |||
797 | 124 | jmorell | feature.setProp("dxfEntity", "Arc"); |
798 | 55 | jmorell | if (grp.hasCode(8)) |
799 | 54 | jmorell | feature.setProp("layer", grp.getDataAsString(8)); |
800 | 124 | jmorell | if (grp.hasCode(39)) { |
801 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
802 | String string = doub.toString();
|
||
803 | feature.setProp("thickness", string);
|
||
804 | } else {
|
||
805 | Double doub = new Double(0.0); |
||
806 | feature.setProp("thickness", doub.toString());
|
||
807 | } |
||
808 | 55 | jmorell | if (grp.hasCode(62)) { |
809 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
810 | String string = integer.toString();
|
||
811 | feature.setProp("color", string);
|
||
812 | 166 | jmorell | feature.setProp("colorByLayer", "false"); |
813 | 55 | jmorell | } else {
|
814 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
815 | int clr = layer.colorNumber;
|
||
816 | Integer integer = new Integer(clr); |
||
817 | String string = integer.toString();
|
||
818 | feature.setProp("color", string);
|
||
819 | 166 | jmorell | feature.setProp("colorByLayer", "true"); |
820 | 54 | jmorell | } |
821 | 44 | jmorell | x = grp.getDataAsDouble(10);
|
822 | y = grp.getDataAsDouble(20);
|
||
823 | 124 | jmorell | if (grp.hasCode(30)) { |
824 | z = grp.getDataAsDouble(30);
|
||
825 | Double doub = new Double(z); |
||
826 | String string = doub.toString();
|
||
827 | feature.setProp("elevation", string);
|
||
828 | } |
||
829 | 44 | jmorell | if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
830 | if (grp.hasCode(50)) empieza = grp.getDataAsDouble(50); |
||
831 | if (grp.hasCode(51)) acaba = grp.getDataAsDouble(51); |
||
832 | if (grp.hasCode(210)) |
||
833 | xtruX = grp.getDataAsDouble(210);
|
||
834 | if (grp.hasCode(220)) |
||
835 | 73 | jmorell | xtruY = grp.getDataAsDouble(220);
|
836 | 44 | jmorell | if (grp.hasCode(230)) |
837 | 73 | jmorell | xtruZ = grp.getDataAsDouble(230);
|
838 | 44 | jmorell | Point3D point_in = new Point3D(x, y, z);
|
839 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
840 | Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
||
841 | x = point_out.getX(); |
||
842 | y = point_out.getY(); |
||
843 | |||
844 | Point2D center = proj.createPoint( x, y);
|
||
845 | 102 | jmorell | //System.out.println("empieza = " + empieza + ", acaba = " + acaba);
|
846 | 44 | jmorell | int iempieza = (int)empieza; |
847 | int iacaba = (int)acaba; |
||
848 | 102 | jmorell | //System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
|
849 | 44 | jmorell | double angulo = 0; |
850 | Point2D[] pts = null; |
||
851 | if (empieza <= acaba) {
|
||
852 | pts = new Point2D[(iacaba-iempieza)+2]; |
||
853 | angulo = empieza; |
||
854 | pts[0] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
||
855 | for (int i=1; i<=(iacaba-iempieza)+1; i++) { |
||
856 | angulo = (double)(iempieza+i);
|
||
857 | pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
||
858 | } |
||
859 | angulo = acaba; |
||
860 | pts[(iacaba-iempieza)+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
||
861 | } else {
|
||
862 | pts = new Point2D[(360-iempieza)+iacaba+2]; |
||
863 | angulo = empieza; |
||
864 | 102 | jmorell | //System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
|
865 | 44 | jmorell | pts[0] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
866 | for (int i=1; i<=(360-iempieza); i++) { |
||
867 | angulo = (double)(iempieza+i);
|
||
868 | pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
||
869 | } |
||
870 | for (int i=(360-iempieza)+1; i<=(360-iempieza)+iacaba; i++) { |
||
871 | angulo = (double)(i-(360-iempieza)); |
||
872 | pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
||
873 | } |
||
874 | angulo = acaba; |
||
875 | pts[(360-iempieza)+iacaba+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
||
876 | } |
||
877 | for (int i=0; i<pts.length; i++) { |
||
878 | lineString.add(pts[i]); |
||
879 | } |
||
880 | 57 | jmorell | |
881 | 44 | jmorell | feature.setGeometry(lineString); |
882 | 74 | jmorell | //features.add(feature);
|
883 | if (addingToBlock == false) { |
||
884 | features.add(feature); |
||
885 | } else {
|
||
886 | 102 | jmorell | //System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
|
887 | 74 | jmorell | blk.add(feature); |
888 | } |
||
889 | 44 | jmorell | } |
890 | |||
891 | public void createInsert(DxfGroupVector grp) throws Exception { |
||
892 | double x = 0.0, y = 0.0, z = 0.0; |
||
893 | DxfGroup g = null;
|
||
894 | 73 | jmorell | Point2D pt = new Point2D.Double(0.0, 0.0); |
895 | Point2D scaleFactor = new Point2D.Double(1.0, 1.0); |
||
896 | double rotAngle = 0.0; |
||
897 | 44 | jmorell | String blockName = ""; |
898 | |||
899 | 73 | jmorell | InsPoint insert = new InsPoint();
|
900 | 44 | jmorell | Feature feature = new Feature();
|
901 | 74 | jmorell | Point secondGeom = new Point(); |
902 | Feature secondFeat = new Feature();
|
||
903 | 44 | jmorell | |
904 | 124 | jmorell | feature.setProp("dxfEntity", "Insert"); |
905 | 128 | jmorell | secondFeat.setProp("dxfEntity", "Insert"); |
906 | 73 | jmorell | if (grp.hasCode(2)) { |
907 | 44 | jmorell | blockName = grp.getDataAsString(2);
|
908 | 74 | jmorell | //feature.setProp("blockName", blockName);
|
909 | insert.setBlockName(blockName); |
||
910 | 73 | jmorell | } |
911 | 74 | jmorell | if (grp.hasCode(8)) { |
912 | 54 | jmorell | feature.setProp("layer", grp.getDataAsString(8)); |
913 | 74 | jmorell | secondFeat.setProp("layer", grp.getDataAsString(8)); |
914 | } |
||
915 | 127 | jmorell | |
916 | Double doub = new Double(0.0); |
||
917 | secondFeat.setProp("thickness", doub.toString());
|
||
918 | |||
919 | 55 | jmorell | if (grp.hasCode(62)) { |
920 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
921 | String string = integer.toString();
|
||
922 | feature.setProp("color", string);
|
||
923 | 74 | jmorell | secondFeat.setProp("color", string);
|
924 | 166 | jmorell | feature.setProp("colorByLayer", "false"); |
925 | secondFeat.setProp("colorByLayer", "false"); |
||
926 | 55 | jmorell | } else {
|
927 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
928 | int clr = layer.colorNumber;
|
||
929 | Integer integer = new Integer(clr); |
||
930 | String string = integer.toString();
|
||
931 | feature.setProp("color", string);
|
||
932 | secondFeat.setProp("color", string);
|
||
933 | 166 | jmorell | feature.setProp("colorByLayer", "true"); |
934 | secondFeat.setProp("colorByLayer", "true"); |
||
935 | 54 | jmorell | } |
936 | 73 | jmorell | if (grp.hasCode(10)) x = grp.getDataAsDouble(10); |
937 | if (grp.hasCode(20)) y = grp.getDataAsDouble(20); |
||
938 | 124 | jmorell | if (grp.hasCode(30)) { |
939 | z = grp.getDataAsDouble(30);
|
||
940 | 127 | jmorell | Double doubz = new Double(z); |
941 | String string = doubz.toString();
|
||
942 | 124 | jmorell | feature.setProp("elevation", string);
|
943 | 127 | jmorell | secondFeat.setProp("elevation", string);
|
944 | 124 | jmorell | } |
945 | 73 | jmorell | if (grp.hasCode(41)) { |
946 | scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
|
||
947 | 74 | jmorell | //Double scaleFactorX = new Double(scaleFactor.getX());
|
948 | //feature.setProp("scaleFactorX", scaleFactorX.toString());
|
||
949 | insert.setScaleFactor(scaleFactor); |
||
950 | 73 | jmorell | } else {
|
951 | 74 | jmorell | //Double scaleFactorX = new Double(scaleFactor.getX());
|
952 | //feature.setProp("scaleFactorX", scaleFactorX.toString());
|
||
953 | insert.setScaleFactor(scaleFactor); |
||
954 | 73 | jmorell | } |
955 | if (grp.hasCode(42)) { |
||
956 | scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
|
||
957 | 74 | jmorell | //Double scaleFactorY = new Double(scaleFactor.getY());
|
958 | //feature.setProp("scaleFactorY", scaleFactorY.toString());
|
||
959 | insert.setScaleFactor(scaleFactor); |
||
960 | 73 | jmorell | } else {
|
961 | 74 | jmorell | //Double scaleFactorY = new Double(scaleFactor.getY());
|
962 | //feature.setProp("scaleFactorY", scaleFactorY.toString());
|
||
963 | insert.setScaleFactor(scaleFactor); |
||
964 | 73 | jmorell | } |
965 | 75 | jmorell | if (grp.hasCode(43)) { |
966 | 73 | jmorell | // TODO La coordenada z
|
967 | 75 | jmorell | } |
968 | if (grp.hasCode(50)) { |
||
969 | 73 | jmorell | rotAngle = grp.getDataAsDouble(50);
|
970 | 74 | jmorell | //Double objRotAngle = new Double(rotAngle);
|
971 | //feature.setProp("rotAngle", objRotAngle.toString());
|
||
972 | insert.setRotAngle(rotAngle); |
||
973 | 73 | jmorell | } |
974 | 44 | jmorell | if (grp.hasCode(210)) |
975 | xtruX = grp.getDataAsDouble(210);
|
||
976 | if (grp.hasCode(220)) |
||
977 | xtruY = grp.getDataAsDouble(220);
|
||
978 | if (grp.hasCode(230)) |
||
979 | xtruZ = grp.getDataAsDouble(230);
|
||
980 | Point3D point_in = new Point3D(x, y, z);
|
||
981 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
982 | Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
||
983 | x = point_out.getX(); |
||
984 | y = point_out.getY(); |
||
985 | |||
986 | 73 | jmorell | insert.setBlkList(blkList); |
987 | 44 | jmorell | |
988 | 73 | jmorell | insert.encuentraBloque(blockName); |
989 | 44 | jmorell | |
990 | 74 | jmorell | insert.add(new Point2D.Double(x, y)); |
991 | secondGeom.add(new Point2D.Double(x, y)); |
||
992 | 73 | jmorell | |
993 | 74 | jmorell | feature.setGeometry(insert); |
994 | secondFeat.setGeometry(secondGeom); |
||
995 | |||
996 | 168 | jmorell | if (insert.getBlockFound()==true) gestionaInsert(feature); |
997 | 73 | jmorell | |
998 | if (addingToBlock == false) { |
||
999 | 74 | jmorell | features.add(secondFeat); |
1000 | 44 | jmorell | } |
1001 | 168 | jmorell | // 040929: Modificado para a?adir el insert aunque no se haya encontrado
|
1002 | // el bloque.
|
||
1003 | if (addingToBlock == true/* && insert.getBlockFound() == true*/) { |
||
1004 | 102 | jmorell | //System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
|
1005 | 73 | jmorell | blk.add(feature); |
1006 | } |
||
1007 | 44 | jmorell | } |
1008 | |||
1009 | 82 | jmorell | public void createSolid(DxfGroupVector grp) throws Exception { |
1010 | double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0, z3 = 0.0, z4 = 0.0; |
||
1011 | DxfGroup g = null;
|
||
1012 | //Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
|
||
1013 | Point2D[] pts = new Point2D[4]; |
||
1014 | //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
1015 | 44 | jmorell | |
1016 | 142 | jmorell | LineString lineString = new LineString();
|
1017 | 82 | jmorell | Polygon polygon = new Polygon(); |
1018 | 142 | jmorell | Feature feaBordes = new Feature();
|
1019 | Feature feaFondos = new Feature();
|
||
1020 | 124 | jmorell | double elev = 0; |
1021 | 82 | jmorell | |
1022 | 142 | jmorell | feaBordes.setProp("dxfEntity", "Solid"); |
1023 | feaFondos.setProp("dxfEntity", "Solid"); |
||
1024 | 128 | jmorell | if (grp.hasCode(8)) |
1025 | 142 | jmorell | feaBordes.setProp("layer", grp.getDataAsString(8)); |
1026 | feaFondos.setProp("layer", grp.getDataAsString(8)); |
||
1027 | 82 | jmorell | x = grp.getDataAsDouble(10);
|
1028 | y = grp.getDataAsDouble(20);
|
||
1029 | 124 | jmorell | if (grp.hasCode(30)) { |
1030 | z1 = grp.getDataAsDouble(30);
|
||
1031 | elev = z1; |
||
1032 | Double doub = new Double(elev); |
||
1033 | String string = doub.toString();
|
||
1034 | 142 | jmorell | feaBordes.setProp("elevation", string);
|
1035 | feaFondos.setProp("elevation", string);
|
||
1036 | 124 | jmorell | } |
1037 | 82 | jmorell | pts[0] = proj.createPoint(x, y);
|
1038 | x = grp.getDataAsDouble(11);
|
||
1039 | y = grp.getDataAsDouble(21);
|
||
1040 | if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31); |
||
1041 | pts[1] = proj.createPoint(x, y);
|
||
1042 | x = grp.getDataAsDouble(12);
|
||
1043 | y = grp.getDataAsDouble(22);
|
||
1044 | if (grp.hasCode(32)) z3 = grp.getDataAsDouble(32); |
||
1045 | pts[2] = proj.createPoint(x, y);
|
||
1046 | x = grp.getDataAsDouble(13);
|
||
1047 | y = grp.getDataAsDouble(23);
|
||
1048 | if (grp.hasCode(33)) z2 = grp.getDataAsDouble(33); |
||
1049 | pts[3] = proj.createPoint(x, y);
|
||
1050 | 124 | jmorell | if (grp.hasCode(39)) { |
1051 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
1052 | String string = doub.toString();
|
||
1053 | 142 | jmorell | feaBordes.setProp("thickness", string);
|
1054 | feaFondos.setProp("thickness", string);
|
||
1055 | 124 | jmorell | } else {
|
1056 | Double doub = new Double(0.0); |
||
1057 | 142 | jmorell | feaBordes.setProp("thickness", doub.toString());
|
1058 | feaFondos.setProp("thickness", doub.toString());
|
||
1059 | 124 | jmorell | } |
1060 | 82 | jmorell | if (grp.hasCode(62)) { |
1061 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
1062 | String string = integer.toString();
|
||
1063 | 142 | jmorell | feaBordes.setProp("color", string);
|
1064 | feaFondos.setProp("color", string);
|
||
1065 | 166 | jmorell | feaBordes.setProp("colorByLayer", "false"); |
1066 | feaFondos.setProp("colorByLayer", "false"); |
||
1067 | 82 | jmorell | } else {
|
1068 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
1069 | int clr = layer.colorNumber;
|
||
1070 | Integer integer = new Integer(clr); |
||
1071 | String string = integer.toString();
|
||
1072 | 142 | jmorell | feaBordes.setProp("color", string);
|
1073 | feaFondos.setProp("color", string);
|
||
1074 | 166 | jmorell | feaBordes.setProp("colorByLayer", "true"); |
1075 | feaFondos.setProp("colorByLayer", "true"); |
||
1076 | 82 | jmorell | } |
1077 | if (grp.hasCode(210)) |
||
1078 | xtruX = grp.getDataAsDouble(210);
|
||
1079 | if (grp.hasCode(220)) |
||
1080 | 162 | luisw | xtruY = grp.getDataAsDouble(220);
|
1081 | 82 | jmorell | if (grp.hasCode(230)) |
1082 | 162 | luisw | xtruZ = grp.getDataAsDouble(230);
|
1083 | 82 | jmorell | Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1); |
1084 | Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2); |
||
1085 | Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3); |
||
1086 | Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4); |
||
1087 | Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
||
1088 | Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
|
||
1089 | Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
|
||
1090 | Point2D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru);
|
||
1091 | Point2D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru);
|
||
1092 | pts[0].setLocation(point_out1);
|
||
1093 | pts[1].setLocation(point_out2);
|
||
1094 | pts[2].setLocation(point_out3);
|
||
1095 | pts[3].setLocation(point_out4);
|
||
1096 | |||
1097 | 106 | jmorell | Point2D aux = pts[2]; |
1098 | pts[2] = pts[3]; |
||
1099 | pts[3] = aux;
|
||
1100 | |||
1101 | 82 | jmorell | for (int i=0; i<pts.length; i++) { |
1102 | 142 | jmorell | lineString.add(pts[i]); |
1103 | 82 | jmorell | polygon.add(pts[i]); |
1104 | } |
||
1105 | |||
1106 | 106 | jmorell | // Para cerrarlos.
|
1107 | 142 | jmorell | lineString.add(pts[0]);
|
1108 | 106 | jmorell | polygon.add(pts[0]);
|
1109 | |||
1110 | 142 | jmorell | feaBordes.setGeometry(lineString); |
1111 | feaFondos.setGeometry(polygon); |
||
1112 | 82 | jmorell | //features.add(feature);
|
1113 | if (addingToBlock == false) { |
||
1114 | 102 | jmorell | //System.out.println("createSolid(): A?ade un solid a la lista de entidades");
|
1115 | 142 | jmorell | features.add(feaBordes); |
1116 | features.add(feaFondos); |
||
1117 | 82 | jmorell | } else {
|
1118 | 102 | jmorell | //System.out.println("createSolid(): A?adimos un circulo al bloque " + iterator);
|
1119 | 142 | jmorell | blk.add(feaBordes); |
1120 | blk.add(feaFondos); |
||
1121 | 82 | jmorell | } |
1122 | 44 | jmorell | } |
1123 | |||
1124 | 73 | jmorell | public void createBlock(DxfGroupVector grp) throws Exception { |
1125 | //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
1126 | blk = new FeatureCollection(proj);
|
||
1127 | 44 | jmorell | |
1128 | 73 | jmorell | Point2D basePoint = new Point2D.Double(); |
1129 | String blockName = ""; |
||
1130 | 102 | jmorell | //System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
|
1131 | 73 | jmorell | |
1132 | addingToBlock = true;
|
||
1133 | 102 | jmorell | //System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
|
1134 | 73 | jmorell | blkList.add(iterator, blk); |
1135 | |||
1136 | 102 | jmorell | //System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
|
1137 | 73 | jmorell | |
1138 | 74 | jmorell | if (grp.hasCode(8)) |
1139 | blk.setProp("layer", grp.getDataAsString(8)); |
||
1140 | if (grp.hasCode(62)) { |
||
1141 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
1142 | String string = integer.toString();
|
||
1143 | blk.setProp("color", string);
|
||
1144 | 166 | jmorell | blk.setProp("colorByLayer", "false"); |
1145 | 74 | jmorell | } else {
|
1146 | 128 | jmorell | DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
|
1147 | int clr = layer.colorNumber;
|
||
1148 | Integer integer = new Integer(clr); |
||
1149 | String string = integer.toString();
|
||
1150 | blk.setProp("color", string);
|
||
1151 | 166 | jmorell | blk.setProp("colorByLayer", "true"); |
1152 | 74 | jmorell | } |
1153 | |||
1154 | 73 | jmorell | if (grp.hasCode(1)) { |
1155 | blockName = grp.getDataAsString(1);
|
||
1156 | //blk.setBlkName(blockName);
|
||
1157 | blk.setProp("blockName", blockName);
|
||
1158 | } |
||
1159 | if (grp.hasCode(2)) { |
||
1160 | blockName = grp.getDataAsString(2);
|
||
1161 | //blk.setBlkName(blockName);
|
||
1162 | blk.setProp("blockName", blockName);
|
||
1163 | } |
||
1164 | if (grp.hasCode(3)) { |
||
1165 | blockName = grp.getDataAsString(3);
|
||
1166 | //blk.setBlkName(blockName);
|
||
1167 | blk.setProp("blockName", blockName);
|
||
1168 | } |
||
1169 | if (grp.hasCode(10)) { |
||
1170 | //basePoint.setLocation(grp.getDataAsDouble(10), basePoint.getY());
|
||
1171 | //blk.setBPoint(basePoint);
|
||
1172 | Double basePointX = new Double(grp.getDataAsDouble(10)); |
||
1173 | blk.setProp("basePointX", basePointX.toString());
|
||
1174 | } |
||
1175 | if (grp.hasCode(20)) { |
||
1176 | //basePoint.setLocation(basePoint.getX(), grp.getDataAsDouble(20));
|
||
1177 | //blk.setBPoint(basePoint);
|
||
1178 | Double basePointY = new Double(grp.getDataAsDouble(20)); |
||
1179 | blk.setProp("basePointY", basePointY.toString());
|
||
1180 | } |
||
1181 | if (grp.hasCode(30)) { |
||
1182 | 124 | jmorell | //basePoint.setLocation(basePoint.getZ(), grp.getDataAsDouble(30));
|
1183 | //blk.setBPoint(basePoint);
|
||
1184 | Double basePointZ = new Double(grp.getDataAsDouble(30)); |
||
1185 | blk.setProp("basePointZ", basePointZ.toString());
|
||
1186 | 73 | jmorell | } |
1187 | if (grp.hasCode(70)) { |
||
1188 | //blk.flags = grp.getDataAsInt(70);
|
||
1189 | Integer blockFlags = new Integer(grp.getDataAsInt(70)); |
||
1190 | blk.setProp("blockFlags", blockFlags.toString());
|
||
1191 | } |
||
1192 | 44 | jmorell | } |
1193 | |||
1194 | public void endBlk(DxfGroupVector grp) throws Exception { |
||
1195 | 73 | jmorell | //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1196 | setAddingToBlock(false);
|
||
1197 | iterator = iterator + 1;
|
||
1198 | } |
||
1199 | |||
1200 | 78 | luisw | public void testBlocks() { |
1201 | System.out.println("getBlkList() = " + getBlkList()); |
||
1202 | Vector blkList = getBlkList();
|
||
1203 | FeatureCollection block = null;
|
||
1204 | Feature feature = null;
|
||
1205 | InsPoint insert = null;
|
||
1206 | Point2D point1 = new Point2D.Double(); |
||
1207 | Point2D point2 = new Point2D.Double(); |
||
1208 | System.out.println("blkList = " + blkList); |
||
1209 | System.out.println("blkList.size() = " + blkList.size()); |
||
1210 | for (int i=0; i<blkList.size(); i++) { |
||
1211 | System.out.println("compruebaBloques(): Bloque " + i +" de " + blkList.size()); |
||
1212 | block = (FeatureCollection) blkList.get(i); |
||
1213 | 96 | luisw | int aux = block.size();
|
1214 | 78 | luisw | for (int j=0; j<aux; j++) { |
1215 | 96 | luisw | feature = (Feature)block.get(j); |
1216 | 78 | luisw | //if (feature.getGeometry() instanceof InsPoint && feature.getProp("isAnInsert") == "true") {
|
1217 | if (feature.getGeometry() instanceof InsPoint) { |
||
1218 | insert = (InsPoint)feature.getGeometry(); |
||
1219 | String nomBlock = insert.getBlockName();
|
||
1220 | System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", inserta el bloque = " + nomBlock); |
||
1221 | System.out.println("compruebaBloques(): insert.get(0) = " + insert.get(0)); |
||
1222 | System.out.println("compruebaBloques(): feature.getProp(rotAngle) = " + insert.getRotAngle()); |
||
1223 | System.out.println("compruebaBloques(): insert.getScaleFactor() = " + insert.getScaleFactor()); |
||
1224 | //if (feature.getProp("blockFound") == "false") {
|
||
1225 | if (insert.getBlockFound() == false) { |
||
1226 | System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock); |
||
1227 | 168 | jmorell | insert.encuentraBloque(nomBlock); |
1228 | //gestionaInsert(feature);
|
||
1229 | //block.add(feature);
|
||
1230 | 78 | luisw | } |
1231 | |||
1232 | } |
||
1233 | } |
||
1234 | } |
||
1235 | } |
||
1236 | |||
1237 | 73 | jmorell | public void gestionaInsert(Feature feature) { |
1238 | Feature feature2 = null;
|
||
1239 | Point point = null; |
||
1240 | LineString lineString = null;
|
||
1241 | Polygon polygon = null; |
||
1242 | 74 | jmorell | InsPoint insert = new InsPoint();
|
1243 | insert = (InsPoint)feature.getGeometry(); |
||
1244 | 77 | jmorell | double bPointX = 0.0; |
1245 | double bPointY = 0.0; |
||
1246 | 168 | jmorell | //if (insert.getBlockFound() == true) {
|
1247 | 77 | jmorell | bPointX = Double.parseDouble(insert.getBlock().getProp("basePointX")); |
1248 | bPointY = Double.parseDouble(insert.getBlock().getProp("basePointY")); |
||
1249 | 168 | jmorell | //}
|
1250 | 74 | jmorell | double sFactorX = insert.getScaleFactor().getX();
|
1251 | double sFactorY = insert.getScaleFactor().getY();
|
||
1252 | 104 | jmorell | double rAngleGra = insert.getRotAngle();
|
1253 | double rAngleRad = rAngleGra*Math.PI/180.0; |
||
1254 | 73 | jmorell | InsPoint insert2 = null;
|
1255 | 44 | jmorell | |
1256 | 96 | luisw | for (int i=0; i<insert.getBlock().size(); i++) { |
1257 | 102 | jmorell | //System.out.println("gestionaInserts: insert.getBlock().features.size() = " + insert.getBlock().size());
|
1258 | 119 | jmorell | feature2 = (Feature)insert.getBlock().get(i); |
1259 | 100 | jmorell | |
1260 | 122 | jmorell | // Para que los elementos dentro del bloque tengan la misma layer
|
1261 | 145 | jmorell | // y color que el insert al que corresponden.
|
1262 | 161 | jmorell | // Segun la especificacion del formato DXF de Autodesk, la layer
|
1263 | // de las entities dentro de in bloque es la del bloque. La
|
||
1264 | // layer especifica para estos elementos en la defincion del
|
||
1265 | // bloque se ignora.
|
||
1266 | 168 | jmorell | System.out.println("TTTTTT: layer = " + feature2.getProp("layer")); |
1267 | if ((feature2.getProp("colorByLayer").equals("false") || feature2.getProp("layer").equals("0")) && !feature.getProp("layer").equals("0")) { |
||
1268 | 166 | jmorell | feature2.setProp("color", feature.getProp("color")); |
1269 | } |
||
1270 | 168 | jmorell | feature2.setProp("layer", feature.getProp("layer")); |
1271 | 100 | jmorell | |
1272 | 73 | jmorell | Point2D point1 = new Point2D.Double(); |
1273 | Point2D point11 = new Point2D.Double(); |
||
1274 | 119 | jmorell | Point2D pointAux = null; |
1275 | 103 | jmorell | |
1276 | 73 | jmorell | if (feature2.getGeometry() instanceof InsPoint){ |
1277 | 148 | jmorell | |
1278 | System.out.println("Encuentra bloques dentro de bloques"); |
||
1279 | |||
1280 | 74 | jmorell | insert2 = (InsPoint)feature2.getGeometry(); |
1281 | 73 | jmorell | point1 = insert2.get(0);
|
1282 | 117 | jmorell | |
1283 | 119 | jmorell | pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY); |
1284 | double laX = insert.get(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad)); |
||
1285 | double laY = insert.get(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad)); |
||
1286 | 103 | jmorell | point11.setLocation(laX, laY); |
1287 | 73 | jmorell | InsPoint insert3 = new InsPoint();
|
1288 | |||
1289 | 74 | jmorell | insert3.add(point11); |
1290 | 73 | jmorell | |
1291 | 74 | jmorell | insert3.setBlkList(insert2.getBlkList()); |
1292 | insert3.setBlock(insert2.getBlock()); |
||
1293 | insert3.setBlockName(insert2.getBlockName()); |
||
1294 | insert3.setRotAngle(insert2.getRotAngle()); |
||
1295 | 119 | jmorell | Point2D newScale = new Point2D.Double(insert2.getScaleFactor().getX() * sFactorX, insert2.getScaleFactor().getY() * sFactorY); |
1296 | insert3.setScaleFactor(newScale); |
||
1297 | 73 | jmorell | |
1298 | 74 | jmorell | Feature feature3 = new Feature();
|
1299 | feature3.setProp("layer", feature2.getProp("layer")); |
||
1300 | feature3.setProp("color", feature2.getProp("color")); |
||
1301 | 124 | jmorell | feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
1302 | feature3.setProp("elevation", feature2.getProp("elevation")); |
||
1303 | 74 | jmorell | feature3.setGeometry(insert3); |
1304 | 73 | jmorell | |
1305 | 74 | jmorell | gestionaInsert(feature3); |
1306 | 73 | jmorell | } else if (feature2.getGeometry() instanceof LineString) { |
1307 | 74 | jmorell | lineString = (LineString)feature2.getGeometry(); |
1308 | 73 | jmorell | LineString lineString2 = new LineString();
|
1309 | Point2D[] points = new Point2D[lineString.pointNr()]; |
||
1310 | Point2D[] pointss = new Point2D[lineString.pointNr()]; |
||
1311 | for (int j=0; j<lineString.pointNr(); j++) { |
||
1312 | points[j] = (Point2D)lineString.get(j);
|
||
1313 | 74 | jmorell | pointss[j] = new Point2D.Double(); |
1314 | 117 | jmorell | |
1315 | 119 | jmorell | pointAux = new Point2D.Double(points[j].getX() - bPointX, points[j].getY() - bPointY); |
1316 | double laX = insert.get(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad)); |
||
1317 | double laY = insert.get(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad)); |
||
1318 | 103 | jmorell | pointss[j].setLocation(laX, laY); |
1319 | 73 | jmorell | lineString2.add(pointss[j]); |
1320 | } |
||
1321 | 74 | jmorell | |
1322 | Feature feature3 = new Feature();
|
||
1323 | feature3.setProp("layer", feature2.getProp("layer")); |
||
1324 | feature3.setProp("color", feature2.getProp("color")); |
||
1325 | 124 | jmorell | feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
1326 | feature3.setProp("elevation", feature2.getProp("elevation")); |
||
1327 | feature3.setProp("thickness", feature2.getProp("thickness")); |
||
1328 | 74 | jmorell | feature3.setGeometry(lineString2); |
1329 | |||
1330 | if (addingToBlock == false) { |
||
1331 | features.add(feature3); |
||
1332 | 73 | jmorell | } |
1333 | 74 | jmorell | } else if (feature2.getGeometry() instanceof Polygon) { |
1334 | polygon = (Polygon)feature2.getGeometry();
|
||
1335 | Polygon polygon2 = new Polygon(); |
||
1336 | Point2D[] points = new Point2D[polygon.pointNr()]; |
||
1337 | Point2D[] pointss = new Point2D[polygon.pointNr()]; |
||
1338 | for (int j=0; j<polygon.pointNr(); j++) { |
||
1339 | points[j] = (Point2D)polygon.get(j);
|
||
1340 | 103 | jmorell | pointss[j] = new Point2D.Double(); |
1341 | 117 | jmorell | |
1342 | 119 | jmorell | points[j].setLocation(points[j].getX() - bPointX, points[j].getY() - bPointY); |
1343 | double laX = insert.get(0).getX() + ((points[j].getX()*sFactorX)*Math.cos(rAngleRad) + (points[j].getY()*sFactorY)*(-1)*Math.sin(rAngleRad)); |
||
1344 | double laY = insert.get(0).getY() + ((points[j].getX()*sFactorX)*Math.sin(rAngleRad) + (points[j].getY()*sFactorY)*Math.cos(rAngleRad)); |
||
1345 | 103 | jmorell | pointss[j].setLocation(laX, laY); |
1346 | 74 | jmorell | polygon2.add(pointss[j]); |
1347 | 73 | jmorell | } |
1348 | 74 | jmorell | |
1349 | Feature feature3 = new Feature();
|
||
1350 | feature3.setProp("layer", feature2.getProp("layer")); |
||
1351 | feature3.setProp("color", feature2.getProp("color")); |
||
1352 | 124 | jmorell | feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
1353 | feature3.setProp("elevation", feature2.getProp("elevation")); |
||
1354 | feature3.setProp("thickness", feature2.getProp("thickness")); |
||
1355 | 74 | jmorell | feature3.setGeometry(polygon2); |
1356 | |||
1357 | if (addingToBlock == false) { |
||
1358 | features.add(feature3); |
||
1359 | } |
||
1360 | } else if (feature2.getGeometry() instanceof Point) { |
||
1361 | point = (Point)feature2.getGeometry();
|
||
1362 | point1 = point.get(0);
|
||
1363 | 117 | jmorell | |
1364 | 119 | jmorell | pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY); |
1365 | double laX = insert.get(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad)); |
||
1366 | double laY = insert.get(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad)); |
||
1367 | 103 | jmorell | point11.setLocation(laX, laY); |
1368 | 74 | jmorell | Point pointt = new Point(); |
1369 | pointt.add(point11); |
||
1370 | |||
1371 | Feature feature3 = new Feature();
|
||
1372 | feature3.setProp("layer", feature2.getProp("layer")); |
||
1373 | feature3.setProp("color", feature2.getProp("color")); |
||
1374 | 124 | jmorell | feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
1375 | feature3.setProp("elevation", feature2.getProp("elevation")); |
||
1376 | feature3.setProp("thickness", feature2.getProp("thickness")); |
||
1377 | 122 | jmorell | if (point.isText) {
|
1378 | feature3.setProp("text", feature2.getProp("text")); |
||
1379 | } |
||
1380 | 74 | jmorell | feature3.setGeometry(pointt); |
1381 | |||
1382 | if (addingToBlock == false) { |
||
1383 | features.add(feature3); |
||
1384 | } |
||
1385 | 73 | jmorell | } else {
|
1386 | 119 | jmorell | System.out.println("gestionaInserts: Encontrado elemento desconocido"); |
1387 | 73 | jmorell | } |
1388 | } |
||
1389 | 44 | jmorell | } |
1390 | |||
1391 | /* (non-Javadoc)
|
||
1392 | * @see org.cresques.io.DxfFile.EntityFactory#getExtent()
|
||
1393 | */
|
||
1394 | public Extent getExtent() {
|
||
1395 | Feature feature = new Feature();
|
||
1396 | Extent extent = new Extent();
|
||
1397 | Iterator iter = features.iterator();
|
||
1398 | while (iter.hasNext()) {
|
||
1399 | feature = (Feature)iter.next(); |
||
1400 | extent.add(feature.getExtent()); |
||
1401 | } |
||
1402 | return extent;
|
||
1403 | } |
||
1404 | |||
1405 | 94 | luisw | public void setProjection(IProjection p) { |
1406 | 44 | jmorell | proj = p; |
1407 | } |
||
1408 | |||
1409 | /* (non-Javadoc)
|
||
1410 | * @see org.cresques.io.DxfFile.EntityFactory#reProject(org.cresques.geo.ReProjection)
|
||
1411 | */
|
||
1412 | 94 | luisw | public void reProject(ICoordTrans rp) { |
1413 | 44 | jmorell | Feature feature = new Feature();
|
1414 | Extent extent = new Extent();
|
||
1415 | Iterator iter = features.iterator();
|
||
1416 | while (iter.hasNext()) {
|
||
1417 | feature = (Feature)iter.next(); |
||
1418 | ((Projected) feature).reProject(rp); |
||
1419 | extent.add(feature.getExtent()); |
||
1420 | } |
||
1421 | setProjection(rp.getPDest()); |
||
1422 | } |
||
1423 | |||
1424 | /* (non-Javadoc)
|
||
1425 | * @see org.cresques.geo.Projected#getProjection()
|
||
1426 | */
|
||
1427 | 94 | luisw | public IProjection getProjection() {
|
1428 | 44 | jmorell | return proj;
|
1429 | } |
||
1430 | |||
1431 | 96 | luisw | public IObjList getObjects() { return features;} |
1432 | 44 | jmorell | |
1433 | 91 | luisw | public void draw(Graphics2D g, ViewPortData vp) { |
1434 | 44 | jmorell | Iterator iter = features.iterator();
|
1435 | Extent extent; |
||
1436 | while (iter.hasNext()) {
|
||
1437 | Feature feature = new Feature();
|
||
1438 | feature = (Feature)iter.next(); |
||
1439 | extent = feature.getExtent(); |
||
1440 | if (vp.getExtent().minX()> extent.maxX()) continue; |
||
1441 | if (vp.getExtent().minY()> extent.maxY()) continue; |
||
1442 | if (vp.getExtent().maxX()< extent.minX()) continue; |
||
1443 | if (vp.getExtent().maxY()< extent.minY()) continue; |
||
1444 | //if (!feature.layer.frozen)
|
||
1445 | feature.draw(g, vp); |
||
1446 | } |
||
1447 | } |
||
1448 | |||
1449 | public static Vector createArc(Point2D coord1, Point2D coord2, double bulge) { |
||
1450 | return new DxfCalArcs(coord1, coord2, bulge).getPoints(1); |
||
1451 | } |
||
1452 | 62 | jmorell | |
1453 | /* (non-Javadoc)
|
||
1454 | * @see org.cresques.io.DxfFile.EntityFactory#getBlkList()
|
||
1455 | */
|
||
1456 | public Vector getBlkList() { |
||
1457 | 76 | jmorell | return blkList;
|
1458 | 62 | jmorell | } |
1459 | 66 | jmorell | |
1460 | /* (non-Javadoc)
|
||
1461 | * @see org.cresques.io.DxfFile.EntityFactory#getDxfEntityList()
|
||
1462 | */
|
||
1463 | public DxfEntityList getDxfEntityList() {
|
||
1464 | // TODO Auto-generated method stub
|
||
1465 | return null; |
||
1466 | } |
||
1467 | 69 | jmorell | |
1468 | /* (non-Javadoc)
|
||
1469 | * @see org.cresques.io.DxfFile.EntityFactory#getBlk()
|
||
1470 | */
|
||
1471 | public DxfBlock getBlk() {
|
||
1472 | // TODO Auto-generated method stub
|
||
1473 | return null; |
||
1474 | } |
||
1475 | 90 | jmorell | |
1476 | /* (non-Javadoc)
|
||
1477 | * @see org.cresques.io.DxfFile.EntityFactory#createSpline(org.cresques.io.DxfGroupVector)
|
||
1478 | */
|
||
1479 | public void createSpline(DxfGroupVector v) throws Exception { |
||
1480 | // TODO Auto-generated method stub
|
||
1481 | |||
1482 | } |
||
1483 | 44 | jmorell | |
1484 | } |