Statistics
| Revision:

svn-gvsig-desktop / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / ScaleCadTool.java @ 1614

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

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

    
60
/**
61
* DOCUMENT ME!
62
*
63
* @author Vicente Caballero Navarro
64
*/
65
public class ScaleCadTool extends AbstractCadTool {
66
        private static Status[] STATUS = {
67
                        new Status("Precise punto base"),
68
                        new Status("Precise factor de escala"),
69
                };
70
        private Escalar scaleStatus = new Escalar();
71
        private Point2D firstPoint;
72
        private Point2D lastPoint;
73

    
74
        /**
75
         * @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
76
         *                 com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
77
         *                 com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
78
         */
79
        public int transition(String text, final EditableFeatureSource editingSource,
80
                final FBitSet selectedGeometries, final double[] ds) {
81
                int ret = scaleStatus.transition(text);
82
                int status = scaleStatus.getStatus();
83

    
84
                if (status == 0) {
85
                        if (selectedGeometries.cardinality() == 0){
86
                                getCadToolAdapter().pushCadTool(new SelectionCadTool());
87
                        }
88
                } else if (status == 1) {
89
                        if (ds.length!=0){
90
                        firstPoint = new Point2D.Double(ds[0], ds[1]);
91
                        }
92
                } else if (status == 2) {
93
                        PluginServices.getMDIManager().setWaitCursor();
94
                                        lastPoint = new Point2D.Double(ds[0], ds[1]);
95
                                        double w;
96
                                        double h;
97
                                                w=lastPoint.getX()-firstPoint.getX();
98
                                                h=lastPoint.getY()-firstPoint.getY();
99
                                        try {
100
                                                //ViewPort vp = getCadToolAdapter().getMapControl().getViewPort(); 
101
                                                editingSource.startComplexGeometry();
102
                                                for (int i = 0; i < editingSource.getGeometryCount(); i++) {
103
                                                        if (selectedGeometries.get(i)) {
104
                                                                IGeometry geometry = editingSource.getGeometry(i);
105
                                                                geometry.scale(firstPoint,firstPoint.distance(lastPoint),firstPoint.distance(lastPoint));
106
                                                                editingSource.modifyGeometry(i,geometry);
107
                                                        }
108
                                                }
109
                                                editingSource.endComplexGeometry();
110
                                        } catch (DriverIOException e) {
111
                                                e.printStackTrace();
112
                                        } catch (IOException e1) {
113
                                                e1.printStackTrace();
114
                                        }
115
                                        PluginServices.getMDIManager().restoreCursor();
116
                        ret = ret | scaleStatus.transition("cancel");
117

    
118
                }else if (status == 3) {
119
                        try {
120
                                for (int i = 0; i < editingSource.getGeometryCount(); i++) {
121
                                        if (selectedGeometries.get(i)) {
122
                                                IGeometry geometry = editingSource.getGeometry(i);
123
                                                geometry.scale(firstPoint,ds[0],ds[0]);
124
                                                editingSource.modifyGeometry(i,geometry);
125
                                        }
126
                                }
127
                        } catch (DriverIOException e) {
128
                                e.printStackTrace();
129
                        } catch (IOException e1) {
130
                                e1.printStackTrace();
131
                        }
132

    
133
                        ret = ret | scaleStatus.transition("cancel");
134
                }
135

    
136
                return ret;
137
        }
138

    
139
        /**
140
         * @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
141
         *                 com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
142
         *                 com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
143
         */
144
        public void drawOperation(Graphics g, EditableFeatureSource efs,
145
                FBitSet selectedGeometries, double x, double y) {
146
                int status = scaleStatus.getStatus();
147
                if (status == 1){
148
                        double w;
149
                        double h;
150
                                w=x-firstPoint.getX();
151
                                h=y-firstPoint.getY();
152
                        try {
153
                        for (int i = 0; i < efs.getGeometryCount(); i++) {
154
                                if (selectedGeometries.get(i)) {
155
                                        IGeometry geometry = efs.getGeometry(i);
156
                                        
157
                                        Point2D currentPoint = new Point2D.Double(x, y);
158
                                        
159
                                        geometry.scale(firstPoint,firstPoint.distance(currentPoint),firstPoint.distance(currentPoint));
160
                                        geometry.draw((Graphics2D) g,
161
                                                        getCadToolAdapter().getMapControl().getViewPort(),
162
                                                        CadTool.modifySymbol);
163
                                        drawLine((Graphics2D)g, firstPoint, currentPoint);
164
                                }
165
                        }
166
                } catch (DriverIOException e) {
167
                        e.printStackTrace();
168
                } catch (IOException e) {
169
                        e.printStackTrace();
170
                }
171
                }
172
        }
173

    
174
        /**
175
         * @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
176
         */
177
        public String getQuestion() {
178
                return STATUS[scaleStatus.getStatus()].getQuestion();
179
        }
180

    
181
        /**
182
         * @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
183
         */
184
        public void initializeStatus() {
185
                scaleStatus.initialize();
186
        }
187

    
188
        /**
189
         * @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
190
         */
191
        public Automaton getAutomaton() {
192
                return scaleStatus;
193
        }
194
}
195