root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / ExploitExtension.java @ 38560
History | View | Annotate | Download (7.13 KB)
1 | 5884 | caballero | /* 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 | 29616 | jpiera | package org.gvsig.editing; |
42 | 5884 | caballero | |
43 | 38533 | jldominguez | import java.util.List; |
44 | |||
45 | 38243 | jldominguez | import javax.swing.JOptionPane; |
46 | |||
47 | import org.slf4j.Logger; |
||
48 | import org.slf4j.LoggerFactory; |
||
49 | |||
50 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
51 | import org.gvsig.andami.plugins.Extension; |
||
52 | 38243 | jldominguez | import org.gvsig.app.ApplicationLocator; |
53 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
54 | 29616 | jpiera | import org.gvsig.editing.gui.cad.tools.ExploitCADTool; |
55 | import org.gvsig.editing.layers.VectorialLayerEdited; |
||
56 | 38243 | jldominguez | import org.gvsig.fmap.dal.DALLocator; |
57 | import org.gvsig.fmap.dal.DataManager; |
||
58 | 24500 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
59 | 24490 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureSelection; |
60 | 38243 | jldominguez | import org.gvsig.fmap.dal.feature.FeatureStore; |
61 | import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
||
62 | import org.gvsig.fmap.geom.Geometry; |
||
63 | import org.gvsig.fmap.geom.type.GeometryType; |
||
64 | 21666 | vcaballero | import org.gvsig.fmap.mapcontrol.MapControl; |
65 | 38250 | jldominguez | import org.gvsig.tools.dispose.DisposableIterator; |
66 | 21666 | vcaballero | |
67 | 5884 | caballero | |
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 | 38243 | jldominguez | |
75 | private static Logger logger = LoggerFactory.getLogger(ExploitExtension.class); |
||
76 | 31496 | jjdelcerro | private DefaultViewPanel view;
|
77 | 5884 | caballero | |
78 | private MapControl mapControl;
|
||
79 | private ExploitCADTool exploit;
|
||
80 | |||
81 | /**
|
||
82 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
83 | 5884 | caballero | */
|
84 | public void initialize() { |
||
85 | exploit=new ExploitCADTool();
|
||
86 | CADExtension.addCADTool("_exploit",exploit);
|
||
87 | 15604 | vcaballero | |
88 | 14810 | jmvivo | registerIcons(); |
89 | 5884 | caballero | } |
90 | 15604 | vcaballero | |
91 | 14810 | jmvivo | private void registerIcons(){ |
92 | 15637 | jmvivo | PluginServices.getIconTheme().registerDefault( |
93 | 14810 | jmvivo | "edition-geometry-exploit",
|
94 | this.getClass().getClassLoader().getResource("images/Exploit.png") |
||
95 | ); |
||
96 | } |
||
97 | 5884 | caballero | |
98 | /**
|
||
99 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
100 | 5884 | caballero | */
|
101 | public void execute(String s) { |
||
102 | CADExtension.initFocus(); |
||
103 | if (s.equals("_exploit")) { |
||
104 | CADExtension.setCADTool(s,true);
|
||
105 | } |
||
106 | CADExtension.getEditionManager().setMapControl(mapControl); |
||
107 | CADExtension.getCADToolAdapter().configureMenu(); |
||
108 | } |
||
109 | |||
110 | /**
|
||
111 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
112 | 5884 | caballero | */
|
113 | public boolean isEnabled() { |
||
114 | 27525 | jmvivo | DisposableIterator iterator = null;
|
115 | 22986 | vcaballero | try {
|
116 | 38243 | jldominguez | if (EditionUtilities.getEditionStatus() ==
|
117 | EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
||
118 | |||
119 | 31496 | jjdelcerro | view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
120 | 6604 | caballero | mapControl = view.getMapControl(); |
121 | 5884 | caballero | EditionManager em=CADExtension.getEditionManager(); |
122 | 27525 | jmvivo | if (em.getActiveLayerEdited()==null) { |
123 | 5884 | caballero | return false; |
124 | 27525 | jmvivo | } |
125 | 5884 | caballero | VectorialLayerEdited vle=(VectorialLayerEdited)em.getActiveLayerEdited(); |
126 | 15604 | vcaballero | // FLyrVect lv=(FLyrVect)vle.getLayer();
|
127 | 27525 | jmvivo | if (((FeatureSelection)vle.getFeatureStore().getSelection()).getSize()<1) { |
128 | 5884 | caballero | return false; |
129 | 27525 | jmvivo | } |
130 | 38243 | jldominguez | |
131 | FeatureStore store = vle.getFeatureStore(); |
||
132 | return canExploit(store);
|
||
133 | |||
134 | /*
|
||
135 | if (!canExploit(store)) {
|
||
136 | return false;
|
||
137 | }
|
||
138 | */
|
||
139 | |||
140 | |||
141 | /*
|
||
142 | * We cannot iterate through selection to get enabled or disbled
|
||
143 | *
|
||
144 | 27525 | jmvivo | iterator = ((FeatureSelection) vle.getFeatureStore()
|
145 | 38243 | jldominguez | .getSelection()).fastIterator();
|
146 | 25859 | vcaballero | if (iterator.hasNext()){
|
147 | 27525 | jmvivo | Feature feature = (Feature) iterator.next();
|
148 | 38243 | jldominguez | if (feature.getDefaultGeometry()!=null &&
|
149 | exploit.isApplicable((feature.getDefaultGeometry()).getType())){
|
||
150 | 25859 | vcaballero | return true;
|
151 | }
|
||
152 | 5884 | caballero | }
|
153 | 38243 | jldominguez | */
|
154 | 5884 | caballero | } |
155 | 38243 | jldominguez | } catch (Throwable e) { |
156 | logger.info("IsEnabled error. ", e);
|
||
157 | ApplicationLocator.getManager().message("_Unable_to_update_tool_status",
|
||
158 | JOptionPane.ERROR_MESSAGE);
|
||
159 | // NotificationManager.addError(e.getMessage(),e);
|
||
160 | 27525 | jmvivo | } finally {
|
161 | if (iterator != null) { |
||
162 | iterator.dispose(); |
||
163 | } |
||
164 | 22986 | vcaballero | } |
165 | 5884 | caballero | return false; |
166 | } |
||
167 | |||
168 | 38243 | jldominguez | private boolean canExploit(FeatureStore store) { |
169 | DataManager dalmanager = DALLocator.getDataManager(); |
||
170 | FeatureStoreProviderFactory factory = |
||
171 | (FeatureStoreProviderFactory) dalmanager.getStoreProviderFactory(store.getProviderName()); |
||
172 | |||
173 | GeometryType geotype = null;
|
||
174 | try {
|
||
175 | geotype = store.getDefaultFeatureType().getDefaultGeometryAttribute().getGeomType(); |
||
176 | } catch (DataException e) {
|
||
177 | logger.info("Cant get geom type.", e);
|
||
178 | return false; |
||
179 | } |
||
180 | |||
181 | |||
182 | 38368 | jldominguez | if (geotype.getType() == Geometry.TYPES.CURVE
|
183 | || geotype.getType() == Geometry.TYPES.MULTICURVE) { |
||
184 | // exploting a curve gives curves, so ok
|
||
185 | 38243 | jldominguez | return true; |
186 | } |
||
187 | |||
188 | 38368 | jldominguez | if (geotype.getType() == Geometry.TYPES.SURFACE
|
189 | || geotype.getType() == Geometry.TYPES.MULTISURFACE) { |
||
190 | |||
191 | 38533 | jldominguez | // exploting a surface can give curves:
|
192 | return allowsCurvesOfSubtype(factory, geotype.getSubType());
|
||
193 | // (factory.allowMultipleGeometryTypes()
|
||
194 | // == FeatureStoreProviderFactory.YES);
|
||
195 | 38243 | jldominguez | } |
196 | 38368 | jldominguez | |
197 | 38243 | jldominguez | if (geotype.isTypeOf(Geometry.TYPES.GEOMETRY)) {
|
198 | 38368 | jldominguez | // if everything is allowed, ok
|
199 | 38243 | jldominguez | return true; |
200 | } |
||
201 | |||
202 | 38368 | jldominguez | // otherwise: (multi)points, etc, not allowed
|
203 | 38243 | jldominguez | return false; |
204 | } |
||
205 | 38533 | jldominguez | |
206 | 5884 | caballero | /**
|
207 | 38533 | jldominguez | * @param factory
|
208 | * @param subType
|
||
209 | * @return whether given factory supports
|
||
210 | * curves of given subtype
|
||
211 | */
|
||
212 | private boolean allowsCurvesOfSubtype( |
||
213 | FeatureStoreProviderFactory fact, |
||
214 | int subt) {
|
||
215 | |||
216 | List arr2_list = fact.getSupportedGeometryTypesSubtypes();
|
||
217 | int[] item = null; |
||
218 | int sz = arr2_list.size();
|
||
219 | for (int i=0; i<sz; i++) { |
||
220 | item = (int[]) arr2_list.get(i); |
||
221 | if (item != null && item.length == 2 |
||
222 | && item[0] == Geometry.TYPES.CURVE
|
||
223 | && item[1] == subt) {
|
||
224 | // found curves of same subtype (dimensions)
|
||
225 | return true; |
||
226 | } |
||
227 | } |
||
228 | return false; |
||
229 | } |
||
230 | |||
231 | /**
|
||
232 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isVisible()
|
233 | 5884 | caballero | */
|
234 | public boolean isVisible() { |
||
235 | 27525 | jmvivo | if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
|
236 | 5884 | caballero | return true; |
237 | 27525 | jmvivo | } |
238 | 6604 | caballero | return false; |
239 | 5884 | caballero | } |
240 | } |