Revision 21293

View differences:

trunk/extensions/extTopology/src/org/gvsig/topology/RegisterGeoprocessesExtension.java
50 50

  
51 51
import com.iver.andami.PluginServices;
52 52
import com.iver.andami.plugins.Extension;
53
import com.iver.cit.gvsig.geoprocess.impl.fliplines.FlipLinesGeoprocessPlugin;
53 54
import com.iver.cit.gvsig.geoprocess.impl.generalization.GeneralizationGeoprocessPlugin;
54 55
import com.iver.cit.gvsig.geoprocess.impl.snapandcrack.SnapAndCrackGeoprocessPlugin;
55 56
import com.iver.cit.gvsig.geoprocess.impl.voronoi.VoronoiGeoprocessPlugin;
......
71 72
		extensionPoints.add("GeoprocessManager",
72 73
				"GENERALIZATION", 
73 74
				GeneralizationGeoprocessPlugin.class);
75
		
76
		extensionPoints.add("GeoprocessManager",
77
				"FLIPLINES", 
78
				FlipLinesGeoprocessPlugin.class);
74 79
		registerIcons();
75 80
	}
76 81
	
......
89 94
				SnapAndCrackGeoprocessPlugin.class.getResource("resources/crackdesc.png")
90 95
			);
91 96
		
97
		PluginServices.getIconTheme().registerDefault(
98
				"fliplines-icon",
99
				FlipLinesGeoprocessPlugin.class.getResource("resources/flipline_desc.png")
100
			);
101
		
102
		
103
		
92 104
	}
93 105
	
