Revision 10305
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/DwgFile.java | ||
---|---|---|
107 | 107 |
acadVersions.put("AC1021", "Autocad R2007"); |
108 | 108 |
|
109 | 109 |
} |
110 |
|
|
110 |
/** |
|
111 |
* Path and name of the dwg file |
|
112 |
* */ |
|
111 | 113 |
private String fileName; |
114 |
/** |
|
115 |
* DWG version of the file (AC1013, AC1018, etc.) |
|
116 |
* */ |
|
112 | 117 |
private String dwgVersion; |
113 | 118 |
|
114 | 119 |
/** |
... | ... | |
164 | 169 |
* Contains all IDwgPolyline implementations |
165 | 170 |
* */ |
166 | 171 |
private List dwgPolylines; |
172 |
/** |
|
173 |
* Contains all INSERT entities of the dwg file |
|
174 |
* (these entities must be processed in a second pass) |
|
175 |
* |
|
176 |
* */ |
|
177 |
private List insertList; |
|
167 | 178 |
|
168 | 179 |
/** |
169 | 180 |
* Constructor. |
... | ... | |
176 | 187 |
dwgObjectOffsets = new ArrayList(); |
177 | 188 |
headerVars = new HashMap(); |
178 | 189 |
|
179 |
//TODO Si finalmente no se leen las clases, quitar |
|
180 |
//dwgClasses |
|
181 | 190 |
dwgClasses = new ArrayList(); |
182 | 191 |
|
183 | 192 |
dwgObjects = new LinkedList(); |
... | ... | |
186 | 195 |
layerTable = new HashMap(); |
187 | 196 |
|
188 | 197 |
dwgPolylines = new ArrayList(); |
198 |
insertList = new ArrayList(); |
|
189 | 199 |
} |
190 | 200 |
|
191 | 201 |
public String getDwgVersion() { |
... | ... | |
247 | 257 |
headerVars.put(key, value); |
248 | 258 |
} |
249 | 259 |
|
250 |
|
|
251 |
|
|
252 |
/** |
|
253 |
* Initialize a new Vector that contains the DWG file layers. |
|
254 |
* Each layer have three parameters. |
|
255 |
* These parameters are handle, name and color |
|
256 |
*/ |
|
257 |
// public void initializeLayerTable() { |
|
258 |
// layerTable = new ArrayList(); |
|
259 |
// for (int i=0;i<dwgObjects.size();i++) { |
|
260 |
// DwgObject obj = (DwgObject)dwgObjects.get(i); |
|
261 |
// if (obj instanceof DwgLayer) { |
|
262 |
// ArrayList layerTableRecord = new ArrayList(); |
|
263 |
// layerTableRecord.add(new Integer(obj.getHandle())); |
|
264 |
// layerTableRecord.add(((DwgLayer)obj).getName()); |
|
265 |
// layerTableRecord.add(new Integer(((DwgLayer)obj).getColor())); |
|
266 |
// layerTable.add(layerTableRecord); |
|
267 |
// } |
|
268 |
// } |
|
269 |
// } |
|
270 |
|
|
271 | 260 |
/* |
272 | 261 |
* A DwgLayer is a DWG drawing entity, so all DwgLayer objects are |
273 | 262 |
* saved in dwgObjects collection. |
... | ... | |
444 | 433 |
colorByLayer = dwgLyr.getColor(); |
445 | 434 |
return colorByLayer; |
446 | 435 |
} |
447 |
|
|
448 |
|
|
449 |
//azabala: esto ahora se hace conforme se van creando los objetos |
|
450 |
//(y no al final en una segunda pasada |
|
451 |
// public void applyExtrusions() { |
|
452 |
// for (int i=0;i<dwgObjects.size();i++) { |
|
453 |
// DwgObject dwgObject = (DwgObject)dwgObjects.get(i); |
|
454 |
// if(dwgObject instanceof IDwgExtrusionable){ |
|
455 |
// ((IDwgExtrusionable)dwgObject).applyExtrussion(); |
|
456 |
// } |
|
457 |
// // Seems that Autocad don't apply the extrusion to Ellipses |
|
458 |
// /*} else if (dwgObject instanceof DwgEllipse) { |
|
459 |
// double[] ellipseCenter = ((DwgEllipse)dwgObject).getCenter(); |
|
460 |
// double[] ellipseExt = ((DwgEllipse)dwgObject).getExtrusion(); |
|
461 |
// ellipseCenter = AcadExtrusionCalculator.CalculateAcadExtrusion(ellipseCenter, ellipseExt); |
|
462 |
// ((DwgEllipse)dwgObject).setCenter(ellipseCenter);*/ |
|
463 |
// }//for |
|
464 |
// } |
|
465 |
|
|
466 | 436 |
/** |
467 | 437 |
* Configure the geometry of the polylines in a DWG file from the vertex list in |
468 | 438 |
* this DWG file. This geometry is given by an array of Points. |
... | ... | |
476 | 446 |
* porque posiblemente una Linea requiera de vertices que vengan |
477 | 447 |
* despues, lo que complicar?a bastante todo.... |
478 | 448 |
* */ |
479 |
|
|
480 |
// for (int i=0;i<dwgObjects.size();i++) { |
|
449 |
|
|
481 | 450 |
for (int i = 0; i < dwgPolylines.size(); i++){ |
482 |
// DwgObject pol = (DwgObject)dwgObjects.get(i); |
|
483 | 451 |
DwgObject pol = (DwgObject)dwgPolylines.get(i); |
484 | 452 |
if (pol instanceof IDwgPolyline) { |
485 |
// ((IDwgPolyline)pol).calculateGisModel(dwgObjects); |
|
486 | 453 |
((IDwgPolyline)pol).calculateGisModel(this); |
487 | 454 |
} |
488 | 455 |
} |
... | ... | |
566 | 533 |
} |
567 | 534 |
} |
568 | 535 |
} |
569 |
/* |
|
536 |
|
|
570 | 537 |
public void blockManagement2(){ |
571 |
LinkedList dwgObjectsWithoutBlocks = new LinkedList(); |
|
572 |
boolean addingToBlock = false; |
|
573 |
try{ |
|
574 |
for (int i=0; i < dwgObjects.size(); i++) { |
|
575 |
DwgObject entity = (DwgObject)dwgObjects.get(i); |
|
576 |
if (entity instanceof DwgArc && !addingToBlock) { |
|
577 |
dwgObjectsWithoutBlocks.add(entity); |
|
578 |
} else if (entity instanceof DwgEllipse && !addingToBlock) { |
|
579 |
dwgObjectsWithoutBlocks.add(entity); |
|
580 |
} else if (entity instanceof DwgCircle && !addingToBlock) { |
|
581 |
dwgObjectsWithoutBlocks.add(entity); |
|
582 |
} else if (entity instanceof DwgPolyline2D && !addingToBlock) { |
|
583 |
dwgObjectsWithoutBlocks.add(entity); |
|
584 |
} else if (entity instanceof DwgPolyline3D && !addingToBlock) { |
|
585 |
dwgObjectsWithoutBlocks.add(entity); |
|
586 |
} else if (entity instanceof DwgLwPolyline && !addingToBlock) { |
|
587 |
dwgObjectsWithoutBlocks.add(entity); |
|
588 |
} else if (entity instanceof DwgSolid && !addingToBlock) { |
|
589 |
dwgObjectsWithoutBlocks.add(entity); |
|
590 |
} else if (entity instanceof DwgLine && !addingToBlock) { |
|
591 |
dwgObjectsWithoutBlocks.add(entity); |
|
592 |
} else if (entity instanceof DwgPoint && !addingToBlock) { |
|
593 |
dwgObjectsWithoutBlocks.add(entity); |
|
594 |
} else if (entity instanceof DwgMText && !addingToBlock) { |
|
595 |
dwgObjectsWithoutBlocks.add(entity); |
|
596 |
} else if (entity instanceof DwgText && !addingToBlock) { |
|
597 |
dwgObjectsWithoutBlocks.add(entity); |
|
598 |
} else if (entity instanceof DwgAttrib && !addingToBlock) { |
|
599 |
dwgObjectsWithoutBlocks.add(entity); |
|
600 |
} else if (entity instanceof DwgAttdef && !addingToBlock) { |
|
601 |
dwgObjectsWithoutBlocks.add(entity); |
|
602 |
} else if (entity instanceof DwgBlock) { |
|
603 |
addingToBlock = true; |
|
604 |
} else if (entity instanceof DwgEndblk) { |
|
605 |
addingToBlock = false; |
|
606 |
} else if (entity instanceof DwgBlockHeader) { |
|
607 |
addingToBlock = true; |
|
608 |
} |
|
609 |
//Segun esto, un insert solo se procesa dentro de un Block (o BlockHeader) |
|
610 |
//?Puede haber INSERT fuera de BLOCK-ENDBLK? |
|
611 |
else if (entity instanceof DwgInsert && !addingToBlock) { |
|
612 |
double[] p = ((DwgInsert)entity).getInsertionPoint(); |
|
613 |
Point2D point = new Point2D.Double(p[0], p[1]); |
|
614 |
double[] scale = ((DwgInsert)entity).getScale(); |
|
615 |
double rot = ((DwgInsert)entity).getRotation(); |
|
616 |
int blockHandle = ((DwgInsert)entity).getBlockHeaderHandle().getOffset(); |
|
617 |
manageInsert(point, scale, rot, blockHandle, dwgObjectsWithoutBlocks); |
|
618 |
} else { |
|
619 |
// System.out.println(entity.getClass().getName() +" en un bloque"); |
|
620 |
//Se ha encontrado una entidad rara, o forma parte de un bloque |
|
621 |
//y ser? procesada despu?s (con los punteros del propio bloque) |
|
622 |
|
|
623 |
//TODO No se podr?a hacer mas rapido, quitando de la lista original |
|
624 |
//las entidades que forman parte de bloque?? |
|
625 |
} |
|
538 |
//once we have read all dwg entities, we look for all of them |
|
539 |
//that has a superentity that is a block (to fill in the entity list |
|
540 |
//of each block |
|
541 |
Iterator it = dwgObjects.iterator(); |
|
542 |
int i = 0; |
|
543 |
while(it.hasNext()){ |
|
544 |
DwgObject entity = (DwgObject)it.next(); |
|
545 |
DwgObject superEnt = entity.getSuperEntity(); |
|
546 |
if(superEnt instanceof DwgBlockHeader){ |
|
547 |
DwgBlockHeader blk = (DwgBlockHeader)superEnt; |
|
548 |
// System.out.println("Entidad "+ |
|
549 |
// i+ |
|
550 |
// " pertenece al bloque "+ |
|
551 |
// blk.getName()); |
|
552 |
blk.addObject(entity); |
|
553 |
it.remove();//TODO Creo que esto es lento, mejor |
|
554 |
//el metodo original (en java solo se duplican las referencias) |
|
555 |
i++; |
|
626 | 556 |
} |
627 |
}catch(RuntimeException re){ |
|
628 |
re.printStackTrace(); |
|
629 |
} |
|
630 |
dwgObjects = dwgObjectsWithoutBlocks; |
|
557 |
}//while |
|
558 |
|
|
559 |
//after that, we process the INSERTs |
|
560 |
it = insertList.iterator(); |
|
561 |
while(it.hasNext()){ |
|
562 |
DwgInsert insert = (DwgInsert) it.next(); |
|
563 |
if(insert.isProcessed()){ |
|
564 |
//It has been processed nexted to other insert |
|
565 |
continue; |
|
566 |
} |
|
567 |
insert.setProcessed(true); |
|
568 |
double[] p = insert.getInsertionPoint(); |
|
569 |
Point2D point = new Point2D.Double(p[0], p[1]); |
|
570 |
double[] scale = insert.getScale(); |
|
571 |
double rot = insert.getRotation(); |
|
572 |
int blockHandle = insert.getBlockHeaderHandle().getOffset(); |
|
573 |
manageInsert2(point, scale, |
|
574 |
rot, blockHandle, |
|
575 |
dwgObjects, handle_objects); |
|
576 |
} |
|
631 | 577 |
} |
632 |
*/ |
|
578 |
|
|
633 | 579 |
/** |
634 | 580 |
* Modify the geometry of the objects contained in the blocks of a DWG file and |
635 | 581 |
* add these objects to the DWG object list. |
... | ... | |
714 | 660 |
this.handle_objects = (HashMap) handle_objectsWithoutBlocks; |
715 | 661 |
} |
716 | 662 |
|
663 |
public void manageInsert2(Point2D insPoint, double[] scale, |
|
664 |
double rot, int bHandle, |
|
665 |
List dwgObjectsWithoutBlocks, |
|
666 |
Map handleObjectsWithoutBlocks) { |
|
667 |
|
|
668 |
DwgObject object = (DwgObject) handle_objects.get(new Integer(bHandle)); |
|
669 |
if(object == null){ |
|
670 |
System.out.println("No hemos encontrado el BlockHeader cuyo handle es "+bHandle); |
|
671 |
return; |
|
672 |
}else if(! (object instanceof DwgBlockHeader)){ |
|
673 |
//Hay un problema con la asignaci?n de handle |
|
674 |
//Un INSERT tiene como handle de Block una entidad que no es block |
|
675 |
// System.out.println("handle incorrecto." + object.getClass().getName() + " no es un blockheader"); |
|
676 |
return; |
|
677 |
} |
|
678 |
|
|
679 |
DwgBlockHeader blockHeader = (DwgBlockHeader)object; |
|
680 |
double[] bPoint = blockHeader.getBasePoint(); |
|
681 |
String bname = blockHeader.getName(); |
|
682 |
if (bname.startsWith("*")) |
|
683 |
return; |
|
684 |
|
|
685 |
//TODO Cambiar por List |
|
686 |
Iterator blkEntIt = blockHeader.getObjects().iterator(); |
|
687 |
while(blkEntIt.hasNext()){ |
|
688 |
DwgObject obj = (DwgObject) blkEntIt.next(); |
|
689 |
manageBlockEntity(obj, bPoint, |
|
690 |
insPoint, scale, |
|
691 |
rot, dwgObjectsWithoutBlocks, |
|
692 |
handleObjectsWithoutBlocks); |
|
693 |
}//while |
|
694 |
} |
|
695 |
|
|
717 | 696 |
/** |
718 | 697 |
* Manages an INSERT of a DWG file. This object is the insertion point of a DWG |
719 | 698 |
* block. |
... | ... | |
742 | 721 |
// System.out.println("handle incorrecto." + object.getClass().getName() + " no es un blockheader"); |
743 | 722 |
return; |
744 | 723 |
} |
724 |
|
|
745 | 725 |
DwgBlockHeader blockHeader = (DwgBlockHeader)object; |
746 | 726 |
double[] bPoint = blockHeader.getBasePoint(); |
747 | 727 |
String bname = blockHeader.getName(); |
... | ... | |
875 | 855 |
} |
876 | 856 |
|
877 | 857 |
|
878 |
/* |
|
879 |
* azabala: Esto ahora se hace mientras las entidades dwg |
|
880 |
* se van creando, y no en una segunda pasada |
|
881 |
* */ |
|
882 |
/* |
|
883 |
public void testDwg3D() { |
|
884 |
for (int i=0;i<dwgObjects.size();i++) { |
|
885 |
DwgObject obj = (DwgObject)dwgObjects.get(i); |
|
886 |
|
|
887 |
if(obj instanceof IDwg3DTestable){ |
|
888 |
if(((IDwg3DTestable)obj).has3DData()) |
|
889 |
dwg3DFile = true; |
|
890 |
return; |
|
891 |
} |
|
892 |
|
|
893 |
//} else if (obj instanceof DwgLinearDimension) { |
|
894 |
// z = ((DwgLinearDimension)obj).getElevation(); |
|
895 |
// if (z!=0.0) dwg3DFile = true; |
|
896 |
}//for |
|
897 |
dwg3DFile = false; |
|
898 |
} |
|
899 |
*/ |
|
900 |
|
|
901 | 858 |
/** |
902 | 859 |
* Add a DWG section offset to the dwgSectionOffsets vector |
903 | 860 |
* |
... | ... | |
951 | 908 |
//(IDwgPolyline, etc) aqu? |
952 | 909 |
dwgObjects.add(dwgObject); |
953 | 910 |
handle_objects.put(new Integer(dwgObject.getHandle().getOffset()), dwgObject); |
911 |
|
|
912 |
if(dwgObject.getHandle().getOffset() == 144349){ |
|
913 |
System.currentTimeMillis(); |
|
914 |
} |
|
915 |
|
|
916 |
|
|
917 |
|
|
954 | 918 |
/* |
955 | 919 |
* TODO Quitar todos estos if-then y sustituirlos por un metodo callbackj |
956 | 920 |
* |
... | ... | |
971 | 935 |
dwg3DFile = ((IDwg3DTestable)dwgObject).has3DData(); |
972 | 936 |
} |
973 | 937 |
} |
974 |
//checks if it is a subentity of a block |
|
975 |
DwgObject superEntity = dwgObject.getSuperEntity(); |
|
976 |
if(superEntity instanceof DwgBlock || superEntity instanceof DwgBlockHeader){ |
|
977 |
System.out.println(dwgObject.getClass().getName()+" pertenece a "+superEntity.getClass().getName()); |
|
938 |
if(dwgObject instanceof DwgInsert){ |
|
939 |
insertList.add(dwgObject); |
|
978 | 940 |
} |
979 | 941 |
} |
980 | 942 |
|
Also available in: Unified diff