root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / SplitGeometryCADToolExtension.java @ 38564
History | View | Annotate | Download (4.56 KB)
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 org.gvsig.editing; |
50 |
|
51 |
import org.gvsig.andami.IconThemeHelper; |
52 |
import org.gvsig.andami.PluginServices; |
53 |
import org.gvsig.andami.messages.NotificationManager; |
54 |
import org.gvsig.andami.plugins.Extension; |
55 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
56 |
import org.gvsig.editing.gui.cad.tools.SplitGeometryCADTool; |
57 |
import org.gvsig.fmap.dal.exception.DataException; |
58 |
import org.gvsig.fmap.geom.Geometry; |
59 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
60 |
import org.gvsig.fmap.mapcontrol.MapControl; |
61 |
|
62 |
|
63 |
/**
|
64 |
* CAD extension to split geometries from a digitized linear geometry.
|
65 |
*
|
66 |
* @author Alvaro Zabala
|
67 |
*
|
68 |
*/
|
69 |
public class SplitGeometryCADToolExtension extends Extension { |
70 |
|
71 |
private DefaultViewPanel view;
|
72 |
private MapControl mapControl;
|
73 |
private SplitGeometryCADTool cadTool;
|
74 |
|
75 |
|
76 |
public void execute(String actionCommand) { |
77 |
CADExtension.initFocus(); |
78 |
if (actionCommand.equals(SplitGeometryCADTool.SPLIT_GEOMETRY_ACTION_NAME)) {
|
79 |
CADExtension.setCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, true);
|
80 |
} |
81 |
CADExtension.getEditionManager().setMapControl(mapControl); |
82 |
CADExtension.getCADToolAdapter().configureMenu(); |
83 |
} |
84 |
|
85 |
public void initialize() { |
86 |
cadTool = new SplitGeometryCADTool();
|
87 |
CADExtension.addCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, cadTool); |
88 |
registerIcons(); |
89 |
} |
90 |
|
91 |
private void registerIcons(){ |
92 |
IconThemeHelper.registerIcon("action", "layer-modify-split", this); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* Returns if this Edit CAD tool is visible.
|
97 |
* For this, there must be an active vectorial editing lyr in the TOC, which geometries'
|
98 |
* dimension would must be linear or polygonal, and with at least one selected geometry.
|
99 |
*
|
100 |
*/
|
101 |
public boolean isEnabled() { |
102 |
try {
|
103 |
if (EditionUtilities.getEditionStatus() ==
|
104 |
EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
105 |
this.view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
|
106 |
mapControl = view.getMapControl(); |
107 |
if (CADExtension.getEditionManager().getActiveLayerEdited() == null) |
108 |
return false; |
109 |
FLyrVect lv = (FLyrVect) CADExtension. |
110 |
getEditionManager(). |
111 |
getActiveLayerEdited(). |
112 |
getLayer(); |
113 |
if (isPoint(lv.getShapeType())){
|
114 |
return false; |
115 |
} |
116 |
|
117 |
return !lv.getFeatureStore().getFeatureSelection().isEmpty();
|
118 |
} |
119 |
} catch (DataException e) {
|
120 |
NotificationManager.addError(e.getMessage(),e); |
121 |
return false; |
122 |
} |
123 |
return true; |
124 |
} |
125 |
|
126 |
private boolean isPoint(int shapeType) { |
127 |
switch (shapeType) {
|
128 |
case Geometry.TYPES.MULTIPOINT:
|
129 |
case Geometry.TYPES.POINT:
|
130 |
return true; |
131 |
default:
|
132 |
return false; |
133 |
} |
134 |
} |
135 |
|
136 |
public boolean isVisible() { |
137 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
138 |
return true; |
139 |
return false; |
140 |
} |
141 |
} |