94 106
	public void execute(String actionCommand) {
trunk/extensions/extTopology/src/com/iver/cit/gvsig/cad/SmoothPolylinesExtension.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.cad;
50

  
51
import org.gvsig.fmap.core.FGeometryUtil;
52
import org.gvsig.jts.JtsUtil;
53
import org.gvsig.topology.ui.util.GUIUtil;
54

  
55
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
56
import com.iver.andami.PluginServices;
57
import com.iver.andami.messages.NotificationManager;
58
import com.iver.andami.plugins.Extension;
59
import com.iver.cit.gvsig.CADExtension;
60
import com.iver.cit.gvsig.EditionUtilities;
61
import com.iver.cit.gvsig.drivers.featureiterators.FeatureBitsetIterator;
62
import com.iver.cit.gvsig.fmap.core.IFeature;
63
import com.iver.cit.gvsig.fmap.core.IGeometry;
64
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
65
import com.iver.cit.gvsig.project.documents.view.gui.View;
66
import com.vividsolutions.jts.geom.Geometry;
67

  
68
/**
69
 * This extension only will active when active layer
70
 * is a linear (dimension = 1) vectorial layer with
71
 * selected lines.
72
 * 
73
 * It smooths the selected lines.
74
 * 
75
 * @author Alvaro Zabala
76
 *
77
 */
78
public class SmoothPolylinesExtension extends Extension {
79

  
80
	private View view;
81
	
82
	public void execute(String actionCommand) {
83
		
84
		try {
85
			FLyrVect lv = (FLyrVect) CADExtension.
86
								getEditionManager().
87
								getActiveLayerEdited().
88
								getLayer();
89
			int geometryDimensions = FGeometryUtil.getDimensions(lv.getShapeType());
90
			
91
			FeatureBitsetIterator iterator = new FeatureBitsetIterator(lv.getSource());
92
			while(iterator.hasNext()){
93
				IFeature feature = iterator.next();
94
				IGeometry geometry = feature.getGeometry();
95
				Geometry jtsGeometry = geometry.toJTSGeometry();
96
				Geometry generalizedGeometry = null;
97
				if(geometryDimensions == 1)
98
					generalizedGeometry = JtsUtil.douglasPeuckerSimplify(jtsGeometry, JtsUtil.GENERALIZATION_FACTOR.doubleValue());
99
				else 
100
					generalizedGeometry = JtsUtil.topologyPreservingSimplify(jtsGeometry, JtsUtil.GENERALIZATION_FACTOR.doubleValue());
101
				
102
			}
103
			
104
			
105
			
106
//			  IGeometry geom1=ShapeFactory.createPolyline2D(newGp1);
107
//	             IGeometry geom2=ShapeFactory.createPolyline2D(newGp2);
108
//
109
//	             DefaultFeature dfLine1 = (DefaultFeature) dre.getLinkedRow().cloneRow();
110
//	             dfLine1.setGeometry(geom1);
111
//	    int indexLine1 = addGeometry(geom1, dfLine1
112
//	      .getAttributes());
113
//
114
//	    selectedRowAux.add(new DefaultRowEdited(dfLine1,
115
//	      IRowEdited.STATUS_ADDED, indexLine1));
116
//
117
//	    DefaultFeature dfLine2 = (DefaultFeature) dre.getLinkedRow().cloneRow();
118
//	          dfLine2.setGeometry(geom2);
119
//	    int indexLine2 = addGeometry(geom2, dfLine2
120
//	       .getAttributes());
121
//
122
//	    selectedRowAux.add(new DefaultRowEdited(dfLine2,
123
//	       IRowEdited.STATUS_ADDED, indexLine2));
124
//			 vea.removeRow(dre.getIndex(), getName(), EditionEvent.GRAPHIC);
125
//		     vea.endComplexRow(getName());
126
//		   vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, selectedRowAux);
127
			
128
		} catch (ReadDriverException e) {
129
			String title = PluginServices.getText(this, "Error_De_Acceso_Datos");
130
			String msg = PluginServices.getText(this, "Error_accediendo_a_los_datos");
131
			GUIUtil.getInstance().messageBox(msg, title);
132
			e.printStackTrace();
133
		}
134
	}
135

  
136
	public void initialize() {
137
		registerIcons();
138
	}
139
	
140
	private void registerIcons(){
141
		PluginServices.getIconTheme().registerDefault("smooth-geometry",
142
													   this.getClass().
143
													   getClassLoader().
144
													   getResource("images/smooth-geometry.gif")
145
		);
146
	}
147

  
148
	/**
149
	 * Returns if this Edit CAD tool is visible. 
150
	 * For this, there must be an active vectorial editing lyr in the TOC, which geometries'
151
	 * dimension would must be linear or polygonal, and with at least one selected geometry.
152
	 *  
153
	 */
154
	public boolean isEnabled() {
155
		try {
156
			if (EditionUtilities.getEditionStatus() == 
157
				EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
158
					this.view = (View) PluginServices.getMDIManager().getActiveWindow();
159
					if (CADExtension.getEditionManager().getActiveLayerEdited() == null)
160
						return false;
161
					FLyrVect lv = (FLyrVect) CADExtension.
162
											getEditionManager().
163
											getActiveLayerEdited().
164
											getLayer();
165
					int geometryDimensions = FGeometryUtil.getDimensions(lv.getShapeType());
166
					if(geometryDimensions <= 0)
167
						return false;
168
					
169
					return lv.getRecordset().getSelection().cardinality() != 0;
170
			}
171
		} catch (ReadDriverException e) {
172
			NotificationManager.addError(e.getMessage(),e);
173
			return false;
174
		}
175
		return true;
176
	}
177

  
178
	public boolean isVisible() {
179
		if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
180
			return true;
181
		return false;
182
	}
183
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/cad/SplitGeometryCADTool.java
50 50

  
51 51
import java.awt.Graphics;
52 52
import java.awt.Graphics2D;
53
import java.awt.Image;
54 53
import java.awt.event.InputEvent;
55 54
import java.awt.event.MouseEvent;
56 55
import java.awt.geom.Point2D;
......
66 65
import com.iver.cit.gvsig.cad.sm.SplitGeometryCADToolContext;
67 66
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
68 67
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException;
69
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException;
70 68
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
71 69
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
72 70
import com.iver.cit.gvsig.fmap.core.IFeature;
......
77 75
import com.iver.cit.gvsig.fmap.edition.EditionEvent;
78 76
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
79 77
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
80
import com.iver.cit.gvsig.fmap.layers.FBitSet;
81 78
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
82 79
import com.iver.cit.gvsig.gui.cad.exception.CommandException;
83 80
import com.iver.cit.gvsig.layers.VectorialLayerEdited;
......
154 151
	}
155 152
	
156 153
	public ArrayList getSelectedRows(){
157
		ArrayList selection = super.getSelectedRows();
158
		if(selection != null ){
159
			if( selection.size() == 0){
160
				VectorialEditableAdapter vea = getVLE().getVEA();
161
				try {
162
					FBitSet bitset = vea.getSelection();
163
					for (int j = bitset.nextSetBit(0);j >= 0;j = bitset.nextSetBit(j + 1)){
164
						IRowEdited rowEd =vea.getRow(j);
165
						selection.add(rowEd);
166
					}
167
				} catch (ExpansionFileReadException e) {
168
					e.printStackTrace();
169
				} catch (ReadDriverException e) {
170
					e.printStackTrace();
171
				}
172
			}//selection size
173
		}
174
		return selection;
154
		return (ArrayList) CADUtil.getSelectedFeatures(getVLE());
175 155
	}
176 156
	
177 157
	public void splitSelectedGeometryWithDigitizedLine(){
......
187 167
		IRowEdited editedRow = null;
188 168
		VectorialLayerEdited vle = getVLE();
189 169
		VectorialEditableAdapter vea = vle.getVEA();
190
//		vea.startComplexRow();
170
		vea.startComplexRow();
191 171
		for (int i = 0; i < selectedRows.size(); i++) {
192 172
			editedRow = (IRowEdited) selectedRows.get(i);
193 173
			IFeature feat = (IFeature) editedRow.getLinkedRow().cloneRow();
......
205 185
					GeometryCollection gc = (GeometryCollection)splittedGeo;
206 186
					for(int j = 0; j < gc.getNumGeometries(); j++){
207 187
						Geometry g = gc.getGeometryN(j);
208
						System.out.println("g"+j+":"+g.toText());
209 188
						IGeometry fmapGeo = FConverter.jts_to_igeometry(g);
210
						DefaultFeature newFeature = new DefaultFeature(fmapGeo, feat.getAttributes(), vea.getNewFID());
211
						int calculatedIndex = vea.addRow(newFeature, getName(), EditionEvent.GRAPHIC);
189
						String newFID = vea.getNewFID();
190
						DefaultFeature df = new DefaultFeature(fmapGeo, feat.getAttributes(), newFID);
191
						int newIdx = CADUtil.addFeature(vle, df, getName());
212 192
						
213
						DefaultRowEdited newRowEdited = new DefaultRowEdited(newFeature,
214
														IRowEdited.STATUS_ADDED, 
215
															calculatedIndex);
193
						DefaultRowEdited newRowEdited = new DefaultRowEdited(df,
194
									IRowEdited.STATUS_ADDED, 
195
										newIdx);
216 196
						splittedSelectionGeoms.add(newRowEdited);
217 197
					}//for j
218 198
				} catch (ExpansionFileReadException e) {
......
221 201
					e.printStackTrace();
222 202
				} catch (ReadDriverException e) {
223 203
					e.printStackTrace();
224
				} catch (ValidateRowException e) {
225
					e.printStackTrace();
226 204
				}
227 205
			}//if splittedGeo
228 206
		}
