Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dxf/DXFMemoryDriver.java

View differences:

DXFMemoryDriver.java
72 72
import org.cresques.px.gml.Polygon3D;
73 73

  
74 74
import com.hardcode.gdbms.driver.DriverUtilities;
75
import com.hardcode.gdbms.engine.data.driver.DriverException;
75
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
76
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException;
77
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
78
import com.hardcode.gdbms.driver.exceptions.ReloadDriverException;
76 79
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
77 80
import com.hardcode.gdbms.engine.data.edition.DataWare;
78 81
import com.hardcode.gdbms.engine.values.IntValue;
79 82
import com.hardcode.gdbms.engine.values.Value;
80 83
import com.hardcode.gdbms.engine.values.ValueFactory;
84
import com.iver.cit.gvsig.exceptions.visitors.ProcessWriterVisitorException;
85
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException;
86
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException;
81 87
import com.iver.cit.gvsig.fmap.core.FPoint2D;
82 88
import com.iver.cit.gvsig.fmap.core.FPoint3D;
83 89
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
......
95 101
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
96 102
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
97 103
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
98
import com.iver.cit.gvsig.fmap.edition.EditionException;
99 104
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
100 105
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter;
101 106
import com.iver.cit.gvsig.fmap.edition.IWriteable;
......
113 118
 */
