Revision 1922 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dwg/DwgMemoryDriver.java

View differences:

DwgMemoryDriver.java
130 130
		long time = System.currentTimeMillis();
131 131
		dwg.read(m_Fich.getAbsolutePath());
132 132
		dwg.calculateDwgPolylines();
133
		//dwg.initializeLayerTable();
134
		dwg.manageInserts();
133 135
		long timeElapsed = System.currentTimeMillis()-time;
134 136
		System.out.println("Tiempo empleado en leer el fichero dwg = " + timeElapsed);
135 137
		dwgObjects = dwg.getDwgObjects();
......
157 159
		
158 160
    	getTableModel().setColumnIdentifiers(arrayFields.toArray());
159 161
		
160
    	boolean addingToBlock = false;
162
    	//boolean addingToBlock = false;
161 163
    	
162 164
		time = System.currentTimeMillis();
163 165
		
......
181 183
            auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
182 184
			
183 185
			DwgObject entity = (DwgObject)dwgObjects.get(i);
184
			if (entity.getType()==0x11 && !addingToBlock) {
185
				//System.out.println("Encuentra un Arc ...");
186
				/*DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
187
				double[] coord = (double[])data.getValue();
188
				Point2D center = new Point2D.Double(coord[0], coord[1]);
189
				data = entity.getDwgObjectSpecificDataItem("RADIUS");
190
				double radius = ((Double)data.getValue()).doubleValue();
191
				data = entity.getDwgObjectSpecificDataItem("START_ANGLE");
192
				double startAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
193
				data = entity.getDwgObjectSpecificDataItem("END_ANGLE");
194
				double endAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());*/
186
			//if (entity.getType()==0x11 && !addingToBlock) {
187
			if (entity.getType()==0x11) {
195 188
				double[] c = ((DwgArc)entity).getCenter();
196 189
				Point2D center = new Point2D.Double(c[0], c[1]);
197 190
				double radius = ((DwgArc)entity).getRadius();
......
222 215
                	}
223 216
            	}*/
224 217
				addShape(arcc, auxRow);
225
			} else if (entity.getType()==0x12 && !addingToBlock) {
218
			//} else if (entity.getType()==0x12 && !addingToBlock) {
219
			} else if (entity.getType()==0x12) {
226 220
				//System.out.println("Encuentra un Circle ...");
227 221
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
228 222
				//double[] coord = (double[])data.getValue();
......
255 249
                	}
256 250
            	}*/
257 251
				addShape(circle, auxRow);
258
			} else if (entity.getType()==0x13 && !addingToBlock) {
252
			//} else if (entity.getType()==0x13 && !addingToBlock) {
253
			} else if (entity.getType()==0x13) {
259 254
				//System.out.println("Encuentra una Line ...");
260 255
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("P1");
261 256
				//double[] coord = (double[])data.getValue();
......
289 284
                	}
290 285
            	}*/
291 286
				addShape(line, auxRow);
292
			} else if (entity.getType()==0x1B && !addingToBlock) {
287
			//} else if (entity.getType()==0x1B && !addingToBlock) {
288
			} else if (entity.getType()==0x1B) {
293 289
				//System.out.println("Encuentra un Point ...");
294 290
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("POINT");
295 291
				//double[] coord = (double[])data.getValue();
......
318 314
                	}
319 315
            	}*/
320 316
				addShape(point, auxRow);
