Statistics
| Revision:

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

History | View | Annotate | Download (7.11 KB)

1 3748 caballero
/* 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 3782 caballero
package com.iver.cit.gvsig.gui.cad.tools;
42
43
import java.awt.Graphics;
44
import java.awt.Graphics2D;
45 4313 fjp
import java.awt.event.InputEvent;
46 3782 caballero
import java.awt.geom.Point2D;
47
48 4584 caballero
import com.iver.andami.PluginServices;
49 5170 caballero
import com.iver.cit.gvsig.fmap.core.FShape;
50 3782 caballero
import com.iver.cit.gvsig.fmap.core.IGeometry;
51
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
52
import com.iver.cit.gvsig.gui.cad.CADTool;
53 3832 caballero
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
54 5735 caballero
import com.iver.cit.gvsig.gui.cad.exception.CommandException;
55 3782 caballero
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext;
56
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState;
57
58
59
/**
60
 * DOCUMENT ME!
61
 *
62
 * @author Vicente Caballero Navarro
63
 */
64 3748 caballero
public class CircleCADTool extends DefaultCADTool {
65
    private CircleCADToolContext _fsm;
66
    private Point2D center;
67
    private Point2D firstPoint;
68
    private Point2D secondPoint;
69
    private Point2D thirdPoint;
70
71
    /**
72
     * Crea un nuevo LineCADTool.
73
     */
74
    public CircleCADTool() {
75
    }
76
77
    /**
78
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
79
     * carga previa a la utilizaci?n de la herramienta.
80
     */
81
    public void init() {
82 3782 caballero
        _fsm = new CircleCADToolContext(this);
83 3748 caballero
    }
84
85
    /* (non-Javadoc)
86 3782 caballero
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
87
     */
88 4892 caballero
    public void transition(double x, double y, InputEvent event){
89 4324 caballero
        _fsm.addPoint(x, y, event);
90 3748 caballero
    }
91 3782 caballero
92 3748 caballero
    /* (non-Javadoc)
93 3782 caballero
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
94
     */
95 3883 caballero
    public void transition(double d){
96 3832 caballero
        _fsm.addValue(d);
97 3782 caballero
    }
98 3748 caballero
99 3782 caballero
    /* (non-Javadoc)
100
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
101
     */
102 5735 caballero
    public void transition(String s) throws CommandException{
103 4892 caballero
            if (!super.changeCommand(s)){
104
                    _fsm.addOption(s);
105
            }
106 3782 caballero
    }
107
108 3748 caballero
    /**
109
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
110
     * editableFeatureSource que ya estar? creado.
111
     *
112
     * @param sel Bitset con las geometr?as que est?n seleccionadas.
113
     * @param x par?metro x del punto que se pase en esta transici?n.
114
     * @param y par?metro y del punto que se pase en esta transici?n.
115
     */
116 4365 caballero
    public void addPoint(double x, double y,InputEvent event) {
117 3748 caballero
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
118
        String status = actualState.getName();
119 3766 caballero
120 3978 caballero
        if (status.equals("Circle.CenterPointOr3p")) {
121 3782 caballero
            center = new Point2D.Double(x, y);
122 3978 caballero
        } else if (status == "Circle.PointOrRadius") {
123 5880 fjp
            addGeometry(ShapeFactory.createCircle(center,
124
                    new Point2D.Double(x, y)));
125 3978 caballero
        } else if (status == "Circle.FirstPoint") {
126 3782 caballero
            firstPoint = new Point2D.Double(x, y);
127 3978 caballero
        } else if (status == "Circle.SecondPoint") {
128 3782 caballero
            secondPoint = new Point2D.Double(x, y);
129 3978 caballero
        } else if (status == "Circle.ThirdPoint") {
130 3782 caballero
            thirdPoint = new Point2D.Double(x, y);
131 5880 fjp
            addGeometry(ShapeFactory.createCircle(firstPoint, secondPoint,
132
                    thirdPoint));
133 3782 caballero
        }
134
    }
135 3748 caballero
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 3832 caballero
    public void drawOperation(Graphics g,double x,
146 3748 caballero
        double y) {
147
        CircleCADToolState actualState = _fsm.getState();
148
        String status = actualState.getName();
149
150 3978 caballero
        if ((status == "Circle.CenterPointOr3p")) { // || (status == "5")) {
151 3748 caballero
152
            if (firstPoint != null) {
153
                drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
154
            }
155
        }
156 3782 caballero
157 3978 caballero
        if (status == "Circle.PointOrRadius") {
158 3782 caballero
            Point2D currentPoint = new Point2D.Double(x, y);
159 5880 fjp
            ShapeFactory.createCircle(center, currentPoint).draw((Graphics2D) g,
160
                getCadToolAdapter().getMapControl().getViewPort(),
161
                CADTool.drawingSymbol);
162 3978 caballero
        } else if (status == "Circle.SecondPoint") {
163 3782 caballero
            drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
164 3978 caballero
        } else if (status == "Circle.ThirdPoint") {
165 3782 caballero
            Point2D currentPoint = new Point2D.Double(x, y);
166
            IGeometry geom = ShapeFactory.createCircle(firstPoint, secondPoint,
167
                    currentPoint);
168 5880 fjp
169 3782 caballero
            if (geom != null) {
170 5880 fjp
                geom.draw((Graphics2D) g,
171 3782 caballero
                    getCadToolAdapter().getMapControl().getViewPort(),
172 3997 fjp
                    CADTool.drawingSymbol);
173 3782 caballero
            }
174
        }
175 3748 caballero
    }
176
177
    /**
178
     * Add a diferent option.
179
     *
180 3782 caballero
     * @param sel DOCUMENT ME!
181 3748 caballero
     * @param s Diferent option.
182
     */
183 3832 caballero
    public void addOption(String s) {
184 3782 caballero
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
185 3748 caballero
        String status = actualState.getName();
186 3782 caballero
187 3978 caballero
        if (status == "Circle.CenterPointOr3p") {
188 9121 caballero
            if (s.equalsIgnoreCase(PluginServices.getText(this,"CircleCADTool.3p"))) {
189 3782 caballero
                //Opci?n correcta.
190
            }
191
        }
192 3748 caballero
    }
193
194
    /* (non-Javadoc)
195
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
196
     */
197 3832 caballero
    public void addValue(double d) {
198 3748 caballero
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
199
        String status = actualState.getName();
200
201 3978 caballero
        if (status == "Circle.PointOrRadius") {
202 5880 fjp
            addGeometry(ShapeFactory.createCircle(center, d));
203 3782 caballero
        }
204 3748 caballero
    }
205 3883 caballero
206 4118 caballero
        public String getName() {
207 4584 caballero
                return PluginServices.getText(this,"circle_");
208 4118 caballero
        }
209
210 4892 caballero
        public String toString() {
211
                return "_circle";
212
        }
213
214 5170 caballero
        public boolean isApplicable(int shapeType) {
215
                switch (shapeType) {
216
                case FShape.POINT:
217 6024 caballero
                case FShape.MULTIPOINT:
218 5170 caballero
                        return false;
219
                }
220
                return true;
221
        }
222
223 3748 caballero
}