Statistics
| Revision:

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

History | View | Annotate | Download (6.73 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
    }
74

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

    
83
    /* (non-Javadoc)
84
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
85
     */
86
    public void transition(double x, double y)
87
        throws TransitionUndefinedException {
88
        _fsm.addPoint(x, y);
89
    }
90

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

    
98
    /* (non-Javadoc)
99
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
100
     */
101
    public void transition(String s){
102
        _fsm.addOption(s);
103
    }
104

    
105
    /**
106
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
107
     * editableFeatureSource que ya estar? creado.
108
     *
109
     * @param sel Bitset con las geometr?as que est?n seleccionadas.
110
     * @param x par?metro x del punto que se pase en esta transici?n.
111
     * @param y par?metro y del punto que se pase en esta transici?n.
112
     */
113
    public void addPoint(double x, double y) {
114
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
115
        String status = actualState.getName();
116

    
117
        if (status.equals("ExecuteMap.Initial")) {
118
            center = new Point2D.Double(x, y);
119
        } else if (status == "ExecuteMap.First") {
120
            addGeometry(ShapeFactory.createCircle(center,
121
                    new Point2D.Double(x, y)));
122
        } else if (status == "ExecuteMap.Seventh") {
123
            firstPoint = new Point2D.Double(x, y);
124
        } else if (status == "ExecuteMap.Second") {
125
            secondPoint = new Point2D.Double(x, y);
126
        } else if (status == "ExecuteMap.Third") {
127
            thirdPoint = new Point2D.Double(x, y);
128
            addGeometry(ShapeFactory.createCircle(firstPoint, secondPoint,
129
                    thirdPoint));
130
        } else if (status == "ExecuteMap.Sixth") {
131
            addGeometry(ShapeFactory.createCircle(center,
132
                    new Point2D.Double(x, y)));
133
        }
134
    }
135

    
136
    /**
137
     * M?todo para dibujar la lo necesario para el estado en el que nos
138
     * encontremos.
139
     *
140
     * @param g Graphics sobre el que dibujar.
141
     * @param selectedGeometries BitSet con las geometr?as seleccionadas.
142
     * @param x par?metro x del punto que se pase para dibujar.
143
     * @param y par?metro x del punto que se pase para dibujar.
144
     */
145
    public void drawOperation(Graphics g,double x,
146
        double y) {
147
        CircleCADToolState actualState = _fsm.getState();
148
        String status = actualState.getName();
149

    
150
        if ((status == "ExecuteMap.Initial")) { // || (status == "5")) {
151

    
152
            if (firstPoint != null) {
153
                drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
154
            }
155
        }
156

    
157
        if (status == "ExecuteMap.First") {
158
            Point2D currentPoint = new Point2D.Double(x, y);
159
            ShapeFactory.createCircle(center, currentPoint).draw((Graphics2D) g,
160
                getCadToolAdapter().getMapControl().getViewPort(),
161
                CADTool.modifySymbol);
162
        } else if (status == "ExecuteMap.Second") {
163
            drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
164
        } else if (status == "ExecuteMap.Third") {
165
            Point2D currentPoint = new Point2D.Double(x, y);
166
            IGeometry geom = ShapeFactory.createCircle(firstPoint, secondPoint,
167
                    currentPoint);
168

    
169
            if (geom != null) {
170
                geom.draw((Graphics2D) g,
171
                    getCadToolAdapter().getMapControl().getViewPort(),
172
                    CADTool.modifySymbol);
173
            }
174
        }
175
    }
176

    
177
    /**
178
     * Add a diferent option.
179
     *
180
     * @param sel DOCUMENT ME!
181
     * @param s Diferent option.
182
     */
183
    public void addOption(String s) {
184
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
185
        String status = actualState.getName();
186

    
187
        if (status == "ExecuteMap.Initial") {
188
            if (s.equals("3p") || s.equals("3P")) {
189
                //Opci?n correcta.
190
            }
191
        }
192
    }
193

    
194
    /* (non-Javadoc)
195
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
196
     */
197
    public void addValue(double d) {
198
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
199
        String status = actualState.getName();
200

    
201
        if (status == "ExecuteMap.First") {
202
            addGeometry(ShapeFactory.createCircle(center, d));
203
        }
204
    }
205

    
206
}