321
			} else if (entity.getType()==0x0F && !addingToBlock) {
322
				//System.out.println("Encuentra una Polyline2D ...");
323
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("FLAGS");
324
				//int flags = ((Integer)data.getValue()).intValue();
325
				/*int flags = ((DwgPolyline2D)entity).getFlags();
326
				int firstHandle = ((DwgPolyline2D)entity).getFirstVertexHandle();
327
				int lastHandle = ((DwgPolyline2D)entity).getLastVertexHandle();
328
				Vector pts = new Vector();
329
				Vector bulges = new Vector();
330
				double[] pt = new double[2];
331
				
332
				for (int j=0;j<dwgObjects.size();j++) {
333
					DwgObject obj = (DwgObject)dwgObjects.get(j);
334
					int objHandle = obj.getHandle();
335
					//if (objHandle==firstHandle && ((Integer)handle.get(1)).intValue()==firstVertexHandle[1]) {
336
					if (objHandle==firstHandle && obj instanceof DwgVertex2D) {
337
						int k=0;
338
						while (true) {
339
							DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
340
							int vHandle = vertex.getHandle();
341
							//data = vertex.getDwgObjectSpecificDataItem("POINT");
342
							//pt = (double[])data.getValue();
343
							pt = ((DwgVertex2D)vertex).getPoint();
344
							pts.add(new Point2D.Double(pt[0], pt[1]));
345
							//data = vertex.getDwgObjectSpecificDataItem("BULGE");
346
							//double bulge = ((Double)data.getValue()).doubleValue();
347
							double bulge = ((DwgVertex2D)vertex).getBulge();
348
							bulges.add(new Double(bulge));
349
							k++;
350
							//if (vHandle==lastHandle && ((Integer)vertexHandle.get(1)).intValue()==lastVertexHandle[1]) {
351
							if (vHandle==lastHandle) {
352
								break;
353
							}
354
						}
355
					}
356
				}
357
				
358
				Point2D[] newPts = new Point2D[pts.size()];
359
				if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) {
360
					for (int j=0;j<pts.size();j++) {
361
						newPts[j] = (Point2D)pts.get(j);
362
					}
363
				} else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) {
364
					newPts = new Point2D[pts.size()+1];
365
					for (int j=0;j<pts.size();j++) {
366
						newPts[j] = (Point2D)pts.get(j);
367
					}
368
					newPts[pts.size()] = (Point2D)pts.get(0);
369
					bulges.add(new Double(0));
370
				}
371
				FPolyline2D pline = createPolyline2D(newPts, bulges);*/
372
				//System.out.println("((DwgPolyline2D)entity).getPts().length = " + ((DwgPolyline2D)entity).getPts().length);
317
			//} else if (entity.getType()==0x0F && !addingToBlock) {
318
			} else if (entity.getType()==0x0F) {
373 319
				Point2D[] points = ((DwgPolyline2D)entity).getPts();
374 320
				FPolyline2D pline = points2DToFPolyline2D(points);
375 321
				auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
......
395 341
            	}*/
396 342
				addShape(pline, auxRow);
397 343
			// Implementaci?n parcial ...
398
			} else if (entity.getType()==0x10 && !addingToBlock) {
344
			//} else if (entity.getType()==0x10 && !addingToBlock) {
345
			} else if (entity.getType()==0x10) {
399 346
				//System.out.println("Encuentra una Polyline3D ...");
400 347
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CLOSED_FLAGS");
401 348
				//int flags = ((Integer)data.getValue()).intValue();
402 349
				int flags = ((DwgPolyline3D)entity).getClosedFlags();
403
				/*data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE");
404
				int[] firstVertexHandle = (int[])data.getValue();
405
				int = fi
406
				data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE");
407
				int[] lastVertexHandle = (int[])data.getValue();
408
				data = entity.getDwgObjectSpecificDataItem("SEQEND_HANDLE");
409
				int[] seqendHandle = (int[])data.getValue();
410
				int vertexNumber = calculateVertexNumber(firstVertexHandle, lastVertexHandle);
411
				Point2D[] pts = new Point2D[vertexNumber];
412
				double[] pt = new double[2];
413
				
414
				for (int j=0;j<dwgObjects.size();j++) {
415
					DwgObject v = (DwgObject)dwgObjects.get(j);
416
					Vector handle = v.getHandle();
417
					if (((Integer)handle.get(handle.size()-2)).intValue()==firstVertexHandle[handle.size()-2] && ((Integer)handle.get(handle.size()-1)).intValue()==firstVertexHandle[handle.size()-1]) {
418
						for (int k=0; k<vertexNumber; k++) {
419
							DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
420
							data = vertex.getDwgObjectSpecificDataItem("POINT");
421
							pt = (double[])data.getValue();
422
							pts[k] = new Point2D.Double(pt[0], pt[1]);
423
						}
424
					}
425
				}
426
				Point2D[] newPts = new Point2D[pts.length];
427
				if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) {
428
					newPts = pts;
429
				} else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) {
430
					newPts = new Point2D[pts.length+1];
431
					for (int j=0;j<pts.length;j++) {
432
						newPts[j] = pts[j];
433
					}
434
					newPts[pts.length] = pts[0];
435
				}
436
				FPolyline2D pline3d = createPolyline3D(newPts);
437
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
438
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline3D"));
439
				//int[] layerHandle = (int[])entity.getLayer();
440
				String layerName = getLayerName(entity, layerTable);
441
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
442
				int color = entity.getColor();
443
				int colorByLayer = getColorByLayer(entity, layerTable);
444
				//if (color==0) color ByBlock
445
				if (color==256) color = colorByLayer;
446
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
447
            	auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
448
            	auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/
449
            	// Attributes
450
            	/*for (int j=0;j<nAtt;j++) {
451
    				String[] attributes = new String[2];
452
    				attributes = (String[])featureMaker.getAttributes().get(j);
453
                	auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
454
                	if (!fea.getProp(attributes[0]).equals(attributes[1])) {
455
                		auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
456
                	}
457
            	}*/
458
				//addShape(pline3d, auxRow);
459
			} else if (entity.getType()==0x1 && !addingToBlock) {
350
			//} else if (entity.getType()==0x1 && !addingToBlock) {
351
			} else if (entity.getType()==0x1) {
460 352
				//System.out.println("Encuentra un Text ...");
461 353
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
462 354
				//Point2D p = (Point2D)data.getValue();
......
516 408
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("NAME");
517 409
				//String blockName = (String)data.getValue();
518 410
				String blockName = ((DwgBlock)entity).getName();
519
				addingToBlock = true;
411
				//addingToBlock = true;
520 412
				//pto = (Point2D.Double)point.get(0);
521 413
				//FShape nuevoShp;
522 414
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
......
543 435
				//addShape(point, auxRow);
544 436
			} else if (entity.getType()==0x5) {
545 437
				//System.out.println("Encuentra un Endblk ...");
546
				addingToBlock = false;
438
				//addingToBlock = false;
547 439
				//pto = (Point2D.Double)point.get(0);
548 440
				//FShape nuevoShp;
549 441
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
......
597 489
				//addShape(point, auxRow);
598 490
			} else if (entity.getType()==0x31) {
599 491
				//System.out.println("Encuentra un Block Header ...");
600
				addingToBlock = true;
492
				//addingToBlock = true;
601 493
				//pto = (Point2D.Double)point.get(0);
602 494
				//FShape nuevoShp;
603 495
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
......
622 514
                	}