229
//		vea.endComplexRow(description);
230
//		vle.setSelectionCache(VectorialLayerEdited.SAVEPREVIOUS,
231
//				splittedSelectionGeoms);
207
		vea.endComplexRow(getName());
208
		vle.setSelectionCache(VectorialLayerEdited.SAVEPREVIOUS,
209
									splittedSelectionGeoms);
232 210
	}
233 211
		
234 212
	public void end(){
trunk/extensions/extTopology/src/com/iver/cit/gvsig/cad/CADUtil.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.cad;
50

  
51
import java.awt.geom.Rectangle2D;
52
import java.util.ArrayList;
53
import java.util.List;
54

  
55
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
56
import com.iver.andami.messages.NotificationManager;
57
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
58
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException;
59
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException;
60
import com.iver.cit.gvsig.fmap.core.FShape;
61
import com.iver.cit.gvsig.fmap.core.IFeature;
62
import com.iver.cit.gvsig.fmap.core.IGeometry;
63
import com.iver.cit.gvsig.fmap.edition.EditionEvent;
64
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
65
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
66
import com.iver.cit.gvsig.fmap.layers.FBitSet;
67
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
68
import com.iver.cit.gvsig.fmap.layers.SpatialCache;
69
import com.iver.cit.gvsig.layers.VectorialLayerEdited;
70
/**
71
 * Utility methods to work with CAD extension
72
 * 
73
 * @author Alvaro Zabala
74
 *
75
 */
76
public class CADUtil {
77
	
78
	/**
79
	 * Adds a new feature to a vectorial layer edited
80
	 * 
81
	 * @param vle vectorial layer to add the new feature
82
	 * @param geometry new feature's geometry
83
	 * @param transactionDesc description of the transaction
84
	 * @param values new feature's attributes
85
	 * 
86
	 * @return index of the new feature in the layer
87
	 */
88
	public static int addFeature(VectorialLayerEdited vle,
89
						   		  IFeature newFeature,
90
						   		  String transactionDesc) {
91
		int index = 0;
92
		VectorialEditableAdapter vea = vle.getVEA();
93
		try {
94
			
95
			index = vea.addRow(newFeature, transactionDesc, EditionEvent.GRAPHIC);
96
			SpatialCache spatialCache=((FLyrVect)vle.getLayer()).getSpatialCache();
97
			IGeometry geometry = newFeature.getGeometry();
98
			Rectangle2D r = geometry.getBounds2D();
99
			if (geometry.getGeometryType() == FShape.POINT) {
100
				r = new Rectangle2D.Double(r.getX(),r.getY(),1,1);
101
			}
102
			spatialCache.insert(r,geometry);
103
		} catch (ValidateRowException e) {
104
			NotificationManager.addError(e);
105
		} catch (ReadDriverException e) {
106
			NotificationManager.addError(e);
107
		}
108
		return vea.getInversedIndex(index);
109
	}
110
	
111
	public static void modifyFeature(VectorialLayerEdited vle, 
112
							  				 int index, 
113
							    String descTransaction, 
114
							    		IFeature row) {
115
		try {
116
			vle.getVEA().modifyRow(index, row, descTransaction,
117
					EditionEvent.GRAPHIC);
118
		} catch (ValidateRowException e) {
119
			NotificationManager.addError(e.getMessage(),e);
120
		} catch (ExpansionFileWriteException e) {
121
			NotificationManager.addError(e.getMessage(),e);
122
		} catch (ReadDriverException e) {
123
			NotificationManager.addError(e.getMessage(),e);
124
		}
125
//		draw(row.getGeometry().cloneGeometry());
126
	}
127
	
128
	/**
129
	 * Returns the selected features in a VectorialLayerEdited.
130
	 * If the selection is previous to the edition beginning, it fills
131
	 * selected row's list
132
	 * @param vle
133
	 * @return
134
	 */
135
	public static List getSelectedFeatures(VectorialLayerEdited vle){
136
		ArrayList selection = vle.getSelectedRow();
137
		if( selection.size() == 0){
138
			VectorialEditableAdapter vea = vle.getVEA();
139
			try {
140
				FBitSet bitset = vea.getSelection();
141
				for (int j = bitset.nextSetBit(0);j >= 0;j = bitset.nextSetBit(j + 1)){
142
					IRowEdited rowEd = vea.getRow(j);
143
					selection.add(rowEd);
144
				}
145
			} catch (ExpansionFileReadException e) {
146
				e.printStackTrace();
147
			} catch (ReadDriverException e) {
148
				e.printStackTrace();
149
			}
150
		}//selection size
151
		return selection;
152
	}
153
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/cad/SimplifyGeometry.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.cad;
50

  
51
import java.util.ArrayList;
52

  
53
import org.gvsig.fmap.core.FGeometryUtil;
54
import org.gvsig.fmap.core.NewFConverter;
55
import org.gvsig.jts.JtsUtil;
56
import org.gvsig.topology.ui.util.GUIUtil;
57

  
58
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
59
import com.iver.andami.PluginServices;
60
import com.iver.andami.messages.NotificationManager;
61
import com.iver.andami.plugins.Extension;
62
import com.iver.cit.gvsig.CADExtension;
63
import com.iver.cit.gvsig.EditionUtilities;
64
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
65
import com.iver.cit.gvsig.fmap.core.IFeature;
66
import com.iver.cit.gvsig.fmap.core.IGeometry;
67
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited;
68
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
69
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
70
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
71
import com.iver.cit.gvsig.layers.VectorialLayerEdited;
72
import com.vividsolutions.jts.geom.Geometry;
73

  
74
/**
75
 * This extension only will active when active layer
76
 * is a linear (dimension = 1) vectorial layer with
77
 * selected lines.
78
 * 
79
 * It smooths the selected lines.
80
 * 
81
 * @author Alvaro Zabala
82
 *
83
 */
84
public class SimplifyGeometry extends Extension {
85
	
86
	public void execute(String actionCommand) {
87
		
88
		try {
89
			FLyrVect lv = (FLyrVect) CADExtension.
90
								getEditionManager().
91
								getActiveLayerEdited().
92
								getLayer();
93
			
94
			int geometryDimensions = FGeometryUtil.getDimensions(lv.getShapeType());
95
			
96
			VectorialLayerEdited vle =
97
				(VectorialLayerEdited) CADExtension.getEditionManager().getActiveLayerEdited();
98
	         VectorialEditableAdapter vea = vle.getVEA();
99
	         
100
	         //FIXME Si el editable adapter coge las selecciones echas antes de entrar en edicion
101
	         ArrayList selectedRow = (ArrayList) CADUtil.getSelectedFeatures(vle);
102
	         ArrayList selectedRowAux = new ArrayList();
103
	         vea.startComplexRow();
104
	         
105
	         for(int i = 0; i < selectedRow.size(); i++){
106
	        	 IRowEdited rowEd = (IRowEdited) selectedRow.get(i);
107
	        	 IFeature feature = (IFeature) rowEd.getLinkedRow();
108
	        	 IGeometry geometry = feature.getGeometry();
109
				 Geometry jtsGeometry = geometry.toJTSGeometry();
110
				 Geometry generalizedGeometry = null;
111
				 if(geometryDimensions == 1)
112
					generalizedGeometry = JtsUtil.douglasPeuckerSimplify(jtsGeometry, JtsUtil.GENERALIZATION_FACTOR.doubleValue());
113
				 else 
114
					generalizedGeometry = JtsUtil.topologyPreservingSimplify(jtsGeometry, JtsUtil.GENERALIZATION_FACTOR.doubleValue());
115
				 
116
				 IGeometry newGeometry = NewFConverter.toFMap(generalizedGeometry);
117
				 
118
				 DefaultFeature modifiedFeature = (DefaultFeature) feature.cloneRow();
119
				 modifiedFeature.setGeometry(newGeometry);
120
				 
121
				 CADUtil.modifyFeature(vle, rowEd.getIndex(), "SIMPLIFY_GEOMETRY", modifiedFeature);
122
				 
123
				 selectedRowAux.add(new DefaultRowEdited(modifiedFeature, 
124
						 					  IRowEdited.STATUS_MODIFIED, 
125
						 					  rowEd.getIndex()));
126
				 
127
	         }//for
128
		     vea.endComplexRow("SIMPLIFY_GEOMETRY");
129
		     vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, selectedRowAux);
130
			
131
		} catch (ReadDriverException e) {
132
			String title = PluginServices.getText(this, "Error_De_Acceso_Datos");
133
			String msg = PluginServices.getText(this, "Error_accediendo_a_los_datos");
134
			GUIUtil.getInstance().messageBox(msg, title);
135
			e.printStackTrace();
136
		}
137
	}
138

  
139
	public void initialize() {
140
		registerIcons();
141
	}
142
	
143
	private void registerIcons(){
144
		PluginServices.getIconTheme().registerDefault("smooth-geometry",
145
													   this.getClass().
146
													   getClassLoader().
147
													   getResource("images/smooth-geometry.gif")
148
		);
149
	}
150

  
151
	/**
152
	 * Returns if this Edit CAD tool is visible. 
153
	 * For this, there must be an active vectorial editing lyr in the TOC, which geometries'
154
	 * dimension would must be linear or polygonal, and with at least one selected geometry.
155
	 *  
156
	 */
157
	public boolean isEnabled() {
158
		try {
159
			if (EditionUtilities.getEditionStatus() == 
160
				EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
161
					if (CADExtension.getEditionManager().getActiveLayerEdited() == null)
162
						return false;
163
					FLyrVect lv = (FLyrVect) CADExtension.
164
											getEditionManager().
165
											getActiveLayerEdited().
166
											getLayer();
167
					int geometryDimensions = FGeometryUtil.getDimensions(lv.getShapeType());
168
					if(geometryDimensions <= 0)
169
						return false;
170
					
171
					return lv.getRecordset().getSelection().cardinality() != 0;
172
			}
173
		} catch (ReadDriverException e) {
174
			NotificationManager.addError(e.getMessage(),e);
175
			return false;
176
		}
177
		return true;
178
	}
179

  
180
	public boolean isVisible() {
181
		if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
182
			return true;
183
		return false;
184
	}
185
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/snapandcrack/fmap/SnapAndCrackGeoprocess.java
70 70
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
71 71
import com.iver.cit.gvsig.fmap.layers.FLayer;
72 72
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
73
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
74
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
75 73
import com.iver.cit.gvsig.geoprocess.GenericGeoprocessTask;
76 74
import com.iver.cit.gvsig.geoprocess.core.AbstractMonitorableGeoprocess;
77 75
import com.iver.cit.gvsig.geoprocess.core.fmap.DefinitionUtils;
......
143 141
		}
144 142
	}
