Statistics
| Revision:

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

History | View | Annotate | Download (5.19 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
 * DOCUMENT ME!
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"),
66
                        new Status("Precisar segundo punto del desplazamiento"),
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.backgroundExecution(new Runnable() {
91
                                public void run() {
92
                                        lastPoint = new Point2D.Double(values[0], values[1]);
93
                                        try {
94
                                                for (int i = selectedGeometries.nextSetBit(0);
95
                                                i >= 0;
96
                                                i = selectedGeometries.nextSetBit(i + 1)){
97
                                                //for (int i = 0; i < editingSource.getGeometryCount(); i++) {
98
                                                //        if (selectedGeometries.get(i)) {
99
                                                                IGeometry geometry = editingSource.getGeometry(i);
100
                                                                geometry.move(lastPoint.getX() - firstPoint.getX(),
101
                                                                        lastPoint.getY() - firstPoint.getY());
102
                                                                editingSource.addGeometry(geometry);
103
                                                        //}
104
                                                }
105
                                                
106
                                        } catch (DriverIOException e) {
107
                                                e.printStackTrace();
108
                                        } catch (IOException e1) {
109
                                                e1.printStackTrace();
110
                                        }
111
                                        
112
                                        selectedGeometries.clear();
113
                                }
114
                        });
115
                        ret = ret | copyStatus.transition("cancel");
116
                }
117
                return ret;
118
        }
119

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

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

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

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

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