root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / ExploitExtension.java @ 38564
History | View | Annotate | Download (7.12 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.editing; |
42 |
|
43 |
import java.util.List; |
44 |
|
45 |
import javax.swing.JOptionPane; |
46 |
|
47 |
import org.gvsig.andami.IconThemeHelper; |
48 |
import org.gvsig.andami.PluginServices; |
49 |
import org.gvsig.andami.plugins.Extension; |
50 |
import org.gvsig.app.ApplicationLocator; |
51 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
52 |
import org.gvsig.editing.gui.cad.tools.ExploitCADTool; |
53 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
54 |
import org.gvsig.fmap.dal.DALLocator; |
55 |
import org.gvsig.fmap.dal.DataManager; |
56 |
import org.gvsig.fmap.dal.exception.DataException; |
57 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
58 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
59 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
60 |
import org.gvsig.fmap.geom.Geometry; |
61 |
import org.gvsig.fmap.geom.type.GeometryType; |
62 |
import org.gvsig.fmap.mapcontrol.MapControl; |
63 |
import org.gvsig.tools.dispose.DisposableIterator; |
64 |
import org.slf4j.Logger; |
65 |
import org.slf4j.LoggerFactory; |
66 |
|
67 |
|
68 |
/**
|
69 |
* Extensi?n que gestiona la simplificaci?n de una geometr?a compuesta en otras m?s sencillas.
|
70 |
*
|
71 |
* @author Vicente Caballero Navarro
|
72 |
*/
|
73 |
public class ExploitExtension extends Extension { |
74 |
|
75 |
private static Logger logger = LoggerFactory.getLogger(ExploitExtension.class); |
76 |
private DefaultViewPanel view;
|
77 |
|
78 |
private MapControl mapControl;
|
79 |
private ExploitCADTool exploit;
|
80 |
|
81 |
/**
|
82 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
83 |
*/
|
84 |
public void initialize() { |
85 |
exploit=new ExploitCADTool();
|
86 |
CADExtension.addCADTool("_exploit",exploit);
|
87 |
|
88 |
registerIcons(); |
89 |
} |
90 |
|
91 |
private void registerIcons(){ |
92 |
IconThemeHelper.registerIcon("action", "layer-modify-explode", this); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
97 |
*/
|
98 |
public void execute(String s) { |
99 |
CADExtension.initFocus(); |
100 |
if ( "layer-modify-explode".equalsIgnoreCase(s) ) { |
101 |
CADExtension.setCADTool("_exploit",true); |
102 |
} |
103 |
CADExtension.getEditionManager().setMapControl(mapControl); |
104 |
CADExtension.getCADToolAdapter().configureMenu(); |
105 |
} |
106 |
|
107 |
/**
|
108 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
109 |
*/
|
110 |
public boolean isEnabled() { |
111 |
DisposableIterator iterator = null;
|
112 |
try {
|
113 |
if (EditionUtilities.getEditionStatus() ==
|
114 |
EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
115 |
|
116 |
view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
117 |
mapControl = view.getMapControl(); |
118 |
EditionManager em=CADExtension.getEditionManager(); |
119 |
if (em.getActiveLayerEdited()==null) { |
120 |
return false; |
121 |
} |
122 |
VectorialLayerEdited vle=(VectorialLayerEdited)em.getActiveLayerEdited(); |
123 |
// FLyrVect lv=(FLyrVect)vle.getLayer();
|
124 |
if (((FeatureSelection)vle.getFeatureStore().getSelection()).getSize()<1) { |
125 |
return false; |
126 |
} |
127 |
|
128 |
FeatureStore store = vle.getFeatureStore(); |
129 |
return canExploit(store);
|
130 |
|
131 |
/*
|
132 |
if (!canExploit(store)) {
|
133 |
return false;
|
134 |
}
|
135 |
*/
|
136 |
|
137 |
|
138 |
/*
|
139 |
* We cannot iterate through selection to get enabled or disbled
|
140 |
*
|
141 |
iterator = ((FeatureSelection) vle.getFeatureStore()
|
142 |
.getSelection()).fastIterator();
|
143 |
if (iterator.hasNext()){
|
144 |
Feature feature = (Feature) iterator.next();
|
145 |
if (feature.getDefaultGeometry()!=null &&
|
146 |
exploit.isApplicable((feature.getDefaultGeometry()).getType())){
|
147 |
return true;
|
148 |
}
|
149 |
}
|
150 |
*/
|
151 |
} |
152 |
} catch (Throwable e) { |
153 |
logger.info("IsEnabled error. ", e);
|
154 |
ApplicationLocator.getManager().message("_Unable_to_update_tool_status",
|
155 |
JOptionPane.ERROR_MESSAGE);
|
156 |
// NotificationManager.addError(e.getMessage(),e);
|
157 |
} finally {
|
158 |
if (iterator != null) { |
159 |
iterator.dispose(); |
160 |
} |
161 |
} |
162 |
return false; |
163 |
} |
164 |
|
165 |
private boolean canExploit(FeatureStore store) { |
166 |
DataManager dalmanager = DALLocator.getDataManager(); |
167 |
FeatureStoreProviderFactory factory = |
168 |
(FeatureStoreProviderFactory) dalmanager.getStoreProviderFactory(store.getProviderName()); |
169 |
|
170 |
GeometryType geotype = null;
|
171 |
try {
|
172 |
geotype = store.getDefaultFeatureType().getDefaultGeometryAttribute().getGeomType(); |
173 |
} catch (DataException e) {
|
174 |
logger.info("Cant get geom type.", e);
|
175 |
return false; |
176 |
} |
177 |
|
178 |
|
179 |
if (geotype.getType() == Geometry.TYPES.CURVE
|
180 |
|| geotype.getType() == Geometry.TYPES.MULTICURVE) { |
181 |
// exploting a curve gives curves, so ok
|
182 |
return true; |
183 |
} |
184 |
|
185 |
if (geotype.getType() == Geometry.TYPES.SURFACE
|
186 |
|| geotype.getType() == Geometry.TYPES.MULTISURFACE) { |
187 |
|
188 |
// exploting a surface can give curves:
|
189 |
return allowsCurvesOfSubtype(factory, geotype.getSubType());
|
190 |
// (factory.allowMultipleGeometryTypes()
|
191 |
// == FeatureStoreProviderFactory.YES);
|
192 |
} |
193 |
|
194 |
if (geotype.isTypeOf(Geometry.TYPES.GEOMETRY)) {
|
195 |
// if everything is allowed, ok
|
196 |
return true; |
197 |
} |
198 |
|
199 |
// otherwise: (multi)points, etc, not allowed
|
200 |
return false; |
201 |
} |
202 |
|
203 |
/**
|
204 |
* @param factory
|
205 |
* @param subType
|
206 |
* @return whether given factory supports
|
207 |
* curves of given subtype
|
208 |
*/
|
209 |
private boolean allowsCurvesOfSubtype( |
210 |
FeatureStoreProviderFactory fact, |
211 |
int subt) {
|
212 |
|
213 |
List arr2_list = fact.getSupportedGeometryTypesSubtypes();
|
214 |
int[] item = null; |
215 |
int sz = arr2_list.size();
|
216 |
for (int i=0; i<sz; i++) { |
217 |
item = (int[]) arr2_list.get(i); |
218 |
if (item != null && item.length == 2 |
219 |
&& item[0] == Geometry.TYPES.CURVE
|
220 |
&& item[1] == subt) {
|
221 |
// found curves of same subtype (dimensions)
|
222 |
return true; |
223 |
} |
224 |
} |
225 |
return false; |
226 |
} |
227 |
|
228 |
/**
|
229 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
230 |
*/
|
231 |
public boolean isVisible() { |
232 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
|
233 |
return true; |
234 |
} |
235 |
return false; |
236 |
} |
237 |
} |