Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / ArcCADTool.java @ 39063

History | View | Annotate | Download (5.56 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.editing.gui.cad.tools;
23

    
24
import java.awt.event.InputEvent;
25
import java.awt.geom.Point2D;
26

    
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.editing.gui.cad.exception.CommandException;
29
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext;
30
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext.ArcCADToolState;
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.primitive.Point;
33
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
34

    
35
/**
36
 * 
37
 * @author Vicente Caballero Navarro
38
 */
39
public class ArcCADTool extends AbstractCurveCADTool {
40

    
41
    private ArcCADToolContext _fsm;
42
    private Point p1;
43
    private Point p2;
44
    private Point p3;
45

    
46
    /**
47
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
48
     * carga previa a la utilizaci?n de la herramienta.
49
     */
50
    public void init() {
51
        _fsm = new ArcCADToolContext(this);
52
    }
53

    
54
    public void transition(double x, double y, InputEvent event) {
55
        _fsm.addPoint(x, y, event);
56
    }
57

    
58
    public void transition(double d) {
59
        _fsm.addValue(d);
60
    }
61

    
62
    public void transition(String s) throws CommandException {
63
        if (!super.changeCommand(s)) {
64
            _fsm.addOption(s);
65
        }
66
    }
67

    
68
    /**
69
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
70
     * editableFeatureSource que ya estar? creado.
71
     * 
72
     * @param sel
73
     *            Bitset con las geometr?as que est?n seleccionadas.
74
     * @param x
75
     *            par?metro x del punto que se pase en esta transici?n.
76
     * @param y
77
     *            par?metro y del punto que se pase en esta transici?n.
78
     */
79
    public void addPoint(double x, double y, InputEvent event) {
80
        ArcCADToolState actualState = (ArcCADToolState) _fsm.getPreviousState();
81
        String status = actualState.getName();
82

    
83
        if (status.equals("Arc.FirstPoint")) {
84
            p1 = createPoint(x, y);
85
        } else
86
            if (status.equals("Arc.SecondPoint")) {
87
                p2 = createPoint(x, y);
88
            } else
89
                if (status.equals("Arc.ThirdPoint")) {
90
                    p3 = createPoint(x, y);
91
                    Geometry ig = createArc(p1, p2, p3);
92
                    if (ig != null) {
93
                        insertAndSelectGeometry(ig);
94
                    }
95
                }
96
    }
97

    
98
    /**
99
     * M?todo para dibujar lo necesario para el estado en el que nos
100
     * encontremos.
101
     * 
102
     * @param g
103
     *            Graphics sobre el que dibujar.
104
     * @param selectedGeometries
105
     *            BitSet con las geometr?as seleccionadas.
106
     * @param x
107
     *            par?metro x del punto que se pase para dibujar.
108
     * @param y
109
     *            par?metro x del punto que se pase para dibujar.
110
     */
111
    public void drawOperation(MapControlDrawer renderer, double x, double y) {
112
        ArcCADToolState actualState = _fsm.getState();
113
        String status = actualState.getName();
114

    
115
        if (status.equals("Arc.SecondPoint")) {
116
            renderer.drawLine(new Point2D.Double(p1.getX(), p1.getY()),
117
                new Point2D.Double(x, y),
118
                mapControlManager.getGeometrySelectionSymbol());
119
        } else
120
            if (status.equals("Arc.ThirdPoint")) {
121
                Point current = createPoint(x, y);
122

    
123
                Geometry ig = createArc(p1, p2, current);
124
                
125
                if (ig != null) {
126
                    /*
127
                     * sometims it's not possible to create arc
128
                     * (example: aligned points)
129
                     */
130
                    renderer.draw(ig,
131
                        mapControlManager.getGeometrySelectionSymbol());
132

    
133
                    Point2D p =
134
                        getCadToolAdapter().getMapControl().getViewPort()
135
                            .fromMapPoint(p1.getX(), p1.getY());
136
                    renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1);
137
                    p =
138
                        getCadToolAdapter().getMapControl().getViewPort()
139
                            .fromMapPoint(p2.getX(), p2.getY());
140
                    renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1);
141
                }
142
            }
143
    }
144

    
145
    /**
146
     * Add a diferent option.
147
     * 
148
     * @param sel
149
     *            DOCUMENT ME!
150
     * @param s
151
     *            Diferent option.
152
     */
153
    public void addOption(String s) {
154
        // Nothing to do
155
    }
156

    
157
    public void addValue(double d) {
158
        // Nothing to do
159
    }
160

    
161
    public String getName() {
162
        return PluginServices.getText(this, "arc_");
163
    }
164

    
165
    public String toString() {
166
        return "_arc";
167
    }
168

    
169
    @Override
170
    protected int getSupportedPrimitiveGeometryType() {
171
        return ARC;
172
    }
173

    
174
}