Statistics
| Revision:

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

History | View | Annotate | Download (8.61 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.event.InputEvent;
46
import java.awt.geom.Point2D;
47

    
48
import com.iver.andami.PluginServices;
49
import com.iver.cit.gvsig.fmap.core.FShape;
50
import com.iver.cit.gvsig.fmap.core.IGeometry;
51
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
52
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
53
import com.iver.cit.gvsig.gui.cad.CADTool;
54
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
55
import com.iver.cit.gvsig.gui.cad.exception.CommandException;
56
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext;
57
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState;
58

    
59

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

    
72
    /**
73
     * Crea un nuevo LineCADTool.
74
     */
75
    public CircleCADTool() {
76
    }
77

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

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

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

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

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

    
121
        if (status.equals("Circle.CenterPointOr3p")) {
122
            center = new Point2D.Double(x, y);
123
        } else if (status == "Circle.PointOrRadius") {
124
            IGeometry geom=ShapeFactory.createCircle(center,
125
                    new Point2D.Double(x, y));
126
//            try {
127
//                            if (getVLE().getVEA().getShapeType()==FShape.LINE)
128
//                                    geom.setGeometryType(FShape.LINE);
129
//                            else
130
//                                    geom.setGeometryType(FShape.POLYGON);
131
//            } catch (DriverIOException e) {
132
//                            e.printStackTrace();
133
//                    }
134
            addGeometry(geom);
135
        } else if (status == "Circle.FirstPoint") {
136
            firstPoint = new Point2D.Double(x, y);
137
        } else if (status == "Circle.SecondPoint") {
138
            secondPoint = new Point2D.Double(x, y);
139
        } else if (status == "Circle.ThirdPoint") {
140
            thirdPoint = new Point2D.Double(x, y);
141
            IGeometry geom=ShapeFactory.createCircle(firstPoint, secondPoint,
142
                    thirdPoint);
143
//            try {
144
//                            if (getVLE().getVEA().getShapeType()==FShape.LINE)
145
//                                    geom.setGeometryType(FShape.LINE);
146
//                            else
147
//                                    geom.setGeometryType(FShape.POLYGON);
148
//            } catch (DriverIOException e) {
149
//                            e.printStackTrace();
150
//                    }
151
            addGeometry(geom);
152
        }
153
    }
154

    
155
    /**
156
     * M?todo para dibujar la lo necesario para el estado en el que nos
157
     * encontremos.
158
     *
159
     * @param g Graphics sobre el que dibujar.
160
     * @param selectedGeometries BitSet con las geometr?as seleccionadas.
161
     * @param x par?metro x del punto que se pase para dibujar.
162
     * @param y par?metro x del punto que se pase para dibujar.
163
     */
164
    public void drawOperation(Graphics g,double x,
165
        double y) {
166
        CircleCADToolState actualState = _fsm.getState();
167
        String status = actualState.getName();
168

    
169
        if ((status == "Circle.CenterPointOr3p")) { // || (status == "5")) {
170

    
171
            if (firstPoint != null) {
172
                drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
173
            }
174
        }
175

    
176
        if (status == "Circle.PointOrRadius") {
177
            Point2D currentPoint = new Point2D.Double(x, y);
178
            IGeometry geom=ShapeFactory.createCircle(center, currentPoint);
179
//            try {
180
//                            if (getVLE().getVEA().getShapeType()==FShape.LINE)
181
//                                    geom.setGeometryType(FShape.LINE);
182
//                            else
183
//                                    geom.setGeometryType(FShape.POLYGON);
184
//            } catch (DriverIOException e) {
185
//                            e.printStackTrace();
186
//                    }
187
            if (geom!=null)
188
                    geom.drawInts((Graphics2D) g,
189
                    getCadToolAdapter().getMapControl().getViewPort(),
190
                    CADTool.drawingSymbol);
191
        } else if (status == "Circle.SecondPoint") {
192
            drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
193
        } else if (status == "Circle.ThirdPoint") {
194
            Point2D currentPoint = new Point2D.Double(x, y);
195
            IGeometry geom = ShapeFactory.createCircle(firstPoint, secondPoint,
196
                    currentPoint);
197
//            try {
198
//                            if (getVLE().getVEA().getShapeType()==FShape.LINE)
199
//                                    geom.setGeometryType(FShape.LINE);
200
//                            else
201
//                                    geom.setGeometryType(FShape.POLYGON);
202
//            } catch (DriverIOException e) {
203
//                            e.printStackTrace();
204
//                    }
205
            if (geom != null) {
206
                geom.drawInts((Graphics2D) g,
207
                    getCadToolAdapter().getMapControl().getViewPort(),
208
                    CADTool.drawingSymbol);
209
            }
210
        }
211
    }
212

    
213
    /**
214
     * Add a diferent option.
215
     *
216
     * @param sel DOCUMENT ME!
217
     * @param s Diferent option.
218
     */
219
    public void addOption(String s) {
220
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
221
        String status = actualState.getName();
222

    
223
        if (status == "Circle.CenterPointOr3p") {
224
            if (s.equals("3p") || s.equals("3P")) {
225
                //Opci?n correcta.
226
            }
227
        }
228
    }
229

    
230
    /* (non-Javadoc)
231
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
232
     */
233
    public void addValue(double d) {
234
        CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState();
235
        String status = actualState.getName();
236

    
237
        if (status == "Circle.PointOrRadius") {
238
            IGeometry geom=ShapeFactory.createCircle(center, d);
239
//            try {
240
//                            if (getVLE().getVEA().getShapeType()==FShape.LINE)
241
//                                    geom.setGeometryType(FShape.LINE);
242
//                            else
243
//                                    geom.setGeometryType(FShape.POLYGON);
244
//            } catch (DriverIOException e) {
245
//                            e.printStackTrace();
246
//                    }
247
            addGeometry(geom);
248
        }
249
    }
250

    
251
        public String getName() {
252
                return PluginServices.getText(this,"circle_");
253
        }
254

    
255
        public String toString() {
256
                return "_circle";
257
        }
258

    
259
        public boolean isApplicable(int shapeType) {
260
                switch (shapeType) {
261
                case FShape.POINT:
262
                        return false;
263
                }
264
                return true;
265
        }
266

    
267
}