114 119
public class DXFMemoryDriver extends AbstractCadMemoryDriver implements
115 120
		VectorialFileDriver, WithDefaultLegend, ISpatialWriter, IWriteable {
116
	
121

  
117 122
	private static String tempDirectoryPath = System
118 123
			.getProperty("java.io.tmpdir");
119 124

  
......
146 151
	 *
147 152
	 * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
148 153
	 */
149
	public void open(File f) throws IOException {
154
	public void open(File f) {
150 155
		m_Fich = f;
151 156
	}
152 157

  
153
	public void initialize() throws IOException {
158
	public void initialize() throws InitializeDriverException {
154 159
		float heightText = 10;
155 160

  
156 161
		attr.setLoadedInMemory(true);
......
252 257
					&& !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) {
253 258
				Point point = (Point) fea.getGeometry();
254 259
				Point2D pto = new Point2D.Double();
255
				pto = (Point2D) point.get(0);
260
				pto = point.get(0);
256 261
				FShape nuevoShp;
257 262
				if (point.isTextPoint()) {
258 263
					auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
......
283 288
						attributes = (String[]) featureMaker.getAttributes()
284 289
								.get(j);
285 290
						auxRow[10 + j] = ValueFactory.createValue(new String(
286
								(String) attributes[1]));
291
								attributes[1]));
287 292
						if (!fea.getProp(attributes[0]).equals(attributes[1])) {
288 293
							auxRow[10 + j] = ValueFactory
289 294
									.createValue(new String(fea
......
312 317
						attributes = (String[]) featureMaker.getAttributes()
313 318
								.get(j);
314 319
						auxRow[10 + j] = ValueFactory.createValue(new String(
315
								(String) attributes[1]));
320
								attributes[1]));
316 321
						if (!fea.getProp(attributes[0]).equals(attributes[1])) {
317 322
							auxRow[10 + j] = ValueFactory
318 323
									.createValue(new String(fea
......
326 331
				org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D) fea
327 332
						.getGeometry();
328 333
				Point3D pto = new Point3D();
329
				pto = (Point3D) point.getPoint3D(0);
334
				pto = point.getPoint3D(0);
330 335
				FShape nuevoShp;
331 336
				if (point.isTextPoint()) {
332 337
					auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
......
357 362
						attributes = (String[]) featureMaker.getAttributes()
358 363
								.get(j);
359 364
						auxRow[10 + j] = ValueFactory.createValue(new String(
360
								(String) attributes[1]));
365
								attributes[1]));
361 366
						if (!fea.getProp(attributes[0]).equals(attributes[1])) {
362 367
							auxRow[10 + j] = ValueFactory
363 368
									.createValue(new String(fea
......
386 391
						attributes = (String[]) featureMaker.getAttributes()
387 392
								.get(j);
388 393
						auxRow[10 + j] = ValueFactory.createValue(new String(
389
								(String) attributes[1]));
394
								attributes[1]));
390 395
						if (!fea.getProp(attributes[0]).equals(attributes[1])) {
391 396
							auxRow[10 + j] = ValueFactory
392 397
									.createValue(new String(fea
......
447 452
				GeneralPathX genPathX = new GeneralPathX();
448 453
				Point2D[] pts = new Point2D[fea.getGeometry().pointNr()];
449 454
				for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
450
					pts[j] = (Point2D) fea.getGeometry().get(j);
455
					pts[j] = fea.getGeometry().get(j);
451 456
				}
452 457
				genPathX.moveTo(pts[0].getX(), pts[0].getY());
453 458
				for (int j = 1; j < pts.length; j++) {
......
475 480
					String[] attributes = new String[2];
476 481
					attributes = (String[]) featureMaker.getAttributes().get(j);
477 482
					auxRow[10 + j] = ValueFactory.createValue(new String(
478
							(String) attributes[1]));
483
							 attributes[1]));
479 484
					if (!fea.getProp(attributes[0]).equals(attributes[1])) {
480 485
						auxRow[10 + j] = ValueFactory.createValue(new String(
481 486
								fea.getProp(attributes[0])));
......
517 522
					String[] attributes = new String[2];
518 523
					attributes = (String[]) featureMaker.getAttributes().get(j);
519 524
					auxRow[10 + j] = ValueFactory.createValue(new String(
520
							(String) attributes[1]));
525
							attributes[1]));
521 526
					if (!fea.getProp(attributes[0]).equals(attributes[1])) {
522 527
						auxRow[10 + j] = ValueFactory.createValue(new String(
523 528
								fea.getProp(attributes[0])));
......
531 536
				// 050112: A?ado una posici?n m?s para el punto que cierra y
532 537
				// creo el objeto firstPt.
533 538
				Point2D firstPt = new Point2D.Double();
534
				firstPt = (Point2D) fea.getGeometry().get(0);
539
				firstPt = fea.getGeometry().get(0);
535 540
				Point2D[] pts = new Point2D[fea.getGeometry().pointNr() + 1];
536 541
				for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
537
					pts[j] = (Point2D) fea.getGeometry().get(j);
542
					pts[j] = fea.getGeometry().get(j);
538 543
				}
539 544
				// 050112: A?ado el primer punto al final para cerrar los
540 545
				// pol?gonos.
......
565 570
					String[] attributes = new String[2];
566 571
					attributes = (String[]) featureMaker.getAttributes().get(j);
567 572
					auxRow[10 + j] = ValueFactory.createValue(new String(
568
							(String) attributes[1]));
573
							attributes[1]));
569 574
					if (!fea.getProp(attributes[0]).equals(attributes[1])) {
570 575
						auxRow[10 + j] = ValueFactory.createValue(new String(
571 576
								fea.getProp(attributes[0])));
......
578 583
				// 050112: A?ado una posici?n m?s para el punto que cierra y
579 584
				// creo el objeto firstPt.
580 585
				Point3D firstPt = new Point3D();
581
				firstPt = (Point3D) ((Polygon3D) fea.getGeometry())
586
				firstPt = ((Polygon3D) fea.getGeometry())
582 587
						.getPoint3D(0);
583 588
				Point3D[] pts = new Point3D[fea.getGeometry().pointNr() + 1];
584 589
				for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
585
					pts[j] = (Point3D) ((Polygon3D) fea.getGeometry())
590
					pts[j] = ((Polygon3D) fea.getGeometry())
586 591
							.getPoint3D(j);
587 592
				}
588 593
				// 050112: A?ado el primer punto al final para cerrar los
......
616 621
					String[] attributes = new String[2];
617 622
					attributes = (String[]) featureMaker.getAttributes().get(j);
618 623
					auxRow[10 + j] = ValueFactory.createValue(new String(
619
							(String) attributes[1]));
624
							attributes[1]));
620 625
					if (!fea.getProp(attributes[0]).equals(attributes[1])) {
621 626
						auxRow[10 + j] = ValueFactory.createValue(new String(
622 627
								fea.getProp(attributes[0])));
......
633 638
				.createVectorialUniqueValueLegend(getShapeType());
634 639
		defaultLegend.setFieldName("Color");
635 640
		defaultLegend.setLabelField("Text");
636
		
637
		FSymbol myDefaultSymbol = new FSymbol(getShapeType());		
641

  
642
		FSymbol myDefaultSymbol = new FSymbol(getShapeType());
638 643
		myDefaultSymbol.setShapeVisible(false);
639 644
		myDefaultSymbol.setFontSizeInPixels(false);
640 645
		myDefaultSymbol.setFont(new Font("SansSerif",Font.PLAIN, 9));
......
643 648
		myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
644 649
		myDefaultSymbol.setSize(3);
645 650
		myDefaultSymbol.setSizeInPixels(true);
646
		
651

  
647 652
		defaultLegend.setDefaultSymbol(myDefaultSymbol);
648 653

  
649 654
		defaultLegend.setLabelHeightField("HeightText");
......
684 689
					defaultLegend.addSymbol(clave, theSymbol);
685 690
				}
686 691
			} // for
687
		} catch (DriverException e) {
688
			e.printStackTrace();
689
			throw new IOException(
690
					"Error al poner la leyenda por defecto en el DXF");
692
		} catch (ReadDriverException e) {
693
			throw new InitializeDriverException(getName(),e);
691 694
		}
