svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / com / iver / cit / gvsig / gui / cad / tools / MultiPointCADTool.java @ 27398
History | View | Annotate | Download (7.14 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.util.ArrayList; |
47 |
|
48 |
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
49 |
import org.gvsig.fmap.geom.Geometry; |
50 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
51 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
52 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
53 |
import org.gvsig.fmap.geom.operation.Draw; |
54 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
55 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
56 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
57 |
import org.gvsig.fmap.geom.primitive.Point; |
58 |
|
59 |
import com.iver.andami.PluginServices; |
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.MultiPointCADToolContext; |
63 |
import com.iver.cit.gvsig.gui.cad.tools.smc.MultiPointCADToolContext.MultiPointCADToolState; |
64 |
|
65 |
|
66 |
/**
|
67 |
* DOCUMENT ME!
|
68 |
*
|
69 |
* @author Vicente Caballero Navarro
|
70 |
*/
|
71 |
public class MultiPointCADTool extends DefaultCADTool { |
72 |
protected MultiPointCADToolContext _fsm;
|
73 |
protected ArrayList points=new ArrayList(); |
74 |
|
75 |
/**
|
76 |
* Crea un nuevo PointCADTool.
|
77 |
*/
|
78 |
public MultiPointCADTool() {
|
79 |
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
84 |
* carga previa a la utilizaci?n de la herramienta.
|
85 |
*/
|
86 |
public void init() { |
87 |
_fsm = new MultiPointCADToolContext(this); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* DOCUMENT ME!
|
92 |
* @param x DOCUMENT ME!
|
93 |
* @param y DOCUMENT ME!
|
94 |
* @param sel DOCUMENT ME!
|
95 |
*/
|
96 |
public void transition(double x, double y, InputEvent event) { |
97 |
_fsm.addPoint(x, y, event); |
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
102 |
*/
|
103 |
public void transition(double d) { |
104 |
_fsm.addValue(d); |
105 |
} |
106 |
|
107 |
/* (non-Javadoc)
|
108 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
109 |
*/
|
110 |
public void transition(String s) throws CommandException { |
111 |
if (!super.changeCommand(s)){ |
112 |
_fsm.addOption(s); |
113 |
} |
114 |
} |
115 |
|
116 |
/**
|
117 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
118 |
* editableFeatureSource que ya estar? creado.
|
119 |
*
|
120 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
121 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
122 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
123 |
*/
|
124 |
public void addPoint(double x, double y,InputEvent event) { |
125 |
MultiPointCADToolState actualState = (MultiPointCADToolState) _fsm.getPreviousState(); |
126 |
String status = actualState.getName();
|
127 |
|
128 |
if (status.equals("MultiPoint.InsertPoint")) { |
129 |
points.add(new double[] {x,y}); |
130 |
//addGeometry(ShapeFactory.createPoint2D(x, y));
|
131 |
} |
132 |
} |
133 |
|
134 |
/**
|
135 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
136 |
* encontremos.
|
137 |
*
|
138 |
* @param g Graphics sobre el que dibujar.
|
139 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
140 |
* @param x par?metro x del punto que se pase para dibujar.
|
141 |
* @param y par?metro x del punto que se pase para dibujar.
|
142 |
*/
|
143 |
public void drawOperation(Graphics g, double x, |
144 |
double y) {
|
145 |
try {
|
146 |
int num=points.size();
|
147 |
Point[] pointsAux = new Point[num]; |
148 |
for (int i=0;i<num;i++) { |
149 |
double[] p=(double[])points.get(i); |
150 |
pointsAux[i] = (Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
151 |
pointsAux[i].setX(p[0]);
|
152 |
pointsAux[i].setY(p[1]);
|
153 |
} |
154 |
|
155 |
DrawOperationContext doc=new DrawOperationContext();
|
156 |
doc.setGraphics((Graphics2D)g);
|
157 |
doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
158 |
doc.setSymbol(DefaultCADTool.geometrySelectSymbol); |
159 |
|
160 |
MultiPoint multiPoint = (MultiPoint)geomManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
161 |
for (int i=0 ; i<pointsAux.length ; i++){ |
162 |
multiPoint.addPoint(pointsAux[i]); |
163 |
} |
164 |
multiPoint.invokeOperation(Draw.CODE,doc); |
165 |
createPoint(x,y).invokeOperation(Draw.CODE,doc); |
166 |
} catch (GeometryOperationNotSupportedException e) {
|
167 |
e.printStackTrace(); |
168 |
} catch (GeometryOperationException e) {
|
169 |
e.printStackTrace(); |
170 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
171 |
logger.error(new CreateGeometryException(TYPES.MULTIPOINT, SUBTYPES.GEOM2D, e));
|
172 |
} |
173 |
|
174 |
// geomFactory.createMultipoint2D(xs,ys).draw((Graphics2D) g,
|
175 |
// getCadToolAdapter().getMapControl().getViewPort(),
|
176 |
// DefaultCADTool.geometrySelectSymbol);
|
177 |
// geomFactory.createPoint2D(x,y).draw((Graphics2D) g,
|
178 |
// getCadToolAdapter().getMapControl().getViewPort(),
|
179 |
// DefaultCADTool.geometrySelectSymbol);
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* Add a diferent option.
|
184 |
*
|
185 |
* @param sel DOCUMENT ME!
|
186 |
* @param s Diferent option.
|
187 |
*/
|
188 |
public void addOption(String s) { |
189 |
// TODO Auto-generated method stub
|
190 |
} |
191 |
|
192 |
/* (non-Javadoc)
|
193 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
194 |
*/
|
195 |
public void addValue(double d) { |
196 |
// TODO Auto-generated method stub
|
197 |
} |
198 |
|
199 |
public String getName() { |
200 |
return PluginServices.getText(this,"multipoint_"); |
201 |
} |
202 |
|
203 |
public String toString() { |
204 |
return "_multipoint"; |
205 |
} |
206 |
public boolean isApplicable(int shapeType) { |
207 |
switch (shapeType) {
|
208 |
case Geometry.TYPES.MULTIPOINT:
|
209 |
return true; |
210 |
} |
211 |
return false; |
212 |
} |
213 |
|
214 |
public void endGeometry(){ |
215 |
try {
|
216 |
int num=points.size();
|
217 |
Point[] pointsAux = new Point[num]; |
218 |
for (int i=0;i<num;i++) { |
219 |
double[] p=(double[])points.get(i); |
220 |
pointsAux[i] = (Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
221 |
pointsAux[i].setX(p[0]);
|
222 |
pointsAux[i].setY(p[1]);
|
223 |
} |
224 |
|
225 |
MultiPoint multiPoint; |
226 |
|
227 |
multiPoint = (MultiPoint)geomManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
228 |
for (int i=0 ; i<pointsAux.length ; i++){ |
229 |
multiPoint.addPoint(pointsAux[i]); |
230 |
} |
231 |
insertAndSelectGeometry(multiPoint); |
232 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
233 |
logger.error(new CreateGeometryException(TYPES.MULTIPOINT, SUBTYPES.GEOM2D, e));
|
234 |
} |
235 |
end(); |
236 |
} |
237 |
public void end() { |
238 |
points.clear(); |
239 |
super.end();
|
240 |
} |
241 |
} |