Revision 21266
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/SplitGeometryCADToolExtension.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 |
|
|
53 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
54 |
import com.iver.andami.PluginServices; |
|
55 |
import com.iver.andami.messages.NotificationManager; |
|
56 |
import com.iver.andami.plugins.Extension; |
|
57 |
import com.iver.cit.gvsig.CADExtension; |
|
58 |
import com.iver.cit.gvsig.EditionUtilities; |
|
59 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
60 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
61 |
import com.iver.cit.gvsig.gui.cad.tools.PolylineCADTool; |
|
62 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
63 |
|
|
64 |
/** |
|
65 |
* CAD extension to split geometries from a digitized linear geometry. |
|
66 |
* |
|
67 |
* @author Alvaro Zabala |
|
68 |
* |
|
69 |
*/ |
|
70 |
public class SplitGeometryCADToolExtension extends Extension { |
|
71 |
|
|
72 |
private View view; |
|
73 |
private MapControl mapControl; |
|
74 |
private SplitGeometryCADTool cadTool; |
|
75 |
|
|
76 |
|
|
77 |
public void execute(String actionCommand) { |
|
78 |
CADExtension.initFocus(); |
|
79 |
if (actionCommand.equals(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME)) { |
|
80 |
CADExtension.setCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, true); |
|
81 |
} |
|
82 |
CADExtension.getEditionManager().setMapControl(mapControl); |
|
83 |
CADExtension.getCADToolAdapter().configureMenu(); |
|
84 |
} |
|
85 |
|
|
86 |
public void initialize() { |
|
87 |
cadTool = new SplitGeometryCADTool(); |
|
88 |
CADExtension.addCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, cadTool); |
|
89 |
registerIcons(); |
|
90 |
} |
|
91 |
|
|
92 |
private void registerIcons(){ |
|
93 |
PluginServices.getIconTheme().registerDefault("split-geometry", |
|
94 |
this.getClass(). |
|
95 |
getClassLoader(). |
|
96 |
getResource("images/split-poly.png") |
|
97 |
); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Returns if this Edit CAD tool is visible. |
|
102 |
* For this, there must be an active vectorial editing lyr in the TOC, which geometries' |
|
103 |
* dimension would must be linear or polygonal, and with at least one selected geometry. |
|
104 |
* |
|
105 |
*/ |
|
106 |
public boolean isEnabled() { |
|
107 |
try { |
|
108 |
if (EditionUtilities.getEditionStatus() == |
|
109 |
EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
|
110 |
this.view = (View) PluginServices.getMDIManager().getActiveWindow(); |
|
111 |
mapControl = view.getMapControl(); |
|
112 |
if (CADExtension.getEditionManager().getActiveLayerEdited() == null) |
|
113 |
return false; |
|
114 |
FLyrVect lv = (FLyrVect) CADExtension. |
|
115 |
getEditionManager(). |
|
116 |
getActiveLayerEdited(). |
|
117 |
getLayer(); |
|
118 |
int geometryDimensions = FGeometryUtil.getDimensions(lv.getShapeType()); |
|
119 |
if(geometryDimensions <= 0) |
|
120 |
return false; |
|
121 |
|
|
122 |
return lv.getRecordset().getSelection().cardinality() != 0; |
|
123 |
} |
|
124 |
} catch (ReadDriverException e) { |
|
125 |
NotificationManager.addError(e.getMessage(),e); |
|
126 |
return false; |
|
127 |
} |
|
128 |
return true; |
|
129 |
} |
|
130 |
|
|
131 |
public boolean isVisible() { |
|
132 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) |
|
133 |
return true; |
|
134 |
return false; |
|
135 |
} |
|
136 |
} |
trunk/extensions/extTopology/src/com/iver/cit/gvsig/cad/SplitGeometryCADTool.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.Graphics; |
|
52 |
import java.awt.Graphics2D; |
|
53 |
import java.awt.Image; |
|
54 |
import java.awt.event.InputEvent; |
|
55 |
import java.awt.event.MouseEvent; |
|
56 |
import java.awt.geom.Point2D; |
|
57 |
import java.util.ArrayList; |
|
58 |
import java.util.List; |
|
59 |
|
|
60 |
import org.gvsig.jts.JtsUtil; |
|
61 |
|
|
62 |
import statemap.State; |
|
63 |
|
|
64 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
65 |
import com.iver.andami.PluginServices; |
|
66 |
import com.iver.cit.gvsig.cad.sm.SplitGeometryCADToolContext; |
|
67 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
|
68 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException; |
|
69 |
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException; |
|
70 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
|
71 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
72 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
73 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
74 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
75 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
|
76 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
|
77 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
|
78 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
|
79 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
|
80 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
81 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
|
82 |
import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
|
83 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
|
84 |
import com.vividsolutions.jts.geom.Coordinate; |
|
85 |
import com.vividsolutions.jts.geom.Geometry; |
|
86 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
87 |
import com.vividsolutions.jts.geom.LineString; |
|
88 |
|
|
89 |
/** |
|
90 |
* CAD Tool which splits the selected geometries of a vectorial editing |
|
91 |
* layer with a digitized polyline. |
|
92 |
* |
|
93 |
* |
|
94 |
* @author Alvaro Zabala |
|
95 |
* |
|
96 |
*/ |
|
97 |
public class SplitGeometryCADTool extends DefaultCADTool { |
|
98 |
/** |
|
99 |
* String representation of this tool (used for example to active the tool |
|
100 |
* in mapcontrol) |
|
101 |
*/ |
|
102 |
public static final String SPLIT_GEOMETRY_TOOL_NAME = "_split_geometry"; |
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
/** |
|
107 |
* finite state machine for this CAD tool |
|
108 |
*/ |
|
109 |
private SplitGeometryCADToolContext _fsm; |
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
/** |
|
114 |
* Flag to mark if the digitized line has been finished. |
|
115 |
*/ |
|
116 |
private boolean digitizingFinished = false; |
|
117 |
|
|
118 |
/** |
|
119 |
* Collection of digitized geometries |
|
120 |
*/ |
|
121 |
private List<Point2D> clickedPoints; |
|
122 |
|
|
123 |
|
|
124 |
/** |
|
125 |
* Default Constructor |
|
126 |
*/ |
|
127 |
public SplitGeometryCADTool(){ |
|
128 |
|
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
/** |
|
133 |
* Initialization method. |
|
134 |
*/ |
|
135 |
public void init() { |
|
136 |
digitizingFinished = false; |
|
137 |
_fsm = new SplitGeometryCADToolContext(this); |
|
138 |
setNextTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME); |
|
139 |
} |
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
public boolean isDigitizingFinished() { |
|
144 |
return digitizingFinished; |
|
145 |
} |
|
146 |
|
|
147 |
public String toString() { |
|
148 |
return SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME; |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
public void finishDigitizedLine(){ |
|
154 |
} |
|
155 |
|
|
156 |
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; |
|
175 |
} |
|
176 |
|
|
177 |
public void splitSelectedGeometryWithDigitizedLine(){ |
|
178 |
Point2D[] clickedPts = new Point2D[this.clickedPoints.size()]; |
|
179 |
clickedPoints.toArray(clickedPts); |
|
180 |
Coordinate[] digitizedCoords = JtsUtil.getPoint2DAsCoordinates(clickedPts); |
|
181 |
LineString splittingLs = JtsUtil.GEOMETRY_FACTORY.createLineString(digitizedCoords); |
|
182 |
|
|
183 |
|
|
184 |
ArrayList selectedRows = getSelectedRows(); |
|
185 |
ArrayList<IRowEdited> splittedSelectionGeoms = new |
|
186 |
ArrayList<IRowEdited>(); |
|
187 |
IRowEdited editedRow = null; |
|
188 |
VectorialLayerEdited vle = getVLE(); |
|
189 |
VectorialEditableAdapter vea = vle.getVEA(); |
|
190 |
// vea.startComplexRow(); |
|
191 |
for (int i = 0; i < selectedRows.size(); i++) { |
|
192 |
editedRow = (IRowEdited) selectedRows.get(i); |
|
193 |
IFeature feat = (IFeature) editedRow.getLinkedRow().cloneRow(); |
|
194 |
IGeometry ig = feat.getGeometry(); |
|
195 |
Geometry jtsGeo = ig.toJTSGeometry(); |
|
196 |
Geometry splittedGeo = JtsUtil.split(jtsGeo, splittingLs); |
|
197 |
if(splittedGeo instanceof GeometryCollection){ |
|
198 |
//first of all we delete the existing geometry |
|
199 |
try { |
|
200 |
vea.removeRow(editedRow.getIndex(), |
|
201 |
PluginServices.getText(this,"deleted_feature"), |
|
202 |
EditionEvent.GRAPHIC); |
|
203 |
|
|
204 |
//and then, we add new features for each splitted geometry |
|
205 |
GeometryCollection gc = (GeometryCollection)splittedGeo; |
|
206 |
for(int j = 0; j < gc.getNumGeometries(); j++){ |
|
207 |
Geometry g = gc.getGeometryN(j); |
|
208 |
System.out.println("g"+j+":"+g.toText()); |
|
209 |
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); |
|
212 |
|
|
213 |
DefaultRowEdited newRowEdited = new DefaultRowEdited(newFeature, |
|
214 |
IRowEdited.STATUS_ADDED, |
|
215 |
calculatedIndex); |
|
216 |
splittedSelectionGeoms.add(newRowEdited); |
|
217 |
}//for j |
|
218 |
} catch (ExpansionFileReadException e) { |
|
219 |
e.printStackTrace(); |
|
220 |
} catch (ExpansionFileWriteException e) { |
|
221 |
e.printStackTrace(); |
|
222 |
} catch (ReadDriverException e) { |
|
223 |
e.printStackTrace(); |
|
224 |
} catch (ValidateRowException e) { |
|
225 |
e.printStackTrace(); |
|
226 |
} |
|
227 |
}//if splittedGeo |
|
228 |
} |
|
229 |
// vea.endComplexRow(description); |
|
230 |
// vle.setSelectionCache(VectorialLayerEdited.SAVEPREVIOUS, |
|
231 |
// splittedSelectionGeoms); |
|
232 |
} |
|
233 |
|
|
234 |
public void end(){ |
|
235 |
getCadToolAdapter().refreshEditedLayer(); |
|
236 |
init(); |
|
237 |
} |
|
238 |
|
|
239 |
|
|
240 |
public void addOption(String s) { |
|
241 |
State actualState = _fsm.getPreviousState(); |
|
242 |
String status = actualState.getName(); |
|
243 |
if (s.equals(PluginServices.getText(this, "cancel"))) { |
|
244 |
init(); |
|
245 |
return; |
|
246 |
} |
|
247 |
if (status.equals("TopologicalEdition.FirstPoint")) { |
|
248 |
return; |
|
249 |
} |
|
250 |
init(); |
|
251 |
|
|
252 |
} |
|
253 |
|
|
254 |
public void addPoint(double x, double y, InputEvent event) { |
|
255 |
|
|
256 |
State actualState = _fsm.getPreviousState(); |
|
257 |
String status = actualState.getName(); |
|
258 |
if (status.equals("SplitGeometry.FirstPoint")) { |
|
259 |
clickedPoints = new ArrayList<Point2D>(); |
|
260 |
clickedPoints.add(new Point2D.Double(x,y)); |
|
261 |
} else if (status.equals("SplitGeometry.DigitizingLine")) { |
|
262 |
clickedPoints.add(new Point2D.Double(x,y)); |
|
263 |
if (event != null && ((MouseEvent) event).getClickCount() == 2) { |
|
264 |
digitizingFinished = true; |
|
265 |
finishDigitizedLine(); |
|
266 |
splitSelectedGeometryWithDigitizedLine(); |
|
267 |
end(); |
|
268 |
} |
|
269 |
} |
|
270 |
} |
|
271 |
|
|
272 |
public void addValue(double d) { |
|
273 |
} |
|
274 |
|
|
275 |
|
|
276 |
/** |
|
277 |
* Draws a polyline with the clicked digitized points in the specified graphics. |
|
278 |
* |
|
279 |
* @param g2 graphics on to draw the polyline |
|
280 |
* @param x last x mouse pointer position |
|
281 |
* @param y last y mouse pointer position |
|
282 |
*/ |
|
283 |
protected void drawPolyLine(Graphics2D g, double x, double y) { |
|
284 |
GeneralPathX gpx = |
|
285 |
new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, |
|
286 |
clickedPoints.size()); |
|
287 |
Point2D firstPoint = clickedPoints.get(0); |
|
288 |
gpx.moveTo(firstPoint.getX(), firstPoint.getY()); |
|
289 |
for (int i = 1; i < clickedPoints.size(); i++) { |
|
290 |
Point2D clickedPoint = clickedPoints.get(i); |
|
291 |
gpx.lineTo(clickedPoint.getX(), clickedPoint.getY()); |
|
292 |
|
|
293 |
} |
|
294 |
gpx.lineTo(x, y); |
|
295 |
ShapeFactory.createPolyline2D(gpx).draw((Graphics2D) g, |
|
296 |
getCadToolAdapter().getMapControl().getViewPort(), |
|
297 |
DefaultCADTool.geometrySelectSymbol); |
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
public void drawOperation(Graphics g, double x, double y) { |
|
304 |
State actualState = _fsm.getState(); |
|
305 |
String status = actualState.getName(); |
|
306 |
|
|
307 |
if (status.equals("SplitGeometry.FirstPoint") ) { |
|
308 |
return; |
|
309 |
} else if ((status.equals("SplitGeometry.DigitizingLine"))) { |
|
310 |
drawPolyLine((Graphics2D) g, x, y); |
|
311 |
} |
|
312 |
// else{ |
|
313 |
// try { |
|
314 |
// Image imgSel = getVLE().getSelectionImage(); |
|
315 |
// if (imgSel != null) |
|
316 |
// g.drawImage(imgSel, 0, 0, null); |
|
317 |
// } catch (Exception e) { |
|
318 |
// e.printStackTrace(); |
|
319 |
// } |
|
320 |
// } |
|
321 |
} |
|
322 |
|
|
323 |
public String getName() { |
|
324 |
return PluginServices.getText(this, SPLIT_GEOMETRY_TOOL_NAME); |
|
325 |
} |
|
326 |
|
|
327 |
|
|
328 |
public void transition(double x, double y, InputEvent event) { |
|
329 |
try { |
|
330 |
_fsm.addPoint(x, y, event); |
|
331 |
} catch (Exception e) { |
|
332 |
init(); |
|
333 |
} |
|
334 |
|
|
335 |
} |
|
336 |
|
|
337 |
|
|
338 |
public void transition(double d) { |
|
339 |
_fsm.addValue(d); |
|
340 |
} |
|
341 |
|
|
342 |
public void transition(String s) throws CommandException { |
|
343 |
if (!super.changeCommand(s)) { |
|
344 |
_fsm.addOption(s); |
|
345 |
} |
|
346 |
} |
|
347 |
|
|
348 |
} |
Also available in: Unified diff