623 515
            	}*/
624 516
				//addShape(point, auxRow);
625
			} else if (entity.getType()==0x7 && !addingToBlock) {
517
			//} else if (entity.getType()==0x7 && !addingToBlock) {
518
			} else if (entity.getType()==0x7) {
626 519
				//System.out.println("Encuentra un Insert ...");
627 520
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
628 521
				//double[] p = (double[])data.getValue();
......
638 531
				//int[] blockHandle = (int[])data.getValue();
639 532
				int blockHandle = ((DwgInsert)entity).getBlockHeaderHandle();
640 533
				
641
				manageInsert(dwgObjects, layerTable, point, scale, rot, blockHandle, i, auxRow);
534
				//manageInsert(dwgObjects, layerTable, point, scale, rot, blockHandle, i, auxRow);
642 535
				
643 536
				auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
644 537
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Insert"));
......
663 556
            	}*/
664 557
            	FPoint2D fPoint = new FPoint2D(point.getX(), point.getY());
665 558
				addShape(fPoint, auxRow);
666
			} else if (entity.getType()==0x2C && !addingToBlock) {
559
			//} else if (entity.getType()==0x2C && !addingToBlock) {
560
			} else if (entity.getType()==0x2C) {
667 561
				//System.out.println("Encuentra un MText ...");
668 562
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
669 563
				//double[] coord = (double[])data.getValue();
......
692 586
                	}
693 587
            	}*/
694 588
				addShape(point, auxRow);
695
			} else if (entity.getType()==0x1F && !addingToBlock) {
589
			//} else if (entity.getType()==0x1F && !addingToBlock) {
590
			} else if (entity.getType()==0x1F) {
696 591
				//System.out.println("Encuentra un Solid ...");
697 592
				//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CORNER1");
698 593
				//double[] coord = (double[])data.getValue();
......
733 628
                	}
734 629
            	}*/
735 630
				addShape(solid, auxRow);
736
			} else if (entity.getType()==0x2 && !addingToBlock) {
631
			//} else if (entity.getType()==0x2 && !addingToBlock) {
632
			} else if (entity.getType()==0x2) {
737 633
				//System.out.println("Encuentra un Attrib ...");
738 634
			/*} else if (entity.getType()==0x3 && !addingToBlock) {
739 635
				System.out.println("Encuentra un Attdef ...");*/
......
1018 914
		}
1019 915
	}*/
1020 916
	
