root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / ArcCADTool.java @ 30788
History | View | Annotate | Download (5.55 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 org.gvsig.editing.gui.cad.tools; |
42 |
|
43 |
import java.awt.Image; |
44 |
import java.awt.event.InputEvent; |
45 |
import java.awt.geom.Point2D; |
46 |
|
47 |
import org.gvsig.andami.PluginServices; |
48 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
49 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
50 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext; |
51 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext.ArcCADToolState; |
52 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
53 |
import org.gvsig.fmap.geom.Geometry; |
54 |
import org.gvsig.fmap.geom.primitive.Point; |
55 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
56 |
|
57 |
|
58 |
|
59 |
/**
|
60 |
* DOCUMENT ME!
|
61 |
*
|
62 |
* @author Vicente Caballero Navarro
|
63 |
*/
|
64 |
public class ArcCADTool extends DefaultCADTool { |
65 |
private ArcCADToolContext _fsm;
|
66 |
private Point p1; |
67 |
private Point p2; |
68 |
private Point p3; |
69 |
|
70 |
/**
|
71 |
* Crea un nuevo LineCADTool.
|
72 |
*/
|
73 |
public ArcCADTool() {
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
78 |
* carga previa a la utilizaci?n de la herramienta.
|
79 |
*/
|
80 |
public void init() { |
81 |
_fsm = new ArcCADToolContext(this); |
82 |
} |
83 |
|
84 |
/* (non-Javadoc)
|
85 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
86 |
*/
|
87 |
public void transition(double x, double y, InputEvent event) { |
88 |
_fsm.addPoint(x, y,event); |
89 |
} |
90 |
|
91 |
/* (non-Javadoc)
|
92 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
93 |
*/
|
94 |
public void transition(double d){ |
95 |
_fsm.addValue(d); |
96 |
} |
97 |
|
98 |
/* (non-Javadoc)
|
99 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
100 |
*/
|
101 |
public void transition(String s) throws CommandException { |
102 |
if (!super.changeCommand(s)){ |
103 |
_fsm.addOption(s); |
104 |
} |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
109 |
* editableFeatureSource que ya estar? creado.
|
110 |
*
|
111 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
112 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
113 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
114 |
*/
|
115 |
public void addPoint(double x, double y,InputEvent event) { |
116 |
ArcCADToolState actualState = (ArcCADToolState) _fsm.getPreviousState(); |
117 |
String status = actualState.getName();
|
118 |
|
119 |
if (status.equals("Arc.FirstPoint")) { |
120 |
p1 = createPoint(x, y); |
121 |
} else if (status.equals("Arc.SecondPoint")) { |
122 |
p2 = createPoint(x, y); |
123 |
} else if (status.equals("Arc.ThirdPoint")) { |
124 |
p3 = createPoint(x, y); |
125 |
Geometry ig = createArc(p1, p2, p3); |
126 |
if (ig != null) { |
127 |
insertAndSelectGeometry(ig); |
128 |
} |
129 |
} |
130 |
} |
131 |
|
132 |
/**
|
133 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
134 |
* encontremos.
|
135 |
*
|
136 |
* @param g Graphics sobre el que dibujar.
|
137 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
138 |
* @param x par?metro x del punto que se pase para dibujar.
|
139 |
* @param y par?metro x del punto que se pase para dibujar.
|
140 |
*/
|
141 |
public void drawOperation(MapControlDrawer renderer, double x, |
142 |
double y) {
|
143 |
ArcCADToolState actualState = _fsm.getState(); |
144 |
String status = actualState.getName();
|
145 |
|
146 |
if (status.equals("Arc.SecondPoint")) { |
147 |
renderer.drawLine(new Point2D.Double(p1.getX(), p1.getY()), |
148 |
new Point2D.Double(x, y), |
149 |
mapControlManager.getGeometrySelectionSymbol()); |
150 |
} else if (status.equals("Arc.ThirdPoint")) { |
151 |
Point current = createPoint(x, y);
|
152 |
|
153 |
Geometry ig = createArc(p1, p2, current); |
154 |
renderer.draw(ig, mapControlManager.getGeometrySelectionSymbol()); |
155 |
|
156 |
Point2D p = getCadToolAdapter().getMapControl().getViewPort()
|
157 |
.fromMapPoint(p1.getX(), p1.getY()); |
158 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
159 |
p = getCadToolAdapter().getMapControl().getViewPort().fromMapPoint(p2.getX(), |
160 |
p2.getY()); |
161 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
162 |
} |
163 |
} |
164 |
|
165 |
/**
|
166 |
* Add a diferent option.
|
167 |
*
|
168 |
* @param sel DOCUMENT ME!
|
169 |
* @param s Diferent option.
|
170 |
*/
|
171 |
public void addOption(String s) { |
172 |
// TODO Auto-generated method stub
|
173 |
} |
174 |
|
175 |
/* (non-Javadoc)
|
176 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
177 |
*/
|
178 |
public void addValue(double d) { |
179 |
} |
180 |
|
181 |
public String getName() { |
182 |
return PluginServices.getText(this,"arc_"); |
183 |
} |
184 |
|
185 |
public String toString() { |
186 |
return "_arc"; |
187 |
} |
188 |
|
189 |
public boolean isApplicable(int shapeType) { |
190 |
switch (shapeType) {
|
191 |
case Geometry.TYPES.POINT:
|
192 |
case Geometry.TYPES.SURFACE:
|
193 |
case Geometry.TYPES.MULTIPOINT:
|
194 |
return false; |
195 |
} |
196 |
return true; |
197 |
} |
198 |
|
199 |
} |