root / trunk / extensions / extDerivedGeometries / src / es / iver / derivedGeom / AddDerivedGeometrySHPExtension.java @ 32725
History | View | Annotate | Download (9.08 KB)
1 |
package es.iver.derivedGeom; |
---|---|
2 |
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government
|
4 |
*
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
6 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
21 |
* MA 02110-1301, USA.
|
22 |
*
|
23 |
*/
|
24 |
|
25 |
import com.iver.andami.PluginServices; |
26 |
import com.iver.andami.plugins.Extension; |
27 |
import com.iver.andami.ui.mdiManager.IWindow; |
28 |
import com.iver.cit.gvsig.fmap.MapContext; |
29 |
import com.iver.cit.gvsig.fmap.core.FShape; |
30 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
32 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
33 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
34 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
35 |
|
36 |
import es.iver.derivedGeom.gui.LayerAndProcessSelectionPanel; |
37 |
|
38 |
/**
|
39 |
* <p>Extension that allows user create a shape layer with derivative geometry.</p>
|
40 |
* <p>Only works with vector layers with line or point geometries.</p>
|
41 |
*
|
42 |
* <p>User will define the output layer, with geometries will use, in which order, and the kind of geometry
|
43 |
* type of the new shape: line, polygon, or multi.</p>
|
44 |
*
|
45 |
* <p>There are 3 kinds of conversions:
|
46 |
* <ul>
|
47 |
* <li><b>Points</b> to <b>Multi-Lines</b>: the selected points will be converted in multi-lines in the specified order.</li>
|
48 |
* <li><b>Points</b> to <b>Polygons</b>: the selected points will be converted in polygons in the specified order, (the last point selected
|
49 |
* will be the start point of the last line of the polygon, the first point will be also the last point of the polygon).</li>
|
50 |
* or
|
51 |
* <li><b>Lines</b> to <b>Polygons</b>: the selected multi-line geometries (only for composed lines).</li>
|
52 |
* </ul>
|
53 |
* </p>
|
54 |
*
|
55 |
* <p>After the selection, that information will be added, if the layer can be edited, as new columns of
|
56 |
* the associated data table.</p>
|
57 |
*
|
58 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
59 |
*/
|
60 |
public class AddDerivedGeometrySHPExtension extends Extension { |
61 |
// private DerivativeGeometryControlPanel controlPanel;
|
62 |
// private boolean isControlPlanelShown = false;
|
63 |
// public static final String ToolID = "dGeomsSnappingTool";
|
64 |
// public static NonEditedLayerSelectionCADTool nonEditedLayerSelectionTool;
|
65 |
// public static FLyrVect nonEditedLayer = null;
|
66 |
|
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
71 |
*/
|
72 |
public void execute(String actionCommand) { |
73 |
if (actionCommand.equals("ADD_DERIVATIVE_GEOMETRY_SHP")) { |
74 |
IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
75 |
if (view instanceof View) { |
76 |
new LayerAndProcessSelectionPanel((View)view); |
77 |
} |
78 |
} |
79 |
} |
80 |
|
81 |
/*
|
82 |
* (non-Javadoc)
|
83 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
84 |
*/
|
85 |
public void initialize() { |
86 |
// nonEditedLayerSelectionTool = new NonEditedLayerSelectionCADTool(null); // By default any layer
|
87 |
registerIcons(); |
88 |
} |
89 |
|
90 |
private void registerIcons() { |
91 |
PluginServices.getIconTheme().registerDefault( |
92 |
"add_v2-icon",
|
93 |
this.getClass().getClassLoader().getResource("images/add_v2-icon.png") |
94 |
); |
95 |
|
96 |
PluginServices.getIconTheme().registerDefault( |
97 |
"add-all-icon",
|
98 |
this.getClass().getClassLoader().getResource("images/add-all-icon.png") |
99 |
); |
100 |
|
101 |
PluginServices.getIconTheme().registerDefault( |
102 |
"button-cancel-icon",
|
103 |
this.getClass().getClassLoader().getResource("images/button-cancel-icon.png") |
104 |
); |
105 |
|
106 |
PluginServices.getIconTheme().registerDefault( |
107 |
"button-ok-icon",
|
108 |
this.getClass().getClassLoader().getResource("images/button-ok-icon.png") |
109 |
); |
110 |
|
111 |
PluginServices.getIconTheme().registerDefault( |
112 |
"double-left-arrow-icon",
|
113 |
this.getClass().getClassLoader().getResource("images/double-left-arrow-icon.png") |
114 |
); |
115 |
|
116 |
PluginServices.getIconTheme().registerDefault( |
117 |
"double-right-arrow-icon",
|
118 |
this.getClass().getClassLoader().getResource("images/double-right-arrow-icon.png") |
119 |
); |
120 |
|
121 |
PluginServices.getIconTheme().registerDefault( |
122 |
"down-arrow-icon",
|
123 |
this.getClass().getClassLoader().getResource("images/down-arrow-icon.png") |
124 |
); |
125 |
|
126 |
PluginServices.getIconTheme().registerDefault( |
127 |
"layerGroup",
|
128 |
this.getClass().getClassLoader().getResource("images/layerGroup.png") |
129 |
); |
130 |
|
131 |
PluginServices.getIconTheme().registerDefault( |
132 |
"left-arrow-icon",
|
133 |
this.getClass().getClassLoader().getResource("images/left-arrow-icon.png") |
134 |
); |
135 |
|
136 |
PluginServices.getIconTheme().registerDefault( |
137 |
"multi-icon",
|
138 |
this.getClass().getClassLoader().getResource("images/multi-icon.png") |
139 |
); |
140 |
|
141 |
PluginServices.getIconTheme().registerDefault( |
142 |
"MultiPoint",
|
143 |
this.getClass().getClassLoader().getResource("images/MultiPoint.png") |
144 |
); |
145 |
|
146 |
PluginServices.getIconTheme().registerDefault( |
147 |
"Point",
|
148 |
this.getClass().getClassLoader().getResource("images/Point.png") |
149 |
); |
150 |
|
151 |
PluginServices.getIconTheme().registerDefault( |
152 |
"Polygon",
|
153 |
this.getClass().getClassLoader().getResource("images/Polygon.png") |
154 |
); |
155 |
|
156 |
PluginServices.getIconTheme().registerDefault( |
157 |
"Rect",
|
158 |
this.getClass().getClassLoader().getResource("images/Rect.png") |
159 |
); |
160 |
|
161 |
PluginServices.getIconTheme().registerDefault( |
162 |
"reload-icon",
|
163 |
this.getClass().getClassLoader().getResource("images/reload-icon.png") |
164 |
); |
165 |
|
166 |
PluginServices.getIconTheme().registerDefault( |
167 |
"remove-all-icon",
|
168 |
this.getClass().getClassLoader().getResource("images/remove-all-icon.png") |
169 |
); |
170 |
|
171 |
PluginServices.getIconTheme().registerDefault( |
172 |
"remove-icon",
|
173 |
this.getClass().getClassLoader().getResource("images/remove-icon.png") |
174 |
); |
175 |
|
176 |
PluginServices.getIconTheme().registerDefault( |
177 |
"right-arrow-icon",
|
178 |
this.getClass().getClassLoader().getResource("images/right-arrow-icon.png") |
179 |
); |
180 |
|
181 |
PluginServices.getIconTheme().registerDefault( |
182 |
"up-arrow-icon",
|
183 |
this.getClass().getClassLoader().getResource("images/up-arrow-icon.png") |
184 |
); |
185 |
|
186 |
PluginServices.getIconTheme().registerDefault( |
187 |
"create-derivative-geometry-shape-icon",
|
188 |
this.getClass().getClassLoader().getResource("images/create-derivative-geometry-shape-icon.png") |
189 |
); |
190 |
} |
191 |
|
192 |
/*
|
193 |
* (non-Javadoc)
|
194 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
195 |
*/
|
196 |
public boolean isEnabled() { |
197 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
198 |
|
199 |
if (f == null) { |
200 |
return false; |
201 |
} |
202 |
|
203 |
if (f instanceof View) { |
204 |
View view = (View) f; |
205 |
|
206 |
IProjectView model = view.getModel(); |
207 |
MapContext map = model.getMapContext(); |
208 |
|
209 |
return hasVectorVisiblePointOrLineLayers(map.getLayers());
|
210 |
} |
211 |
|
212 |
return false; |
213 |
} |
214 |
|
215 |
/*
|
216 |
* (non-Javadoc)
|
217 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
218 |
*/
|
219 |
public boolean isVisible() { |
220 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
221 |
|
222 |
if (f == null) { |
223 |
return false; |
224 |
} |
225 |
|
226 |
if (f instanceof View) { |
227 |
View view = (View) f; |
228 |
|
229 |
IProjectView model = view.getModel(); |
230 |
MapContext map = model.getMapContext(); |
231 |
|
232 |
return map.getLayers().getLayersCount() > 0; |
233 |
} else {
|
234 |
return false; |
235 |
} |
236 |
} |
237 |
|
238 |
/**
|
239 |
* <p>Finds recursively if there is any visible non being edited vector layer of lines of point geometries.</p>
|
240 |
*
|
241 |
* @param root the root node
|
242 |
* @return <code>true</code> if there is any visible vector layer of lines of point geometries; otherwise <code>false</code>
|
243 |
*/
|
244 |
private boolean hasVectorVisiblePointOrLineLayers(FLayers root) { |
245 |
if (root != null) { |
246 |
FLayer node; |
247 |
FLyrVect vectNode; |
248 |
|
249 |
for (int i = 0; i < root.getLayersCount(); i++) { |
250 |
node = root.getLayer(i); |
251 |
|
252 |
if (node instanceof FLyrVect) { |
253 |
vectNode = (FLyrVect)node; |
254 |
|
255 |
try {
|
256 |
if ((!node.isEditing()) && (node.isVisible()) && ((vectNode.getShapeType() == FShape.LINE) || (vectNode.getShapeType() == FShape.POINT)) )
|
257 |
return true; |
258 |
} |
259 |
catch(Exception ex) { |
260 |
PluginServices.getLogger().error(ex); |
261 |
continue;
|
262 |
} |
263 |
} |
264 |
else {
|
265 |
if (node instanceof FLayers) { |
266 |
if (hasVectorVisiblePointOrLineLayers((FLayers) node))
|
267 |
return true; |
268 |
} |
269 |
} |
270 |
} |
271 |
} |
272 |
|
273 |
return false; |
274 |
} |
275 |
|
276 |
// public void showControlPanel(DerivativeGeometryProcessParameters parameters) {
|
277 |
// if ((controlPanel != null) && (! isControlPlanelShown)) {
|
278 |
//
|
279 |
// if (parameters != null)
|
280 |
// controlPanel.setParameters(parameters);
|
281 |
//
|
282 |
// PluginServices.getMDIManager().addWindow(controlPanel);
|
283 |
// isControlPlanelShown = true;
|
284 |
// }
|
285 |
// }
|
286 |
//
|
287 |
// public void hideControlPanel() {
|
288 |
// if ((controlPanel != null) && (isControlPlanelShown)) {
|
289 |
// PluginServices.getMDIManager().closeWindow(controlPanel);
|
290 |
// isControlPlanelShown = false;
|
291 |
// }
|
292 |
// }
|
293 |
} |