root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / CopyCADTool.java @ 4892
History | View | Annotate | Download (7.96 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.event.InputEvent; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.io.IOException; |
48 |
import java.util.ArrayList; |
49 |
|
50 |
import com.iver.andami.PluginServices; |
51 |
import com.iver.cit.gvsig.CADExtension; |
52 |
import com.iver.cit.gvsig.fmap.ViewPort; |
53 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
54 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
55 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
56 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
57 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
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 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
62 |
|
63 |
|
64 |
/**
|
65 |
* DOCUMENT ME!
|
66 |
*
|
67 |
* @author Vicente Caballero Navarro
|
68 |
*/
|
69 |
public class CopyCADTool extends DefaultCADTool { |
70 |
private CopyCADToolContext _fsm;
|
71 |
private Point2D firstPoint; |
72 |
private Point2D lastPoint; |
73 |
|
74 |
/**
|
75 |
* Crea un nuevo PolylineCADTool.
|
76 |
*/
|
77 |
public CopyCADTool() {
|
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 CopyCADToolContext(this); |
86 |
} |
87 |
|
88 |
/* (non-Javadoc)
|
89 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
90 |
*/
|
91 |
public void transition(double x, double y, InputEvent event) { |
92 |
_fsm.addPoint(x, y, event); |
93 |
} |
94 |
|
95 |
/* (non-Javadoc)
|
96 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
97 |
*/
|
98 |
public void transition(double d) { |
99 |
//_fsm.addValue(sel,d);
|
100 |
} |
101 |
|
102 |
/* (non-Javadoc)
|
103 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
104 |
*/
|
105 |
public void transition(String s) { |
106 |
if (!super.changeCommand(s)){ |
107 |
_fsm.addOption(s); |
108 |
} |
109 |
} |
110 |
|
111 |
/**
|
112 |
* DOCUMENT ME!
|
113 |
*/
|
114 |
public void selection() { |
115 |
ArrayList selectedRow=getSelectedRows();
|
116 |
if (selectedRow.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
117 |
CADExtension.setCADTool("selection",false); |
118 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
119 |
"copy");
|
120 |
} |
121 |
} |
122 |
|
123 |
/**
|
124 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
125 |
* editableFeatureSource que ya estar? creado.
|
126 |
*
|
127 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
128 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
129 |
*/
|
130 |
public void addPoint(double x, double y,InputEvent event) { |
131 |
CopyCADToolState actualState = (CopyCADToolState) _fsm.getPreviousState(); |
132 |
String status = actualState.getName();
|
133 |
VectorialLayerEdited vle=getVLE(); |
134 |
VectorialEditableAdapter vea = vle.getVEA(); |
135 |
ArrayList selectedRow=getSelectedRows();
|
136 |
|
137 |
if (status.equals("Copy.FirstPointToMove")) { |
138 |
firstPoint = new Point2D.Double(x, y); |
139 |
} else if (status.equals("Copy.SecondPointToMove")) { |
140 |
PluginServices.getMDIManager().setWaitCursor(); |
141 |
lastPoint = new Point2D.Double(x, y); |
142 |
vea.startComplexRow(); |
143 |
|
144 |
try {
|
145 |
///ArrayList selectedRowAux=new ArrayList();
|
146 |
|
147 |
for (int i = 0; i < selectedRow.size(); i++) { |
148 |
DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited)selectedRow.get(i)) |
149 |
.getLinkedRow() |
150 |
.cloneRow(); |
151 |
// Movemos la geometr?a
|
152 |
UtilFunctions.moveGeom(fea.getGeometry(), lastPoint.getX() - |
153 |
firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
154 |
|
155 |
int index=vea.addRow(fea,getName());
|
156 |
/// selectedRowAux.add(new DefaultRowEdited(fea,IRowEdited.STATUS_ADDED,index));
|
157 |
} |
158 |
vea.endComplexRow(); |
159 |
clearSelection(); |
160 |
/// selectedRow=selectedRowAux;
|
161 |
} catch (DriverIOException e) {
|
162 |
e.printStackTrace(); |
163 |
} catch (IOException e) { |
164 |
e.printStackTrace(); |
165 |
} |
166 |
|
167 |
PluginServices.getMDIManager().restoreCursor(); |
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 |
VectorialLayerEdited vle=getVLE(); |
183 |
//ArrayList selectedRow=getSelectedRows();
|
184 |
// drawHandlers(g, selectedRow,
|
185 |
// getCadToolAdapter().getMapControl().getViewPort()
|
186 |
// .getAffineTransform());
|
187 |
if (status.equals("Copy.SecondPointToMove")) { |
188 |
ViewPort vp=vle.getLayer().getFMap().getViewPort(); |
189 |
int dx = vp.fromMapDistance(x - firstPoint.getX());
|
190 |
int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
191 |
Image img = vle.getSelectionImage();
|
192 |
g.drawImage(img, dx, dy, null);
|
193 |
/* for (int i = 0; i < selectedRow.size(); i++) {
|
194 |
IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
195 |
IFeature feat = (IFeature) edRow.getLinkedRow();
|
196 |
IGeometry geometry = feat.getGeometry().cloneGeometry();
|
197 |
// Movemos la geometr?a
|
198 |
UtilFunctions.moveGeom(geometry, x - firstPoint.getX(), y - firstPoint.getY());
|
199 |
geometry.draw((Graphics2D) g,
|
200 |
getCadToolAdapter().getMapControl().getViewPort(),
|
201 |
CADTool.drawingSymbol);
|
202 |
}
|
203 |
*/
|
204 |
}else{
|
205 |
Image imgSel = vle.getSelectionImage();
|
206 |
g.drawImage(imgSel, 0, 0, null); |
207 |
Image imgHand = vle.getHandlersImage();
|
208 |
g.drawImage(imgHand, 0, 0, null); |
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* Add a diferent option.
|
214 |
*
|
215 |
* @param s Diferent option.
|
216 |
*/
|
217 |
public void addOption(String s) { |
218 |
} |
219 |
|
220 |
/* (non-Javadoc)
|
221 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
222 |
*/
|
223 |
public void addValue(double d) { |
224 |
} |
225 |
|
226 |
public String getName() { |
227 |
return PluginServices.getText(this,"copy_"); |
228 |
} |
229 |
|
230 |
public String toString() { |
231 |
return "_copy"; |
232 |
} |
233 |
} |