Statistics
| Revision:

root / branches / gvSIG_CAD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / CopyCadTool.java @ 3513

History | View | Annotate | Download (5.32 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.Image;
45
import java.awt.geom.Point2D;
46
import java.io.IOException;
47

    
48
import com.iver.andami.PluginServices;
49
import com.iver.cit.gvsig.fmap.core.IGeometry;
50
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
51
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource;
52
import com.iver.cit.gvsig.fmap.edition.cad.Status;
53
import com.iver.cit.gvsig.fmap.layers.FBitSet;
54
import com.iver.cit.gvsig.gui.cad.automaton.Copiar;
55
import com.iver.fsac.Automaton;
56

    
57

    
58
/**
59
 * Herramienta para copiar una geometr?a.
60
 *
61
 * @author Vicente Caballero Navarro
62
 */
63
public class CopyCadTool extends AbstractCadTool {
64
        private static Status[] STATUS = {
65
                        new Status("Precisar punto de desplazamiento(x,y):"),
66
                        new Status("Precisar segundo punto del desplazamiento(x,y):"),
67
                };
68
        private Copiar copyStatus = new Copiar();
69
        private Point2D firstPoint;
70
        private Point2D lastPoint;
71
        
72
        /**
73
         * @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
74
         *                 com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
75
         *                 com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
76
         */
77
        public int transition(String text, final EditableFeatureSource editingSource,
78
                final FBitSet selectedGeometries, final double[] values) {
79
                int ret = copyStatus.transition(text);
80

    
81
                int status = copyStatus.getStatus();
82

    
83
                if (status == 0) {
84
                        if (selectedGeometries.cardinality() == 0){
85
                                getCadToolAdapter().pushCadTool(new SelectionCadTool());
86
                        }
87
                } else if (status == 1) {
88
                        firstPoint = new Point2D.Double(values[0], values[1]);
89
                } else if (status == 2) {
90
                        PluginServices.getMDIManager().setWaitCursor();
91
                                        lastPoint = new Point2D.Double(values[0], values[1]);
92
                                        try {
93
                                                editingSource.startComplexGeometry();
94
                                                for (int i = selectedGeometries.nextSetBit(0);
95
                                                i >= 0;
96
                                                i = selectedGeometries.nextSetBit(i + 1)){
97
                                        
98
                                                        IGeometry geometry = editingSource.getGeometry(i);
99
                                                                geometry.move(lastPoint.getX() - firstPoint.getX(),
100
                                                                        lastPoint.getY() - firstPoint.getY());
101
                                                                editingSource.addGeometry(geometry);
102
                                                                
103
                                                }
104
                                                editingSource.endComplexGeometry();
105
                                        } catch (DriverIOException e) {
106
                                                e.printStackTrace();
107
                                        } catch (IOException e1) {
108
                                                e1.printStackTrace();
109
                                        }
110
                                        
111
                                        selectedGeometries.clear();
112
                                        PluginServices.getMDIManager().restoreCursor();
113
                        ret = ret | copyStatus.transition("cancel");
114
                }
115
                return ret;
116
        }
117

    
118
        /**
119
         * @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
120
         *                 com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
121
         *                 com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
122
         */
123
        public void drawOperation(Graphics g, EditableFeatureSource efs,
124
                FBitSet selectedGeometries, double x, double y) {
125
                int status = copyStatus.getStatus();
126

    
127
                if (status == 1) {
128
                        int dx = getCadToolAdapter().getMapControl().getViewPort().fromMapDistance(x - firstPoint.getX());
129
                        int dy = -getCadToolAdapter().getMapControl().getViewPort().fromMapDistance(y - firstPoint.getY());
130
                        Image img = getCadToolAdapter().getEditableFeatureSource().getImage();
131
                        g.drawImage(img, dx, dy, null);
132
/*                        try {
133
                                for (int i = selectedGeometries.nextSetBit(0);
134
                                i >= 0;
135
                                i = selectedGeometries.nextSetBit(i + 1)){
136
                                        IGeometry geometry = efs.getGeometry(i).cloneGeometry();
137
                                        geometry.move(x - firstPoint.getX(),
138
                                                        y - firstPoint.getY());
139
                                                geometry.draw((Graphics2D) g,
140
                                                        getCadToolAdapter().getMapControl().getViewPort(),
141
                                                        CadTool.drawingSymbol);
142
                                }
143
                        } catch (DriverIOException e) {
144
                                e.printStackTrace();
145
                        } catch (IOException e) {
146
                                e.printStackTrace();
147
                        }
148
                        */
149
                }
150
        }
151

    
152
        /**
153
         * @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
154
         */
155
        public String getQuestion() {
156
                return STATUS[copyStatus.getStatus()].getQuestion();
157
        }
158

    
159
        /**
160
         * @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
161
         */
162
        public void initializeStatus() {
163
                copyStatus.initialize();
164
        }
165

    
166
        /**
167
         * @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
168
         */
169
        public Automaton getAutomaton() {
170
                return copyStatus;
171
        }
172

    
173
        /**
174
         * @see com.iver.cit.gvsig.gui.cad.CadTool#getName()
175
         */
176
        public String getName() {
177
                return "COPIAR";
178
        }
179
}