Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / CircleCADTool.java @ 30335

History | View | Annotate | Download (7.89 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 org.gvsig.editing.gui.cad.tools;
42

    
43
import java.awt.Graphics2D;
44
import java.awt.Image;
45
import java.awt.event.InputEvent;
46
import java.awt.geom.Point2D;
47

    
48
import org.gvsig.andami.PluginServices;
49
import org.gvsig.editing.gui.cad.DefaultCADTool;
50
import org.gvsig.editing.gui.cad.exception.CommandException;
51
import org.gvsig.editing.gui.cad.tools.smc.CircleCADToolContext;
52
import org.gvsig.editing.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState;
53
import org.gvsig.editing.layers.VectorialLayerEdited;
54
import org.gvsig.fmap.geom.Geometry;
55
import org.gvsig.fmap.geom.operation.Draw;
56
import org.gvsig.fmap.geom.operation.DrawOperationContext;
57
import org.gvsig.fmap.geom.operation.GeometryOperationException;
58
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
59
import org.gvsig.fmap.geom.primitive.Circle;
60
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
61

    
62

    
63

    
64
/**
65
 * DOCUMENT ME!
66
 *
67
 * @author Vicente Caballero Navarro
68
 */
69
public class CircleCADTool extends DefaultCADTool {
70
    protected CircleCADToolContext _fsm;
71
    protected Point2D center;
72
    protected Point2D firstPoint;
73
    protected Point2D secondPoint;
74
    protected Point2D thirdPoint;
75

    
76
    /**
77
     * Crea un nuevo LineCADTool.
78
     */
79
    public CircleCADTool() {
80
    }
81

    
82
    /**
83
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
84
     * carga previa a la utilizaci?n de la herramienta.
85
     */
86
    public void init() {
87
        _fsm = new CircleCADToolContext(this);
88
    }
89

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

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

    
104
    /* (non-Javadoc)
105
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
106
     */
107
    public void transition(String s) throws CommandException{
108
            if (!super.changeCommand(s)){
109
                    _fsm.addOption(s);
110
            }
111
    }
112

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

    
125
        if (status.equals("Circle.CenterPointOr3p")) {
126
            center = new Point2D.Double(x, y);
127
        } else if (status == "Circle.PointOrRadius") {
128
                insertAndSelectGeometry(createCircle(createPoint(center),
129
                                createPoint(x, y)));
130
        } else if (status == "Circle.FirstPoint") {
131
            firstPoint = new Point2D.Double(x, y);
132
        } else if (status == "Circle.SecondPoint") {
133
            secondPoint = new Point2D.Double(x, y);
134
        } else if (status == "Circle.ThirdPoint") {
135
                thirdPoint = new Point2D.Double(x, y);
136
                insertAndSelectGeometry(createCircle(createPoint(firstPoint),
137
                                createPoint(secondPoint),
138
                                createPoint(thirdPoint)));
139
        }
140
    }
141

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

    
156
        if ((status == "Circle.CenterPointOr3p")) { // || (status == "5")) {
157

    
158
            if (firstPoint != null) {
159
                renderer.drawLine(firstPoint, new Point2D.Double(x, y), mapControlManager.getGeometrySelectionSymbol());
160
            }
161
        }
162

    
163
        if (status == "Circle.PointOrRadius") {
164
            Point2D currentPoint = new Point2D.Double(x, y);
165
            DrawOperationContext doc=new DrawOperationContext();
166
                        Circle circle = createCircle(createPoint(center), createPoint(currentPoint));
167
            renderer.draw(circle, mapControlManager.getAxisReferenceSymbol());                         
168
        } else if (status == "Circle.SecondPoint") {
169
            renderer.drawLine(firstPoint, new Point2D.Double(x, y), mapControlManager.getGeometrySelectionSymbol());                
170
        } else if (status == "Circle.ThirdPoint") {
171
            Point2D currentPoint = new Point2D.Double(x, y);
172
            Geometry geom = createCircle(createPoint(firstPoint),
173
                            createPoint(secondPoint),
174
                    createPoint(currentPoint));
175

    
176
            if (geom != null) {
177
                    renderer.draw(geom, mapControlManager.getAxisReferenceSymbol());                                    
178
            }
179
        }else{
180
                VectorialLayerEdited vle=getVLE();
181
                if (!vle.getLayer().isVisible())
182
                        return;
183
                try{
184
                        Image imgSel = vle.getSelectionImage();
185
                        renderer.drawImage(imgSel, 0, 0);
186
                        
187
                        Image imgHand = vle.getHandlersImage();
188
                        renderer.drawImage(imgHand, 0, 0);
189
                }catch (Exception e) {
190
                }
191
        }
192
    }
193

    
194
    /**
195
     * Add a diferent option.
196
     *
197
     * @param sel DOCUMENT ME!
198
     * @param s Diferent option.
199
     */
200
    public void addOption(String s) {
201
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
202
        String status = actualState.getName();
203

    
204
        if (status == "Circle.CenterPointOr3p") {
205
            if (s.equalsIgnoreCase(PluginServices.getText(this,"CircleCADTool.3p"))) {
206
                //Opci?n correcta.
207
            }
208
        }
209
    }
210

    
211
    /* (non-Javadoc)
212
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
213
     */
214
    public void addValue(double d) {
215
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
216
        String status = actualState.getName();
217

    
218
        if (status == "Circle.PointOrRadius") {
219
                insertAndSelectGeometry(createCircle(createPoint(center), d));
220
        }
221
    }
222

    
223
        public String getName() {
224
                return PluginServices.getText(this,"circle_");
225
        }
226

    
227
        public String toString() {
228
                return "_circle";
229
        }
230

    
231
        public boolean isApplicable(int shapeType) {
232
                switch (shapeType) {
233
                case Geometry.TYPES.POINT:
234
                case Geometry.TYPES.MULTIPOINT:
235
                        return false;
236
                }
237
                return true;
238
        }
239

    
240
}