Statistics
| Revision:

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

History | View | Annotate | Download (6.5 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.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.exception.CommandException;
54
import com.iver.cit.gvsig.gui.cad.tools.smc.EllipseCADToolContext;
55
import com.iver.cit.gvsig.gui.cad.tools.smc.EllipseCADToolContext.EllipseCADToolState;
56

    
57

    
58
/**
59
 * DOCUMENT ME!
60
 *
61
 * @author Vicente Caballero Navarro
62
 */
63
public class EllipseCADTool extends DefaultCADTool {
64
    private EllipseCADToolContext _fsm;
65
    private Point2D startAxis;
66
    private Point2D endAxis;
67

    
68
    /**
69
     * Crea un nuevo LineCADTool.
70
     */
71
    public EllipseCADTool() {
72

    
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 EllipseCADToolContext(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, InputEvent event) {
87
        _fsm.addPoint(x, y, event);
88
    }
89

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

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

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

    
118
        if (status.equals("Ellipse.FirstPointAxis")) {
119
            startAxis = new Point2D.Double(x, y);
120
        } else if (status.equals("Ellipse.SecondPointAxis")) {
121
            endAxis = new Point2D.Double(x, y);
122
        } else if (status.equals("Ellipse.DistanceOtherAxis")) {
123
            Point2D middle = new Point2D.Double((startAxis.getX() +
124
                    endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2);
125
            Point2D third = new Point2D.Double(x, y);
126
            double distance = middle.distance(third);
127
            addGeometry(ShapeFactory.createEllipse(startAxis, endAxis, distance));
128
        }
129
    }
130

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

    
145
        if (status.equals("Ellipse.SecondPointAxis")) {
146
            drawLine((Graphics2D) g, startAxis, new Point2D.Double(x, y));
147
        } else if (status.equals("Ellipse.DistanceOtherAxis")) {
148
            Point2D middle = new Point2D.Double((startAxis.getX() +
149
                    endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2);
150

    
151
            Point2D third = new Point2D.Double(x, y);
152

    
153
            double distance = middle.distance(third);
154

    
155
            ShapeFactory.createEllipse(startAxis, endAxis, distance).draw((Graphics2D) g,
156
                getCadToolAdapter().getMapControl().getViewPort(),
157
                CADTool.modifySymbol);
158

    
159
            Point2D mediop = new Point2D.Double((startAxis.getX() +
160
                    endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2);
161
            drawLine((Graphics2D) g, mediop, third);
162
        }
163
    }
164

    
165
    /**
166
     * Add a diferent option.
167
     *
168
     * @param sel DOCUMENT ME!
169
     * @param s Diferent option.
170
     */
171
    public void addOption(String s) {
172
        // TODO Auto-generated method stub
173
    }
174

    
175
    /* (non-Javadoc)
176
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
177
     */
178
    public void addValue(double d) {
179
        EllipseCADToolState actualState = (EllipseCADToolState) _fsm.getPreviousState();
180
        String status = actualState.getName();
181

    
182
        if (status.equals("Ellipse.DistanceOtherAxis")) {
183
            double distance = d;
184
            addGeometry(ShapeFactory.createEllipse(startAxis, endAxis, distance));
185
        }
186
    }
187

    
188
        public String getName() {
189
                return PluginServices.getText(this,"ellipse_");
190
        }
191

    
192
        public String toString() {
193
                return "_ellipse";
194
        }
195
        public boolean isApplicable(int shapeType) {
196
                switch (shapeType) {
197
                case FShape.POINT:
198
                        return false;
199
                }
200
                return true;
201
        }
202
}