Revision 4791 trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/layers/FLyrPoints.java

View differences:

FLyrPoints.java
19 19
package com.iver.cit.gvsig.fmap.layers;
20 20

  
21 21
import java.awt.Color;
22
import java.awt.Dimension;
22 23
import java.awt.Graphics2D;
23 24
import java.awt.geom.Point2D;
24 25
import java.awt.geom.Rectangle2D;
......
26 27
import java.util.ArrayList;
27 28
import java.util.Iterator;
28 29

  
30
import org.cresques.cts.ProjectionPool;
31

  
29 32
import com.iver.andami.PluginServices;
30 33
import com.iver.cit.gvsig.fmap.DriverException;
31 34
import com.iver.cit.gvsig.fmap.ViewPort;
......
34 37
import com.iver.cit.gvsig.gui.dialogs.GeoreferencingDialog;
35 38
import com.iver.cit.gvsig.utils.GeoPointPersistence;
36 39
import com.iver.cit.gvsig.utils.PointManager;
40
import com.iver.utiles.XMLEntity;
37 41

  
38 42

  
39 43
/**
......
94 98
		this.lyrGeoRaster = lyGeoRaster;
95 99
		geoPointPersistence = new GeoPointPersistence(this);
96 100
	}
101
	
102
	/**
103
	 * Crea una capa FLyrPoints a partir de los par?metros de entrada.
104
	 * @param lyGeoRaster	Capa a georreferenciar
105
	 * @param pixel			Coordenadas relativas a la imagen a georreferenciar en pixels
106
	 * @param map			Coordenadas de destino
107
	 * @param active		True o false si el punto est? activo o no
108
	 * @param leftCenter	Punto central del viewport de la miniimagen de coordenadas reales
109
	 * @param rightCenter	Punto central del viewport de la miniimagen de coordenadas en pixels
110
	 * @param leftViewPort	ViewPort de la miniimagen de coordenadas reales
111
	 * @param rightViewPort	ViewPort de la miniimagen de coordenadas en pixels
112
	 * @return Capa de puntos creada.
113
	 */
114
	public static FLyrPoints createFLyrPoints(	FLyrGeoRaster lyGeoRaster, 
115
												Point2D[] pixel, 
116
												Point2D[] map, 
117
												boolean[] active,
118
												Point2D[] leftCenter, 
119
												Point2D[] rightCenter,
120
												ViewPort[] leftViewPort,
121
												ViewPort[] rightViewPort){
122
		FLyrPoints lyrPoints = new FLyrPoints(lyGeoRaster);
123
	
124
		lyrPoints.getPointManager().newEmptyPoint();
125
		View theView = null;
126
		try{
127
			theView = (View)PluginServices.getMDIManager().getActiveView();
128
		}catch(ClassCastException exc){
129
			return null;
130
		}
131
		int pos = lyrPoints.getCountPoints() -1;
132
		for(int i = 0;i < pixel.length;i++){
133
			lyrPoints.setPointActive(pos, active[i]);
134
			lyrPoints.setLeftCenterPoint(pos,leftCenter[i]);
135
			lyrPoints.setRightCenterPoint(pos, rightCenter[i]);
136
			lyrPoints.setLeftViewPort(pos, leftViewPort[i]);
137
			lyrPoints.setRightViewPort(pos, rightViewPort[i]);
138
			lyrPoints.getPointManager().updateData(pos + 1, pixel[i], map[i], lyrPoints.getPointManager().getDialog(), theView);
139
		}
97 140
		
141
		if(lyrPoints.getCountPoints() > 0){
142
			GeoreferencingDialog grd = lyrPoints.getPointManager().getDialog();
143
			grd.getConectorPanel().getDataPointsTabPanel().
144
				getSelectPointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
145
			grd.getConectorPanel().getDataPointsTabPanel().
146
				getTablePointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
147
			lyrPoints.getPointManager().selectPoint(0, grd);
148
		}
149
		return lyrPoints;
150
	}
151

  
98 152
	/**
99 153
	 * Salva el estado actual de la capa de puntos. Podr? ser recuperado
100 154
	 * este ?ltimo estado salvado con la funci?n recoveryState
......
428 482
	public void PointList2Ascii(String file){;
429 483
		geoPointPersistence.saveAsciiPointList(file);
430 484
	}
485
	
486
	/* (non-Javadoc)
487
	 * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
488
	 */