692 695
	}
693 696

  
......
739 742
	/**
740 743
	 * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
741 744
	 */
742
	public int[] getPrimaryKeys() throws DriverException {
745
	public int[] getPrimaryKeys() {
743 746
		return null;
744 747
	}
745 748

  
746 749
	/**
747 750
	 * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
748 751
	 */
749
	public void write(DataWare arg0) throws DriverException {
752
	public void write(DataWare arg0) {
750 753
		// TODO Auto-generated method stub
751 754

  
752 755
	}
......
756 759
	 *
757 760
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
758 761
	 */
759
	public void close() throws IOException {
762
	public void close() {
760 763
		// TODO Auto-generated method stub
761 764

  
762 765
	}
......
769 772
		return dxfWriter.canWriteGeometry(gvSIGgeometryType);
770 773
	}
771 774

  
772
	public void initialize(ITableDefinition layerDef) throws EditionException {
775
	public void initialize(ITableDefinition layerDef) throws InitializeWriterException {
773 776
		int aux = (int) (Math.random() * 1000);
774 777
		fTemp = new File(tempDirectoryPath + "/tmpDxf" + aux + ".dxf");
775 778
		dxfWriter.setFile(fTemp);
......
795 798
		dxfWriter.setProjection(((ILayerDefinition)layerDef).getProjection());
796 799
	}
797 800

  
798
	public void preProcess() throws EditionException {
801
	public void preProcess() throws StartWriterVisitorException {
799 802
		dxfWriter.preProcess();
800 803
	}
801 804

  
802
	public void process(IRowEdited row) throws EditionException {
805
	public void process(IRowEdited row) throws ProcessWriterVisitorException {
803 806
		dxfWriter.process(row);
804 807
	}
805 808

  
806
	public void postProcess() throws EditionException {
809
	public void postProcess() throws StopWriterVisitorException {
807 810
		dxfWriter.postProcess();
808 811
		try {
809 812

  
......
819 822
			reload();
820 823

  
821 824
		} catch (FileNotFoundException e) {
822
			e.printStackTrace();
823
			throw new EditionException(e);
825
			throw new StopWriterVisitorException(getName(),e);
824 826
		} catch (IOException e) {
825
			e.printStackTrace();
826
			throw new EditionException(e);
827
		} catch (DriverException e) {
828
			e.printStackTrace();
829
			throw new EditionException(e);
827
			throw new StopWriterVisitorException(getName(),e);
828
		} catch (ReloadDriverException e) {
829
			throw new StopWriterVisitorException(getName(),e);
830 830
		}
831 831

  
832 832
	}
......
849 849
	 *
850 850
	 * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#reLoad()
851 851
	 */
852
	public void reload() throws IOException, DriverException {
852
	public void reload() throws ReloadDriverException {
853 853
		super.reload();
854 854
		try {
855 855
			initialize();
856
		} catch (IOException e) {
857
			e.printStackTrace();
858
			throw new IOException("DXF: Error reloading " + path + " file.");
856
		} catch (InitializeDriverException e) {
857
			throw new ReloadDriverException(getName(),e);
859 858
		}
860 859
	}
861 860

  

Also available in: Unified diff