Statistics
| Revision:

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

History | View | Annotate | Download (4.64 KB)

1 28070 vcaballero
/*
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 36668 jpiera
 *
46
 * $Id:
47
 * $Log:
48
 */
49 29616 jpiera
package org.gvsig.editing;
50 28070 vcaballero
51 29616 jpiera
import org.gvsig.andami.PluginServices;
52
import org.gvsig.andami.messages.NotificationManager;
53
import org.gvsig.andami.plugins.Extension;
54 31496 jjdelcerro
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
55 29616 jpiera
import org.gvsig.editing.gui.cad.tools.SplitGeometryCADTool;
56 28070 vcaballero
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 36668 jpiera
    private DefaultViewPanel view;
71
    private MapControl mapControl;
72
    private SplitGeometryCADTool cadTool;
73 28070 vcaballero
74
75 36668 jpiera
    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 28070 vcaballero
        }
80 36668 jpiera
        CADExtension.getEditionManager().setMapControl(mapControl);
81
        CADExtension.getCADToolAdapter().configureMenu();
82
    }
83 28070 vcaballero
84 36668 jpiera
    public void initialize() {
85
        cadTool = new SplitGeometryCADTool();
86
        CADExtension.addCADTool(SplitGeometryCADTool.SPLIT_GEOMETRY_TOOL_NAME, cadTool);
87
        registerIcons();
88
    }
89 28070 vcaballero
90 36668 jpiera
    private void registerIcons(){
91
        PluginServices.getIconTheme().registerDefault("split-geometry",
92
            this.getClass().
93
            getClassLoader().
94
            getResource("images/split-poly.png")
95
        );
96
    }
97 28070 vcaballero
98 36668 jpiera
    /**
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 36669 jpiera
                if (isPoint(lv.getShapeType())){
117 36668 jpiera
                    return false;
118 36669 jpiera
                }
119 28070 vcaballero
120 36668 jpiera
                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 36669 jpiera
129
    private boolean isPoint(int shapeType) {
130
        switch (shapeType) {
131 36668 jpiera
        case Geometry.TYPES.MULTIPOINT:
132 36669 jpiera
        case Geometry.TYPES.POINT:
133
            return true;
134 36668 jpiera
        default:
135 36669 jpiera
            return false;
136 36668 jpiera
        }
137
    }
138 28070 vcaballero
139 36668 jpiera
    public boolean isVisible() {
140
        if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
141
            return true;
142
        return false;
143
    }
144 28070 vcaballero
}