489
	public void setXMLEntity(XMLEntity xml)throws XMLException {
490
		int nPoints = -1;
491
		if (xml.contains("raster.geoPoints.nPoints")) {
492
			nPoints = xml.getIntProperty("raster.geoPoints.nPoints");
493
			if(nPoints > 0){
494
				Point2D[] pixel = new Point2D[nPoints];
495
				Point2D[] map = new Point2D[nPoints];
496
				boolean[] active = new boolean[nPoints];
497
				Point2D[] leftCenter = new Point2D[nPoints];
498
				Point2D[] rightCenter = new Point2D[nPoints];
499
				ViewPort[] leftViewPort = new ViewPort[nPoints];
500
				ViewPort[] rightViewPort = new ViewPort[nPoints];
501
				for(int i = 0;i<nPoints;i++){
502
					pixel[i] = new Point2D.Double();
503
					map[i] = new Point2D.Double();
504
					leftCenter[i] = new Point2D.Double();
505
					rightCenter[i] = new Point2D.Double();
506
					ViewPort vp = new ViewPort(null);
507
					if (xml.contains("raster.geoPoint."+i+".pixelX") && xml.contains("raster.geoPoint."+i+".pixelY"))
508
						pixel[i].setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".pixelX"), xml.getDoubleProperty("raster.geoPoint."+i+".pixelY"));
509
					
510
					if (xml.contains("raster.geoPoint."+i+".mapX") && xml.contains("raster.geoPoint."+i+".mapY"))
511
						map[i].setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".mapX"), xml.getDoubleProperty("raster.geoPoint."+i+".mapY"));
512
					
513
					if (xml.contains("raster.geoPoint."+i+".active"))
514
						active[i] = xml.getBooleanProperty("raster.geoPoint."+i+".active");
515
					
516
					if (xml.contains("raster.geoPoint."+i+".leftCenterX") && xml.contains("raster.geoPoint."+i+".leftCenterY"))
517
						leftCenter[i].setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".leftCenterX"), xml.getDoubleProperty("raster.geoPoint."+i+".leftCenterY"));
518
					
519
					if (xml.contains("raster.geoPoint."+i+".rightCenterX") && xml.contains("raster.geoPoint."+i+".rightCenterY"))
520
						rightCenter[i].setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".rightCenterX"), xml.getDoubleProperty("raster.geoPoint."+i+".rightCenterY"));
521
					
522
					double x = 0D, y = 0D, w = 0D, h = 0D;
523
					int width = 0, height = 0;
524
					Rectangle2D r = new Rectangle2D.Double();
525
					if (xml.contains("raster.geoPoint."+i+".leftViewPort.proj"))
526
						vp.setProjection(ProjectionPool.get(xml.getStringProperty("raster.geoPoint."+i+".leftViewPort.proj")));
527
					if (xml.contains("raster.geoPoint."+i+".leftViewPort.x"))
528
						x = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.x");
529
					if (xml.contains("raster.geoPoint."+i+".leftViewPort.y"))
530
						y = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.y");
531
					if (xml.contains("raster.geoPoint."+i+".leftViewPort.w"))
532
						w = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.w");
533
					if (xml.contains("raster.geoPoint."+i+".leftViewPort.h"))
534
						h = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.h");
535
					r.setRect(x, y, w, h);
536
					leftViewPort[i].setExtent(r);
537
					if (xml.contains("raster.geoPoint."+i+".leftViewPort.imgWidth"))
538
						width = xml.getIntProperty("raster.geoPoint."+i+".leftViewPort.imgWidth");
539
					if (xml.contains("raster.geoPoint."+i+".leftViewPort.imgHeight"))
540
						height = xml.getIntProperty("raster.geoPoint."+i+".leftViewPort.imgHeight");
541
					leftViewPort[i].setImageSize(new Dimension(width, height));
542
					
543
					r = new Rectangle2D.Double();
544
					if (xml.contains("raster.geoPoint."+i+".rightViewPort.proj"))
545
						vp.setProjection(ProjectionPool.get(xml.getStringProperty("raster.geoPoint."+i+".rightViewPort.proj")));
546
					if (xml.contains("raster.geoPoint."+i+".rightViewPort.x"))
547
						x = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.x");
548
					if (xml.contains("raster.geoPoint."+i+".rightViewPort.y"))
549
						y = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.y");
550
					if (xml.contains("raster.geoPoint."+i+".rightViewPort.w"))
