Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / MultiPointCADTool.java @ 24363

History | View | Annotate | Download (6.54 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.util.ArrayList;
47

    
48
import org.gvsig.fmap.geom.Geometry;
49
import org.gvsig.fmap.geom.GeometryFactory;
50
import org.gvsig.fmap.geom.GeometryManager;
51
import org.gvsig.fmap.geom.operation.Draw;
52
import org.gvsig.fmap.geom.operation.DrawOperationContext;
53
import org.gvsig.fmap.geom.operation.GeometryOperationException;
54
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
55

    
56
import com.iver.andami.PluginServices;
57
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
58
import com.iver.cit.gvsig.gui.cad.exception.CommandException;
59
import com.iver.cit.gvsig.gui.cad.tools.smc.MultiPointCADToolContext;
60
import com.iver.cit.gvsig.gui.cad.tools.smc.MultiPointCADToolContext.MultiPointCADToolState;
61

    
62

    
63
/**
64
 * DOCUMENT ME!
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class MultiPointCADTool extends DefaultCADTool {
69
    private MultiPointCADToolContext _fsm;
70
    private ArrayList points=new ArrayList();
71
    private GeometryFactory geomFactory=GeometryManager.getInstance().getGeometryFactory();
72

    
73
    /**
74
     * Crea un nuevo PointCADTool.
75
     */
76
    public MultiPointCADTool() {
77

    
78
    }
79

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

    
88
    /**
89
     * DOCUMENT ME!
90
     * @param x DOCUMENT ME!
91
     * @param y DOCUMENT ME!
92
     * @param sel DOCUMENT ME!
93
     */
94
    public void transition(double x, double y, InputEvent event) {
95
        _fsm.addPoint(x, y, event);
96
    }
97

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

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

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

    
126
        if (status.equals("MultiPoint.InsertPoint")) {
127
            points.add(new double[] {x,y});
128
                //addGeometry(ShapeFactory.createPoint2D(x, y));
129
        }
130
    }
131

    
132
    /**
133
     * M?todo para dibujar la lo necesario para el estado en el que nos
134
     * encontremos.
135
     *
136
     * @param g Graphics sobre el que dibujar.
137
     * @param selectedGeometries BitSet con las geometr?as seleccionadas.
138
     * @param x par?metro x del punto que se pase para dibujar.
139
     * @param y par?metro x del punto que se pase para dibujar.
140
     */
141
    public void drawOperation(Graphics g, double x,
142
        double y) {
143
            int num=points.size();
144
                double[] xs=new double[num];
145
                double[] ys=new double[num];
146
                for (int i=0;i<num;i++) {
147
                        double[] p=(double[])points.get(i);
148
                        xs[i]=p[0];
149
                        ys[i]=p[1];
150
                }
151

    
152
                DrawOperationContext doc=new DrawOperationContext();
153
                doc.setGraphics((Graphics2D)g);
154
                doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort());
155
                doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
156
            try {
157
                    geomFactory.createMultipoint2D(xs,ys).invokeOperation(Draw.CODE,doc);
158
                    geomFactory.createPoint2D(x,y).invokeOperation(Draw.CODE,doc);
159
                } catch (GeometryOperationNotSupportedException e) {
160
                        e.printStackTrace();
161
                } catch (GeometryOperationException e) {
162
                        e.printStackTrace();
163
                }
164

    
165
//                geomFactory.createMultipoint2D(xs,ys).draw((Graphics2D) g,
166
//                getCadToolAdapter().getMapControl().getViewPort(),
167
//                DefaultCADTool.geometrySelectSymbol);
168
//                geomFactory.createPoint2D(x,y).draw((Graphics2D) g,
169
//                getCadToolAdapter().getMapControl().getViewPort(),
170
//                DefaultCADTool.geometrySelectSymbol);
171
    }
172

    
173
    /**
174
     * Add a diferent option.
175
     *
176
     * @param sel DOCUMENT ME!
177
     * @param s Diferent option.
178
     */
179
    public void addOption(String s) {
180
        // TODO Auto-generated method stub
181
    }
182

    
183
    /* (non-Javadoc)
184
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
185
     */
186
    public void addValue(double d) {
187
        // TODO Auto-generated method stub
188
    }
189

    
190
        public String getName() {
191
                return PluginServices.getText(this,"multipoint_");
192
        }
193

    
194
        public String toString() {
195
                return "_multipoint";
196
        }
197
        public boolean isApplicable(int shapeType) {
198
                switch (shapeType) {
199
                case Geometry.TYPES.MULTIPOINT:
200
                        return true;
201
                }
202
                return false;
203
        }
204

    
205
        public void endGeometry() {
206
                int num=points.size();
207
                double[] xs=new double[num];
208
                double[] ys=new double[num];
209
                for (int i=0;i<num;i++) {
210
                        double[] p=(double[])points.get(i);
211
                        xs[i]=p[0];
212
                        ys[i]=p[1];
213
                }
214
                addGeometry(geomFactory.createMultipoint2D(xs,ys));
215
                end();
216
        }
217
        public void end() {
218
                points.clear();
219
                super.end();
220
        }
221
}