root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / CopyCADTool.java @ 4365
History | View | Annotate | Download (7.94 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.awt.geom.Point2D; |
47 |
import java.io.IOException; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.cit.gvsig.CADExtension; |
51 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
52 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
53 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
54 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
55 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
56 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
57 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
58 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
59 |
import com.iver.cit.gvsig.gui.cad.tools.smc.CopyCADToolContext; |
60 |
import com.iver.cit.gvsig.gui.cad.tools.smc.CopyCADToolContext.CopyCADToolState; |
61 |
|
62 |
|
63 |
/**
|
64 |
* DOCUMENT ME!
|
65 |
*
|
66 |
* @author Vicente Caballero Navarro
|
67 |
*/
|
68 |
public class CopyCADTool extends DefaultCADTool { |
69 |
private CopyCADToolContext _fsm;
|
70 |
private Point2D firstPoint; |
71 |
private Point2D lastPoint; |
72 |
|
73 |
/**
|
74 |
* Crea un nuevo PolylineCADTool.
|
75 |
*/
|
76 |
public CopyCADTool() {
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
81 |
* carga previa a la utilizaci?n de la herramienta.
|
82 |
*/
|
83 |
public void init() { |
84 |
_fsm = new CopyCADToolContext(this); |
85 |
} |
86 |
|
87 |
/* (non-Javadoc)
|
88 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
89 |
*/
|
90 |
public void transition(double x, double y, InputEvent event) { |
91 |
_fsm.addPoint(x, y, event); |
92 |
} |
93 |
|
94 |
/* (non-Javadoc)
|
95 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
96 |
*/
|
97 |
public void transition(double d) { |
98 |
//_fsm.addValue(sel,d);
|
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
103 |
*/
|
104 |
public void transition(String s) { |
105 |
_fsm.addOption(s); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* DOCUMENT ME!
|
110 |
*/
|
111 |
public void selection() { |
112 |
FBitSet selection = CADExtension.getCADToolAdapter() |
113 |
.getVectorialAdapter().getSelection(); |
114 |
|
115 |
if (selection.cardinality() == 0) { |
116 |
CADExtension.setCADTool("selection");
|
117 |
((SelectionCADTool) CADExtension.getCADToolAdapter().getCadTool()).setNextTool( |
118 |
"copy");
|
119 |
} |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
124 |
* editableFeatureSource que ya estar? creado.
|
125 |
*
|
126 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
127 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
128 |
*/
|
129 |
public void addPoint(double x, double y,InputEvent event) { |
130 |
CopyCADToolState actualState = (CopyCADToolState) _fsm.getPreviousState(); |
131 |
String status = actualState.getName();
|
132 |
VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter(); |
133 |
FBitSet selection = vea.getSelection(); |
134 |
|
135 |
if (status.equals("Copy.FirstPointToMove")) { |
136 |
firstPoint = new Point2D.Double(x, y); |
137 |
} else if (status.equals("Copy.SecondPointToMove")) { |
138 |
PluginServices.getMDIManager().setWaitCursor(); |
139 |
lastPoint = new Point2D.Double(x, y); |
140 |
vea.startComplexRow(); |
141 |
|
142 |
try {
|
143 |
for (int i = selection.nextSetBit(0); i >= 0; |
144 |
i = selection.nextSetBit(i + 1)) {
|
145 |
DefaultFeature fea = (DefaultFeature) vea.getRow(i) |
146 |
.getLinkedRow() |
147 |
.cloneRow(); |
148 |
// Movemos la geometr?a
|
149 |
UtilFunctions.moveGeom(fea.getGeometry(), lastPoint.getX() - |
150 |
firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
151 |
|
152 |
vea.addRow(fea,getName()); |
153 |
} |
154 |
|
155 |
vea.endComplexRow(); |
156 |
} catch (DriverIOException e) {
|
157 |
// TODO Auto-generated catch block
|
158 |
e.printStackTrace(); |
159 |
} catch (IOException e) { |
160 |
// TODO Auto-generated catch block
|
161 |
e.printStackTrace(); |
162 |
} |
163 |
|
164 |
selection.clear(); |
165 |
PluginServices.getMDIManager().restoreCursor(); |
166 |
|
167 |
//ret = ret | copyStatus.transition("cancel");
|
168 |
} |
169 |
} |
170 |
|
171 |
/**
|
172 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
173 |
* encontremos.
|
174 |
*
|
175 |
* @param g Graphics sobre el que dibujar.
|
176 |
* @param x par?metro x del punto que se pase para dibujar.
|
177 |
* @param y par?metro x del punto que se pase para dibujar.
|
178 |
*/
|
179 |
public void drawOperation(Graphics g, double x, double y) { |
180 |
CopyCADToolState actualState = ((CopyCADToolContext) _fsm).getState(); |
181 |
String status = actualState.getName();
|
182 |
VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter(); |
183 |
FBitSet selection = vea.getSelection(); |
184 |
|
185 |
try {
|
186 |
drawHandlers(g, selection, |
187 |
getCadToolAdapter().getMapControl().getViewPort() |
188 |
.getAffineTransform()); |
189 |
} catch (DriverIOException e) {
|
190 |
// TODO Auto-generated catch block
|
191 |
e.printStackTrace(); |
192 |
} |
193 |
|
194 |
if (status.equals("Copy.SecondPointToMove")) { |
195 |
///int dx = getCadToolAdapter().getMapControl().getViewPort().fromMapDistance(x - firstPoint.getX());
|
196 |
///int dy = -getCadToolAdapter().getMapControl().getViewPort().fromMapDistance(y - firstPoint.getY());
|
197 |
///Image img = getCadToolAdapter().getVectorialAdapter().getImage();
|
198 |
///g.drawImage(img, dx, dy, null);
|
199 |
try {
|
200 |
for (int i = selection.nextSetBit(0); i >= 0; |
201 |
i = selection.nextSetBit(i + 1)) {
|
202 |
IGeometry geometry = vea.getShape(i).cloneGeometry(); |
203 |
// Movemos la geometr?a
|
204 |
UtilFunctions.moveGeom(geometry, x - firstPoint.getX(), y - firstPoint.getY()); |
205 |
// geometry.move(x - firstPoint.getX(), y - firstPoint.getY());
|
206 |
geometry.draw((Graphics2D) g,
|
207 |
getCadToolAdapter().getMapControl().getViewPort(), |
208 |
CADTool.drawingSymbol); |
209 |
} |
210 |
} catch (DriverIOException e) {
|
211 |
e.printStackTrace(); |
212 |
} |
213 |
} |
214 |
} |
215 |
|
216 |
/**
|
217 |
* Add a diferent option.
|
218 |
*
|
219 |
* @param s Diferent option.
|
220 |
*/
|
221 |
public void addOption(String s) { |
222 |
} |
223 |
|
224 |
/* (non-Javadoc)
|
225 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
226 |
*/
|
227 |
public void addValue(double d) { |
228 |
} |
229 |
|
230 |
public String getName() { |
231 |
return "COPIAR"; |
232 |
} |
233 |
} |