Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / CircleCADTool.java @ 38564

History | View | Annotate | Download (8.23 KB)

1 37138 cordinyana
/* gvSIG. Geographic Information System of the Valencian Government
2 3748 caballero
 *
3 37138 cordinyana
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6 3748 caballero
 * 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 2
9
 * of the License, or (at your option) any later version.
10 37138 cordinyana
 *
11 3748 caballero
 * 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 37138 cordinyana
 *
16 3748 caballero
 * 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 37138 cordinyana
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21 3748 caballero
 */
22 29616 jpiera
package org.gvsig.editing.gui.cad.tools;
23 3782 caballero
24 4313 fjp
import java.awt.event.InputEvent;
25 3782 caballero
import java.awt.geom.Point2D;
26
27 38393 jldominguez
import javax.swing.JOptionPane;
28
29 29616 jpiera
import org.gvsig.andami.PluginServices;
30 38393 jldominguez
import org.gvsig.app.ApplicationLocator;
31 29616 jpiera
import org.gvsig.editing.gui.cad.exception.CommandException;
32
import org.gvsig.editing.gui.cad.tools.smc.CircleCADToolContext;
33
import org.gvsig.editing.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState;
34 21668 vcaballero
import org.gvsig.fmap.geom.Geometry;
35 38393 jldominguez
import org.gvsig.fmap.geom.GeometryLocator;
36 30335 jpiera
import org.gvsig.fmap.geom.primitive.Circle;
37
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
38 38393 jldominguez
import org.gvsig.i18n.Messages;
39 21668 vcaballero
40 3782 caballero
/**
41
 * DOCUMENT ME!
42 37138 cordinyana
 *
43 3782 caballero
 * @author Vicente Caballero Navarro
44
 */
45 37328 cordinyana
public class CircleCADTool extends AbstractSurfaceCADTool {
46 37138 cordinyana
47 26921 jpiera
    protected CircleCADToolContext _fsm;
48
    protected Point2D center;
49
    protected Point2D firstPoint;
50
    protected Point2D secondPoint;
51
    protected Point2D thirdPoint;
52 27270 vcaballero
53 3748 caballero
    /**
54
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
55
     * carga previa a la utilizaci?n de la herramienta.
56
     */
57
    public void init() {
58 3782 caballero
        _fsm = new CircleCADToolContext(this);
59 3748 caballero
    }
60
61 37138 cordinyana
    public void transition(double x, double y, InputEvent event) {
62 4324 caballero
        _fsm.addPoint(x, y, event);
63 3748 caballero
    }
64 3782 caballero
65 37138 cordinyana
    public void transition(double d) {
66 3832 caballero
        _fsm.addValue(d);
67 3782 caballero
    }
68 3748 caballero
69 37138 cordinyana
    public void transition(String s) throws CommandException {
70
        if (!super.changeCommand(s)) {
71
            _fsm.addOption(s);
72
        }
73 3782 caballero
    }
74
75 3748 caballero
    /**
76
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
77
     * editableFeatureSource que ya estar? creado.
78 37138 cordinyana
     *
79
     * @param sel
80
     *            Bitset con las geometr?as que est?n seleccionadas.
81
     * @param x
82
     *            par?metro x del punto que se pase en esta transici?n.
83
     * @param y
84
     *            par?metro y del punto que se pase en esta transici?n.
85 3748 caballero
     */
86 37138 cordinyana
    public void addPoint(double x, double y, InputEvent event) {
87
        CircleCADToolState actualState =
88
            (CircleCADToolState) _fsm.getPreviousState();
89 3748 caballero
        String status = actualState.getName();
90 3766 caballero
91 3978 caballero
        if (status.equals("Circle.CenterPointOr3p")) {
92 3782 caballero
            center = new Point2D.Double(x, y);
93 37138 cordinyana
        } else
94
            if (status == "Circle.PointOrRadius") {
95
                insertAndSelectGeometry(createCircle(createPoint(center),
96
                    createPoint(x, y)));
97
            } else
98
                if (status == "Circle.FirstPoint") {
99
                    firstPoint = new Point2D.Double(x, y);
100
                } else
101
                    if (status == "Circle.SecondPoint") {
102
                        secondPoint = new Point2D.Double(x, y);
103
                    } else
104
                        if (status == "Circle.ThirdPoint") {
105
                            thirdPoint = new Point2D.Double(x, y);
106
                            insertAndSelectGeometry(createCircle(
107
                                createPoint(firstPoint),
108
                                createPoint(secondPoint),
109
                                createPoint(thirdPoint)));
110
                        }
111 3782 caballero
    }
112 3748 caballero
113
    /**
114
     * M?todo para dibujar la lo necesario para el estado en el que nos
115
     * encontremos.
116 37138 cordinyana
     *
117
     * @param g
118
     *            Graphics sobre el que dibujar.
119
     * @param selectedGeometries
120
     *            BitSet con las geometr?as seleccionadas.
121
     * @param x
122
     *            par?metro x del punto que se pase para dibujar.
123
     * @param y
124
     *            par?metro x del punto que se pase para dibujar.
125 3748 caballero
     */
126 37138 cordinyana
    public void drawOperation(MapControlDrawer renderer, double x, double y) {
127 3748 caballero
        CircleCADToolState actualState = _fsm.getState();
128
        String status = actualState.getName();
129
130 38393 jldominguez
        Geometry help_geom_perim = null;
131
132 3978 caballero
        if ((status == "Circle.CenterPointOr3p")) { // || (status == "5")) {
133 3748 caballero
134
            if (firstPoint != null) {
135 37138 cordinyana
                renderer.drawLine(firstPoint, new Point2D.Double(x, y),
136
                    mapControlManager.getGeometrySelectionSymbol());
137 3748 caballero
            }
138
        }
139 3782 caballero
140 3978 caballero
        if (status == "Circle.PointOrRadius") {
141 3782 caballero
            Point2D currentPoint = new Point2D.Double(x, y);
142 37138 cordinyana
            Circle circle =
143
                createCircle(createPoint(center), createPoint(currentPoint));
144 38393 jldominguez
145
            try {
146
                help_geom_perim = GeometryLocator.
147
                    getGeometryManager().createCurve(
148
                        circle.getGeneralPath(),
149
                        Geometry.SUBTYPES.GEOM2D);
150
                renderer.draw(help_geom_perim,
151
                    mapControlManager.getAxisReferenceSymbol());
152
            } catch (Exception e) {
153
                ApplicationLocator.getManager().message(
154
                    Messages.getText("_Unable_to_draw_help_geometry"),
155
                    JOptionPane.ERROR_MESSAGE);
156
            }
157
158
159 37138 cordinyana
        } else
160
            if (status == "Circle.SecondPoint") {
161
                renderer.drawLine(firstPoint, new Point2D.Double(x, y),
162
                    mapControlManager.getGeometrySelectionSymbol());
163
            } else
164
                if (status == "Circle.ThirdPoint") {
165
                    Point2D currentPoint = new Point2D.Double(x, y);
166
                    Geometry geom =
167
                        createCircle(createPoint(firstPoint),
168
                            createPoint(secondPoint), createPoint(currentPoint));
169 5880 fjp
170 37138 cordinyana
                    if (geom != null) {
171 38393 jldominguez
172
                        try {
173
                            help_geom_perim = GeometryLocator.
174
                                getGeometryManager().createCurve(
175
                                    geom.getGeneralPath(),
176
                                    Geometry.SUBTYPES.GEOM2D);
177
                            renderer.draw(help_geom_perim,
178
                                mapControlManager.getAxisReferenceSymbol());
179
                        } catch (Exception e) {
180
                            ApplicationLocator.getManager().message(
181
                                Messages.getText("_Unable_to_draw_help_geometry"),
182
                                JOptionPane.ERROR_MESSAGE);
183
                        }
184 37138 cordinyana
                    }
185
                }
186 3748 caballero
    }
187
188
    /**
189
     * Add a diferent option.
190 37138 cordinyana
     *
191
     * @param sel
192
     *            DOCUMENT ME!
193
     * @param s
194
     *            Diferent option.
195 3748 caballero
     */
196 3832 caballero
    public void addOption(String s) {
197 37138 cordinyana
        CircleCADToolState actualState =
198
            (CircleCADToolState) _fsm.getPreviousState();
199 3748 caballero
        String status = actualState.getName();
200 3782 caballero
201 3978 caballero
        if (status == "Circle.CenterPointOr3p") {
202 37138 cordinyana
            if (s.equalsIgnoreCase(PluginServices.getText(this,
203
                "CircleCADTool.3p"))) {
204
                // Opci?n correcta.
205 3782 caballero
            }
206
        }
207 3748 caballero
    }
208
209 37138 cordinyana
    /*
210
     * (non-Javadoc)
211
     *
212 3748 caballero
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
213
     */
214 3832 caballero
    public void addValue(double d) {
215 37138 cordinyana
        CircleCADToolState actualState =
216
            (CircleCADToolState) _fsm.getPreviousState();
217 3748 caballero
        String status = actualState.getName();
218
219 3978 caballero
        if (status == "Circle.PointOrRadius") {
220 37138 cordinyana
            insertAndSelectGeometry(createCircle(createPoint(center), d));
221 3782 caballero
        }
222 3748 caballero
    }
223 3883 caballero
224 37138 cordinyana
    public String getName() {
225
        return PluginServices.getText(this, "circle_");
226
    }
227 4118 caballero
228 37138 cordinyana
    public String toString() {
229
        return "_circle";
230
    }
231 4892 caballero
232 37328 cordinyana
    @Override
233
    protected int getSupportedPrimitiveGeometryType() {
234
        return CIRCLE;
235 37138 cordinyana
    }
236 3748 caballero
}