145 143

  
146
	public void process() throws GeoprocessException {
147
		try {
148
			createTask().run();
149
		} catch (Exception e) {
150
			throw new GeoprocessException("Error al ejecutar la tarea", e);
151
		}
152 144

  
153
	}
154

  
155 145
	public void setParameters(Map params) throws GeoprocessException {
156 146
		Double snapTol = (Double) params.get("snap_tolerance");
157 147
		if (snapTol != null) {
......
164 154
		}
165 155
	}
166 156

  
167
	public IMonitorableTask createTask() {
168
		return new GenericGeoprocessTask(this);
169
	}
170 157

  
171
	
172 158
	public void process(CancellableProgressTask progressMonitor) throws GeoprocessException {
173 159
		if (progressMonitor != null) {
174 160
			initialize(progressMonitor);
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/voronoi/fmap/VoronoiGeoprocess.java
104 104
		fields[1].setFieldLength(10);
105 105
		fields[1].setFieldDecimalCount(4);
106 106
		fields[1].setFieldName(PluginServices.getText(this, "punto_causante"));
107
		fields[1].setFieldType(XTypes.DOUBLE);
107
		fields[1].setFieldType(XTypes.BIGINT);
108 108

  
109 109
		resultLayerDefinition.setFieldsDesc(fields);
110 110
		return resultLayerDefinition;
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/fliplines/FlipLinesGeoprocessPlugin.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.geoprocess.impl.fliplines;
50

  
51
import java.net.URL;
52

  
53
import com.iver.andami.PluginServices;
54
import com.iver.cit.gvsig.fmap.layers.FLayers;
55
import com.iver.cit.gvsig.geoprocess.core.GeoprocessPluginAbstract;
56
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessController;
57
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessPlugin;
58
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessUserEntries;
59
import com.iver.cit.gvsig.geoprocess.impl.fliplines.gui.FlipLinesGeoprocessPanel;
60
import com.iver.cit.gvsig.geoprocess.impl.generalization.gui.GeneralizationGeoprocessPanel;
61
import com.iver.cit.gvsig.project.documents.view.gui.View;
62

  
63
public class FlipLinesGeoprocessPlugin extends GeoprocessPluginAbstract  implements IGeoprocessPlugin {
64

  
65
	private static String dataConvertPkg;
66
	private static String geoprocessName;
67
	
68
	static{
69
		dataConvertPkg = 
70
			PluginServices.getText(null, "Conversion_de_datos");
71
		geoprocessName =
72
			PluginServices.getText(null, "Flip_Lines");
73
	}
74
	
75
	
76
	
77
	
78
	public IGeoprocessUserEntries getGeoprocessPanel() {
79
		com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow();
80
		View vista = (View) view;
81
		FLayers layers = vista.getModel().getMapContext().getLayers();
82
		return  new FlipLinesGeoprocessPanel(layers);
83
	}
84

  
85
	public URL getImgDescription() {
86
		URL url = PluginServices.getIconTheme().getURL("fliplines-icon");
87
		return url;
88
	}
89

  
90
	public IGeoprocessController getGpController() {
91
		return new FlipLinesGeoprocessController();
92
	}
93

  
94
	
95
	public String getNamespace() {
96
		return dataConvertPkg + "/" + geoprocessName;
97
	}
98
	
99
	public String toString(){
100
		return geoprocessName;
101
	}
102

  
103
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/fliplines/IFlipLinesGeoprocessUserEntries.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.geoprocess.impl.fliplines;
50

  
51
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessUserEntries;
52

  
53
public interface IFlipLinesGeoprocessUserEntries extends IGeoprocessUserEntries {
54
	public boolean onlyFirstLayerSelected();
55

  
56
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/fliplines/FlipLinesGeoprocessController.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.geoprocess.impl.fliplines;
50

  
51
import java.io.File;
52
import java.io.FileNotFoundException;
53
import java.util.HashMap;
54

  
55
import com.iver.andami.PluginServices;
56
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
57
import com.iver.cit.gvsig.fmap.edition.IWriter;
58
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
59
import com.iver.cit.gvsig.fmap.layers.FLayers;
60
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
61
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
62
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
63
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
64
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
65
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessUserEntries;
66
import com.iver.cit.gvsig.geoprocess.impl.fliplines.fmap.FlipLinesGeoprocess;
67
import com.iver.utiles.swing.threads.IMonitorableTask;
68
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
69

  
70
public class FlipLinesGeoprocessController extends AbstractGeoprocessController {
71

  
72
	private IFlipLinesGeoprocessUserEntries userEntries;
73
	private FlipLinesGeoprocess geoprocess;
74

  
75
	public void setView(IGeoprocessUserEntries viewPanel) {
76
		this.userEntries =  (IFlipLinesGeoprocessUserEntries) viewPanel;
77
	}
78

  
79
	public IGeoprocess getGeoprocess() {
80
		return geoprocess;
81
	}
82

  
83
	public boolean launchGeoprocess() {
84
/*MOVER A CLASE ABSTRACTA*/		
85
		final FLyrVect inputLayer = userEntries.getInputLayer();
86
		FLayers layers = userEntries.getFLayers();
87
		File outputFile = null;
88
		try {
89
			outputFile = userEntries.getOutputFile();
90
		} catch (FileNotFoundException e3) {
91
			String error = PluginServices.getText(this, "Error_entrada_datos");
92
			String errorDescription = PluginServices.getText(this,
93
					"Error_seleccionar_resultado");
94
			userEntries.error(errorDescription, error);
95
			return false;
96
		}
97
		if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
98
			String error = PluginServices.getText(this, "Error_entrada_datos");
99
			String errorDescription = PluginServices.getText(this,
100
					"Error_seleccionar_resultado");
101
			userEntries.error(errorDescription, error);
102
			return false;
103
		}
104
		if (outputFile.exists()) {
105
			if (!userEntries.askForOverwriteOutputFile(outputFile)) {
106
				return false;
107
			}
108
		}
109
/*MOVER A CLASE ABSTRACTA*/		
110
		
111
		geoprocess = new FlipLinesGeoprocess(inputLayer);
112

  
113
/*MOVER A CLASE ABSTRACTA*/		
114
		SHPLayerDefinition definition = (SHPLayerDefinition) geoprocess
115
				.createLayerDefinition();
116
		definition.setFile(outputFile);
117
		ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile
118
				.getAbsolutePath());
119
		IWriter writer = null;
120
		try {
121
			writer = getShpWriter(definition);
122
		} catch (Exception e1) {
123
			String error = PluginServices.getText(this,
124
					"Error_escritura_resultados");
125
			String errorDescription = PluginServices.getText(this,
126
					"Error_preparar_escritura_resultados");
127
			userEntries.error(errorDescription, error);
128
			return false;
129
		}
130
		geoprocess.setResultLayerProperties(writer, schemaManager);
131

  
132
/*MOVER A CLASE ABSTRACTA*/	
133
		
134
		HashMap params = new HashMap();
135
		
136
		boolean onlySelection = userEntries.onlyFirstLayerSelected();
137
		params.put("layer_selection", new Boolean(onlySelection));
138
		
139
/*
140
 * MOVER A CLASE ABSTRACTA 
141
 * */		
142
		try {
143
			geoprocess.setParameters(params);
144
			geoprocess.checkPreconditions();
145
			IMonitorableTask task1 = geoprocess.createTask();
146
			if (task1 == null) {
147
				return false;
148

  
149
			}
150
			AddResultLayerTask task2 = new AddResultLayerTask(geoprocess);
151
			task2.setLayers(layers);
152
			MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(
153
					task1, task2);
154
			if (globalTask.preprocess())
155
				PluginServices.cancelableBackgroundExecution(globalTask);
156

  
157
		} catch (GeoprocessException e) {
158
			String error = PluginServices.getText(this, "Error_ejecucion");
159
			String errorDescription = PluginServices.getText(this,
160
					"Error_fallo_geoproceso");
161
			userEntries.error(errorDescription, error);
162
			return false;
163
		}
164
		return true;
165
		/*
166
		 * MOVER A CLASE ABSTRACTA 
167
		 * */		
168
	}
169

  
170
	public int getWidth() {
171
		return 700;
172
	}
173

  
174
	public int getHeight() {
175
		return 600;
176
	}
177

  
178
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/fliplines/fmap/FlipLinesGeoprocess.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.geoprocess.impl.fliplines.fmap;
50

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

  
54
import org.apache.log4j.Logger;
55
import org.gvsig.exceptions.BaseException;
56
import org.gvsig.fmap.core.FGeometryUtil;
57
import org.gvsig.fmap.core.NewFConverter;
58
import org.gvsig.jts.JtsUtil;
59
import org.gvsig.topology.Messages;
60

  
61
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
62
import com.hardcode.gdbms.engine.values.Value;
63
import com.iver.cit.gvsig.drivers.featureiterators.FeatureBitsetIterator;
64
import com.iver.cit.gvsig.exceptions.visitors.StartVisitorException;
65
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException;
66
import com.iver.cit.gvsig.exceptions.visitors.StopVisitorException;
67
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
68
import com.iver.cit.gvsig.fmap.core.IFeature;
69
import com.iver.cit.gvsig.fmap.core.IGeometry;
70
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
71
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
72
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
73
import com.iver.cit.gvsig.fmap.layers.FBitSet;
74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
75
import com.iver.cit.gvsig.geoprocess.core.AbstractMonitorableGeoprocess;
76
import com.iver.cit.gvsig.geoprocess.core.fmap.DefinitionUtils;
77
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2;
78
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
79
import com.iver.utiles.swing.threads.CancellableProgressTask;
80
import com.vividsolutions.jts.geom.Geometry;
81
import com.vividsolutions.jts.geom.GeometryCollection;
82
import com.vividsolutions.jts.geom.LineString;
83

  
84
/**
85
 * Geoprocess to generalize linear or poligonal vectorial layers.
86
 * @author Alvaro Zabala
87
 *
88
 */
89
public class FlipLinesGeoprocess extends AbstractMonitorableGeoprocess {
90

  
91
	private static Logger logger = Logger.getLogger(FlipLinesGeoprocess.class
92
			.getName());
93
	
94
	private LayerDefinition resultLayerDefinition;
95
	
96
	
97
	
98
	public FlipLinesGeoprocess(FLyrVect inputLayer) {
99
		this.firstLayer = inputLayer;
100
	}
101

  
102
	public void checkPreconditions() throws GeoprocessException {
103
		int lyrDimensions;
104
		try {
105
			lyrDimensions = FGeometryUtil.getDimensions(firstLayer.getShapeType());
106
		
107
			if(lyrDimensions != 1)
108
				throw new GeoprocessException(
109
					"Geoproceso invertir lineas con capa que no es de lineas");
110
		
111
		} catch (ReadDriverException e) {
112
			throw new GeoprocessException("Error intentando acceder al tipo de geometria de capa vectorial");
113
		}
114

  
115
	}
116

  
117
	public ILayerDefinition createLayerDefinition() {
118
		if(resultLayerDefinition == null){
119
			try {
120
				resultLayerDefinition = DefinitionUtils
121
						.createLayerDefinition(firstLayer);
122
			} catch (Exception e) {
123
				logger.error(e);
124
			}
125
		}
126
		return resultLayerDefinition;
127
	}
128

  
129
	
130

  
131
	public void setParameters(Map params) throws GeoprocessException {
132
		Boolean onlySelection = (Boolean) params.get("layer_selection");
133
		if (onlySelection != null)
134
			this.operateOnlyWithSelection = onlySelection.booleanValue();
135
	}
136

  
137
	
138

  
139
	public void process(CancellableProgressTask progressMonitor)
140
			throws GeoprocessException {
141
		if (progressMonitor != null) {
142
			initialize(progressMonitor);
143
		}
144

  
145
		// Prepare the result
146
		try {
147
			writer.preProcess();
148
		} catch (StartWriterVisitorException e) {
149
			throw new GeoprocessException(e);
150
		}
151
		FeaturePersisterProcessor2 featureProcessor = new FeaturePersisterProcessor2(
152
				writer);
153
		try {
154
			featureProcessor.start();
155
		} catch (StartVisitorException e1) {
156
			throw new GeoprocessException(e1);
157
		}
158

  
159
		try {
160
			IFeatureIterator featureIterator = null;
161
			if(this.operateOnlyWithSelection){
162
				FBitSet selection = firstLayer.getRecordset().getSelection();
163
	        	featureIterator = new FeatureBitsetIterator(selection, firstLayer.getSource());
164
			}else{
165
				featureIterator = firstLayer.getSource().getFeatureIterator();
166
			}
167
			
168
			while(featureIterator.hasNext()){
169
				IFeature feature = featureIterator.next();
170
				IGeometry fmapGeo = feature.getGeometry();
171
				Value[] values = feature.getAttributes();
172
				Geometry geometry = JtsUtil.toJtsGeometry(fmapGeo);
173
				Geometry reversedGeometry = null;
174
				LineString[] lineStrings = JtsUtil.extractLineStrings(geometry);
175
				GeometryCollection gc = JtsUtil.GEOMETRY_FACTORY.createGeometryCollection(lineStrings);
176
				reversedGeometry = gc;
177
				if(progressMonitor != null)
178
					progressMonitor.reportStep();
179
				
180
				if(reversedGeometry != null){
181
					IGeometry simplifiedFMap = NewFConverter.toFMap(reversedGeometry);
182
					DefaultFeature newFeature = 
183
						new DefaultFeature(simplifiedFMap, 
184
													values, 
185
												new UID().toString());
186
					featureProcessor.processFeature(newFeature);
187
				}
188
			}
189
			featureProcessor.finish();
190
			if (progressMonitor != null) {
191
				progressMonitor.finished();
192
			}
193
		} catch (StopVisitorException e) {
194
			throw new GeoprocessException(
195
					"Error al finalizar el guardado de los resultados del geoproceso",
196
					e);
197
		} catch (BaseException e) {
198
			throw new GeoprocessException(
199
					"Error al acceder a la informacion del driver dentro del geoproceso",
200
					e);
201
		} 
202
	}
203
	
204
	
205

  
206
	public void initialize(CancellableProgressTask progressMonitor)
207
			throws GeoprocessException {
208
		try {
209
			progressMonitor.setInitialStep(0);
210
			int numOfSteps = firstLayer.getSource().getShapeCount();
211
			progressMonitor.setFinalStep(numOfSteps);
212
			progressMonitor.setDeterminatedProcess(true);
213
			progressMonitor.setNote(Messages.getText("flip_lines_note"));
214
			progressMonitor.setStatusMessage(Messages
215
					.getText("flip_lines_layer_message"));
216
		} catch (ReadDriverException e) {
217
			throw new GeoprocessException(
218
					"error accediendo al numero de features de una layer", e);
219
		}
220
	}
221

  
222
}
trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/fliplines/gui/FlipLinesGeoprocessPanel.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.geoprocess.impl.fliplines.gui;
50

  
51
import java.awt.event.ItemEvent;
52

  
53
import com.iver.andami.PluginServices;
54
import com.iver.cit.gvsig.fmap.layers.FLayers;
55
import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessGridbagPanel;
56
import com.iver.cit.gvsig.geoprocess.impl.fliplines.IFlipLinesGeoprocessUserEntries;
57

  
58
public class FlipLinesGeoprocessPanel 
59
	extends AbstractGeoprocessGridbagPanel implements IFlipLinesGeoprocessUserEntries{
60

  
61
	private static final long serialVersionUID = 6833607794721720432L;
62

  
63

  
64
	public FlipLinesGeoprocessPanel(FLayers arg0) {
65
		super(arg0, PluginServices.getText(null, "Generalization"));
66
	}
67

  
68
	protected void addSpecificDesign() {
69
		initSelectedItemsJCheckBox();
70
		updateNumSelectedFeaturesLabel();
71
	}
72

  
73
	
74

  
75
	protected void processLayerComboBoxStateChange(ItemEvent arg0) {
76
	}
77
	
78
	
79
	public boolean onlyFirstLayerSelected() {
80
		return isFirstOnlySelected();
81
	}
82
}
83

  

Also available in: Unified diff