Statistics
| Revision:

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

History | View | Annotate | Download (5.71 KB)

1
package com.iver.cit.gvsig.gui.cad.tools;
2

    
3
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
4
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
5
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
6
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
7
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
8
import com.iver.cit.gvsig.fmap.layers.FBitSet;
9
import com.iver.cit.gvsig.gui.cad.tools.smc.LineCADToolContext;//.LineCADToolState;
10
import com.iver.cit.gvsig.gui.cad.tools.smc.LineCADToolContext.LineCADToolState;
11

    
12
import java.awt.Graphics;
13
import java.awt.Graphics2D;
14
import java.awt.geom.Point2D;
15
import java.io.IOException;
16

    
17
import java.util.BitSet;
18

    
19

    
20
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
21
 *
22
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
23
 *
24
 * This program is free software; you can redistribute it and/or
25
 * modify it under the terms of the GNU General Public License
26
 * as published by the Free Software Foundation; either version 2
27
 * of the License, or (at your option) any later version.
28
 *
29
 * This program is distributed in the hope that it will be useful,
30
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
 * GNU General Public License for more details.
33
 *
34
 * You should have received a copy of the GNU General Public License
35
 * along with this program; if not, write to the Free Software
36
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
37
 *
38
 * For more information, contact:
39
 *
40
 *  Generalitat Valenciana
41
 *   Conselleria d'Infraestructures i Transport
42
 *   Av. Blasco Ib??ez, 50
43
 *   46010 VALENCIA
44
 *   SPAIN
45
 *
46
 *      +34 963862235
47
 *   gvsig@gva.es
48
 *      www.gvsig.gva.es
49
 *
50
 *    or
51
 *
52
 *   IVER T.I. S.A
53
 *   Salamanca 50
54
 *   46005 Valencia
55
 *   Spain
56
 *
57
 *   +34 963163400
58
 *   dac@iver.es
59
 */
60
public class LineCADTool extends DefaultCADTool {
61
    private LineCADToolContext _fsm;
62
    private VectorialEditableAdapter vea;
63
    private String question;
64
    private Point2D firstPoint;
65
    private Point2D lastPoint;
66
    private double angle;
67
        private double length;
68
public LineCADTool(){
69
        _fsm=new LineCADToolContext(this);
70
}
71
    /**
72
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
73
     * carga previa a la utilizaci?n de la herramienta.
74
     */
75
    public void init() {
76

    
77
    }
78
    public void transition(FBitSet sel, double x, double y){
79
                _fsm.addpoint(sel,x,y);
80
        }
81
    /**
82
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
83
     * editableFeatureSource que ya estar? creado.
84
     *
85
     * @param sel Bitset con las geometr?as que est?n seleccionadas.
86
     * @param x par?metro x del punto que se pase en esta transici?n.
87
     * @param y par?metro y del punto que se pase en esta transici?n.
88
     */
89
    public void addpoint(FBitSet sel, double x, double y) {
90
       // _fsm.addpoint(sel, x, y);
91

    
92
        LineCADToolState actualState = (LineCADToolState)_fsm.getPreviousState();
93
      //  CADToolState previousState=(CADToolState)_fsm.getPreviousState();
94
        String status = actualState.getName();
95
       // String previousstatus=previousState.getName();
96

    
97
        if (status.equals("ExecuteMap.Initial")) {
98
                firstPoint=new Point2D.Double(x,y);
99
                System.out.println("Question : "+question);
100
        } else if (status == "ExecuteMap.First") {
101
                        firstPoint=new Point2D.Double(x,y);
102
                        System.out.println("Question : "+question);
103

    
104
                } else if (status == "ExecuteMap.Second") {
105
                        System.out.println("Question : "+question);
106
                        //firstPoint=lastPoint;
107
                        lastPoint=new Point2D.Double(x,y);
108
                        try {
109
                                GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
110
                                                2);
111
                                elShape.moveTo(firstPoint.getX(), firstPoint.getY());
112
                                elShape.lineTo(lastPoint.getX(), lastPoint.getY());
113
                                DefaultFeature df=new DefaultFeature(ShapeFactory.createPolyline2D(elShape),null);
114
                                vea.addRow(df);
115
                        } catch (DriverIOException e) {
116
                                e.printStackTrace();
117
                        } catch (IOException e) {
118
                                e.printStackTrace();
119
                        }
120
                        firstPoint=lastPoint;
121
                }
122

    
123
    }
124

    
125
    /**
126
     * Devuelve la cadena que corresponde al estado en el que nos encontramos.
127
     *
128
     * @return Cadena para mostrar por consola.
129
     */
130
    public String getQuestion() {
131
            System.out.println("Question : "+question);
132
        return question;
133
    }
134

    
135
    /**
136
     * Devuelve el nombre de la clase en la que nos encontramos.
137
     *
138
     * @return Nombre de la clase en la que nos encontramos.
139
     */
140
    public String getName() {
141
        return this.getClass().getName();
142
    }
143

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

    
157
             if ((status == "ExecuteMap.Second")){// || (status == "5")) {
158
                        if (firstPoint!=null)
159
                        drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y));
160
             }
161
        }
162

    
163
    /**
164
     * Actualiza la cadena que corresponde al estado actual.
165
     *
166
     * @param s Cadena que aparecer? en consola.
167
     */
168
    public void setQuestion(String s) {
169
        question = s;
170
    }
171

    
172
    /**
173
     * Add a diferent option.
174
     *
175
     * @param s Diferent option.
176
     */
177
    public void addoption(String s) {
178
        // TODO Auto-generated method stub
179
    }
180
    public void refresh(){
181

    
182
    }
183
        public void setVectorialAdapter(VectorialEditableAdapter vea) {
184
        this.vea=vea;
185

    
186
        }
187
}