svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / MoveCADTool.java @ 4490
History | View | Annotate | Download (7.3 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 |
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.core.IFeature; |
53 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
54 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
55 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
56 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
57 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
58 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
59 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
60 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
61 |
import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext; |
62 |
import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext.MoveCADToolState; |
63 |
|
64 |
|
65 |
/**
|
66 |
* DOCUMENT ME!
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*/
|
70 |
public class MoveCADTool extends DefaultCADTool { |
71 |
private MoveCADToolContext _fsm;
|
72 |
private Point2D firstPoint; |
73 |
private Point2D lastPoint; |
74 |
|
75 |
/**
|
76 |
* Crea un nuevo PolylineCADTool.
|
77 |
*/
|
78 |
public MoveCADTool() {
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
83 |
* carga previa a la utilizaci?n de la herramienta.
|
84 |
*/
|
85 |
public void init() { |
86 |
_fsm = new MoveCADToolContext(this); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
91 |
*/
|
92 |
public void transition(double x, double y, InputEvent event) { |
93 |
_fsm.addPoint(x, y, event); |
94 |
} |
95 |
|
96 |
/* (non-Javadoc)
|
97 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
98 |
*/
|
99 |
public void transition(double d) { |
100 |
//_fsm.addValue(sel,d);
|
101 |
} |
102 |
|
103 |
/* (non-Javadoc)
|
104 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
105 |
*/
|
106 |
public void transition(String s) { |
107 |
_fsm.addOption(s); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* DOCUMENT ME!
|
112 |
*/
|
113 |
public void selection() { |
114 |
FBitSet selection = CADExtension.getCADToolAdapter() |
115 |
.getVectorialAdapter().getSelection(); |
116 |
|
117 |
if (selection.cardinality() == 0 && !CADExtension.getCADToolAdapter().getCadTool().getName().equals("selection")) { |
118 |
CADExtension.setCADTool("selection");
|
119 |
((SelectionCADTool) CADExtension.getCADToolAdapter().getCadTool()).setNextTool( |
120 |
"move");
|
121 |
} |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
126 |
* editableFeatureSource que ya estar? creado.
|
127 |
*
|
128 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
129 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
130 |
*/
|
131 |
public void addPoint(double x, double y,InputEvent event) { |
132 |
MoveCADToolState actualState = (MoveCADToolState) _fsm.getPreviousState(); |
133 |
String status = actualState.getName();
|
134 |
VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter(); |
135 |
ArrayList selectedRow=getSelectedRow();
|
136 |
|
137 |
if (status.equals("Move.FirstPointToMove")) { |
138 |
firstPoint = new Point2D.Double(x, y); |
139 |
} else if (status.equals("Move.SecondPointToMove")) { |
140 |
PluginServices.getMDIManager().setWaitCursor(); |
141 |
lastPoint = new Point2D.Double(x, y); |
142 |
vea.startComplexRow(); |
143 |
|
144 |
try {
|
145 |
for (int i = 0; i < selectedRow.size(); i++) { |
146 |
IRowEdited edRow = (IRowEdited) selectedRow.get(i); |
147 |
IFeature feat = (IFeature) edRow.getLinkedRow().cloneRow(); |
148 |
IGeometry ig = feat.getGeometry(); |
149 |
if (ig == null) |
150 |
continue;
|
151 |
// Movemos la geometr?a
|
152 |
UtilFunctions.moveGeom(ig, lastPoint.getX() - |
153 |
firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
154 |
|
155 |
vea.modifyRow(edRow.getIndex(),feat,getName()); |
156 |
} |
157 |
FBitSet selection = CADExtension.getCADToolAdapter() |
158 |
.getVectorialAdapter().getSelection(); |
159 |
selection.clear(); |
160 |
selectedRow.clear(); |
161 |
vea.endComplexRow(); |
162 |
} catch (DriverIOException e) {
|
163 |
e.printStackTrace(); |
164 |
} catch (IOException e) { |
165 |
e.printStackTrace(); |
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 |
MoveCADToolState actualState = ((MoveCADToolContext) _fsm).getState(); |
181 |
String status = actualState.getName();
|
182 |
ArrayList selectedRow=getSelectedRow();
|
183 |
drawHandlers(g, selectedRow, |
184 |
getCadToolAdapter().getMapControl().getViewPort() |
185 |
.getAffineTransform()); |
186 |
if (status.equals("Move.SecondPointToMove")) { |
187 |
for (int i = 0; i < selectedRow.size(); i++) { |
188 |
IRowEdited edRow = (IRowEdited) selectedRow.get(i); |
189 |
IFeature feat = (IFeature) edRow.getLinkedRow(); |
190 |
IGeometry ig = feat.getGeometry().cloneGeometry(); |
191 |
if (ig == null) |
192 |
continue;
|
193 |
// Movemos la geometr?a
|
194 |
UtilFunctions.moveGeom(ig, x - firstPoint.getX(), y - firstPoint.getY()); |
195 |
ig.draw((Graphics2D) g,
|
196 |
getCadToolAdapter().getMapControl().getViewPort(), |
197 |
CADTool.drawingSymbol); |
198 |
} |
199 |
} |
200 |
} |
201 |
|
202 |
/**
|
203 |
* Add a diferent option.
|
204 |
*
|
205 |
* @param s Diferent option.
|
206 |
*/
|
207 |
public void addOption(String s) { |
208 |
} |
209 |
|
210 |
/* (non-Javadoc)
|
211 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
212 |
*/
|
213 |
public void addValue(double d) { |
214 |
} |
215 |
|
216 |
public String getName() { |
217 |
return "DESPLAZAR"; |
218 |
} |
219 |
} |