Revision 23163

View differences:

trunk/extensions/extTopology/config/config.xml
134 134
			</tool-bar>
135 135
		 </extension>
136 136
		 
137
		 <extension class-name="com.iver.cit.gvsig.cad.GenerateAdjacentPolygonCADToolExtension"
138
				   description="Herramienta para digitalizar capas continuas de poligonos"
139
				   active="true">		
140
		 			<tool-bar name="Topology">
141
					<action-tool icon="adjacent-polygon"
142
							 action-command="_adjacent_polygon"
143
							 tooltip="adjacent-polygon"
144
							 enable-text="put_a_polygon_layer_in_edition" 
145
							 last="true" 
146
							 position="11"/>
147
			</tool-bar>
148
		</extension>
149
		 
137 150
		 <extension class-name="com.iver.cit.gvsig.cad.SimplifyGeometry"
138 151
			description="herramienta para simplificar geometrias de 1 y 2 dimensiones"
139 152
			active="true">
......
193 206
							 position="11"/>
194 207
			</tool-bar>
195 208
		</extension>
209
		
210
		
211
		
196 212
	</extensions>
197 213
</plugin-config>
trunk/extensions/extTopology/src/com/iver/cit/gvsig/referencing/MappedPositionPanel.java
293 293
								};
294 294
								
295 295
								mapCtrl.addMapTool(sTool, new Behavior[] {
296
										new VectorBehavior(vl),
296
										new VectorBehavior(vl, null),
297 297
										new MouseMovementBehavior(sbl) });
298 298
								mapCtrl.setTool(sTool);
299 299

  
trunk/extensions/extTopology/src/com/iver/cit/gvsig/referencing/MappedPositionContainerImpl.java
56 56
import org.cresques.cts.IProjection;
57 57
import org.geotools.referencefork.referencing.operation.builder.MappedPosition;
58 58
import org.gvsig.referencing.MappedPositionContainer;
59
import org.gvsig.referencing.ReferencingUtil;
59 60

  
60 61
import com.iver.andami.PluginServices;
61 62
import com.iver.cit.gvsig.drivers.VectorErrorMemoryDriver;
......
74 75
 */
