root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / SplitGeometryCADToolExtension.java @ 30955
History | View | Annotate | Download (5.39 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 com.iver.cit.gvsig; |
50 |
|
51 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.andami.messages.NotificationManager; |
54 |
import com.iver.andami.plugins.Extension; |
55 |
import com.iver.cit.gvsig.CADExtension; |
56 |
import com.iver.cit.gvsig.EditionUtilities; |
57 |
import com.iver.cit.gvsig.fmap.MapControl; |
58 |
import com.iver.cit.gvsig.fmap.core.FArc2D; |
59 |
import com.iver.cit.gvsig.fmap.core.FCircle2D; |
60 |
import com.iver.cit.gvsig.fmap.core.FEllipse2D; |
61 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
62 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
63 |
import com.iver.cit.gvsig.fmap.core.FMultiPoint2D; |
64 |
import com.iver.cit.gvsig.fmap.core.FMultipoint3D; |
65 |
import com.iver.cit.gvsig.fmap.core.FNullGeometry; |
66 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
67 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
68 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
69 |
import com.iver.cit.gvsig.fmap.core.FPolygon3D; |
70 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
71 |
import com.iver.cit.gvsig.fmap.core.FPolyline3D; |
72 |
import com.iver.cit.gvsig.fmap.core.FShape; |
73 |
import com.iver.cit.gvsig.fmap.core.FSpline2D; |
74 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
75 |
import com.iver.cit.gvsig.fmap.core.gt2.FLiteShape; |
76 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
77 |
import com.iver.cit.gvsig.gui.cad.tools.SplitGeometryCADTool; |
78 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
79 |
import com.vividsolutions.jts.geom.Geometry; |
80 |
|
81 |
/**
|
82 |
* CAD extension to split geometries from a digitized linear geometry.
|
83 |
*
|
84 |
* @author Alvaro Zabala
|
85 |
*
|
86 |
*/
|
87 |
public class SplitGeometryCADToolExtension extends Extension { |
88 |
|
89 |
private View view; |
90 |
private MapControl mapControl;
|
91 |
private SplitGeometryCADTool cadTool;
|
92 |
|
93 |
|
94 |
public void execute(String actionCommand) { |
95 |
CADExtension.initFocus(); |
96 |
if (actionCommand.equals(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME)) {
|
97 |
CADExtension.setCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, true);
|
98 |
} |
99 |
CADExtension.getEditionManager().setMapControl(mapControl); |
100 |
CADExtension.getCADToolAdapter().configureMenu(); |
101 |
} |
102 |
|
103 |
public void initialize() { |
104 |
cadTool = new SplitGeometryCADTool();
|
105 |
CADExtension.addCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, cadTool); |
106 |
registerIcons(); |
107 |
} |
108 |
|
109 |
private void registerIcons(){ |
110 |
PluginServices.getIconTheme().registerDefault("split-geometry",
|
111 |
this.getClass().
|
112 |
getClassLoader(). |
113 |
getResource("images/split-poly.png")
|
114 |
); |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Returns if this Edit CAD tool is visible.
|
119 |
* For this, there must be an active vectorial editing lyr in the TOC, which geometries'
|
120 |
* dimension would must be linear or polygonal, and with at least one selected geometry.
|
121 |
*
|
122 |
*/
|
123 |
public boolean isEnabled() { |
124 |
try {
|
125 |
if (EditionUtilities.getEditionStatus() ==
|
126 |
EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
127 |
this.view = (View) PluginServices.getMDIManager().getActiveWindow(); |
128 |
mapControl = view.getMapControl(); |
129 |
if (CADExtension.getEditionManager().getActiveLayerEdited() == null) |
130 |
return false; |
131 |
FLyrVect lv = (FLyrVect) CADExtension. |
132 |
getEditionManager(). |
133 |
getActiveLayerEdited(). |
134 |
getLayer(); |
135 |
int geometryDimensions = getDimensions(lv.getShapeType());
|
136 |
if(geometryDimensions <= 0) |
137 |
return false; |
138 |
|
139 |
return lv.getRecordset().getSelection().cardinality() != 0; |
140 |
} |
141 |
} catch (ReadDriverException e) {
|
142 |
NotificationManager.addError(e.getMessage(),e); |
143 |
return false; |
144 |
} |
145 |
return true; |
146 |
} |
147 |
private static int getDimensions(int shapeType) { |
148 |
switch (shapeType) {
|
149 |
case FShape.ARC:
|
150 |
case FShape.LINE:
|
151 |
return 1; |
152 |
|
153 |
case FShape.CIRCLE:
|
154 |
case FShape.ELLIPSE:
|
155 |
case FShape.POLYGON:
|
156 |
case FShape.MULTI:
|
157 |
return 2; |
158 |
|
159 |
case FShape.MULTIPOINT:
|
160 |
case FShape.POINT:
|
161 |
case FShape.TEXT:
|
162 |
return 0; |
163 |
default:
|
164 |
return -1; |
165 |
} |
166 |
} |
167 |
|
168 |
public boolean isVisible() { |
169 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
170 |
return true; |
171 |
return false; |
172 |
} |
173 |
} |