Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / SplitGeometryCADToolExtension.java @ 31496

History | View | Annotate | Download (4.54 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.PluginServices;
52
import org.gvsig.andami.messages.NotificationManager;
53
import org.gvsig.andami.plugins.Extension;
54
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
55
import org.gvsig.editing.gui.cad.tools.SplitGeometryCADTool;
56
import org.gvsig.fmap.dal.exception.DataException;
57
import org.gvsig.fmap.geom.Geometry;
58
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
59
import org.gvsig.fmap.mapcontrol.MapControl;
60

    
61

    
62
/**
63
 * CAD extension to split geometries from a digitized linear geometry.
64
 *
65
 * @author Alvaro Zabala
66
 *
67
 */
68
public class SplitGeometryCADToolExtension extends Extension {
69

    
70
        private DefaultViewPanel view;
71
        private MapControl mapControl;
72
        private SplitGeometryCADTool cadTool;
73

    
74

    
75
        public void execute(String actionCommand) {
76
                CADExtension.initFocus();
77
                if (actionCommand.equals(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME)) {
78
                CADExtension.setCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, true);
79
        }
80
                CADExtension.getEditionManager().setMapControl(mapControl);
81
                CADExtension.getCADToolAdapter().configureMenu();
82
        }
83

    
84
        public void initialize() {
85
                cadTool = new SplitGeometryCADTool();
86
                CADExtension.addCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, cadTool);
87
                registerIcons();
88
        }
89

    
90
        private void registerIcons(){
91
                PluginServices.getIconTheme().registerDefault("split-geometry",
92
                                                                                                           this.getClass().
93
                                                                                                           getClassLoader().
94
                                                                                                           getResource("images/split-poly.png")
95
                );
96
        }
97

    
98
        /**
99
         * Returns if this Edit CAD tool is visible.
100
         * For this, there must be an active vectorial editing lyr in the TOC, which geometries'
101
         * dimension would must be linear or polygonal, and with at least one selected geometry.
102
         *
103
         */
104
        public boolean isEnabled() {
105
                try {
106
                        if (EditionUtilities.getEditionStatus() ==
107
                                EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
108
                                        this.view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
109
                                        mapControl = view.getMapControl();
110
                                        if (CADExtension.getEditionManager().getActiveLayerEdited() == null)
111
                                                return false;
112
                                        FLyrVect lv = (FLyrVect) CADExtension.
113
                                                                                        getEditionManager().
114
                                                                                        getActiveLayerEdited().
115
                                                                                        getLayer();
116
                                        int geometryDimensions = getDimensions(lv.getShapeType());
117
                                        if(geometryDimensions <= 0)
118
                                                return false;
119

    
120
                                        return !lv.getFeatureStore().getFeatureSelection().isEmpty();
121
                        }
122
                } catch (DataException e) {
123
                        NotificationManager.addError(e.getMessage(),e);
124
                        return false;
125
                }
126
                return true;
127
        }
128
        private static int getDimensions(int shapeType) {
129
                switch (shapeType) {
130
                case Geometry.TYPES.ARC:
131
                case Geometry.TYPES.CURVE:
132
                        return 1;
133

    
134
                case Geometry.TYPES.CIRCLE:
135
                case Geometry.TYPES.ELLIPSE:
136
                case Geometry.TYPES.SURFACE:
137
                case Geometry.TYPES.GEOMETRY:
138
                        return 2;
139

    
140
                case Geometry.TYPES.MULTIPOINT:
141
                case Geometry.TYPES.POINT:
142
                case Geometry.TYPES.TEXT:
143
                        return 0;
144
                default:
145
                        return -1;
146
                }
147
        }
148

    
149
        public boolean isVisible() {
150
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
151
                        return true;
152
                return false;
153
        }
154
}