75 76
public class MappedPositionContainerImpl implements MappedPositionContainer {
76 77

  
77
	/**
78
	 * Number of created dialogs counter.
79
	 */
80
	private static  int numberOfCreatedLyrs = 0;
81 78
	
82 79
	
83
	
84 80
	/**
85 81
	 * Digitized vector errors
86 82
	 */
......
120 116
	//HAY QUE A?ADIR ALGUNA EXTENSION AL TOC??
121 117
	public FLyrVect getLinkLyr(IProjection projection){
122 118
		if(linksLyr == null){
119
			ReferencingUtil ref = ReferencingUtil.getInstance();
120
			int numberOfSessions = ref.getNumberOfSpatialAdjustSessions();
123 121
			linksLyr = new FLayerGenericVectorial();
124 122
			String name = PluginServices.getText(this, "LINKS_SPATIAL_ADJUST") +
125 123
										"_" +
126
								MappedPositionContainerImpl.numberOfCreatedLyrs++;
124
								numberOfSessions;
125
			ref.incrementAdjustSessions();
127 126
			linksLyr.setName(name);
128 127
			linksLyr.setProjection(projection);
129 128
			((FLayerGenericVectorial)linksLyr).setDriver(new VectorErrorMemoryDriver(name, this));
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/referencing/IReferencingGeoprocessUserEntries.java
50 50

  
51 51
import org.opengis.referencing.operation.MathTransform;
52 52

  
53
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
53 54
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
54 55
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessUserEntries;
55 56

  
......
61 62

  
62 63
	public boolean onlyFirstLayerSelected();
63 64
	public MathTransform getMathTransform() throws GeoprocessException;
65
	public boolean hasAuxiliarLyrs();
66
	public FLyrVect[] getAuxiliarLyrs();
64 67
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/referencing/fmap/ReferencingGeoprocess.java
42 42
 *   dac@iver.es
43 43
 */
44 44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
45
 *
46
 * $Id: 
47
 * $Log: 
48
 */
49 49
package com.iver.cit.gvsig.geoprocess.impl.referencing.fmap;
50 50

  
51 51
import java.rmi.server.UID;
52 52
import java.util.Map;
53 53

  
54 54
import org.apache.log4j.Logger;
55
import org.geotools.referencefork.referencing.operation.transform.AbstractMathTransform;
56 55
import org.gvsig.exceptions.BaseException;
57 56
import org.gvsig.referencing.ReferencingUtil;
58 57
import org.gvsig.topology.Messages;
......
62 61

  
63 62
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
64 63
import com.hardcode.gdbms.engine.values.Value;
64
import com.iver.andami.PluginServices;
65 65
import com.iver.cit.gvsig.drivers.featureiterators.FeatureBitsetIterator;
66 66
import com.iver.cit.gvsig.exceptions.visitors.StartVisitorException;
67 67
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException;
68 68
import com.iver.cit.gvsig.exceptions.visitors.StopVisitorException;
69
import com.iver.cit.gvsig.fmap.MapContext;
69 70
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
70 71
import com.iver.cit.gvsig.fmap.core.IFeature;
71 72
import com.iver.cit.gvsig.fmap.core.IGeometry;
......
73 74
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
74 75
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
75 76
import com.iver.cit.gvsig.fmap.layers.FBitSet;
77
import com.iver.cit.gvsig.fmap.layers.FLayer;
78
import com.iver.cit.gvsig.fmap.layers.FLayers;
76 79
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
77 80
import com.iver.cit.gvsig.geoprocess.core.AbstractMonitorableGeoprocess;
78 81
import com.iver.cit.gvsig.geoprocess.core.fmap.DefinitionUtils;
79 82
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2;
80 83
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
84
import com.iver.cit.gvsig.project.documents.view.gui.View;
81 85
import com.iver.utiles.swing.threads.CancellableProgressTask;
82 86

  
83 87
/**
84 88
 * Geoprocess to spatial adjust or reference a vectorial layer
89
 * 
85 90
 * @author Alvaro Zabala
86
 *
91
 * 
87 92
 */
88 93
public class ReferencingGeoprocess extends AbstractMonitorableGeoprocess {
89 94
	private static Logger logger = Logger.getLogger(ReferencingGeoprocess.class
90 95
			.getName());
91
	
96

  
92 97
	private LayerDefinition resultLayerDefinition;
93
	
94
	private /*Abstract*/MathTransform mathTransform;
95
	
96
	
97
	public ReferencingGeoprocess(FLyrVect inputLyr){
98

  
99
	private MathTransform mathTransform;
100

  
101
	private boolean hasAuxiliarLyrs = false;
102

  
103
	private FLyrVect[] auxiliarLyrs = null;
104

  
105
	public ReferencingGeoprocess(FLyrVect inputLyr) {
98 106
		firstLayer = inputLyr;
99 107
	}
100
	
108

  
101 109
	@Override
102 110
	public void checkPreconditions() throws GeoprocessException {
103 111
		try {
104 112
			int numShapes = firstLayer.getSource().getShapeCount();
105
			if(numShapes == 0)
113
			if (numShapes == 0)
106 114
				throw new GeoprocessException("capa de entrada sin features");
107 115
		} catch (ReadDriverException e) {
108
			throw new GeoprocessException("Error de driver al tratar de acceder al numero de elementos", e);
116
			throw new GeoprocessException(
117
					"Error de driver al tratar de acceder al numero de elementos",
118
					e);
109 119
		}
110
		
111
		if(mathTransform == null)
112
			throw new GeoprocessException("No se ha especificado un metodo de transformacion espacial");
120

  
121
		if (mathTransform == null)
122
			throw new GeoprocessException(
123
					"No se ha especificado un metodo de transformacion espacial");
113 124
	}
114 125

  
115 126
	@Override
116 127
	public ILayerDefinition createLayerDefinition() {
117
		if(resultLayerDefinition == null){
128
		if (resultLayerDefinition == null) {
118 129
			try {
119 130
				resultLayerDefinition = DefinitionUtils
120 131
						.createLayerDefinition(firstLayer);
......
125 136
		return resultLayerDefinition;
126 137
	}
127 138

  
128
	
129 139
	@Override
130 140
	public void setParameters(Map params) throws GeoprocessException {
131
		mathTransform = (MathTransform) /*(AbstractMathTransform)*/ params.get("mathTransform");
141
		mathTransform = (MathTransform) params.get("mathTransform");
142
		hasAuxiliarLyrs = ((Boolean) params.get("hasAuxiliar")).booleanValue();
143
		if(hasAuxiliarLyrs){
144
			this.auxiliarLyrs = (FLyrVect[]) params.get("auxiliarLyrs");
145
		}
132 146
	}
133 147

  
134 148
	@Override
......
139 153
			int numOfSteps = firstLayer.getSource().getShapeCount();
140 154
			progressMonitor.setFinalStep(numOfSteps);
141 155
			progressMonitor.setDeterminatedProcess(true);
142
			progressMonitor.setNote(Messages.getText("referencing_geoprocess_note"));
156
			progressMonitor.setNote(Messages
157
					.getText("referencing_geoprocess_note"));
143 158
			progressMonitor.setStatusMessage(Messages
144 159
					.getText("referencing_geoprocess_layer_message"));
145 160
		} catch (ReadDriverException e) {
146 161
			throw new GeoprocessException(
147 162
					"error accediendo al numero de features de una layer", e);
148 163
		}
149
		
164

  
150 165
	}
151 166

  
152 167
	@Override
153 168
	public void process(CancellableProgressTask progressMonitor)
154 169
			throws GeoprocessException {
155
		
156
	/*
157
	 * ++++++++++++++++++++++++++
158
	 * FIXME: MOVER A CLASE ABSTRACTA
159
	 * */
170

  
171
		/*
172
		 * ++++++++++++++++++++++++++ FIXME: MOVER A CLASE ABSTRACTA
173
		 */
160 174
		if (progressMonitor != null) {
161 175
			initialize(progressMonitor);
162 176
		}
......
175 189
			throw new GeoprocessException(e1);
176 190
		}
177 191

  
178
	/*
179
	 * +++++++++++++++++
180
	 */	
181
		
192
		/*
193
		 * +++++++++++++++++
194
		 */
195

  
182 196
		try {
183 197
			IFeatureIterator featureIterator = null;
184
			if(this.operateOnlyWithSelection){
198
			if (this.operateOnlyWithSelection) {
185 199
				FBitSet selection = firstLayer.getRecordset().getSelection();
186
	        	featureIterator = new FeatureBitsetIterator(selection, firstLayer.getSource());
187
			}else{
200
				featureIterator = new FeatureBitsetIterator(selection,
201
						firstLayer.getSource());
202
			} else {
188 203
				featureIterator = firstLayer.getSource().getFeatureIterator();
189 204
			}
190
			
191
			while(featureIterator.hasNext()){
205

  
206
			while (featureIterator.hasNext()) {
192 207
				IFeature feature = featureIterator.next();
193 208
				IGeometry fmapGeo = feature.getGeometry();
194 209
				Value[] values = feature.getAttributes();
195
				IGeometry transformedGeometry = ReferencingUtil.getInstance().
196
										createTransformedGeometry(fmapGeo,
197
																null, 
198
																null, 
199
																this.mathTransform);
200
				if(progressMonitor != null)
210
				IGeometry transformedGeometry = ReferencingUtil.getInstance()
211
						.createTransformedGeometry(fmapGeo, null, null,
212
								this.mathTransform);
213
				if (progressMonitor != null)
201 214
					progressMonitor.reportStep();
202
				
203
				if(transformedGeometry != null){
204
					DefaultFeature newFeature = 
205
						new DefaultFeature(transformedGeometry, 
206
													values, 
207
												new UID().toString());
215

  
216
				if (transformedGeometry != null) {
217
					DefaultFeature newFeature = new DefaultFeature(
218
							transformedGeometry, values, new UID().toString());
208 219
					featureProcessor.processFeature(newFeature);
209 220
				}
210
			}//while
221
			}// while
211 222
			featureProcessor.finish();
212 223
			if (progressMonitor != null) {
213 224
				progressMonitor.finished();
......
221 232
					"Error al acceder a la informacion del driver dentro del geoproceso",
222 233
					e);
223 234
		} catch (TransformException e) {
224
			throw new GeoprocessException("Error de transformacion de coordenadas", e);
235
			throw new GeoprocessException(
236
					"Error de transformacion de coordenadas", e);
225 237
		} catch (FactoryException e) {
226
			throw new GeoprocessException("Error al tratar de construir una transformacion de coordenadas", e);
238
			throw new GeoprocessException(
239
					"Error al tratar de construir una transformacion de coordenadas",
240
					e);
241
		}
242

  
243
	}
244

  
245
	@Override
246
	public FLayer getResult() throws GeoprocessException {
247
		MapContext map = ((View) PluginServices.getMDIManager()
248
				.getActiveWindow()).getModel().getMapContext();
249

  
250
		// first of all, we look for an existing flayers container
251
		FLayers rootLyrs = map.getLayers();
252
		String folderName = PluginServices.getText(this,
253
				"SPATIAL_ADJUST_SESSION")
254
				+ " "
255
				+ ReferencingUtil.getInstance()
256
						.getNumberOfSpatialAdjustSessions();
257
		FLayers adjustSessionLyrs = (FLayers) rootLyrs.getLayer(folderName);
258
		if (adjustSessionLyrs == null){
259
			adjustSessionLyrs = new FLayers();
260
			adjustSessionLyrs.setMapContext(map);
261
			adjustSessionLyrs.setParentLayer(map.getLayers());
262
			adjustSessionLyrs.setName(folderName);
263
			System.err.println("Error, geoproceso ajuste espacial sin capa de links");
264
		}
265
		if (hasAuxiliarLyrs && auxiliarLyrs != null) {
266
			int position = 0;
267
			for (int i = 0; i < auxiliarLyrs.length; i++) {
268
				adjustSessionLyrs.addLayer(position, auxiliarLyrs[i]);
269
				position++;
270
			}
227 271
		} 
228 272
		
273
		adjustSessionLyrs.addLayer(super.getResult());
274
		
275
		map.invalidate();
276
		return adjustSessionLyrs;
229 277
	}
230 278

  
231 279
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/referencing/gui/ReferencingGeoprocessPanel.java
57 57
import javax.swing.JLabel;
58 58
import javax.vecmath.MismatchedSizeException;
59 59

  
60
import org.geotools.referencefork.referencing.operation.transform.AbstractMathTransform;
60
import org.geotools.referencefork.referencing.operation.builder.RubberSheetBuilder;
61 61
import org.gvsig.referencing.MappedPositionContainer;
62
import org.gvsig.referencing.ReferencingUtil;
62 63
import org.gvsig.topology.ui.util.GUIUtil;
63 64
import org.opengis.referencing.FactoryException;
64 65
import org.opengis.referencing.operation.MathTransform;
......
69 70
import com.iver.andami.ui.mdiManager.IWindow;
70 71
import com.iver.cit.gvsig.fmap.MapControl;
71 72
import com.iver.cit.gvsig.fmap.layers.FLayers;
73
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
72 74
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
73 75
import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessGridbagPanel;
74 76
import com.iver.cit.gvsig.geoprocess.impl.referencing.IReferencingGeoprocessUserEntries;
75 77
import com.iver.cit.gvsig.project.documents.view.gui.View;
76
import com.iver.cit.gvsig.referencing.DisactivableMappedPositionContainerImpl;
77 78
import com.iver.cit.gvsig.referencing.TransformationsRegistry;
78 79
import com.iver.cit.gvsig.referencing.TransformationsRegistry.TransformationRegistryEntry;
79 80

  
......
81 82

  
82 83
	private MapControl currentView;
83 84
	
84
	private MappedPositionContainer verrorList;
85
//	private MappedPositionContainer verrorList;
85 86

  
86 87
//	private String controlPointsTitle;
87 88

  
......
107 108
			MapControl mapControl = vista.getMapControl();
108 109
			this.currentView = mapControl;
109 110
		}
110
		verrorList = new DisactivableMappedPositionContainerImpl();
111 111
		
112
		
112 113
//		controlPointsTitle = PluginServices.getText(null, "Control_points");
113 114
		transformationTitle = PluginServices.getText(null, "Transform");
114 115
		
......
117 118
//		addComponent(controlPointsLbl);
118 119
		
119 120
		JComboBox cb = getTransformationOptionCb();
120
		addComponent(vectorErrorTable = new VectorErrorTable(currentView, verrorList, (TransformationRegistryEntry)cb.getSelectedItem() ));
121
		addComponent(vectorErrorTable = new VectorErrorTable(currentView, 
122
														 getInputLayer(),
123
														 (TransformationRegistryEntry)cb.getSelectedItem() ));
121 124
		
122 125
		
123 126
		JLabel transformTitleLbl = new JLabel(transformationTitle);
......
173 176
	}
174 177
	
175 178
	@Override
179
	/**
180
	 * This method is called when layer combo box selection changes.
181
	 */
176 182
	protected void processLayerComboBoxStateChange(ItemEvent e) {
183
		vectorErrorTable.setAdjustingLyr(getInputLayer());
177 184
	}
178 185

  
179 186
	public MathTransform getMathTransform() throws GeoprocessException {
180 187
		try {
181
			return  ((TransformationRegistryEntry)getTransformationOptionCb().getSelectedItem()).
182
							createTransformBuilder(verrorList.getAsList()).getMathTransform();
188
//			return  ((TransformationRegistryEntry)getTransformationOptionCb().getSelectedItem()).
189
//							createTransformBuilder(verrorList.getAsList()).getMathTransform();
190
			MappedPositionContainer mp = this.vectorErrorTable.getVerrorContainer();
191
			return  ((TransformationRegistryEntry)getTransformationOptionCb().
192
															getSelectedItem()).
193
															createTransformBuilder(mp.getAsList()).
194
															getMathTransform();
183 195
		} catch (FactoryException e) {
184 196
			throw new GeoprocessException(e);
185 197
		}catch(RuntimeException re){
......
192 204
		return isFirstOnlySelected();
193 205
	}
194 206

  
207

  
208

  
209
	public FLyrVect[] getAuxiliarLyrs() {
210
		if(hasAuxiliarLyrs()){
211
			MappedPositionContainer mp = this.vectorErrorTable.getVerrorContainer();
212
			TransformationRegistryEntry transformRegistryEntry = 
213
				(TransformationRegistryEntry)getTransformationOptionCb().getSelectedItem();
214
			RubberSheetBuilder transformBuilder = 
215
				(RubberSheetBuilder) transformRegistryEntry.createTransformBuilder(mp.getAsList());
216
			FLyrVect tinLyr = ReferencingUtil.getInstance().getTinAsFMapLyr(transformBuilder, currentView.getProjection());
217
			return new FLyrVect[]{tinLyr};
218
		}else{
219
			return new FLyrVect[]{};
220
		}
221
	}
222

  
223

  
224

  
225
	public boolean hasAuxiliarLyrs() {
226
		//by now, the only transformation with auxiliar layers is Rubber Sheet Transform,
227
		//being this auxiliar layer TIN formed with mapped positions.
228
		TransformationRegistryEntry transformRegistryEntry = 
229
			(TransformationRegistryEntry)getTransformationOptionCb().getSelectedItem();
230
		return transformRegistryEntry.getName().
231
			equals(PluginServices.getText(null, "RUBBER_SHEET_TRANSFORM"));
232
	}
233

  
195 234
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/referencing/gui/VectorErrorTable.java
50 50

  
51 51
import java.awt.BorderLayout;
52 52
import java.awt.Dimension;
53
import java.awt.KeyEventDispatcher;
53 54
import java.awt.Window;
54 55
import java.awt.event.ActionEvent;
55 56
import java.awt.event.ActionListener;
57
import java.awt.event.KeyEvent;
56 58

  
57 59
import javax.swing.BorderFactory;
58 60
import javax.swing.JComponent;
......
61 63
import javax.swing.JPanel;
62 64
import javax.swing.JScrollPane;
63 65
import javax.swing.JTable;
66
import javax.swing.KeyStroke;
64 67
import javax.swing.ListSelectionModel;
65 68
import javax.swing.border.EtchedBorder;
66 69
import javax.swing.table.AbstractTableModel;
......
74 77
import org.gvsig.gui.beans.swing.JButton;
75 78
import org.gvsig.referencing.DisactivableMappedPosition;
76 79
import org.gvsig.referencing.MappedPositionContainer;
80
import org.gvsig.referencing.ReferencingUtil;
77 81
import org.gvsig.topology.ui.LayerJComboBox;
78 82
import org.gvsig.topology.ui.LayerJComboBox.LayerFilter;
79 83
import org.gvsig.topology.ui.util.BoxLayoutPanel;
......
96 100
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
97 101
import com.iver.cit.gvsig.fmap.layers.FLayer;
98 102
import com.iver.cit.gvsig.fmap.layers.FLayerGenericVectorial;
103
import com.iver.cit.gvsig.fmap.layers.FLayers;
99 104
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
100 105
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
101 106
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
102 107
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
103 108
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent;
109
import com.iver.cit.gvsig.project.documents.view.gui.View;
104 110
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
111
import com.iver.cit.gvsig.referencing.DisactivableMappedPositionContainerImpl;
105 112
import com.iver.cit.gvsig.referencing.MappedPositionContainerLayerBased;
106 113
import com.iver.cit.gvsig.referencing.TransformationsRegistry.TransformationRegistryEntry;
107 114

  
......
114 121
public class VectorErrorTable extends BoxLayoutPanel {
115 122

  
116 123
	private static final long serialVersionUID = -6506747314549738246L;
124
	
125
	
126
	private static boolean registeredKeyStrokes = false;
117 127

  
118 128
	/**
119 129
	 * Current active view where user could digitize new vectorial errors.
......
125 135
	 */
126 136
	MappedPositionContainer verrorContainer;
127 137

  
128
	
129 138
	/**
130 139
	 * Current transformation provider
131 140
	 */
132 141
	TransformationRegistryEntry transformBuilderProvider;
133
	
142

  
134 143
	/**
135
	 * Current transformation built from control points in vector error container
136
	 * with the current transformBuilderProvider
144
	 * Current transformation built from control points in vector error
145
	 * container with the current transformBuilderProvider
137 146
	 */
138 147
	MathTransform mathTransform;
139
	
140 148
	/**
149
	 * Lyr we are spatially adjusting 
150
	 */
151
	FLyrVect adjustingLyr;
152

  
153
	/**
141 154
	 * Table model to show control points and associated errors in a JTable
155
	 * 
142 156
	 * @author Alvaro Zabala
143
	 *
157
	 * 
144 158
	 */
145 159
	private final class VErrorTableModel extends AbstractTableModel {
146 160

  
......
156 170
		public int getRowCount() {
157 171
			return verrorContainer.getCount();
158 172
		}
159
		
173

  
160 174
		public Class getColumnClass(int c) {
161
            return getValueAt(0, c).getClass();
162
        }
163
		
175
			return getValueAt(0, c).getClass();
176
		}
177

  
164 178
		public boolean isCellEditable(int row, int col) {
165
            if (col == 6) {
166
                return true;
167
            } else {
168
                return false;
169
            }
170
        }
179
			if (col == 6) {
180
				return true;
181
			} else {
182
				return false;
183
			}
184
		}
171 185

  
172
        public void setValueAt(Object value, int row, int col) {
173
        	if(col != 6)
174
        		return;
175
           DisactivableMappedPosition mappedPosition = 
176
        	   (DisactivableMappedPosition) verrorContainer.getMappedPosition(row);
177
           mappedPosition.setActive(((Boolean)value).booleanValue());
178
           fireTableCellUpdated(row, col);
179
           
180
           updateVErrorTable();
181
           updateRmsText();
182
        }
186
		public void setValueAt(Object value, int row, int col) {
187
			if (col != 6)
188
				return;
189
			DisactivableMappedPosition mappedPosition = (DisactivableMappedPosition) verrorContainer
190
					.getMappedPosition(row);
191
			mappedPosition.setActive(((Boolean) value).booleanValue());
192
			fireTableCellUpdated(row, col);
183 193

  
194
			updateVErrorTable();
195
			updateRmsText();
196
		}
184 197

  
185
		public Object getValueAt(int row, int col) {//FIXME USAR NUMBERFORMAT PARA LAS COORDENADAS
198
		public Object getValueAt(int row, int col) {// FIXME USAR NUMBERFORMAT
199
													// PARA LAS COORDENADAS
186 200
			Object solution = null;
187 201
			MappedPosition mappedPosition = verrorContainer
188 202
					.getMappedPosition(row);
189
			
203

  
190 204
			DirectPosition position = null;
191 205
			switch (col) {
192 206
			case 0:// Verror id
......
210 224
				break;
211 225
			case 5:// RMS
212 226
				try {
213
					if(mathTransform == null){
214
						//mathTransform at begininng will allways be null, because there arent
215
						//enought control points to build a transformation
216
						mathTransform = transformBuilderProvider.createTransformBuilder(verrorContainer.getAsList()).getMathTransform();	
227
					if (mathTransform == null) {
228
						// mathTransform at begininng will allways be null,
229
						// because there arent
230
						// enought control points to build a transformation
231
						mathTransform = transformBuilderProvider
232
								.createTransformBuilder(
233
										verrorContainer.getAsList())
234
								.getMathTransform();
217 235
					}
218 236
					solution = mappedPosition.getError(mathTransform, buffer)
219 237
							+ "";
220 238
				} catch (TransformException e) {
221 239
					solution = "";
222
					getRmsLabel().setText(PluginServices.getText(this, "Error_computing_RMS"));
223
				}catch(MismatchedSizeException e){
240
					getRmsLabel()
241
							.setText(
242
									PluginServices.getText(this,
243
											"Error_computing_RMS"));
244
				} catch (MismatchedSizeException e) {
224 245
					solution = "";
225
					getRmsLabel().setText(PluginServices.getText(this, "More_control_points_needed_for_the_current_transform"));
226
				}catch(MismatchedDimensionException e){
246
					getRmsLabel()
247
							.setText(
248
									PluginServices
249
											.getText(this,
250
													"More_control_points_needed_for_the_current_transform"));
251
				} catch (MismatchedDimensionException e) {
227 252
					solution = "";
228
					getRmsLabel().setText(PluginServices.getText(this, "Control_points_coordinates_dimension_are_insufficient_for_the_current_transform"));
229
				}catch(MismatchedReferenceSystemException e){
253
					getRmsLabel()
254
							.setText(
255
									PluginServices
256
											.getText(
257
													this,
258
													"Control_points_coordinates_dimension_are_insufficient_for_the_current_transform"));
259
				} catch (MismatchedReferenceSystemException e) {
230 260
					solution = "";
231
					getRmsLabel().setText(PluginServices.getText(this, "Control_points_have_inconsistent_reference_system"));
261
					getRmsLabel()
262
							.setText(
263
									PluginServices
264
											.getText(this,
265
													"Control_points_have_inconsistent_reference_system"));
232 266
				} catch (FactoryException e) {
233 267
					solution = "";
234
					getRmsLabel().setText(PluginServices.getText(this, "Error_creating_mathTransform"));
268
					getRmsLabel().setText(
269
							PluginServices.getText(this,
270
									"Error_creating_mathTransform"));
235 271
				}
236
//				catch(RuntimeException e){//FIXME DIFERENCIAR MISMATCHED SIZE, MISMATCHED DIMENSION Y MISMATCHED REFERENCE SYSTEM
237
//					solution = "";
238
//					e.printStackTrace();
239
//				}
272
				// catch(RuntimeException e){//FIXME DIFERENCIAR MISMATCHED
273
				// SIZE, MISMATCHED DIMENSION Y MISMATCHED REFERENCE SYSTEM
274
				// solution = "";
275
				// e.printStackTrace();
276
				// }
240 277
				break;
241
				
242
			case 6://active or disactive
243
				if(mappedPosition instanceof DisactivableMappedPosition){
244
					DisactivableMappedPosition pos = 
245
						(DisactivableMappedPosition)mappedPosition;
278

  
279
			case 6:// active or disactive
280
				if (mappedPosition instanceof DisactivableMappedPosition) {
281
					DisactivableMappedPosition pos = (DisactivableMappedPosition) mappedPosition;
246 282
					solution = new Boolean(pos.isActive());
247
				}else{
283
				} else {
248 284
					solution = new Boolean(true);
249 285
				}
250 286
				break;
......
264 300
	private JButton addLinkBtn;
265 301

  
266 302
	private JButton loadLinksBtn;
267

  
303
	
304
	/**
305
	 * Listener for mouse events in MapControl
306
	 */
307
	private ExtendedVectorListener vl;
308
	/**
309
	 * Behavior to digitize vector errors
310
	 */
311
	private VectorBehavior vb;
312
	
313
	/**
314
	 * Constructor.
315
	 * @param currentView
316
	 * @param adjustingLyr
317
	 * @param transformBuilderProvider
318
	 */
268 319
	public VectorErrorTable(MapControl currentView,
269
			MappedPositionContainer verrorContainer,
320
							FLyrVect adjustingLyr,
270 321
			TransformationRegistryEntry transformBuilderProvider) {
271 322
		this.currentView = currentView;
272
		this.verrorContainer = verrorContainer;
323
		this.verrorContainer = new DisactivableMappedPositionContainerImpl();
273 324
		this.transformBuilderProvider = transformBuilderProvider;
325
		this.adjustingLyr = adjustingLyr;
274 326
		try {
275
			this.mathTransform = transformBuilderProvider.createTransformBuilder(verrorContainer.getAsList()).getMathTransform();
276
		}catch (Exception e) {
327
			this.mathTransform = transformBuilderProvider
328
					.createTransformBuilder(verrorContainer.getAsList())
329
					.getMathTransform();
330
		} catch (Exception e) {
277 331
			e.printStackTrace();
278 332
		}
279 333
		initialize();
334
		
335
		ReferencingUtil.getInstance().incrementAdjustSessions();
280 336
	}
281 337

  
282 338
	public void updateVErrorTable() {
......
289 345
		this.addRow(new JComponent[] { new JLabel(PluginServices.getText(this,
290 346
				"VERROR_TITLE")) });
291 347

  
292
		
293 348
		JScrollPane scrollPane = new JScrollPane();
294 349
		scrollPane.setViewportView(getVErrorTable());
295
		scrollPane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
296
//		scrollPane.setPreferredSize(new Dimension(600, 160));
297
//		scrollPane.setMinimumSize(new Dimension(600, 120));
298
		scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
299
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
300
		
301
		this.addRow(new JComponent[] { scrollPane },
302
											600, 300);
350
		scrollPane.setBorder(BorderFactory
351
				.createEtchedBorder(EtchedBorder.RAISED));
352
		// scrollPane.setPreferredSize(new Dimension(600, 160));
353
		// scrollPane.setMinimumSize(new Dimension(600, 120));
354
		scrollPane
355
				.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
356
		scrollPane
357
				.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
303 358

  
304
		
359
		this.addRow(new JComponent[] { scrollPane }, 600, 300);
360

  
305 361
		this.addRow(new JComponent[] { getAddVErrorButton(),
306
				getDeleteVErrorButton(), getLoadLinksButton()}, 600, DEFAULT_HEIGHT);
362
				getDeleteVErrorButton(), getLoadLinksButton() }, 600,
363
				DEFAULT_HEIGHT);
307 364

  
308 365
		this.addRow(new JComponent[] { getRmsLabel() });
366
		
367
		initializeKeyEventsListening();
309 368

  
310 369
	}
370
	
371
	private void initializeKeyEventsListening(){
372
		if(! registeredKeyStrokes){
373
		KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
374
		
375
		PluginServices.registerKeyStroke(key, new KeyEventDispatcher(){
376
			public boolean dispatchKeyEvent(KeyEvent e) {
377
				if (e.getID() != KeyEvent.KEY_RELEASED)
378
					return false;
379
				
380
				IWindow v = PluginServices.getMDIManager().getActiveWindow();
381
				if (!(v instanceof View))
382
					return false;
311 383

  
384
				View view = (View)v;
385
				MapControl mapControl = view.getMapControl();
386
				if(mapControl.getCurrentTool().equals("digitizeVectorError")){
387
					if (e.getKeyCode() == KeyEvent.VK_ESCAPE){
388
						vl.showContainer();
389
						return true;
390
					}
391
				}
392
				return false;
393
			}});
394
		
395
//		KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
396
//		kfm.addKeyEventPostProcessor(new KeyEventPostProcessor(){
397
//			public boolean postProcessKeyEvent(KeyEvent arg0) {
398
//				return false;
399
//			}});
400
		registeredKeyStrokes = true;
401
		}
402

  
403
	}
404

  
312 405
	private JTable getVErrorTable() {
313 406
		if (verrorTable == null) {
314 407
			verrorTable = new JTable();
......
331 424

  
332 425
			verrorTable.getColumnModel().getColumn(5).setHeaderValue(
333 426
					PluginServices.getText(this, "RMS"));
334
			
427

  
335 428
			verrorTable.getColumnModel().getColumn(6).setHeaderValue(
336 429
					PluginServices.getText(this, "Active"));
337
			
430

  
338 431
			verrorTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
339 432
		}
340 433
		return verrorTable;
......
356 449

  
357 450
	private JButton getAddVErrorButton() {
358 451
		if (addLinkBtn == null) {
359
			addLinkBtn = new JButton(PluginServices.getText(this,
360
					"Add_VError"));
452
			addLinkBtn = new JButton(PluginServices.getText(this, "Add_VError"));
361 453
			addLinkBtn.addActionListener(new ActionListener() {
362 454
				public void actionPerformed(ActionEvent arg0) {
363 455
					addLink();
......
366 458
		}
367 459
		return addLinkBtn;
368 460
	}
369
	
370
	private JButton getLoadLinksButton(){
371
		if(loadLinksBtn == null){
461

  
462
	private JButton getLoadLinksButton() {
463
		if (loadLinksBtn == null) {
372 464
			loadLinksBtn = new JButton(PluginServices.getText(this,
373
			"Load_links"));
374
			loadLinksBtn.addActionListener(new ActionListener(){
465
					"Load_links"));
466
			loadLinksBtn.addActionListener(new ActionListener() {
375 467
				public void actionPerformed(ActionEvent arg0) {
376 468
					loadLinks();
377
				}});
469
				}
470
			});
378 471
		}
379 472
		return loadLinksBtn;
380 473
	}
......
390 483
	private void updateRmsText() {
391 484
		try {
392 485
			getRmsLabel().setText(
393
					PluginServices.getText(this, "RMS") + " : "
394
							+ transformBuilderProvider.createTransformBuilder(verrorContainer.getAsList()).getErrorStatistics().rms());
486
					PluginServices.getText(this, "RMS")
487
							+ " : "
488
							+ transformBuilderProvider.createTransformBuilder(
489
									verrorContainer.getAsList())
490
									.getErrorStatistics().rms());
395 491
		} catch (FactoryException e) {
396 492
			getRmsLabel().setText(
397 493
					PluginServices.getText(this, "Error_al_calcular_RMS"));
398
		}catch(RuntimeException re){
494
		} catch (RuntimeException re) {
399 495
			getRmsLabel().setText("");
400 496
		}
497

  
498
		// MismatchedSizeException, MismatchedDimensionException,
499
		// MismatchedReferenceSystemException
500
	}
501
	
502
	class ExtendedVectorListener extends VectorListenerImpl{
503
		JComponent container;
401 504
		
402
//		MismatchedSizeException, MismatchedDimensionException,
403
//        MismatchedReferenceSystemException
404
	}
505
		public ExtendedVectorListener(MapControl mapCtrl, 
506
									  MappedPositionContainer linksList,
507
									  JComponent container) {
508
			super(mapCtrl, linksList);
509
			this.container = container;
510
		}
511
		
512
		public void hideContainer(){
513
			if (container != null) {
514
				GUIUtil.getInstance().getParentOfType(container,
515
						JDialog.class).setVisible(false);
516
			}
517
		}
518
		
519
		public void showContainer(){
520
			if (container != null) {
521
				if (!GUIUtil.getInstance().getParentOfType(container, JDialog.class).isVisible()) {
522
					GUIUtil.getInstance().getParentOfType(container, JDialog.class).setVisible(true);
523
				}//if
524
			}// thisContainer
525
		}
526
		
527
		public void vector(MoveEvent event) throws BehaviorException {
528
			super.vector(event);
529
			if(isZooming)
530
				return;
531
			mapCtrl.setPrevTool();
405 532

  
533
			if (!verrorContainer.existsLinksLyr()) {
534
				FLyrVect linkLyr = verrorContainer
535
						.getLinkLyr(currentView.getProjection());
536
				MapContext mapContext = currentView.getMapContext();
537
				
538
				//each time we create a new link layer, we are creating a new spatial adjusting session
539
				FLayers solution = new FLayers();
540
				solution.setMapContext(mapContext);
541
				solution.setParentLayer(mapContext.getLayers());
542
				solution.setName(PluginServices.getText(this, "SPATIAL_ADJUST_SESSION")+" "+ReferencingUtil.getInstance().getNumberOfSpatialAdjustSessions());
543
				solution.addLayer(linkLyr);
544
				mapContext.beginAtomicEvent();
545
				mapContext.getLayers().addLayer(solution);
546
				mapContext.endAtomicEvent();
547
			}
548
			mapCtrl.commandRepaint();
549

  
550
			updateVErrorTable();
551
			updateRmsText();
552

  
553
			showContainer();
554
		}
555
	}//class ExtendedVectorListener
556

  
406 557
	private void addLink() {
407 558
		final MapControl mapCtrl = currentView;
408 559
		if (mapCtrl != null) {
409 560
			String sTool = "digitizeVectorError";
410
			StatusBarListener sbl = new StatusBarListener(mapCtrl);
411

  
412
			final JComponent thisContainer = (JComponent) GUIUtil.getInstance()
413
					.getParentOfType(this, IWindow.class);
414

  
415
			VectorListenerImpl vl = new VectorListenerImpl(mapCtrl,
416
					verrorContainer) {
417
				public void vector(MoveEvent event) throws BehaviorException {
418
					super.vector(event);
419
					mapCtrl.setPrevTool();
420

  
421
					if (!verrorContainer.existsLinksLyr()) {
422
						//TODO Use a FLayers as a container of all spatial adjust 
423
						//auxiliar layers.
424
						
425
						FLyrVect linkLyr = verrorContainer
426
								.getLinkLyr(currentView.getProjection());
427
						MapContext mapContext = currentView.getMapContext();
428
						mapContext.beginAtomicEvent();
429
						mapContext.getLayers().addLayer(linkLyr);
430
						mapContext.endAtomicEvent();
431
					}
432
					mapCtrl.commandRepaint();
433
					
434
					updateVErrorTable();
435
					updateRmsText();
436
					
437
					if (thisContainer != null) {
438
						if (!GUIUtil.getInstance().getParentOfType(
439
								thisContainer, JDialog.class)
440
								.isVisible()) {
441
							GUIUtil.getInstance().getParentOfType(
442
									thisContainer, JDialog.class)
443
									.setVisible(true);
444
						}
445

  
446
					}// thisContainer
447
				}
448
			};
449

  
450
			mapCtrl.addMapTool(sTool, new Behavior[] { new VectorBehavior(vl),
451
					new MouseMovementBehavior(sbl) });
561
			
562
			if(vb == null){
563
				JComponent container = (JComponent) GUIUtil.getInstance()
564
				.getParentOfType(this, IWindow.class);
565
		
566
				vl = new ExtendedVectorListener(mapCtrl,
567
											verrorContainer, 
568
												container);
569
				vb = new VectorBehavior(vl, this.adjustingLyr);
570
				
571
				StatusBarListener sbl = new StatusBarListener(mapCtrl);
572
				mapCtrl.addMapTool(sTool, 
573
						new Behavior[] { vb, 
574
						new MouseMovementBehavior(sbl) });
575
			}//if vl == null
576
			
452 577
			mapCtrl.setTool(sTool);
453 578

  
454
			if (thisContainer != null) {
455
				GUIUtil.getInstance().getParentOfType(thisContainer,
456
						JDialog.class).setVisible(false);
457
			}
579
			vl.hideContainer();
458 580
		}// if mapCtrl != null
459 581
	}
460 582

  
583
	
461 584
	private void deleteLink() {
462 585
		int toDelete = getVErrorTable().getSelectedRow();
463 586
		this.verrorContainer.delete(toDelete);
464 587
		updateVErrorTable();
465 588
		updateRmsText();
466 589
	}
467
	
468
	
590

  
469 591
	/**
470 592
	 * Creates de MappedPositionContainer from one of the TOC's layer
471 593
	 */
472 594
	private void loadLinks() {
473
		LayerJComboBox lyrComboBox = 
474
			new LayerJComboBox(currentView.getMapContext().getLayers(),
475
							new LayerFilter(){
476
								public boolean filter(FLayer layer) {
477
									if(layer instanceof FLyrVect){
478
										FLyrVect aux = (FLyrVect) layer;
479
										try {
480
											if(aux.getShapeType() == FShape.LINE)
481
												return true;
482
										} catch (ReadDriverException e) {
483
											e.printStackTrace();
484
										}
485
									}
486
									return false;
487
								}});
488
		
489
		class LayerComboPanel extends JPanel implements IWindow{
490
			
595
		LayerJComboBox lyrComboBox = new LayerJComboBox(currentView
596
				.getMapContext().getLayers(), new LayerFilter() {
597
			public boolean filter(FLayer layer) {
598
				if (layer instanceof FLyrVect) {
599
					FLyrVect aux = (FLyrVect) layer;
600
					try {
601
						if (aux.getShapeType() == FShape.LINE)
602
							return true;
603
					} catch (ReadDriverException e) {
604
						e.printStackTrace();
605
					}
606
				}
607
				return false;
608
			}
609
		});
610

  
611
		class LayerComboPanel extends JPanel implements IWindow {
612

  
491 613
			private boolean okPressed = false;
492
			
614

  
493 615
			public WindowInfo getWindowInfo() {
494
				WindowInfo solution = new WindowInfo(WindowInfo.MODALDIALOG|
495
						  								 WindowInfo.PALETTE|
496
						  								 WindowInfo.ICONIFIABLE|
497
						  								 WindowInfo.RESIZABLE|
498
						  								 WindowInfo.MAXIMIZABLE);
499
				solution.setTitle(PluginServices.getText(this, "Link_layer_Selection"));
616
				WindowInfo solution = new WindowInfo(WindowInfo.MODALDIALOG
617
						| WindowInfo.PALETTE | WindowInfo.ICONIFIABLE
618
						| WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
619
				solution.setTitle(PluginServices.getText(this,
620
						"Link_layer_Selection"));
500 621
				solution.setWidth(300);
501 622
				solution.setHeight(50);
502 623
				return solution;
503 624
			}
504
			
505
			public void setOkPressed(boolean okPressed){
625

  
626
			public void setOkPressed(boolean okPressed) {
506 627
				this.okPressed = okPressed;
507 628
			}
508
			
509
			public boolean isOkPressed(){
629

  
630
			public boolean isOkPressed() {
510 631
				return this.okPressed;
511 632
			}
512
		}//class
513
		
633
		}// class
634

  
514 635
		final LayerComboPanel panel = new LayerComboPanel();
515 636
		panel.setLayout(new BorderLayout());
516
		
637

  
517 638
		JPanel centerPanel = new JPanel();
518 639
		centerPanel.setLayout(new BorderLayout());
519 640
		JPanel caux = new JPanel();
520
		caux.add(new JLabel(PluginServices.getText(this,"Select_link_layer")), BorderLayout.WEST);
641
		caux.add(new JLabel(PluginServices.getText(this, "Select_link_layer")),
642
				BorderLayout.WEST);
521 643
		caux.add(lyrComboBox, BorderLayout.EAST);
522 644
		centerPanel.add(caux, BorderLayout.EAST);
523 645
		panel.add(centerPanel, BorderLayout.CENTER);
524
		
646

  
525 647
		JPanel southPanel = new JPanel();
526 648
		JButton okButton = new JButton(PluginServices.getText(this, "OK"));
527
		
528
		okButton.addActionListener(new ActionListener(){
649

  
650
		okButton.addActionListener(new ActionListener() {
529 651
			public void actionPerformed(ActionEvent arg0) {
530
				Window parentWindow = GUIUtil.getInstance().getParentWindow(panel);
652
				Window parentWindow = GUIUtil.getInstance().getParentWindow(
653
						panel);
531 654
				parentWindow.setVisible(false);
532 655
				parentWindow.dispose();
533 656
				panel.setOkPressed(true);
534
			}});
535
		
657
			}
658
		});
659

  
536 660
		southPanel.setLayout(new BorderLayout());
537 661
		JPanel aux = new JPanel();
538 662
		aux.add(okButton, BorderLayout.EAST);
539 663
		southPanel.add(aux, BorderLayout.EAST);
540 664
		panel.add(southPanel, BorderLayout.SOUTH);
541
		
665

  
542 666
		panel.setSize(new Dimension(300, 50));
543 667
		PluginServices.getMDIManager().addWindow(panel);
544
		
545
		//Now we check if user presssed ok
546
		if(panel.isOkPressed()){
547
			FLyrVect selectedLyr = (FLyrVect) lyrComboBox.getSelectedLayer();
668

  
669
		// Now we check if user presssed ok
670
		FLyrVect selectedLyr = null;
671
		if (panel.isOkPressed()) {
672
			selectedLyr = (FLyrVect) lyrComboBox.getSelectedLayer();
548 673
			MappedPositionContainer auxContainer = null;
549
			if(selectedLyr instanceof FLayerGenericVectorial){
550
				FLayerGenericVectorial genericLyr = (FLayerGenericVectorial)selectedLyr;
674
			if (selectedLyr instanceof FLayerGenericVectorial) {
675
				FLayerGenericVectorial genericLyr = (FLayerGenericVectorial) selectedLyr;
551 676
				VectorialDriver driver = genericLyr.getDriver();
552
				if(driver  instanceof VectorErrorMemoryDriver){
553
					VectorErrorMemoryDriver errorDriver = (VectorErrorMemoryDriver)driver;
677
				if (driver instanceof VectorErrorMemoryDriver) {
678
					VectorErrorMemoryDriver errorDriver = (VectorErrorMemoryDriver) driver;
554 679
					auxContainer = errorDriver.getMappedPositionContainer();
555 680
				}
556
			}else{
681
			} else {
557 682
				try {
558
					auxContainer = new MappedPositionContainerLayerBased(selectedLyr);
683
					auxContainer = new MappedPositionContainerLayerBased(
684
							selectedLyr);
559 685
				} catch (BaseException e) {
560 686
					e.printStackTrace();
561
					GUIUtil.getInstance().messageBox(PluginServices.getText(this, "Error_cargando_links"),
562
								PluginServices.getText(this, "Error_cargando_links"));
687
					GUIUtil.getInstance().messageBox(
688
							PluginServices
689
									.getText(this, "Error_cargando_links"),
690
							PluginServices
691
									.getText(this, "Error_cargando_links"));
563 692
					return;
564 693
				}
565 694
			}
566 695
			boolean overwriteCurrentLinks = true;
567
			if(this.verrorContainer.getCount() > 0){
568
				overwriteCurrentLinks = GUIUtil.getInstance().
569
					optionMessage(PluginServices.getText(this, "overwrite_current_vector_error"), PluginServices.getText(this, "spatial_adjust_warning"));
570
				
696
			if (this.verrorContainer.getCount() > 0) {
697
				overwriteCurrentLinks = GUIUtil.getInstance().optionMessage(
698
						PluginServices.getText(this,
699
								"overwrite_current_vector_error"),
700
						PluginServices.getText(this, "spatial_adjust_warning"));
701

  
571 702
			}
572
			if(overwriteCurrentLinks){
703
			if (overwriteCurrentLinks) {
573 704
				this.verrorContainer = auxContainer;
574
				actualizar tambien la referencia en ReferencePanel y en el VectorialListener
575 705
				updateVErrorTable();
706
				String folderName = PluginServices.getText(this,
707
										"SPATIAL_ADJUST_SESSION")
708
												+ " "
709
												+ ReferencingUtil.getInstance()
710
												.getNumberOfSpatialAdjustSessions();
711
				FLayers rootLyrs = currentView.getMapContext().getLayers();
712
				FLayers adjustSessionLyrs = (FLayers) rootLyrs.getLayer(folderName);
713
				if(adjustSessionLyrs == null){
714
					adjustSessionLyrs = new FLayers();
715
					adjustSessionLyrs.setMapContext(currentView.getMapContext());
716
					adjustSessionLyrs.setParentLayer(rootLyrs);
717
					adjustSessionLyrs.setName(folderName);
718
					rootLyrs.addLayer(adjustSessionLyrs);
719
				}//if
720
				rootLyrs.removeLayer(selectedLyr);
721
				adjustSessionLyrs.addLayer(selectedLyr);
722
				
723
				
576 724
			}
577
		}
578
			
579
	
580
	
581
}
582
	
583
	
725
		}//if ok pressed
726
	}
584 727

  
585 728
	public TransformationRegistryEntry getTransformBuilderProvider() {
586 729
		return transformBuilderProvider;
587 730
	}
588 731

  
589 732
	public void setTransformBuilderProvider(
590
			TransformationRegistryEntry transformBuilderProvider) throws FactoryException {
733
			TransformationRegistryEntry transformBuilderProvider)
734
			throws FactoryException {
591 735
		this.transformBuilderProvider = transformBuilderProvider;
592
		this.mathTransform = transformBuilderProvider.createTransformBuilder(verrorContainer.getAsList()).getMathTransform();
736
		this.mathTransform = transformBuilderProvider.createTransformBuilder(
737
				verrorContainer.getAsList()).getMathTransform();
593 738
		updateVErrorTable();
594 739
		updateRmsText();
595 740
	}
......
602 747
		this.verrorContainer = verrorContainer;
603 748
	}
604 749

  
750
	public FLyrVect getAdjustingLyr() {
751
		return adjustingLyr;
752
	}
753

  
754
	public void setAdjustingLyr(FLyrVect adjustingLyr) {
755
		this.adjustingLyr = adjustingLyr;
756
		if(vb != null)
757
			vb.setSnappingLyr(adjustingLyr);
758
	}
759

  
605 760
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/referencing/ReferencingGeoprocessController.java
144 144
			return false;
145 145
		}
146 146
		
147
		boolean hasAuxiliarLyrs = userEntries.hasAuxiliarLyrs();
148
		params.put("hasAuxiliar", new Boolean(hasAuxiliarLyrs));
149
		if(hasAuxiliarLyrs){
150
			params.put("auxiliarLyrs", userEntries.getAuxiliarLyrs());
151
		}
152
		
147 153
/*
148 154
 * MOVER A CLASE ABSTRACTA 
149 155
 * */		
trunk/extensions/extTopology/src/org/gvsig/fmap/tools/behavior/VectorBehavior.java
59 59
import java.awt.geom.Point2D;
60 60
import java.awt.geom.Rectangle2D;
61 61
import java.awt.image.BufferedImage;
62
import java.util.List;
62 63

  
63 64
import org.gvsig.fmap.core.FGeometryUtil;
65
import org.gvsig.fmap.core.ShapePointExtractor;
64 66
import org.gvsig.fmap.tools.listeners.VectorListener;
65 67

  
68
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
69
import com.iver.andami.PluginServices;
66 70
import com.iver.cit.gvsig.fmap.ViewPort;
67 71
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
68 72
import com.iver.cit.gvsig.fmap.core.FShape;
69 73
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
74
import com.iver.cit.gvsig.fmap.core.IFeature;
75
import com.iver.cit.gvsig.fmap.core.IGeometry;
76
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
77
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
70 78
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
71 79
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
72 80
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent;
73 81
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener;
82
import com.iver.cit.gvsig.project.documents.view.snapping.SnappingVisitor;
83
import com.iver.cit.gvsig.project.documents.view.snapping.snappers.NearestPointSnapper;
74 84

  
75 85
/**
76 86
 * Behavior to digitize two points vectors in mapcontrol
77 87
 * @author azabala
78 88
 */
79 89
public class VectorBehavior extends Behavior {
90

  
91
	NearestPointSnapper snapper = new NearestPointSnapper();
92
	PointSnapper pointSnapper = new PointSnapper();
93
	
94
	FLyrVect snappingLyr = null;
95
	
96
	
97
	private boolean isZooming = false;
80 98
	private Point2D m_FirstPoint;
81 99
	private Point2D m_LastPoint;
82 100
	private VectorListener listener;
......
90 108
			BufferedImage.TYPE_INT_ARGB);
91 109
	protected static Rectangle rect = new Rectangle(0, 0, 1, 1);
92 110

  
111
	
112
	class PointSnapper extends NearestPointSnapper {
93 113

  
114
		public Point2D getSnapPoint(Point2D queryPoint, IGeometry geomToSnap,
115
				double tolerance, Point2D lastPointEntered) {
116
			
117
			Point2D solution = null;
118
			double minDistance = tolerance;
119
			
120
			List<Point2D[]> pointsParts =
121
				ShapePointExtractor.extractPoints(geomToSnap);
122
			for(int i = 0; i < pointsParts.size(); i++){
123
				Point2D[] points = pointsParts.get(i);
124
				for(int j = 0; j < points.length; j++){
125
					Point2D point = points[j];
126
					double dist = point.distance(queryPoint);
127
					if(dist <= minDistance){
128
						solution = point;
129
						minDistance = dist;
130
					}//if
131
				}//for j
132
			}//for i
133
			return solution;
134
		}
94 135

  
136
		public String getToolTipText() {
137
			return PluginServices.getText(this, "nearest_point_for_point_layers");
138
		}
139
		
140
	}
141

  
95 142
	
96 143
	/**
97 144
	 * Crea un nuevo RectangleBehavior.
98 145
	 *
99 146
	 * @param zili listener.
100 147
	 */
101
	public VectorBehavior(VectorListener zili) {
148
	public VectorBehavior(VectorListener zili, FLyrVect snappingLyr) {
102 149
		listener = zili;
103
		
150
		this.snappingLyr = snappingLyr;
104 151
		Graphics2D g2 = img.createGraphics();
105 152
		drawInsideRectangle(g2, g2.getTransform(), rect);
106 153
		rgb = img.getRGB(0, 0);
......
142 189
		
143 190

  
144 191
		// Dibujamos el actual
145
		if ((m_FirstPoint != null) && (m_LastPoint != null)) {
192
		if ((m_FirstPoint != null) && (m_LastPoint != null) && !isZooming) {
146 193
			GeneralPathX line = new GeneralPathX();			
147 194
			line.moveTo(m_FirstPoint.getX(), m_FirstPoint.getY());
148 195
			line.lineTo(m_LastPoint.getX(), m_LastPoint.getY());
......
158 205
	 * @param e MouseEvent
159 206
	 */
160 207
	public void mousePressed(MouseEvent e) {
161
//		if (e.getButton() == MouseEvent.BUTTON1) {
208

  
209
			int modifiers = e.getModifiersEx();
210
			int ctrlDownMask = modifiers & MouseEvent.CTRL_DOWN_MASK;
211
			if(ctrlDownMask == MouseEvent.CTRL_DOWN_MASK ){
212
				isZooming = true;
213
			}
162 214
			m_FirstPoint = e.getPoint();
163 215
			getMapControl().repaint();
164
//		}
165
		if (listener.cancelDrawing()) {
166
			getMapControl().cancelDrawing();
167
			getMapControl().repaint();
168
		}
216

  
217
			if (listener.cancelDrawing()) {
218
				getMapControl().cancelDrawing();
219
				getMapControl().repaint();
220
			}
169 221
	}
222
	
223
	
224
	
225
		
226
	
170 227

  
171 228
	/**
172 229
	 * Reimplementaci?n del m?todo mouseReleased de Behavior.
......
176 233
	 * @throws BehaviorException Excepci?n lanzada cuando el Behavior.
177 234
	 */
178 235
	public void mouseReleased(MouseEvent e) throws BehaviorException {
179
	    if (m_FirstPoint == null) return;
236
	    if (m_FirstPoint == null) {
237
	    	isZooming = false;
238
	    	return;
239
	    }
180 240
		Point2D p1;
181 241
		Point2D p2;
182 242
		Point pScreen = e.getPoint();
183 243

  
184 244
		ViewPort vp = getMapControl().getMapContext().getViewPort();
245
		p1 = vp.toMapPoint(m_FirstPoint);
246
		
247
		
248
		//we snap to the nearest point of the adjusting layer
249
		int pixelTolerance = 8;
250
		double mapTolerance = vp.toMapDistance(pixelTolerance);
251
		
252
		double minDist = mapTolerance;
253
		Rectangle2D r = new Rectangle2D.Double(p1.getX() - mapTolerance / 2,
254
				p1.getY() - mapTolerance / 2, mapTolerance, mapTolerance);
185 255

  
186
		p1 = vp.toMapPoint(m_FirstPoint);
256
		if (snappingLyr.isVisible()){
257
			try {
258
				IFeatureIterator iterator = snappingLyr.getSource().getFeatureIterator(r, null, null, false);
259
				SnappingVisitor snapVisitor = 
260
					new SnappingVisitor(snapper, p1, mapTolerance, null);
261
				SnappingVisitor snapVisitor2 = 
262
					new SnappingVisitor(pointSnapper, p1, mapTolerance, null);
263
				
264
				while(iterator.hasNext()){
265
					IFeature feature = iterator.next();
266
					IGeometry geo = feature.getGeometry();
267
					snapVisitor.visitItem(geo);
268
					snapVisitor2.visitItem(geo);
269
				}
270
				Point2D theSnappedPoint = snapVisitor.getSnapPoint();
271
				if(theSnappedPoint == null)
272
					theSnappedPoint = snapVisitor2.getSnapPoint();
273
				
274
				if (theSnappedPoint != null) {
275
					p1.setLocation(theSnappedPoint);
276
				}
277
			} catch (ReadDriverException e1) {
278
				e1.printStackTrace();
279
				throw new BehaviorException("Error de driver intentando aplicar snap", e1);
280
			}
281
		}//isVisible
282
				
283
				
187 284
		p2 = vp.toMapPoint(pScreen);
285
//		Rectangle2D.Double rectangle = new Rectangle2D.Double();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff