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 / EllipseCADTool.java @ 40557

History | View | Annotate | Download (6.81 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.EllipseCADToolContext;
35
import org.gvsig.editing.gui.cad.tools.smc.EllipseCADToolContext.EllipseCADToolState;
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.geom.GeometryLocator;
38
import org.gvsig.fmap.geom.primitive.Ellipse;
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 EllipseCADTool extends AbstractSurfaceCADTool {
48

    
49
    protected EllipseCADToolContext _fsm;
50
    protected Point2D startAxis;
51
    protected Point2D endAxis;
52

    
53
    /**
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
        _fsm = new EllipseCADToolContext(this);
59
    }
60

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

    
65
    public void transition(double d) {
66
        _fsm.addValue(d);
67
    }
68

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

    
75
    /**
76
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
77
     * editableFeatureSource que ya estar? creado.
78
     * 
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
     */
86
    public void addPoint(double x, double y, InputEvent event) {
87
        EllipseCADToolState actualState =
88
            (EllipseCADToolState) _fsm.getPreviousState();
89
        String status = actualState.getName();
90

    
91
        if (status.equals("Ellipse.FirstPointAxis")) {
92
            startAxis = new Point2D.Double(x, y);
93
        } else
94
            if (status.equals("Ellipse.SecondPointAxis")) {
95
                endAxis = new Point2D.Double(x, y);
96
            } else
97
                if (status.equals("Ellipse.DistanceOtherAxis")) {
98
                    Point2D middle =
99
                        new Point2D.Double(
100
                            (startAxis.getX() + endAxis.getX()) / 2,
101
                            (startAxis.getY() + endAxis.getY()) / 2);
102
                    Point2D third = new Point2D.Double(x, y);
103
                    double distance = middle.distance(third);
104
                    insertAndSelectGeometry(createEllipse(startAxis, endAxis,
105
                        distance));
106
                }
107
    }
108

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

    
126
        if (status.equals("Ellipse.SecondPointAxis")) {
127
            renderer.drawLine(startAxis, new Point2D.Double(x, y),
128
                mapControlManager.getGeometrySelectionSymbol());
129
        } else
130
            if (status.equals("Ellipse.DistanceOtherAxis")) {
131
                Point2D middle =
132
                    new Point2D.Double((startAxis.getX() + endAxis.getX()) / 2,
133
                        (startAxis.getY() + endAxis.getY()) / 2);
134

    
135
                Point2D third = new Point2D.Double(x, y);
136

    
137
                double distance = middle.distance(third);
138
                Ellipse ellipse = createEllipse(startAxis, endAxis, distance);
139
                
140
                Geometry help_geom_perim = null;
141
                try {
142
                    help_geom_perim = GeometryLocator.
143
                        getGeometryManager().createCurve(
144
                            ellipse.getGeneralPath(),
145
                            Geometry.SUBTYPES.GEOM2D);
146
                    renderer.draw(help_geom_perim,
147
                        mapControlManager.getAxisReferenceSymbol());
148
                } catch (Exception e) {
149
                    ApplicationLocator.getManager().message(
150
                        Messages.getText("_Unable_to_draw_help_geometry"),
151
                        JOptionPane.ERROR_MESSAGE);
152
                }  
153

    
154
                Point2D mediop =
155
                    new Point2D.Double((startAxis.getX() + endAxis.getX()) / 2,
156
                        (startAxis.getY() + endAxis.getY()) / 2);
157
                renderer.drawLine(mediop, third,
158
                    mapControlManager.getGeometrySelectionSymbol());
159
            }
160
    }
161

    
162
    /**
163
     * Add a diferent option.
164
     * 
165
     * @param sel
166
     *            DOCUMENT ME!
167
     * @param s
168
     *            Diferent option.
169
     */
170
    public void addOption(String s) {
171
        // TODO Auto-generated method stub
172
    }
173

    
174
    public void addValue(double d) {
175
        EllipseCADToolState actualState =
176
            (EllipseCADToolState) _fsm.getPreviousState();
177
        String status = actualState.getName();
178

    
179
        if (status.equals("Ellipse.DistanceOtherAxis")) {
180
            double distance = d;
181
            insertAndSelectGeometry(createEllipse(startAxis, endAxis, distance));
182
        }
183
    }
184

    
185
    public String getName() {
186
        return PluginServices.getText(this, "ellipse_");
187
    }
188

    
189
    public String toString() {
190
        return "_ellipse";
191
    }
192

    
193
    @Override
194
    protected int getSupportedPrimitiveGeometryType() {
195
        return ELLIPSE;
196
    }
197
}