Statistics
| Revision:

root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / CircleCADTool.java @ 3832

History | View | Annotate | Download (7 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.gui.cad.tools;
42

    
43
import java.awt.Graphics;
44
import java.awt.Graphics2D;
45
import java.awt.geom.Point2D;
46

    
47
import statemap.TransitionUndefinedException;
48

    
49
import com.iver.cit.gvsig.fmap.core.IGeometry;
50
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
51
import com.iver.cit.gvsig.gui.cad.CADTool;
52
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
53
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext;
54
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState;
55

    
56

    
57
/**
58
 * DOCUMENT ME!
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class CircleCADTool extends DefaultCADTool {
63
    private CircleCADToolContext _fsm;
64
    private Point2D center;
65
    private Point2D firstPoint;
66
    private Point2D secondPoint;
67
    private Point2D thirdPoint;
68

    
69
    /**
70
     * Crea un nuevo LineCADTool.
71
     */
72
    public CircleCADTool() {
73
        _fsm = new CircleCADToolContext(this);
74
    }
75

    
76
    /**
77
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
78
     * carga previa a la utilizaci?n de la herramienta.
79
     */
80
    public void init() {
81
    }
82

    
83
    /* (non-Javadoc)
84
     * @see com.iver.cit.gvsig.gui.cad.CADTool#end()
85
     */
86
    public void end() {
87
        _fsm = new CircleCADToolContext(this);
88
        firstPoint = null;
89
    }
90

    
91
    /* (non-Javadoc)
92
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
93
     */
94
    public void transition(double x, double y)
95
        throws TransitionUndefinedException {
96
        _fsm.addPoint(x, y);
97
    }
98

    
99
    /* (non-Javadoc)
100
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
101
     */
102
    public void transition(double d)
103
        throws TransitionUndefinedException {
104
        _fsm.addValue(d);
105
    }
106

    
107
    /* (non-Javadoc)
108
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
109
     */
110
    public void transition(String s)
111
        throws TransitionUndefinedException {
112
        _fsm.addOption(s);
113
    }
114

    
115
    /**
116
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
117
     * editableFeatureSource que ya estar? creado.
118
     *
119
     * @param sel Bitset con las geometr?as que est?n seleccionadas.
120
     * @param x par?metro x del punto que se pase en esta transici?n.
121
     * @param y par?metro y del punto que se pase en esta transici?n.
122
     */
123
    public void addPoint(double x, double y) {
124
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
125
        String status = actualState.getName();
126

    
127
        if (status.equals("ExecuteMap.Initial")) {
128
            center = new Point2D.Double(x, y);
129
        } else if (status == "ExecuteMap.First") {
130
            addGeometry(ShapeFactory.createCircle(center,
131
                    new Point2D.Double(x, y)));
132
        } else if (status == "ExecuteMap.Seventh") {
133
            firstPoint = new Point2D.Double(x, y);
134
        } else if (status == "ExecuteMap.Second") {
135
            secondPoint = new Point2D.Double(x, y);
136
        } else if (status == "ExecuteMap.Third") {
137
            thirdPoint = new Point2D.Double(x, y);
138
            addGeometry(ShapeFactory.createCircle(firstPoint, secondPoint,
139
                    thirdPoint));
140
        } else if (status == "ExecuteMap.Sixth") {
141
            addGeometry(ShapeFactory.createCircle(center,
142
                    new Point2D.Double(x, y)));
143
        }
144
    }
145

    
146
    /**
147
     * M?todo para dibujar la lo necesario para el estado en el que nos
148
     * encontremos.
149
     *
150
     * @param g Graphics sobre el que dibujar.
151
     * @param selectedGeometries BitSet con las geometr?as seleccionadas.
152
     * @param x par?metro x del punto que se pase para dibujar.
153
     * @param y par?metro x del punto que se pase para dibujar.
154
     */
155
    public void drawOperation(Graphics g,double x,
156
        double y) {
157
        CircleCADToolState actualState = _fsm.getState();
158
        String status = actualState.getName();
159

    
160
        if ((status == "ExecuteMap.Initial")) { // || (status == "5")) {
161

    
162
            if (firstPoint != null) {
163
                drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
164
            }
165
        }
166

    
167
        if (status == "ExecuteMap.First") {
168
            Point2D currentPoint = new Point2D.Double(x, y);
169
            ShapeFactory.createCircle(center, currentPoint).draw((Graphics2D) g,
170
                getCadToolAdapter().getMapControl().getViewPort(),
171
                CADTool.modifySymbol);
172
        } else if (status == "ExecuteMap.Second") {
173
            drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
174
        } else if (status == "ExecuteMap.Third") {
175
            Point2D currentPoint = new Point2D.Double(x, y);
176
            IGeometry geom = ShapeFactory.createCircle(firstPoint, secondPoint,
177
                    currentPoint);
178

    
179
            if (geom != null) {
180
                geom.draw((Graphics2D) g,
181
                    getCadToolAdapter().getMapControl().getViewPort(),
182
                    CADTool.modifySymbol);
183
            }
184
        }
185
    }
186

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

    
197
        if (status == "ExecuteMap.Initial") {
198
            if (s.equals("3p") || s.equals("3P")) {
199
                //Opci?n correcta.
200
            }
201
        }
202
    }
203

    
204
    /* (non-Javadoc)
205
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
206
     */
207
    public void addValue(double d) {
208
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
209
        String status = actualState.getName();
210

    
211
        if (status == "ExecuteMap.Fiveth") {
212
            addGeometry(ShapeFactory.createCircle(center, d));
213
        }
214
    }
215
}