Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / CircleCADTool.java @ 40557

History | View | Annotate | Download (8.27 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.editing.gui.cad.tools;
25

    
26
import java.awt.event.InputEvent;
27
import java.awt.geom.Point2D;
28

    
29
import javax.swing.JOptionPane;
30

    
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.app.ApplicationLocator;
33
import org.gvsig.editing.gui.cad.exception.CommandException;
34
import org.gvsig.editing.gui.cad.tools.smc.CircleCADToolContext;
35
import org.gvsig.editing.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState;
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.geom.GeometryLocator;
38
import org.gvsig.fmap.geom.primitive.Circle;
39
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
40
import org.gvsig.i18n.Messages;
41

    
42
/**
43
 * DOCUMENT ME!
44
 * 
45
 * @author Vicente Caballero Navarro
46
 */
47
public class CircleCADTool extends AbstractSurfaceCADTool {
48

    
49
    protected CircleCADToolContext _fsm;
50
    protected Point2D center;
51
    protected Point2D firstPoint;
52
    protected Point2D secondPoint;
53
    protected Point2D thirdPoint;
54

    
55
    /**
56
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
57
     * carga previa a la utilizaci?n de la herramienta.
58
     */
59
    public void init() {
60
        _fsm = new CircleCADToolContext(this);
61
    }
62

    
63
    public void transition(double x, double y, InputEvent event) {
64
        _fsm.addPoint(x, y, event);
65
    }
66

    
67
    public void transition(double d) {
68
        _fsm.addValue(d);
69
    }
70

    
71
    public void transition(String s) throws CommandException {
72
        if (!super.changeCommand(s)) {
73
            _fsm.addOption(s);
74
        }
75
    }
76

    
77
    /**
78
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
79
     * editableFeatureSource que ya estar? creado.
80
     * 
81
     * @param sel
82
     *            Bitset con las geometr?as que est?n seleccionadas.
83
     * @param x
84
     *            par?metro x del punto que se pase en esta transici?n.
85
     * @param y
86
     *            par?metro y del punto que se pase en esta transici?n.
87
     */
88
    public void addPoint(double x, double y, InputEvent event) {
89
        CircleCADToolState actualState =
90
            (CircleCADToolState) _fsm.getPreviousState();
91
        String status = actualState.getName();
92

    
93
        if (status.equals("Circle.CenterPointOr3p")) {
94
            center = new Point2D.Double(x, y);
95
        } else
96
            if (status == "Circle.PointOrRadius") {
97
                insertAndSelectGeometry(createCircle(createPoint(center),
98
                    createPoint(x, y)));
99
            } else
100
                if (status == "Circle.FirstPoint") {
101
                    firstPoint = new Point2D.Double(x, y);
102
                } else
103
                    if (status == "Circle.SecondPoint") {
104
                        secondPoint = new Point2D.Double(x, y);
105
                    } else
106
                        if (status == "Circle.ThirdPoint") {
107
                            thirdPoint = new Point2D.Double(x, y);
108
                            insertAndSelectGeometry(createCircle(
109
                                createPoint(firstPoint),
110
                                createPoint(secondPoint),
111
                                createPoint(thirdPoint)));
112
                        }
113
    }
114

    
115
    /**
116
     * M?todo para dibujar la lo necesario para el estado en el que nos
117
     * encontremos.
118
     * 
119
     * @param g
120
     *            Graphics sobre el que dibujar.
121
     * @param selectedGeometries
122
     *            BitSet con las geometr?as seleccionadas.
123
     * @param x
124
     *            par?metro x del punto que se pase para dibujar.
125
     * @param y
126
     *            par?metro x del punto que se pase para dibujar.
127
     */
128
    public void drawOperation(MapControlDrawer renderer, double x, double y) {
129
        CircleCADToolState actualState = _fsm.getState();
130
        String status = actualState.getName();
131

    
132
        Geometry help_geom_perim = null; 
133
        
134
        if ((status == "Circle.CenterPointOr3p")) { // || (status == "5")) {
135

    
136
            if (firstPoint != null) {
137
                renderer.drawLine(firstPoint, new Point2D.Double(x, y),
138
                    mapControlManager.getGeometrySelectionSymbol());
139
            }
140
        }
141

    
142
        if (status == "Circle.PointOrRadius") {
143
            Point2D currentPoint = new Point2D.Double(x, y);
144
            Circle circle =
145
                createCircle(createPoint(center), createPoint(currentPoint));
146
            
147
            try {
148
                help_geom_perim = GeometryLocator.
149
                    getGeometryManager().createCurve(
150
                        circle.getGeneralPath(),
151
                        Geometry.SUBTYPES.GEOM2D);
152
                renderer.draw(help_geom_perim,
153
                    mapControlManager.getAxisReferenceSymbol());
154
            } catch (Exception e) {
155
                ApplicationLocator.getManager().message(
156
                    Messages.getText("_Unable_to_draw_help_geometry"),
157
                    JOptionPane.ERROR_MESSAGE);
158
            }            
159
            
160
            
161
        } else
162
            if (status == "Circle.SecondPoint") {
163
                renderer.drawLine(firstPoint, new Point2D.Double(x, y),
164
                    mapControlManager.getGeometrySelectionSymbol());
165
            } else
166
                if (status == "Circle.ThirdPoint") {
167
                    Point2D currentPoint = new Point2D.Double(x, y);
168
                    Geometry geom =
169
                        createCircle(createPoint(firstPoint),
170
                            createPoint(secondPoint), createPoint(currentPoint));
171

    
172
                    if (geom != null) {
173
                        
174
                        try {
175
                            help_geom_perim = GeometryLocator.
176
                                getGeometryManager().createCurve(
177
                                    geom.getGeneralPath(),
178
                                    Geometry.SUBTYPES.GEOM2D);
179
                            renderer.draw(help_geom_perim,
180
                                mapControlManager.getAxisReferenceSymbol());
181
                        } catch (Exception e) {
182
                            ApplicationLocator.getManager().message(
183
                                Messages.getText("_Unable_to_draw_help_geometry"),
184
                                JOptionPane.ERROR_MESSAGE);
185
                        }            
186
                    }
187
                }
188
    }
189

    
190
    /**
191
     * Add a diferent option.
192
     * 
193
     * @param sel
194
     *            DOCUMENT ME!
195
     * @param s
196
     *            Diferent option.
197
     */
198
    public void addOption(String s) {
199
        CircleCADToolState actualState =
200
            (CircleCADToolState) _fsm.getPreviousState();
201
        String status = actualState.getName();
202

    
203
        if (status == "Circle.CenterPointOr3p") {
204
            if (s.equalsIgnoreCase(PluginServices.getText(this,
205
                "CircleCADTool.3p"))) {
206
                // Opci?n correcta.
207
            }
208
        }
209
    }
210

    
211
    /*
212
     * (non-Javadoc)
213
     * 
214
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
215
     */
216
    public void addValue(double d) {
217
        CircleCADToolState actualState =
218
            (CircleCADToolState) _fsm.getPreviousState();
219
        String status = actualState.getName();
220

    
221
        if (status == "Circle.PointOrRadius") {
222
            insertAndSelectGeometry(createCircle(createPoint(center), d));
223
        }
224
    }
225

    
226
    public String getName() {
227
        return PluginServices.getText(this, "circle_");
228
    }
229

    
230
    public String toString() {
231
        return "_circle";
232
    }
233

    
234
    @Override
235
    protected int getSupportedPrimitiveGeometryType() {
236
        return CIRCLE;
237
    }
238
}