svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / SplitGeometryCADToolExtension.java @ 40557
History | View | Annotate | Download (4.25 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/* CVS MESSAGES:
|
25 |
*
|
26 |
* $Id:
|
27 |
* $Log:
|
28 |
*/
|
29 |
package org.gvsig.editing; |
30 |
|
31 |
import org.gvsig.andami.IconThemeHelper; |
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.andami.messages.NotificationManager; |
34 |
import org.gvsig.andami.plugins.Extension; |
35 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
36 |
import org.gvsig.editing.gui.cad.tools.SplitGeometryCADTool; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.geom.Geometry; |
39 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
40 |
import org.gvsig.fmap.mapcontrol.MapControl; |
41 |
|
42 |
|
43 |
/**
|
44 |
* CAD extension to split geometries from a digitized linear geometry.
|
45 |
*
|
46 |
* @author Alvaro Zabala
|
47 |
*
|
48 |
*/
|
49 |
public class SplitGeometryCADToolExtension extends Extension { |
50 |
|
51 |
private DefaultViewPanel view;
|
52 |
private MapControl mapControl;
|
53 |
private SplitGeometryCADTool cadTool;
|
54 |
|
55 |
|
56 |
public void execute(String actionCommand) { |
57 |
CADExtension.initFocus(); |
58 |
if (actionCommand.equals(SplitGeometryCADTool.SPLIT_GEOMETRY_ACTION_NAME)) {
|
59 |
CADExtension.setCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, true);
|
60 |
} |
61 |
CADExtension.getEditionManager().setMapControl(mapControl); |
62 |
CADExtension.getCADToolAdapter().configureMenu(); |
63 |
} |
64 |
|
65 |
public void initialize() { |
66 |
cadTool = new SplitGeometryCADTool();
|
67 |
CADExtension.addCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, cadTool); |
68 |
registerIcons(); |
69 |
} |
70 |
|
71 |
private void registerIcons(){ |
72 |
IconThemeHelper.registerIcon("action", "layer-modify-split", this); |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Returns if this Edit CAD tool is visible.
|
77 |
* For this, there must be an active vectorial editing lyr in the TOC, which geometries'
|
78 |
* dimension would must be linear or polygonal, and with at least one selected geometry.
|
79 |
*
|
80 |
*/
|
81 |
public boolean isEnabled() { |
82 |
try {
|
83 |
if (EditionUtilities.getEditionStatus() ==
|
84 |
EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
85 |
this.view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
|
86 |
mapControl = view.getMapControl(); |
87 |
if (CADExtension.getEditionManager().getActiveLayerEdited() == null) |
88 |
return false; |
89 |
FLyrVect lv = (FLyrVect) CADExtension. |
90 |
getEditionManager(). |
91 |
getActiveLayerEdited(). |
92 |
getLayer(); |
93 |
if (isPoint(lv.getShapeType())){
|
94 |
return false; |
95 |
} |
96 |
|
97 |
return !lv.getFeatureStore().getFeatureSelection().isEmpty();
|
98 |
} |
99 |
} catch (DataException e) {
|
100 |
NotificationManager.addError(e.getMessage(),e); |
101 |
return false; |
102 |
} |
103 |
return true; |
104 |
} |
105 |
|
106 |
private boolean isPoint(int shapeType) { |
107 |
switch (shapeType) {
|
108 |
case Geometry.TYPES.MULTIPOINT:
|
109 |
case Geometry.TYPES.POINT:
|
110 |
return true; |
111 |
default:
|
112 |
return false; |
113 |
} |
114 |
} |
115 |
|
116 |
public boolean isVisible() { |
117 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
118 |
return true; |
119 |
return false; |
120 |
} |
121 |
} |