1021
	private void manageInsert(Vector dwgObjects, Vector layerTable, Point2D insPoint, double[] scale, double rot, int bHandle, int id, Value[] auxRow) {
917
	/*private void manageInsert(Vector dwgObjects, Vector layerTable, Point2D insPoint, double[] scale, double rot, int bHandle, int id, Value[] auxRow) {
1022 918
		for (int j=0;j<dwgObjects.size();j++) {
1023 919
			DwgObject obj = (DwgObject)dwgObjects.get(j);
1024 920
			//DwgObjectSpecificDataItem dataa = obj.getDwgObjectSpecificDataItem("BLOCK_ENTITY_HANDLE");
......
1085 981
				}
1086 982
			}
1087 983
		}
1088
	}
984
	}*/
1089 985
	
1090
	private void manageBlockEntity(DwgObject entity, Vector layerTable, double[] bPoint, Point2D insPoint, double[] scale, double rot, DwgObject block, int id, Value[] auxRow) {
986
	/*private void manageBlockEntity(DwgObject entity, Vector layerTable, double[] bPoint, Point2D insPoint, double[] scale, double rot, DwgObject block, int id, Value[] auxRow) {
1091 987
		if (entity.getType()==0x11) {
1092 988
			//System.out.println("Encuentra un arco dentro de un bloque ...");
1093 989
			//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
......
1124 1020
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1125 1021
        	auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1126 1022
        	auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1127
        	// Attributes
1128
        	/*for (int j=0;j<nAtt;j++) {
1129
				String[] attributes = new String[2];
1130
				attributes = (String[])featureMaker.getAttributes().get(j);
1131
            	auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1132
            	if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1133
            		auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1134
            	}
1135
        	}*/
1136 1023
			addShape(arcc, auxRow);
1137 1024
		} else if (entity.getType()==0x12) {
1138 1025
			//System.out.println("Encuentra un c?rculo dentro de un bloque ...");
......
1165 1052
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1166 1053
        	auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1167 1054
        	auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1168
        	// Attributes
1169
        	/*for (int j=0;j<nAtt;j++) {
1170
				String[] attributes = new String[2];
1171
				attributes = (String[])featureMaker.getAttributes().get(j);
1172
            	auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1173
            	if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1174
            		auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1175
            	}
1176
        	}*/
1177 1055
			addShape(circle, auxRow);
1178 1056
		} else if (entity.getType()==0x13) {
1179 1057
			//System.out.println("Encuentra una l?nea dentro de un bloque ...");
......
1211 1089
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1212 1090
        	auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1213 1091
        	auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1214
        	// Attributes
1215
        	/*for (int j=0;j<nAtt;j++) {
1216
				String[] attributes = new String[2];
1217
				attributes = (String[])featureMaker.getAttributes().get(j);
1218
            	auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1219
            	if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1220
            		auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1221
            	}
1222
        	}*/
1223 1092
			addShape(line, auxRow);
1224 1093
		} else if (entity.getType()==0x7) {
1225 1094
			//System.out.println("Encuentra un insert dentro de un bloque ...");
......
1245 1114
			newScale = new double[]{scale[0]*newScale[0], scale[1]*newScale[1], scale[2]*newScale[2]};
1246 1115
			
1247 1116
			manageInsert(dwgObjects, layerTable, newInsPoint, newScale, newRot, newBlockHandle, id, auxRow);
1248
			
1249
			/*auxRow[ID_FIELD_ID] = ValueFactory.createValue(0);
1250
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
1251
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
1252
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
1253
        	auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1254
        	auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/
1255
        	// Attributes
1256
        	/*for (int j=0;j<nAtt;j++) {
1257
				String[] attributes = new String[2];
1258
				attributes = (String[])featureMaker.getAttributes().get(j);
1259
            	auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1260
            	if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1261
            		auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1262
            	}
1263
        	}*/
1264
        	/*FPoint2D fPoint = createPoint(newInsPoint);
1265
			addShape(fPoint, auxRow);*/
1266
		} else if (entity.getType()==0x0F) {
1117
		} else if (entity.getType()==0x0F) {*/
1267 1118
			//System.out.println("Encuentra una polil?nea dentro de un bloque ...");
1268 1119
			//DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("FLAGS");
1269 1120
			//int flags = ((Integer)data.getValue()).intValue();
......
1309 1160
				newPts[pts.size()] = (Point2D)pts.get(0);
1310 1161
				bulges.add(new Double(0));
1311 1162
			}*/
1312
			Point2D[] points = ((DwgPolyline2D)entity).getPts();
1163
			/*Point2D[] points = ((DwgPolyline2D)entity).getPts();
1313 1164
			for (int i=0;i<points.length;i++) {
1314 1165
				Point2D pointAux = new Point2D.Double(points[i].getX() - bPoint[0], points[i].getY() - bPoint[1]);
1315 1166
				double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
......
1330 1181
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1331 1182
        	auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1332 1183
        	auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1333
        	// Attributes
1334
        	/*for (int j=0;j<nAtt;j++) {
1335
				String[] attributes = new String[2];
1336
				attributes = (String[])featureMaker.getAttributes().get(j);
1337
            	auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1338
            	if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1339
            		auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1340
            	}
1341
        	}*/
1342 1184
			addShape(pline, auxRow);
1343 1185
		} else if (entity.getType()==0x2) {
1344 1186
			//System.out.println("Encuentra un Attrib dentro de un bloque ...");
1345 1187
		} else if (entity.getType()==0x3) {
1346 1188
			//System.out.println("Encuentra un Attdef dentro de un bloque ...");
1347 1189
		}
1348
	}
1190
	}*/
1349 1191
	
1350 1192
	/**
1351 1193
	 * LayerTable podr?a ser un objeto y LayerTableRecord tambi?n ...

Also available in: Unified diff