Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / ArcCADTool.java @ 4465

History | View | Annotate | Download (5.64 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.cit.gvsig.fmap.core.IGeometry;
49
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
50
import com.iver.cit.gvsig.gui.cad.CADTool;
51
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
52
import com.iver.cit.gvsig.gui.cad.tools.smc.ArcCADToolContext;
53
import com.iver.cit.gvsig.gui.cad.tools.smc.ArcCADToolContext.ArcCADToolState;
54

    
55

    
56
/**
57
 * DOCUMENT ME!
58
 *
59
 * @author Vicente Caballero Navarro
60
 */
61
public class ArcCADTool extends DefaultCADTool {
62
    private ArcCADToolContext _fsm;
63
    private Point2D p1;
64
    private Point2D p2;
65
    private Point2D p3;
66

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

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

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

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

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

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

    
114
        if (status.equals("Arc.FirstPoint")) {
115
            p1 = new Point2D.Double(x, y);
116
        } else if (status.equals("Arc.SecondPoint")) {
117
            p2 = new Point2D.Double(x, y);
118
        } else if (status.equals("Arc.ThirdPoint")) {
119
            p3 = new Point2D.Double(x, y);
120

    
121
            IGeometry ig = ShapeFactory.createArc(p1, p2, p3);
122

    
123
            if (ig != null) {
124
                addGeometry(ig);
125
            }
126
        }
127
    }
128

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

    
143
        if (status.equals("Arc.SecondPoint")) {
144
            drawLine((Graphics2D) g, p1, new Point2D.Double(x, y));
145
        } else if (status.equals("Arc.ThirdPoint")) {
146
            Point2D current = new Point2D.Double(x, y);
147
            IGeometry ig = ShapeFactory.createArc(p1, p2, current);
148

    
149
            if (ig != null) {
150
                ig.draw((Graphics2D) g,
151
                    getCadToolAdapter().getMapControl().getViewPort(),
152
                    CADTool.modifySymbol);
153
            }
154

    
155
            Point2D p = getCadToolAdapter().getMapControl().getViewPort()
156
                            .fromMapPoint(p1.getX(), p1.getY());
157
            g.drawRect((int) p.getX(), (int) p.getY(), 1, 1);
158
            p = getCadToolAdapter().getMapControl().getViewPort().fromMapPoint(p2.getX(),
159
                    p2.getY());
160
            g.drawRect((int) p.getX(), (int) p.getY(), 1, 1);
161
        }
162
    }
163

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

    
174
    /* (non-Javadoc)
175
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
176
     */
177
    public void addValue(double d) {
178
    }
179

    
180
        public String getName() {
181
                return "ARCO";
182
        }
183

    
184
}