551
						w = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.w");
552
					if (xml.contains("raster.geoPoint."+i+".rightViewPort.h"))
553
						h = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.h");
554
					r.setRect(x, y, w, h);
555
					rightViewPort[i].setExtent(r);
556
					if (xml.contains("raster.geoPoint."+i+".rightViewPort.imgWidth"))
557
						width = xml.getIntProperty("raster.geoPoint."+i+".rightViewPort.imgWidth");
558
					if (xml.contains("raster.geoPoint."+i+".rightViewPort.imgHeight"))
559
						height = xml.getIntProperty("raster.geoPoint."+i+".rightViewPort.imgHeight");
560
					rightViewPort[i].setImageSize(new Dimension(width, height));
561
					
562
				}
563
			}
564
		}
565
	}
566
	
567
	/* (non-Javadoc)
568
	 * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
569
	 */
570
	public void getXMLEntity(XMLEntity xml) throws XMLException {
571
		xml.putProperty("raster.geoPoints.nPoints", getCountPoints());
572
		for(int i=0;i<this.getCountPoints();i++){
573
			xml.putProperty("raster.geoPoint."+i+".pixelX", getPoint(i).pixelPoint.getX());	
574
			xml.putProperty("raster.geoPoint."+i+".pixelY", getPoint(i).pixelPoint.getY());
575
			xml.putProperty("raster.geoPoint."+i+".mapX", getPoint(i).mapPoint.getX());
576
			xml.putProperty("raster.geoPoint."+i+".mapY", getPoint(i).mapPoint.getX());
577
			
578
			xml.putProperty("raster.geoPoint."+i+".active", getPoint(i).active);
579
			
580
			xml.putProperty("raster.geoPoint."+i+".leftCenterX", getPoint(i).leftCenterPoint.getX());
581
			xml.putProperty("raster.geoPoint."+i+".leftCenterY", getPoint(i).leftCenterPoint.getY());
582
			xml.putProperty("raster.geoPoint."+i+".rightCenterX", getPoint(i).rightCenterPoint.getX());
583
			xml.putProperty("raster.geoPoint."+i+".rightCenterY", getPoint(i).rightCenterPoint.getY());
584
			
585
			xml.putProperty("raster.geoPoint."+i+".leftViewPort.proj", getPoint(i).leftViewPort.getProjection().getAbrev());
586
			xml.putProperty("raster.geoPoint."+i+".leftViewPort.x", getPoint(i).leftViewPort.getExtent().getX());
587
			xml.putProperty("raster.geoPoint."+i+".leftViewPort.y", getPoint(i).leftViewPort.getExtent().getY());
588
			xml.putProperty("raster.geoPoint."+i+".leftViewPort.w", getPoint(i).leftViewPort.getExtent().getWidth());
589
			xml.putProperty("raster.geoPoint."+i+".leftViewPort.h", getPoint(i).leftViewPort.getExtent().getHeight());
590
			xml.putProperty("raster.geoPoint."+i+".leftViewPort.imgWidth", getPoint(i).leftViewPort.getImageWidth());
591
			xml.putProperty("raster.geoPoint."+i+".leftViewPort.imgHeight", getPoint(i).leftViewPort.getImageHeight());
592
			
593
			xml.putProperty("raster.geoPoint."+i+".rightViewPort.proj", getPoint(i).rightViewPort.getProjection().getAbrev());
594
			xml.putProperty("raster.geoPoint."+i+".rightViewPort.x", getPoint(i).rightViewPort.getExtent().getX());
595
			xml.putProperty("raster.geoPoint."+i+".rightViewPort.y", getPoint(i).rightViewPort.getExtent().getY());
596
			xml.putProperty("raster.geoPoint."+i+".rightViewPort.w", getPoint(i).rightViewPort.getExtent().getWidth());
597
			xml.putProperty("raster.geoPoint."+i+".rightViewPort.h", getPoint(i).rightViewPort.getExtent().getHeight());
598
			xml.putProperty("raster.geoPoint."+i+".rightViewPort.imgWidth", getPoint(i).rightViewPort.getImageWidth());
599
			xml.putProperty("raster.geoPoint."+i+".rightViewPort.imgHeight", getPoint(i).rightViewPort.getImageHeight());
600
		}
601
	}
431 602
	//**********************End Methods********************************
432 603
	
433 604
	//**********************Setters & Getters**************************

Also available in: Unified diff