root / tags / v1_0_2_Build_906 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / CopyCADTool.java @ 10972
History | View | Annotate | Download (8.28 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.EditionEvent; |
57 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
58 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
59 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
60 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
61 |
import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
62 |
import com.iver.cit.gvsig.gui.cad.tools.smc.CopyCADToolContext; |
63 |
import com.iver.cit.gvsig.gui.cad.tools.smc.CopyCADToolContext.CopyCADToolState; |
64 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
65 |
|
66 |
|
67 |
/**
|
68 |
* DOCUMENT ME!
|
69 |
*
|
70 |
* @author Vicente Caballero Navarro
|
71 |
*/
|
72 |
public class CopyCADTool extends DefaultCADTool { |
73 |
private CopyCADToolContext _fsm;
|
74 |
private Point2D firstPoint; |
75 |
private Point2D lastPoint; |
76 |
|
77 |
/**
|
78 |
* Crea un nuevo PolylineCADTool.
|
79 |
*/
|
80 |
public CopyCADTool() {
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
85 |
* carga previa a la utilizaci?n de la herramienta.
|
86 |
*/
|
87 |
public void init() { |
88 |
_fsm = new CopyCADToolContext(this); |
89 |
} |
90 |
|
91 |
/* (non-Javadoc)
|
92 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
93 |
*/
|
94 |
public void transition(double x, double y, InputEvent event) { |
95 |
_fsm.addPoint(x, y, event); |
96 |
} |
97 |
|
98 |
/* (non-Javadoc)
|
99 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
100 |
*/
|
101 |
public void transition(double d) { |
102 |
_fsm.addValue(d); |
103 |
} |
104 |
|
105 |
/* (non-Javadoc)
|
106 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
107 |
*/
|
108 |
public void transition(String s) throws CommandException { |
109 |
if (!super.changeCommand(s)){ |
110 |
_fsm.addOption(s); |
111 |
} |
112 |
} |
113 |
|
114 |
/**
|
115 |
* DOCUMENT ME!
|
116 |
*/
|
117 |
public void selection() { |
118 |
ArrayList selectedRow=getSelectedRows();
|
119 |
if (selectedRow.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
120 |
CADExtension.setCADTool("_selection",false); |
121 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
122 |
"_copy");
|
123 |
} |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
128 |
* editableFeatureSource que ya estar? creado.
|
129 |
*
|
130 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
131 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
132 |
*/
|
133 |
public void addPoint(double x, double y,InputEvent event) { |
134 |
CopyCADToolState actualState = (CopyCADToolState) _fsm.getPreviousState(); |
135 |
String status = actualState.getName();
|
136 |
VectorialLayerEdited vle=getVLE(); |
137 |
VectorialEditableAdapter vea = vle.getVEA(); |
138 |
ArrayList selectedRow=getSelectedRows();
|
139 |
ArrayList selectedRowAux=new ArrayList(); |
140 |
if (status.equals("Copy.FirstPointToMove")) { |
141 |
firstPoint = new Point2D.Double(x, y); |
142 |
} else if (status.equals("Copy.SecondPointToMove")) { |
143 |
PluginServices.getMDIManager().setWaitCursor(); |
144 |
lastPoint = new Point2D.Double(x, y); |
145 |
vea.startComplexRow(); |
146 |
|
147 |
try {
|
148 |
for (int i = 0; i < selectedRow.size(); i++) { |
149 |
DefaultRowEdited dre=(DefaultRowEdited)selectedRow.get(i); |
150 |
DefaultFeature fea = (DefaultFeature)dre.getLinkedRow() |
151 |
.cloneRow(); |
152 |
// Movemos la geometr?a
|
153 |
UtilFunctions.moveGeom(fea.getGeometry(), lastPoint.getX() - |
154 |
firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
155 |
|
156 |
int index=vea.addRow(fea,getName(),EditionEvent.GRAPHIC);
|
157 |
selectedRowAux.add(new DefaultRowEdited(fea,IRowEdited.STATUS_ADDED,vea.getInversedIndex(index)));
|
158 |
} |
159 |
vea.endComplexRow(getName()); |
160 |
//clearSelection();
|
161 |
//selectedRow.addAll(selectedRowAux);
|
162 |
vle.setSelectionCache(selectedRowAux); |
163 |
} catch (DriverIOException e) {
|
164 |
e.printStackTrace(); |
165 |
} catch (IOException e) { |
166 |
e.printStackTrace(); |
167 |
} |
168 |
|
169 |
PluginServices.getMDIManager().restoreCursor(); |
170 |
} |
171 |
} |
172 |
|
173 |
/**
|
174 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
175 |
* encontremos.
|
176 |
*
|
177 |
* @param g Graphics sobre el que dibujar.
|
178 |
* @param x par?metro x del punto que se pase para dibujar.
|
179 |
* @param y par?metro x del punto que se pase para dibujar.
|
180 |
*/
|
181 |
public void drawOperation(Graphics g, double x, double y) { |
182 |
CopyCADToolState actualState = ((CopyCADToolContext) _fsm).getState(); |
183 |
String status = actualState.getName();
|
184 |
VectorialLayerEdited vle=getVLE(); |
185 |
//ArrayList selectedRow=getSelectedRows();
|
186 |
// drawHandlers(g, selectedRow,
|
187 |
// getCadToolAdapter().getMapControl().getViewPort()
|
188 |
// .getAffineTransform());
|
189 |
if (status.equals("Copy.SecondPointToMove")) { |
190 |
ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
191 |
int dx = vp.fromMapDistance(x - firstPoint.getX());
|
192 |
int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
193 |
Image img = vle.getSelectionImage();
|
194 |
g.drawImage(img, dx, dy, null);
|
195 |
/* for (int i = 0; i < selectedRow.size(); i++) {
|
196 |
IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
197 |
IFeature feat = (IFeature) edRow.getLinkedRow();
|
198 |
IGeometry geometry = feat.getGeometry().cloneGeometry();
|
199 |
// Movemos la geometr?a
|
200 |
UtilFunctions.moveGeom(geometry, x - firstPoint.getX(), y - firstPoint.getY());
|
201 |
geometry.draw((Graphics2D) g,
|
202 |
getCadToolAdapter().getMapControl().getViewPort(),
|
203 |
CADTool.drawingSymbol);
|
204 |
}
|
205 |
*/
|
206 |
}else{
|
207 |
if (!vle.getLayer().isVisible())
|
208 |
return;
|
209 |
Image imgSel = vle.getSelectionImage();
|
210 |
g.drawImage(imgSel, 0, 0, null); |
211 |
Image imgHand = vle.getHandlersImage();
|
212 |
g.drawImage(imgHand, 0, 0, null); |
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 PluginServices.getText(this,"copy_"); |
232 |
} |
233 |
|
234 |
public String toString() { |
235 |
return "_copy"; |
236 |
} |
237 |
|
238 |
|
239 |
} |